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,6 +2,12 @@
2 2
 
3 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 11
     [ 20150405 ]
6 12
     * No longer flipping axis in shaders, now turning camera upside-down.
7 13
     * Mostly fixed portal-to-portal 2D visibility checks.

+ 1
- 1
src/Camera.cpp View File

@@ -372,7 +372,7 @@ bool Camera::boxInFrustum(BoundingBox b) {
372 372
     for (int i = 0; i < 6; i++) {
373 373
         int out = 0, in = 0;
374 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 376
                 out++;
377 377
             else
378 378
                 in++;

+ 8
- 14
src/Render.cpp View File

@@ -110,26 +110,20 @@ void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max)
110 110
             // Display the visibility test for the portal to this room
111 111
             BoundingBox debugBox(glm::vec3(min, 0.0f), glm::vec3(max, 0.0f));
112 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 115
         // Check all portals leading from this room to somewhere else
119 116
         for (int i = 0; i < World::getRoom(room).sizePortals(); i++) {
120 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 121
             glm::vec3 newMin, newMax;
124 122
             for (int c = 0; c < 4; c++) {
125 123
                 glm::vec3 vert = portal.getVertex(c);
126 124
                 glm::vec4 result = VP * glm::vec4(vert, 1.0f);
127 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 127
                 if (c == 0) {
134 128
                     newMin = vert;
135 129
                     newMax = vert;
@@ -149,11 +143,6 @@ void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max)
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 146
             //! \fixme Currently also checking behind player, because Z is always 1.0f?!
158 147
             //if ((newMin.z > 0.0f) || (newMin.z < -1.0f) || (newMax.z > 0.0f) || (newMax.z < -1.0f)) {
159 148
             //    continue;
@@ -165,10 +154,15 @@ void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max)
165 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 162
             // Check if this room is already in the list...
169 163
             bool found = false;
170 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 166
                     found = true;
173 167
                     break;
174 168
                 }

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

@@ -357,13 +357,13 @@ protected:
357 357
     static struct stat stat1;
358 358
     static struct stat stat2;
359 359
     static SorterSignature sorter;
360
-#   ifdef MSC_VER
360
+#   ifdef _MSC_VER
361 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 362
     inline static int strcasecmp( const char *s1, const char *s2 )  {
363 363
         return _stricmp(s1,s2);
364 364
         //return lstrcmpiA(s1,s2);  // Not sure this is better
365 365
     }
366
-#   endif //MSC_VER
366
+#   endif //_MSC_VER
367 367
     // Possible problem: sorting is in ASCII with these methods
368 368
     static int Alphasort(const struct dirent **e1,const struct dirent **e2)    {
369 369
         return strcasecmp((*e1)->d_name,(*e2)->d_name);

+ 47
- 1
src/main.cpp View File

@@ -27,8 +27,47 @@
27 27
 
28 28
 #include <glbinding/Binding.h>
29 29
 
30
+#ifdef DEBUG
31
+#include <glbinding/callbacks.h>
32
+#include <glbinding/Meta.h>
33
+#endif
34
+
30 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 71
 int main(int argc, char* argv[]) {
33 72
     command_t cmd;
34 73
     command_init(&cmd, argv[0], VERSION);
@@ -42,9 +81,16 @@ int main(int argc, char* argv[]) {
42 81
     glbinding::Binding::initialize();
43 82
     Log::initialize();
44 83
     RunTime::initialize(); // RunTime is required by other constructors
45
-
46 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 94
     Log::get(LOG_INFO) << "Initializing " << VERSION << Log::endl;
49 95
 
50 96
     // Initialize Windowing

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

@@ -9,6 +9,7 @@
9 9
 
10 10
 #include "global.h"
11 11
 #include "Log.h"
12
+#include "Render.h"
12 13
 #include "system/Window.h"
13 14
 #include "system/Shader.h"
14 15
 
@@ -132,7 +133,12 @@ void Shader::loadUniform(int uni, glm::mat4 mat) {
132 133
 }
133 134
 
134 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 144
 void Shader::use() {

Loading…
Cancel
Save