Jump to content

  • Log In with Google      Sign In   
  • Create Account


Meshes and the rendering api


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 KaiserJohan   Members   -  Reputation: 1126

Like
0Likes
Like

Posted 26 December 2012 - 06:31 PM

I am unsure how to structure my meshes without getting them tightly coupled with the underlying rendering API.
Say I have a class Mesh I intend to add to my scene object. My first instinct is to immediately buffer the mesh vertex data in its constructor using for example glBuffer objects in OpenGL, so I dont have to keep it all in my applications memory.

I am also puzzled what to expose to the renderer when I send a batch of meshes to be rendered. The way I imagine it is to simply expose a Render() method from the mesh which internally binds the VAO and draws the primitives... but then again it couples it with the graphics api.

From what I've read a good solution is to send it all in batch jobs to a dedicated rendering class that encapsulates the graphics api, which sounds good but how to structure the vertex data without touching the graphics api is abit unclear to me.

Edited by KaiserJohan, 26 December 2012 - 06:34 PM.


Sponsor:

#2 Burnt_Fyr   Members   -  Reputation: 1233

Like
2Likes
Like

Posted 26 December 2012 - 07:22 PM

I think you should first seperate the idea of geometry, buffers, and the game objects themselves.

 

Geometry is just that. A collection of verts and faces that make up some object. It is not the object itself, nor is it a buffer. It is just points and lines.

 

Buffers are render objects, they are behind the interface of your rendering system. You can have a buffer created from geometry, but again, it is not geometry in and of itself.

 

Your Game object is the higher level object in game or engine code.

 

Your game wants some entities, so it creates game objects, and adds them to the world. The objects have visual representations, so the geometry is loaded from a file. Since this process was started in the game code, it knows what formats are needed, and buffer objects can be created via the rendering system. (So the system has no idea about the game objects, yet can be told how to structure the buffer data). When you render the scene, the game objects Render method can pass game info such as what buffers are needed, what shaders and constants(transforms, lighting info, etc) to the rendering system. After the game objects have pushed their data, the renderer can make the draw calls, knowing how many of each object, where they are, which of them need shadows, etc using a batching system to reduce hangups.

 

Bear in mind that I have little to no idea of what i'm talking about on any professional level, only that i've been hobby developing for a few years.

 

TL,DR: Your render api should expose methods to create buffers, and draw them, and little more. Internally it can use information deduced from the draw calls to optimize for performance. In a sense, your meshes are tightly coupled to your render API, but they are also encapsulated, and this little detail helps reduce coupling from outside of the renderer, where games have little business doing stuff.



#3 Krohm   Crossbones+   -  Reputation: 3064

Like
2Likes
Like

Posted 27 December 2012 - 02:51 AM

I think you should first seperate the idea of geometry, buffers, and the game objects themselves.

Absolutely.

It's worth noticing that while meshes, are purely graphical objects (in the world of pretty demo land) in the real world, they are not.

At a minimum, they might feature a simplified collision hull.

Therefore, I think it's a good idea to actually model the mesh independently from the rendering. Such as having a MeshCreationParams and a Mesh structure, with the former being effectively the model and dealing with persistent representation.

From what I've read a good solution is to send it all in batch jobs to a dedicated rendering class that encapsulates the graphics api, which sounds good but how to structure the vertex data without touching the graphics api is abit unclear to me.

Of course those statements don't make sense by themselves, they take from granted we have some middle API to help us with those "batch jobs".

Personally I suggest you to not think about it too much. Use an explorative approach to better understand your needs and then rewrite.

Nobody, unless highly skilled, can figure out something useful. There are way too many variables to consider, especially when dealing with various hardware configurations. Don't be afraid of throwing away prototypes.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS