Sign in to follow this  
Phobon

[DX10] Input Layouts - how do you manage them?

Recommended Posts

Hi! I'm currently porting my old engine to DX10. Now, my InputLayout-class used to be (basically) just a container of the VertexDeclaration with an Apply() function. As in DX10 every InputLayout must be linked to the shader, I'm struggling to find an elegant solution to encapsulating this behaviour. Now there's two approaches I'm currently considering: 1) Each CInputLayout stores one [i]ID3D10InputLayout[i] for every pass in those effects it is used in. (Possibly in an associative array?) 2) A dedicated manager creates ID3D10InputLayouts for any needed Layout-shader-combination. Now I could do this like CInputLayout.Apply(Shader); with CInputLayou having pointers to the manager-created layouts -or- I could have the manager apply them via Manager->Apply(Layout, Shader); 3) some truly elegant way I don't see. So, which way would you prefer in terms of good OO design? Any other ideas? How do you manage and encapsulate the new InputLayouts in your engines? Thanks for any ideas and advice!

Share this post


Link to post
Share on other sites
I settled on creating quite a few different input layouts (like 6 or so) and making a dummy shader with all the various vertex shader input structs. You can also put these vertex shader input structs in a global fx header file that is included in other fx files so your shaders only use those formats. That seemed to work pretty well for me. I think you could also use shader reflection via the ID3D10ShaderReflection interface, but unless you need to work with any type of input layout, I think it might be too much work.

I then store a pointer to an input layout on a per mesh basis, since you need the input layout when rendering. You could choose this at load time based on the vertex layout of your mesh's vertex buffer.

I don't claim this is the 'best' way to do things, but it seems Hellgate London uses a similar approach (see: pg 61 of http://developer.download.nvidia.com/presentations/2007/gdc/UsingD3D10Now.pdf). There are probably much more elegant ways, but this method is pretty simple and easy to implement.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this