Browse Source

linear filter for framebuffers

Kajetan Johannes Hammerle 3 years ago
parent
commit
ba410dfb8d
4 changed files with 37 additions and 33 deletions
  1. 3 0
      wrapper/Framebuffer.h
  2. 2 2
      wrapper/Texture.cpp
  3. 25 25
      wrapper/TextureFormat.cpp
  4. 7 6
      wrapper/TextureFormat.h

+ 3 - 0
wrapper/Framebuffer.h

@@ -21,6 +21,9 @@ public:
         for(int i = 0; i < N; i++) {
             textures.add(init[i]);
             textures[i].setClampWrap();
+            if(init[i].linear) {
+                textures[i].setLinearFilter();
+            }
         }
     }
 

+ 2 - 2
wrapper/Texture.cpp

@@ -33,9 +33,9 @@ void Texture::setNearestFilter() {
 
 void Texture::setLinearFilter() {
     if(maxMipMaps > 0) {
-        setFilter(GL_LINEAR, GL_LINEAR);
-    } else {
         setFilter(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR);
+    } else {
+        setFilter(GL_LINEAR, GL_LINEAR);
     }
 }
 

+ 25 - 25
wrapper/TextureFormat.cpp

@@ -2,51 +2,51 @@
 
 #include "wrapper/TextureFormat.h"
 
-TextureFormat::TextureFormat(GLint internalformat, GLenum format, GLenum type, bool depth)
-    : internalformat(internalformat), format(format), type(type), depth(depth) {
+TextureFormat::TextureFormat(GLint internalformat, GLenum format, GLenum type, bool linear, bool depth)
+    : internalformat(internalformat), format(format), type(type), linear(linear), depth(depth) {
 }
 
-TextureFormat TextureFormat::color8(int channels) {
+TextureFormat TextureFormat::color8(int channels, bool linear) {
     switch(channels) {
-        case 1: return TextureFormat(GL_RED, GL_RED, GL_UNSIGNED_BYTE);
-        case 2: return TextureFormat(GL_RG, GL_RG, GL_UNSIGNED_BYTE);
-        case 3: return TextureFormat(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE);
-        case 4: return TextureFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
+        case 1: return TextureFormat(GL_RED, GL_RED, GL_UNSIGNED_BYTE, linear);
+        case 2: return TextureFormat(GL_RG, GL_RG, GL_UNSIGNED_BYTE, linear);
+        case 3: return TextureFormat(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE, linear);
+        case 4: return TextureFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, linear);
     }
     std::cout << channels << " is not a valid amount of channels\n";
-    return TextureFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE);
+    return TextureFormat(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, linear);
 }
 
-TextureFormat TextureFormat::float16(int channels) {
+TextureFormat TextureFormat::float16(int channels, bool linear) {
     switch(channels) {
-        case 1: return TextureFormat(GL_R16F, GL_RED, GL_FLOAT);
-        case 2: return TextureFormat(GL_RG16F, GL_RG, GL_FLOAT);
-        case 3: return TextureFormat(GL_RGB16F, GL_RGB, GL_FLOAT);
-        case 4: return TextureFormat(GL_RGBA16F, GL_RGBA, GL_FLOAT);
+        case 1: return TextureFormat(GL_R16F, GL_RED, GL_FLOAT, linear);
+        case 2: return TextureFormat(GL_RG16F, GL_RG, GL_FLOAT, linear);
+        case 3: return TextureFormat(GL_RGB16F, GL_RGB, GL_FLOAT, linear);
+        case 4: return TextureFormat(GL_RGBA16F, GL_RGBA, GL_FLOAT, linear);
     }
     std::cout << channels << " is not a valid amount of channels\n";
-    return TextureFormat(GL_RGBA16F, GL_RGBA, GL_FLOAT);
+    return TextureFormat(GL_RGBA16F, GL_RGBA, GL_FLOAT, linear);
 }
 
-TextureFormat TextureFormat::float32(int channels) {
+TextureFormat TextureFormat::float32(int channels, bool linear) {
     switch(channels) {
-        case 1: return TextureFormat(GL_R32F, GL_RED, GL_FLOAT);
-        case 2: return TextureFormat(GL_RG32F, GL_RG, GL_FLOAT);
-        case 3: return TextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT);
-        case 4: return TextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT);
+        case 1: return TextureFormat(GL_R32F, GL_RED, GL_FLOAT, linear);
+        case 2: return TextureFormat(GL_RG32F, GL_RG, GL_FLOAT, linear);
+        case 3: return TextureFormat(GL_RGB32F, GL_RGB, GL_FLOAT, linear);
+        case 4: return TextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, linear);
     }
     std::cout << channels << " is not a valid amount of channels\n";
-    return TextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT);
+    return TextureFormat(GL_RGBA32F, GL_RGBA, GL_FLOAT, linear);
 }
 
-TextureFormat TextureFormat::depth16() {
-    return TextureFormat(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_FLOAT, true);
+TextureFormat TextureFormat::depth16(bool linear) {
+    return TextureFormat(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_FLOAT, linear, true);
 }
 
-TextureFormat TextureFormat::depth32() {
-    return TextureFormat(GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT, true);
+TextureFormat TextureFormat::depth32(bool linear) {
+    return TextureFormat(GL_DEPTH_COMPONENT32, GL_DEPTH_COMPONENT, GL_FLOAT, linear, true);
 }
 
 TextureFormat TextureFormat::unknown() {
-    return TextureFormat(-1, -1, -1, false);
+    return TextureFormat(-1, -1, -1, false, false);
 }

+ 7 - 6
wrapper/TextureFormat.h

@@ -7,17 +7,18 @@ struct TextureFormat final {
     GLint internalformat;
     GLenum format;
     GLenum type;
+    bool linear;
     bool depth;
 
-    static TextureFormat color8(int channels);
-    static TextureFormat float16(int channels);
-    static TextureFormat float32(int channels);
-    static TextureFormat depth16();
-    static TextureFormat depth32();
+    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(GLint internalformat, GLenum format, GLenum type, bool depth = false);
+    TextureFormat(GLint internalformat, GLenum format, GLenum type, bool linear, bool depth = false);
 };
 
 #endif