Browse Source

file texture merged into texture as it was only one call

Kajetan Johannes Hammerle 2 years ago
parent
commit
f5e2d0b61f
5 changed files with 25 additions and 51 deletions
  1. 0 1
      meson.build
  2. 0 32
      rendering/FileTexture.cpp
  3. 0 18
      rendering/FileTexture.h
  4. 23 0
      rendering/Texture.cpp
  5. 2 0
      rendering/Texture.h

+ 0 - 1
meson.build

@@ -12,7 +12,6 @@ src = [
     'network/ENet.cpp',
     'network/Packet.cpp',
     'network/Server.cpp',
-    'rendering/FileTexture.cpp',
     'rendering/Shader.cpp',
     'rendering/Texture.cpp',
     'rendering/TextureFormat.cpp',

+ 0 - 32
rendering/FileTexture.cpp

@@ -1,32 +0,0 @@
-#include "rendering/FileTexture.h"
-#include "io/ImageReader.h"
-
-Error FileTexture::load(const char* path, int maxMipMaps) {
-    ImageReader::Image image;
-    Error error = ImageReader::load(image, path);
-    if(error.has()) {
-        return error;
-    }
-    if(image.channels < 1 || image.channels > 4) {
-        Error error = {"'"};
-        error.message.append(path)
-            .append("' has unsupported number of channels: ")
-            .append(image.channels);
-        return error;
-    } else if(image.bitdepth != 8) {
-        Error error = {"bit depth of '"};
-        error.message.append(path).append("' is not 8");
-        return error;
-    }
-    texture.init(TextureFormat::color8(image.channels), maxMipMaps);
-    texture.setData(image.width, image.height, image.data);
-    return {};
-}
-
-void FileTexture::bindTo(int index) const {
-    texture.bindTo(index);
-}
-
-void FileTexture::setLinearFilter() {
-    texture.setLinearFilter();
-}

+ 0 - 18
rendering/FileTexture.h

@@ -1,18 +0,0 @@
-#ifndef FILETEXTURE_H
-#define FILETEXTURE_H
-
-#include "rendering/Texture.h"
-#include "utils/Error.h"
-
-class FileTexture final {
-    Texture texture;
-
-public:
-    Error load(const char* path, int maxMipMaps);
-
-    void bindTo(int index) const;
-
-    void setLinearFilter();
-};
-
-#endif

+ 23 - 0
rendering/Texture.cpp

@@ -1,4 +1,5 @@
 #include "rendering/Texture.h"
+#include "io/ImageReader.h"
 
 Texture::Texture()
     : format(TextureFormat::unknown()), texture(0), maxMipMaps(0) {
@@ -62,4 +63,26 @@ void Texture::bind() const {
 void Texture::bindTo(int index) const {
     GL::activeTexture(index);
     bind();
+}
+
+Error Texture::load(const char* path, int maxMipMaps) {
+    ImageReader::Image image;
+    Error error = ImageReader::load(image, path);
+    if(error.has()) {
+        return error;
+    }
+    if(image.channels < 1 || image.channels > 4) {
+        Error error = {"'"};
+        error.message.append(path)
+            .append("' has unsupported number of channels: ")
+            .append(image.channels);
+        return error;
+    } else if(image.bitdepth != 8) {
+        Error error = {"bit depth of '"};
+        error.message.append(path).append("' is not 8");
+        return error;
+    }
+    init(TextureFormat::color8(image.channels), maxMipMaps);
+    setData(image.width, image.height, image.data);
+    return {};
 }

+ 2 - 0
rendering/Texture.h

@@ -30,6 +30,8 @@ public:
 
     void bindTo(int index = 0) const;
 
+    Error load(const char* path, int maxMipMaps);
+
 private:
     void bind() const;
 };