Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

X:/dropbox/visualizationlibrary/src/vlGraphics/Actor.hpp

Go to the documentation of this file.
00001 /**************************************************************************************/
00002 /*                                                                                    */
00003 /*  Visualization Library                                                             */
00004 /*  http://www.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 #ifndef Actor_INCLUDE_ONCE
00033 #define Actor_INCLUDE_ONCE
00034 
00035 #include <vlCore/Collection.hpp>
00036 #include <vlCore/Sphere.hpp>
00037 #include <vlCore/AABB.hpp>
00038 #include <vlCore/Transform.hpp>
00039 #include <vlGraphics/link_config.hpp>
00040 #include <vlGraphics/Effect.hpp>
00041 #include <vlGraphics/Renderable.hpp>
00042 #include <vlGraphics/LODEvaluator.hpp>
00043 #include <vlGraphics/UniformSet.hpp>
00044 #include <vlGraphics/Scissor.hpp>
00045 
00046 namespace vl
00047 {
00048   //------------------------------------------------------------------------------
00049   // ActorEventCallback
00050   //------------------------------------------------------------------------------
00075   class VLGRAPHICS_EXPORT ActorEventCallback: public Object
00076   {
00077     VL_INSTRUMENT_ABSTRACT_CLASS(vl::ActorEventCallback, Object)
00078 
00079   public:
00080     ActorEventCallback(): mEnabled(true) {}
00081 
00090     virtual void onActorRenderStarted(Actor* actor, real frame_clock, const Camera* cam, Renderable* renderable, const Shader* shader, int pass) = 0;
00091 
00093     virtual void onActorDelete(Actor* actor) = 0;
00094 
00095     void setEnabled(bool enabled) { mEnabled = enabled; }
00096 
00097     bool isEnabled() const { return mEnabled; }
00098 
00099   protected:
00100     bool mEnabled;
00101   };
00102 
00103   //------------------------------------------------------------------------------
00104   // Actor
00105   //------------------------------------------------------------------------------
00131   class VLGRAPHICS_EXPORT Actor: public Object
00132   {
00133     VL_INSTRUMENT_CLASS(vl::Actor, Object)
00134 
00135   public:
00143     Actor(Renderable* renderable = NULL, Effect* effect = NULL, Transform* transform = NULL, int block = 0, int rank = 0):
00144       mEffect(effect), mTransform(transform), mRenderBlock(block), mRenderRank(rank),
00145       mTransformUpdateTick(-1), mBoundsUpdateTick(-1), mEnableMask(0xFFFFFFFF), mOcclusionQuery(0), mOcclusionQueryTick(0xFFFFFFFF), mIsOccludee(true)
00146     {
00147       VL_DEBUG_SET_OBJECT_NAME()
00148       mActorEventCallbacks.setAutomaticDelete(false);
00149       setLod(0,renderable);
00150       // actor user data
00151       #if VL_ACTOR_USER_DATA
00152         mActorUserData = NULL;
00153       #endif
00154     }
00155 
00157     virtual ~Actor();
00158 
00160     void setLod(int lod_index, Renderable* renderable) 
00161     { 
00162       mRenderables[lod_index] = renderable;
00163       
00164       // schedule update of the Actor's bounds.
00165       if (lod_index == 0)
00166       {
00167         mBoundsUpdateTick = -1;
00168         mAABB.setNull();
00169         mSphere.setNull();
00170       }
00171     }
00172 
00174     const Renderable* lod(int lod_index) const { return mRenderables[lod_index].get(); }
00175 
00177     Renderable* lod(int lod_index) { return mRenderables[lod_index].get(); }
00178 
00180     void setLODs(Renderable* lod0, Renderable* lod1=NULL, Renderable* lod2=NULL, Renderable* lod3=NULL, Renderable* lod4=NULL, Renderable* lod5=NULL);
00181 
00183     void setTransform(Transform* transform)
00184     {
00185       mTransform = transform;
00186       mTransformUpdateTick = -1;
00187       mBoundsUpdateTick    = -1;
00188     }
00189     
00191     Transform* transform()  { return mTransform.get(); }
00192     
00194     const Transform* transform() const { return mTransform.get(); }
00195 
00197     void setEffect(Effect* effect) { mEffect = effect; }
00198     
00200     Effect* effect() { return mEffect.get(); }
00201     
00203     const Effect* effect() const { return mEffect.get(); }
00204 
00206     const AABB& boundingBox() const { return mAABB; }
00207 
00209     const Sphere& boundingSphere() const { return mSphere; }
00210 
00212     const AABB& boundingBoxSafe() { computeBounds(); return mAABB; }
00213 
00215     const Sphere& boundingSphereSafe() { computeBounds(); return mSphere; }
00216 
00218     void computeBounds();
00219 
00221     bool boundsDirty() const;
00222 
00232     void setRenderRank(int rank) { mRenderRank = rank; }
00233 
00244     void setRenderBlock(int block) { mRenderBlock = block; }
00245 
00247     int renderRank() const { return mRenderRank; }
00248 
00250     int renderBlock() const { return mRenderBlock; }
00251 
00253     void setLODEvaluator(LODEvaluator* lod_evaluator) { mLODEvaluator = lod_evaluator; }
00254 
00256     LODEvaluator* lodEvaluator() { return mLODEvaluator.get(); }
00257 
00259     const LODEvaluator* lodEvaluator() const { return mLODEvaluator.get(); }
00260 
00261     int evaluateLOD(Camera* camera);
00262 
00266     void setEnableMask(unsigned int mask) { mEnableMask = mask; }
00267 
00271     unsigned int enableMask() const { return mEnableMask; }
00272 
00273     // uniforms methods
00274 
00278     void setUniform(Uniform* uniform);
00279 
00283     const std::vector< ref<Uniform> >& uniforms() const;
00284 
00288     std::vector< ref<Uniform> >& uniforms();
00289 
00293     void eraseUniform(const char* name);
00294 
00298     void eraseUniform(const Uniform* uniform);
00299 
00303     void eraseAllUniforms();
00304 
00308     Uniform* gocUniform(const char* name);
00309 
00313     Uniform* getUniform(const char* name);
00314     
00318     const Uniform* getUniform(const char* name) const;
00319 
00328     void setUniformSet(UniformSet* uniforms) { mUniformSet = uniforms; }
00329 
00339     const UniformSet* getUniformSet() const { return mUniformSet.get(); }
00340     
00350     UniformSet* getUniformSet() { return mUniformSet.get(); }
00351 
00361     UniformSet* gocUniformSet() { if (!mUniformSet) mUniformSet = new UniformSet; return mUniformSet.get(); }
00362 
00364     const Collection<ActorEventCallback>* actorEventCallbacks() const { return &mActorEventCallbacks; }
00365 
00367     Collection<ActorEventCallback>* actorEventCallbacks() { return &mActorEventCallbacks; }
00368 
00370     void dispatchOnActorRenderStarted( real frame_clock, const Camera* camera, Renderable* renderable, const Shader* shader, int pass)
00371     {
00372       for(int i=0; i<actorEventCallbacks()->size(); ++i)
00373       {
00374         ActorEventCallback& cb = *actorEventCallbacks()->at(i);
00375         if (cb.isEnabled())
00376           cb.onActorRenderStarted(this, frame_clock, camera, renderable, shader, pass);
00377       }
00378     }
00379 
00381     void dispatchOnActorDelete()
00382     {
00383       for(int i=0; i<actorEventCallbacks()->size(); ++i)
00384       {
00385         ActorEventCallback& cb = *actorEventCallbacks()->at(i);
00386         cb.onActorDelete(this);
00387       }
00388     }
00389 
00398     void setScissor(Scissor* scissor) { mScissor = scissor; }
00405     const Scissor* scissor() const { return mScissor.get(); }
00406     
00413     Scissor* scissor() { return mScissor.get(); }
00414 
00417     void setOccludee(bool is_occludee) { mIsOccludee = is_occludee; }
00418 
00421     bool isOccludee() const { return mIsOccludee; }
00422 
00425     void createOcclusionQuery();
00426 
00429     void deleteOcclusionQuery();
00430 
00433     GLuint occlusionQuery() const { return mOcclusionQuery; }
00434 
00436     void setOcclusionQueryTick(unsigned tick) { mOcclusionQueryTick = tick; }
00437 
00439     unsigned occlusionQueryTick() const { return mOcclusionQueryTick; }
00440 
00441 #if VL_ACTOR_USER_DATA
00442   public:
00443     void* actorUserData() { return mActorUserData; }
00444     const void* actorUserData() const { return mActorUserData; }
00445     void setActorUserData(void* user_data) { mActorUserData = user_data; }
00446 
00447   private:
00448     void* mActorUserData;
00449 #endif
00450 
00451   protected:
00452     AABB mAABB;
00453     Sphere mSphere;
00454     ref<Effect> mEffect;
00455     ref<Renderable> mRenderables[VL_MAX_ACTOR_LOD];
00456     ref<Transform> mTransform;
00457     ref<LODEvaluator> mLODEvaluator;
00458     ref<UniformSet> mUniformSet;
00459     ref<Scissor> mScissor;
00460     Collection<ActorEventCallback> mActorEventCallbacks;
00461     int mRenderBlock;
00462     int mRenderRank;
00463     long long mTransformUpdateTick;
00464     long long mBoundsUpdateTick;
00465     unsigned int mEnableMask;
00466     GLuint mOcclusionQuery;
00467     unsigned mOcclusionQueryTick;
00468     bool mIsOccludee;
00469   };
00470   //---------------------------------------------------------------------------
00472   class ActorCollection: public Collection<Actor> {};
00473   //---------------------------------------------------------------------------
00474 }
00475 
00476 #endif

Visualization Library 2011.09.1160 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 2 2013 13:40:34.
Permission is granted to use this page to write and publish articles regarding Visualization Library.