3
\$\begingroup\$

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.

\$\endgroup\$
16
  • \$\begingroup\$ You can also specify states in effects (.fx files). msdn.microsoft.com/en-us/library/windows/desktop/… \$\endgroup\$
    – Kikaimaru
    Commented Jun 6, 2013 at 15:06
  • \$\begingroup\$ ooh i didnt know that \$\endgroup\$ Commented Jun 6, 2013 at 16:44
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jun 6, 2013 at 17:30
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Jun 6, 2013 at 17:50
  • \$\begingroup\$ 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 ? \$\endgroup\$ Commented Jun 6, 2013 at 18:22

1 Answer 1

1
\$\begingroup\$

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .