GML vertex_begin and vertex_end: how are they best used?

Erik Leppen

Member
I want to create a set of scripts to draw vertex primitives more easily. So, I want to create a vertex buffer and then call some scripts to put shapes in them. So the idea is:

Event code:
Code:
//create vertex buffer
//call script to add positions, colours etc.
//call script to add positions, colours etc.
//call script to add positions, colours etc.
//freeze vertex buffer
Script:
Code:
//add positions, texcoords, colours to vertexbuffer
Now I wonder about the use of the functions vertex_begin and vertex_end. Between creating the buffer and adding the vertex data, I should call vertex_begin to define a primitive type (trianglelist, linelist etc.). For this, I have two options.
1. Put the vertex_begin and vertex_end in the script. Then, they are re-called with every shape, but I don't have to mind the primitve type (trianglelist etc.) of various shapes in the same buffer, so more freedom in script calling
2. Put the vertex_begin and vertex_end in the calling code? Then, I can call the functions once and add 1000 shapes, but all shapes have to have the same primitve type (trianglelist etc.). So, if I need triangles and lines, I have to add vertex_begin and _end manually between calls. Also, the script silently assumes a particular primitive type, which is less flexible.
Edit: sorry, I confused primitive types with vertex formats, so this argument doesn't hold. Apparently a vertexbuffer still can't have both lines and triangles, is that correct? But it can hold differently formatted vertices? E.g. one with texcoords and one without?

I wondered which option was the best. Are there differences in performance? Is it slower to have a vertex buffer with 1000 separate vertex_begin and _end? (Provided the buffer is frozen using vertex_freeze)? Or doesn't that change anything?

What would you recommend?
Put vertex_begin and _end in the script:
Event code:
Code:
vbuff = vertex_create_buffer(...);
  vbuff_script(vbuff, ...);
  vbuff_script(vbuff, ...);
  vbuff_script(vbuff, ...);
  //etc.
vertex_freeze(vbuff);
Script:
Code:
vertex_begin(argument0, vertexformat);
  vertex_position(argument0, ...);
  vertex_colour(argument0, ...);
  //etc.
vertex_end(argument0);
Or put vertex_begin and _end in the calling code?
Event code:
Code:
vbuff = vertex_create_buffer(...);
  vertex_begin(vbuff, vertexformat);
    vbuff_script(vbuff, ...);
    vbuff_script(vbuff, ...);
    vbuff_script(vbuff, ...);
    //etc.
  vertex_end(vbuff);
vertex_freeze(vbuff);
Script:
Code:
vertex_position(argument0, ...);
vertex_colour(argument0, ...);
//etc.
Thanks in advance for any insights :)
 
Last edited:
Top