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,10 +67,9 @@ typedef enum {
67 67
 } KeyboardButton;
68 68
 
69 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 74
 /*! \fixme Is there a better way to handle this?
76 75
  * We wan't to use our own assert(). Unfortunately, glm includes

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

@@ -73,7 +73,7 @@ class Shader {
73 73
     static void set2DState(bool on, bool depth = true);
74 74
 
75 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 77
                        ShaderTexture* target = nullptr, Shader& shader = textShader);
78 78
 
79 79
     static void drawGL(ShaderBuffer& vertices, ShaderBuffer& uvs, unsigned int texture, glm::mat4 MVP,
@@ -85,10 +85,10 @@ class Shader {
85 85
                        Shader& shader = textureShader);
86 86
 
87 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 89
                        Shader& shader = colorShader);
90 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 92
                        Shader& shader = colorShader);
93 93
 
94 94
   private:

+ 8
- 18
src/CMakeLists.txt View File

@@ -7,10 +7,14 @@ find_package (OpenGL REQUIRED)
7 7
 include_directories (SYSTEM ${OPENGL_INCLUDE_DIRS})
8 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 19
 # Add SDL2 Library
16 20
 find_package (SDL2)
@@ -39,20 +43,6 @@ if (OPENAL_FOUND)
39 43
     endif (ALUT_FOUND)
40 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 48
 # Set Source files

+ 8
- 8
src/TextureManager.cpp View File

@@ -160,7 +160,7 @@ int TextureManager::loadBufferSlot(unsigned char* image,
160 160
         getIds(s).push_back(id);
161 161
     }
162 162
 
163
-    unsigned int glcMode;
163
+    GLenum glcMode;
164 164
     switch (mode) {
165 165
         case ColorMode::BGR:
166 166
             glcMode = GL_BGR;
@@ -187,18 +187,18 @@ int TextureManager::loadBufferSlot(unsigned char* image,
187 187
 
188 188
     glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
189 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 192
     if (filter) {
193 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 198
         glGenerateMipmap(GL_TEXTURE_2D);
199 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 204
     return slot;

+ 2
- 2
src/main.cpp View File

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

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

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

Loading…
Cancel
Save