• 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 Vertex buffer tilesets and changing tiles

vdweller

Member
Hello!

The past few days I have been fiddling with using vertex buffers for rendering tilesets. I understand that this is a quite fast method. However, what happens when you have a map where tiles change?

Do I need to re-create the entire vertex buffer in that case? If so, doesn't that defeat the purpose of using vertex buffers for speed?

For example, if you have a 300x300 map with tiles, every time a tile changes you would have to iterate through 90,000 tiles and recreate the vertex buffer data. Have I understood that correctly or is there some trick to update vertex buffer contents without having to go through all available tiles?

The same goes with tile smoothing. Every time a tile changes, the only way to update the "edge vertices" that will fade out to give that nice blend is to recreate the buffer from scratch?
 
M

Misty

Guest
I have the same problem. Trying to use vertex buffers for 3d decals but the system doesnt allow me to.
 

TheSnidr

Heavy metal viking dentist
GMC Elder
There are a couple of useful functions that let you convert between vertex buffers and regular buffers. I believe they're named something along the lines of vertex_create_buffer_from_buffer and buffer_create_from_vertex_buffer.
Once your vertex buffer has been converted to a regular one, you can overwrite the vertices of the mesh, and then convert back to vertex buffer. The conversion is actually fairly fast.
 

vdweller

Member
There are a couple of useful functions that let you convert between vertex buffers and regular buffers. I believe they're named something along the lines of vertex_create_buffer_from_buffer and buffer_create_from_vertex_buffer.
Once your vertex buffer has been converted to a regular one, you can overwrite the vertices of the mesh, and then convert back to vertex buffer. The conversion is actually fairly fast.
That's very interesting to know! Another interesting approach could be breaking down the terrain into chunks and simply updating a chunk instead of the entire thing.
 
M

Misty

Guest
There are a couple of useful functions that let you convert between vertex buffers and regular buffers. I believe they're named something along the lines of vertex_create_buffer_from_buffer and buffer_create_from_vertex_buffer.
Once your vertex buffer has been converted to a regular one, you can overwrite the vertices of the mesh, and then convert back to vertex buffer. The conversion is actually fairly fast.
I tried but it gave me an error saying "Error vertex buffer does not exists". The typo was really disheartening and I tried mixing different types of buffers to no avail.
 
Something that has worked pretty well for me is to draw the entire map as a single quad, and to use a second texture that has encoded into it the tile map. In other words each fragment looks up its tile in the texture, calculates its position within the tile, and then samples the tileset texture. With this setup, the tilemap can be a surface texture.

Misty, do you mind showing a sample of the code you're trying to use to convert a buffer into a vertex buffer?
 
M

Misty

Guest
Something that has worked pretty well for me is to draw the entire map as a single quad, and to use a second texture that has encoded into it the tile map. In other words each fragment looks up its tile in the texture, calculates its position within the tile, and then samples the tileset texture. With this setup, the tilemap can be a surface texture.

Misty, do you mind showing a sample of the code you're trying to use to convert a buffer into a vertex buffer?
I never saved the project since the code never worked. The code I did amounted to creating some buffers then trying to use the functions that the Snidr said. It kept saying the buffer didn't exist even though I made sure I created it and it existed.

I just wish there was some kind of tutorial or example project I could look at instead of aimlessly being in the dark.
 
M

Misty

Guest
Thanks I'll check it out soon.

Okay I got it to work with the moving objects. However I have not tried it yet for decals. For decals I will need to convert the vertex buffer back into a regular buffer, then reconvert the regular buffer back into a vertex buffer. If that doesn't work then I can just use ds_lists. If ds_lists are faster then I can just use ds_list instead anyway.
 
Last edited:
M

Misty

Guest
you don't need to conver the vertex buffer back to a regular buffer. The regular buffer still remains.
Hmm. Not sure what I'm doing wrong then because the moving objects won't leave a trail.

If I delete buffer_seek or change it to buffer_seek_end or buffer_seek_relative, the objects just won't move. If I put it to buffer_seek_start the objects will move, but no trail.
 
Last edited:
M

Misty

Guest
@Misty

can you describe exactly what you are intending to do?

Just want a decal system. I am using your example as a training grounds to do future 3d things. I made your objects move to prove that your code works Per Step. The next part I need to do is have them add their data to the buffer instead of erasing each time. If it is erased each step I can't use decals in games. Right now it refuses to draw trails and keeps erasing each step.

I put it to buffer_seek_relative and buffer_seek_end but then it is not updating the buffer at all for some odd reason. If I keep it to buffer_seek_start then it just draw the objects moving but no trail because it erases the old buffer data each step.


Wait nvm lol I forgot you clamped the buffer to too small a size lol. It is working now xD
 
M

Misty

Guest
@Misty do you mind me asking, do you have any idea what was causing the error message you were getting before? "Error vertex buffer does not exists"
Haven't the slightest idea, my code looked very similar to yours. One of these days I'll try and see if I can replicate the original problem.

Okay so I decided to look at it today...I still have no idea why my original code didn't work.

Basically in my Create event I had

global.v_buffer=buffer_create(1024*1024,buffer_wrap,1)

then in step I had

global.v_x=vertex_create_buffer_from_buffer(global.v_buffer, global.my_format);


Yet it keeps saying it doesn't "exists".
 
Last edited:
Top