Browse Source

OpenGL error checking.

Thomas Buck 9 years ago
parent
commit
f8eee299e8
6 changed files with 71 additions and 19 deletions
  1. 6
    0
      ChangeLog.md
  2. 1
    1
      src/Camera.cpp
  3. 8
    14
      src/Render.cpp
  4. 2
    2
      src/deps/imguifilesystem/imguifilesystem.cpp
  5. 47
    1
      src/main.cpp
  6. 7
    1
      src/system/Shader.cpp

+ 6
- 0
ChangeLog.md View File

2
 
2
 
3
 ## OpenRaider (0.1.4) xythobuz <xythobuz@xythobuz.de>
3
 ## OpenRaider (0.1.4) xythobuz <xythobuz@xythobuz.de>
4
 
4
 
5
+    [ 20150408 ]
6
+    * Now checking for errors after every OpenGL call.
7
+    * Slightly tweaked portal visibility checks.
8
+    * Fix to allow imguifilesystem to compile using Visual Studio 2013.
9
+    * Very simple implementation of solid-mode using white texture.
10
+
5
     [ 20150405 ]
11
     [ 20150405 ]
6
     * No longer flipping axis in shaders, now turning camera upside-down.
12
     * No longer flipping axis in shaders, now turning camera upside-down.
7
     * Mostly fixed portal-to-portal 2D visibility checks.
13
     * Mostly fixed portal-to-portal 2D visibility checks.

+ 1
- 1
src/Camera.cpp View File

