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

Revision 3326, 4.6 KB checked in by mattausch, 16 years ago (diff)

strange texture error!!

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