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