[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 | {
|
---|
[2795] | 50 | friend class ResourceManager;
|
---|
[3054] | 51 | friend class RenderQueue;
|
---|
[2795] | 52 |
|
---|
[2747] | 53 | public:
|
---|
[2755] | 54 |
|
---|
[2957] | 55 | /** Sets default material (ambient intensity 0.2f, diffuse intensity 1.0f)
|
---|
| 56 | */
|
---|
[3042] | 57 | Technique();
|
---|
[2957] | 58 | /** Sets ambient and diffuse color to color
|
---|
| 59 | */
|
---|
[3042] | 60 | Technique(const RgbaColor &color);
|
---|
[3047] | 61 | /** Renders this technique.
|
---|
| 62 | */
|
---|
| 63 | void Render(RenderState *state);
|
---|
| 64 | /** Initialize this technique material with default values
|
---|
| 65 | */
|
---|
| 66 | void Init();
|
---|
[2755] | 67 |
|
---|
[2769] | 68 | inline Texture *GetTexture() const { return mTexture; }
|
---|
[2756] | 69 |
|
---|
[2795] | 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; }
|
---|
[2844] | 83 | inline void SetCullFaceEnabled(bool cull) { mCullFaceEnabled = cull; }
|
---|
| 84 |
|
---|
[2795] | 85 | inline bool IsAlphaTestEnabled() const { return mAlphaTestEnabled; }
|
---|
[2844] | 86 | inline bool IsCullFaceEnabled() const { return mCullFaceEnabled; }
|
---|
[2769] | 87 |
|
---|
[3047] | 88 | inline void SetLightingEnabled(bool l) { mLightingEnabled = l; }
|
---|
| 89 | inline void SetColorWriteEnabled(bool c) { mColorWriteEnabled = c; }
|
---|
[3050] | 90 | inline void SetDepthWriteEnabled(bool d) { mDepthWriteEnabled = d; }
|
---|
[3047] | 91 |
|
---|
| 92 | inline bool IsLightingEnabled() const { return mLightingEnabled; }
|
---|
| 93 | inline bool IsColorWriteEnabled() const { return mColorWriteEnabled; }
|
---|
[3050] | 94 | inline bool IsDepthWriteEnabled() const { return mDepthWriteEnabled; }
|
---|
[3047] | 95 |
|
---|
[3036] | 96 | void SetFragmentProgram(ShaderProgram *p);
|
---|
| 97 | void SetVertexProgram(ShaderProgram *p);
|
---|
[3034] | 98 |
|
---|
[3050] | 99 | inline ShaderProgram *GetFragmentProgram() { return mFragmentProgram; }
|
---|
| 100 | inline ShaderProgram *GetVertexProgram() { return mVertexProgram; }
|
---|
[3034] | 101 |
|
---|
[3047] | 102 | /** Get the set of fragment parameters of this technique
|
---|
[3045] | 103 | */
|
---|
| 104 | GPUProgramParameters * const GetFragmentProgramParameters() { return &mFragmentProgramParameters; }
|
---|
[3047] | 105 | /** Get the set of vertex parameters of this technique
|
---|
| 106 | */
|
---|
[3045] | 107 | GPUProgramParameters * const GetVertexProgramParameters() { return &mVertexProgramParameters; }
|
---|
[3036] | 108 |
|
---|
[2795] | 109 | protected:
|
---|
| 110 |
|
---|
[2769] | 111 | ///////////
|
---|
| 112 |
|
---|
| 113 | RgbaColor mDiffuseColor;
|
---|
| 114 | RgbaColor mSpecularColor;
|
---|
| 115 | RgbaColor mAmbientColor;
|
---|
[2795] | 116 | RgbaColor mEmmisiveColor;
|
---|
[2769] | 117 |
|
---|
| 118 | bool mAlphaTestEnabled;
|
---|
[2844] | 119 | bool mCullFaceEnabled;
|
---|
[2968] | 120 | /// the associated texture
|
---|
[2756] | 121 | Texture *mTexture;
|
---|
[3036] | 122 |
|
---|
[3045] | 123 | GPUProgramParameters mVertexProgramParameters;
|
---|
| 124 | GPUProgramParameters mFragmentProgramParameters;
|
---|
[3036] | 125 |
|
---|
| 126 | ShaderProgram *mFragmentProgram;
|
---|
| 127 | ShaderProgram *mVertexProgram;
|
---|
[3047] | 128 | /// if this material can write colors
|
---|
| 129 | bool mColorWriteEnabled;
|
---|
| 130 | /// if lighting is used
|
---|
| 131 | bool mLightingEnabled;
|
---|
[3050] | 132 | /// if depth write is enabled
|
---|
| 133 | bool mDepthWriteEnabled;
|
---|
[3054] | 134 | /// pointer to the renderqueue bucket this entity belongs to
|
---|
| 135 | RenderQueueBucket *mRenderQueueBucket;
|
---|
[2747] | 136 | };
|
---|
| 137 |
|
---|
| 138 |
|
---|
[3042] | 139 | /** A material consists of one or more techniques.
|
---|
| 140 | */
|
---|
| 141 | class Material
|
---|
| 142 | {
|
---|
| 143 | public:
|
---|
| 144 | /** Default constructor creating one default technique.
|
---|
| 145 | */
|
---|
| 146 | Material();
|
---|
[2747] | 147 |
|
---|
[3042] | 148 | ~Material();
|
---|
| 149 | /** Renders this material.
|
---|
| 150 | */
|
---|
| 151 | void Render(RenderState *state);
|
---|
| 152 |
|
---|
| 153 | void AddTechnique(Technique *t);
|
---|
| 154 |
|
---|
| 155 | Technique *GetDefaultTechnique() const;
|
---|
| 156 |
|
---|
| 157 | Technique *GetTechnique(int i) const;
|
---|
| 158 |
|
---|
| 159 | int GetNumTechniques() const;
|
---|
| 160 |
|
---|
| 161 |
|
---|
| 162 |
|
---|
| 163 | protected:
|
---|
| 164 |
|
---|
| 165 | TechniqueContainer mTechniques;
|
---|
| 166 | };
|
---|
| 167 |
|
---|
[2751] | 168 | }
|
---|
[2747] | 169 |
|
---|
| 170 | #endif
|
---|