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

Revision 3065, 4.3 KB checked in by mattausch, 16 years ago (diff)

found bug with near plane intersection: q? why did it work with vbo rendering? (probably because of tighter bounds ...)

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{
50friend class ResourceManager;
51friend class RenderQueue;
52
53public:
54
55        /** Sets default material (ambient intensity 0.2f, diffuse intensity 1.0f)
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        inline void SetDepthWriteEnabled(bool d) { mDepthWriteEnabled = d; }
91
92        inline bool IsLightingEnabled() const { return mLightingEnabled; }
93        inline bool IsColorWriteEnabled() const { return mColorWriteEnabled; }
94        inline bool IsDepthWriteEnabled() const { return mDepthWriteEnabled; }
95
96        void SetFragmentProgram(ShaderProgram *p);
97        void SetVertexProgram(ShaderProgram *p);
98
99        inline ShaderProgram *GetFragmentProgram() { return mFragmentProgram; }
100        inline ShaderProgram *GetVertexProgram() { return mVertexProgram; }
101
102        /** Get the set of fragment parameters of this technique
103        */
104        GPUProgramParameters * const GetFragmentProgramParameters() { return &mFragmentProgramParameters; }
105        /**  Get the set of vertex parameters of this technique
106        */
107        GPUProgramParameters * const GetVertexProgramParameters() { return &mVertexProgramParameters; }
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        /// if depth write is enabled
133        bool mDepthWriteEnabled;
134        /// pointer to the renderqueue bucket this entity belongs to
135        RenderQueueBucket *mRenderQueueBucket;
136};
137
138
139/** A material consists of one or more techniques.
140*/
141class Material
142{
143public:
144        /** Default constructor creating one default technique.
145        */
146        Material();
147
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
163protected:
164
165        TechniqueContainer mTechniques;
166};
167
168}
169
170#endif
Note: See TracBrowser for help on using the repository browser.