Browse Source

shader moved to gaming core

Kajetan Johannes Hammerle 3 years ago
parent
commit
ec90958dcb
6 changed files with 11 additions and 126 deletions
  1. 1 1
      Main.cpp
  2. 1 1
      gaming-core
  3. 8 8
      meson.build
  4. 1 1
      rendering/Renderer.h
  5. 0 85
      rendering/wrapper/Shader.cpp
  6. 0 30
      rendering/wrapper/Shader.h

+ 1 - 1
Main.cpp

@@ -7,7 +7,7 @@
 #include "rendering/wrapper/Window.h"
 #include "rendering/Options.h"
 #include "gaming-core/utils/Clock.h"
-#include "rendering/wrapper/Shader.h"
+#include "gaming-core/wrapper/Shader.h"
 #include "rendering/Renderer.h"
 #include "Game.h"
 

+ 1 - 1
gaming-core

@@ -1 +1 @@
-Subproject commit 144ae380f04a521d93dc63a58d644c84cf944e5b
+Subproject commit 647e4f95de28a6300ed0d50762ff19a22b7be5f5

+ 8 - 8
meson.build

@@ -5,22 +5,22 @@ sources = [
     'gaming-core/wrapper/GLFW.cpp', 
     'gaming-core/wrapper/GL.cpp', 
     'gaming-core/wrapper/GLEW.cpp', 
+    'gaming-core/wrapper/Shader.cpp', 
+    'gaming-core/wrapper/Texture.cpp',
+    'gaming-core/math/Matrix.cpp',
+    'gaming-core/math/Quaternion.cpp',
+    'gaming-core/math/Vector.cpp',
     'gaming-core/utils/Size.cpp', 
-    'rendering/wrapper/Window.cpp', 
     'gaming-core/utils/Clock.cpp', 
-    'rendering/wrapper/Shader.cpp', 
+    'gaming-core/rendering/FileTexture.cpp',
+    'gaming-core/images/PNGReader.cpp',
+    'rendering/wrapper/Window.cpp', 
     'Game.cpp',
     'input/Controller.cpp',
     'input/Button.cpp',
     'rendering/Renderer.cpp',
-    'gaming-core/math/Matrix.cpp',
-    'gaming-core/math/Quaternion.cpp',
-    'gaming-core/math/Vector.cpp',
-    'gaming-core/images/PNGReader.cpp',
     'rendering/wrapper/StreamBuffer.cpp',
-    'gaming-core/wrapper/Texture.cpp',
     'rendering/wrapper/VertexBuffer.cpp',
-    'gaming-core/rendering/FileTexture.cpp',
     'rendering/ColorRenderer.cpp',
     'rendering/FontRenderer.cpp',
     'rendering/Mesh.cpp',

+ 1 - 1
rendering/Renderer.h

@@ -1,7 +1,7 @@
 #ifndef RENDERER_H
 #define RENDERER_H
 
-#include "rendering/wrapper/Shader.h"
+#include "gaming-core/wrapper/Shader.h"
 #include "utils/Size.h"
 #include "math/MatrixStack.h"
 #include "rendering/FontRenderer.h"

+ 0 - 85
rendering/wrapper/Shader.cpp

@@ -1,85 +0,0 @@
-#include <fstream>
-#include <iostream>
-
-#include "rendering/wrapper/Shader.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)) {
-        return;
-    }
-    program = glCreateProgram();
-    glAttachShader(program, vShader);
-    glAttachShader(program, fShader);
-    glLinkProgram(program);
-    if(GL::checkAndPrintError("shader linking error")) {
-        return;
-    }
-    GLint linked;
-    glGetProgramiv(program, GL_LINK_STATUS, &linked);
-    if(linked == GL_FALSE) {
-        GLchar buffer[512];
-        glGetProgramInfoLog(program, 512, nullptr, buffer);
-        std::cout << "programm linking info log: " << buffer << "\n";
-        return;
-    }
-}
-
-Shader::~Shader() {
-    glDeleteProgram(program);
-    glDeleteShader(vShader);
-    glDeleteShader(fShader);
-}
-
-bool Shader::hasError() const {
-    return vShader == 0 || fShader == 0 || program == 0;
-}
-
-bool Shader::readFileAndCompile(const GLchar* path, GLuint& shader, GLenum shaderType) {
-    GLchar buffer[8192];
-    if(readFile(buffer, 8192, path)) {
-        return true;
-    }
-    return compile(shader, buffer, shaderType);
-}
-
-bool Shader::readFile(GLchar* buffer, size_t bufferSize, const GLchar* path) const {
-    std::ifstream in;
-    in.open(path);
-    if(in.fail()) {
-        std::cout << "cannot read shader file: '" << path << "'\n";
-        return true;
-    }
-    in.get(buffer, bufferSize, EOF);
-    return false;
-}
-
-bool Shader::compile(GLuint& shader, const GLchar* code, GLenum shaderType) {
-    shader = glCreateShader(shaderType);
-    glShaderSource(shader, 1, &code, nullptr);
-    glCompileShader(shader);
-    if(GL::checkAndPrintError("shader error")) {
-        return true;
-    }
-    GLint compiled;
-    glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
-    if(compiled == GL_FALSE) {
-        GLchar buffer[512];
-        glGetShaderInfoLog(shader, 512, nullptr, buffer);
-        std::cout << "shader info log: " << buffer << "\n";
-        return true;
-    }
-    return false;
-}
-
-void Shader::use() const {
-    glUseProgram(program);
-}
-
-void Shader::setMatrix(const GLchar* name, const GLfloat* data) const {
-    glUniformMatrix4fv(glGetUniformLocation(program, name), 1, GL_TRUE, data);
-}
-
-void Shader::setInt(const GLchar* name, GLint data) const {
-    glUniform1i(glGetUniformLocation(program, name), data);
-}

+ 0 - 30
rendering/wrapper/Shader.h

@@ -1,30 +0,0 @@
-#ifndef SHADER_H
-#define SHADER_H
-
-#include <GL/glew.h>
-
-class Shader final {
-public:
-    Shader(const GLchar* vPath, const GLchar* fPath);
-    ~Shader();
-    Shader(const Shader& other) = delete;
-    Shader(Shader&& other) = delete;
-    Shader& operator=(const Shader& other) = delete;
-    Shader& operator=(Shader&& other) = delete;
-
-    bool hasError() const;
-    void use() const;
-    void setMatrix(const GLchar* name, const GLfloat* data) const;
-    void setInt(const GLchar* name, GLint data) const;
-
-private:
-    bool readFileAndCompile(const GLchar* path, GLuint& shader, GLenum shaderType);
-    bool readFile(GLchar* buffer, size_t bufferSize, const GLchar* path) const;
-    bool compile(GLuint& shader, const GLchar* code, GLenum shaderType);
-
-    GLuint vShader;
-    GLuint fShader;
-    GLuint program;
-};
-
-#endif