# Visualization Library

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

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

- Main Page
- Related Pages
- 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.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
    00265     void setEnableMask(unsigned int mask) { mEnableMask = mask; }
    00266
    00269     unsigned int enableMask() const { return mEnableMask; }
    00270
    00271     // uniforms methods
    00272
    00276     void setUniform(Uniform* uniform);
    00277
    00281     const std::vector< ref<Uniform> >& uniforms() const;
    00282
    00286     std::vector< ref<Uniform> >& uniforms();
    00287
    00291     void eraseUniform(const char* name);
    00292
    00296     void eraseUniform(const Uniform* uniform);
    00297
    00301     void eraseAllUniforms();
    00302
    00306     Uniform* gocUniform(const char* name);
    00307
    00311     Uniform* getUniform(const char* name);
    00312
    00316     const Uniform* getUniform(const char* name) const;
    00317
    00326     void setUniformSet(UniformSet* uniforms) { mUniformSet = uniforms; }
    00327
    00337     const UniformSet* getUniformSet() const { return mUniformSet.get(); }
    00338
    00348     UniformSet* getUniformSet() { return mUniformSet.get(); }
    00349
    00359     UniformSet* gocUniformSet() { if (!mUniformSet) mUniformSet = new UniformSet; return mUniformSet.get(); }
    00360
    00362     const Collection<ActorEventCallback>* actorEventCallbacks() const { return &mActorEventCallbacks; }
    00363
    00365     Collection<ActorEventCallback>* actorEventCallbacks() { return &mActorEventCallbacks; }
    00366
    00368     void dispatchOnActorRenderStarted( real frame_clock, const Camera* camera, Renderable* renderable, const Shader* shader, int pass)
    00369     {
    00370       for(int i=0; i<actorEventCallbacks()->size(); ++i)
    00371       {
    00372         ActorEventCallback& cb = *actorEventCallbacks()->at(i);
    00373         if (cb.isEnabled())
    00374           cb.onActorRenderStarted(this, frame_clock, camera, renderable, shader, pass);
    00375       }
    00376     }
    00377
    00379     void dispatchOnActorDelete()
    00380     {
    00381       for(int i=0; i<actorEventCallbacks()->size(); ++i)
    00382       {
    00383         ActorEventCallback& cb = *actorEventCallbacks()->at(i);
    00384         cb.onActorDelete(this);
    00385       }
    00386     }
    00387
    00396     void setScissor(Scissor* scissor) { mScissor = scissor; }
    00403     const Scissor* scissor() const { return mScissor.get(); }
    00404
    00411     Scissor* scissor() { return mScissor.get(); }
    00412
    00415     void setOccludee(bool is_occludee) { mIsOccludee = is_occludee; }
    00416
    00419     bool isOccludee() const { return mIsOccludee; }
    00420
    00423     void createOcclusionQuery();
    00424
    00427     void deleteOcclusionQuery();
    00428
    00431     GLuint occlusionQuery() const { return mOcclusionQuery; }
    00432
    00434     void setOcclusionQueryTick(unsigned tick) { mOcclusionQueryTick = tick; }
    00435
    00437     unsigned occlusionQueryTick() const { return mOcclusionQueryTick; }
    00438
    00439 #if VL_ACTOR_USER_DATA
    00440   public:
    00441     void* actorUserData() { return mActorUserData; }
    00442     const void* actorUserData() const { return mActorUserData; }
    00443     void setActorUserData(void* user_data) { mActorUserData = user_data; }
    00444
    00445   private:
    00446     void* mActorUserData;
    00447 #endif
    00448
    00449   protected:
    00450     AABB mAABB;
    00451     Sphere mSphere;
    00452     ref<Effect> mEffect;
    00453     ref<Renderable> mRenderables[VL_MAX_ACTOR_LOD];
    00454     ref<Transform> mTransform;
    00455     ref<LODEvaluator> mLODEvaluator;
    00456     ref<UniformSet> mUniformSet;
    00457     ref<Scissor> mScissor;
    00458     Collection<ActorEventCallback> mActorEventCallbacks;
    00459     int mRenderBlock;
    00460     int mRenderRank;
    00461     long long mTransformUpdateTick;
    00462     long long mBoundsUpdateTick;
    00463     unsigned int mEnableMask;
    00464     GLuint mOcclusionQuery;
    00465     unsigned mOcclusionQueryTick;
    00466     bool mIsOccludee;
    00467   };
    00468   //---------------------------------------------------------------------------
    00470   class ActorCollection: public Collection<Actor> {};
    00471   //---------------------------------------------------------------------------
    00472 }
    00473
    00474 #endif

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:35.
Permission is granted to use this page to write and publish articles regarding Visualization Library.