I'm creating a small framework of classes to manage pixel and vertex shaders outside of the Direct3D effects framework. Later I'll create classes that will do the same within the confines of the effects framework.
My design issue is this:
Should I create an object called CShader which encapsulates both a CPixelShader and CVertexShader object or should I just leave the two classes as they are?
Not every vertex shader will have a pixel shader but most will. My idea was to place pointers in CShader and then create functions for pixel and vertex shaders which access the pointers.
Then I was going to create a shader collection class which would manage a collection of CShader objects. The shaders would be compiled by calling CShaderMgr::CompileAll() which would then create the IDirect3DVertexShader9 and IDirect3DPixelShader9 interfaces in the CShader collection for later use. Setting a vertex or pixel shader would be as simple as calling CShader::GetPixelShader() or CShader::GetVertexShader() and passing those objects to IDirect3DDevice9::SetPixelShader() and IDirect3DDevice9::SetVertexShader().
Any ideas as to how I should or shouldn't structure this?
Current structure idea:
CShader
- CVertexShader
- -CVertexShader.h
- -CVertexShader.cpp
- CPixelShader
- - CPixelShader.h
CShaderMgr
- std::map<DWORD,CShader *> m_mapShaders;
Sample code:
Code:#pragma once //CVertexShader.h //Encapsulates a vertex shader #include <d3dx9.h> #include "dxutil.h" class CVertexShader { //Shared pointers IDirect3DDevice9 *m_spDevice; //Owned pointers IDirect3DVertexDeclaration9 *m_pVertexDec; IDirect3DVertexShader9 *m_pVSH; ID3DXConstantTable *m_pConstantTable; ID3DXBuffer *m_pShaderCode; ID3DXBuffer *m_pErrorBuf; public: CVertexShader(IDirect3DDevice9 *pDevice): m_spDevice(pDevice),m_pVertexDec(NULL),m_pVSH(NULL),m_pConstantTable(NULL), m_pShaderCode(NULL),m_pErrorBuf(NULL) { } virtual ~CVertexShader() { SAFE_RELEASE(m_pVertexDec); SAFE_RELEASE(m_pVSH); SAFE_RELEASE(m_pConstantTable); SAFE_RELEASE(m_pShaderCode); SAFE_RELEASE(m_pErrorBuf); } //Vertex declaration functions HRESULT CreateVertexDeclaration(CONST D3DVERTEXELEMENT9 *pElements); IDirect3DVertexDeclaration9 *GetVertexDeclaration() { return m_pVertexDec; } HRESULT CompileFromFile(LPCSTR pSrcFile, CONST D3DXMACRO *pDefines, LPD3DXINCLUDE pIncludes, LPCSTR pFunctionName, LPCSTR pTarget, DWORD dwFlags); //Constant table access ID3DXConstantTable *GetConstantTable() {return m_pConstantTable;} //Shader code access ID3DXBuffer *GetShaderCode() {return m_pShaderCode;} //Shader error buffer access ID3DXBuffer *GetErrorBuf() {return m_pErrorBuf;} //Vertex shader object access IDirect3DVertexShader9 *m_pGetVertexShader() {return m_pVSH;} };



LinkBack URL
About LinkBacks


