From 6cd72578f03cfd829127e005ab9575b94019de5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Mon, 20 Feb 2012 00:17:12 +0100 Subject: [PATCH] Greatly simplified Texture::setWrapping(). Temporarily removed the check for not setting repeat wrap mode on rectangle textures. --- src/AbstractTexture.h | 22 +++++++++++++++++++++ src/CMakeLists.txt | 1 - src/Texture.cpp | 46 ------------------------------------------- src/Texture.h | 5 ++++- 4 files changed, 26 insertions(+), 48 deletions(-) delete mode 100644 src/Texture.cpp diff --git a/src/AbstractTexture.h b/src/AbstractTexture.h index 2ec484b76..9c484d773 100644 --- a/src/AbstractTexture.h +++ b/src/AbstractTexture.h @@ -215,6 +215,13 @@ class MAGNUM_EXPORT AbstractTexture { */ inline constexpr static GLenum target(); + /** + * @brief Set texture wrapping + * @param target Target, such as @c GL_TEXTURE_RECTANGLE + * @param wrapping Wrapping type for all texture dimensions + */ + inline static void setWrapping(GLenum target, const Math::Vector& wrapping); + /** * @brief Set texture data * @param target Target, such as @c GL_TEXTURE_RECTANGLE @@ -256,6 +263,10 @@ class MAGNUM_EXPORT AbstractTexture { template<> struct AbstractTexture::DataHelper<1> { inline constexpr static GLenum target() { return GL_TEXTURE_1D; } + inline static void setWrapping(GLenum target, const Math::Vector& wrapping) { + glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping.at(0))); + } + inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, Type type, const void* data) { glTexImage1D(target, mipLevel, static_cast(internalFormat), dimensions.at(0), 0, static_cast(colorFormat), static_cast(type), data); } @@ -267,6 +278,11 @@ template<> struct AbstractTexture::DataHelper<1> { template<> struct AbstractTexture::DataHelper<2> { inline constexpr static GLenum target() { return GL_TEXTURE_2D; } + inline static void setWrapping(GLenum target, const Math::Vector& wrapping) { + glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping.at(0))); + glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast(wrapping.at(1))); + } + inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, Type type, const void* data) { glTexImage2D(target, mipLevel, static_cast(internalFormat), dimensions.at(0), dimensions.at(1), 0, static_cast(colorFormat), static_cast(type), data); } @@ -278,6 +294,12 @@ template<> struct AbstractTexture::DataHelper<2> { template<> struct AbstractTexture::DataHelper<3> { inline constexpr static GLenum target() { return GL_TEXTURE_3D; } + inline static void setWrapping(GLenum target, const Math::Vector& wrapping) { + glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping.at(0))); + glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast(wrapping.at(1))); + glTexParameteri(target, GL_TEXTURE_WRAP_R, static_cast(wrapping.at(2))); + } + inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector& dimensions, ColorFormat colorFormat, Type type, const void* data) { glTexImage3D(target, mipLevel, static_cast(internalFormat), dimensions.at(0), dimensions.at(1), dimensions.at(2), 0, static_cast(colorFormat), static_cast(type), data); } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a2489e82..25cab50cd 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,6 @@ set(Magnum_SRCS Scene.cpp Shader.cpp SizeTraits.cpp - Texture.cpp TypeTraits.cpp Trade/AbstractImporter.cpp diff --git a/src/Texture.cpp b/src/Texture.cpp deleted file mode 100644 index 358ae7384..000000000 --- a/src/Texture.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright © 2010, 2011, 2012 Vladimír Vondruš - - This file is part of Magnum. - - Magnum is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License version 3 - only, as published by the Free Software Foundation. - - Magnum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License version 3 for more details. -*/ - -#include "Texture.h" - -namespace Magnum { - -template void Texture::setWrapping(const Math::Vector& wrapping) { - bind(); - for(size_t i = 0; i != Dimensions; ++i) { - /* Repeat wrap modes are not available on rectangle textures. */ - if(target == GL_TEXTURE_RECTANGLE && (wrapping.at(i) == Wrapping::Repeat || wrapping.at(i) == Wrapping::MirroredRepeat)) - continue; - - switch(i) { - case 0: - glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast(wrapping.at(i))); - break; - case 1: - glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast(wrapping.at(i))); - break; - case 2: - glTexParameteri(target, GL_TEXTURE_WRAP_R, static_cast(wrapping.at(i))); - break; - } - } -} - -/* Instantiate all textures */ -template class Texture<1>; -template class Texture<2>; -template class Texture<3>; - -} diff --git a/src/Texture.h b/src/Texture.h index 625a80f91..9df76a1b8 100644 --- a/src/Texture.h +++ b/src/Texture.h @@ -72,7 +72,10 @@ template class MAGNUM_EXPORT Texture: public AbstractTexture * textures. Note that for rectangle textures repeating wrapping modes * are unavailable. */ - void setWrapping(const Math::Vector& wrapping); + inline void setWrapping(const Math::Vector& wrapping) { + bind(); + DataHelper::setWrapping(target, wrapping); + } /** * @brief Set texture data