source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h @ 3045

Revision 3045, 3.7 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef __MATERIAL_H
2#define __MATERIAL_H
3
4#include "glInterface.h"
5#include "common.h"
6#include "ShaderProgram.h"
7
8
9namespace CHCDemoEngine
10{
11
12class Texture;
13class RenderState;
14class GPUProgramParameters;
15class ShaderProgram;
16
17
18/** Class representing an rgba color vector.
19*/
20class RgbaColor
21{
22
23public:
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
41RgbaColor 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*/
47class Technique
48{
49friend class ResourceManager;
50
51public:
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
105protected:
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*/
129class Material
130{
131public:
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
151protected:
152
153        TechniqueContainer mTechniques;
154};
155
156}
157
158#endif
Note: See TracBrowser for help on using the repository browser.