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 GeometryLoadCallback_INCLUDE_ONCE 00033 #define GeometryLoadCallback_INCLUDE_ONCE 00034 00035 #include <vlGraphics/Geometry.hpp> 00036 #include <vlGraphics/TriangleStripGenerator.hpp> 00037 #include <vlGraphics/DoubleVertexRemover.hpp> 00038 #include <vlCore/LoadWriterManager.hpp> 00039 00040 namespace vl 00041 { 00045 class GeometryLoadCallback: public LoadCallback 00046 { 00047 VL_INSTRUMENT_CLASS(vl::GeometryLoadCallback, LoadCallback) 00048 00049 public: 00050 GeometryLoadCallback() 00051 { 00052 mMakeGLESFriendly = false; 00053 mComputeNormals = true; 00054 mUseBufferObjects = true; 00055 mUseDisplayLists = false; 00056 mTransformGeometry = false; 00057 mDiscardOriginalNormals = false; 00058 mRemoveDoubles = false; 00059 mSortVertices = false; 00060 mStripfy = false; 00061 mConvertToDrawArrays = false; 00062 } 00063 00064 void operator()(ResourceDatabase* db) 00065 { 00066 if (stripfy()) 00067 setRemoveDoubles(true); 00068 00069 std::vector< vl::ref<vl::Geometry> > geom; 00070 db->get<Geometry>(geom); 00071 for(unsigned int i=0; i<geom.size(); ++i) 00072 { 00073 if (discardOriginalNormals()) 00074 geom[i]->setNormalArray(NULL); 00075 00076 if (computeNormals() && !geom[i]->normalArray()) 00077 geom[i]->computeNormals(); 00078 00079 if (removeDoubles()) 00080 DoubleVertexRemover().removeDoubles(geom[i].get()); 00081 00082 if (sortVertices()) 00083 geom[i]->sortVertices(); 00084 00085 if (stripfy()) 00086 TriangleStripGenerator().stripfy(geom[i].get(), 22, true, false, true); 00087 00088 if (convertToDrawArrays()) 00089 geom[i]->convertDrawCallToDrawArrays(); 00090 00091 geom[i]->setDisplayListEnabled(useDisplayLists()); 00092 geom[i]->setBufferObjectEnabled(useBufferObjects()); 00093 00094 if (transformGeometry()) 00095 geom[i]->transform(transformMatrix(),true); 00096 00097 if (makeGLESFriendly()) 00098 geom[i]->makeGLESFriendly(); 00099 } 00100 } 00101 00103 bool discardOriginalNormals() const { return mDiscardOriginalNormals; } 00105 void setDiscardOriginalNormals(bool on) { mDiscardOriginalNormals = on; } 00106 00108 bool computeNormals() const { return mComputeNormals; } 00110 void setComputeNormals(bool cn) { mComputeNormals = cn; } 00111 00113 bool removeDoubles() const { return mRemoveDoubles; } 00115 void setRemoveDoubles(bool rd) { mRemoveDoubles = rd; } 00116 00118 void setSortVertices(bool on) { mSortVertices = on; } 00120 bool sortVertices() const { return mSortVertices; } 00121 00123 void setStripfy(bool on) { mStripfy = on; } 00125 bool stripfy() const { return mStripfy; } 00126 00128 bool convertToDrawArrays() const { return mConvertToDrawArrays; } 00130 void setConvertToDrawArrays(bool on) { mConvertToDrawArrays = on; } 00131 00133 void setUseDisplayLists(bool on) { mUseDisplayLists = on; } 00135 bool useDisplayLists() const { return mUseDisplayLists; } 00136 00138 void setUseBufferObjects(bool on) { mUseBufferObjects = on; } 00140 bool useBufferObjects() const { return mUseBufferObjects; } 00141 00142 const mat4& transformMatrix() const { return mMatrix; } 00143 void setTransformMatrix(const mat4& m) { mMatrix = m; } 00144 00146 bool transformGeometry() const { return mTransformGeometry; } 00148 void setTransformGeometry(bool on) { mTransformGeometry = on; } 00149 00151 bool makeGLESFriendly() const { return mMakeGLESFriendly; } 00153 void setMakeGLESFriendly(bool on) { mMakeGLESFriendly = on; } 00154 00155 protected: 00156 mat4 mMatrix; 00157 bool mTransformGeometry; 00158 bool mDiscardOriginalNormals; 00159 bool mComputeNormals; 00160 bool mRemoveDoubles; 00161 bool mSortVertices; 00162 bool mStripfy; 00163 bool mConvertToDrawArrays; 00164 bool mUseDisplayLists; 00165 bool mUseBufferObjects; 00166 bool mMakeGLESFriendly; 00167 }; 00168 } 00169 00170 #endif