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

Revision 3048, 4.0 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();
58        /** Sets ambient and diffuse color to color
59        */
60        Technique(const RgbaColor &color);
61        /** Renders this technique.
62        */
63        void Render(RenderState *state);
64        /** Initialize this technique material with default values
65        */
66        void Init();
67
68        inline Texture *GetTexture() const { return mTexture; }
69
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; }
83        inline void SetCullFaceEnabled(bool cull) { mCullFaceEnabled = cull; }
84
85        inline bool IsAlphaTestEnabled() const { return mAlphaTestEnabled; }
86        inline bool IsCullFaceEnabled() const { return mCullFaceEnabled; }
87
88        inline void SetLightingEnabled(bool l) { mLightingEnabled = l; }
89        inline void SetColorWriteEnabled(bool c) { mColorWriteEnabled = c; }
90
91        inline bool IsLightingEnabled() const { return mLightingEnabled; }
92        inline bool IsColorWriteEnabled() const { return mColorWriteEnabled; }
93
94        void SetFragmentProgram(ShaderProgram *p);
95        void SetVertexProgram(ShaderProgram *p);
96
97        ShaderProgram *GetFragmentProgram() { return mFragmentProgram; }
98        ShaderProgram *GetVertexProgram() { return mVertexProgram; }
99
100        /** Get the set of fragment parameters of this technique
101        */
102        GPUProgramParameters * const GetFragmentProgramParameters() { return &mFragmentProgramParameters; }
103        /**  Get the set of vertex parameters of this technique
104        */
105        GPUProgramParameters * const GetVertexProgramParameters() { return &mVertexProgramParameters; }
106
107        static Technique GetQueryTechnique();
108
109protected:
110
111        ///////////
112
113        RgbaColor mDiffuseColor;
114        RgbaColor mSpecularColor;
115        RgbaColor mAmbientColor;
116        RgbaColor mEmmisiveColor;
117
118        bool mAlphaTestEnabled;
119        bool mCullFaceEnabled;
120        /// the associated texture
121        Texture *mTexture;
122
123        GPUProgramParameters mVertexProgramParameters;
124        GPUProgramParameters mFragmentProgramParameters;
125
126        ShaderProgram *mFragmentProgram;
127        ShaderProgram *mVertexProgram;
128        /// if this material can write colors
129        bool mColorWriteEnabled;
130        /// if lighting is used
131        bool mLightingEnabled;
132};
133
134
135/** A material consists of one or more techniques.
136*/
137class Material
138{
139public:
140        /** Default constructor creating one default technique.
141        */
142        Material();
143
144        ~Material();
145        /** Renders this material.
146        */
147        void Render(RenderState *state);
148
149        void AddTechnique(Technique *t);
150
151        Technique *GetDefaultTechnique() const;
152
153        Technique *GetTechnique(int i) const;
154
155        int GetNumTechniques() const;
156
157
158
159protected:
160
161        TechniqueContainer mTechniques;
162};
163
164}
165
166#endif
Note: See TracBrowser for help on using the repository browser.