Jump to content
  • Advertisement
Sign in to follow this  
ElJoelio

OpenGL Renderer-independant mesh handling

This topic is 4794 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Herro I'm looking for ideas on abstracting renderer objects (mesh, texture, etc) from the renderer implementation that uses them (DirectX, OpenGL, etc). Here's my plan of attack, using a mesh as an example: I have a CMesh class that has a function, Load(std::string &strFilename), that will load a mesh from disk into a polygon list. This bit works fine - I have the mesh data loaded into the CMesh class. My application can access the mesh data and do whatever it needs to do to it, animate it, etc. The renderer, however, prefers the mesh data be locked away in video card memory somewhere and in a format specific to the renderer implementation, e.g. DirectX wants the data to be copied into a Vertex Buffer or similar. If the local mesh data gets updated, the renderer is notified that it needs to update its own copy. This is fine, but it essentially means the mesh data will exist in memory twice - once in the application-supported format and once in the renderer's format. Is this method OK? The main disadvantage is the mesh existing in memory twice (once in system RAM and once in the video card's RAM). I guess also that if the application doesn't need to access and alter the mesh data, then the local data could be freed after uploading to the renderer. Does anyone have other ways to acheive the overall goal of renderer-independant mesh handling? Thanks Joel Malone

Share this post


Link to post
Share on other sites
Advertisement
You can lock the mesh buffers in video memory and retrieve pointers to the index, vertex and attribute buffers whenever you want to manipulate the data, I'm not sure about timings, but you can test it and see. It would save you from having two copies of the mesh data.

As for the renderer specific resource handling, I would look into implementing some kind of abstract factory to control the creation of your objects. Try googling for abstract factory design pattern.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can have a CStaticMesh and a CDynamicMesh class where the first dumps everything in video memory while the other one is smarter and keeps a copy in system memory for quick updates. Both derive from a CBaseMesh class where the reading API is not defined; CDynamicMesh defines that API, but the CBaseMesh* is carried around in the scene DAG. Surely, when you load the scene data you must know what is static from what is going to be animated. Most games load the scenery data first and then the character models. The exception would be for fully destructible scenery where everything is pretty much dynamic. Therefore you would need to implement some sort of dirty flag where you need to 'page in' the vertex data out of the video card on demand and the CMesh class marks it as a R/W rather than a R/O class. The actual implementation of the CStaticMesh and CDynamicMesh classes would depend on the API being used. But at least the semantics is made at a higher level in the application.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!