Pyrogenesis  trunk
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 
22 #include "lib/ogl.h"
23 
24 /**
25  * Implements a render pass consisting of various GL state changes and a shader,
26  * used by CShaderTechnique.
27  */
29 {
30 public:
31  CShaderPass();
32 
33  /**
34  * Set the shader program used for rendering with this pass.
35  */
36  void SetShader(const CShaderProgramPtr& shader) { m_Shader = shader; }
37 
38  // Add various bits of GL state to the pass:
39  void AlphaFunc(GLenum func, GLclampf ref);
40  void BlendFunc(GLenum src, GLenum dst);
41  void ColorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a);
42  void DepthMask(GLboolean mask);
43  void DepthFunc(GLenum func);
44 
45  /**
46  * Set up all the GL state that was previously specified on this pass.
47  */
48  void Bind();
49 
50  /**
51  * Reset the GL state to the default.
52  */
53  void Unbind();
54 
55  const CShaderProgramPtr& GetShader() const { return m_Shader; }
56 
57 private:
59 
60  bool m_HasAlpha;
61  GLenum m_AlphaFunc;
62  GLclampf m_AlphaRef;
63 
64  bool m_HasBlend;
65  GLenum m_BlendSrc;
66  GLenum m_BlendDst;
67 
69  GLboolean m_ColorMaskR;
70  GLboolean m_ColorMaskG;
71  GLboolean m_ColorMaskB;
72  GLboolean m_ColorMaskA;
73 
75  GLboolean m_DepthMask;
76 
78  GLenum m_DepthFunc;
79 };
80 
81 /**
82  * Implements a render technique consisting of a sequence of passes.
83  * CShaderManager loads these from shader effect XML files.
84  */
86 {
87 public:
89  void AddPass(const CShaderPass& pass);
90 
91  int GetNumPasses() const;
92 
93  void BeginPass(int pass = 0);
94  void EndPass(int pass = 0);
95  const CShaderProgramPtr& GetShader(int pass = 0) const;
96 
97  /**
98  * Whether this technique uses alpha blending that requires objects to be
99  * drawn from furthest to nearest.
100  */
101  bool GetSortByDistance() const;
102 
103  void SetSortByDistance(bool enable);
104 
105  void Reset();
106 
107 private:
108  std::vector<CShaderPass> m_Passes;
109 
111 };
112 
113 typedef shared_ptr<CShaderTechnique> CShaderTechniquePtr;
114 
115 #endif // INCLUDED_SHADERTECHNIQUE
bool m_HasBlend
Definition: ShaderTechnique.h:64
void Bind()
Set up all the GL state that was previously specified on this pass.
Definition: ShaderTechnique.cpp:29
bool m_HasAlpha
Definition: ShaderTechnique.h:60
void AlphaFunc(GLenum func, GLclampf ref)
Definition: ShaderTechnique.cpp:81
GLclampf m_AlphaRef
Definition: ShaderTechnique.h:62
shared_ptr< CShaderTechnique > CShaderTechniquePtr
Definition: ShaderTechnique.h:113
bool m_HasColorMask
Definition: ShaderTechnique.h:68
GLboolean m_ColorMaskA
Definition: ShaderTechnique.h:72
GLenum m_BlendSrc
Definition: ShaderTechnique.h:65
void ColorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a)
Definition: ShaderTechnique.cpp:95
GLboolean m_DepthMask
Definition: ShaderTechnique.h:75
CShaderProgramPtr m_Shader
Definition: ShaderTechnique.h:58
Implements a render pass consisting of various GL state changes and a shader, used by CShaderTechniqu...
Definition: ShaderTechnique.h:28
bool m_HasDepthFunc
Definition: ShaderTechnique.h:77
void BlendFunc(GLenum src, GLenum dst)
Definition: ShaderTechnique.cpp:88
GLboolean m_ColorMaskG
Definition: ShaderTechnique.h:70
bool m_HasDepthMask
Definition: ShaderTechnique.h:74
const CShaderProgramPtr & GetShader() const
Definition: ShaderTechnique.h:55
GLenum m_DepthFunc
Definition: ShaderTechnique.h:78
GLenum m_AlphaFunc
Definition: ShaderTechnique.h:61
Implements a render technique consisting of a sequence of passes.
Definition: ShaderTechnique.h:85
GLenum m_BlendDst
Definition: ShaderTechnique.h:66
void DepthFunc(GLenum func)
Definition: ShaderTechnique.cpp:110
void DepthMask(GLboolean mask)
Definition: ShaderTechnique.cpp:104
CShaderPass()
Definition: ShaderTechnique.cpp:24
GLboolean m_ColorMaskB
Definition: ShaderTechnique.h:71
void SetShader(const CShaderProgramPtr &shader)
Set the shader program used for rendering with this pass.
Definition: ShaderTechnique.h:36
bool m_SortByDistance
Definition: ShaderTechnique.h:110
GLboolean m_ColorMaskR
Definition: ShaderTechnique.h:69
std::vector< CShaderPass > m_Passes
Definition: ShaderTechnique.h:108
std::shared_ptr< CShaderProgram > CShaderProgramPtr
Definition: ShaderProgramPtr.h:25
void Unbind()
Reset the GL state to the default.
Definition: ShaderTechnique.cpp:59