Parcourir la source

Removed Exceptions, moved GL code into Shader

Thomas Buck il y a 10 ans
Parent
révision
a3d6411368

+ 4
- 0
ChangeLog.md Voir le fichier

@@ -2,6 +2,10 @@
2 2
 
3 3
 ## OpenRaider (0.1.3) xythobuz <xythobuz@xythobuz.de>
4 4
 
5
+    [ 20141231 ]
6
+    * No longer using Exceptions.
7
+    * Moved OpenGL related code from Window into Shader, imguiShader in UI.
8
+
5 9
     [ 20141230 ]
6 10
     * Added random number generation utility
7 11
     * Added file name searching utilities

+ 0
- 28
include/Exception.h Voir le fichier

@@ -1,28 +0,0 @@
1
-/*!
2
- * \file include/Exception.h
3
- * \brief Custom global Exception
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#ifndef _EXCEPTION_H_
9
-#define _EXCEPTION_H_
10
-
11
-#include <memory>
12
-#include <stdexcept>
13
-#include <string>
14
-
15
-class Exception : std::runtime_error {
16
-  public:
17
-    Exception(std::string what);
18
-
19
-    static std::string getLastException();
20
-
21
-  private:
22
-    static std::string lastException;
23
-
24
-    virtual void foo(); //!< We don't want to emit a vtable in every translation unit
25
-};
26
-
27
-#endif
28
-

+ 6
- 0
include/UI.h Voir le fichier

@@ -15,6 +15,8 @@
15 15
 #include <glm/vec2.hpp>
16 16
 #include <glm/gtc/type_precision.hpp>
17 17
 
18
+#include "system/Shader.h"
19
+
18 20
 class ImDrawList;
19 21
 
20 22
 class UI {
@@ -49,6 +51,10 @@ class UI {
49 51
     static std::list<std::tuple<unsigned int, unsigned int, KeyboardButton, bool>> clickEvents;
50 52
     static std::list<std::tuple<int, int, int, int>> motionEvents;
51 53
     static std::list<std::tuple<int, int>> scrollEvents;
54
+
55
+    static Shader imguiShader;
56
+    static const char* imguiShaderVertex;
57
+    static const char* imguiShaderFragment;
52 58
 };
53 59
 
54 60
 #endif

+ 49
- 4
include/system/Shader.h Voir le fichier

@@ -15,6 +15,26 @@
15 15
 
16 16
 #include "TextureManager.h"
17 17
 
18
+class ShaderBuffer {
19
+  public:
20
+    ShaderBuffer() : buffer(0), created(false) { }
21
+    ~ShaderBuffer();
22
+
23
+    void bufferData(int elem, int size, void* data);
24
+
25
+    template<typename T>
26
+    void bufferData(std::vector<T> v)
27
+        { bufferData(v.size(), sizeof(T), &v[0]); }
28
+
29
+    void bindBuffer();
30
+    void bindBuffer(int location, int size);
31
+    void unbind(int location);
32
+
33
+  private:
34
+    unsigned int buffer;
35
+    bool created;
36
+};
37
+
18 38
 class Shader {
19 39
   public:
20 40
     Shader() : programID(-1) { }
@@ -30,10 +50,9 @@ class Shader {
30 50
     unsigned int getBuffer(int n);
31 51
 
32 52
     template<typename T>
33
-    void bufferData(int buff, std::vector<T> v) {
34
-        glBindBuffer(GL_ARRAY_BUFFER, getBuffer(buff));
35
-        glBufferData(GL_ARRAY_BUFFER, v.size() * sizeof(T), &v[0], GL_STATIC_DRAW);
36
-    }
53
+    void bufferData(int buff, std::vector<T> v)
54
+        { bufferData(buff, v.size(), sizeof(T), &v[0]); }
55
+    void bufferData(int buff, int elem, int size, void* d);
37 56
 
38 57
     void loadUniform(int uni, glm::vec2 vec);
39 58
     void loadUniform(int uni, glm::vec4 vec);
@@ -45,11 +64,37 @@ class Shader {
45 64
 
46 65
     void disableAttribs();
47 66
 
67
+    static int initialize();
68
+    static void shutdown();
69
+
70
+    static void drawGL(std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs,
71
+                       glm::vec4 color, unsigned int texture);
72
+
73
+    static void drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& uvs,
74
+                       std::vector<unsigned short>& indices, glm::mat4 MVP, unsigned int texture);
75
+
76
+    static void drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& colors,
77
+                       std::vector<unsigned short>& indices, glm::mat4 MVP, int mode = GL_TRIANGLES);
78
+
48 79
   private:
49 80
     int programID;
50 81
     std::vector<unsigned int> uniforms;
51 82
     std::vector<unsigned int> buffers;
52 83
     std::vector<bool> attribs;
84
+
85
+    static Shader textShader;
86
+    static const char* textShaderVertex;
87
+    static const char* textShaderFragment;
88
+
89
+    static Shader textureShader;
90
+    static const char* textureShaderVertex;
91
+    static const char* textureShaderFragment;
92
+
93
+    static Shader colorShader;
94
+    static const char* colorShaderVertex;
95
+    static const char* colorShaderFragment;
96
+
97
+    static unsigned int vertexArrayID;
53 98
 };
54 99
 
55 100
 #endif

+ 0
- 34
include/system/Window.h Voir le fichier

@@ -15,8 +15,6 @@
15 15
 #include <glm/vec4.hpp>
16 16
 #include <glm/gtc/type_precision.hpp>
17 17
 
18
-#include "Shader.h"
19
-
20 18
 class Window {
21 19
   public:
22 20
     static int initialize();
@@ -35,38 +33,6 @@ class Window {
35 33
 
36 34
     static void setTextInput(bool t);
37 35
     static bool getTextInput();
38
-
39
-    static void drawTextGL(std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs,
40
-                           glm::vec4 color, unsigned int texture);
41
-
42
-    static void drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& uvs,
43
-                       std::vector<unsigned short>& indices, glm::mat4 MVP, unsigned int texture);
44
-
45
-    static void drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& colors,
46
-                       std::vector<unsigned short>& indices, glm::mat4 MVP, int mode = GL_TRIANGLES);
47
-
48
-  private:
49
-    static int initializeGL();
50
-    static void shutdownGL();
51
-
52
-    static Shader textShader;
53
-    static const char* textShaderVertex;
54
-    static const char* textShaderFragment;
55
-
56
-    static Shader imguiShader;
57
-    static const char* imguiShaderVertex;
58
-    static const char* imguiShaderFragment;
59
-    friend class UI;
60
-
61
-    static Shader textureShader;
62
-    static const char* textureShaderVertex;
63
-    static const char* textureShaderFragment;
64
-
65
-    static Shader colorShader;
66
-    static const char* colorShaderVertex;
67
-    static const char* colorShaderFragment;
68
-
69
-    static unsigned int vertexArrayID;
70 36
 };
71 37
 
72 38
 #endif

+ 0
- 2
include/utils/Folder.h Voir le fichier

@@ -8,8 +8,6 @@
8 8
 #ifndef _UTILS_FOLDER_H_
9 9
 #define _UTILS_FOLDER_H_
10 10
 
11
-#include "Exception.h"
12
-
13 11
 #include <functional>
14 12
 #include <memory>
15 13
 #include <string>

+ 0
- 1
src/CMakeLists.txt Voir le fichier

@@ -58,7 +58,6 @@ endif (GLM_FOUND)
58 58
 set (SRCS ${SRCS} "Camera.cpp" "../include/Camera.h")
59 59
 set (SRCS ${SRCS} "Console.cpp" "../include/Console.h")
60 60
 set (SRCS ${SRCS} "Entity.cpp" "../include/Entity.h")
61
-set (SRCS ${SRCS} "Exception.cpp" "../include/Exception.h")
62 61
 set (SRCS ${SRCS} "Game.cpp" "../include/Game.h")
63 62
 set (SRCS ${SRCS} "Log.cpp" "../include/Log.h")
64 63
 set (SRCS ${SRCS} "main.cpp")

+ 3
- 2
src/Camera.cpp Voir le fichier

@@ -13,6 +13,7 @@
13 13
 
14 14
 #include "global.h"
15 15
 #include "RunTime.h"
16
+#include "system/Shader.h"
16 17
 #include "system/Window.h"
17 18
 #include "Camera.h"
18 19
 
@@ -334,7 +335,7 @@ void Camera::displayFrustum(glm::mat4 MVP) {
334 335
         inds.push_back(4 * i);
335 336
     }
336 337
 
337
-    Window::drawGL(verts, cols, inds, MVP);
338
+    Shader::drawGL(verts, cols, inds, MVP);
338 339
 
339 340
     verts.clear();
340 341
     cols.clear();
@@ -343,6 +344,6 @@ void Camera::displayFrustum(glm::mat4 MVP) {
343 344
     verts.push_back(drawPos);
344 345
     cols.push_back(glm::vec3(1.0f, 1.0f, 1.0f));
345 346
     inds.push_back(0);
346
-    Window::drawGL(verts, cols, inds, MVP, GL_POINTS);
347
+    Shader::drawGL(verts, cols, inds, MVP, GL_POINTS);
347 348
 }
348 349
 

+ 0
- 22
src/Exception.cpp Voir le fichier

@@ -1,22 +0,0 @@
1
-/*!
2
- * \file src/Exception.cpp
3
- * \brief Custom global Exception
4
- *
5
- * \author xythobuz
6
- */
7
-
8
-#include "global.h"
9
-#include "Exception.h"
10
-
11
-std::string Exception::lastException("No custom exception since start!");
12
-
13
-Exception::Exception(std::string what) : runtime_error(what) {
14
-    lastException = what;
15
-}
16
-
17
-std::string Exception::getLastException() {
18
-    return lastException;
19
-}
20
-
21
-void Exception::foo() { }
22
-

