Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Creating a static buffer that you can add/remove models to/from on the go

A topic by sindn created Dec 13, 2023 Views: 207 Replies: 1
Viewing posts 1 to 2
(4 edits)

I was wondering if it was possible to create a static buffer in the create event, and then add or remove models from the static buffer as needed. Sort of placing them in the buffer "on standby" when they don't need to be changed in any way. This would be great for performance.

Currently, if fauxton_model_add_static() is not called within the game step the buffer is created, the game creates an error popup window saying:

Win32 function failed: HRESULT: 0x80070057

Call: GR_D3D_Device->CreateBuffer at line 296 in file \VertexBuilderM.cpp

(I tracked this down to a vertex_freeze call in load_buffer_maps(), which if removed gives even more errors)

Also, can you give me some info on how to go about making a fauxton_model_REMOVE_static() function? That would be great!

TL;DR Basically I want to add/remove models from a static buffer whenever needed to massively boost performance

Thanks

(1 edit)

So the ability to 'remove' mesh data from a static buffer is a bit complex and not a feature I have implemented. This is because I do not have anything implemented that keeps track of not only where things are stored in the static buffer, but also how many bytes are stored for 1 particular instance, since all that building a static buffer does is add vertex positions on the fly. 

This is an intentional design decision because they are meant to be static, and thus not modified. You must build them when you create them or you will get an empty vertex buffer (the error you receive). 

This could also negatively impact performance because it would require re-creating the buffer without the element, and then re-building it from scratch as GM doesn't have a way to directly modify vertex buffers since vertex buffers are stored in GPU memory (this is why they are so efficient, because you don't modify them. haha). 

That said, you are free to add this functionality yourself if you wish! The __FauxtingWrite* functions are what is used to add data to vertex buffers. You could add some way to keep track of the byte position within a buffer and how many bytes the object adds to the buffer, and then use buffer_create_from_vertex_buffer(), copy the buffer up to that positions using buffer_copy, skip the number of bytes for a specific object, and append the copied buffer with another buffer_copy from that positions to the end of the buffer. 

Hopefully that makes sense. haha. Unfortunately there just isn't a simple way to handle doing something like this and the likelihood is that you would get massive frame drops while you wait for the program to de-build the vertex buffer, remove elements, and then re-build the buffer. haha.

 I hope this helps!