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

glfw and gl wrapper moved to gaming core

Kajetan Johannes Hammerle 3 лет назад
Родитель
Сommit
32c8f9aa77

+ 5 - 5
client/Main.cpp

@@ -1,6 +1,7 @@
 #include <iostream>
 
-#include "client/rendering/wrapper/GLFWWrapper.h"
+#include "gaming-core/wrapper/GLFW.h"
+#include "gaming-core/wrapper/GL.h"
 #include "gaming-core/utils/Size.h"
 #include "client/rendering/wrapper/Window.h"
 #include "client/rendering/Shaders.h"
@@ -9,7 +10,6 @@
 #include "client/rendering/Engine.h"
 #include "gaming-core/utils/Clock.h"
 #include "client/rendering/RenderSettings.h"
-#include "rendering/wrapper/GLWrapper.h"
 
 bool initGLEW() {
     GLenum err = glewInit();
@@ -51,7 +51,7 @@ void initCallbacks(Window& w, Size& size, Framebuffers& framebuffers, Control& c
 }
 
 int main() {
-    if(GLFWWrapper::hasError()) {
+    if(GLFW::init()) {
         return 0;
     }
     
@@ -82,12 +82,12 @@ int main() {
     initCallbacks(window, size, framebuffers, control);
     window.show();
     
-    GLWrapper::checkAndPrintError("setup error");
+    GL::checkAndPrintError("setup error");
 
     const Clock::Nanos nanosPerTick = 50000000;
     Clock::Nanos lag = 0;
     while(!window.shouldClose() && game.isRunning()) {
-        GLWrapper::checkAndPrintError("loop error");
+        GL::checkAndPrintError("loop error");
         engine.renderTick(static_cast<float> (lag) / nanosPerTick, game);
         window.swapBuffers();
         lag += fps.update();

+ 7 - 8
client/rendering/Engine.cpp

@@ -2,8 +2,7 @@
 #include <cfloat>
 
 #include "client/rendering/Engine.h"
-#include "client/rendering/wrapper/GLFWWrapper.h"
-#include "client/rendering/wrapper/GLWrapper.h"
+#include "gaming-core/wrapper/GL.h"
 #include "client/rendering/Renderer.h"
 
 Engine::Engine(Shaders& shaders, Framebuffers& fb, const Size& size, RenderSettings& renderSettings) :
@@ -36,7 +35,7 @@ void Engine::renderTick(float lag, const Game& game) {
 
 void Engine::renderShadow(float lag, const Game& game) {
     framebuffers.shadow.bind();
-    GLWrapper::enableDepthTesting();
+    GL::enableDepthTesting();
     shaders.shadow.use();
     worldShadowProjView = worldShadowProj;
     worldShadowProjView *= worldShadowView;
@@ -49,7 +48,7 @@ void Engine::renderShadow(float lag, const Game& game) {
 
 void Engine::renderWorld(float lag, const Game& game) {
     framebuffers.world.bind();
-    GLWrapper::enableDepthTesting();
+    GL::enableDepthTesting();
     shaders.world.use();
 
     Matrix rWorldShadowProjView;
@@ -95,7 +94,7 @@ void Engine::renderSSAO() {
 }
 
 void Engine::renderPostWorld() {
-    GLWrapper::prepareMainFramebuffer();
+    GL::prepareMainFramebuffer();
     shaders.postWorld.use();
     framebuffers.world.bindColorTexture(0);
     framebuffers.ssaoBlur.bindRedTexture(1);
@@ -107,7 +106,7 @@ void Engine::renderPostWorld() {
 }
 
 void Engine::renderTextOverlay(float lag, const Game& game) {
-    GLWrapper::disableDepthTesting();
+    GL::disableDepthTesting();
     shaders.text.use();
 
     Matrix m;
@@ -117,10 +116,10 @@ void Engine::renderTextOverlay(float lag, const Game& game) {
     model.clear();
     shaders.text.setMatrix("model", model.peek().getValues());
 
-    GLWrapper::enableBlending();
+    GL::enableBlending();
     Renderer renderer(shaders.text, model, m);
     game.renderTextOverlay(lag, renderer, fontRenderer);
-    GLWrapper::disableBlending();
+    GL::disableBlending();
 }
 
 void Engine::updateWorldProjection() {

+ 0 - 26
client/rendering/wrapper/GLFWWrapper.cpp

@@ -1,26 +0,0 @@
-#include <iostream>
-
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-
-#include "client/rendering/wrapper/GLFWWrapper.h"
-
-struct GLFWInit final {
-    bool error;
-
-    GLFWInit() : error(glfwInit() == GLFW_FALSE) {
-        if(error) {
-            std::cout << "could not initialize GLFW\n";
-        }
-    }
-
-    ~GLFWInit() {
-        glfwTerminate();
-    }
-};
-
-static GLFWInit init;
-
-bool GLFWWrapper::hasError() {
-    return init.error;
-}

+ 0 - 8
client/rendering/wrapper/GLFWWrapper.h

@@ -1,8 +0,0 @@
-#ifndef GLFWWRAPPER_H
-#define GLFWWRAPPER_H
-
-namespace GLFWWrapper {
-    bool hasError();
-}
-
-#endif

+ 0 - 63
client/rendering/wrapper/GLWrapper.cpp

@@ -1,63 +0,0 @@
-#include <GL/glew.h>
-#include <iostream>
-
-#include "client/rendering/wrapper/GLWrapper.h"
-
-bool GLWrapper::checkAndPrintError(const char* message) {
-    GLenum error = glGetError();
-    switch(error) {
-        case GL_NO_ERROR:
-            return false;
-        case GL_INVALID_ENUM:
-            std::cout << message << ": an unacceptable value is specified for an enumerated argument.\n";
-            break;
-        case GL_INVALID_VALUE:
-            std::cout << message << ": a numeric argument is out of range.\n";
-            break;
-        case GL_INVALID_OPERATION:
-            std::cout << message << ": the specified operation is not allowed in the current state.\n";
-            break;
-        case GL_INVALID_FRAMEBUFFER_OPERATION:
-            std::cout << message << ": the framebuffer object is not complete.\n";
-            break;
-        case GL_OUT_OF_MEMORY:
-            std::cout << message << ": there is not enough memory left to execute the command.\n";
-            break;
-        case GL_STACK_UNDERFLOW:
-            std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to underflow.\n";
-            break;
-        case GL_STACK_OVERFLOW:
-            std::cout << message << ": an attempt has been made to perform an operation that would cause an internal stack to overflow.\n";
-            break;
-        default:
-            std::cout << message << ": unknown OpenGL error: " << error << "\n";
-    }
-    return true;
-}
-
-void GLWrapper::enableDepthTesting() {
-    glEnable(GL_DEPTH_TEST);
-}
-
-void GLWrapper::disableDepthTesting() {
-    glDisable(GL_DEPTH_TEST);
-}
-
-void GLWrapper::prepareMainFramebuffer() {
-    glBindFramebuffer(GL_FRAMEBUFFER, 0);
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-}
-
-void GLWrapper::enableBlending() {
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-    glBlendEquation(GL_FUNC_ADD);
-}
-
-void GLWrapper::disableBlending() {
-    glDisable(GL_BLEND);
-}
-
-void GLWrapper::setLineThickness(float f) {
-    glLineWidth(f);
-}

+ 0 - 14
client/rendering/wrapper/GLWrapper.h

@@ -1,14 +0,0 @@
-#ifndef GLWRAPPER_H
-#define GLWRAPPER_H
-
-namespace GLWrapper {
-    bool checkAndPrintError(const char* message);
-    void enableDepthTesting();
-    void disableDepthTesting();
-    void prepareMainFramebuffer();
-    void enableBlending();
-    void disableBlending();
-    void setLineThickness(float f);
-}
-
-#endif

+ 3 - 3
client/rendering/wrapper/Shader.cpp

@@ -2,7 +2,7 @@
 #include <iostream>
 
 #include "client/rendering/wrapper/Shader.h"
-#include "client/rendering/wrapper/GLWrapper.h"
+#include "gaming-core/wrapper/GL.h"
 
 Shader::Shader(const GLchar* vPath, const GLchar* fPath) : vShader(0), fShader(0), program(0) {
     if(readFileAndCompile(vPath, vShader, GL_VERTEX_SHADER) || readFileAndCompile(fPath, fShader, GL_FRAGMENT_SHADER)) {
@@ -12,7 +12,7 @@ Shader::Shader(const GLchar* vPath, const GLchar* fPath) : vShader(0), fShader(0
     glAttachShader(program, vShader);
     glAttachShader(program, fShader);
     glLinkProgram(program);
-    if(GLWrapper::checkAndPrintError("shader linking error")) {
+    if(GL::checkAndPrintError("shader linking error")) {
         return;
     }
     GLint linked;
@@ -58,7 +58,7 @@ bool Shader::compile(GLuint& shader, const GLchar* code, GLenum shaderType) {
     shader = glCreateShader(shaderType);
     glShaderSource(shader, 1, &code, nullptr);
     glCompileShader(shader);
-    if(GLWrapper::checkAndPrintError("shader error")) {
+    if(GL::checkAndPrintError("shader error")) {
         return true;
     }
     GLint compiled;

+ 1 - 1
gaming-core

@@ -1 +1 @@
-Subproject commit bbefefa41450ae7f4e292cc1a40fdb9d0fc473b4
+Subproject commit 4a994d3a5cf2ae6e058ca33162143b82cfd9abfd

+ 3 - 3
meson.build

@@ -23,7 +23,8 @@ sourcesClient = ['client/Main.cpp',
     'gaming-core/math/Frustum.cpp',
     'gaming-core/math/Plane.cpp',
     'client/rendering/Framebuffers.cpp',
-    'client/rendering/wrapper/GLFWWrapper.cpp',
+    'gaming-core/wrapper/GLFW.cpp',
+    'gaming-core/wrapper/GL.cpp',
     'client/rendering/wrapper/Window.cpp',
     'client/rendering/Engine.cpp',
     'client/input/Keys.cpp',
@@ -42,9 +43,8 @@ sourcesClient = ['client/Main.cpp',
     'client/rendering/RenderSettings.cpp',
     'client/rendering/wrapper/VertexBuffer.cpp',
     'client/rendering/wrapper/StreamBuffer.cpp',
-    'gaming-core/gl/Texture.cpp',
+    'gaming-core/wrapper/Texture.cpp',
     'gaming-core/images/PNGReader.cpp',
-    'client/rendering/wrapper/GLWrapper.cpp',
     'client/rendering/Renderer.cpp',
     'client/rendering/renderer/WorldRenderer.cpp',
     'client/rendering/Vertex.cpp',