source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp @ 3114

Revision 3114, 2.8 KB checked in by mattausch, 16 years ago (diff)

worked on dynamic objects: now ook, but have to work on render queue

Line 
1#include "common.h"
2#include "Material.h"
3#include "Texture.h"
4#include "glInterface.h"
5#include "RenderState.h"
6
7
8using namespace std;
9
10
11namespace CHCDemoEngine
12{
13
14RgbaColor RandomColor(float a, float b)
15{
16        return RgbaColor(a + Random(b), a + Random(b), a + Random(b), 1);
17}
18
19
20void Technique::Init()
21{
22        mTexture = NULL;
23        mAlphaTestEnabled = false;
24        mCullFaceEnabled = true;
25       
26        mVertexProgramParameters.Reset();
27        mFragmentProgramParameters.Reset();
28       
29        mVertexProgram = NULL;
30        mFragmentProgram = NULL;
31
32        // if this material can write colors
33        mColorWriteEnabled = true;
34        // if lighting is used
35        mLightingEnabled = true;
36        /// if depth write should be enabled
37        mDepthWriteEnabled = true;
38        /// the render queue bucket this technique is assigned to
39        mRenderQueueBucket = NULL;
40}
41
42
43Technique::Technique():
44mAmbientColor(RgbaColor(0.2f, 0.2f, 0.2f, 1.0f)),
45mDiffuseColor(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)),
46mSpecularColor(RgbaColor(.0f, .0f, .0f, 1.0f)),
47mEmmisiveColor(RgbaColor(.0f, .0f, .0f, 1.0f))
48{
49        Init();
50}
51
52
53Technique::Technique(const RgbaColor &color):
54mDiffuseColor(color),
55mAmbientColor(color),
56mSpecularColor(0, 0, 0, 1),
57mTexture(NULL)
58{
59        Init();
60}
61
62
63void Technique::Render(RenderState *state, SceneEntity *ent)
64{
65        glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r);
66        glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mDiffuseColor.r);
67        glMaterialfv(GL_FRONT, GL_EMISSION, (float *)&mEmmisiveColor.r);
68        glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mSpecularColor.r);
69
70        state->SetState(this, ent);
71}
72
73
74void Technique::SetFragmentProgram(ShaderProgram *p)
75{
76        mFragmentProgram = p;
77        mFragmentProgramParameters.Reset();
78        mFragmentProgramParameters.SetProgram(p);
79}
80       
81
82void Technique::SetVertexProgram(ShaderProgram *p)
83{
84        mVertexProgram = p;
85        mVertexProgramParameters.Reset();
86        mVertexProgramParameters.SetProgram(p);
87}
88
89
90
91/***************************************************/
92/*          class Material implementation          */
93/***************************************************/
94
95
96void Material::Render(RenderState *state, SceneEntity *parent)
97{
98        // set technique if available
99        int idx = min((int)mTechniques.size() - 1 , state->GetRenderTechnique());
100        mTechniques[idx]->Render(state, parent);
101}
102
103
104Technique *Material::GetDefaultTechnique() const
105{
106        return mTechniques[0];
107}
108
109
110Technique *Material::GetTechnique(int i) const
111{
112        return mTechniques[i];
113}
114
115
116Material::Material()
117{
118        Technique *tech = new Technique();
119        mTechniques.push_back(tech);
120}
121
122
123Material::~Material()
124{
125        CLEAR_CONTAINER(mTechniques);
126}
127
128
129int Material::GetNumTechniques() const
130{
131        return (int)mTechniques.size();
132}
133
134
135void Material::AddTechnique(Technique *tech)
136{
137        mTechniques.push_back(tech);
138}
139
140
141}
Note: See TracBrowser for help on using the repository browser.