Browse Source

texture and file texture moved to gaming core

Kajetan Johannes Hammerle 3 years ago
parent
commit
d64b6c2c90

+ 1 - 1
gaming-core

@@ -1 +1 @@
-Subproject commit bff2959facb9b6d78684bc188f5b9e326dbc95d6
+Subproject commit bbefefa41450ae7f4e292cc1a40fdb9d0fc473b4

+ 2 - 2
meson.build

@@ -17,9 +17,9 @@ sources = [
     'gaming-core/math/Vector.cpp',
     'gaming-core/images/PNGReader.cpp',
     'rendering/wrapper/StreamBuffer.cpp',
-    'rendering/wrapper/Texture.cpp',
+    'gaming-core/gl/Texture.cpp',
     'rendering/wrapper/VertexBuffer.cpp',
-    'rendering/FileTexture.cpp',
+    'gaming-core/rendering/FileTexture.cpp',
     'rendering/ColorRenderer.cpp',
     'rendering/FontRenderer.cpp',
     'rendering/Mesh.cpp',

+ 0 - 26
rendering/FileTexture.cpp

@@ -1,26 +0,0 @@
-#include "rendering/FileTexture.h"
-
-FileTexture::FileTexture(const char* path) {
-    PNGReader png(path);
-    if(png.hasError()) {
-        return;
-    }
-    switch(png.getChannels()) {
-        case 1:
-            read<1>(png);
-            break;
-        case 2:
-            read<2>(png);
-            break;
-        case 3:
-            read<3>(png);
-            break;
-        case 4:
-            read<4>(png);
-            break;
-    }
-}
-
-void FileTexture::bind() const {
-    texture.bind();
-}

+ 0 - 28
rendering/FileTexture.h

@@ -1,28 +0,0 @@
-#ifndef FILE_TEXTURE_H
-#define FILE_TEXTURE_H
-
-#include "rendering/wrapper/Texture.h"
-#include "gaming-core/images/PNGReader.h"
-
-class FileTexture final {
-    Texture texture;
-
-public:
-    FileTexture(const char* path);
-
-    void bind() const;
-
-private:
-
-    template<int N>
-    void read(PNGReader& png) {
-        Color<N>* buffer = new Color<N>[png.getBufferSize()];
-        if(png.readData(buffer)) {
-            return;
-        }
-        texture.setColorData(png.getWidth(), png.getHeight(), buffer);
-        delete[] buffer;
-    }
-};
-
-#endif

+ 1 - 1
rendering/FontRenderer.h

@@ -3,7 +3,7 @@
 
 #include "rendering/wrapper/VertexBuffer.h"
 #include "rendering/wrapper/StreamBuffer.h"
-#include "rendering/FileTexture.h"
+#include "gaming-core/rendering/FileTexture.h"
 #include "utils/Array.h"
 
 class FontRenderer final {

+ 0 - 36
rendering/wrapper/Texture.cpp

@@ -1,36 +0,0 @@
-#include "rendering/wrapper/Texture.h"
-#include "rendering/wrapper/GLWrapper.h"
-
-Texture::Texture() : texture(0) {
-    glGenTextures(1, &texture);
-    glBindTexture(GL_TEXTURE_2D, texture);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-}
-
-Texture::~Texture() {
-    glDeleteTextures(1, &texture);
-}
-
-void Texture::setColorData(int width, int height, const Color4* data) {
-    setColorData(width, height, GL_RGBA, data);
-}
-
-void Texture::setColorData(int width, int height, const Color3* data) {
-    setColorData(width, height, GL_RGB, data);
-}
-
-void Texture::setColorData(int width, int height, const Color2* data) {
-    setColorData(width, height, GL_RG, data);
-}
-
-void Texture::setColorData(int width, int height, const Color1* data) {
-    setColorData(width, height, GL_RED, data);
-}
-
-void Texture::bind() const {
-    glActiveTexture(GL_TEXTURE0);
-    glBindTexture(GL_TEXTURE_2D, texture);
-}

+ 0 - 35
rendering/wrapper/Texture.h

@@ -1,35 +0,0 @@
-#ifndef TEXTURE_H
-#define TEXTURE_H
-
-#include <GL/glew.h>
-
-#include "gaming-core/utils/Color.h"
-
-class Texture final {
-    GLuint texture;
-
-public:
-    Texture();
-    ~Texture();
-    Texture(const Texture& other) = delete;
-    Texture(Texture&& other) = delete;
-    Texture& operator=(const Texture& other) = delete;
-    Texture& operator=(Texture&& other) = delete;
-
-    void setColorData(int width, int height, const Color4* data);
-    void setColorData(int width, int height, const Color3* data);
-    void setColorData(int width, int height, const Color2* data);
-    void setColorData(int width, int height, const Color1* data);
-
-    void bind() const;
-
-private:
-
-    template<int N>
-    void setColorData(int width, int height, int mode, const Color<N>* data) {
-        glBindTexture(GL_TEXTURE_2D, texture);
-        glTexImage2D(GL_TEXTURE_2D, 0, mode, width, height, 0, mode, GL_UNSIGNED_BYTE, data);
-    }
-};
-
-#endif