Visualization Library 2.0.0-b3

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
init_graphics.cpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2017, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
34 #include <vlGraphics/Rendering.hpp>
37 
38 using namespace vl;
39 
40 #if defined(VL_IO_3D_VLX)
41  #include "plugins/ioVLX.hpp"
43 #endif
44 #if defined(VL_IO_3D_3DS)
45  #include "plugins/io3DS.hpp"
46 #endif
47 #if defined(VL_IO_3D_OBJ)
48  #include "plugins/ioOBJ.hpp"
49 #endif
50 #if defined(VL_IO_3D_AC3D)
51  #include "plugins/ioAC3D.hpp"
52 #endif
53 #if defined(VL_IO_3D_PLY)
54  #include "plugins/ioPLY.hpp"
55 #endif
56 #if defined(VL_IO_3D_STL)
57  #include "plugins/ioSTL.hpp"
58 #endif
59 #if defined(VL_IO_3D_MD2)
60  #include "plugins/ioMD2.hpp"
61 #endif
62 #if defined(VL_IO_3D_COLLADA)
63  #include "plugins/COLLADA/ioDae.hpp"
64 #endif
65 
66 //------------------------------------------------------------------------------
67 // VL misc
68 //------------------------------------------------------------------------------
69 namespace
70 {
71  bool gInitializedGraphics = false;
72 };
73 //-----------------------------------------------------------------------------
74 // Default FontManager
75 //-----------------------------------------------------------------------------
76 namespace
77 {
78  ref<FontManager> gDefaultFontManager = NULL;
79 }
81 {
82  return gDefaultFontManager.get();
83 }
85 {
86  gDefaultFontManager = fm;
87 }
88 //-----------------------------------------------------------------------------
89 #if defined(VL_IO_3D_VLX)
90 namespace
91 {
92  void registerVLXWrappers()
93  {
94  // Geometry serializer
96 
97  // BezierSurface
98  defVLXRegistry()->registerClassWrapper( BezierSurface::Type(), new VLXClassWrapper_Geometry );
99 
100  // PatchParameter
101  defVLXRegistry()->registerClassWrapper( PatchParameter::Type(), new VLXClassWrapper_PatchParameter );
102 
103  // DrawCall
105  defVLXRegistry()->registerClassWrapper( DrawArrays::Type(), drawcall_serializer.get() );
106  defVLXRegistry()->registerClassWrapper( DrawElementsUInt::Type(), drawcall_serializer.get() );
107  defVLXRegistry()->registerClassWrapper( DrawElementsUShort::Type(), drawcall_serializer.get() );
108  defVLXRegistry()->registerClassWrapper( DrawElementsUByte::Type(), drawcall_serializer.get() );
109  defVLXRegistry()->registerClassWrapper( MultiDrawElementsUInt::Type(), drawcall_serializer.get() );
110  defVLXRegistry()->registerClassWrapper( MultiDrawElementsUShort::Type(), drawcall_serializer.get() );
111  defVLXRegistry()->registerClassWrapper( MultiDrawElementsUByte::Type(), drawcall_serializer.get() );
112 
113  // ResourceDatabase
114  defVLXRegistry()->registerClassWrapper( ResourceDatabase::Type(), new VLXClassWrapper_ResourceDatabase );
115 
116  // Uniform
118 
119  // LODEvaluator
120  defVLXRegistry()->registerClassWrapper( LODEvaluator::Type(), new VLXClassWrapper_LODEvaluator );
121 
122  // Transform
124 
125  // Material
127 
128  // Texture
130 
131  // TextureSampler
132  defVLXRegistry()->registerClassWrapper( TextureSampler::Type(), new VLXClassWrapper_TextureSampler );
133 
134  // TexParameter
135  defVLXRegistry()->registerClassWrapper( TexParameter::Type(), new VLXClassWrapper_TexParameter );
136 
137  // ActorEventCallback
138  defVLXRegistry()->registerClassWrapper( DepthSortCallback::Type(), new VLXClassWrapper_ActorEventCallback );
139 
140  // LODEvaluator
142  defVLXRegistry()->registerClassWrapper( PixelLODEvaluator::Type(), lod_evaluator.get() );
143  defVLXRegistry()->registerClassWrapper( DistanceLODEvaluator::Type(), lod_evaluator.get() );
144 
145  // Actor
147 
148  // Effect
150 
151  // Shader
153 
154  // Camera
156 
157  // Light
159 
160  // ClipPlane
162 
163  // Color
165 
166  // SecondaryColor
167  defVLXRegistry()->registerClassWrapper( SecondaryColor::Type(), new VLXClassWrapper_SecondaryColor );
168 
169  // Normal
171 
172  // VertexAttrib
173  defVLXRegistry()->registerClassWrapper( VertexAttrib::Type(), new VLXClassWrapper_VertexAttrib );
174 
175  // Viewport
177 
178  // GLSL
179  defVLXRegistry()->registerClassWrapper( GLSLProgram::Type(), new VLXClassWrapper_GLSLProgram );
181  defVLXRegistry()->registerClassWrapper( GLSLVertexShader::Type(), sh_serializer.get() );
182  defVLXRegistry()->registerClassWrapper( GLSLFragmentShader::Type(), sh_serializer.get() );
183  defVLXRegistry()->registerClassWrapper( GLSLGeometryShader::Type(), sh_serializer.get() );
184  defVLXRegistry()->registerClassWrapper( GLSLTessControlShader::Type(), sh_serializer.get() );
185  defVLXRegistry()->registerClassWrapper( GLSLTessEvaluationShader::Type(), sh_serializer.get() );
186 
187  // GLSLShader
188  defVLXRegistry()->registerClassWrapper( GLSLShader::Type(), new VLXClassWrapper_GLSLShader );
189 
190  // Array serializer
191  ref<VLXClassWrapper_Array> array_serializer = new VLXClassWrapper_Array;
192 
193  defVLXRegistry()->registerClassWrapper( ArrayFloat1::Type(), array_serializer.get() );
194  defVLXRegistry()->registerClassWrapper( ArrayFloat2::Type(), array_serializer.get() );
195  defVLXRegistry()->registerClassWrapper( ArrayFloat3::Type(), array_serializer.get() );
196  defVLXRegistry()->registerClassWrapper( ArrayFloat4::Type(), array_serializer.get() );
197 
198  defVLXRegistry()->registerClassWrapper( ArrayDouble1::Type(), array_serializer.get() );
199  defVLXRegistry()->registerClassWrapper( ArrayDouble2::Type(), array_serializer.get() );
200  defVLXRegistry()->registerClassWrapper( ArrayDouble3::Type(), array_serializer.get() );
201  defVLXRegistry()->registerClassWrapper( ArrayDouble4::Type(), array_serializer.get() );
202 
203  defVLXRegistry()->registerClassWrapper( ArrayInt1::Type(), array_serializer.get() );
204  defVLXRegistry()->registerClassWrapper( ArrayInt2::Type(), array_serializer.get() );
205  defVLXRegistry()->registerClassWrapper( ArrayInt3::Type(), array_serializer.get() );
206  defVLXRegistry()->registerClassWrapper( ArrayInt4::Type(), array_serializer.get() );
207 
208  defVLXRegistry()->registerClassWrapper( ArrayUInt1::Type(), array_serializer.get() );
209  defVLXRegistry()->registerClassWrapper( ArrayUInt2::Type(), array_serializer.get() );
210  defVLXRegistry()->registerClassWrapper( ArrayUInt3::Type(), array_serializer.get() );
211  defVLXRegistry()->registerClassWrapper( ArrayUInt4::Type(), array_serializer.get() );
212 
213  defVLXRegistry()->registerClassWrapper( ArrayShort1::Type(), array_serializer.get() );
214  defVLXRegistry()->registerClassWrapper( ArrayShort2::Type(), array_serializer.get() );
215  defVLXRegistry()->registerClassWrapper( ArrayShort3::Type(), array_serializer.get() );
216  defVLXRegistry()->registerClassWrapper( ArrayShort4::Type(), array_serializer.get() );
217 
218  defVLXRegistry()->registerClassWrapper( ArrayUShort1::Type(), array_serializer.get() );
219  defVLXRegistry()->registerClassWrapper( ArrayUShort2::Type(), array_serializer.get() );
220  defVLXRegistry()->registerClassWrapper( ArrayUShort3::Type(), array_serializer.get() );
221  defVLXRegistry()->registerClassWrapper( ArrayUShort4::Type(), array_serializer.get() );
222 
223  defVLXRegistry()->registerClassWrapper( ArrayByte1::Type(), array_serializer.get() );
224  defVLXRegistry()->registerClassWrapper( ArrayByte2::Type(), array_serializer.get() );
225  defVLXRegistry()->registerClassWrapper( ArrayByte3::Type(), array_serializer.get() );
226  defVLXRegistry()->registerClassWrapper( ArrayByte4::Type(), array_serializer.get() );
227 
228  defVLXRegistry()->registerClassWrapper( ArrayUByte1::Type(), array_serializer.get() );
229  defVLXRegistry()->registerClassWrapper( ArrayUByte2::Type(), array_serializer.get() );
230  defVLXRegistry()->registerClassWrapper( ArrayUByte3::Type(), array_serializer.get() );
231  defVLXRegistry()->registerClassWrapper( ArrayUByte4::Type(), array_serializer.get() );
232  }
233 }
234 #endif
235 //------------------------------------------------------------------------------
236 void VisualizationLibrary::initGraphics()
237 {
238  VL_CHECK(!gInitializedGraphics);
239  if (gInitializedGraphics)
240  {
241  Log::bug("VisualizationLibrary::initGraphics(): Visualization Library Graphics is already initialized!\n");
242  return;
243  }
244 
245  // --- Init Graphics ---
246 
247  // Install default FontManager
248  gDefaultFontManager = new FontManager;
249 
250  // Register 3D modules
251  #if defined(VL_IO_3D_VLX)
252  registerVLXWrappers();
254  #endif
255  #if defined(VL_IO_3D_OBJ)
257  #endif
258  #if defined(VL_IO_3D_3DS)
260  #endif
261  #if defined(VL_IO_3D_AC3D)
263  #endif
264  #if defined(VL_IO_3D_PLY)
266  #endif
267  #if defined(VL_IO_3D_STL)
269  #endif
270  #if defined(VL_IO_3D_MD2)
272  #endif
273  #if defined(VL_IO_3D_COLLADA)
275  #endif
276 
277  // ---
278 
279  // Initialized = on
280  gInitializedGraphics = true;
281 }
282 //------------------------------------------------------------------------------
283 void VisualizationLibrary::shutdownGraphics()
284 {
285  if (gInitializedGraphics)
286  {
287  gInitializedGraphics = false;
288 
289  // --- Dispose Graphics ---
290 
291  // Dispose default FontManager
292  gDefaultFontManager->releaseAllFonts();
293  gDefaultFontManager = NULL;
294  }
295 }
296 //------------------------------------------------------------------------------
297 void VisualizationLibrary::init(bool log_info)
298 {
299  initCore(log_info);
300  initGraphics();
301 }
302 //------------------------------------------------------------------------------
304 {
305  Log::debug("VisualizationLibrary::shutdown()\n");
306  shutdownGraphics();
307  shutdownCore();
308 }
309 //------------------------------------------------------------------------------
310 bool VisualizationLibrary::isGraphicsInitialized() { return gInitializedGraphics; }
311 //------------------------------------------------------------------------------
static void debug(const String &message)
Use this function to provide extra information useful to investigate and solve problems.
Definition: Log.cpp:144
The FontManager class keeps a map associating a font path, size and smoothing flag to a Font object...
Definition: FontManager.hpp:45
VLX wrapper of vl::Shader.
VLX wrapper of vl::Viewport.
VLX wrapper of vl::Geometry.
VLCORE_EXPORT VLXRegistry * defVLXRegistry()
Definition: init_core.cpp:168
VLX wrapper of vl::TextureSampler.
A ResourceLoadWriter capable of reading Visualization Library&#39;s VLT and VLB files.
Definition: ioVLX.hpp:82
const T * get() const
Definition: Object.hpp:128
static VLCORE_EXPORT void initCore(bool log_info=true)
Initializes only VLCore library.
Definition: init_core.cpp:192
VLX wrapper of vl::DrawCall and subclasses.
The LoadWriterMD2 class is a ResourceLoadWriter capable of reading MD2 files.
Definition: ioMD2.hpp:52
VLX wrapper of vl::Array.
Definition: VLXWrappers.hpp:58
VLX wrapper of vl::Light.
VLX wrapper of vl::ClipPlane.
static VLGRAPHICS_EXPORT void shutdown()
Releases all the resources acquired by VLCore and VLGraphics.
VLX wrapper of vl::TexParameter.
VLX wrapper of vl::DepthSortCallback.
VLGRAPHICS_EXPORT void setDefFontManager(FontManager *)
Sets the default FontManager used by Visualization Library.
VLX wrapper of vl::PatchParameter.
VLX wrapper of vl::GLSLProgram.
VLX wrapper of vl::DistanceLODEvaluator and vl::PixelLODEvaluator.
The LoadWriterPLY class is a ResourceLoadWriter capable of reading PLY files.
Definition: ioPLY.hpp:56
void registerClassWrapper(const TypeInfo &type, VLXClassWrapper *wrapper)
Definition: VLXRegistry.hpp:47
The LoadWriterAC3D class is a ResourceLoadWriter capable of reading AC3D files.
Definition: ioAC3D.hpp:73
Visualization Library main namespace.
VLX wrapper of vl::Uniform.
The LoadWriterDae class is a ResourceLoadWriter capable of reading COLLADA files. ...
Definition: ioDae.hpp:48
VLX wrapper of vl::GLSLVertexShader, vl::GLSLFragmentShader, vl::GLSLGeometryShader, vl::GLSLTessControlShader, vl::GLSLTessEvaluationShader.
static VLGRAPHICS_EXPORT void init(bool log_info=true)
Initializes VLCore and VLGraphics libraries.
static VLCORE_EXPORT void shutdownCore()
Releases all the resources acquired by Visualization Library Core Call shutdownCore() instead of shut...
Definition: init_core.cpp:261
static void bug(const String &message)
Use this function to provide information about programming errors: wrong parameter initialization...
Definition: Log.cpp:174
static VLGRAPHICS_EXPORT bool isGraphicsInitialized()
Returns true if VLGraphics library is initialized and shutdown has not been called.
The LoadWriterOBJ class is a ResourceLoadWriter capable of reading OBJ files.
Definition: ioOBJ.hpp:57
VLX wrapper of vl::Actor.
VLX wrapper of vl::Transform.
VLX wrapper of vl::Camera.
#define NULL
Definition: OpenGLDefs.hpp:81
VLX wrapper of vl::VertexAttrib.
VLX wrapper of vl::SecondaryColor.
VLX wrapper of vl::Effect.
VLX wrapper of vl::Color.
VLX wrapper of vl::Texture.
VLX wrapper of vl::Normal.
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
The LoadWriterSTL class is a ResourceLoadWriter capable of reading STL files.
Definition: ioSTL.hpp:56
#define VL_CHECK(expr)
Definition: checks.hpp:73
VLX wrapper of vl::ResourceDatabase.
VLGRAPHICS_EXPORT FontManager * defFontManager()
Returns the default FontManager used by Visualization Library.
void registerLoadWriter(ResourceLoadWriter *rlw)
Utility function, equivalent to defLoadWriterManager()->registerLoadWriter(rlw).
VLX wrapper of vl::Material.
The LoadWriter3DS class is a ResourceLoadWriter capable of reading 3DS files.
Definition: io3DS.hpp:57