Browse Source

Now using glbinding

Thomas Buck 9 years ago
parent
commit
eedb4ec4ed
6 changed files with 31 additions and 42 deletions
  1. 3
    4
      include/global.h
  2. 3
    3
      include/system/Shader.h
  3. 8
    18
      src/CMakeLists.txt
  4. 8
    8
      src/TextureManager.cpp
  5. 2
    2
      src/main.cpp
  6. 7
    7
      src/system/Shader.cpp

+ 3
- 4
include/global.h View File

67
 } KeyboardButton;
67
 } KeyboardButton;
68
 
68
 
69
 // Globally include OpenGL header
69
 // Globally include OpenGL header
70
-#ifdef __APPLE__
71
-#include <OpenGL/gl3.h>
72
-#else // __APPLE__
73
-#endif // __APPLE__
70
+#include <glbinding/gl/gl.h>
71
+#include <glbinding/Binding.h>
72
+using namespace gl;
74
 
73
 
75
 /*! \fixme Is there a better way to handle this?
74
 /*! \fixme Is there a better way to handle this?
76
  * We wan't to use our own assert(). Unfortunately, glm includes
75
  * We wan't to use our own assert(). Unfortunately, glm includes

+ 3
- 3
include/system/Shader.h View File

73
     static void set2DState(bool on, bool depth = true);
73
     static void set2DState(bool on, bool depth = true);
74
 
74
 
75
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
75
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color, unsigned int texture,
76
-                       TextureStorage store = TextureStorage::SYSTEM, unsigned int mode = GL_TRIANGLES,
76
+                       TextureStorage store = TextureStorage::SYSTEM, GLenum = GL_TRIANGLES,
77
                        ShaderTexture* target = nullptr, Shader& shader = textShader);
77
                        ShaderTexture* target = nullptr, Shader& shader = textShader);
78
 
78
 
79
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
79
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
85
                        Shader& shader = textureShader);
85
                        Shader& shader = textureShader);
86
 
86
 
87
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
87
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
88
-                       unsigned int mode = GL_TRIANGLES, ShaderTexture* target = nullptr,
88
+                       GLenum mode = GL_TRIANGLES, ShaderTexture* target = nullptr,
89
                        Shader& shader = colorShader);
89
                        Shader& shader = colorShader);
90
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
90
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
91
-                       glm::mat4 MVP, unsigned int mode = GL_TRIANGLES, ShaderTexture* target = nullptr,
91
+                       glm::mat4 MVP, GLenum mode = GL_TRIANGLES, ShaderTexture* target = nullptr,
92
                        Shader& shader = colorShader);
92
                        Shader& shader = colorShader);
93
 
93
 
94
   private:
94
   private:

+ 8
- 18
src/CMakeLists.txt View File

7
 include_directories (SYSTEM ${OPENGL_INCLUDE_DIRS})
7
 include_directories (SYSTEM ${OPENGL_INCLUDE_DIRS})
8
 set (LIBS ${LIBS} ${OPENGL_LIBRARIES})
8
 set (LIBS ${LIBS} ${OPENGL_LIBRARIES})
9
 
9
 
10
-# Add Z Library
11
-find_package (ZLIB REQUIRED)
12
-include_directories (SYSTEM ${ZLIB_INCLUDE_DIRS})
13
-set (LIBS ${LIBS} ${ZLIB_LIBRARIES})
10
+# Add GLM Library
11
+find_package (GLM REQUIRED)
12
+include_directories (SYSTEM  ${GLM_INCLUDE_DIRS})
13
+
14
+# Add glbinding Library
15
+find_package (glbinding REQUIRED)
16
+include_directories (SYSTEM ${GLBINDING_INCLUDES})
17
+set (LIBS ${LIBS} ${GLBINDING_LIBRARIES})
14
 
18
 
15
 # Add SDL2 Library
19
 # Add SDL2 Library
16
 find_package (SDL2)
20
 find_package (SDL2)
39
     endif (ALUT_FOUND)
43
     endif (ALUT_FOUND)
40
 endif (OPENAL_FOUND)
44
 endif (OPENAL_FOUND)
41
 
45
 
42
-# Add GLM Library
43
-find_package (GLM REQUIRED)
44
-if (GLM_FOUND)
45
-    include_directories (SYSTEM  ${GLM_INCLUDE_DIRS})
46
-endif (GLM_FOUND)
47
-
48
-if (WIN32)
49
-    find_package (GLEW REQUIRED)
50
-    if (GLEW_FOUND)
51
-        include_directories (SYSTEM ${GLEW_INCLUDE_DIRS})
52
-        set (LIBS ${LIBS} ${GLEW_LIBRARIES})
53
-    endif (GLEW_FOUND)
54
-endif (WIN32)
55
-
56
 #################################################################
46
 #################################################################
57
 
47
 
58
 # Set Source files
48
 # Set Source files

+ 8
- 8
src/TextureManager.cpp View File

160
         getIds(s).push_back(id);
160
         getIds(s).push_back(id);
161
     }
161
     }
162
 
162
 
163
-    unsigned int glcMode;
163
+    GLenum glcMode;
164
     switch (mode) {
164
     switch (mode) {
165
         case ColorMode::BGR:
165
         case ColorMode::BGR:
166
             glcMode = GL_BGR;
166
             glcMode = GL_BGR;
187
 
187
 
188
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
188
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
189
     bindTexture(slot, s);
189
     bindTexture(slot, s);
190
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, glcMode, GL_UNSIGNED_BYTE, image);
190
+    glTexImage2D(GL_TEXTURE_2D, 0, GLint(GL_RGBA), width, height, 0, glcMode, GL_UNSIGNED_BYTE, image);
191
 
191
 
192
     if (filter) {
192
     if (filter) {
193
         // Trilinear filtering
193
         // Trilinear filtering
194
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
195
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
196
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
197
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
194
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GLint(GL_REPEAT));
195
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GLint(GL_REPEAT));
196
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GLint(GL_LINEAR));
197
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GLint(GL_LINEAR_MIPMAP_LINEAR));
198
         glGenerateMipmap(GL_TEXTURE_2D);
198
         glGenerateMipmap(GL_TEXTURE_2D);
199
     } else {
199
     } else {
200
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
201
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
200
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GLint(GL_NEAREST));
201
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GLint(GL_NEAREST));
202
     }
202
     }
203
 
203
 
204
     return slot;
204
     return slot;

+ 2
- 2
src/main.cpp View File

43
     command_parse(&cmd, argc, argv);
43
     command_parse(&cmd, argc, argv);
44
     command_free(&cmd);
44
     command_free(&cmd);
45
 
45
 
46
-    // RunTime is required by other constructors
46
+    glbinding::Binding::initialize();
47
     Log::initialize();
47
     Log::initialize();
48
-    RunTime::initialize();
48
+    RunTime::initialize(); // RunTime is required by other constructors
49
 
49
 
50
     gWorld.reset(new World());
50
     gWorld.reset(new World());
51
 
51
 

+ 7
- 7
src/system/Shader.cpp View File

143
     GLuint vertexID = glCreateShader(GL_VERTEX_SHADER);
143
     GLuint vertexID = glCreateShader(GL_VERTEX_SHADER);
144
     GLuint fragmentID = glCreateShader(GL_FRAGMENT_SHADER);
144
     GLuint fragmentID = glCreateShader(GL_FRAGMENT_SHADER);
145
 
145
 
146
-    GLint result = GL_FALSE;
146
+    GLint result = GLint(GL_FALSE);
147
     GLint logLength = 0;
147
     GLint logLength = 0;
148
 
148
 
149
     // Compile vertex shader
149
     // Compile vertex shader
153
     // Check vertex shader
153
     // Check vertex shader
154
     glGetShaderiv(vertexID, GL_COMPILE_STATUS, &result);
154
     glGetShaderiv(vertexID, GL_COMPILE_STATUS, &result);
155
     glGetShaderiv(vertexID, GL_INFO_LOG_LENGTH, &logLength);
155
     glGetShaderiv(vertexID, GL_INFO_LOG_LENGTH, &logLength);
156
-    if ((logLength > 0) && (result != GL_TRUE)) {
156
+    if ((logLength > 0) && (result != GLint(GL_TRUE))) {
157
         std::vector<char> message(logLength + 1);
157
         std::vector<char> message(logLength + 1);
158
         glGetShaderInfoLog(vertexID, logLength, nullptr, &message[0]);
158
         glGetShaderInfoLog(vertexID, logLength, nullptr, &message[0]);
159
         Log::get(LOG_ERROR) << "Vertex Shader compilation error:" << Log::endl;
159
         Log::get(LOG_ERROR) << "Vertex Shader compilation error:" << Log::endl;
170
     // Check fragment shader
170
     // Check fragment shader
171
     glGetShaderiv(fragmentID, GL_COMPILE_STATUS, &result);
171
     glGetShaderiv(fragmentID, GL_COMPILE_STATUS, &result);
172
     glGetShaderiv(fragmentID, GL_INFO_LOG_LENGTH, &logLength);
172
     glGetShaderiv(fragmentID, GL_INFO_LOG_LENGTH, &logLength);
173
-    if ((logLength > 0) && (result != GL_TRUE)) {
173
+    if ((logLength > 0) && (result != GLint(GL_TRUE))) {
174
         std::vector<char> message(logLength + 1);
174
         std::vector<char> message(logLength + 1);
175
         glGetShaderInfoLog(fragmentID, logLength, nullptr, &message[0]);
175
         glGetShaderInfoLog(fragmentID, logLength, nullptr, &message[0]);
176
         Log::get(LOG_ERROR) << "Fragment Shader compilation error:" << Log::endl;
176
         Log::get(LOG_ERROR) << "Fragment Shader compilation error:" << Log::endl;
189
     // Check resulting program
189
     // Check resulting program
190
     glGetProgramiv(programID, GL_LINK_STATUS, &result);
190
     glGetProgramiv(programID, GL_LINK_STATUS, &result);
191
     glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &logLength);
191
     glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &logLength);
192
-    if ((logLength > 0) && (result != GL_TRUE)) {
192
+    if ((logLength > 0) && (result != GLint(GL_TRUE))) {
193
         std::vector<char> message(logLength + 1);
193
         std::vector<char> message(logLength + 1);
194
         glGetProgramInfoLog(programID, logLength, nullptr, &message[0]);
194
         glGetProgramInfoLog(programID, logLength, nullptr, &message[0]);
195
         Log::get(LOG_ERROR) << "Shader link error:" << Log::endl;
195
         Log::get(LOG_ERROR) << "Shader link error:" << Log::endl;
273
 }
273
 }
274
 
274
 
275
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
275
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, glm::vec4 color,
276
-                    unsigned int texture, TextureStorage store, unsigned int mode,
276
+                    unsigned int texture, TextureStorage store, GLenum mode,
277
                     ShaderTexture* target, Shader& shader) {
277
                     ShaderTexture* target, Shader& shader) {
278
     assert(vertices.getSize() == uvs.getSize());
278
     assert(vertices.getSize() == uvs.getSize());
279
     if (mode == GL_TRIANGLES) {
279
     if (mode == GL_TRIANGLES) {
365
 }
365
 }
366
 
366
 
367
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
367
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, glm::mat4 MVP,
368
-                    unsigned int mode, ShaderTexture* target, Shader& shader) {
368
+                    GLenum mode, ShaderTexture* target, Shader& shader) {
369
     assert(vertices.getSize() == colors.getSize());
369
     assert(vertices.getSize() == colors.getSize());
370
     if (mode == GL_TRIANGLES) {
370
     if (mode == GL_TRIANGLES) {
371
         assert((vertices.getSize() % 3) == 0);
371
         assert((vertices.getSize() % 3) == 0);
388
 }
388
 }
389
 
389
 
390
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
390
 void Shader::drawGL(ShaderBuffer& vertices, ShaderBuffer& colors, ShaderBuffer& indices,
391
-                    glm::mat4 MVP, unsigned int mode, ShaderTexture* target, Shader& shader) {
391
+                    glm::mat4 MVP, GLenum mode, ShaderTexture* target, Shader& shader) {
392
     assert(vertices.getSize() == colors.getSize());
392
     assert(vertices.getSize() == colors.getSize());
393
     if (mode == GL_TRIANGLES) {
393
     if (mode == GL_TRIANGLES) {
394
         assert((indices.getSize() % 3) == 0);
394
         assert((indices.getSize() % 3) == 0);

Loading…
Cancel
Save