[2747] | 1 | #ifndef __MATERIAL_H
|
---|
| 2 | #define __MATERIAL_H
|
---|
| 3 |
|
---|
[2819] | 4 | #include "glInterface.h"
|
---|
[2795] | 5 | #include "common.h"
|
---|
[3045] | 6 | #include "ShaderProgram.h"
|
---|
[2747] | 7 |
|
---|
[2795] | 8 |
|
---|
[2776] | 9 | namespace CHCDemoEngine
|
---|
[2751] | 10 | {
|
---|
[2747] | 11 |
|
---|
[2756] | 12 | class Texture;
|
---|
[2769] | 13 | class RenderState;
|
---|
[3034] | 14 | class GPUProgramParameters;
|
---|
| 15 | class ShaderProgram;
|
---|
[2755] | 16 |
|
---|
[2769] | 17 |
|
---|
[3042] | 18 | /** Class representing an rgba color vector.
|
---|
| 19 | */
|
---|
[2769] | 20 | class RgbaColor
|
---|
[2747] | 21 | {
|
---|
[2755] | 22 |
|
---|
[2747] | 23 | public:
|
---|
[2755] | 24 |
|
---|
[2769] | 25 | RgbaColor(): r(1), g(1), b(1), a(1)
|
---|
| 26 | {}
|
---|
[2747] | 27 |
|
---|
[2769] | 28 | RgbaColor(float _r, float _g, float _b, float _a): r(_r), g(_g), b(_b), a(_a)
|
---|
| 29 | {}
|
---|
[2747] | 30 |
|
---|
[2769] | 31 | friend RgbaColor RandomColor(float a = 0.0f, float b = 1.0f);
|
---|
[3045] | 32 |
|
---|
| 33 |
|
---|
| 34 | /////////////////////
|
---|
| 35 |
|
---|
| 36 | float r, g, b, a;
|
---|
[2747] | 37 | };
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | // Forward declarations
|
---|
[2769] | 41 | RgbaColor RandomColor(float a, float b);
|
---|
[2747] | 42 |
|
---|
| 43 |
|
---|
[3042] | 44 | /** This class represents a certain rendering technique of a shape.
|
---|
| 45 | A material consists of one or more techniques
|
---|
| 46 | */
|
---|
| 47 | class Technique
|
---|
[2747] | 48 | {
|
---|
[2795] | 49 | friend class ResourceManager;
|
---|
| 50 |
|
---|
[2747] | 51 | public:
|
---|
[2755] | 52 |
|
---|
[2957] | 53 | /** Sets default material (ambient intensity 0.2f, diffuse intensity 1.0f)
|
---|
| 54 | */
|
---|
[3042] | 55 | Technique();
|
---|
[2747] | 56 |
|
---|
[3045] | 57 | Technique(const Technique &tech);
|
---|
| 58 |
|
---|
[3042] | 59 | ~Technique();
|
---|
[2957] | 60 | /** Sets ambient and diffuse color to color
|
---|
| 61 | */
|
---|
[3042] | 62 | Technique(const RgbaColor &color);
|
---|
[2755] | 63 |
|
---|
[2769] | 64 | inline Texture *GetTexture() const { return mTexture; }
|
---|
[2756] | 65 |
|
---|
[2795] | 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; }
|
---|
[2844] | 79 | inline void SetCullFaceEnabled(bool cull) { mCullFaceEnabled = cull; }
|
---|
| 80 |
|
---|
[2795] | 81 | inline bool IsAlphaTestEnabled() const { return mAlphaTestEnabled; }
|
---|
[2844] | 82 | inline bool IsCullFaceEnabled() const { return mCullFaceEnabled; }
|
---|
[3042] | 83 | /** Renders this technique.
|
---|
[2769] | 84 | */
|
---|
| 85 | void Render(RenderState *state);
|
---|
[2795] | 86 | /** Initialize the material with default values
|
---|
| 87 | */
|
---|
| 88 | void InitMaterial();
|
---|
[2769] | 89 |
|
---|
[3036] | 90 | void SetFragmentProgram(ShaderProgram *p);
|
---|
| 91 | void SetVertexProgram(ShaderProgram *p);
|
---|
[3034] | 92 |
|
---|
[3036] | 93 | ShaderProgram *GetFragmentProgram() { return mFragmentProgram; }
|
---|
| 94 | ShaderProgram *GetVertexProgram() { return mVertexProgram; }
|
---|
[3034] | 95 |
|
---|
[3045] | 96 | //void SetFragmentProgramParameters(const GPUProgramParameters &p) { mGPUFragmentParameters = p; }
|
---|
| 97 | //void SetVertexProgramParameters(const GPUProgramParameters &p) { mGPUVertexParameters = p; }
|
---|
[3036] | 98 |
|
---|
[3045] | 99 | /** Each technique has a distict set of parameters.
|
---|
| 100 | */
|
---|
| 101 | GPUProgramParameters * const GetFragmentProgramParameters() { return &mFragmentProgramParameters; }
|
---|
| 102 | GPUProgramParameters * const GetVertexProgramParameters() { return &mVertexProgramParameters; }
|
---|
[3036] | 103 |
|
---|
| 104 |
|
---|
[2795] | 105 | protected:
|
---|
| 106 |
|
---|
[2769] | 107 | ///////////
|
---|
| 108 |
|
---|
| 109 | RgbaColor mDiffuseColor;
|
---|
| 110 | RgbaColor mSpecularColor;
|
---|
| 111 | RgbaColor mAmbientColor;
|
---|
[2795] | 112 | RgbaColor mEmmisiveColor;
|
---|
[2769] | 113 |
|
---|
| 114 | bool mAlphaTestEnabled;
|
---|
[2844] | 115 | bool mCullFaceEnabled;
|
---|
[2968] | 116 | /// the associated texture
|
---|
[2756] | 117 | Texture *mTexture;
|
---|
[3036] | 118 |
|
---|
[3045] | 119 | GPUProgramParameters mVertexProgramParameters;
|
---|
| 120 | GPUProgramParameters mFragmentProgramParameters;
|
---|
[3036] | 121 |
|
---|
| 122 | ShaderProgram *mFragmentProgram;
|
---|
| 123 | ShaderProgram *mVertexProgram;
|
---|
[2747] | 124 | };
|
---|
| 125 |
|
---|
| 126 |
|
---|
[3042] | 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();
|
---|
[2747] | 135 |
|
---|
[3042] | 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 |
|
---|
[2751] | 156 | }
|
---|
[2747] | 157 |
|
---|
| 158 | #endif
|
---|