+ 3
- 3
src/Mesh.cpp Voir le fichier

@@ -7,7 +7,7 @@
7 7
 
8 8
 #include "global.h"
9 9
 #include "TextureManager.h"
10
-#include "system/Window.h"
10
+#include "system/Shader.h"
11 11
 #include "Mesh.h"
12 12
 
13 13
 Mesh::Mesh(const std::vector<glm::vec3>& vert,
@@ -131,7 +131,7 @@ void Mesh::display(glm::mat4 MVP) {
131 131
                 indexPos++;
132 132
 
133 133
             std::vector<unsigned short> ind(indices.begin() + indexStart, indices.begin() + indexPos);
134
-            Window::drawGL(vertices, uvs, ind, MVP, texture);
134
+            Shader::drawGL(vertices, uvs, ind, MVP, texture);
135 135
 
136 136
             if (indexPos < indices.size()) {
137 137
                 indexStart = indexPos;
@@ -142,6 +142,6 @@ void Mesh::display(glm::mat4 MVP) {
142 142
     }
143 143
 
144 144
     if (indicesColor.size() > 0)
145
-        Window::drawGL(verticesColor, colors, indicesColor, MVP);
145
+        Shader::drawGL(verticesColor, colors, indicesColor, MVP);
146 146
 }
147 147
 

+ 3
- 2
src/Render.cpp Voir le fichier

@@ -19,6 +19,7 @@
19 19
 #include "Log.h"
20 20
 #include "UI.h"
21 21
 #include "World.h"
22
+#include "system/Shader.h"
22 23
 #include "system/Window.h"
23 24
 #include "utils/strings.h"
24 25
 #include "Render.h"
@@ -184,10 +185,10 @@ void Render::drawTexture(float x, float y, float w, float h, glm::vec4 color,
184 185
     uvs.push_back(glm::vec2(1.0f, 1.0f));
185 186
     uvs.push_back(glm::vec2(0.0f, 0.0f));
186 187
 
187
-    //! \fixme drawTextGL only uses SYSTEM textures!
188
+    //! \fixme This drawGL only uses SYSTEM textures!
188 189
     assert(s == TextureManager::TextureStorage::SYSTEM);
189 190
 
190
-    Window::drawTextGL(vertices, uvs, color, texture);
191
+    Shader::drawGL(vertices, uvs, color, texture);
191 192
 }
192 193
 
193 194
 static const int modeStringCount = 4;

+ 3
- 3
src/RoomData.cpp Voir le fichier

@@ -10,7 +10,7 @@
10 10
 #include "global.h"
11 11
 #include "SkeletalModel.h"
12 12
 #include "World.h"
13
-#include "system/Window.h"
13
+#include "system/Shader.h"
14 14
 #include "RoomData.h"
15 15
 
16 16
 void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot) {
@@ -40,7 +40,7 @@ void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot)
40 40
     inds.push_back(5);
41 41
     inds.push_back(2);
42 42
 
43
-    Window::drawGL(verts, cols, inds, VP, GL_LINE_STRIP);
43
+    Shader::drawGL(verts, cols, inds, VP, GL_LINE_STRIP);
44 44
 
45 45
     cols.clear();
46 46
     inds.clear();
@@ -50,7 +50,7 @@ void BoundingBox::display(glm::mat4 VP, glm::vec3 colorLine, glm::vec3 colorDot)
50 50
         inds.push_back(i);
51 51
     }
