Browse Source

texture format merged into texture as they are always together

Kajetan Johannes Hammerle 2 years ago
parent
commit
27ee1c341e
7 changed files with 58 additions and 67 deletions
  1. 1 0
      Main.cpp
  2. 0 1
      meson.build
  3. 6 6
      rendering/Framebuffer.h
  4. 31 4
      rendering/Texture.cpp
  5. 20 4
      rendering/Texture.h
  6. 0 30
      rendering/TextureFormat.cpp
  7. 0 22
      rendering/TextureFormat.h

+ 1 - 0
Main.cpp

@@ -1,4 +1,5 @@
 #include "math/Vector.h"
+#include "rendering/Framebuffer.h"
 #include "rendering/Window.h"
 #include "tests/ArrayListTests.h"
 #include "tests/ArrayTests.h"

+ 0 - 1
meson.build

@@ -14,7 +14,6 @@ src = [
     'network/Server.cpp',
     'rendering/Shader.cpp',
     'rendering/Texture.cpp',
-    'rendering/TextureFormat.cpp',
     'rendering/VertexBuffer.cpp',
     'rendering/Window.cpp',
     'rendering/WindowOptions.cpp',

+ 6 - 6
rendering/Framebuffer.h

@@ -1,10 +1,10 @@
 #ifndef FRAMEBUFFER_H
 #define FRAMEBUFFER_H
 
+#include "math/Vector.h"
 #include "rendering/Texture.h"
 #include "utils/Array.h"
 #include "utils/ArrayList.h"
-#include "utils/Size.h"
 
 template<int N>
 class Framebuffer final {
@@ -25,9 +25,9 @@ public:
     Framebuffer& operator=(Framebuffer&&) = delete;
 
     template<typename... Args>
-    Error init(const Size& size, Args&&... args) {
+    Error init(const IntVector2& size, Args&&... args) {
         const int n = sizeof...(args);
-        TextureFormat init[n] = {args...};
+        Texture::Format init[n] = {args...};
         static_assert(N == n,
                       "framebuffer size and amount of arguments do not match");
         for(int i = 0; i < N; i++) {
@@ -43,7 +43,7 @@ public:
 
         ArrayList<GL::ColorAttachment, N> attachments;
         for(Texture& t : textures) {
-            t.setData(size.width, size.height);
+            t.setData(size[0], size[1]);
             if(t.format.depth) {
                 GL::framebufferDepthTexture2D(t.texture);
             } else {
@@ -65,9 +65,9 @@ public:
         textures[index].bindTo(textureUnit);
     }
 
-    void resize(const Size& size) {
+    void resize(const IntVector2& size) {
         for(Texture& t : textures) {
-            t.setData(size.width, size.height);
+            t.setData(size[0], size[1]);
         }
     }
 };

+ 31 - 4
rendering/Texture.cpp

@@ -1,15 +1,42 @@
 #include "rendering/Texture.h"
 #include "io/ImageReader.h"
 
-Texture::Texture()
-    : format(TextureFormat::unknown()), texture(0), maxMipMaps(0) {
+Texture::Format::Format(const GL::TextureFormat& tf, bool linear, bool depth)
+    : format(tf), linear(linear), depth(depth) {
+}
+
+Texture::Format Texture::Format::color8(int channels, bool linear) {
+    return Format(GL::TextureFormat::color8(channels), linear);
+}
+
+Texture::Format Texture::Format::float16(int channels, bool linear) {
+    return Format(GL::TextureFormat::float16(channels), linear);
+}
+
+Texture::Format Texture::Format::float32(int channels, bool linear) {
+    return Format(GL::TextureFormat::float32(channels), linear);
+}
+
+Texture::Format Texture::Format::depth16(bool linear) {
+    return Format(GL::TextureFormat::depth16(), linear, true);
+}
+
+Texture::Format Texture::Format::depth32(bool linear) {
+    return Format(GL::TextureFormat::depth32(), linear, true);
+}
+
+Texture::Format Texture::Format::unknown() {
+    return Format(GL::TextureFormat::unknown(), false, false);
+}
+
+Texture::Texture() : format(Format::unknown()), texture(0), maxMipMaps(0) {
 }
 
 Texture::~Texture() {
     GL::deleteTexture(texture);
 }
 
-void Texture::init(const TextureFormat& format, int maxMipMaps) {
+void Texture::init(const Format& format, int maxMipMaps) {
     if(texture != 0) {
         return;
     }
@@ -82,7 +109,7 @@ Error Texture::load(const char* path, int maxMipMaps) {
         error.message.append(path).append("' is not 8");
         return error;
     }
-    init(TextureFormat::color8(image.channels), maxMipMaps);
+    init(Format::color8(image.channels), maxMipMaps);
     setData(image.width, image.height, image.data);
     return {};
 }

+ 20 - 4
rendering/Texture.h

@@ -1,11 +1,27 @@
 #ifndef TEXTURE_H
 #define TEXTURE_H
 
-#include "rendering/TextureFormat.h"
 #include "wrapper/GL.h"
 
-class Texture final {
-    TextureFormat format;
+struct Texture final {
+    struct Format final {
+        GL::TextureFormat format;
+        bool linear;
+        bool depth;
+
+        static Format color8(int channels, bool linear = false);
+        static Format float16(int channels, bool linear = false);
+        static Format float32(int channels, bool linear = false);
+        static Format depth16(bool linear = false);
+        static Format depth32(bool linear = false);
+        static Format unknown();
+
+    private:
+        Format(const GL::TextureFormat& tf, bool linear, bool depth = false);
+    };
+
+private:
+    Format format;
     GL::Texture texture;
     int maxMipMaps;
 
@@ -20,7 +36,7 @@ public:
     Texture& operator=(const Texture& other) = delete;
     Texture& operator=(Texture&& other) = delete;
 
-    void init(const TextureFormat& format, int maxMipMaps);
+    void init(const Format& format, int maxMipMaps);
 
     void setNearestFilter();
     void setLinearFilter();

+ 0 - 30
rendering/TextureFormat.cpp

@@ -1,30 +0,0 @@
-#include "rendering/TextureFormat.h"
-
-TextureFormat::TextureFormat(const GL::TextureFormat& tf, bool linear,
-                             bool depth)
-    : format(tf), linear(linear), depth(depth) {
-}
-
-TextureFormat TextureFormat::color8(int channels, bool linear) {
-    return TextureFormat(GL::TextureFormat::color8(channels), linear);
-}
-
-TextureFormat TextureFormat::float16(int channels, bool linear) {
-    return TextureFormat(GL::TextureFormat::float16(channels), linear);
-}
-
-TextureFormat TextureFormat::float32(int channels, bool linear) {
-    return TextureFormat(GL::TextureFormat::float32(channels), linear);
-}
-
-TextureFormat TextureFormat::depth16(bool linear) {
-    return TextureFormat(GL::TextureFormat::depth16(), linear, true);
-}
-
-TextureFormat TextureFormat::depth32(bool linear) {
-    return TextureFormat(GL::TextureFormat::depth32(), linear, true);
-}
-
-TextureFormat TextureFormat::unknown() {
-    return TextureFormat(GL::TextureFormat::unknown(), false, false);
-}

+ 0 - 22
rendering/TextureFormat.h

@@ -1,22 +0,0 @@
-#ifndef TEXTUREDATA_H
-#define TEXTUREDATA_H
-
-#include "wrapper/GL.h"
-
-struct TextureFormat final {
-    GL::TextureFormat format;
-    bool linear;
-    bool depth;
-
-    static TextureFormat color8(int channels, bool linear = false);
-    static TextureFormat float16(int channels, bool linear = false);
-    static TextureFormat float32(int channels, bool linear = false);
-    static TextureFormat depth16(bool linear = false);
-    static TextureFormat depth32(bool linear = false);
-    static TextureFormat unknown();
-
-private:
-    TextureFormat(const GL::TextureFormat& tf, bool linear, bool depth = false);
-};
-
-#endif