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-2011, 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 DrawCommand_INCLUDE_ONCE 00033 #define DrawCommand_INCLUDE_ONCE 00034 00035 #include <vlGraphics/Array.hpp> 00036 #include <vlGraphics/TriangleIterator.hpp> 00037 #include <vlGraphics/IndexIterator.hpp> 00038 #include <vlGraphics/PatchParameter.hpp> 00039 00040 namespace vl 00041 { 00042 //------------------------------------------------------------------------------ 00043 // DrawCall 00044 //------------------------------------------------------------------------------ 00090 class DrawCall: public Object 00091 { 00092 VL_INSTRUMENT_ABSTRACT_CLASS(vl::DrawCalls, Object) 00093 00094 public: 00096 DrawCall(): mType(PT_TRIANGLES), mEnabled(true) {} 00097 00099 DrawCall& operator=(const DrawCall& other) 00100 { 00101 mType = other.mType; 00102 mEnabled = other.mEnabled; 00103 return *this; 00104 } 00105 00107 void setPrimitiveType(EPrimitiveType type) { mType = type; } 00108 00110 EPrimitiveType primitiveType() const { return mType; } 00111 00113 virtual void render(bool use_bo = true) const = 0; 00114 00116 virtual ref<DrawCall> clone() const = 0; 00117 00119 virtual void updateDirtyBufferObject(EBufferObjectUpdateMode) = 0; 00120 00122 virtual void deleteBufferObject() = 0; 00123 00125 void setEnabled(bool enable) { mEnabled = enable; } 00126 00128 bool isEnabled() const { return mEnabled; } 00129 00134 virtual TriangleIterator triangleIterator() const = 0; 00135 00139 virtual IndexIterator indexIterator() const = 0; 00140 00142 u32 countIndices() const 00143 { 00144 u32 count = 0; 00145 for( IndexIterator it = indexIterator(); it.hasNext(); it.next() ) 00146 ++count; 00147 return count; 00148 } 00149 00151 u32 countTriangles() const 00152 { 00153 u32 count = 0; 00154 for( TriangleIterator it = triangleIterator(); it.hasNext(); it.next() ) 00155 ++count; 00156 return count; 00157 } 00158 00160 virtual int instances() const { return 1; } 00161 00163 virtual bool primitiveRestartEnabled() const { return false; } 00164 00166 virtual unsigned int primitiveRestartIndex() { return 0; } 00167 00169 void setPatchParameter(PatchParameter* patch_param) { mPatchParameter = patch_param; } 00170 00172 PatchParameter* patchParameter() { return mPatchParameter.get(); } 00173 00175 const PatchParameter* patchParameter() const { return mPatchParameter.get(); } 00176 00177 protected: 00178 void applyPatchParameters() const 00179 { 00180 if (mType == PT_PATCHES && mPatchParameter) 00181 mPatchParameter->apply(); 00182 00183 if (mPatchParameter && mType != PT_PATCHES) 00184 { 00185 vl::Log::warning("PatchParameter used with non PT_PATCHES draw call!\n"); 00186 } 00187 else 00188 if (!mPatchParameter && mType == PT_PATCHES) 00189 { 00190 vl::Log::warning("No PatchParameter supplied while using PT_PATCHES draw call!\n"); 00191 } 00192 } 00193 00194 protected: 00195 ref<PatchParameter> mPatchParameter; 00196 EPrimitiveType mType; 00197 bool mEnabled; 00198 }; 00199 } 00200 00201 #endif