GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
OglInclude.hpp
Go to the documentation of this file.
1 /* ************************************************************************************************************* */
2 /* */
3 /* GLIP-LIB */
4 /* OpenGL Image Processing LIBrary */
5 /* */
6 /* Author : R. Kerviche */
7 /* LICENSE : MIT License */
8 /* Website : glip-lib.net */
9 /* */
10 /* File : OglInclude.hpp */
11 /* Original Date : October 17th 2010 */
12 /* */
13 /* Description : OpenGL includes and tools */
14 /* */
15 /* ************************************************************************************************************* */
16 
24 #ifndef __OGLINCLUDE_INCLUDE__
25 #define __OGLINCLUDE_INCLUDE__
26 
27  #include <iostream>
28  #include <vector>
29  #include "devDebugTools.hpp"
30  #include "Core/LibTools.hpp"
31 
32  #ifdef _WIN32
33  #define WINDOWS_LEAN_AND_MEAN
34  #define NOMINMAX
35  #include <windows.h>
36  #define GLEW_STATIC
37  #include "glew.h"
38  #ifdef __GLIP_USE_GLES__
39  #include <GLES/gl.h>
40  #else
41  #include <GL/gl.h>
42  #endif
43  #endif
44 
45  #if defined(linux) || defined(__linux) || defined(__linux__)
46  #define GLEW_STATIC
47  #include "glew.h"
48  #ifdef __GLIP_USE_GLES__
49  #include <GLES/gl.h>
50  #else
51  #include <GL/gl.h>
52  #endif
53  #endif
54 
55  namespace Glip
56  {
57  namespace CoreGL
58  {
59  // Macros
60  #define NEED_EXTENSION(ext) if(!ext) \
61  throw Exception("OpenGL Extension " #ext " is required but not available on Hardware or Driver (updating the driver might help).",__FILE__,__LINE__,Exception::GLException);
62 
63  #define FIX_MISSING_GLEW_CALL(call, replacement) if(call==NULL) \
64  { \
65  std::cerr << "OpenGL Function " #call " is required but GLEW failed to load it, the library will (try to) use " #replacement " instead." << std::endl; \
66  if(replacement==NULL) \
67  throw Exception("OpenGL Functions " #call " and " #replacement " aren't available according to GLEW (updating the driver might help).", __FILE__, __LINE__,Exception::GLException); \
68  call = replacement; \
69  }
70 
71  #define GLIP_NUM_SHADER_TYPES (6)
72 
73  // Object
78  class GLIP_API HandleOpenGL
79  {
80  public :
83  {
91  vd_UNKNOWN
92  };
93 
95  static const unsigned int numShaderTypes = GLIP_NUM_SHADER_TYPES; // See GL_SHADER_TYPE and GL_*_SHADER
97  static const GLenum shaderTypes[GLIP_NUM_SHADER_TYPES];
98 
99  private :
100  // OpenGL keyword :
101  struct GLIP_API KeywordPair
102  {
103  GLenum value;
104  const std::string name;
105  };
106 
107  static HandleOpenGL *instance;
108  static SupportedVendor vendor;
109  static const KeywordPair glKeywords[];
110 
111  public :
112  HandleOpenGL(void);
113  ~HandleOpenGL(void);
114 
115  static void init(void);
116  static void deinit(void);
117  static bool isInitialized(void);
118  static SupportedVendor getVendorID(void);
119  static std::string getVendorName(void);
120  static std::string getRendererName(void);
121  static std::string getVersion(void);
122  static void getVersion(int& major, int& minor);
123  static std::string getGLSLVersion(void);
124  static std::vector<std::string> getAvailableGLSLVersions(void);
125  static unsigned int getShaderTypeIndex(GLenum shaderType);
126 
127  // Friend functions :
128  GLIP_API friend std::string getGLEnumName(const GLenum& p);
129  GLIP_API friend std::string getGLEnumNameSafe(const GLenum& p) throw();
130  GLIP_API friend GLenum getGLEnum(const std::string& s);
131  };
132 
133  // Tools
134  GLIP_API_FUNC std::string getGLErrorDescription(const GLenum& e);
135  GLIP_API_FUNC void debugGL(void);
136  GLIP_API_FUNC std::string getGLEnumName(const GLenum& p);
137  GLIP_API_FUNC std::string getGLEnumNameSafe(const GLenum& p) throw();
138  GLIP_API_FUNC GLenum getGLEnum(const std::string& s);
139  GLIP_API_FUNC bool belongsToGLEnums(const GLenum& p, const GLenum* list, const size_t s);
140 
155  template<size_t N>
156  bool belongsToGLEnums(const GLenum& p, const GLenum (&list) [N])
157  {
158  return (std::find(list, list+N, p)!=(list+N));
159  }
160  }
161  }
162 
163 #endif
164 
Specific defines for the API structure.
Main OpenGL Handle.
Definition: OglInclude.hpp:78
For NVIDIA.
Definition: OglInclude.hpp:85
Definition: Component.hpp:32
SupportedVendor
ID of the supported hardware vendors.
Definition: OglInclude.hpp:82
For AMD/ATI.
Definition: OglInclude.hpp:87
Development and debugging tools.
For INTEL.
Definition: OglInclude.hpp:89