# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/Actor.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    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   public:
    00078     ActorEventCallback(): mEnabled(true) {}
    00079
    00088     virtual void onActorRenderStarted(Actor* actor, Real frame_clock, const Camera* cam, Renderable* renderable, const Shader* shader, int pass) = 0;
    00089
    00091     virtual void onActorDelete(Actor* actor) = 0;
    00092
    00093     void setEnabled(bool enabled) { mEnabled = enabled; }
    00094
    00095     bool isEnabled() const { return mEnabled; }
    00096
    00097   protected:
    00098     bool mEnabled;
    00099   };
    00100
    00101   //------------------------------------------------------------------------------
    00102   // Actor
    00103   //------------------------------------------------------------------------------
    00129   class VLGRAPHICS_EXPORT Actor: public Object
    00130   {
    00131   public:
    00132     virtual const char* className() { return "vl::Actor"; }
    00133
    00141     Actor(Renderable* renderable = NULL, Effect* effect = NULL, Transform* transform = NULL, int block = 0, int rank = 0):
    00142       mEffect(effect), mTransform(transform), mRenderBlock(block), mRenderRank(rank),
    00143       mTransformUpdateTick(-1), mBoundsUpdateTick(-1), mEnableMask(0xFFFFFFFF), mOcclusionQuery(0), mIsOccludee(true), mOcclusionQueryTick(0xFFFFFFFF)
    00144     {
    00145       VL_DEBUG_SET_OBJECT_NAME()
    00146       mActorEventCallbacks.setAutomaticDelete(false);
    00147       setLod(0,renderable);
    00148       // actor user data
    00149       #if VL_ACTOR_USER_DATA
    00150         mActorUserData = NULL;
    00151       #endif
    00152     }
    00153
    00155     virtual ~Actor();
    00156
    00158     void setLod(int lod_index, Renderable* renderable)
    00159     {
    00160       mRenderables[lod_index] = renderable;
    00161
    00162       // schedule update of the Actor's bounds.
    00163       if (lod_index == 0)
    00164       {
    00165         mBoundsUpdateTick = -1;
    00166         mAABB.setNull();
    00167         mSphere.setNull();
    00168       }
    00169     }
    00170
    00172     const ref<Renderable>& lod(int lod_index) const { return mRenderables[lod_index]; }
    00173
    00175     void setLODs(Renderable* lod0, Renderable* lod1=NULL, Renderable* lod2=NULL, Renderable* lod3=NULL, Renderable* lod4=NULL, Renderable* lod5=NULL);
    00176
    00178     void setTransform(Transform* transform)
    00179     {
    00180       mTransform = transform;
    00181       mTransformUpdateTick = -1;
    00182       mBoundsUpdateTick    = -1;
    00183     }
    00184
    00186     Transform* transform()  { return mTransform.get(); }
    00187
    00189     const Transform* transform() const { return mTransform.get(); }
    00190
    00192     void setEffect(Effect* effect) { mEffect = effect; }
    00193
    00195     Effect* effect() { return mEffect.get(); }
    00196
    00198     const Effect* effect() const { return mEffect.get(); }
    00199
    00201     const AABB& boundingBox() const { return mAABB; }
    00202
    00204     const Sphere& boundingSphere() const { return mSphere; }
    00205
    00207     const AABB& boundingBoxSafe() { computeBounds(); return mAABB; }
    00208
    00210     const Sphere& boundingSphereSafe() { computeBounds(); return mSphere; }
    00211
    00213     void computeBounds();
    00214
    00216     bool boundsDirty() const;
    00217
    00227     void setRenderRank(int rank) { mRenderRank = rank; }
    00228
    00239     void setRenderBlock(int block) { mRenderBlock = block; }
    00240
    00242     int renderRank() const { return mRenderRank; }
    00243
    00245     int renderBlock() const { return mRenderBlock; }
    00246
    00248     void setLODEvaluator(LODEvaluator* lod_evaluator) { mLODEvaluator = lod_evaluator; }
    00249
    00251     LODEvaluator* lodEvaluator() { return mLODEvaluator.get(); }
    00252
    00254     const LODEvaluator* lodEvaluator() const { return mLODEvaluator.get(); }
    00255
    00256     int evaluateLOD(Camera* camera);
    00257
    00260     void setEnableMask(unsigned int mask) { mEnableMask = mask; }
    00261
    00264     unsigned int enableMask() const { return mEnableMask; }
    00265
    00266     // uniforms methods
    00267
    00271     void setUniform(Uniform* uniform);
    00272
    00276     const std::vector< ref<Uniform> >& uniforms() const;
    00277
    00281     std::vector< ref<Uniform> >& uniforms();
    00282
    00286     void eraseUniform(const std::string& name);
    00287
    00291     void eraseUniform(const Uniform* uniform);
    00292
    00296     void eraseAllUniforms();
    00297
    00301     Uniform* gocUniform(const std::string& name);
    00302
    00306     Uniform* getUniform(const std::string& name);
    00307
    00311     const Uniform* getUniform(const std::string& name) const;
    00312
    00321     void setUniformSet(UniformSet* uniforms) { mUniformSet = uniforms; }
    00322
    00332     const UniformSet* getUniformSet() const { return mUniformSet.get(); }
    00333
    00343     UniformSet* getUniformSet() { return mUniformSet.get(); }
    00344
    00354     UniformSet* gocUniformSet() { if (!mUniformSet) mUniformSet = new UniformSet; return mUniformSet.get(); }
    00355
    00357     const Collection<ActorEventCallback>* actorEventCallbacks() const { return &mActorEventCallbacks; }
    00358
    00360     Collection<ActorEventCallback>* actorEventCallbacks() { return &mActorEventCallbacks; }
    00361
    00363     void dispatchOnActorRenderStarted( Real frame_clock, const Camera* camera, Renderable* renderable, const Shader* shader, int pass)
    00364     {
    00365       for(int i=0; i<actorEventCallbacks()->size(); ++i)
    00366       {
    00367         ActorEventCallback& cb = *actorEventCallbacks()->at(i);
    00368         if (cb.isEnabled())
    00369           cb.onActorRenderStarted(this, frame_clock, camera, renderable, shader, pass);
    00370       }
    00371     }
    00372
    00374     void dispatchOnActorDelete()
    00375     {
    00376       for(int i=0; i<actorEventCallbacks()->size(); ++i)
    00377       {
    00378         ActorEventCallback& cb = *actorEventCallbacks()->at(i);
    00379         cb.onActorDelete(this);
    00380       }
    00381     }
    00382
    00391     void setScissor(Scissor* scissor) { mScissor = scissor; }
    00398     const Scissor* scissor() const { return mScissor.get(); }
    00399
    00406     Scissor* scissor() { return mScissor.get(); }
    00407
    00410     void setOccludee(bool is_occludee) { mIsOccludee = is_occludee; }
    00411
    00414     bool isOccludee() const { return mIsOccludee; }
    00415
    00418     void createOcclusionQuery();
    00419
    00422     void deleteOcclusionQuery();
    00423
    00426     GLuint occlusionQuery() const { return mOcclusionQuery; }
    00427
    00429     void setOcclusionQueryTick(unsigned tick) { mOcclusionQueryTick = tick; }
    00430
    00432     unsigned occlusionQueryTick() const { return mOcclusionQueryTick; }
    00433
    00434 #if VL_ACTOR_USER_DATA
    00435   public:
    00436     void* actorUserData() { return mActorUserData; }
    00437     const void* actorUserData() const { return mActorUserData; }
    00438     void setActorUserData(void* user_data) { mActorUserData = user_data; }
    00439
    00440   private:
    00441     void* mActorUserData;
    00442 #endif
    00443
    00444   protected:
    00445     AABB mAABB;
    00446     Sphere mSphere;
    00447     ref<Effect> mEffect;
    00448     ref<Renderable> mRenderables[VL_MAX_ACTOR_LOD];
    00449     ref<Transform> mTransform;
    00450     ref<LODEvaluator> mLODEvaluator;
    00451     ref<UniformSet> mUniformSet;
    00452     ref<Scissor> mScissor;
    00453     Collection<ActorEventCallback> mActorEventCallbacks;
    00454     int mRenderBlock;
    00455     int mRenderRank;
    00456     long long mTransformUpdateTick;
    00457     long long mBoundsUpdateTick;
    00458     unsigned int mEnableMask;
    00459     GLuint mOcclusionQuery;
    00460     bool mIsOccludee;
    00461     unsigned mOcclusionQueryTick;
    00462   };
    00463   //---------------------------------------------------------------------------
    00465   class ActorCollection: public Collection<Actor> {};
    00466   //---------------------------------------------------------------------------
    00467 }
    00468
    00469 #endif

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:22.
Permission is granted to use this page to write and publish articles regarding Visualization Library.