Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm currently working with a mesh class so I can easily create mesh objects. Now I want a draw function in my mesh class so when ever i want draw it to the screen I can just call it without any fuss. But i have run in to a dilema and i need some insperation/ other persons perspectiv. To draw a mesh object there is alot of thing you need. You need blend states, rasterizer state, depth stencils ect (lets call them "tools" for futher reference).

Now there is a couple of diffrent ways you can go about it and i wanted your input to choose one.

  1. You can have the object create their own tools. It requires more space, but you dont have to pass pointer around as much.

  2. You create the tools in the GameEngine object and pass pointers to the tools in the draw function parameters. It looks messy and could cost alot of time, but it take up less space.

  3. You create the tools in the GameEngine object and then store pointers to them in the mesh object. Now this save both time and space, however i got the feeling that this could get really messy and caus you alot of trouble easily.

I greatly appriceate any feedback or diffrent solutions. Thank in advance.

share|improve this question
    
You can also specify states in effects (.fx files). msdn.microsoft.com/en-us/library/windows/desktop/… –  Kikaimaru Jun 6 '13 at 15:06
    
ooh i didnt know that –  Fredrik Boston Westman Jun 6 '13 at 16:44
    
Normally these states are part of the material or part of the render pass and are not called "tools." Using the common vernacular might help you find better documentation when searching. –  Sean Middleditch Jun 6 '13 at 17:30
    
To amplify a bit on what Sean said: you usually have multiple meshes using the same material, and perhaps multiple materials using the same shader code with different textures etc. The render states don't belong to the object but rather to the shader, and the object would have a pointer to the material it uses, which would in turn have a pointer to its shader. See this question for more details. –  Nathan Reed Jun 6 '13 at 17:50
    
Sorry didnt have any better word for them. But if i get you rigth, your saying that rather then set each object with shaders ect. I should prepare diffrent sections of my code. Like one section where i draw transparant object, one for non transparant ect ? –  Fredrik Boston Westman Jun 6 '13 at 18:22

1 Answer 1

You are using Direct3D 11. So the only thing your mesh should be doing is setting up the Input Assembly stage and issuing some form of Draw call. So your mesh should only call IASetIndexBuffer, IASetInputLayout, IASetPrimitiveTopology, and IASetVertexBuffers, followed by one or more Draw* calls.

Everything else should be handled by whatever code called the mesh's draw function. A mesh is just a dumb collection of the vertex state needed to draw. Any higher-level logic (what shaders to use, blend modes, etc) should be handled outside of the mesh.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.