Vertex Formats

This section explains how to define and build your own vertex formats.

In general when you start working with shaders you need not worry too much about the vertex format being used, since GameMaker: Studio will automatically set up and pass through the vertex data for you.

However, sometimes it is necessary to create your own vertex data and format it to suit, especially when you need to boost speed, or wish to pass in extra information. For example the standard vertex format includes an x, y, z 3D position, colour (with alpha), and UV texture coordinates, which, if you were creating it yourself, would look something like:

my_format = vertex_format_end();

However, if you are only using (for example) the shader to manipulate the position of the vertex, then there would be no need to pass through colour or texture data. In this case you would create your own format as so:

my_format = vertex_format_end();

You should note that once you have created your vertex format, the order in which you have defined the vertex properties must be honoured when building your primitives. So, if you have defined a vertex format as position, colour, texture coordinate, then you must add these properties to the primitive in the same order otherwise you will get an error. Also note that like any other dynamic resource, a vector format requires memory and therefore should be removed when not needed using the function vector_format_delete().

The following functions are available for drawing shaders:

  1. vertex_format_begin
  2. vertex_format_add_colour
  3. vertex_format_add_position
  4. vertex_format_add_position_3d
  5. vertex_format_add_textcoord
  6. vertex_format_add_normal
  7. vertex_format_add_custom
  8. vertex_format_end
  9. vertex_format_delete

One final important point to note when using your own vertex buffers in this way is how it affects the vertex batches that are sent to the GPU. When you create a vertex buffer you are creating the lowest level of graphics data, so when you draw all that happens is we send your buffer directly to the graphics card. Because of this, if you want better batching, you must work it out yourself and store things you want batch inside the same buffer. So you can't put in 3 sprites then draw many of them and expect vertex buffers to be merged - you're in charge of vertex buffer data at this point. If you want auto-batching then you have to give the engine higher level primitives - like a sprite - at which point GameMaker: Studio can work out what your doing, and fill buffers properly.

Building Your Primitives

Once you have defined your new vertex format, you can then go ahead and build your primitives that will use it. The functions available for this can be found in the following section:

  1. Primitive Building

Back: Shaders
Next: Primitive Building
© Copyright YoYo Games Ltd. 2018 All Rights Reserved