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 #ifndef RendererAbstract_INCLUDE_ONCE 00033 #define RendererAbstract_INCLUDE_ONCE 00034 00035 #include <vlGraphics/link_config.hpp> 00036 #include <vlCore/Collection.hpp> 00037 #include <vlGraphics/RenderEventCallback.hpp> 00038 00039 namespace vl 00040 { 00041 class Camera; 00042 class RenderQueue; 00043 class Framebuffer; 00044 00045 //----------------------------------------------------------------------------- 00046 // RendererAbstract 00047 //----------------------------------------------------------------------------- 00051 class VLGRAPHICS_EXPORT RendererAbstract: public Object 00052 { 00053 VL_INSTRUMENT_ABSTRACT_CLASS(vl::RendererAbstract, Object) 00054 00055 public: 00056 RendererAbstract() 00057 { 00058 VL_DEBUG_SET_OBJECT_NAME() 00059 mOnStartedCallbacks = new Collection<RenderEventCallback>; 00060 mOnFinishedCallbacks = new Collection<RenderEventCallback>; 00061 mClearFlags = CF_CLEAR_COLOR_DEPTH; 00062 mEnableMask = 0xFFFFFFFF; 00063 mRenderTick = 0; 00064 mFrameClock = 0; 00065 } 00066 00067 RendererAbstract& operator=(const RendererAbstract& other) 00068 { 00069 *mOnStartedCallbacks = *other.mOnStartedCallbacks; 00070 *mOnFinishedCallbacks = *other.mOnFinishedCallbacks; 00071 mClearFlags = other.mClearFlags; 00072 mEnableMask = other.mEnableMask; 00073 /* mRenderTick = other.mRenderTick; */ // render-tick remains local 00074 /* mFrameClock = other.mFrameClock; */ // update time remains local 00075 return *this; 00076 } 00077 00080 virtual const RenderQueue* render(const RenderQueue* in_render_queue, Camera* camera, real frame_clock) = 0; 00081 00083 virtual const Framebuffer* framebuffer() const = 0; 00084 00086 virtual Framebuffer* framebuffer() = 0; 00087 00089 void dispatchOnRendererStarted() 00090 { 00091 Collection<RenderEventCallback>& cb = *mOnStartedCallbacks; 00092 for(int i=0; i<cb.size(); ++i) 00093 { 00094 if ( cb[i]->isEnabled() && cb[i]->onRendererStarted(this) && cb[i]->removeAfterCall() ) 00095 { 00096 onStartedCallbacks()->eraseAt( i ); 00097 --i; 00098 } 00099 } 00100 } 00101 00103 void dispatchOnRendererFinished() 00104 { 00105 Collection<RenderEventCallback>& cb = *mOnFinishedCallbacks; 00106 for(int i=0; i<cb.size(); ++i) 00107 { 00108 if ( cb[i]->isEnabled() && cb[i]->onRendererFinished(this) && cb[i]->removeAfterCall() ) 00109 { 00110 onFinishedCallbacks()->eraseAt( i ); 00111 --i; 00112 } 00113 } 00114 } 00115 00117 Collection<RenderEventCallback>* onFinishedCallbacks() { return mOnFinishedCallbacks.get(); } 00118 00120 const Collection<RenderEventCallback>* onFinishedCallbacks() const { return mOnFinishedCallbacks.get(); } 00121 00123 Collection<RenderEventCallback>* onStartedCallbacks() { return mOnStartedCallbacks.get(); } 00124 00126 const Collection<RenderEventCallback>* onStartedCallbacks() const { return mOnStartedCallbacks.get(); } 00127 00129 unsigned long renderTick() const { return mRenderTick; } 00130 00132 void incrementRenderTick() { ++mRenderTick; } 00133 00135 void setClearFlags(EClearFlags clear_flags) { mClearFlags = clear_flags; } 00136 00138 EClearFlags clearFlags() const { return mClearFlags; } 00139 00141 void setEnableMask(unsigned int mask) { mEnableMask = mask; } 00142 00144 unsigned int enableMask() const { return mEnableMask; } 00145 00147 void setFrameClock(real t) { mFrameClock = t; } 00148 00150 real frameClock() const { return mFrameClock; } 00151 00152 protected: 00153 ref< Collection<RenderEventCallback> > mOnFinishedCallbacks; 00154 ref< Collection<RenderEventCallback> > mOnStartedCallbacks; 00155 unsigned long mRenderTick; 00156 unsigned int mEnableMask; 00157 EClearFlags mClearFlags; 00158 real mFrameClock; 00159 }; 00160 //------------------------------------------------------------------------------ 00161 } 00162 00163 #endif