Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ShaderTechnique.h
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_SHADERTECHNIQUE
19 #define INCLUDED_SHADERTECHNIQUE
20 
21 #include "graphics/ShaderProgram.h"
22 
23 /**
24  * Implements a render pass consisting of various GL state changes and a shader,
25  * used by CShaderTechnique.
26  */
28 {
29 public:
30  CShaderPass();
31 
32  /**
33  * Set the shader program used for rendering with this pass.
34  */
35  void SetShader(const CShaderProgramPtr& shader) { m_Shader = shader; }
36 
37  // Add various bits of GL state to the pass:
38  void AlphaFunc(GLenum func, GLclampf ref);
39  void BlendFunc(GLenum src, GLenum dst);
40  void ColorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a);
41  void DepthMask(GLboolean mask);
42  void DepthFunc(GLenum func);
43 
44  /**
45  * Set up all the GL state that was previously specified on this pass.
46  */
47  void Bind();
48 
49  /**
50  * Reset the GL state to the default.
51  */
52  void Unbind();
53 
54  const CShaderProgramPtr& GetShader() const { return m_Shader; }
55 
56 private:
58 
59  bool m_HasAlpha;
60  GLenum m_AlphaFunc;
61  GLclampf m_AlphaRef;
62 
63  bool m_HasBlend;
64  GLenum m_BlendSrc;
65  GLenum m_BlendDst;
66 
68  GLboolean m_ColorMaskR;
69  GLboolean m_ColorMaskG;
70  GLboolean m_ColorMaskB;
71  GLboolean m_ColorMaskA;
72 
74  GLboolean m_DepthMask;
75 
77  GLenum m_DepthFunc;
78 };
79 
80 /**
81  * Implements a render technique consisting of a sequence of passes.
82  * CShaderManager loads these from shader effect XML files.
83  */
85 {
86 public:
88  void AddPass(const CShaderPass& pass);
89 
90  int GetNumPasses() const;
91 
92  void BeginPass(int pass = 0);
93  void EndPass(int pass = 0);
94  const CShaderProgramPtr& GetShader(int pass = 0) const;
95 
96  /**
97  * Whether this technique uses alpha blending that requires objects to be
98  * drawn from furthest to nearest.
99  */
100  bool GetSortByDistance() const;
101 
102  void SetSortByDistance(bool enable);
103 
104  void Reset();
105 
106 private:
107  std::vector<CShaderPass> m_Passes;
108 
110 };
111 
112 typedef shared_ptr<CShaderTechnique> CShaderTechniquePtr;
113 
114 #endif // INCLUDED_SHADERTECHNIQUE
void Bind()
Set up all the GL state that was previously specified on this pass.
void AlphaFunc(GLenum func, GLclampf ref)
void BeginPass(int pass=0)
GLclampf m_AlphaRef
const CShaderProgramPtr & GetShader(int pass=0) const
shared_ptr< CShaderTechnique > CShaderTechniquePtr
void SetSortByDistance(bool enable)
GLboolean m_ColorMaskA
GLenum m_BlendSrc
void ColorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a)
GLboolean m_DepthMask
CShaderProgramPtr m_Shader
Implements a render pass consisting of various GL state changes and a shader, used by CShaderTechniqu...
bool GetSortByDistance() const
Whether this technique uses alpha blending that requires objects to be drawn from furthest to nearest...
void BlendFunc(GLenum src, GLenum dst)
GLboolean m_ColorMaskG
void EndPass(int pass=0)
const CShaderProgramPtr & GetShader() const
GLenum m_DepthFunc
GLenum m_AlphaFunc
Implements a render technique consisting of a sequence of passes.
GLenum m_BlendDst
int GetNumPasses() const
void DepthFunc(GLenum func)
void DepthMask(GLboolean mask)
GLboolean m_ColorMaskB
void AddPass(const CShaderPass &pass)
void SetShader(const CShaderProgramPtr &shader)
Set the shader program used for rendering with this pass.
GLboolean m_ColorMaskR
shared_ptr< CShaderProgram > CShaderProgramPtr
std::vector< CShaderPass > m_Passes
void Unbind()
Reset the GL state to the default.