Changeset 3042
- Timestamp:
- 10/19/08 01:33:16 (16 years ago)
- Location:
- GTP/trunk/App/Demos/Vis/FriendlyCulling/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Bvh.cpp
r3021 r3042 1081 1081 1082 1082 // hack: for deferred shading we have to define a material 1083 static MaterialboxMat;1083 static Technique boxMat; 1084 1084 boxMat.SetEmmisive(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)); 1085 1085 -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.cpp
r3039 r3042 18 18 19 19 20 void Material::InitMaterial()20 void Technique::InitMaterial() 21 21 { 22 22 mTexture = NULL; … … 32 32 33 33 34 Material::Material():34 Technique::Technique(): 35 35 mAmbientColor(RgbaColor(0.2f, 0.2f, 0.2f, 1.0f)), 36 36 mDiffuseColor(RgbaColor(1.0f, 1.0f, 1.0f, 1.0f)), … … 42 42 43 43 44 Material::~Material()44 Technique::~Technique() 45 45 { 46 46 //DEL_PTR(mGPUFragmentParameters); … … 49 49 50 50 51 Material::Material(const RgbaColor &color):51 Technique::Technique(const RgbaColor &color): 52 52 mDiffuseColor(color), 53 53 mAmbientColor(color), … … 59 59 60 60 61 Material RandomMaterial() 62 { 63 float a = 0.1f; 64 float b = 0.9f; 65 66 Material m; 67 m.mDiffuseColor = RandomColor(a, b); 68 69 return m; 70 } 71 72 73 void Material::Render(RenderState *state) 61 void Technique::Render(RenderState *state) 74 62 { 75 63 glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mAmbientColor.r); … … 82 70 83 71 84 void Material::SetFragmentProgram(ShaderProgram *p)72 void Technique::SetFragmentProgram(ShaderProgram *p) 85 73 { 86 74 mFragmentProgram = p; … … 91 79 92 80 93 void Material::SetVertexProgram(ShaderProgram *p)81 void Technique::SetVertexProgram(ShaderProgram *p) 94 82 { 95 83 mVertexProgram = p; … … 99 87 } 100 88 89 90 void Material::Render(RenderState *state) 91 { 92 mTechniques[0]->Render(state); 101 93 } 94 95 96 Technique *Material::GetDefaultTechnique() const 97 { 98 return mTechniques[0]; 99 } 100 101 102 Technique *Material::GetTechnique(int i) const 103 { 104 return mTechniques[i]; 105 } 106 107 108 Material::Material() 109 { 110 Technique *tech = new Technique(); 111 112 mTechniques.push_back(tech); 113 } 114 115 116 Material::~Material() 117 { 118 CLEAR_CONTAINER(mTechniques); 119 } 120 121 122 int Material::GetNumTechniques() const 123 { 124 return (int)mTechniques.size(); 125 } 126 127 128 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Material.h
r3036 r3042 15 15 16 16 17 /** Class representing an rgba color vector. 18 */ 17 19 class RgbaColor 18 20 { … … 36 38 37 39 38 39 class Material 40 /** This class represents a certain rendering technique of a shape. 41 A material consists of one or more techniques 42 */ 43 class Technique 40 44 { 41 45 friend class ResourceManager; … … 45 49 /** Sets default material (ambient intensity 0.2f, diffuse intensity 1.0f) 46 50 */ 47 Material();51 Technique(); 48 52 49 ~ Material();53 ~Technique(); 50 54 /** Sets ambient and diffuse color to color 51 55 */ 52 Material(const RgbaColor &color); 53 54 friend Material RandomMaterial(); 56 Technique(const RgbaColor &color); 55 57 56 58 inline Texture *GetTexture() const { return mTexture; } … … 73 75 inline bool IsAlphaTestEnabled() const { return mAlphaTestEnabled; } 74 76 inline bool IsCullFaceEnabled() const { return mCullFaceEnabled; } 75 /** Renders this material.77 /** Renders this technique. 76 78 */ 77 79 void Render(RenderState *state); … … 115 117 116 118 117 extern Material RandomMaterial(); 119 /** A material consists of one or more techniques. 120 */ 121 class Material 122 { 123 public: 124 /** Default constructor creating one default technique. 125 */ 126 Material(); 127 128 ~Material(); 129 /** Renders this material. 130 */ 131 void Render(RenderState *state); 132 133 void AddTechnique(Technique *t); 134 135 Technique *GetDefaultTechnique() const; 136 137 Technique *GetTechnique(int i) const; 138 139 int GetNumTechniques() const; 140 141 142 143 protected: 144 145 TechniqueContainer mTechniques; 146 }; 118 147 119 148 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp
r2848 r3042 51 51 bool RenderQueue::FitsInBucket(Shape *shape, size_t idx) const 52 52 { 53 Material *mat = shape->GetMaterial();53 Technique *tech = shape->GetMaterial()->GetDefaultTechnique(); 54 54 55 55 // test if entity belongs to this bucket 56 56 // note: rather slows down the application for some reason!! 57 if ( mat->IsAlphaTestEnabled() != mBuckets[idx]->mAlphaTestEnabled)57 if (tech->IsAlphaTestEnabled() != mBuckets[idx]->mAlphaTestEnabled) 58 58 return false; 59 59 60 if ( mat->IsCullFaceEnabled() != mBuckets[idx]->mCullFaceEnabled)60 if (tech->IsCullFaceEnabled() != mBuckets[idx]->mCullFaceEnabled) 61 61 return false; 62 62 63 const bool hasTexture = ( mat->GetTexture() != NULL);63 const bool hasTexture = (tech->GetTexture() != NULL); 64 64 65 65 if (hasTexture != mBuckets[idx]->mHasTexture) … … 68 68 if (hasTexture) 69 69 { 70 if ( mat->GetTexture()->GetWidth() != mBuckets[idx]->mTexWidth)70 if (tech->GetTexture()->GetWidth() != mBuckets[idx]->mTexWidth) 71 71 return false; 72 72 73 if ( mat->GetTexture()->GetHeight() != mBuckets[idx]->mTexHeight)73 if (tech->GetTexture()->GetHeight() != mBuckets[idx]->mTexHeight) 74 74 return false; 75 75 } … … 119 119 bucket->mMinDistance = -1; 120 120 121 Material *mat = shape->GetMaterial();122 123 bucket->mAlphaTestEnabled = mat->IsAlphaTestEnabled();124 bucket->mCullFaceEnabled = mat->IsCullFaceEnabled();125 126 const bool hasTexture = ( mat->GetTexture() != NULL);121 Technique *tech = shape->GetMaterial()->GetDefaultTechnique(); 122 123 bucket->mAlphaTestEnabled = tech->IsAlphaTestEnabled(); 124 bucket->mCullFaceEnabled = tech->IsCullFaceEnabled(); 125 126 const bool hasTexture = (tech->GetTexture() != NULL); 127 127 128 128 bucket->mHasTexture = hasTexture; 129 129 130 bucket->mTexWidth = hasTexture ? mat->GetTexture()->GetWidth() : 0;131 bucket->mTexHeight = hasTexture ? mat->GetTexture()->GetHeight() : 0;130 bucket->mTexWidth = hasTexture ? tech->GetTexture()->GetWidth() : 0; 131 bucket->mTexHeight = hasTexture ? tech->GetTexture()->GetHeight() : 0; 132 132 133 133 mBuckets.push_back(bucket); … … 204 204 Shape *shape = *sit; 205 205 206 Material *mat = shape->GetMaterial();207 int tsize = mat->GetTexture() ? mat->GetTexture()->GetByteSize() : 0;206 Technique *tech = shape->GetMaterial()->GetDefaultTechnique(); 207 int tsize = tech->GetTexture() ? tech->GetTexture()->GetByteSize() : 0; 208 208 209 209 float dist = SqrMagnitude(shape->GetBoundingBox().Center() - mCamera->GetPosition()); 210 210 211 Debug << "e: " << shape << " a: " << mat->IsAlphaTestEnabled() << " s: " << tsize << " d: " << dist << " " << endl;211 Debug << "e: " << shape << " a: " << tech->IsAlphaTestEnabled() << " s: " << tsize << " d: " << dist << " " << endl; 212 212 } 213 213 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.cpp
r3039 r3042 95 95 glDepthMask(GL_FALSE); 96 96 97 static Material defaultMat;98 SetState(&default Mat);97 static Technique defaultTech; 98 SetState(&defaultTech); 99 99 } 100 100 else // mode returns to render … … 122 122 123 123 124 void RenderState::SetState( Material *mat)125 { 126 Texture *tex = mat->GetTexture();124 void RenderState::SetState(Technique *tech) 125 { 126 Texture *tex = tech->GetTexture(); 127 127 128 128 const bool texturing = (tex != NULL); 129 129 130 bool alphaTest = mat->IsAlphaTestEnabled();131 bool cullFace = mat->IsCullFaceEnabled();130 bool alphaTest = tech->IsAlphaTestEnabled(); 131 bool cullFace = tech->IsCullFaceEnabled(); 132 132 133 133 if (!mLockCullFaceEnabled) … … 189 189 if (mRenderType == DEFERRED) 190 190 { 191 if (mat->GetFragmentProgram()) 192 { 193 if (mat->GetFragmentProgram() != mCurrentFragmentProgram) 191 ShaderProgram *frag = tech->GetFragmentProgram(); 192 193 if (frag) 194 { 195 if (frag != mCurrentFragmentProgram) 194 196 { 195 mCurrentFragmentProgram = mat->GetFragmentProgram();197 mCurrentFragmentProgram = frag; 196 198 mCurrentFragmentProgram->Bind(); 197 199 } 198 200 199 mat->GetFragmentProgramParameters()->UpdateParameters(); 200 201 } 202 203 if (mat->GetVertexProgram()) 204 { 205 if (mat->GetVertexProgram() != mCurrentVertexProgram) 206 { 207 mCurrentVertexProgram = mat->GetVertexProgram(); 201 tech->GetFragmentProgramParameters()->UpdateParameters(); 202 203 } 204 205 ShaderProgram *vert = tech->GetVertexProgram(); 206 207 if (vert) 208 { 209 if (vert != mCurrentVertexProgram) 210 { 211 mCurrentVertexProgram = vert; 208 212 mCurrentVertexProgram->Bind(); 209 213 } 210 214 211 mat->GetVertexProgramParameters()->UpdateParameters();215 tech->GetVertexProgramParameters()->UpdateParameters(); 212 216 } 213 217 } -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderState.h
r3038 r3042 45 45 /** Sets the current render state. 46 46 */ 47 void SetState( Material *mat);47 void SetState(Technique *tech); 48 48 /** Returns either query or render mode 49 49 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/ResourceManager.cpp
r3041 r3042 166 166 Shape *shape = *it; 167 167 Material *mat = shape->GetMaterial(); 168 mat->SetVertexProgram(sTreeAnimation); 169 170 GPUProgramParameters *vtxParams = mat->GetVertexProgramParameters(); 168 Technique *tech = mat->GetDefaultTechnique(); 169 170 tech->SetVertexProgram(sTreeAnimation); 171 172 GPUProgramParameters *vtxParams = tech->GetVertexProgramParameters(); 171 173 172 174 vtxParams->SetTimerParam(0); … … 251 253 Material *mat = new Material(); 252 254 255 // set default fragment + vertex programs 256 Technique *tech = mat->GetDefaultTechnique(); 257 253 258 // texture 254 259 int texId; … … 256 261 257 262 if (texId >= 0) 258 mat->SetTexture(mTextureTable[texId]);259 260 str.read(reinterpret_cast<char *>(& mat->mAlphaTestEnabled), sizeof(bool));261 str.read(reinterpret_cast<char *>(& mat->mCullFaceEnabled), sizeof(bool));263 tech->SetTexture(mTextureTable[texId]); 264 265 str.read(reinterpret_cast<char *>(&tech->mAlphaTestEnabled), sizeof(bool)); 266 str.read(reinterpret_cast<char *>(&tech->mCullFaceEnabled), sizeof(bool)); 262 267 263 268 // gl material 264 269 bool hasGlMaterial; 265 270 str.read(reinterpret_cast<char *>(&hasGlMaterial), sizeof(bool)); 266 271 267 272 if (hasGlMaterial) 268 273 { 269 274 // only write rgb part of the material 270 str.read(reinterpret_cast<char *>(& mat->mAmbientColor), sizeof(Vector3));271 str.read(reinterpret_cast<char *>(& mat->mDiffuseColor), sizeof(Vector3));272 str.read(reinterpret_cast<char *>(& mat->mEmmisiveColor), sizeof(Vector3));273 str.read(reinterpret_cast<char *>(& mat->mSpecularColor), sizeof(Vector3));274 } 275 276 if ( mat->GetTexture())277 { 278 mat->mFragmentProgram = mMrtDefaultFragmentTexProgram;279 280 mat->mGPUFragmentParameters = CreateGPUProgramParameters(mat->mFragmentProgram);281 mat->mGPUFragmentParameters->SetTexture(0, mat->GetTexture()->GetId());275 str.read(reinterpret_cast<char *>(&tech->mAmbientColor), sizeof(Vector3)); 276 str.read(reinterpret_cast<char *>(&tech->mDiffuseColor), sizeof(Vector3)); 277 str.read(reinterpret_cast<char *>(&tech->mEmmisiveColor), sizeof(Vector3)); 278 str.read(reinterpret_cast<char *>(&tech->mSpecularColor), sizeof(Vector3)); 279 } 280 281 if (tech->GetTexture()) 282 { 283 tech->mFragmentProgram = mMrtDefaultFragmentTexProgram; 284 285 tech->mGPUFragmentParameters = CreateGPUProgramParameters(tech->mFragmentProgram); 286 tech->mGPUFragmentParameters->SetTexture(0, tech->GetTexture()->GetId()); 282 287 } 283 288 else 284 289 { 285 mat->mFragmentProgram = mMrtDefaultFragmentProgram;286 mat->mGPUFragmentParameters = CreateGPUProgramParameters(mat->mFragmentProgram);287 } 288 289 mat->mVertexProgram = mMrtDefaultVertexProgram;290 mat->mGPUVertexParameters = CreateGPUProgramParameters(mat->mVertexProgram);290 tech->mFragmentProgram = mMrtDefaultFragmentProgram; 291 tech->mGPUFragmentParameters = CreateGPUProgramParameters(tech->mFragmentProgram); 292 } 293 294 tech->mVertexProgram = mMrtDefaultVertexProgram; 295 tech->mGPUVertexParameters = CreateGPUProgramParameters(tech->mVertexProgram); 291 296 292 297 return mat; -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SceneEntity.h
r2980 r3042 35 35 SceneEntity(Transform3 *trafo); 36 36 37 ~SceneEntity();37 virtual ~SceneEntity(); 38 38 /** Renders this node. 39 39 */ 40 v oid Render(RenderState *state);40 virtual void Render(RenderState *state); 41 41 /** Set pointer to the shape 42 42 */ -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/SkyPreetham.cpp
r3041 r3042 80 80 Material *mat = shape->GetMaterial(); 81 81 82 mat-> SetFragmentProgram(mSkyFragProgram);83 mat-> SetVertexProgram(mSkyVtxProgram);82 mat->GetDefaultTechnique()->SetFragmentProgram(mSkyFragProgram); 83 mat->GetDefaultTechnique()->SetVertexProgram(mSkyVtxProgram); 84 84 } 85 85 … … 114 114 mSkyDome->GetTransform()->SetMatrix(s * m); 115 115 116 GPUProgramParameters *vtxParams = mSkyDome->GetShape(0)->GetMaterial()->GetVertexProgramParameters(); 116 Material *mat = mSkyDome->GetShape(0)->GetMaterial(); 117 Technique *tech = mat->GetDefaultTechnique(); 118 119 GPUProgramParameters *vtxParams = tech->GetVertexProgramParameters(); 117 120 118 121 vtxParams->SetValue3f(0, sunDir.x, sunDir.y, sunDir.z); … … 138 141 } 139 142 140 mSkyDome->GetShape(0)->GetMaterial()->GetVertexProgramParameters()->UpdateParameters();141 mSkyDome->GetShape(0)->GetMaterial()->GetVertexProgram()->Bind();142 143 mSkyDome->GetShape(0)->GetMaterial()->GetFragmentProgramParameters()->UpdateParameters();144 mSkyDome->GetShape(0)->GetMaterial()->GetFragmentProgram()->Bind();143 tech->GetVertexProgramParameters()->UpdateParameters(); 144 tech->GetVertexProgram()->Bind(); 145 146 tech->GetFragmentProgramParameters()->UpdateParameters(); 147 tech->GetFragmentProgram()->Bind(); 145 148 146 149 // Render sky dome. -
GTP/trunk/App/Demos/Vis/FriendlyCulling/src/common.h
r3038 r3042 37 37 class ShaderProgram; 38 38 class FrameBufferObject; 39 class Technique; 39 40 40 41 struct LODLevel; … … 501 502 typedef std::vector<Material *> MaterialContainer; 502 503 typedef std::vector<GPUProgramParameters *> GPUParamContainer; 503 typedef 504 typedef 505 504 typedef std::vector<FrameBufferObject *> FBOContainer; 505 typedef std::vector<ShaderProgram *> ShaderContainer; 506 typedef std::vector<Technique *> TechniqueContainer; 506 507 typedef std::vector<Vector3> VertexArray; 508 507 509 508 510 typedef std::pair<float, float> Texcoord2;
Note: See TracChangeset
for help on using the changeset viewer.