Visualization Library 2.1.0

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-2020, 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 #include <vlX/WrappersGraphics.hpp>
39 
40 #if defined(VL_IO_3D_3DS)
42 #endif
43 #if defined(VL_IO_3D_OBJ)
45 #endif
46 #if defined(VL_IO_3D_AC3D)
48 #endif
49 #if defined(VL_IO_3D_PLY)
51 #endif
52 #if defined(VL_IO_3D_STL)
54 #endif
55 #if defined(VL_IO_3D_MD2)
57 #endif
58 #if defined(VL_IO_3D_COLLADA)
60 #endif
61 
62 static void registerVLXGraphicsWrappers();
63 
64 using namespace vl;
65 
66 //------------------------------------------------------------------------------
67 namespace
68 {
69  bool gInitializedGraphics = false;
70 };
71 //------------------------------------------------------------------------------
72 void VisualizationLibrary::initGraphics()
73 {
74  VL_CHECK( ! gInitializedGraphics );
75  if (gInitializedGraphics) {
76  Log::bug("VisualizationLibrary::initGraphics(): Visualization Library Graphics is already initialized!\n");
77  return;
78  }
79 
80  // Install default FontManager
82 
83  // Register VLGraphics classes to VLX
84  registerVLXGraphicsWrappers();
85 
86  // Register VLGraphics modules
87 
88  #if defined(VL_IO_3D_OBJ)
90  #endif
91  #if defined(VL_IO_3D_3DS)
93  #endif
94  #if defined(VL_IO_3D_AC3D)
96  #endif
97  #if defined(VL_IO_3D_PLY)
99  #endif
100  #if defined(VL_IO_3D_STL)
102  #endif
103  #if defined(VL_IO_3D_MD2)
105  #endif
106  #if defined(VL_IO_3D_COLLADA)
108  #endif
109 
110  gInitializedGraphics = true;
111 }
112 //------------------------------------------------------------------------------
113 void VisualizationLibrary::shutdownGraphics()
114 {
115  if ( ! gInitializedGraphics ) {
116  Log::debug("VisualizationLibrary::shutdownGraphics(): VL Graphics not initialized.\n");
117  return;
118  }
119 
120  gInitializedGraphics = false;
121 
122  // Dispose default FontManager
123  if ( defFontManager() ) {
126  }
127 
128  Log::debug("VisualizationLibrary::shutdownGraphics()\n");
129 }
130 //------------------------------------------------------------------------------
131 void VisualizationLibrary::init(bool log_info)
132 {
133  initCore(log_info);
134  initGraphics();
135 }
136 //------------------------------------------------------------------------------
138 {
139  shutdownGraphics();
140  shutdownCore();
141 }
142 //------------------------------------------------------------------------------
143 bool VisualizationLibrary::isGraphicsInitialized() { return gInitializedGraphics; }
144 //------------------------------------------------------------------------------
145 void registerVLXGraphicsWrappers()
146 {
147  // Geometry serializer
149 
150  // BezierSurface
152 
153  // PatchParameter
155 
156  // DrawCall
158  vlX::defVLXRegistry()->registerClassWrapper( DrawArrays::Type(), drawcall_serializer.get() );
159  vlX::defVLXRegistry()->registerClassWrapper( DrawElementsUInt::Type(), drawcall_serializer.get() );
160  vlX::defVLXRegistry()->registerClassWrapper( DrawElementsUShort::Type(), drawcall_serializer.get() );
161  vlX::defVLXRegistry()->registerClassWrapper( DrawElementsUByte::Type(), drawcall_serializer.get() );
162  vlX::defVLXRegistry()->registerClassWrapper( MultiDrawElementsUInt::Type(), drawcall_serializer.get() );
163  vlX::defVLXRegistry()->registerClassWrapper( MultiDrawElementsUShort::Type(), drawcall_serializer.get() );
164  vlX::defVLXRegistry()->registerClassWrapper( MultiDrawElementsUByte::Type(), drawcall_serializer.get() );
165 
166  // ResourceDatabase
168 
169  // Uniform
171 
172  // LODEvaluator
174 
175  // Transform
177 
178  // Material
180 
181  // Texture
183 
184  // TextureImageUnit
186 
187  // TexParameter
189 
190  // ActorEventCallback
192 
193  // LODEvaluator
195  vlX::defVLXRegistry()->registerClassWrapper( PixelLODEvaluator::Type(), lod_evaluator.get() );
196  vlX::defVLXRegistry()->registerClassWrapper( DistanceLODEvaluator::Type(), lod_evaluator.get() );
197 
198  // Actor
200 
201  // Effect
203 
204  // Shader
206 
207  // Camera
209 
210  // Light
212 
213  // ClipPlane
215 
216  // Color
218 
219  // SecondaryColor
221 
222  // Normal
224 
225  // VertexAttrib
227 
228  // Viewport
230 
231  // GLSL
234  vlX::defVLXRegistry()->registerClassWrapper( GLSLVertexShader::Type(), sh_serializer.get() );
235  vlX::defVLXRegistry()->registerClassWrapper( GLSLFragmentShader::Type(), sh_serializer.get() );
236  vlX::defVLXRegistry()->registerClassWrapper( GLSLGeometryShader::Type(), sh_serializer.get() );
237  vlX::defVLXRegistry()->registerClassWrapper( GLSLTessControlShader::Type(), sh_serializer.get() );
238  vlX::defVLXRegistry()->registerClassWrapper( GLSLTessEvaluationShader::Type(), sh_serializer.get() );
239 
240  // GLSLShader
242 
243  // Array serializer
245 
246  vlX::defVLXRegistry()->registerClassWrapper( ArrayFloat1::Type(), array_serializer.get() );
247  vlX::defVLXRegistry()->registerClassWrapper( ArrayFloat2::Type(), array_serializer.get() );
248  vlX::defVLXRegistry()->registerClassWrapper( ArrayFloat3::Type(), array_serializer.get() );
249  vlX::defVLXRegistry()->registerClassWrapper( ArrayFloat4::Type(), array_serializer.get() );
250 
251  vlX::defVLXRegistry()->registerClassWrapper( ArrayDouble1::Type(), array_serializer.get() );
252  vlX::defVLXRegistry()->registerClassWrapper( ArrayDouble2::Type(), array_serializer.get() );
253  vlX::defVLXRegistry()->registerClassWrapper( ArrayDouble3::Type(), array_serializer.get() );
254  vlX::defVLXRegistry()->registerClassWrapper( ArrayDouble4::Type(), array_serializer.get() );
255 
256  vlX::defVLXRegistry()->registerClassWrapper( ArrayInt1::Type(), array_serializer.get() );
257  vlX::defVLXRegistry()->registerClassWrapper( ArrayInt2::Type(), array_serializer.get() );
258  vlX::defVLXRegistry()->registerClassWrapper( ArrayInt3::Type(), array_serializer.get() );
259  vlX::defVLXRegistry()->registerClassWrapper( ArrayInt4::Type(), array_serializer.get() );
260 
261  vlX::defVLXRegistry()->registerClassWrapper( ArrayUInt1::Type(), array_serializer.get() );
262  vlX::defVLXRegistry()->registerClassWrapper( ArrayUInt2::Type(), array_serializer.get() );
263  vlX::defVLXRegistry()->registerClassWrapper( ArrayUInt3::Type(), array_serializer.get() );
264  vlX::defVLXRegistry()->registerClassWrapper( ArrayUInt4::Type(), array_serializer.get() );
265 
266  vlX::defVLXRegistry()->registerClassWrapper( ArrayShort1::Type(), array_serializer.get() );
267  vlX::defVLXRegistry()->registerClassWrapper( ArrayShort2::Type(), array_serializer.get() );
268  vlX::defVLXRegistry()->registerClassWrapper( ArrayShort3::Type(), array_serializer.get() );
269  vlX::defVLXRegistry()->registerClassWrapper( ArrayShort4::Type(), array_serializer.get() );
270 
271  vlX::defVLXRegistry()->registerClassWrapper( ArrayUShort1::Type(), array_serializer.get() );
272  vlX::defVLXRegistry()->registerClassWrapper( ArrayUShort2::Type(), array_serializer.get() );
273  vlX::defVLXRegistry()->registerClassWrapper( ArrayUShort3::Type(), array_serializer.get() );
274  vlX::defVLXRegistry()->registerClassWrapper( ArrayUShort4::Type(), array_serializer.get() );
275 
276  vlX::defVLXRegistry()->registerClassWrapper( ArrayByte1::Type(), array_serializer.get() );
277  vlX::defVLXRegistry()->registerClassWrapper( ArrayByte2::Type(), array_serializer.get() );
278  vlX::defVLXRegistry()->registerClassWrapper( ArrayByte3::Type(), array_serializer.get() );
279  vlX::defVLXRegistry()->registerClassWrapper( ArrayByte4::Type(), array_serializer.get() );
280 
281  vlX::defVLXRegistry()->registerClassWrapper( ArrayUByte1::Type(), array_serializer.get() );
282  vlX::defVLXRegistry()->registerClassWrapper( ArrayUByte2::Type(), array_serializer.get() );
283  vlX::defVLXRegistry()->registerClassWrapper( ArrayUByte3::Type(), array_serializer.get() );
284  vlX::defVLXRegistry()->registerClassWrapper( ArrayUByte4::Type(), array_serializer.get() );
285 }
286 //------------------------------------------------------------------------------
static void debug(const String &message)
Use this function to provide extra information useful to investigate and solve problems.
Definition: Log.cpp:145
VLX wrapper of vl::Array.
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::Uniform.
void registerClassWrapper(const vl::TypeInfo &type, ClassWrapper *wrapper)
Definition: Registry.hpp:48
const T * get() const
Definition: Object.hpp:128
VLX wrapper of vl::Texture.
VLX wrapper of vl::DistanceLODEvaluator and vl::PixelLODEvaluator.
The LoadWriterMD2 class is a ResourceLoadWriter capable of reading MD2 files.
Definition: ioMD2.hpp:52
VLX wrapper of vl::Material.
static void shutdown()
Releases all the resources acquired by VLCore and VLGraphics.
VLX wrapper of vl::Viewport.
VLGRAPHICS_EXPORT void setDefFontManager(FontManager *)
Sets the default FontManager used by Visualization Library.
Definition: pimpl.cpp:47
VLX wrapper of vl::GLSLProgram.
VLX_EXPORT Registry * defVLXRegistry()
Definition: pimpl.cpp:43
The LoadWriterPLY class is a ResourceLoadWriter capable of reading PLY files.
Definition: ioPLY.hpp:56
The LoadWriterAC3D class is a ResourceLoadWriter capable of reading AC3D files.
Definition: ioAC3D.hpp:73
Visualization Library main namespace.
The LoadWriterDae class is a ResourceLoadWriter capable of reading COLLADA files. ...
Definition: ioDae.hpp:48
VLX wrapper of vl::SecondaryColor.
static void init(bool log_info=true)
Initializes VLCore and VLGraphics libraries.
static void bug(const String &message)
Use this function to provide information about programming errors: wrong parameter initialization...
Definition: Log.cpp:175
VLX wrapper of vl::Light.
VLX wrapper of vl::Color.
static 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::Geometry.
void releaseAllFonts()
Releases all Fonts and associated resources and memory.
Definition: FontManager.cpp:94
VLX wrapper of vl::Actor.
VLX wrapper of vl::ClipPlane.
VLX wrapper of vl::Transform.
#define NULL
Definition: OpenGLDefs.hpp:81
VLX wrapper of vl::DepthSortCallback.
VLX wrapper of vl::Camera.
VLX wrapper of vl::GLSLVertexShader, vl::GLSLFragmentShader, vl::GLSLGeometryShader, vl::GLSLTessControlShader, vl::GLSLTessEvaluationShader.
VLX wrapper of vl::VertexAttrib.
VLX wrapper of vl::ResourceDatabase.
VLX wrapper of vl::Normal.
VLX wrapper of vl::TexParameter.
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
VLX wrapper of vl::TextureImageUnit.
VLX wrapper of vl::Shader.
VLX wrapper of vl::DrawCall and subclasses.
The LoadWriterSTL class is a ResourceLoadWriter capable of reading STL files.
Definition: ioSTL.hpp:56
#define VL_CHECK(expr)
Definition: checks.hpp:73
VLGRAPHICS_EXPORT FontManager * defFontManager()
Returns the default FontManager used by Visualization Library.
Definition: pimpl.cpp:43
VLX wrapper of vl::Effect.
void registerLoadWriter(ResourceLoadWriter *rlw)
Utility function, equivalent to defLoadWriterManager()->registerLoadWriter(rlw).
VLX wrapper of vl::PatchParameter.
The LoadWriter3DS class is a ResourceLoadWriter capable of reading 3DS files.
Definition: io3DS.hpp:57