PageRenderTime 45ms CodeModel.GetById 19ms app.highlight 20ms RepoModel.GetById 1ms app.codeStats 1ms

/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
 20#ifndef _SHADER_H_
 21#define _SHADER_H_
 22
 23#include <vector>
 24#include "d3dx9.h"
 25#include "Renderer.h"
 26
 27enum EShaderType
 28{
 29	ST_VERTEX,
 30	ST_PIXEL
 31};
 32
 33#define DECLARE_SHADER(InShaderName) \
 34	public: \
 35	static	InShaderName StaticType;
 36
 37#define IMPLEMENT_SHADER(ShaderName, ShaderSrc, ShaderType)\
 38	ShaderName ShaderName::StaticType = ShaderName( ShaderType, ShaderSrc );
 39
 40class Shader
 41{
 42public:
 43	Shader( EShaderType ShaderType, char* pShaderSrc ) :
 44		m_ShaderType( ShaderType ),
 45		m_pShaderSrc( pShaderSrc )
 46		{
 47			std::vector<Shader*>&  ShaderList = GetShaderList();
 48			ShaderList.push_back( this );
 49		}
 50
 51		static std::vector<Shader*>& GetShaderList()
 52		{
 53			static std::vector<Shader*> s_Shaders;
 54			return s_Shaders;
 55		}
 56
 57		static bool CompileAllShaders();
 58		static void ReleaseAllShaders();
 59
 60		LPDIRECT3DVERTEXSHADER9	GetVertexShader() { return m_pVShader; }
 61		LPDIRECT3DPIXELSHADER9	GetPixelShader() { return m_pPShader; }
 62
 63protected:
 64	EShaderType	m_ShaderType;
 65	char* m_pShaderSrc;
 66
 67	bool CompileShader();
 68
 69 	LPDIRECT3DVERTEXSHADER9	m_pVShader;
 70	LPDIRECT3DPIXELSHADER9	m_pPShader;
 71	LPD3DXCONSTANTTABLE m_pConstantTable;
 72//	LPDIRECT3DVERTEXDECLARATION9* m_ppVertexDecl;
 73};
 74
 75class DiffuseUVVertexShader : public Shader
 76{
 77	DECLARE_SHADER(DiffuseUVVertexShader);
 78public:
 79	DiffuseUVVertexShader( EShaderType ShaderType, char* pShaderSrc ) : Shader( ShaderType, pShaderSrc ){};
 80
 81	void SetWVP( D3DXMATRIX* pWVPMat )
 82	{
 83		Renderer::SetConstantTableMatrix( m_pConstantTable, "WVPMat", pWVPMat );
 84	}
 85	void SetWV( D3DXMATRIX* pWVMat )
 86	{
 87		Renderer::SetConstantTableMatrix( m_pConstantTable, "WVMat", pWVMat );
 88	}
 89};
 90
 91class DiffuseUVEnvVertexShader : public DiffuseUVVertexShader
 92{
 93	DECLARE_SHADER(DiffuseUVEnvVertexShader);
 94public:
 95	DiffuseUVEnvVertexShader( EShaderType ShaderType, char* pShaderSrc ) : DiffuseUVVertexShader( ShaderType, pShaderSrc ){};
 96};
 97
 98class DiffuseUVCubeVertexShader : public DiffuseUVVertexShader
 99{
100	DECLARE_SHADER(DiffuseUVCubeVertexShader);
101public:
102	DiffuseUVCubeVertexShader( EShaderType ShaderType, char* pShaderSrc ) : DiffuseUVVertexShader( ShaderType, pShaderSrc ){};
103
104	void SetScale( D3DXVECTOR4* pvScale )
105	{
106		Renderer::SetConstantTableVector( m_pConstantTable, "vScale", pvScale);
107	}
108	void SetColour( D3DXVECTOR4* pvCol )
109	{
110		Renderer::SetConstantTableVector( m_pConstantTable, "Col", pvCol);
111	}
112
113};
114
115class DiffuseUVEnvCubeVertexShader : public DiffuseUVCubeVertexShader
116{
117	DECLARE_SHADER(DiffuseUVEnvCubeVertexShader);
118public:
119	DiffuseUVEnvCubeVertexShader( EShaderType ShaderType, char* pShaderSrc ) : DiffuseUVCubeVertexShader( ShaderType, pShaderSrc ){};
120};
121
122class DiffuseNormalEnvCubeVertexShader : public DiffuseUVCubeVertexShader
123{
124	DECLARE_SHADER(DiffuseNormalEnvCubeVertexShader);
125public:
126	DiffuseNormalEnvCubeVertexShader( EShaderType ShaderType, char* pShaderSrc ) : DiffuseUVCubeVertexShader( ShaderType, pShaderSrc ){};
127};
128
129class UVNormalEnvVertexShader : public DiffuseUVVertexShader
130{
131	DECLARE_SHADER(UVNormalEnvVertexShader);
132public:
133	UVNormalEnvVertexShader( EShaderType ShaderType, char* pShaderSrc ) : DiffuseUVVertexShader( ShaderType, pShaderSrc ){};
134};
135
136#endif _SHADER_H_