Просмотр исходного кода

First try at scissoring room portals

Thomas Buck 9 лет назад
Родитель
Сommit
9c84aa597f
6 измененных файлов: 44 добавлений и 30 удалений
  1. 9
    1
      include/Render.h
  2. 7
    12
      src/BoundingBox.cpp
  3. 26
    6
      src/Render.cpp
  4. 0
    1
      src/RoomData.cpp
  5. 0
    2
      src/main.cpp
  6. 2
    8
      src/system/Shader.cpp

+ 9
- 1
include/Render.h Просмотреть файл

@@ -23,6 +23,14 @@ enum class RenderMode {
23 23
     Texture
24 24
 };
25 25
 
26
+struct RoomRenderList {
27
+    RoomRenderList(Room* r, glm::vec2 pos, glm::vec2 size)
28
+        : room(r), portalPos(pos), portalSize(size) { }
29
+
30
+    Room* room;
31
+    glm::vec2 portalPos, portalSize;
32
+};
33
+
26 34
 class Render {
27 35
   public:
28 36
 
@@ -45,7 +53,7 @@ class Render {
45 53
                               glm::vec2 max = glm::vec2(1.0f, 1.0f));
46 54
 
47 55
     static RenderMode mode;
48
-    static std::vector<Room*> roomList;
56
+    static std::vector<RoomRenderList> roomList;
49 57
 
50 58
     static bool displayViewFrustum;
51 59
     static bool displayVisibilityCheck;

+ 7
- 12
src/BoundingBox.cpp Просмотреть файл

@@ -39,7 +39,8 @@ void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot)
39 39
     auto startSize = vertices.size();
40 40
 
41 41
     for (auto& c : corner) {
42
-        vertices.emplace_back(VP * glm::vec4(c, 1.0f));
42
+        glm::vec4 t = VP * glm::vec4(c, 1.0f);
43
+        vertices.emplace_back(glm::vec3(t) / t.w);
43 44
         colorsLine.emplace_back(colorLine);
44 45
         colorsPoint.emplace_back(colorDot);
45 46
     }
@@ -62,16 +63,10 @@ void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot)
62 63
     indicesLine.emplace_back(startSize);
63 64
     indicesLine.emplace_back(startSize);
64 65
     indicesLine.emplace_back(startSize + 1);
65
-    indicesLine.emplace_back(startSize + 1);
66
-    indicesLine.emplace_back(startSize + 4);
67 66
     indicesLine.emplace_back(startSize + 4);
68 67
     indicesLine.emplace_back(startSize + 7);
69
-    indicesLine.emplace_back(startSize + 7);
70
-    indicesLine.emplace_back(startSize + 6);
71 68
     indicesLine.emplace_back(startSize + 6);
72 69
     indicesLine.emplace_back(startSize + 3);
73
-    indicesLine.emplace_back(startSize + 3);
74
-    indicesLine.emplace_back(startSize + 5);
75 70
     indicesLine.emplace_back(startSize + 5);
76 71
     indicesLine.emplace_back(startSize + 2);
77 72
 }
@@ -80,11 +75,11 @@ void BoundingBox::display() {
80 75
     if (vertices.size() > 0) {
81 76
         Shader::drawGL(vertices, colorsLine, indicesLine, glm::mat4(1.0f), gl::GL_LINES);
82 77
         Shader::drawGL(vertices, colorsPoint, glm::mat4(1.0f), gl::GL_POINTS);
83
-
84
-        vertices.clear();
85
-        colorsLine.clear();
86
-        colorsPoint.clear();
87
-        indicesLine.clear();
88 78
     }
79
+
80
+    vertices.clear();
81
+    colorsLine.clear();
82
+    colorsPoint.clear();
83
+    indicesLine.clear();
89 84
 }
90 85
 

+ 26
- 6
src/Render.cpp Просмотреть файл

@@ -10,6 +10,7 @@
10 10
 #include <sstream>
11 11
 
12 12
 #include "global.h"
13
+#include "BoundingBox.h"
13 14
 #include "Camera.h"
14 15
 #include "Log.h"
15 16
 #include "Menu.h"
@@ -26,7 +27,7 @@
26 27
 #include "stb/stb_image_write.h"
27 28
 
28 29
 RenderMode Render::mode = RenderMode::LoadScreen;
29
-std::vector<Room*> Render::roomList;
30
+std::vector<RoomRenderList> Render::roomList;
30 31
 bool Render::displayViewFrustum = false;
31 32
 bool Render::displayVisibilityCheck = false;
32 33
 
@@ -63,25 +64,44 @@ void Render::display() {
63 64
     }
64 65
 
