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]
pimpl.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 <vlX/Registry.hpp>
35 #include <vlCore/FileSystem.hpp>
37 #include <vlCore/Log.hpp>
38 #include <vlCore/Say.hpp>
39 #include <vlCore/Time.hpp>
40 #include <vlCore/Quaternion.hpp>
41 #include <vlCore/AABB.hpp>
42 #include <vlCore/Sphere.hpp>
44 #include <cassert>
45 
46 using namespace vl;
47 
48 namespace
49 {
50  ref<GlobalSettings> gSettings = NULL;
51 }
53 {
54  return gSettings.get();
55 }
57 {
58  gSettings = gs;
59 }
60 //------------------------------------------------------------------------------
61 // Default logger
62 //------------------------------------------------------------------------------
63 namespace
64 {
65  ref<Log> gDefaultLogger;
66 }
67 void vl::setDefLogger(Log* logger)
68 {
69  gDefaultLogger = logger;
70 }
72 {
73  return gDefaultLogger.get();
74 }
75 //------------------------------------------------------------------------------
76 // Default LoadWriterManager
77 //------------------------------------------------------------------------------
78 namespace
79 {
80  ref<LoadWriterManager> gDefaultLoadWriterManager = NULL;
81 }
83 {
84  return gDefaultLoadWriterManager.get();
85 }
87 {
88  gDefaultLoadWriterManager = lwm;
89 }
90 //-----------------------------------------------------------------------------
91 // Default FileSystem
92 //-----------------------------------------------------------------------------
93 namespace
94 {
95  ref<FileSystem> gDefaultFileSystem = NULL;;
96 }
98 {
99  return gDefaultFileSystem.get();
100 }
102 {
103  gDefaultFileSystem = fs;
104 }
105 //-----------------------------------------------------------------------------
106 // Default MersenneTwister
107 //-----------------------------------------------------------------------------
108 namespace
109 {
110  ref<MersenneTwister> gDefaultMersenneTwister = NULL;
111 }
113 {
114  return gDefaultMersenneTwister.get();
115 }
117 {
118  gDefaultMersenneTwister= reg;
119 }
120 //------------------------------------------------------------------------------
122 {
123  vl::Time::sleep(3000);
124  exit(1);
125 }
126 // ------------------------------------------------------------------------------
127 namespace
128 {
129  std::string gVersionString = String( Say("%n.%n.%s") << VL_Major << VL_Minor << VL_Patch ).toStdString();
130 };
131 // ------------------------------------------------------------------------------
132 const char* vl::versionString() { return gVersionString.c_str(); }
133 //------------------------------------------------------------------------------
134 #if defined(VL_PLATFORM_WINDOWS)
135  // console includes
136  #include <io.h>
137  #include <fcntl.h>
138 #endif
140 {
141  #if defined(VL_PLATFORM_WINDOWS)
142  if (AllocConsole() == 0)
143  return;
144  FILE* f_new_stdout = nullptr;
145  FILE* f_new_stderr = nullptr;
146  FILE* f_new_stdin = nullptr;
147  ::freopen_s(&f_new_stdout, "CONOUT$", "w", stdout);
148  ::freopen_s(&f_new_stderr, "CONOUT$", "w", stderr);
149  ::freopen_s(&f_new_stdin, "CONIN$", "r", stdin);
150  std::cout.clear();
151  std::cerr.clear();
152  std::cin.clear();
153  std::wcout.clear();
154  std::wcerr.clear();
155  std::wcin.clear();
156  #endif
157 }
158 //------------------------------------------------------------------------------
160 {
161  #if defined(_MSC_VER)
162  const char* compiler = "MSVC";
163  #elif defined(__GNUG__)
164  const char* compiler = "GCC";
165  #else
166  const char* compiler = "UNKNOWN";
167  #endif
168 
169  #if defined(DEBUG) || !defined(NDEBUG)
170  const char* build_type = "DEBUG";
171  #else
172  const char* build_type = "RELEASE";
173  #endif
174 
175  vl::Log::print( Say("Visualization Library v%s [%s]\n%s - %s - %s compiler [%s] [%s]\n")
176  << vl::versionString()
177  << (sizeof(vec3) == sizeof(fvec3) ? "f32" : "f64")
178  << __DATE__ << __TIME__ << compiler << build_type
179  << (sizeof(void*) == 4 ? "x32" : "x64") );
180 
181  vl::Log::print("\n --- Environment ---\n");
182  const char* val = getenv("VL_LOGFILE_PATH");
183  if (val)
184  vl::Log::print( Say("VL_LOGFILE_PATH = %s\n") << val );
185  else
186  vl::Log::print("VL_LOGFILE_PATH <not present>\n");
187 
188  val = getenv("VL_DATA_PATH");
189  if (val)
190  vl::Log::print( Say("VL_DATA_PATH = %s\n") << val );
191  else
192  vl::Log::print("VL_DATA_PATH <not present>\n");
193 
194  val = getenv("VL_VERBOSITY_LEVEL");
195  if (val)
196  vl::Log::print( Say("VL_VERBOSITY_LEVEL = %s\n") << val );
197  else
198  vl::Log::print("VL_VERBOSITY_LEVEL <not present>\n");
199 
200  val = getenv("VL_CHECK_GL_STATES");
201  if (val)
202  vl::Log::print( Say("VL_CHECK_GL_STATES = %s\n") << val );
203  else
204  vl::Log::print("VL_CHECK_GL_STATES <not present>\n");
205 
206  vl::Log::print("\n --- Global Settings --- \n");
207  vl::Log::print( Say("Log file = %s\n") << globalSettings()->defaultLogPath() );
208  vl::Log::print( Say("Data path = %s\n") << globalSettings()->defaultDataPath() );
209  vl::Log::print("Verbosity level = ");
210  switch(globalSettings()->verbosityLevel())
211  {
212  /*case vl::VEL_VERBOSITY_SILENT: print("SILENT\n"); break;*/
213  case vl::VEL_VERBOSITY_ERROR: vl::Log::print("ERROR\n"); break;
214  case vl::VEL_VERBOSITY_NORMAL: vl::Log::print("NORMAL\n"); break;
215  case vl::VEL_VERBOSITY_DEBUG: vl::Log::print("DEBUG\n"); break;
216  default: break;
217  }
218  vl::Log::print( Say("Check OpenGL States = %s\n") << (globalSettings()->checkOpenGLStates()?"YES":"NO") );
219 
220  vl::Log::print("\n");
221 }
Utility class to generate logs.
Definition: Log.hpp:45
VLCORE_EXPORT FileSystem * defFileSystem()
Returns the default FileSystem used by VisualizationLibrary.
Definition: pimpl.cpp:97
VLCORE_EXPORT void abort_vl()
Definition: pimpl.cpp:121
A simple String formatting class.
Definition: Say.hpp:124
VLCORE_EXPORT void logSystemInfo()
Logs VL and system information.
Definition: pimpl.cpp:159
VLCORE_EXPORT void showWin32Console()
Shows a console window that displays the standard output. This function is meant to be used only unde...
Definition: pimpl.cpp:139
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
Definition: String.hpp:62
Global application settings controlling how Visualization Library behaves.
The LoadWriterManager class loads and writes resources using the registered ResourceLoadWriter object...
< Outputs normal information messages, plus all error messages.
VLCORE_EXPORT void setGlobalSettings(GlobalSettings *)
Sets VisulizationLibrary&#39;s global settings.
Definition: pimpl.cpp:56
Visualization Library main namespace.
Manages multiple VirtualDirectory objects.
Definition: FileSystem.hpp:58
static void print(const String &message)
Application message for the user.
Definition: Log.cpp:136
VLCORE_EXPORT void setDefFileSystem(FileSystem *fs)
Sets the default FileSystem used by VisualizationLibrary.
Definition: pimpl.cpp:101
#define NULL
Definition: OpenGLDefs.hpp:81
VLCORE_EXPORT const char * versionString()
Returns the Visualization Library&#39;s version string.
Definition: pimpl.cpp:132
< Outputs critical and runtime error messages.
VLCORE_EXPORT void setDefLoadWriterManager(LoadWriterManager *lwm)
Sets the default LoadWriterManager used by Visualization Library.
Definition: pimpl.cpp:86
< Outputs extra information messages useful for debugging, plus all normal and error messages...
VLCORE_EXPORT void setDefLogger(Log *logger)
Installs the default logger used by Visualization Library. Setting this to NULL will disable logging...
Definition: pimpl.cpp:67
VLCORE_EXPORT void setDefMersenneTwister(MersenneTwister *)
Definition: pimpl.cpp:116
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
std::string toStdString() const
Returns a UTF8 encoded std::string.
Definition: String.cpp:1156
VLCORE_EXPORT Log * defLogger()
Returns the currently installed default logger.
Definition: pimpl.cpp:71
static void sleep(unsigned int milliseconds)
Definition: Time.cpp:144
VLCORE_EXPORT MersenneTwister * defMersenneTwister()
Definition: pimpl.cpp:112
VLCORE_EXPORT LoadWriterManager * defLoadWriterManager()
Returs the default LoadWriterManager used by Visualization Library.
Definition: pimpl.cpp:82
VLCORE_EXPORT GlobalSettings * globalSettings()
Returns VisulizationLibrary&#39;s global settings.
Definition: pimpl.cpp:52