| 1 | #pragma once
|
|---|
| 2 |
|
|---|
| 3 | #define D3D_DEBUG_INFO
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 | #include <d3d9.h>
|
|---|
| 7 | #include <DxErr.h>
|
|---|
| 8 | #include <d3dx9.h>
|
|---|
| 9 | #include <map>
|
|---|
| 10 | #include <stdint.h>
|
|---|
| 11 | /**
|
|---|
| 12 | * A vertex shader containing the shader and a
|
|---|
| 13 | * declaration of our vertex structure
|
|---|
| 14 | */
|
|---|
| 15 | class CD3D9VertexShader
|
|---|
| 16 | {
|
|---|
| 17 | public:
|
|---|
| 18 | CD3D9VertexShader()
|
|---|
| 19 | {
|
|---|
| 20 | vertexDeclaration = NULL;
|
|---|
| 21 | vertexShader = NULL;
|
|---|
| 22 | }
|
|---|
| 23 | friend class CD3D9ShaderList;
|
|---|
| 24 | protected:
|
|---|
| 25 | /**
|
|---|
| 26 | * Vertex declaration for this particular shader
|
|---|
| 27 | */
|
|---|
| 28 | IDirect3DVertexDeclaration9 * vertexDeclaration;
|
|---|
| 29 | /**
|
|---|
| 30 | * Pointer to our actual vertex shader
|
|---|
| 31 | */
|
|---|
| 32 | IDirect3DVertexShader9 * vertexShader;
|
|---|
| 33 | /**
|
|---|
| 34 | * Pointer to the vertex shader's constants
|
|---|
| 35 | */
|
|---|
| 36 | ID3DXConstantTable * vertexShaderConstants;
|
|---|
| 37 | };
|
|---|
| 38 |
|
|---|
| 39 | struct shaderKeyCompareFunc
|
|---|
| 40 | {
|
|---|
| 41 | bool operator() (const uint32_t& lhs, const uint32_t& rhs) const
|
|---|
| 42 | {
|
|---|
| 43 | return lhs<rhs;
|
|---|
| 44 | }
|
|---|
| 45 | };
|
|---|
| 46 |
|
|---|
| 47 | /**
|
|---|
| 48 | * A pixel shader
|
|---|
| 49 | */
|
|---|
| 50 | class CD3D9PixelShader
|
|---|
| 51 | {
|
|---|
| 52 | public:
|
|---|
| 53 | CD3D9PixelShader()
|
|---|
| 54 | {
|
|---|
| 55 | pixelShader = NULL;
|
|---|
| 56 | pixelShaderConstants = NULL;
|
|---|
| 57 | }
|
|---|
| 58 | friend class CD3D9ShaderList;
|
|---|
| 59 | protected:
|
|---|
| 60 | /**
|
|---|
| 61 | * Pointer to our actual pixel shader
|
|---|
| 62 | */
|
|---|
| 63 | IDirect3DPixelShader9 * pixelShader;
|
|---|
| 64 | /**
|
|---|
| 65 | * Pointer to our pixel shader's constants
|
|---|
| 66 | */
|
|---|
| 67 | ID3DXConstantTable * pixelShaderConstants;
|
|---|
| 68 | };
|
|---|
| 69 | /**
|
|---|
| 70 | * Our Direct3D 9 shader list
|
|---|
| 71 | */
|
|---|
| 72 | class CD3D9ShaderList
|
|---|
| 73 | {
|
|---|
| 74 | protected:
|
|---|
| 75 | IDirect3DDevice9 * lpD3D9Device;
|
|---|
| 76 | /**
|
|---|
| 77 | * List of vertex shaders
|
|---|
| 78 | */
|
|---|
| 79 | std::map<uint32_t,CD3D9VertexShader *,shaderKeyCompareFunc> vertexShaders;
|
|---|
| 80 | /**
|
|---|
| 81 | * List of pixel shaders
|
|---|
| 82 | */
|
|---|
| 83 | std::map<uint32_t,CD3D9PixelShader *,shaderKeyCompareFunc> pixelShaders;
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 | public:
|
|---|
| 87 | CD3D9ShaderList(void);
|
|---|
| 88 | ~CD3D9ShaderList(void);
|
|---|
| 89 |
|
|---|
| 90 | void InitialiseShaderList(IDirect3DDevice9 * device);
|
|---|
| 91 |
|
|---|
| 92 | void CreateVertexShader(LPCSTR shaderPath,uint32_t shaderID,D3DVERTEXELEMENT9 * vertexElementDeclaration);
|
|---|
| 93 | void CreatePixelShader(LPCSTR shaderPath, uint32_t shaderID);
|
|---|
| 94 |
|
|---|
| 95 | void SetVertexShaderViewProjectionMatrix(D3DXMATRIX * viewProj, uint32_t shaderID);
|
|---|
| 96 | void SetVertexShaderModelMatrix(D3DXMATRIX * model, uint32_t shaderID);
|
|---|
| 97 |
|
|---|
| 98 | CD3D9VertexShader * GetVertexShader(uint32_t shaderID);
|
|---|
| 99 | CD3D9PixelShader * GetPixelShader(uint32_t shaderID);
|
|---|
| 100 |
|
|---|
| 101 | void SetShaderAndVertexDeclaration(uint16_t shaderID);
|
|---|
| 102 |
|
|---|
| 103 | friend class CD3D9VertexShader;
|
|---|
| 104 | friend class CD3D9PixelShader;
|
|---|
| 105 | };
|
|---|
| 106 |
|
|---|