Browse Source

glfw and gl wrapper moved to gaming core

Kajetan Johannes Hammerle 3 years ago
parent
commit
0e23de86fb

+ 0 - 1
Game.cpp

@@ -1,6 +1,5 @@
 #include "Game.h"
 #include "rendering/Renderer.h"
-#include "rendering/wrapper/GLFW.h"
 #include "utils/StringBuffer.h"
 
 float x = 0.0f;

+ 3 - 3
Main.cpp

@@ -1,8 +1,8 @@
 #include <iostream>
 #include <bits/getopt_core.h>
 
-#include "rendering/wrapper/GLFW.h"
-#include "rendering/wrapper/GLWrapper.h"
+#include "gaming-core/wrapper/GLFW.h"
+#include "gaming-core/wrapper/GL.h"
 #include "rendering/wrapper/Window.h"
 #include "rendering/Options.h"
 #include "gaming-core/utils/Clock.h"
@@ -71,7 +71,7 @@ int main(int argAmount, char* const* args) {
     const Clock::Nanos nanosPerTick = 10'000'000;
     Clock::Nanos lag = 0;
     while(!window.shouldClose() && game.isRunning()) {
-        GLWrapper::checkAndPrintError("GL-Error");
+        GL::checkAndPrintError("GL-Error");
 
         lag += fps.update();
         while(lag >= nanosPerTick) {

+ 1 - 1
gaming-core

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

+ 3 - 3
meson.build

@@ -2,12 +2,12 @@ project('pigine', 'cpp')
 
 sources = [
     'Main.cpp', 
-    'rendering/wrapper/GLFW.cpp', 
+    'gaming-core/wrapper/GLFW.cpp', 
+    'gaming-core/wrapper/GL.cpp', 
     'gaming-core/utils/Size.cpp', 
     'rendering/wrapper/Window.cpp', 
     'gaming-core/utils/Clock.cpp', 
     'rendering/wrapper/Shader.cpp', 
-    'rendering/wrapper/GLWrapper.cpp',
     'Game.cpp',
     'input/Controller.cpp',
     'input/Button.cpp',
@@ -17,7 +17,7 @@ sources = [
     'gaming-core/math/Vector.cpp',
     'gaming-core/images/PNGReader.cpp',
     'rendering/wrapper/StreamBuffer.cpp',
-    'gaming-core/gl/Texture.cpp',
+    'gaming-core/wrapper/Texture.cpp',
     'rendering/wrapper/VertexBuffer.cpp',
     'gaming-core/rendering/FileTexture.cpp',
     'rendering/ColorRenderer.cpp',

+ 2 - 2
rendering/Renderer.cpp

@@ -1,9 +1,9 @@
 #include "rendering/Renderer.h"
-#include "rendering/wrapper/GLWrapper.h"
+#include "gaming-core/wrapper/GL.h"
 
 Renderer::Renderer(const Size& size, Shader& shader) : size(size), shader(shader), texture(true), color(true) {
     shader.use();
-    GLWrapper::enableBlending();
+    GL::enableBlending();
     setTextureMode(false);
     setColorMode(false);
 }

+ 0 - 17
rendering/wrapper/GLFW.cpp

@@ -1,17 +0,0 @@
-#include <iostream>
-
-#include <GL/glew.h>
-#include <GLFW/glfw3.h>
-
-#include "rendering/wrapper/GLFW.h"
-
-bool GLFW::init() {
-    if(glfwInit()) {
-        atexit([]() {
-            glfwTerminate();
-        });
-        return false;
-    }
-    std::cout << "could not initialize GLFW\n";
-    return true;
-}

+ 0 - 8
rendering/wrapper/GLFW.h

@@ -1,8 +0,0 @@
-#ifndef GLFW_H
-#define GLFW_H
-
-namespace GLFW {
-    bool init();
-}
-
-#endif

+ 0 - 59
rendering/wrapper/GLWrapper.cpp

@@ -1,59 +0,0 @@
-#include <GL/glew.h>
-#include <iostream>
-
-#include "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);
-}

+ 0 - 13
rendering/wrapper/GLWrapper.h

@@ -1,13 +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();
-}
-
-#endif

+ 3 - 3
rendering/wrapper/Shader.cpp

@@ -2,7 +2,7 @@
 #include <iostream>
 
 #include "rendering/wrapper/Shader.h"
-#include "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;