GameMaker Studio 2 permits you to define your own custom primitives following the specifications of the vertex format that you have chosen (see Vertex Formats). These can then be used within any shaders that you have created.
Any primitives that you build are held in a vertex buffer. This must be created beforehand and then referenced by the functions that are used to build your primitive. The vertex buffer can be re-used as many times as necessary to create different primitives, or it can be "frozen" to maintain a specific primitive type for the duration of your game or level (which is the fastest approach, so if you know that a primitive you build will not change then you should always use this option).
The following functions are available for the vertex buffer:
The primitives that you build should follow the format that you have set using the Vertex Formats functions, so if you have defined a vertex format with only positional data, there is no point building your primitive with colour data. You should note that the order in which you add properties to the primitive you are building is defined by the order in which you added these properties when creating the vertex format, so if you have defined the vector format with the order position, colour and texture coordinate, you must add these properties to the primitive being built in the same order otherwise you will get errors.
An example of a single triangle primitive being built is shown in the following code:
v_buff = vertex_create_buffer();
vertex_begin(v_buff, global.my_format);
vertex_position(v_buff, 10, 10);
vertex_colour(v_buff, c_white, 1);
vertex_texcoord(v_buff, 0, 0);
vertex_position(v_buff, 110, 10);
vertex_colour(v_buff, c_white, 1);
vertex_texcoord(v_buff, 1, 0);
vertex_position(v_buff, 110, 110);
vertex_colour(v_buff, c_white, 1);
vertex_texcoord(v_buff, 1, 1);
vertex_end(v_buff);
var tex = sprite_get_texture(spr_Background);
shader_set(shader_prim);
vertex_submit(v_buff, pr_trianglelist, tex);
shader_reset();Primitives can be points, line lists or strips, or triangle lists or strips, but you are not permitted triangle fans since most mobile hardware will not accept that primitive type. The constants used to define these different primitive types can be found here.
NOTE: You can build the primitive and store it in the vertex buffer in any step of your game, however to draw it, you must submit it during the Draw Event.The following functions are available for building primitives: