Visualization Library v1.0.3A lightweight C++ OpenGL middleware for 2D/3D graphics |
[Download] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://visualizationlibrary.org */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00029 /* */ 00030 /**************************************************************************************/ 00031 00032 #include <vlGraphics/Actor.hpp> 00033 00034 using namespace vl; 00035 00036 //----------------------------------------------------------------------------- 00037 // Actor 00038 //----------------------------------------------------------------------------- 00039 Actor::~Actor() 00040 { 00041 dispatchOnActorDelete(); 00042 deleteOcclusionQuery(); 00043 } 00044 //----------------------------------------------------------------------------- 00045 void Actor::setLODs(Renderable* lod0, Renderable* lod1, Renderable* lod2, Renderable* lod3, Renderable* lod4, Renderable* lod5) 00046 { 00047 if (lod0) { VL_CHECK(0<VL_MAX_ACTOR_LOD) setLod(0,lod0); } 00048 if (lod1) { VL_CHECK(1<VL_MAX_ACTOR_LOD) setLod(1,lod1); } 00049 if (lod2) { VL_CHECK(2<VL_MAX_ACTOR_LOD) setLod(2,lod2); } 00050 if (lod3) { VL_CHECK(3<VL_MAX_ACTOR_LOD) setLod(3,lod3); } 00051 if (lod4) { VL_CHECK(4<VL_MAX_ACTOR_LOD) setLod(4,lod4); } 00052 if (lod5) { VL_CHECK(5<VL_MAX_ACTOR_LOD) setLod(5,lod5); } 00053 } 00054 //----------------------------------------------------------------------------- 00055 int Actor::evaluateLOD(Camera* camera) 00056 { 00057 if (mLODEvaluator) 00058 return mLODEvaluator->evaluate(this, camera); 00059 else 00060 return 0; 00061 } 00062 //----------------------------------------------------------------------------- 00063 void Actor::createOcclusionQuery() 00064 { 00065 VL_CHECK_OGL(); 00066 if (!mOcclusionQuery && Has_Occlusion_Query) 00067 glGenQueries(1, &mOcclusionQuery); 00068 VL_CHECK_OGL(); 00069 VL_CHECK(mOcclusionQuery) 00070 } 00071 //----------------------------------------------------------------------------- 00072 void Actor::deleteOcclusionQuery() 00073 { 00074 if(Has_Occlusion_Query) 00075 { 00076 if (mOcclusionQuery) 00077 { 00078 glDeleteQueries(1, &mOcclusionQuery); 00079 mOcclusionQuery = 0; 00080 } 00081 } 00082 } 00083 //----------------------------------------------------------------------------- 00084 bool Actor::boundsDirty() const 00085 { 00086 // (1) renderable dirty or we're not up to date with the renderable. 00087 bool dirty = lod(0)->boundsDirty() || lod(0)->boundsUpdateTick() != mBoundsUpdateTick; 00088 00089 // (2) we're not not up to date with the transform. 00090 dirty |= transform() && transform()->worldMatrixUpdateTick() != mTransformUpdateTick; 00091 00092 return dirty; 00093 } 00094 //----------------------------------------------------------------------------- 00095 void Actor::computeBounds() 00096 { 00097 if ( lod(0) == NULL ) 00098 return; 00099 00100 bool geom_update = lod(0)->boundsDirty() || lod(0)->boundsUpdateTick() != mBoundsUpdateTick; 00101 00102 if ( transform() && (geom_update || transform()->worldMatrixUpdateTick() != mTransformUpdateTick) ) 00103 { 00104 lod(0)->boundingBox().transformed( mAABB, transform()->worldMatrix() ); 00105 mTransformUpdateTick = transform()->worldMatrixUpdateTick(); 00106 mSphere = mAABB.isNull() ? Sphere() : mAABB; 00107 mBoundsUpdateTick = lod(0)->boundsUpdateTick(); 00108 } 00109 else 00110 if (geom_update) 00111 { 00112 mAABB = lod(0)->boundingBox(); 00113 mSphere = mAABB.isNull() ? Sphere() : mAABB; 00114 mBoundsUpdateTick = lod(0)->boundsUpdateTick(); 00115 } 00116 } 00117 //----------------------------------------------------------------------------- 00118 void Actor::setUniform(Uniform* uniform) { gocUniformSet()->setUniform(uniform); } 00119 //----------------------------------------------------------------------------- 00120 const std::vector< ref<Uniform> >& Actor::uniforms() const { return getUniformSet()->uniforms(); } 00121 //----------------------------------------------------------------------------- 00122 std::vector< ref<Uniform> >& Actor::uniforms() { return gocUniformSet()->uniforms(); } 00123 //----------------------------------------------------------------------------- 00124 void Actor::eraseUniform(const char* name) { if(getUniformSet()) getUniformSet()->eraseUniform(name); } 00125 //----------------------------------------------------------------------------- 00126 void Actor::eraseUniform(const Uniform* uniform) { if(getUniformSet()) getUniformSet()->eraseUniform(uniform); } 00127 //----------------------------------------------------------------------------- 00128 void Actor::eraseAllUniforms() { if(getUniformSet()) getUniformSet()->eraseAllUniforms(); } 00129 //----------------------------------------------------------------------------- 00130 Uniform* Actor::gocUniform(const char* name) { return gocUniformSet()->gocUniform(name); } 00131 //----------------------------------------------------------------------------- 00132 Uniform* Actor::getUniform(const char* name) { if (getUniformSet()) return getUniformSet()->getUniform(name); else return NULL; } 00133 //----------------------------------------------------------------------------- 00134 const Uniform* Actor::getUniform(const char* name) const { if (getUniformSet()) return getUniformSet()->getUniform(name); else return NULL; } 00135 //-----------------------------------------------------------------------------