# 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/Effect.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 Effect_INCLUDE_ONCE
    00033 #define Effect_INCLUDE_ONCE
    00034
    00035 #include <vlGraphics/Renderable.hpp>
    00036 #include <vlGraphics/LODEvaluator.hpp>
    00037 #include <vlGraphics/Shader.hpp>
    00038 #include <vlCore/Collection.hpp>
    00039 #include <vector>
    00040
    00041 namespace vl
    00042 {
    00043   class Actor;
    00044   //------------------------------------------------------------------------------
    00045   // ShaderPasses
    00046   //------------------------------------------------------------------------------
    00051   class ShaderPasses: public Collection<Shader>
    00052   {
    00053     VL_INSTRUMENT_CLASS(vl::ShaderPasses, Collection<Shader>)
    00054
    00055   public:
    00062     ShaderPasses(Shader* pass1=NULL, Shader* pass2=NULL, Shader* pass3=NULL, Shader* pass4=NULL )
    00063     {
    00064       VL_DEBUG_SET_OBJECT_NAME()
    00065       if (pass1)
    00066         push_back(pass1);
    00067       if (pass2)
    00068         push_back(pass2);
    00069       if (pass3)
    00070         push_back(pass3);
    00071       if (pass4)
    00072         push_back(pass4);
    00073     }
    00074   };
    00075   //------------------------------------------------------------------------------
    00076   // Effect
    00077   //------------------------------------------------------------------------------
    00091   class VLGRAPHICS_EXPORT Effect: public Object
    00092   {
    00093     VL_INSTRUMENT_CLASS(vl::Effect, Object)
    00094
    00095     // use deepCopy() and shallowCopy() instead
    00096     Effect(const Effect&): Object() {}
    00097     Effect& operator=(const Effect&) { return *this; }
    00098
    00099   public:
    00101     Effect()
    00102     {
    00103       VL_DEBUG_SET_OBJECT_NAME()
    00104       mEnableMask = 0xFFFFFFFF;
    00105       mRenderRank = 0;
    00106       mActiveLod  = 0;
    00107       mLODShaders[0] = new ShaderPasses(new Shader);
    00108     }
    00109
    00110     ref<Effect> shallowCopy(EShaderCopyMode shader_copy) const
    00111     {
    00112       ref<Effect> fx = new Effect;
    00113       fx->shallowCopyFrom(*this, shader_copy);
    00114       return fx;
    00115     }
    00116
    00117     Effect& shallowCopyFrom(const Effect& other, EShaderCopyMode shader_copy)
    00118     {
    00119       for(int i=0; i<VL_MAX_EFFECT_LOD; ++i)
    00120         mLODShaders[i] = other.mLODShaders[i];
    00121
    00122       if (shader_copy == SCM_OwnShaders)
    00123       {
    00124         // create local shallow copies of all the Shaders
    00125         for(int lod=0; lod<VL_MAX_EFFECT_LOD; ++lod)
    00126           for(int pass=0; mLODShaders[lod] && pass<mLODShaders[lod]->size(); ++pass)
    00127             (*mLODShaders[lod])[pass] = (*mLODShaders[lod])[pass]->shallowCopy();
    00128       }
    00129
    00130       mLODEvaluator = other.mLODEvaluator;
    00131
    00132       mActiveLod = other.mActiveLod;
    00133       mRenderRank = other.mRenderRank;
    00134       mEnableMask = other.mEnableMask;
    00135
    00136       return *this;
    00137     }
    00138
    00139     ref<Effect> deepCopy() const
    00140     {
    00141       ref<Effect> fx = new Effect;
    00142       fx->deepCopyFrom(*this);
    00143       return fx;
    00144     }
    00145
    00146     Effect& deepCopyFrom(const Effect& other)
    00147     {
    00148       shallowCopyFrom(other, SCM_ShareShaders);
    00149
    00150       // create local clones of all the Shaders
    00151       for(int lod=0; lod<VL_MAX_EFFECT_LOD; ++lod)
    00152         for(int pass=0; mLODShaders[lod] && pass<mLODShaders[lod]->size(); ++pass)
    00153           (*mLODShaders[lod])[pass] = (*mLODShaders[lod])[pass]->deepCopy();
    00154
    00155       return *this;
    00156     }
    00157
    00164     void setRenderRank(int rank) { mRenderRank = rank; }
    00165
    00167     int renderRank() const { return mRenderRank; }
    00168
    00171     const ref<ShaderPasses>& lod(int lod_level) const { return mLODShaders[lod_level]; }
    00172
    00175     ref<ShaderPasses>& lod(int lod_level) { return mLODShaders[lod_level]; }
    00176
    00178     Shader* shader(int lodi=0, int pass=0) { return lod(lodi)->at(pass); }
    00179
    00181     const Shader* shader(int lodi=0, int pass=0) const { return lod(lodi)->at(pass); }
    00182
    00184     void setLOD(int lodi, Shader* shader1, Shader* shader2=NULL, Shader* shader3=NULL, Shader* shader4=NULL)
    00185     {
    00186       VL_CHECK(lodi<VL_MAX_EFFECT_LOD)
    00187       lod(lodi) = new ShaderPasses(shader1,shader2,shader3,shader4);
    00188     }
    00189
    00191     void setLODEvaluator(LODEvaluator* lod_evaluator) { mLODEvaluator = lod_evaluator; }
    00192
    00194     LODEvaluator* lodEvaluator() { return mLODEvaluator.get(); }
    00195
    00197     const LODEvaluator* lodEvaluator() const { return mLODEvaluator.get(); }
    00198
    00200     void setEnableMask(unsigned int mask) { mEnableMask = mask; }
    00201
    00203     unsigned int enableMask() const { return mEnableMask; }
    00204
    00206     int evaluateLOD(Actor* actor, Camera* camera);
    00207
    00209     void setActiveLod(int lod)
    00210     {
    00211       VL_CHECK( lod < VL_MAX_EFFECT_LOD )
    00212       VL_CHECK( lod >= 0 )
    00213       mActiveLod = lod;
    00214     }
    00215
    00217     int activeLod() const { return mActiveLod; }
    00218
    00219   protected:
    00220     ref<ShaderPasses> mLODShaders[VL_MAX_EFFECT_LOD];
    00221     ref<LODEvaluator> mLODEvaluator;
    00222     int mActiveLod;
    00223     int mRenderRank;
    00224     unsigned int mEnableMask;
    00225   };
    00226   //------------------------------------------------------------------------------
    00227 }
    00228
    00229 #endif

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