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