How best to handle ID3D11InputLayout in rendering code?
Posted
by
JohnB
on Game Development
See other posts from Game Development
or by JohnB
Published on 2012-03-12T09:21:17Z
Indexed on
2012/06/26
21:26 UTC
Read the original article
Hit count: 416
directx11
I'm looking for an elegant way to handle input layouts in my directx11 code.
The problem I have that I have an Effect class and a Element class. The effect class encapsulates shaders and similar settings, and the Element class contains something that can be drawn (3d model, lanscape etc)
My drawing code sets the device shaders etc using the effect specified and then calls the draw function of the Element to draw the actual geometry contained in it.
The problem is this - I need to create an D3D11InputLayout somewhere. This really belongs in the Element class as it's no business of the rest of the system how that element chooses to represent it's vertex layout. But in order to create the object the API requires the vertex shader bytecode for the vertex shader that will be used to draw the object. In directx9 it was easy, there was no dependency so my element could contain it's own input layout structures and set them without the effect being involved.
But the Element shouldn't really have to know anything about the effect that it's being drawn with, that's just render settings, and the Element is there to provide geometry.
So I don't really know where to store and how to select the InputLayout for each draw call. I mean, I've made something work but it seems very ugly.
This makes me thing I've either missed something obvious, or else my design of having all the render settings in an Effect, the Geometry in an Element, and a 3rd party that draws it all is just flawed.
Just wondering how anyone else handles their input layouts in directx11 in a elegant way?
© Game Development or respective owner