From 0b8c05ded996559784c5669534c7c3deaa368114 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Tue, 27 Feb 2018 16:04:38 +0100 Subject: [PATCH] Unify texture configuration. --- src/InputLayerVisualisation.cpp | 9 +-------- src/Texture.cpp | 15 +++++++++++++++ src/Texture.hpp | 1 + src/glutils.cpp | 15 +-------------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/InputLayerVisualisation.cpp b/src/InputLayerVisualisation.cpp index 53bfae0..c2bfe40 100644 --- a/src/InputLayerVisualisation.cpp +++ b/src/InputLayerVisualisation.cpp @@ -61,14 +61,7 @@ InputLayerVisualisation::InputLayerVisualisation(const LayerData &data) nodePositions_.push_back(nodePositions_[i % 3]); } - texture.bind(GL_TEXTURE_2D); - // Set up (lack of) repetition - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - - // Set up texture scaling - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); // Use mipmapping for scaling down - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Use nearest pixel when scaling up. + texture.configure(GL_TEXTURE_2D); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, GL_RGB, GL_FLOAT, imageData.data()); } diff --git a/src/Texture.cpp b/src/Texture.cpp index fb69529..b34b49f 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -34,3 +34,18 @@ void Texture::bind(GLenum target) const { glBindTexture(target, id); } + +void Texture::configure(GLenum target) const +{ + bind(target); + const float color[] = {1, 0, 1}; // Background color for textures. + + // Set up (lack of) repetition + glTexParameteri(target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER); + glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); + glTexParameterfv(target, GL_TEXTURE_BORDER_COLOR, color); + + // Set up texture scaling + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); // Use mipmapping for scaling down + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Use nearest pixel when scaling up. +} diff --git a/src/Texture.hpp b/src/Texture.hpp index 7e71f20..3e4eb63 100644 --- a/src/Texture.hpp +++ b/src/Texture.hpp @@ -36,6 +36,7 @@ namespace fmri * @param target valid target for glBindTexture. */ void bind(GLenum target) const; + void configure(GLenum target) const; private: GLuint id; diff --git a/src/glutils.cpp b/src/glutils.cpp index 7685a9f..0f9a28a 100644 --- a/src/glutils.cpp +++ b/src/glutils.cpp @@ -38,21 +38,8 @@ fmri::Texture fmri::loadTexture(DType const *data, int width, int height, int su vector textureBuffer(data, data + (width * height)); rescaleSubImages(textureBuffer, subImages); - const float color[] = {1, 1, 1}; // Background color for textures. - Texture texture; - texture.bind(GL_TEXTURE_2D); - - // Set up (lack of) repetition - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color); - - // Set up texture scaling - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); // Use mipmapping for scaling down - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Use nearest pixel when scaling up. - checkGLErrors(); - + texture.configure(GL_TEXTURE_2D); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, width, height, GL_LUMINANCE, GL_FLOAT, textureBuffer.data()); return texture;