1 | #ifndef __MATERIAL_H
|
---|
2 | #define __MATERIAL_H
|
---|
3 |
|
---|
4 | #include "glInterface.h"
|
---|
5 | #include "common.h"
|
---|
6 | #include "ShaderProgram.h"
|
---|
7 |
|
---|
8 |
|
---|
9 | namespace CHCDemoEngine
|
---|
10 | {
|
---|
11 |
|
---|
12 | class Texture;
|
---|
13 | class RenderState;
|
---|
14 | class GPUProgramParameters;
|
---|
15 | class ShaderProgram;
|
---|
16 | struct RenderQueueBucket;
|
---|
17 |
|
---|
18 |
|
---|
19 | /** Class representing an rgba color vector.
|
---|
20 | */
|
---|
21 | class RgbaColor
|
---|
22 | {
|
---|
23 |
|
---|
24 | public:
|
---|
25 |
|
---|
26 | RgbaColor(): r(1), g(1), b(1), a(1)
|
---|
27 | {}
|
---|
28 |
|
---|
29 | RgbaColor(float _r, float _g, float _b, float _a): r(_r), g(_g), b(_b), a(_a)
|
---|
30 | {}
|
---|
31 |
|
---|
32 | friend RgbaColor RandomColor(float a = 0.0f, float b = 1.0f);
|
---|
33 |
|
---|
34 |
|
---|
35 | /////////////////////
|
---|
36 |
|
---|
37 | float r, g, b, a;
|
---|
38 | };
|
---|
39 |
|
---|
40 |
|
---|
41 | // Forward declarations
|
---|
42 | RgbaColor RandomColor(float a, float b);
|
---|
43 |
|
---|
44 |
|
---|
45 | /** This class represents a certain rendering technique of a shape.
|
---|
46 | A material consists of one or more techniques
|
---|
47 | */
|
---|
48 | class Technique
|
---|
49 | {
|
---|
50 | friend class ResourceManager;
|
---|
51 | friend class RenderQueue;
|
---|
52 |
|
---|
53 | public:
|
---|
54 |
|
---|
55 | /** Sets default material (ambient intensity 0.2f, diffuse intensity 1.0f)
|
---|
56 | */
|
---|
57 | Technique();
|
---|
58 |
|
---|
59 | //Technique(const Technique &tech);
|
---|
60 | /** Sets ambient and diffuse color to color
|
---|
61 | */
|
---|
62 | Technique(const RgbaColor &color);
|
---|
63 |
|
---|
64 | ~Technique();
|
---|
65 | /** Renders this technique.
|
---|
66 | */
|
---|
67 | void Render(RenderState *state);
|
---|
68 | /** Initialize this technique material with default values
|
---|
69 | */
|
---|
70 | void Init();
|
---|
71 |
|
---|
72 | inline Texture *GetTexture() const { return mTexture; }
|
---|
73 |
|
---|
74 | inline RgbaColor GetAmbient() const { return mAmbientColor; }
|
---|
75 | inline RgbaColor GetDiffuse() const { return mDiffuseColor; }
|
---|
76 | inline RgbaColor GetSpecular() const { return mSpecularColor; }
|
---|
77 | inline RgbaColor GetEmmisive() const { return mEmmisiveColor; }
|
---|
78 |
|
---|
79 | inline void SetTexture(Texture *texture) { mTexture = texture; }
|
---|
80 |
|
---|
81 | inline void SetAmbient(const RgbaColor &color) { mAmbientColor = color; }
|
---|
82 | inline void SetDiffuse(const RgbaColor &color) { mDiffuseColor = color; }
|
---|
83 | inline void SetSpecular(const RgbaColor &color) { mSpecularColor = color; }
|
---|
84 | inline void SetEmmisive(const RgbaColor &color) { mEmmisiveColor = color; }
|
---|
85 |
|
---|
86 | inline void SetAlphaTestEnabled(bool alpha) { mAlphaTestEnabled = alpha; }
|
---|
87 | inline void SetCullFaceEnabled(bool cull) { mCullFaceEnabled = cull; }
|
---|
88 |
|
---|
89 | inline bool IsAlphaTestEnabled() const { return mAlphaTestEnabled; }
|
---|
90 | inline bool IsCullFaceEnabled() const { return mCullFaceEnabled; }
|
---|
91 |
|
---|
92 | inline void SetLightingEnabled(bool l) { mLightingEnabled = l; }
|
---|
93 | inline void SetColorWriteEnabled(bool c) { mColorWriteEnabled = c; }
|
---|
94 | inline void SetDepthWriteEnabled(bool d) { mDepthWriteEnabled = d; }
|
---|
95 |
|
---|
96 | inline bool IsLightingEnabled() const { return mLightingEnabled; }
|
---|
97 | inline bool IsColorWriteEnabled() const { return mColorWriteEnabled; }
|
---|
98 | inline bool IsDepthWriteEnabled() const { return mDepthWriteEnabled; }
|
---|
99 |
|
---|
100 | void SetFragmentProgram(ShaderProgram *p);
|
---|
101 | void SetVertexProgram(ShaderProgram *p);
|
---|
102 |
|
---|
103 | inline ShaderProgram *GetFragmentProgram() { return mFragmentProgram; }
|
---|
104 | inline ShaderProgram *GetVertexProgram() { return mVertexProgram; }
|
---|
105 |
|
---|
106 | /** Get the set of fragment parameters of this technique
|
---|
107 | */
|
---|
108 | GPUProgramParameters * const GetFragmentProgramParameters() { return &mFragmentProgramParameters; }
|
---|
109 | /** Get the set of vertex parameters of this technique
|
---|
110 | */
|
---|
111 | GPUProgramParameters * const GetVertexProgramParameters() { return &mVertexProgramParameters; }
|
---|
112 |
|
---|
113 | protected:
|
---|
114 |
|
---|
115 | ///////////
|
---|
116 |
|
---|
117 | RgbaColor mDiffuseColor;
|
---|
118 | RgbaColor mSpecularColor;
|
---|
119 | RgbaColor mAmbientColor;
|
---|
120 | RgbaColor mEmmisiveColor;
|
---|
121 |
|
---|
122 | bool mAlphaTestEnabled;
|
---|
123 | bool mCullFaceEnabled;
|
---|
124 | /// the associated texture
|
---|
125 | Texture *mTexture;
|
---|
126 |
|
---|
127 | GPUProgramParameters mVertexProgramParameters;
|
---|
128 | GPUProgramParameters mFragmentProgramParameters;
|
---|
129 |
|
---|
130 | ShaderProgram *mFragmentProgram;
|
---|
131 | ShaderProgram *mVertexProgram;
|
---|
132 | /// if this material can write colors
|
---|
133 | bool mColorWriteEnabled;
|
---|
134 | /// if lighting is used
|
---|
135 | bool mLightingEnabled;
|
---|
136 | /// if depth write is enabled
|
---|
137 | bool mDepthWriteEnabled;
|
---|
138 | /// pointer to the renderqueue bucket this entity belongs to
|
---|
139 | RenderQueueBucket *mRenderQueueBucket;
|
---|
140 | };
|
---|
141 |
|
---|
142 |
|
---|
143 | /** A material consists of one or more techniques.
|
---|
144 | */
|
---|
145 | class Material
|
---|
146 | {
|
---|
147 | public:
|
---|
148 | /** Default constructor creating one default technique.
|
---|
149 | */
|
---|
150 | Material();
|
---|
151 |
|
---|
152 | ~Material();
|
---|
153 | /** Renders this material.
|
---|
154 | */
|
---|
155 | void Render(RenderState *state);
|
---|
156 |
|
---|
157 | void AddTechnique(Technique *t);
|
---|
158 |
|
---|
159 | Technique *GetDefaultTechnique() const;
|
---|
160 |
|
---|
161 | Technique *GetTechnique(int i) const;
|
---|
162 |
|
---|
163 | int GetNumTechniques() const;
|
---|
164 |
|
---|
165 |
|
---|
166 |
|
---|
167 | protected:
|
---|
168 |
|
---|
169 | TechniqueContainer mTechniques;
|
---|
170 | };
|
---|
171 |
|
---|
172 | }
|
---|
173 |
|
---|
174 | #endif
|
---|