Browse Source

Greatly simplified Texture::setWrapping().

Temporarily removed the check for not setting repeat wrap mode on
rectangle textures.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
6cd72578f0
  1. 22
      src/AbstractTexture.h
  2. 1
      src/CMakeLists.txt
  3. 46
      src/Texture.cpp
  4. 5
      src/Texture.h

22
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, Dimensions>& 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, 1>& wrapping) {
glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast<GLint>(wrapping.at(0)));
}
inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<GLsizei, 1>& dimensions, ColorFormat colorFormat, Type type, const void* data) {
glTexImage1D(target, mipLevel, static_cast<GLint>(internalFormat), dimensions.at(0), 0, static_cast<GLenum>(colorFormat), static_cast<GLenum>(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, 2>& wrapping) {
glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast<GLint>(wrapping.at(0)));
glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast<GLint>(wrapping.at(1)));
}
inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<GLsizei, 2>& dimensions, ColorFormat colorFormat, Type type, const void* data) {
glTexImage2D(target, mipLevel, static_cast<GLint>(internalFormat), dimensions.at(0), dimensions.at(1), 0, static_cast<GLenum>(colorFormat), static_cast<GLenum>(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, 3>& wrapping) {
glTexParameteri(target, GL_TEXTURE_WRAP_S, static_cast<GLint>(wrapping.at(0)));
glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast<GLint>(wrapping.at(1)));
glTexParameteri(target, GL_TEXTURE_WRAP_R, static_cast<GLint>(wrapping.at(2)));
}
inline static void set(GLenum target, GLint mipLevel, InternalFormat internalFormat, const Math::Vector<GLsizei, 3>& dimensions, ColorFormat colorFormat, Type type, const void* data) {
glTexImage3D(target, mipLevel, static_cast<GLint>(internalFormat), dimensions.at(0), dimensions.at(1), dimensions.at(2), 0, static_cast<GLenum>(colorFormat), static_cast<GLenum>(type), data);
}

1
src/CMakeLists.txt

@ -18,7 +18,6 @@ set(Magnum_SRCS
Scene.cpp
Shader.cpp
SizeTraits.cpp
Texture.cpp
TypeTraits.cpp
Trade/AbstractImporter.cpp

46
src/Texture.cpp

@ -1,46 +0,0 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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<size_t dimensions> void Texture<dimensions>::setWrapping(const Math::Vector<Wrapping, Dimensions>& 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<GLint>(wrapping.at(i)));
break;
case 1:
glTexParameteri(target, GL_TEXTURE_WRAP_T, static_cast<GLint>(wrapping.at(i)));
break;
case 2:
glTexParameteri(target, GL_TEXTURE_WRAP_R, static_cast<GLint>(wrapping.at(i)));
break;
}
}
}
/* Instantiate all textures */
template class Texture<1>;
template class Texture<2>;
template class Texture<3>;
}

5
src/Texture.h

@ -72,7 +72,10 @@ template<size_t dimensions> class MAGNUM_EXPORT Texture: public AbstractTexture
* textures. Note that for rectangle textures repeating wrapping modes
* are unavailable.
*/
void setWrapping(const Math::Vector<Wrapping, Dimensions>& wrapping);
inline void setWrapping(const Math::Vector<Wrapping, Dimensions>& wrapping) {
bind();
DataHelper<Dimensions>::setWrapping(target, wrapping);
}
/**
* @brief Set texture data

Loading…
Cancel
Save