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(const Technique &tech);
|
---|
58 |
|
---|
59 | ~Technique();
|
---|
60 | /** Sets ambient and diffuse color to color
|
---|
61 | */
|
---|
62 | Technique(const RgbaColor &color);
|
---|
63 |
|
---|
64 | inline Texture *GetTexture() const { return mTexture; }
|
---|
65 |
|
---|
66 | inline RgbaColor GetAmbient() const { return mAmbientColor; }
|
---|
67 | inline RgbaColor GetDiffuse() const { return mDiffuseColor; }
|
---|
68 | inline RgbaColor GetSpecular() const { return mSpecularColor; }
|
---|
69 | inline RgbaColor GetEmmisive() const { return mEmmisiveColor; }
|
---|
70 |
|
---|
71 | inline void SetTexture(Texture *texture) { mTexture = texture; }
|
---|
72 |
|
---|
73 | inline void SetAmbient(const RgbaColor &color) { mAmbientColor = color; }
|
---|
74 | inline void SetDiffuse(const RgbaColor &color) { mDiffuseColor = color; }
|
---|
75 | inline void SetSpecular(const RgbaColor &color) { mSpecularColor = color; }
|
---|
76 | inline void SetEmmisive(const RgbaColor &color) { mEmmisiveColor = color; }
|
---|
77 |
|
---|
78 | inline void SetAlphaTestEnabled(bool alpha) { mAlphaTestEnabled = alpha; }
|
---|
79 | inline void SetCullFaceEnabled(bool cull) { mCullFaceEnabled = cull; }
|
---|
80 |
|
---|
81 | inline bool IsAlphaTestEnabled() const { return mAlphaTestEnabled; }
|
---|
82 | inline bool IsCullFaceEnabled() const { return mCullFaceEnabled; }
|
---|
83 | /** Renders this technique.
|
---|
84 | */
|
---|
85 | void Render(RenderState *state);
|
---|
86 | /** Initialize the material with default values
|
---|
87 | */
|
---|
88 | void InitMaterial();
|
---|
89 |
|
---|
90 | void SetFragmentProgram(ShaderProgram *p);
|
---|
91 | void SetVertexProgram(ShaderProgram *p);
|
---|
92 |
|
---|
93 | ShaderProgram *GetFragmentProgram() { return mFragmentProgram; }
|
---|
94 | ShaderProgram *GetVertexProgram() { return mVertexProgram; }
|
---|
95 |
|
---|
96 | //void SetFragmentProgramParameters(const GPUProgramParameters &p) { mGPUFragmentParameters = p; }
|
---|
97 | //void SetVertexProgramParameters(const GPUProgramParameters &p) { mGPUVertexParameters = p; }
|
---|
98 |
|
---|
99 | /** Each technique has a distict set of parameters.
|
---|
100 | */
|
---|
101 | GPUProgramParameters * const GetFragmentProgramParameters() { return &mFragmentProgramParameters; }
|
---|
102 | GPUProgramParameters * const GetVertexProgramParameters() { return &mVertexProgramParameters; }
|
---|
103 |
|
---|
104 |
|
---|
105 | protected:
|
---|
106 |
|
---|
107 | ///////////
|
---|
108 |
|
---|
109 | RgbaColor mDiffuseColor;
|
---|
110 | RgbaColor mSpecularColor;
|
---|
111 | RgbaColor mAmbientColor;
|
---|
112 | RgbaColor mEmmisiveColor;
|
---|
113 |
|
---|
114 | bool mAlphaTestEnabled;
|
---|
115 | bool mCullFaceEnabled;
|
---|
116 | /// the associated texture
|
---|
117 | Texture *mTexture;
|
---|
118 |
|
---|
119 | GPUProgramParameters mVertexProgramParameters;
|
---|
120 | GPUProgramParameters mFragmentProgramParameters;
|
---|
121 |
|
---|
122 | ShaderProgram *mFragmentProgram;
|
---|
123 | ShaderProgram *mVertexProgram;
|
---|
124 | };
|
---|
125 |
|
---|
126 |
|
---|
127 | /** A material consists of one or more techniques.
|
---|
128 | */
|
---|
129 | class Material
|
---|
130 | {
|
---|
131 | public:
|
---|
132 | /** Default constructor creating one default technique.
|
---|
133 | */
|
---|
134 | Material();
|
---|
135 |
|
---|
136 | ~Material();
|
---|
137 | /** Renders this material.
|
---|
138 | */
|
---|
139 | void Render(RenderState *state);
|
---|
140 |
|
---|
141 | void AddTechnique(Technique *t);
|
---|
142 |
|
---|
143 | Technique *GetDefaultTechnique() const;
|
---|
144 |
|
---|
145 | Technique *GetTechnique(int i) const;
|
---|
146 |
|
---|
147 | int GetNumTechniques() const;
|
---|
148 |
|
---|
149 |
|
---|
150 |
|
---|
151 | protected:
|
---|
152 |
|
---|
153 | TechniqueContainer mTechniques;
|
---|
154 | };
|
---|
155 |
|
---|
156 | }
|
---|
157 |
|
---|
158 | #endif
|
---|