Commit 67c4cd79 authored by Robert Menzel's avatar Robert Menzel

added TextureBuffer

parent ff726547
......@@ -22,9 +22,122 @@
#include <vector>
#include <ACGL/OpenGL/Objects/Buffer.hh>
namespace ACGL{
namespace OpenGL{
/*
class TextureNG
{
ACGL_NOT_COPYABLE(TextureNG)
public:
TextureNG(GLenum _target) : mObjectName(0),
mTarget(_target) {
glGenTextures(1, &mObjectName);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate texture!" << std::endl;
}
}
virtual ~TextureNG()
{
// object name 0 will get ignored by OpenGL
glDeleteTextures(1, &mObjectName);
}
inline GLuint getObjectName () const { return mObjectName; }
inline GLenum getTarget () const { return mTarget; }
//! Activate texture unit and bind this texture.
void bind(GLuint _textureUnit = 0) const
{
glActiveTexture(GL_TEXTURE0 + _textureUnit);
glBindTexture(mTarget, mObjectName);
openGLRareError();
}
private:
GLuint mObjectName;
GLenum mTarget;
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureNG)
*/
#if (ACGL_OPENGL_VERSION >= 30)
/*
* TextureBuffers are 1D textures which store there data in a Buffer.
* They are useful to access large chunks of data from within a shader.
* Technically they are accessed as textures (uniform samplerBuffer) via texelFetch
* with a 1D coordinate (int coordinate, so no filtering). This means they benefit from
* texture caches.
* Use these if the data doesn't fit into a UniformBufferObject.
*
* Data gets stored in the Buffer, no glTexImage calles are allowed!
*/
class TextureBuffer : public Buffer
{
public:
// _reservedMemory is counted in bytes
TextureBuffer( GLenum _dataType, size_t _reservedMemory = 1 ) : Buffer(GL_TEXTURE_BUFFER) {
glGenTextures(1, &mTextureObjectName);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate texture object for texture buffer!" << std::endl;
}
mDataType = _dataType;
Buffer::setData( _reservedMemory );
attachBufferToTexture();
}
//! the GL buffer can get changed at any time
void setBufferObject( SharedBufferObject _pBuffer ) {
Buffer::setBufferObject( _pBuffer );
if (_pBuffer == NULL) {
// detach all buffers:
glTexBuffer( GL_TEXTURE_BUFFER, mDataType, 0 );
} else {
attachBufferToTexture();
}
}
~TextureBuffer() {
setBufferObject( SharedBufferObject() ); // detach the Buffer
glDeleteTextures(1, &mTextureObjectName);
}
void bindTexture(GLuint _textureUnit = 0) const {
glActiveTexture(GL_TEXTURE0 + _textureUnit);
glBindTexture(GL_TEXTURE_BUFFER, mTextureObjectName);
openGLRareError();
}
void bindBuffer() const {
Buffer::bind();
}
inline GLuint getTextureObjectName() const { return mTextureObjectName; }
inline GLuint getBufferObjectName() const { return Buffer::getObjectName(); }
private:
//! private to prevent it from being called -> it's not clear whether the texture or the buffer should get bound, call
//! bindBuffer() or bindTexture() directly!
void bind() {}
void attachBufferToTexture() {
assert( Buffer::getSize() > 0 && "glTexBuffer will fail if the buffer is empty" );
TextureNG::bind();
openGLCriticalErrorOccured();
glTexBuffer( GL_TEXTURE_BUFFER, mDataType, Buffer::getObjectName() );
openGLCriticalErrorOccured();
}
GLenum mDataType;
GLuint mTextureObjectName;
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureBuffer)
#endif // OpenGL 3.0+
class Texture
{
ACGL_NOT_COPYABLE(Texture)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment