• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker what's the vertex buffers size? [solved]

I don't know more than the very basics of buffers and got a question about vertex buffer size. Here's the example code I was testing some stuff with:
Code:
n_points = 512;
line_buffer = vertex_create_buffer_ext(12 * (n_points)); // <- that's the important line for my question
vertex_begin(line_buffer, line_buffer_format);
    for (i = 0; i < n_points; i++) {
        vertex_position(line_buffer, i, points_array[i]);
        vertex_colour(line_buffer, c_white, 1);
    }
vertex_end(line_buffer);
-> vertex_get_buffer_size(line_buffer) returns 6144


When i increase the buffer by 12 bytes:
Code:
line_buffer = vertex_create_buffer_ext(12 * (n_points + 1)); // <- + 1
-> vertex_get_buffer_size(line_buffer) returns 6156
kinda as expected, 12 more

If I decrease buffer size by 12 however:
Code:
line_buffer = vertex_create_buffer_ext(12 * (n_points - 1)); // <- - 1
-> vertex_get_buffer_size(line_buffer) returns 9210
That was unexpected.

  1. Can anyone explain to me why it's more in the third example?
    (I'm guessing because it's a grow-buffer and GMS2 increases its size by more than needed just in case or something like that)
  2. And am I assuming correctly, that each vertex made out of a 2D position and a colour uses 12 bytes? Can someone explain why or why I'm wrong?
 

Simon Gust

Member
It says it's a grow-buffer, so yeah, it will increase it's own size by a lot (more than needed) so it doesn't have to resize a billion times causing severe slowdown.
Usually grow_buffers double in size. But your's seems to grow by 1.502 times somehow.
When I create an empty vertex buffer it's size will be 256. I did some Tests and when the buffer grows, it seems to take on unrealistic sizes like 1393 Bytes for 100 Points.
I've initially set the size to 12 (the size of 1 Point) which I can confirm: if I create a buffer at size 264 Bytes, with 22 Points, it does not resize the Buffer. If I create it with 263 bytes however, the end size is 406 Bytes.
 

Simon Gust

Member
4 Bytes for x
4 Bytes for y
4 Bytes for Color+alpha: 1 Byte = red. 1 Byte = green, 1 Byte = blue, 1 Byte = alpha
 
Top