# 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/init_graphics.cpp

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 #include <vlCore/VisualizationLibrary.hpp>
    00033 #include <vlCore/LoadWriterManager.hpp>
    00034 #include <vlGraphics/Rendering.hpp>
    00035 #include <vlGraphics/BezierSurface.hpp>
    00036 #include <vlGraphics/FontManager.hpp>
    00037
    00038 using namespace vl;
    00039
    00040 #if defined(VL_IO_3D_VLX)
    00041   #include "plugins/ioVLX.hpp"
    00042 #include <vlGraphics/VLXWrappers.hpp>
    00043 #endif
    00044 #if defined(VL_IO_3D_3DS)
    00045   #include "plugins/io3DS.hpp"
    00046 #endif
    00047 #if defined(VL_IO_3D_OBJ)
    00048   #include "plugins/ioOBJ.hpp"
    00049 #endif
    00050 #if defined(VL_IO_3D_AC3D)
    00051   #include "plugins/ioAC3D.hpp"
    00052 #endif
    00053 #if defined(VL_IO_3D_PLY)
    00054   #include "plugins/ioPLY.hpp"
    00055 #endif
    00056 #if defined(VL_IO_3D_STL)
    00057   #include "plugins/ioSTL.hpp"
    00058 #endif
    00059 #if defined(VL_IO_3D_MD2)
    00060   #include "plugins/ioMD2.hpp"
    00061 #endif
    00062 #if defined(VL_IO_3D_COLLADA)
    00063   #include "plugins/COLLADA/ioDae.hpp"
    00064 #endif
    00065
    00066 //------------------------------------------------------------------------------
    00067 // VL misc
    00068 //------------------------------------------------------------------------------
    00069 namespace
    00070 {
    00071   bool gInitializedGraphics = false;
    00072 };
    00073 //-----------------------------------------------------------------------------
    00074 // Default FontManager
    00075 //-----------------------------------------------------------------------------
    00076 namespace
    00077 {
    00078   ref<FontManager> gDefaultFontManager = NULL;
    00079 }
    00080 FontManager* vl::defFontManager()
    00081 {
    00082   return gDefaultFontManager.get();
    00083 }
    00084 void vl::setDefFontManager(FontManager* fm)
    00085 {
    00086   gDefaultFontManager = fm;
    00087 }
    00088 //-----------------------------------------------------------------------------
    00089 #if defined(VL_IO_3D_VLX)
    00090 namespace
    00091 {
    00092   void registerVLXWrappers()
    00093   {
    00094     // Geometry serializer
    00095     defVLXRegistry()->registerClassWrapper( Geometry::Type(), new VLXClassWrapper_Geometry );
    00096
    00097     // VertexAttribInfo
    00098     defVLXRegistry()->registerClassWrapper( VertexAttribInfo::Type(), new VLXClassWrapper_VertexAttribInfo );
    00099
    00100     // BezierSurface
    00101     defVLXRegistry()->registerClassWrapper( BezierSurface::Type(), new VLXClassWrapper_Geometry );
    00102
    00103     // PatchParameter
    00104     defVLXRegistry()->registerClassWrapper( PatchParameter::Type(), new VLXClassWrapper_PatchParameter );
    00105
    00106     // DrawCall
    00107     ref<VLXClassWrapper_DrawCall> drawcall_serializer = new VLXClassWrapper_DrawCall;
    00108     defVLXRegistry()->registerClassWrapper( DrawArrays::Type(), drawcall_serializer.get() );
    00109     defVLXRegistry()->registerClassWrapper( DrawElementsUInt::Type(), drawcall_serializer.get() );
    00110     defVLXRegistry()->registerClassWrapper( DrawElementsUShort::Type(), drawcall_serializer.get() );
    00111     defVLXRegistry()->registerClassWrapper( DrawElementsUByte::Type(), drawcall_serializer.get() );
    00112     defVLXRegistry()->registerClassWrapper( MultiDrawElementsUInt::Type(), drawcall_serializer.get() );
    00113     defVLXRegistry()->registerClassWrapper( MultiDrawElementsUShort::Type(), drawcall_serializer.get() );
    00114     defVLXRegistry()->registerClassWrapper( MultiDrawElementsUByte::Type(), drawcall_serializer.get() );
    00115
    00116     // ResourceDatabase
    00117     defVLXRegistry()->registerClassWrapper( ResourceDatabase::Type(), new VLXClassWrapper_ResourceDatabase );
    00118
    00119     // Uniform
    00120     defVLXRegistry()->registerClassWrapper( Uniform::Type(), new VLXClassWrapper_Uniform );
    00121
    00122     // LODEvaluator
    00123     defVLXRegistry()->registerClassWrapper( LODEvaluator::Type(), new VLXClassWrapper_LODEvaluator );
    00124
    00125     // Transform
    00126     defVLXRegistry()->registerClassWrapper( Transform::Type(), new VLXClassWrapper_Transform );
    00127
    00128     // Material
    00129     defVLXRegistry()->registerClassWrapper( Material::Type(), new VLXClassWrapper_Material );
    00130
    00131     // Texture
    00132     defVLXRegistry()->registerClassWrapper( Texture::Type(), new VLXClassWrapper_Texture );
    00133
    00134     // TextureSampler
    00135     defVLXRegistry()->registerClassWrapper( TextureSampler::Type(), new VLXClassWrapper_TextureSampler );
    00136
    00137     // TexParameter
    00138     defVLXRegistry()->registerClassWrapper( TexParameter::Type(), new VLXClassWrapper_TexParameter );
    00139
    00140     // ActorEventCallback
    00141     defVLXRegistry()->registerClassWrapper( DepthSortCallback::Type(), new VLXClassWrapper_ActorEventCallback );
    00142
    00143     // LODEvaluator
    00144     ref<VLXClassWrapper_LODEvaluator> lod_evaluator = new VLXClassWrapper_LODEvaluator;
    00145     defVLXRegistry()->registerClassWrapper( PixelLODEvaluator::Type(), lod_evaluator.get() );
    00146     defVLXRegistry()->registerClassWrapper( DistanceLODEvaluator::Type(), lod_evaluator.get() );
    00147
    00148     // Actor
    00149     defVLXRegistry()->registerClassWrapper( Actor::Type(), new VLXClassWrapper_Actor );
    00150
    00151     // Effect
    00152     defVLXRegistry()->registerClassWrapper( Effect::Type(), new VLXClassWrapper_Effect );
    00153
    00154     // Shader
    00155     defVLXRegistry()->registerClassWrapper( Shader::Type(), new VLXClassWrapper_Shader );
    00156
    00157     // Camera
    00158     defVLXRegistry()->registerClassWrapper( Camera::Type(), new VLXClassWrapper_Camera );
    00159
    00160     // Light
    00161     defVLXRegistry()->registerClassWrapper( Light::Type(), new VLXClassWrapper_Light );
    00162
    00163     // ClipPlane
    00164     defVLXRegistry()->registerClassWrapper( ClipPlane::Type(), new VLXClassWrapper_ClipPlane );
    00165
    00166     // Color
    00167     defVLXRegistry()->registerClassWrapper( Color::Type(), new VLXClassWrapper_Color );
    00168
    00169     // SecondaryColor
    00170     defVLXRegistry()->registerClassWrapper( SecondaryColor::Type(), new VLXClassWrapper_SecondaryColor );
    00171
    00172     // Normal
    00173     defVLXRegistry()->registerClassWrapper( Normal::Type(), new VLXClassWrapper_Normal );
    00174
    00175     // VertexAttrib
    00176     defVLXRegistry()->registerClassWrapper( VertexAttrib::Type(), new VLXClassWrapper_VertexAttrib );
    00177
    00178     // Viewport
    00179     defVLXRegistry()->registerClassWrapper( Viewport::Type(), new VLXClassWrapper_Viewport );
    00180
    00181     // GLSL
    00182     defVLXRegistry()->registerClassWrapper( GLSLProgram::Type(), new VLXClassWrapper_GLSLProgram );
    00183     ref<VLXClassWrapper_GLSLShader> sh_serializer = new VLXClassWrapper_GLSLShader;
    00184     defVLXRegistry()->registerClassWrapper( GLSLVertexShader::Type(), sh_serializer.get() );
    00185     defVLXRegistry()->registerClassWrapper( GLSLFragmentShader::Type(), sh_serializer.get() );
    00186     defVLXRegistry()->registerClassWrapper( GLSLGeometryShader::Type(), sh_serializer.get() );
    00187     defVLXRegistry()->registerClassWrapper( GLSLTessControlShader::Type(), sh_serializer.get() );
    00188     defVLXRegistry()->registerClassWrapper( GLSLTessEvaluationShader::Type(), sh_serializer.get() );
    00189
    00190     // GLSLShader
    00191     defVLXRegistry()->registerClassWrapper( GLSLShader::Type(), new VLXClassWrapper_GLSLShader );
    00192
    00193     // Array serializer
    00194     ref<VLXClassWrapper_Array> array_serializer = new VLXClassWrapper_Array;
    00195
    00196     defVLXRegistry()->registerClassWrapper( ArrayFloat1::Type(), array_serializer.get() );
    00197     defVLXRegistry()->registerClassWrapper( ArrayFloat2::Type(), array_serializer.get() );
    00198     defVLXRegistry()->registerClassWrapper( ArrayFloat3::Type(), array_serializer.get() );
    00199     defVLXRegistry()->registerClassWrapper( ArrayFloat4::Type(), array_serializer.get() );
    00200
    00201     defVLXRegistry()->registerClassWrapper( ArrayDouble1::Type(), array_serializer.get() );
    00202     defVLXRegistry()->registerClassWrapper( ArrayDouble2::Type(), array_serializer.get() );
    00203     defVLXRegistry()->registerClassWrapper( ArrayDouble3::Type(), array_serializer.get() );
    00204     defVLXRegistry()->registerClassWrapper( ArrayDouble4::Type(), array_serializer.get() );
    00205
    00206     defVLXRegistry()->registerClassWrapper( ArrayInt1::Type(), array_serializer.get() );
    00207     defVLXRegistry()->registerClassWrapper( ArrayInt2::Type(), array_serializer.get() );
    00208     defVLXRegistry()->registerClassWrapper( ArrayInt3::Type(), array_serializer.get() );
    00209     defVLXRegistry()->registerClassWrapper( ArrayInt4::Type(), array_serializer.get() );
    00210
    00211     defVLXRegistry()->registerClassWrapper( ArrayUInt1::Type(), array_serializer.get() );
    00212     defVLXRegistry()->registerClassWrapper( ArrayUInt2::Type(), array_serializer.get() );
    00213     defVLXRegistry()->registerClassWrapper( ArrayUInt3::Type(), array_serializer.get() );
    00214     defVLXRegistry()->registerClassWrapper( ArrayUInt4::Type(), array_serializer.get() );
    00215
    00216     defVLXRegistry()->registerClassWrapper( ArrayShort1::Type(), array_serializer.get() );
    00217     defVLXRegistry()->registerClassWrapper( ArrayShort2::Type(), array_serializer.get() );
    00218     defVLXRegistry()->registerClassWrapper( ArrayShort3::Type(), array_serializer.get() );
    00219     defVLXRegistry()->registerClassWrapper( ArrayShort4::Type(), array_serializer.get() );
    00220
    00221     defVLXRegistry()->registerClassWrapper( ArrayUShort1::Type(), array_serializer.get() );
    00222     defVLXRegistry()->registerClassWrapper( ArrayUShort2::Type(), array_serializer.get() );
    00223     defVLXRegistry()->registerClassWrapper( ArrayUShort3::Type(), array_serializer.get() );
    00224     defVLXRegistry()->registerClassWrapper( ArrayUShort4::Type(), array_serializer.get() );
    00225
    00226     defVLXRegistry()->registerClassWrapper( ArrayByte1::Type(), array_serializer.get() );
    00227     defVLXRegistry()->registerClassWrapper( ArrayByte2::Type(), array_serializer.get() );
    00228     defVLXRegistry()->registerClassWrapper( ArrayByte3::Type(), array_serializer.get() );
    00229     defVLXRegistry()->registerClassWrapper( ArrayByte4::Type(), array_serializer.get() );
    00230
    00231     defVLXRegistry()->registerClassWrapper( ArrayUByte1::Type(), array_serializer.get() );
    00232     defVLXRegistry()->registerClassWrapper( ArrayUByte2::Type(), array_serializer.get() );
    00233     defVLXRegistry()->registerClassWrapper( ArrayUByte3::Type(), array_serializer.get() );
    00234     defVLXRegistry()->registerClassWrapper( ArrayUByte4::Type(), array_serializer.get() );
    00235   }
    00236 }
    00237 #endif
    00238 //------------------------------------------------------------------------------
    00239 void VisualizationLibrary::initGraphics()
    00240 {
    00241   VL_CHECK(!gInitializedGraphics);
    00242   if (gInitializedGraphics)
    00243   {
    00244     Log::bug("VisualizationLibrary::initGraphics(): Visualization Library Graphics is already initialized!\n");
    00245     return;
    00246   }
    00247
    00248   // --- Init Graphics ---
    00249
    00250   // Install default FontManager
    00251   gDefaultFontManager = new FontManager;
    00252
    00253   // Register 3D modules
    00254   #if defined(VL_IO_3D_VLX)
    00255     registerVLXWrappers();
    00256     registerLoadWriter(new LoadWriterVLX);
    00257   #endif
    00258   #if defined(VL_IO_3D_OBJ)
    00259     registerLoadWriter(new LoadWriterOBJ);
    00260   #endif
    00261   #if defined(VL_IO_3D_3DS)
    00262     registerLoadWriter(new LoadWriter3DS);
    00263   #endif
    00264   #if defined(VL_IO_3D_AC3D)
    00265     registerLoadWriter(new LoadWriterAC3D);
    00266   #endif
    00267   #if defined(VL_IO_3D_PLY)
    00268     registerLoadWriter(new LoadWriterPLY);
    00269   #endif
    00270   #if defined(VL_IO_3D_STL)
    00271     registerLoadWriter(new LoadWriterSTL);
    00272   #endif
    00273   #if defined(VL_IO_3D_MD2)
    00274     registerLoadWriter(new LoadWriterMD2);
    00275   #endif
    00276   #if defined(VL_IO_3D_COLLADA)
    00277     registerLoadWriter(new LoadWriterDae);
    00278   #endif
    00279
    00280   // ---
    00281
    00282   // Initialized = on
    00283   gInitializedGraphics = true;
    00284 }
    00285 //------------------------------------------------------------------------------
    00286 void VisualizationLibrary::shutdownGraphics()
    00287 {
    00288   if (gInitializedGraphics)
    00289   {
    00290     gInitializedGraphics = false;
    00291
    00292     // --- Dispose Graphics ---
    00293
    00294     // Dispose default FontManager
    00295     gDefaultFontManager->releaseAllFonts();
    00296     gDefaultFontManager = NULL;
    00297   }
    00298 }
    00299 //------------------------------------------------------------------------------
    00300 void VisualizationLibrary::init(bool log_info)
    00301 {
    00302   initCore(log_info);
    00303   initGraphics();
    00304 }
    00305 //------------------------------------------------------------------------------
    00306 void VisualizationLibrary::shutdown()
    00307 {
    00308   Log::debug("VisualizationLibrary::shutdown()\n");
    00309   shutdownGraphics();
    00310   shutdownCore();
    00311 }
    00312 //------------------------------------------------------------------------------
    00313 bool VisualizationLibrary::isGraphicsInitialized() { return gInitializedGraphics; }
    00314 //------------------------------------------------------------------------------

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