372
     for (int i = 0; i < 6; i++) {
372
     for (int i = 0; i < 6; i++) {
373
         int out = 0, in = 0;
373
         int out = 0, in = 0;
374
         for (int c = 0; (c < 8) && ((in == 0) || (out == 0)); c++) {
374
         for (int c = 0; (c < 8) && ((in == 0) || (out == 0)); c++) {
375
-            if (planes[i].distance(b.getCorner(c)) > 0)
375
+            if (planes[i].distance(b.getCorner(c)) >= 0)
376
                 out++;
376
                 out++;
377
             else
377
             else
378
                 in++;
378
                 in++;

+ 8
- 14
src/Render.cpp View File

110
             // Display the visibility test for the portal to this room
110
             // Display the visibility test for the portal to this room
111
             BoundingBox debugBox(glm::vec3(min, 0.0f), glm::vec3(max, 0.0f));
111
             BoundingBox debugBox(glm::vec3(min, 0.0f), glm::vec3(max, 0.0f));
112
             debugBox.display(glm::mat4(1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.0f, 1.0f, 0.0f));
112
             debugBox.display(glm::mat4(1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(0.0f, 1.0f, 0.0f));
113
-
114
-            ImGui::Text("   Min: %.3f %.3f", min.x, min.y);
115
-            ImGui::Text("   Max: %.3f %.3f", max.x, max.y);
116
         }
113
         }
117
 
114
 
118
         // Check all portals leading from this room to somewhere else
115
         // Check all portals leading from this room to somewhere else
119
         for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
116
         for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
120
             auto& portal = World::getRoom(room).getPortal(i);
117
             auto& portal = World::getRoom(room).getPortal(i);
118
+            auto& room = World::getRoom(portal.getAdjoiningRoom());
121
 
119
 
122
-            // Calculate the 2D window of this portal
120
+            // Calculate the 2D screen-space bounding box of this portal
123
             glm::vec3 newMin, newMax;
121
             glm::vec3 newMin, newMax;
124
             for (int c = 0; c < 4; c++) {
122
             for (int c = 0; c < 4; c++) {
125
                 glm::vec3 vert = portal.getVertex(c);
123
                 glm::vec3 vert = portal.getVertex(c);
126
                 glm::vec4 result = VP * glm::vec4(vert, 1.0f);
124
                 glm::vec4 result = VP * glm::vec4(vert, 1.0f);
127
                 vert = glm::vec3(result) / result.w;
125
                 vert = glm::vec3(result) / result.w;
128
 
126
 
129
-                if (displayVisibilityCheck) {
130
-                    ImGui::Text("Test %d: %.3f %.3f %.3f", c, vert.x, vert.y, vert.z);
131
-                }
132
-
133
                 if (c == 0) {
127
                 if (c == 0) {
134
                     newMin = vert;
128
                     newMin = vert;
135
                     newMax = vert;
129
                     newMax = vert;
149
                 }
143
                 }
150
             }
144
             }
151
 
145
 
152
-            if (displayVisibilityCheck) {
153
-                ImGui::Text("NewMin: %.3f %.3f %.3f", newMin.x, newMin.y, newMin.z);
154
-                ImGui::Text("NewMax: %.3f %.3f %.3f", newMax.x, newMax.y, newMax.z);
155
-            }
156
-
157
             //! \fixme Currently also checking behind player, because Z is always 1.0f?!
146
             //! \fixme Currently also checking behind player, because Z is always 1.0f?!
158
             //if ((newMin.z > 0.0f) || (newMin.z < -1.0f) || (newMax.z > 0.0f) || (newMax.z < -1.0f)) {
147
             //if ((newMin.z > 0.0f) || (newMin.z < -1.0f) || (newMax.z > 0.0f) || (newMax.z < -1.0f)) {
159
             //    continue;
148
             //    continue;
165
                 continue;
154
                 continue;
166
             }
155
             }
167
 
156
 
157
+            // Check if the connected room is in our view frustum (could be visible)
158
+            if (!Camera::boxInFrustum(room.getBoundingBox())) {
159
+                continue;
160
+            }
161
+
168
             // Check if this room is already in the list...
162
             // Check if this room is already in the list...
169
             bool found = false;
163
             bool found = false;
170
             for (int n = 0; n < roomList.size(); n++) {
164
             for (int n = 0; n < roomList.size(); n++) {
171
-                if (roomList.at(n) == &World::getRoom(portal.getAdjoiningRoom())) {
165
+                if (roomList.at(n) == &room) {
172
                     found = true;
166
                     found = true;
173
                     break;
167
                     break;
174
                 }
168
                 }

+ 2
- 2
src/deps/imguifilesystem/imguifilesystem.cpp View File

357
     static struct stat stat1;
357
     static struct stat stat1;
358
     static struct stat stat2;
358
     static struct stat stat2;
359
     static SorterSignature sorter;
359
     static SorterSignature sorter;
360
-#   ifdef MSC_VER
360
+#   ifdef _MSC_VER
361
     // Never tested (I've just been told that cl.exe does not have strcasecmp: please search the web for other possible alternative implementations)
361
     // Never tested (I've just been told that cl.exe does not have strcasecmp: please search the web for other possible alternative implementations)
362
     inline static int strcasecmp( const char *s1, const char *s2 )  {
362
     inline static int strcasecmp( const char *s1, const char *s2 )  {
363
         return _stricmp(s1,s2);
363
         return _stricmp(s1,s2);
364
         //return lstrcmpiA(s1,s2);  // Not sure this is better
364
         //return lstrcmpiA(s1,s2);  // Not sure this is better
365
     }
365
     }
366
-#   endif //MSC_VER
366
+#   endif //_MSC_VER
367
     // Possible problem: sorting is in ASCII with these methods
367
     // Possible problem: sorting is in ASCII with these methods
368
     static int Alphasort(const struct dirent **e1,const struct dirent **e2)    {
368
     static int Alphasort(const struct dirent **e1,const struct dirent **e2)    {
369
         return strcasecmp((*e1)->d_name,(*e2)->d_name);
369
         return strcasecmp((*e1)->d_name,(*e2)->d_name);

+ 47
- 1
src/main.cpp View File

27
 
27
 
28
 #include <glbinding/Binding.h>
28
 #include <glbinding/Binding.h>
29
 
29
 
30
+#ifdef DEBUG
31
+#include <glbinding/callbacks.h>
32
+#include <glbinding/Meta.h>
33
+#endif
34
+
30
 static std::string configFileToUse;
35
 static std::string configFileToUse;
31
 
36
 
37
+#ifdef DEBUG
38
+static void glErrorCallback(const glbinding::FunctionCall& call) {
39
+    gl::GLenum error = gl::glGetError();
40
+    if (error == gl::GL_NO_ERROR) {
41
+        return;
42
+    }
43
+
44
+    auto& log = Log::get(LOG_DEBUG);
45
+    if (glbinding::Meta::stringsByGL()) {
46
+        log << "OpenGL Error: " << glbinding::Meta::getString(error) << Log::endl;
47
+    } else {
48
+        log << "OpenGL Error: "
49
+            << static_cast<std::underlying_type<gl::GLenum>::type>(error)
50
+            << Log::endl;
51
+    }
52
+    log << call.function->name() << "(";
53
+
54
+    for (int i = 0; i < call.parameters.size(); i++) {
55
+        log << call.parameters[i]->asString();
56
+        if (i < (call.parameters.size() - 1)) {
57
+            log << ", ";
58
+        }
59
+    }
60
+
61
+    log << ")";
62
+
63
+    if (call.returnValue) {
64
+        log << " -> " << call.returnValue->asString();
65
+    }
66
+
67
+    log << Log::endl;
68
+}
69
+#endif
70
+
32
 int main(int argc, char* argv[]) {
71
 int main(int argc, char* argv[]) {
33
     command_t cmd;
72
     command_t cmd;
34
     command_init(&cmd, argv[0], VERSION);
73
     command_init(&cmd, argv[0], VERSION);
42
     glbinding::Binding::initialize();
81
     glbinding::Binding::initialize();
43
     Log::initialize();
82
     Log::initialize();
44
     RunTime::initialize(); // RunTime is required by other constructors
83
     RunTime::initialize(); // RunTime is required by other constructors
45
-
46
     Command::fillCommandList();
84
     Command::fillCommandList();
47
 
85
 
86
+#ifdef DEBUG
87
+    // Register global OpenGL after-callback for all GL functions except glGetError
88
+    glbinding::setCallbackMaskExcept(glbinding::CallbackMask::After
89
+                                     | glbinding::CallbackMask::ParametersAndReturnValue,
90
+                                     { "glGetError" });
91
+    glbinding::setAfterCallback(glErrorCallback);
92
+#endif
93
+
48
     Log::get(LOG_INFO) << "Initializing " << VERSION << Log::endl;
94
     Log::get(LOG_INFO) << "Initializing " << VERSION << Log::endl;
49
 
95
 
50
     // Initialize Windowing
96
     // Initialize Windowing

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

9
 
9
 
10
 #include "global.h"
10
 #include "global.h"
11
 #include "Log.h"
11
 #include "Log.h"
12
+#include "Render.h"
12
 #include "system/Window.h"
13
 #include "system/Window.h"
13
 #include "system/Shader.h"
14
 #include "system/Shader.h"
14
 
15
 
132
 }
133
 }
133
 
134
 
134
 void Shader::loadUniform(int uni, int texture, TextureStorage store) {
135
 void Shader::loadUniform(int uni, int texture, TextureStorage store) {
135
-    gl::glUniform1i(getUniform(uni), TextureManager::bindTexture(texture, store));
136
+    if ((Render::getMode() == RenderMode::Solid)
137
+        && (store == TextureStorage::GAME)) {
138
+        gl::glUniform1i(getUniform(uni), TextureManager::bindTexture(TEXTURE_SPLASH, TextureStorage::SYSTEM));
139
+    } else {
140
+        gl::glUniform1i(getUniform(uni), TextureManager::bindTexture(texture, store));
141
+    }
136
 }
142
 }
137
 
143
 
138
 void Shader::use() {
144
 void Shader::use() {

Loading…
Cancel
Save