# Visualization Library

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

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

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/GeometryLoadCallback.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.com                                               */
    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   public:
    00048     GeometryLoadCallback()
    00049     {
    00050       mTransformGeometry = false;
    00051       mDiscardOriginalNormals = false;
    00052       mComputeNormals  = true;
    00053       mRemoveDoubles   = false;
    00054       mSortVertices    = false;
    00055       mStripfy         = false;
    00056       mConvertToDrawArrays = false;
    00057       mUseDisplayLists = false;
    00058       mUseVBOs         = true;
    00059     }
    00060     virtual const char* className() { return "vl::GeometryLoadCallback"; }
    00061
    00062     void operator()(ResourceDatabase* db)
    00063     {
    00064       if (stripfy())
    00065         setRemoveDoubles(true);
    00066
    00067       std::vector< vl::ref<vl::Geometry> > geom;
    00068       db->get<Geometry>(geom);
    00069       for(unsigned int i=0; i<geom.size(); ++i)
    00070       {
    00071         if (discardOriginalNormals())
    00072           geom[i]->setNormalArray(NULL);
    00073
    00074         if (computeNormals() && !geom[i]->normalArray())
    00075           geom[i]->computeNormals();
    00076
    00077         if (removeDoubles())
    00078           DoubleVertexRemover().removeDoubles(geom[i].get());
    00079
    00080         if (sortVertices())
    00081           geom[i]->sortVertices();
    00082
    00083         if (stripfy())
    00084           TriangleStripGenerator().stripfy(geom[i].get(), 22, true, false, true);
    00085
    00086         if (convertToDrawArrays())
    00087           geom[i]->convertDrawCallToDrawArrays();
    00088
    00089         geom[i]->setDisplayListEnabled(useDisplayLists());
    00090         geom[i]->setVBOEnabled(useVBOs());
    00091
    00092         if (transformGeometry())
    00093           geom[i]->transform(transformMatrix(),true);
    00094       }
    00095     }
    00096
    00098     bool discardOriginalNormals() const { return mDiscardOriginalNormals; }
    00100     void setDiscardOriginalNormals(bool on) { mDiscardOriginalNormals = on; }
    00101
    00103     bool computeNormals() const { return mComputeNormals; }
    00105     void setComputeNormals(bool cn) { mComputeNormals = cn; }
    00106
    00108     bool removeDoubles() const { return mRemoveDoubles; }
    00110     void setRemoveDoubles(bool rd) { mRemoveDoubles = rd; }
    00111
    00113     void setSortVertices(bool on) { mSortVertices = on; }
    00115     bool sortVertices() const { return mSortVertices; }
    00116
    00118     void setStripfy(bool on) { mStripfy = on; }
    00120     bool stripfy() const { return mStripfy; }
    00121
    00123     bool convertToDrawArrays() const { return mConvertToDrawArrays; }
    00125     void setConvertToDrawArrays(bool on) { mConvertToDrawArrays = on; }
    00126
    00128     void setUseDisplayLists(bool on) { mUseDisplayLists = on; }
    00130     bool useDisplayLists() const { return mUseDisplayLists; }
    00131
    00133     void setUseVBOs(bool on) { mUseVBOs = on; }
    00135     bool useVBOs() const { return mUseVBOs; }
    00136
    00137     const mat4& transformMatrix() const { return mMatrix; }
    00138     void setTransformMatrix(const mat4& m) { mMatrix = m; }
    00139
    00141     bool transformGeometry() const { return mTransformGeometry; }
    00143     void setTransformGeometry(bool on) { mTransformGeometry = on; }
    00144
    00145   protected:
    00146     mat4 mMatrix;
    00147     bool mTransformGeometry;
    00148     bool mDiscardOriginalNormals;
    00149     bool mComputeNormals;
    00150     bool mRemoveDoubles;
    00151     bool mSortVertices;
    00152     bool mStripfy;
    00153     bool mConvertToDrawArrays;
    00154     bool mUseDisplayLists;
    00155     bool mUseVBOs;
    00156   };
    00157 }
    00158
    00159 #endif

Visualization Library v2011.05.1142 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu May 26 2011 22:51:23.
Permission is granted to use this page to write and publish articles regarding Visualization Library.