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

Revision 3047, 4.0 KB checked in by mattausch, 16 years ago (diff)

adding special technique for depth pass (not working yet)

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