52 52
 
53
-    Window::drawGL(verts, cols, inds, VP, GL_POINTS);
53
+    Shader::drawGL(verts, cols, inds, VP, GL_POINTS);
54 54
 }
55 55
 
56 56
 // ----------------------------------------------------------------------------

+ 2
- 2
src/RoomMesh.cpp Voir le fichier

@@ -8,7 +8,7 @@
8 8
 #include "global.h"
9 9
 #include "Mesh.h"
10 10
 #include "TextureManager.h"
11
-#include "system/Window.h"
11
+#include "system/Shader.h"
12 12
 #include "RoomMesh.h"
13 13
 
14 14
 RoomMesh::RoomMesh(const std::vector<RoomVertexTR2>& vert,
@@ -83,7 +83,7 @@ void RoomMesh::display(glm::mat4 MVP) {
83 83
                 indexPos++;
84 84
 
85 85
             std::vector<unsigned short> ind(indices.begin() + indexStart, indices.begin() + indexPos);
86
-            Window::drawGL(vertices, uvs, ind, MVP, texture);
86
+            Shader::drawGL(vertices, uvs, ind, MVP, texture);
87 87
 
88 88
             if (indexPos < indices.size()) {
89 89
                 indexStart = indexPos;

+ 62
- 10
src/UI.cpp Voir le fichier

@@ -28,6 +28,7 @@
28 28
 #include "utils/time.h"
29 29
 #include "UI.h"
30 30
 
31
+Shader UI::imguiShader;
31 32
 bool UI::visible = false;
32 33
 unsigned int UI::fontTex;
33 34
 std::string UI::iniFilename;
@@ -45,6 +46,14 @@ void UI::setSize(glm::i32vec2 s) {
45 46
 }
46 47
 
47 48
 int UI::initialize() {
49
+    if (imguiShader.compile(imguiShaderVertex, imguiShaderFragment) < 0)
50
+        return -1;
51
+    if (imguiShader.addUniform("screen") < 0)
52
+        return -2;
53
+    if (imguiShader.addUniform("textureSampler") < 0)
54
+        return -3;
55
+    imguiShader.addBuffer(3);
56
+
48 57
     iniFilename = RunTime::getBaseDir() + "/imgui.ini";
49 58
     logFilename = RunTime::getBaseDir() + "/imgui_log.txt";
50 59
 
@@ -525,12 +534,12 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
525 534
     glEnable(GL_SCISSOR_TEST);
526 535
     glDisable(GL_DEPTH_TEST);
527 536
 
528
-    Window::imguiShader.use();
529
-    Window::imguiShader.loadUniform(0, Window::getSize());
530
-    Window::imguiShader.loadUniform(1, fontTex, TextureManager::TextureStorage::SYSTEM);
531
-    Window::imguiShader.bindBuffer(0, 0, 2);
532
-    Window::imguiShader.bindBuffer(1, 1, 2);
533
-    Window::imguiShader.bindBuffer(2, 2, 4);
537
+    imguiShader.use();
538
+    imguiShader.loadUniform(0, Window::getSize());
539
+    imguiShader.loadUniform(1, fontTex, TextureManager::TextureStorage::SYSTEM);
540
+    imguiShader.bindBuffer(0, 0, 2);
541
+    imguiShader.bindBuffer(1, 1, 2);
542
+    imguiShader.bindBuffer(2, 2, 4);
534 543
 
535 544
     std::vector<glm::vec2> vertices;
536 545
     std::vector<glm::vec2> uvs;
@@ -561,9 +570,9 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
561 570
 
562 571
             offset += commands[n].vtx_count;
563 572
 
564
-            Window::imguiShader.bufferData(0, vertices);
565
-            Window::imguiShader.bufferData(1, uvs);
566
-            Window::imguiShader.bufferData(2, colors);
573
+            imguiShader.bufferData(0, vertices);
574
+            imguiShader.bufferData(1, uvs);
575
+            imguiShader.bufferData(2, colors);
567 576
 
568 577
             glScissor(commands[n].clip_rect.x,
569 578
                       Window::getSize().y - commands[n].clip_rect.w,
@@ -578,9 +587,52 @@ void UI::renderImGui(ImDrawList** const cmd_lists, int cmd_lists_count) {
578 587
         }
579 588
     }
580 589
 
581
-    Window::imguiShader.disableAttribs();
590
+    imguiShader.disableAttribs();
582 591
 
583 592
     glEnable(GL_DEPTH_TEST);
584 593
     glDisable(GL_SCISSOR_TEST);
585 594
 }
586 595
 
596
+// --------------------------------------
597
+// *INDENT-OFF*
598
+
599
+const char* UI::imguiShaderVertex = R"!?!(
600
+#version 330 core
601
+
602
+layout(location = 0) in vec2 vertexPosition_screen;
603
+layout(location = 1) in vec2 vertexUV;
604
+layout(location = 2) in vec4 vertexColor;
605
+
606
+out vec2 UV;
607
+out vec4 FragColor;
608
+
609
+uniform vec2 screen;
610
+
611
+void main() {
612
+    vec2 halfScreen = screen / 2;
613
+    vec2 vertexPosition_homogenous = (vertexPosition_screen - halfScreen) / halfScreen;
614
+
615
+    gl_Position = vec4(vertexPosition_homogenous.x, -vertexPosition_homogenous.y, 0, 1);
616
+    UV = vertexUV;
617
+    FragColor = vertexColor;
618
+}
619
+)!?!";
620
+
621
+const char* UI::imguiShaderFragment = R"!?!(
622
+#version 330 core
623
+
624
+in vec2 UV;
625
+in vec4 FragColor;
626
+
627
+out vec4 color;
628
+
629
+uniform sampler2D textureSampler;
630
+
631
+void main() {
632
+    color = texture(textureSampler, UV) * FragColor;
633
+}
634
+)!?!";
635
+
636
+// --------------------------------------
637
+// *INDENT-ON*
638
+

+ 15
- 11
src/main.cpp Voir le fichier

@@ -10,7 +10,6 @@
10 10
 
11 11
 #include "global.h"
12 12
 #include "Camera.h"
13
-#include "Exception.h"
14 13
 #include "Game.h"
15 14
 #include "Log.h"
16 15
 #include "MenuFolder.h"
@@ -22,6 +21,7 @@
22 21
 #include "commander/commander.h"
23 22
 #include "commands/Command.h"
24 23
 #include "system/Font.h"
24
+#include "system/Shader.h"
25 25
 #include "system/Sound.h"
26 26
 #include "system/Window.h"
27 27
 #include "utils/time.h"
@@ -80,15 +80,21 @@ int main(int argc, char* argv[]) {
80 80
     // Initialize Windowing
81 81
     int error = Window::initialize();
82 82
     if (error != 0) {
83
-        std::cout << "Could not initialize Window/GL (" << error << ")!" << std::endl;
83
+        std::cout << "Could not initialize Window (" << error << ")!" << std::endl;
84 84
         return -1;
85 85
     }
86 86
 
87
+    error = Shader::initialize();
88
+    if (error != 0) {
89
+        std::cout << "Could not initialize OpenGL (" << error << ")!" << std::endl;
90
+        return -2;
91
+    }
92
+
87 93
     // Initialize Texture Manager
88 94
     error = getTextureManager().initialize();
89 95
     if (error != 0) {
90 96
         std::cout << "Could not initialize TextureManager (" << error << ")!" << std::endl;
91
-        return -2;
97
+        return -3;
92 98
     }
93 99
 
94 100
     if (configFileToUse == "") {
@@ -108,35 +114,35 @@ int main(int argc, char* argv[]) {
108 114
     error = getTextureManager().initializeSplash();
109 115
     if (error != 0) {
110 116
         std::cout << "Coult not load Splash Texture (" << error << ")!" << std::endl;
111
-        return -3;
117
+        return -4;
112 118
     }
113 119
 
114 120
     // Initialize Sound
115 121
     error = Sound::initialize();
116 122
     if (error != 0) {
117 123
         std::cout << "Could not initialize Sound (" << error << ")!" << std::endl;
118
-        return -4;
124
+        return -5;
119 125
     }
120 126
 
121 127
     // Initialize Menu
122 128
     error = getMenu().initialize();
123 129
     if (error != 0) {
124 130
         std::cout << "Could not initialize Menu (" << error << ")!" << std::endl;
125
-        return -5;
131
+        return -6;
126 132
     }
127 133
 
128 134
     // Initialize Debug UI
129 135
     error = UI::initialize();
130 136
     if (error != 0) {
131 137
         std::cout << "Could not initialize Debug UI (" << error << ")!" << std::endl;
132
-        return -6;
138
+        return -7;
133 139
     }
134 140
 
135 141
     // Initialize Game Engine
136 142
     error = getGame().initialize();
137 143
     if (error != 0) {
138 144
         std::cout << "Could not initialize Game (" << error << ")!" << std::endl;
139
-        return -7;
145
+        return -8;
140 146
     }
141 147
 
142 148
     getLog() << "Starting " << VERSION << Log::endl;
@@ -153,6 +159,7 @@ int main(int argc, char* argv[]) {
153 159
     UI::shutdown();
154 160
     Font::shutdown();
155 161
     Sound::shutdown();
162
+    Shader::shutdown();
156 163
     Window::shutdown();
157 164
 
158 165
 #ifdef DEBUG
@@ -196,9 +203,6 @@ namespace {
196 203
 
197 204
         delete [] strs;
198 205
 
199
-        std::cout << std::endl << "Last custom Exception:" << std::endl;
200
-        std::cout << "    " << Exception::getLastException() << std::endl << std::endl;
201
-
202 206
         oldTerminateHandler();
203 207
         abort();
204 208
     }

+ 3
- 3
src/system/FontSDL.cpp Voir le fichier

@@ -9,7 +9,7 @@
9 9
 
10 10
 #include "global.h"
11 11
 #include "TextureManager.h"
12
-#include "system/Window.h"
12
+#include "system/Shader.h"
13 13
 #include "system/FontSDL.h"
14 14
 
15 15
 bool FontSDL::mFontInit = false;
@@ -126,7 +126,7 @@ void FontSDL::drawText(unsigned int x, unsigned int y, float scale,
126 126
     uvs.push_back(glm::vec2(1.0f, 1.0f));
127 127
     uvs.push_back(glm::vec2(0.0f, 0.0f));
128 128
 
129
-    Window::drawTextGL(vertices, uvs, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), mFontTexture);
129
+    Shader::drawGL(vertices, uvs, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), mFontTexture);
130 130
 }
131 131
 
132 132
 unsigned int FontSDL::heightText(float scale, unsigned int maxWidth, std::string s) {
@@ -208,6 +208,6 @@ void FontSDL::drawTextWrapped(unsigned int x, unsigned int y, float scale,
208 208
     uvs.push_back(glm::vec2(1.0f, 1.0f));
209 209
     uvs.push_back(glm::vec2(0.0f, 0.0f));
210 210
 
211
-    Window::drawTextGL(vertices, uvs, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), mFontTexture);
211
+    Shader::drawGL(vertices, uvs, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f), mFontTexture);
212 212
 }
213 213
 

+ 3
- 3
src/system/FontTRLE.cpp Voir le fichier

@@ -13,7 +13,7 @@
13 13
 #include "global.h"
14 14
 #include "TextureManager.h"
15 15
 #include "utils/strings.h"
16
-#include "system/Window.h"
16
+#include "system/Shader.h"
17 17
 #include "system/FontTRLE.h"
18 18
 
19 19
 #define SCALING 2.0f
@@ -167,7 +167,7 @@ void FontTRLE::drawText(unsigned int x, unsigned int y, float scale,
167 167
     }
168 168
 
169 169
     glm::vec4 col(color[0] / 256.0f, color[1] / 256.0f, color[2] / 256.0f, color[3] / 256.0f);
170
-    Window::drawTextGL(vertices, uvs, col, mFontTexture);
170
+    Shader::drawGL(vertices, uvs, col, mFontTexture);
171 171
 }
172 172
 
173 173
 unsigned int FontTRLE::heightText(float scale, unsigned int maxWidth, std::string s) {
@@ -241,7 +241,7 @@ void FontTRLE::drawTextWrapped(unsigned int x, unsigned int y, float scale,
241 241
     }
242 242
 
243 243
     glm::vec4 col(color[0] / 256.0f, color[1] / 256.0f, color[2] / 256.0f, color[3] / 256.0f);
244
-    Window::drawTextGL(vertices, uvs, col, mFontTexture);
244
+    Shader::drawGL(vertices, uvs, col, mFontTexture);
245 245
 }
246 246
 
247 247
 int FontTRLE::defaultOffsets[106][5] = {

+ 267
- 0
src/system/Shader.cpp Voir le fichier

@@ -8,8 +8,41 @@
8 8
 #include "global.h"
9 9
 #include "Log.h"
10 10
 #include "TextureManager.h"
11
+#include "system/Window.h"
11 12
 #include "system/Shader.h"
12 13
 
14
+ShaderBuffer::~ShaderBuffer() {
15
+    if (created) {
16
+        glDeleteBuffers(1, &buffer);
17
+    }
18
+}
19
+
20
+void ShaderBuffer::bufferData(int elem, int size, void* data) {
21
+    if (!created) {
22
+        glGenBuffers(1, &buffer);
23
+        created = true;
24
+    }
25
+
26
+    glBindBuffer(GL_ARRAY_BUFFER, buffer);
27
+    glBufferData(GL_ARRAY_BUFFER, elem * size, data, GL_STATIC_DRAW);
28
+}
29
+
30
+void ShaderBuffer::bindBuffer() {
31
+    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffer);
32
+}
33
+
34
+void ShaderBuffer::bindBuffer(int location, int size) {
35
+    glEnableVertexAttribArray(location);
36
+    glBindBuffer(GL_ARRAY_BUFFER, buffer);
37
+    glVertexAttribPointer(location, size, GL_FLOAT, GL_FALSE, 0, nullptr);
38
+}
39
+
40
+void ShaderBuffer::unbind(int location) {
41
+    glDisableVertexAttribArray(location);
42
+}
43
+
44
+// ----------------------------------------------------------------------------
45
+
13 46
 Shader::~Shader() {
14 47
     if (programID >= 0)
15 48
         glDeleteProgram(programID);
@@ -48,6 +81,11 @@ unsigned int Shader::getBuffer(int n) {
48 81
     return buffers.at(n);
49 82
 }
50 83
 
84
+void Shader::bufferData(int buff, int elem, int size, void* d) {
85
+    glBindBuffer(GL_ARRAY_BUFFER, getBuffer(buff));
86
+    glBufferData(GL_ARRAY_BUFFER, elem * size, d, GL_STREAM_DRAW);
87
+}
88
+
51 89
 void Shader::loadUniform(int uni, glm::vec2 vec) {
52 90
     glUniform2f(getUniform(uni), vec.x, vec.y);
53 91
 }
@@ -165,3 +203,232 @@ int Shader::compile(const char* vertex, const char* fragment) {
165 203
     return programID;
166 204
 }
167 205
 
206
+// ----------------------------------------------------------------------------
207
+
208
+Shader Shader::textShader;
209
+Shader Shader::textureShader;
210
+Shader Shader::colorShader;
211
+unsigned int Shader::vertexArrayID = 0;
212
+
213
+int Shader::initialize() {
214
+    getLog() << "GL Ven.: " << glGetString(GL_VENDOR) << Log::endl;
215
+    getLog() << "GL Ren.: " << glGetString(GL_RENDERER) << Log::endl;
216
+    getLog() << "GL Ver.: " << glGetString(GL_VERSION) << Log::endl;
217
+    getLog() << "GLSL V.: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << Log::endl;
218
+
219
+    glGenVertexArrays(1, &vertexArrayID);
220
+    glBindVertexArray(vertexArrayID);
221
+
222
+    // Set background to black
223
+    //glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f, BLACK[2] / 256.0f, BLACK[3] / 256.0f);
224
+    glClearColor(0.0f, 0.0f, 0.4f, 1.0f);
225
+
226
+    // Set up Z buffer
227
+    glEnable(GL_DEPTH_TEST);
228
+    // Accept fragment if closer to camera
229
+    glDepthFunc(GL_LESS);
230
+
231
+    // Set up culling
232
+    //glEnable(GL_CULL_FACE); //! \todo Transparency?
233
+
234
+    glPointSize(5.0f);
235
+
236
+    if (textShader.compile(textShaderVertex, textShaderFragment) < 0)
237
+        return -1;
238
+    if (textShader.addUniform("screen") < 0)
239
+        return -2;
240
+    if (textShader.addUniform("textureSampler") < 0)
241
+        return -3;
242
+    if (textShader.addUniform("colorVar") < 0)
243
+        return -4;
244
+    textShader.addBuffer(2);
245
+
246
+    if (textureShader.compile(textureShaderVertex, textureShaderFragment) < 0)
247
+        return -5;
248
+    if (textureShader.addUniform("MVP") < 0)
249
+        return -6;
250
+    if (textureShader.addUniform("textureSampler") < 0)
251
+        return -7;
252
+    textureShader.addBuffer(3);
253
+
254
+    if (colorShader.compile(colorShaderVertex, colorShaderFragment) < 0)
255
+        return -8;
256
+    if (colorShader.addUniform("MVP") < 0)
257
+        return -9;
258
+    colorShader.addBuffer(3);
259
+
260
+    glEnable(GL_BLEND);
261
+    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
262
+
263
+    return 0;
264
+}
265
+
266
+void Shader::shutdown() {
267
+    glDeleteVertexArrays(1, &vertexArrayID);
268
+}
269
+
270
+void Shader::drawGL(std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs,
271
+                    glm::vec4 color, unsigned int texture) {
272
+    assert(vertices.size() == uvs.size());
273
+    assert((vertices.size() % 3) == 0);
274
+
275
+    textShader.bufferData(0, vertices);
276
+    textShader.bufferData(1, uvs);
277
+    textShader.use();
278
+    textShader.loadUniform(0, Window::getSize());
279
+    textShader.loadUniform(1, texture, TextureManager::TextureStorage::SYSTEM);
280
+    textShader.loadUniform(2, color);
281
+    textShader.bindBuffer(0, 0, 2);
282
+    textShader.bindBuffer(1, 1, 2);
283
+
284
+    glDisable(GL_DEPTH_TEST);
285
+    glDrawArrays(GL_TRIANGLES, 0, vertices.size());
286
+    glEnable(GL_DEPTH_TEST);
287
+
288
+    textShader.disableAttribs();
289
+}
290
+
291
+void Shader::drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& uvs,
292
+                    std::vector<unsigned short>& indices, glm::mat4 MVP, unsigned int texture) {
293
+    assert(vertices.size() == uvs.size());
294
+    assert((indices.size() % 3) == 0);
295
+
296
+    textureShader.bufferData(0, vertices);
297
+    textureShader.bufferData(1, uvs);
298
+    textureShader.bufferData(2, indices);
299
+    textureShader.use();
300
+    textureShader.loadUniform(0, MVP);
301
+    textureShader.loadUniform(1, texture, TextureManager::TextureStorage::GAME);
302
+    textureShader.bindBuffer(0, 0, 3);
303
+    textureShader.bindBuffer(1, 1, 2);
304
+    textureShader.bindBuffer(2);
305
+    glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, nullptr);
306
+    textureShader.disableAttribs();
307
+}
308
+
309
+void Shader::drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& colors,
310
+                    std::vector<unsigned short>& indices, glm::mat4 MVP, int mode) {
311
+    assert(vertices.size() == colors.size());
312
+
313
+    colorShader.bufferData(0, vertices);
314
+    colorShader.bufferData(1, colors);
315
+    colorShader.bufferData(2, indices);
316
+    colorShader.use();
317
+    colorShader.loadUniform(0, MVP);
318
+    colorShader.bindBuffer(0, 0, 3);
319
+    colorShader.bindBuffer(1, 1, 3);
320
+    colorShader.bindBuffer(2);
321
+    glDrawElements(mode, indices.size(), GL_UNSIGNED_SHORT, nullptr);
322
+    colorShader.disableAttribs();
323
+}
324
+
325
+// --------------------------------------
326
+// *INDENT-OFF*
327
+
328
+const char* Shader::textShaderVertex = R"!?!(
329
+#version 330 core
330
+
331
+layout(location = 0) in vec2 vertexPosition_screen;
332
+layout(location = 1) in vec2 vertexUV;
333
+
334
+out vec2 UV;
335
+
336
+uniform vec2 screen;
337
+
338
+void main() {
339
+    vec2 halfScreen = screen / 2;
340
+    vec2 vertexPosition_homogenous = (vertexPosition_screen - halfScreen) / halfScreen;
341
+
342
+    gl_Position = vec4(vertexPosition_homogenous.x, -vertexPosition_homogenous.y, 0, 1);
343
+    UV = vertexUV;
344
+}
345
+)!?!";
346
+
347
+const char* Shader::textShaderFragment = R"!?!(
348
+#version 330 core
349
+
350
+in vec2 UV;
351
+
352
+out vec4 color;
353
+
354
+uniform sampler2D textureSampler;
355
+uniform vec4 colorVar;
356
+
357
+void main() {
358
+    color = texture(textureSampler, UV) * colorVar;
359
+}
360
+)!?!";
361
+
362
+// --------------------------------------
363
+
364
+const char* Shader::textureShaderVertex = R"!?!(
365
+#version 330 core
366
+
367
+layout(location = 0) in vec3 vertexPosition_modelspace;
368
+layout(location = 1) in vec2 vertexUV;
369
+
370
+out vec2 UV;
371
+
372
+uniform mat4 MVP;
373
+
374
+void main() {
375
+    vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
376
+                          -vertexPosition_modelspace.y,
377
+                          vertexPosition_modelspace.z,
378
+                          1);
379
+    gl_Position = vec4(-pos.x, pos.yzw);
380
+    UV = vertexUV;
381
+}
382
+)!?!";
383
+
384
+const char* Shader::textureShaderFragment = R"!?!(
385
+#version 330 core
386
+
387
+in vec2 UV;
388
+
389
+out vec4 color;
390
+
391
+uniform sampler2D textureSampler;
392
+
393
+void main() {
394
+    color = texture(textureSampler, UV);
395
+}
396
+)!?!";
397
+
398
+// --------------------------------------
399
+
400
+const char* Shader::colorShaderVertex = R"!?!(
401
+#version 330 core
402
+
403
+layout(location = 0) in vec3 vertexPosition_modelspace;
404
+layout(location = 1) in vec3 vertexColor;
405
+
406
+out vec3 Color;
407
+
408
+uniform mat4 MVP;
409
+
410
+void main() {
411
+    vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
412
+                          -vertexPosition_modelspace.y,
413
+                          vertexPosition_modelspace.z,
414
+                          1);
415
+    gl_Position = vec4(-pos.x, pos.yzw);
416
+    Color = vertexColor;
417
+}
418
+)!?!";
419
+
420
+const char* Shader::colorShaderFragment = R"!?!(
421
+#version 330 core
422
+
423
+in vec3 Color;
424
+
425
+out vec4 color;
426
+
427
+void main() {
428
+    color = vec4(Color, 1);
429
+}
430
+)!?!";
431
+
432
+// --------------------------------------
433
+// *INDENT-ON*
434
+

