/xbmc/visualizations/Vortex/VortexVis/Core/Shader.h

http://github.com/xbmc/xbmc · C Header · 136 lines · 95 code · 22 blank · 19 comment · 0 complexity · c9620d25c27453107820704e3765cc4b MD5 · raw file

  1. /*
  2. * Copyright Š 2010-2013 Team XBMC
  3. * http://xbmc.org
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #ifndef _SHADER_H_
  20. #define _SHADER_H_
  21. #include <vector>
  22. #include "d3dx9.h"
  23. #include "Renderer.h"
  24. enum EShaderType
  25. {
  26. ST_VERTEX,
  27. ST_PIXEL
  28. };
  29. #define DECLARE_SHADER(InShaderName) \
  30. public: \
  31. static InShaderName StaticType;
  32. #define IMPLEMENT_SHADER(ShaderName, ShaderSrc, ShaderType)\
  33. ShaderName ShaderName::StaticType = ShaderName( ShaderType, ShaderSrc );
  34. class Shader
  35. {
  36. public:
  37. Shader( EShaderType ShaderType, char* pShaderSrc ) :
  38. m_ShaderType( ShaderType ),
  39. m_pShaderSrc( pShaderSrc )
  40. {
  41. std::vector<Shader*>& ShaderList = GetShaderList();
  42. ShaderList.push_back( this );
  43. }
  44. static std::vector<Shader*>& GetShaderList()
  45. {
  46. static std::vector<Shader*> s_Shaders;
  47. return s_Shaders;
  48. }
  49. static bool CompileAllShaders();
  50. static void ReleaseAllShaders();
  51. LPDIRECT3DVERTEXSHADER9 GetVertexShader() { return m_pVShader; }
  52. LPDIRECT3DPIXELSHADER9 GetPixelShader() { return m_pPShader; }
  53. protected:
  54. EShaderType m_ShaderType;
  55. char* m_pShaderSrc;
  56. bool CompileShader();
  57. LPDIRECT3DVERTEXSHADER9 m_pVShader;
  58. LPDIRECT3DPIXELSHADER9 m_pPShader;
  59. LPD3DXCONSTANTTABLE m_pConstantTable;
  60. // LPDIRECT3DVERTEXDECLARATION9* m_ppVertexDecl;
  61. };
  62. class DiffuseUVVertexShader : public Shader
  63. {
  64. DECLARE_SHADER(DiffuseUVVertexShader);
  65. public:
  66. DiffuseUVVertexShader( EShaderType ShaderType, char* pShaderSrc ) : Shader( ShaderType, pShaderSrc ){};
  67. void SetWVP( D3DXMATRIX* pWVPMat )
  68. {
  69. Renderer::SetConstantTableMatrix( m_pConstantTable, "WVPMat", pWVPMat );
  70. }
  71. void SetWV( D3DXMATRIX* pWVMat )
  72. {
  73. Renderer::SetConstantTableMatrix( m_pConstantTable, "WVMat", pWVMat );
  74. }
  75. };
  76. class DiffuseUVEnvVertexShader : public DiffuseUVVertexShader
  77. {
  78. DECLARE_SHADER(DiffuseUVEnvVertexShader);
  79. public:
  80. DiffuseUVEnvVertexShader( EShaderType ShaderType, char* pShaderSrc ) : DiffuseUVVertexShader( ShaderType, pShaderSrc ){};
  81. };
  82. class DiffuseUVCubeVertexShader : public DiffuseUVVertexShader
  83. {
  84. DECLARE_SHADER(DiffuseUVCubeVertexShader);
  85. public:
  86. DiffuseUVCubeVertexShader( EShaderType ShaderType, char* pShaderSrc ) : DiffuseUVVertexShader( ShaderType, pShaderSrc ){};
  87. void SetScale( D3DXVECTOR4* pvScale )
  88. {
  89. Renderer::SetConstantTableVector( m_pConstantTable, "vScale", pvScale);
  90. }
  91. void SetColour( D3DXVECTOR4* pvCol )
  92. {
  93. Renderer::SetConstantTableVector( m_pConstantTable, "Col", pvCol);
  94. }
  95. };
  96. class DiffuseUVEnvCubeVertexShader : public DiffuseUVCubeVertexShader
  97. {
  98. DECLARE_SHADER(DiffuseUVEnvCubeVertexShader);
  99. public:
  100. DiffuseUVEnvCubeVertexShader( EShaderType ShaderType, char* pShaderSrc ) : DiffuseUVCubeVertexShader( ShaderType, pShaderSrc ){};
  101. };
  102. class DiffuseNormalEnvCubeVertexShader : public DiffuseUVCubeVertexShader
  103. {
  104. DECLARE_SHADER(DiffuseNormalEnvCubeVertexShader);
  105. public:
  106. DiffuseNormalEnvCubeVertexShader( EShaderType ShaderType, char* pShaderSrc ) : DiffuseUVCubeVertexShader( ShaderType, pShaderSrc ){};
  107. };
  108. class UVNormalEnvVertexShader : public DiffuseUVVertexShader
  109. {
  110. DECLARE_SHADER(UVNormalEnvVertexShader);
  111. public:
  112. UVNormalEnvVertexShader( EShaderType ShaderType, char* pShaderSrc ) : DiffuseUVVertexShader( ShaderType, pShaderSrc ){};
  113. };
  114. #endif _SHADER_H_