Explorar el Código

texture and file texture moved to gaming core

Kajetan Johannes Hammerle hace 3 años
padre
commit
832af4146c

+ 0 - 26
client/rendering/FileTexture.cpp

@@ -1,26 +0,0 @@
-#include "client/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(int index) const {
-    texture.bind(index);
-}

+ 0 - 30
client/rendering/FileTexture.h

@@ -1,30 +0,0 @@
-#ifndef FILE_TEXTURE_H
-#define FILE_TEXTURE_H
-
-#include <iostream>
-
-#include "client/rendering/wrapper/Texture.h"
-#include "gaming-core/images/PNGReader.h"
-
-class FileTexture final {
-    Texture texture;
-
-public:
-    FileTexture(const char* path);
-
-    void bind(int index) 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
client/rendering/FontRenderer.h

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

+ 1 - 1
client/rendering/NoiseTexture.h

@@ -1,7 +1,7 @@
 #ifndef NOISETEXTURE_H
 #define NOISETEXTURE_H
 
-#include "client/rendering/wrapper/Texture.h"
+#include "gaming-core/rendering/FileTexture.h"
 
 class NoiseTexture final {
     Texture texture;

+ 1 - 1
client/rendering/renderer/WorldRenderer.h

@@ -4,7 +4,7 @@
 #include "client/rendering/Renderer.h"
 #include "common/world/World.h"
 #include "client/rendering/Mesh.h"
-#include "client/rendering/FileTexture.h"
+#include "gaming-core/rendering/FileTexture.h"
 
 class WorldRenderer {
 public:

+ 0 - 48
client/rendering/wrapper/Texture.cpp

@@ -1,48 +0,0 @@
-#include "client/rendering/wrapper/Texture.h"
-
-Texture::Texture(Mode mode) : texture(0) {
-    glGenTextures(1, &texture);
-    glBindTexture(GL_TEXTURE_2D, texture);
-    switch(mode) {
-        case NEAREST:
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-            break;
-        case LINEAR:
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-            break;
-    }
-    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) {
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
-    //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
-}
-
-void Texture::setColorData(int width, int height, const Color3* data) {
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
-}
-
-void Texture::setColorData(int width, int height, const Color2* data) {
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RG, width, height, 0, GL_RG, GL_UNSIGNED_BYTE, data);
-}
-
-void Texture::setColorData(int width, int height, const Color1* data) {
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_UNSIGNED_BYTE, data);
-}
-
-void Texture::setRGBFloatData(int width, int height, const float* data) {
-    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, width, height, 0, GL_RGB, GL_FLOAT, data);
-}
-
-void Texture::bind(int index) const {
-    glActiveTexture(GL_TEXTURE0 + index);
-    glBindTexture(GL_TEXTURE_2D, texture);
-}

+ 0 - 34
client/rendering/wrapper/Texture.h

@@ -1,34 +0,0 @@
-#ifndef TEXTURE_H
-#define TEXTURE_H
-
-#include <GL/glew.h>
-
-#include "gaming-core/utils/Color.h"
-
-class Texture final {
-    GLuint texture;
-
-public:
-
-    enum Mode {
-        NEAREST, LINEAR
-    };
-
-    Texture(Mode mode = NEAREST);
-    ~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 setRGBFloatData(int width, int height, const float* data);
-
-    void bind(int index) const;
-};
-
-#endif

+ 1 - 1
gaming-core

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

+ 2 - 2
meson.build

@@ -34,7 +34,7 @@ sourcesClient = ['client/Main.cpp',
     'gaming-core/math/Quaternion.cpp',
     'client/Game.cpp',
     'client/input/MouseButtons.cpp',
-    'client/rendering/FileTexture.cpp',
+    'gaming-core/rendering/FileTexture.cpp',
     'client/rendering/FontRenderer.cpp',
     'client/rendering/wrapper/Framebuffer.cpp',
     'client/rendering/NoiseTexture.cpp',
@@ -42,7 +42,7 @@ sourcesClient = ['client/Main.cpp',
     'client/rendering/RenderSettings.cpp',
     'client/rendering/wrapper/VertexBuffer.cpp',
     'client/rendering/wrapper/StreamBuffer.cpp',
-    'client/rendering/wrapper/Texture.cpp',
+    'gaming-core/gl/Texture.cpp',
     'gaming-core/images/PNGReader.cpp',
     'client/rendering/wrapper/GLWrapper.cpp',
     'client/rendering/Renderer.cpp',