+ 0
- 283
src/system/Window.cpp Voir le fichier

@@ -7,9 +7,7 @@
7 7
 
8 8
 #include "global.h"
9 9
 #include "Camera.h"
10
-#include "Log.h"
11 10
 #include "UI.h"
12
-#include "utils/strings.h"
13 11
 #include "system/Window.h"
14 12
 
15 13
 #ifdef USING_SDL
@@ -29,8 +27,6 @@ int Window::initialize() {
29 27
 #else
30 28
     res = -1;
31 29
 #endif
32
-
33
-    initializeGL();
34 30
     return res;
35 31
 }
36 32
 
@@ -51,8 +47,6 @@ void Window::swapBuffers() {
51 47
 }
52 48
 
53 49
 void Window::shutdown() {
54
-    shutdownGL();
55
-
56 50
 #ifdef USING_SDL
57 51
     WindowSDL::shutdown();
58 52
 #elif defined(USING_GLFW)
@@ -146,280 +140,3 @@ bool Window::getTextInput() {
146 140
     return ret;
147 141
 }
148 142
 
149
-// --------------------------------------
150
-
151
-Shader Window::textShader;
152
-Shader Window::imguiShader;
153
-Shader Window::textureShader;
154
-Shader Window::colorShader;
155
-unsigned int Window::vertexArrayID = 0;
156
-
157
-int Window::initializeGL() {
158
-    getLog() << "GL Ven.: " << glGetString(GL_VENDOR) << Log::endl;
159
-    getLog() << "GL Ren.: " << glGetString(GL_RENDERER) << Log::endl;
160
-    getLog() << "GL Ver.: " << glGetString(GL_VERSION) << Log::endl;
161
-    getLog() << "GLSL V.: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << Log::endl;
162
-
163
-    glGenVertexArrays(1, &vertexArrayID);
164
-    glBindVertexArray(vertexArrayID);
165
-
166
-    // Set background to black
167
-    //glClearColor(BLACK[0] / 256.0f, BLACK[1] / 256.0f, BLACK[2] / 256.0f, BLACK[3] / 256.0f);
168
-    glClearColor(0.0f, 0.0f, 0.4f, 1.0f);
169
-
170
-    // Set up Z buffer
171
-    glEnable(GL_DEPTH_TEST);
172
-    // Accept fragment if closer to camera
173
-    glDepthFunc(GL_LESS);
174
-
175
-    // Set up culling
176
-    //glEnable(GL_CULL_FACE); //! \todo Transparency?
177
-
178
-    glPointSize(5.0f);
179
-
180
-    if (textShader.compile(textShaderVertex, textShaderFragment) < 0)
181
-        return -1;
182
-    if (textShader.addUniform("screen") < 0)
183
-        return -2;
184
-    if (textShader.addUniform("textureSampler") < 0)
185
-        return -3;
186
-    if (textShader.addUniform("colorVar") < 0)
187
-        return -4;
188
-    textShader.addBuffer(2);
189
-
190
-    if (imguiShader.compile(imguiShaderVertex, imguiShaderFragment) < 0)
191
-        return -5;
192
-    if (imguiShader.addUniform("screen") < 0)
193
-        return -6;
194
-    if (imguiShader.addUniform("textureSampler") < 0)
195
-        return -7;
196
-    imguiShader.addBuffer(3);
197
-
198
-    if (textureShader.compile(textureShaderVertex, textureShaderFragment) < 0)
199
-        return -8;
200
-    if (textureShader.addUniform("MVP") < 0)
201
-        return -9;
202
-    if (textureShader.addUniform("textureSampler") < 0)
203
-        return -10;
204
-    textureShader.addBuffer(3);
205
-
206
-    if (colorShader.compile(colorShaderVertex, colorShaderFragment) < 0)
207
-        return -11;
208
-    if (colorShader.addUniform("MVP") < 0)
209
-        return -12;
210
-    colorShader.addBuffer(3);
211
-
212
-    glEnable(GL_BLEND);
213
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
214
-
215
-    return 0;
216
-}
217
-
218
-void Window::shutdownGL() {
219
-    glDeleteVertexArrays(1, &vertexArrayID);
220
-}
221
-
222
-void Window::drawTextGL(std::vector<glm::vec2>& vertices, std::vector<glm::vec2>& uvs,
223
-                        glm::vec4 color, unsigned int texture) {
224
-    assert(vertices.size() == uvs.size());
225
-    assert((vertices.size() % 3) == 0);
226
-
227
-    textShader.bufferData(0, vertices);
228
-    textShader.bufferData(1, uvs);
229
-    textShader.use();
230
-    textShader.loadUniform(0, getSize());
231
-    textShader.loadUniform(1, texture, TextureManager::TextureStorage::SYSTEM);
232
-    textShader.loadUniform(2, color);
233
-    textShader.bindBuffer(0, 0, 2);
234
-    textShader.bindBuffer(1, 1, 2);
235
-
236
-    glDisable(GL_DEPTH_TEST);
237
-    glDrawArrays(GL_TRIANGLES, 0, vertices.size());
238
-    glEnable(GL_DEPTH_TEST);
239
-
240
-    textShader.disableAttribs();
241
-}
242
-
243
-void Window::drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec2>& uvs,
244
-                    std::vector<unsigned short>& indices, glm::mat4 MVP, unsigned int texture) {
245
-    assert(vertices.size() == uvs.size());
246
-    assert((indices.size() % 3) == 0);
247
-
248
-    textureShader.bufferData(0, vertices);
249
-    textureShader.bufferData(1, uvs);
250
-    textureShader.bufferData(2, indices);
251
-    textureShader.use();
252
-    textureShader.loadUniform(0, MVP);
253
-    textureShader.loadUniform(1, texture, TextureManager::TextureStorage::GAME);
254
-    textureShader.bindBuffer(0, 0, 3);
255
-    textureShader.bindBuffer(1, 1, 2);
256
-    textureShader.bindBuffer(2);
257
-    glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, nullptr);
258
-    textureShader.disableAttribs();
259
-}
260
-
261
-void Window::drawGL(std::vector<glm::vec3>& vertices, std::vector<glm::vec3>& colors,
262
-                    std::vector<unsigned short>& indices, glm::mat4 MVP, int mode) {
263
-    assert(vertices.size() == colors.size());
264
-
265
-    colorShader.bufferData(0, vertices);
266
-    colorShader.bufferData(1, colors);
267
-    colorShader.bufferData(2, indices);
268
-    colorShader.use();
269
-    colorShader.loadUniform(0, MVP);
270
-    colorShader.bindBuffer(0, 0, 3);
271
-    colorShader.bindBuffer(1, 1, 3);
272
-    colorShader.bindBuffer(2);
273
-    glDrawElements(mode, indices.size(), GL_UNSIGNED_SHORT, nullptr);
274
-    colorShader.disableAttribs();
275
-}
276
-
277
-// --------------------------------------
278
-// *INDENT-OFF*
279
-
280
-const char* Window::textShaderVertex = R"!?!(
281
-#version 330 core
282
-
283
-layout(location = 0) in vec2 vertexPosition_screen;
284
-layout(location = 1) in vec2 vertexUV;
285
-
286
-out vec2 UV;
287
-
288
-uniform vec2 screen;
289
-
290
-void main() {
291
-    vec2 halfScreen = screen / 2;
292
-    vec2 vertexPosition_homogenous = (vertexPosition_screen - halfScreen) / halfScreen;
293
-
294
-    gl_Position = vec4(vertexPosition_homogenous.x, -vertexPosition_homogenous.y, 0, 1);
295
-    UV = vertexUV;
296
-}
297
-)!?!";
298
-
299
-const char* Window::textShaderFragment = R"!?!(
300
-#version 330 core
301
-
302
-in vec2 UV;
303
-
304
-out vec4 color;
305
-
306
-uniform sampler2D textureSampler;
307
-uniform vec4 colorVar;
308
-
309
-void main() {
310
-    color = texture(textureSampler, UV) * colorVar;
311
-}
312
-)!?!";
313
-
314
-// --------------------------------------
315
-
316
-const char* Window::imguiShaderVertex = R"!?!(
317
-#version 330 core
318
-
319
-layout(location = 0) in vec2 vertexPosition_screen;
320
-layout(location = 1) in vec2 vertexUV;
321
-layout(location = 2) in vec4 vertexColor;
322
-
323
-out vec2 UV;
324
-out vec4 FragColor;
325
-
326
-uniform vec2 screen;
327
-
328
-void main() {
329
-    vec2 halfScreen = screen / 2;
330
-    vec2 vertexPosition_homogenous = (vertexPosition_screen - halfScreen) / halfScreen;
331
-
332
-    gl_Position = vec4(vertexPosition_homogenous.x, -vertexPosition_homogenous.y, 0, 1);
333
-    UV = vertexUV;
334
-    FragColor = vertexColor;
335
-}
336
-)!?!";
337
-
338
-const char* Window::imguiShaderFragment = R"!?!(
339
-#version 330 core
340
-
341
-in vec2 UV;
342
-in vec4 FragColor;
343
-
344
-out vec4 color;
345
-
346
-uniform sampler2D textureSampler;
347
-
348
-void main() {
349
-    color = texture(textureSampler, UV) * FragColor;
350
-}
351
-)!?!";
352
-
353
-// --------------------------------------
354
-
355
-const char* Window::textureShaderVertex = R"!?!(
356
-#version 330 core
357
-
358
-layout(location = 0) in vec3 vertexPosition_modelspace;
359
-layout(location = 1) in vec2 vertexUV;
360
-
361
-out vec2 UV;
362
-
363
-uniform mat4 MVP;
364
-
365
-void main() {
366
-    vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
367
-                          -vertexPosition_modelspace.y,
368
-                          vertexPosition_modelspace.z,
369
-                          1);
370
-    gl_Position = vec4(-pos.x, pos.yzw);
371
-    UV = vertexUV;
372
-}
373
-)!?!";
374
-
375
-const char* Window::textureShaderFragment = R"!?!(
376
-#version 330 core
377
-
378
-in vec2 UV;
379
-
380
-out vec4 color;
381
-
382
-uniform sampler2D textureSampler;
383
-
384
-void main() {
385
-    color = texture(textureSampler, UV);
386
-}
387
-)!?!";
388
-
389
-// --------------------------------------
390
-
391
-const char* Window::colorShaderVertex = R"!?!(
392
-#version 330 core
393
-
394
-layout(location = 0) in vec3 vertexPosition_modelspace;
395
-layout(location = 1) in vec3 vertexColor;
396
-
397
-out vec3 Color;
398
-
399
-uniform mat4 MVP;
400
-
401
-void main() {
402
-    vec4 pos = MVP * vec4(vertexPosition_modelspace.x,
403
-                          -vertexPosition_modelspace.y,
404
-                          vertexPosition_modelspace.z,
405
-                          1);
406
-    gl_Position = vec4(-pos.x, pos.yzw);
407
-    Color = vertexColor;
408
-}
409
-)!?!";
410
-
411
-const char* Window::colorShaderFragment = R"!?!(
412
-#version 330 core
413
-
414
-in vec3 Color;
415
-
416
-out vec4 color;
417
-
418
-void main() {
419
-    color = vec4(Color, 1);
420
-}
421
-)!?!";
422
-
423
-// --------------------------------------
424
-// *INDENT-ON*
425
-

