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

Revision 3054, 4.4 KB checked in by mattausch, 16 years ago (diff)

worked on render queue

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