GlobeEngine
Common.h
Go to the documentation of this file.
1 
9 #ifndef GlobeEngine_Common_h
10 #define GlobeEngine_Common_h
11 
12 #include "OpenGL_Includes.h"
13 #include <iostream>
14 #include <string>
15 #include <algorithm>
16 #include <stdexcept>
17 #include <cassert>
18 
19 #define PI 3.1415926535897932384626433832795
20 #define HALF_PI 1.57079632679489661923
21 
22 namespace ge {
23  static unsigned int findNextPowerOfTwo(unsigned int _in){
24  unsigned int res = _in;
25  res--;
26  res |= res >> 1;
27  res |= res >> 2;
28  res |= res >> 4;
29  res |= res >> 8;
30  res |= res >> 16;
31  res++;
32  return res;
33  }
34 
35  // Small to Big Endian
36  static float floatSwap(float _f)
37  {
38  union
39  {
40  float f;
41  unsigned char b[4];
42  } dat1, dat2;
43 
44  dat1.f = _f;
45  dat2.b[0] = dat1.b[3];
46  dat2.b[1] = dat1.b[2];
47  dat2.b[2] = dat1.b[1];
48  dat2.b[3] = dat1.b[0];
49  return dat2.f;
50  }
51 
52  static float clamp(float _x,float _minVal, float _maxVal)
53  {
54  return std::min(std::max(_x, _minVal), _maxVal);
55  }
56 
57 
59  static bool printOpenGLError(const char* addInfo = NULL)
60  {
61  GLenum errCode = glGetError();
62  if (errCode != GL_NO_ERROR)
63  {
64  switch (errCode)
65  {
66  case GL_INVALID_ENUM: {
67  std::cout << "GL_INVALID_ENUM:" << "An unacceptable value is specified for an enumerated argument. For occlusion queries: " << std::endl;
68  break;
69  }
70  case GL_INVALID_VALUE: {
71  std::cout << "GL_INVALID_VALUE:" << "A numeric argument is out of range." << std::endl;
72  break;
73  }
74  case GL_INVALID_OPERATION: {
75  std::cout << "GL_INVALID_OPERATION:" << "The specified operation is not allowed in the current state. " << std::endl;
76  break;
77  }
78  case GL_INVALID_FRAMEBUFFER_OPERATION: {
79  std::cout << "GL_INVALID_FRAMEBUFFER_OPERATION:" << "The framebuffer object is not complete." << std::endl;
80  break;
81  }
82  case GL_OUT_OF_MEMORY: {
83  std::cout << "GL_OUT_OF_MEMORY:" << "There is not enough memory left to execute the command. The state of the GL is undefined, except for the state of the error flags, after this error is recorded." << std::endl;
84  break;
85  }
86 #ifndef GENGINE_GL_BELOW_410
87  case GL_STACK_UNDERFLOW: {
88  std::cout << "GL_STACK_UNDERFLOW:" << "An attempt has been made to perform an operation that would cause an internal stack to underflow." << std::endl;
89  break;
90  }
91  case GL_STACK_OVERFLOW: {
92  std::cout << "GL_STACK_OVERFLOW:" << "An attempt has been made to perform an operation that would cause an internal stack to overflow." << std::endl;
93  break;
94  }
95 #endif
96  }
97 
98  if (addInfo != NULL)
99  {
100  std::cout << ": " << addInfo << std::endl;
101  }
102  else
103  {
104  std::cout << "Some openGLError Appeared" << std::endl;
105  }
106  return true;
107  }
108 
109  return false;
110  }
111 
112  static bool checkForExtension(std::string _input, std::string _ext)
113  {
114  std::size_t found = _input.find(_ext);
115  if (found != std::string::npos){
116  std::cout << "Found a " << _ext << " file: " << found << '\n';
117  return true;
118  }
119  return false;
120  }
121 
122  static std::string getFileNameFromURL(const std::string& str)
123  {
124  std::size_t found = str.find_last_of("/\\");
125  return str.substr(found + 1);
126  }
127 
128  static std::string getFilePathfromURL(const std::string& str)
129  {
130  return str.substr(0, str.find_last_of("/\\"));
131  }
132 }
133 #endif
Definition: AvalancheTrainingSimulationEngine.h:28