65 66
     for (int r = roomList.size() - 1; r >= 0; r--) {
66
-        roomList.at(r)->display(VP);
67
+        auto& rl = roomList.at(r);
68
+
69
+        //! \fixme TODO scissor to portal in screenspace to fix 4D rendering
70
+
71
+        //gl::glEnable(gl::GL_SCISSOR_TEST);
72
+        //gl::glScissor(rl.portalPos.x, rl.portalPos.y, rl.portalSize.x, rl.portalSize.y);
73
+
74
+        //ImGui::Text("%.2f %.2f", rl.portalPos.x, rl.portalPos.y);
75
+        //ImGui::Text("%.2f %.2f", rl.portalSize.x, rl.portalSize.y);
76
+        //ImGui::Text("--");
77
+
78
+        rl.room->display(VP);
67 79
 
68 80
         for (int i = 0; i < World::sizeEntity(); i++) {
69 81
             auto& e = World::getEntity(i);
70
-            if (roomList.at(r)->getIndex() == e.getRoom()) {
82
+            if (rl.room->getIndex() == e.getRoom()) {
71 83
                 e.display(VP);
72 84
             }
73 85
         }
86
+
87
+        //gl::glDisable(gl::GL_SCISSOR_TEST);
74 88
     }
75 89
 
76 90
     if (displayViewFrustum)
77 91
         Camera::displayFrustum(VP);
78 92
 
93
+    BoundingBox::display();
94
+
79 95
     if (mode == RenderMode::Wireframe) {
80 96
         gl::glPolygonMode(gl::GL_FRONT_AND_BACK, gl::GL_FILL);
81 97
     }
82 98
 }
83 99
 
84 100
 void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max) {
101
+    glm::vec2 halfSize = glm::vec2(Window::getSize()) / 2.0f;
102
+    glm::vec2 pos = (min * halfSize) + halfSize;
103
+    glm::vec2 size = (max * halfSize) + halfSize - pos;
104
+
85 105
     if (room < -1) {
86 106
         // Check if the camera currently is in a room...
87 107
         for (int i = 0; i < World::sizeRoom(); i++) {
@@ -95,11 +115,11 @@ void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max)
95 115
         // Check visibility for all rooms!
96 116
         for (int i = 0; i < World::sizeRoom(); i++) {
97 117
             if (Camera::boxInFrustum(World::getRoom(i).getBoundingBox())) {
98
-                roomList.push_back(&World::getRoom(i));
118
+                roomList.emplace_back(&World::getRoom(i), pos, size);
99 119
             }
100 120
         }
101 121
     } else {
102
-        roomList.push_back(&World::getRoom(room));
122
+        roomList.emplace_back(&World::getRoom(room), pos, size);
103 123
 
104 124
         if (displayVisibilityCheck) {
105 125
             // Display the visibility test for the portal to this room
@@ -157,7 +177,7 @@ void Render::buildRoomList(glm::mat4 VP, int room, glm::vec2 min, glm::vec2 max)
157 177
             // Check if this room is already in the list...
158 178
             bool found = false;
159 179
             for (int n = 0; n < roomList.size(); n++) {
160
-                if (roomList.at(n) == &room) {
180
+                if (roomList.at(n).room == &room) {
161 181
                     found = true;
162 182
                     break;
163 183
                 }

+ 0
- 1
src/RoomData.cpp Просмотреть файл

@@ -13,7 +13,6 @@
13 13
 
14 14
 #include "imgui/imgui.h"
15 15
 
16
-#include <glbinding/gl/gl.h>
17 16
 #include <glm/gtc/matrix_transform.hpp>
18 17
 
19 18
 StaticModel::StaticModel(glm::vec3 pos, float angle, int i) : id(i), cache(-1) {

+ 0
- 2
src/main.cpp Просмотреть файл

@@ -9,7 +9,6 @@
9 9
 #include <memory>
10 10
 
11 11
 #include "global.h"
12
-#include "BoundingBox.h"
13 12
 #include "Camera.h"
14 13
 #include "Log.h"
15 14
 #include "Menu.h"
@@ -196,7 +195,6 @@ int main(int argc, char* argv[]) {
196 195
 
197 196
 void renderFrame() {
198 197
     Render::display();
199
-    BoundingBox::display();
200 198
     UI::display();
201 199
     Window::swapBuffers();
202 200
     RunTime::updateFPS();

+ 2
- 8
src/system/Shader.cpp Просмотреть файл

@@ -416,10 +416,7 @@ out vec2 UV;
416 416
 uniform mat4 MVP;
417 417
 
418 418
 void main() {
419
-    vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
420
-                          vertexPosition_modelspace.y,
421
-                          vertexPosition_modelspace.z,
422
-                          1);
419
+    vec4 pos = MVP * vec4(vertexPosition_modelspace, 1);
423 420
     gl_Position = pos;
424 421
     UV = vertexUV;
425 422
 }
@@ -452,10 +449,7 @@ out vec3 color;
452 449
 uniform mat4 MVP;
453 450
 
454 451
 void main() {
455
-    vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
456
-                          vertexPosition_modelspace.y,
457
-                          vertexPosition_modelspace.z,
458
-                          1);
452
+    vec4 pos = MVP * vec4(vertexPosition_modelspace, 1);
459 453
     gl_Position = pos;
460 454
     color = vertexColor;
461 455
 }

Загрузка…
Отмена
Сохранить