Browse Source

Added support for three-component internal formats to BufferedTexture.

It's slight copypaste, because operator| doesn't accept typedefs and
extracting the algorithm from Renderbuffer would cause the code to be
overcomplicated and not prepared for more buffer texture/renderbuffer
format additions.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
dc19538f2a
  1. 52
      src/BufferedTexture.cpp
  2. 74
      src/BufferedTexture.h
  3. 1
      src/CMakeLists.txt

52
src/BufferedTexture.cpp

@ -0,0 +1,52 @@
/*
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 "BufferedTexture.h"
namespace Magnum {
BufferedTexture::InternalFormat::InternalFormat(Components components, ComponentType type) {
#define internalFormatSwitch(c) switch(type) { \
case ComponentType::UnsignedByte: \
internalFormat = GL_##c##8UI; break; \
case ComponentType::Byte: \
internalFormat = GL_##c##8I; break; \
case ComponentType::UnsignedShort: \
internalFormat = GL_##c##16UI; break; \
case ComponentType::Short: \
internalFormat = GL_##c##16I; break; \
case ComponentType::UnsignedInt: \
internalFormat = GL_##c##32UI; break; \
case ComponentType::Int: \
internalFormat = GL_##c##32I; break; \
case ComponentType::Half: \
internalFormat = GL_##c##16F; break; \
case ComponentType::Float: \
internalFormat = GL_##c##32F; break; \
case ComponentType::NormalizedUnsignedByte: \
internalFormat = GL_##c##8; break; \
case ComponentType::NormalizedUnsignedShort: \
internalFormat = GL_##c##16; break; \
}
if(components == Components::Red)
internalFormatSwitch(R)
else if(components == Components::RedGreen)
internalFormatSwitch(RG)
else if(components == Components::RGBA)
internalFormatSwitch(RGBA)
#undef internalFormatSwitch
}
}

74
src/BufferedTexture.h

@ -45,11 +45,63 @@ class BufferedTexture {
BufferedTexture& operator=(BufferedTexture&& other) = delete;
public:
/** @{ @name Internal buffered texture formats */
/** @copydoc Renderbuffer::Components */
typedef Renderbuffer::Components Components;
enum class Components {
Red, RedGreen, RGBA
};
/** @copydoc Renderbuffer::ComponentType */
typedef Renderbuffer::ComponentType ComponentType;
enum class ComponentType {
UnsignedByte, Byte, UnsignedShort, Short, UnsignedInt, Int, Half,
Float, NormalizedUnsignedByte, NormalizedUnsignedShort
};
/** @copydoc AbstractTexture::Format */
enum class Format: GLenum {
/**
* Three-component RGB, float, each component 32bit, 96bit total.
*
* @requires_gl40 Extension <tt>ARB_texture_buffer_object_rgb32</tt>
*/
RGB32Float = GL_RGB32F,
/**
* Three-component RGB, unsigned non-normalized, each component
* 32bit, 96bit total.
*
* @requires_gl40 Extension <tt>ARB_texture_buffer_object_rgb32</tt>
*/
RGB32UnsignedInt = GL_RGB32UI,
/**
* Three-component RGB, signed non-normalized, each component
* 32bit, 96bit total.
*
* @requires_gl40 Extension <tt>ARB_texture_buffer_object_rgb32</tt>
*/
RGB32Int = GL_RGB32I
};
/** @copydoc AbstractTexture::InternalFormat */
class MAGNUM_EXPORT InternalFormat {
public:
/** @copydoc AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Components, AbstractTexture::ComponentType) */
InternalFormat(Components components, ComponentType type);
/** @copydoc AbstractTexture::InternalFormat::InternalFormat(AbstractTexture::Format) */
inline constexpr InternalFormat(Format format): internalFormat(static_cast<GLenum>(format)) {}
/** @brief OpenGL internal format ID */
/* doxygen: @copydoc AbstractTexture::InternalFormat::operator GLint() doesn't work */
inline constexpr operator GLint() const { return internalFormat; }
private:
GLint internalFormat;
};
/*@}*/
/**
* @brief Constructor
@ -76,17 +128,16 @@ class BufferedTexture {
/**
* @brief Set texture buffer
* @param components Component count
* @param type Data type per component
* @param buffer %Buffer with data
* @param internalFormat Internal format
* @param buffer %Buffer with data
*
* Binds given buffer to this texture. The buffer itself can be then
* filled with data of proper format at any time using Buffer own data
* setting functions.
*/
void setBuffer(Components components, ComponentType type, Buffer* buffer) {
void setBuffer(InternalFormat internalFormat, Buffer* buffer) {
bind();
glTexBuffer(GL_TEXTURE_BUFFER, components|type, buffer->id());
glTexBuffer(GL_TEXTURE_BUFFER, internalFormat, buffer->id());
}
private:
@ -94,6 +145,15 @@ class BufferedTexture {
GLuint texture;
};
/** @copydoc operator|(AbstractTexture::Components, AbstractTexture::ComponentType) */
inline BufferedTexture::InternalFormat operator|(BufferedTexture::Components components, BufferedTexture::ComponentType type) {
return BufferedTexture::InternalFormat(components, type);
}
/** @copydoc operator|(AbstractTexture::ComponentType, AbstractTexture::Components) */
inline BufferedTexture::InternalFormat operator|(BufferedTexture::ComponentType type, BufferedTexture::Components components) {
return BufferedTexture::InternalFormat(components, type);
}
}
#endif

1
src/CMakeLists.txt

@ -13,6 +13,7 @@ set(Magnum_SRCS
AbstractImage.cpp
AbstractTexture.cpp
AbstractShaderProgram.cpp
BufferedTexture.cpp
Camera.cpp
Framebuffer.cpp
IndexedMesh.cpp

Loading…
Cancel
Save