+ 4
- 2
src/utils/Folder.cpp Voir le fichier

@@ -11,6 +11,7 @@
11 11
 #include <cstring>
12 12
 
13 13
 #include "global.h"
14
+#include <Log.h>
14 15
 #include "utils/filesystem.h"
15 16
 #include "utils/strings.h"
16 17
 #include "utils/Folder.h"
@@ -122,8 +123,9 @@ void Folder::createFolderItems() {
122 123
         return;
123 124
 
124 125
     std::vector<std::string> foundFiles, foundFolders;
125
-    if (readFolderItems(foundFiles, foundFolders) != 0)
126
-        throw Exception(std::string("Could not open folder ") + name);
126
+    if (readFolderItems(foundFiles, foundFolders) != 0) {
127
+        getLog() << "Could not open folder " << name << Log::endl;
128
+    }
127 129
 
128 130
     if (!listDot) {
129 131
         std::vector<std::string>::iterator it = foundFiles.begin();

+ 1
- 8
src/utils/binary.cpp Voir le fichier

@@ -8,7 +8,6 @@
8 8
 #include <sstream>
9 9
 
10 10
 #include "global.h"
11
-#include "Exception.h"
12 11
 #include "utils/binary.h"
13 12
 
14 13
 BinaryReader::~BinaryReader() {
@@ -189,13 +188,7 @@ bool BinaryMemory::eof() {
189 188
 void BinaryMemory::read(char* d, int c) {
190 189
     assert(offset >= 0);
191 190
     assert(c > 0);
192
-    if ((offset + c) > max) {
193
-        std::ostringstream ss;
194
-        ss << "BinaryMemory read out of bounds ("
195
-           << offset << " + " << c << " > " << max << ")";
196
-        throw new Exception(ss.str());
197
-    }
198
-
191
+    assert((offset + c) <= max);
199 192
     for (int i = 0; i < c; i++) {
200 193
         d[i] = data[offset + i];
201 194
     }

+ 1
- 3
test/CMakeLists.txt Voir le fichier

@@ -8,7 +8,6 @@ add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure)
8 8
 
9 9
 add_executable (tester_binary EXCLUDE_FROM_ALL
10 10
     "binary.cpp" "../src/utils/binary.cpp"
11
-    "../src/Exception.cpp"
12 11
 )
13 12
 add_dependencies (check tester_binary)
14 13
 add_test (NAME test_binary COMMAND tester_binary)
@@ -17,8 +16,7 @@ add_test (NAME test_binary COMMAND tester_binary)
17 16
 
18 17
 add_executable (tester_script EXCLUDE_FROM_ALL
19 18
     "Script.cpp" "ScriptPayload.h" "ScriptTest.h"
20
-    "../src/Script.cpp" "../src/Exception.cpp"
21
-    "../src/utils/binary.cpp"
19
+    "../src/Script.cpp" "../src/utils/binary.cpp"
22 20
 )
23 21
 
24 22
 find_package (ZLIB REQUIRED)

Chargement…
Annuler
Enregistrer