From 7b40da95adf4f835b02c194564ace742293393f7 Mon Sep 17 00:00:00 2001 From: Robert Menzel Date: Fri, 1 Feb 2013 13:28:58 +0100 Subject: [PATCH] cleanups and additional TextureBuffer constructor --- include/ACGL/OpenGL/Objects/Texture.hh | 44 +++++++++++++++++++++----- include/ACGL/OpenGL/Tools.hh | 4 +-- src/ACGL/OpenGL/Objects/Texture.cc | 1 - 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/include/ACGL/OpenGL/Objects/Texture.hh b/include/ACGL/OpenGL/Objects/Texture.hh index 6c0a6b7..8fdc6d5 100644 --- a/include/ACGL/OpenGL/Objects/Texture.hh +++ b/include/ACGL/OpenGL/Objects/Texture.hh @@ -46,8 +46,24 @@ public: glDeleteTextures(1, &mObjectName); } - inline GLuint getObjectName () const { return mObjectName; } - inline GLenum getTarget () const { return mTarget; } + GLuint getObjectName () const { return mObjectName; } + GLenum getTarget () const { return mTarget; } + + GLsizei getWidth () const; + GLsizei getHeight () const; + GLsizei getDepth () const; + glm::uvec3 getSize () const { return glm::uvec3( getWidth(), getHeight(), getDepth() ); } + GLenum getInternalFormat () const; + GLenum getFormat () const; + GLenum getType () const; + GLint getMinFilter () const; + GLint getMagFilter () const; + +#ifndef ACGL_OPENGLES_VERSION_20 + GLenum getWrapS () const; + GLenum getWrapT () const; + GLenum getWrapR () const; +#endif // ACGL_OPENGLES_VERSION_20 //! Activate texture unit and bind this texture. void bind(GLuint _textureUnit = 0) const @@ -78,7 +94,7 @@ ACGL_SMARTPOINTER_TYPEDEFS(TextureNG) class TextureBuffer : public Buffer { public: - // _reservedMemory is counted in bytes + // create a new BufferObject with _reservedMemory space (in bytes!) TextureBuffer( GLenum _dataType, size_t _reservedMemory = 1 ) : Buffer(GL_TEXTURE_BUFFER) { glGenTextures(1, &mTextureObjectName); if (openGLCriticalErrorOccured() ) { @@ -89,6 +105,21 @@ public: attachBufferToTexture(); } + // use an existing BufferObject + TextureBuffer( GLenum _dataType, SharedBufferObject _pBuffer ) : Buffer(_pBuffer, GL_TEXTURE_BUFFER) { + glGenTextures(1, &mTextureObjectName); + if (openGLCriticalErrorOccured() ) { + ACGL::Utils::error() << "could not generate texture object for texture buffer!" << std::endl; + } + mDataType = _dataType; + attachBufferToTexture(); + } + + ~TextureBuffer() { + setBufferObject( SharedBufferObject() ); // detach the Buffer + glDeleteTextures(1, &mTextureObjectName); + } + //! the GL buffer can get changed at any time void setBufferObject( SharedBufferObject _pBuffer ) { Buffer::setBufferObject( _pBuffer ); @@ -100,17 +131,14 @@ public: } } - ~TextureBuffer() { - setBufferObject( SharedBufferObject() ); // detach the Buffer - glDeleteTextures(1, &mTextureObjectName); - } - + //! Bind the texture part to access it from a shader void bindTexture(GLuint _textureUnit = 0) const { glActiveTexture(GL_TEXTURE0 + _textureUnit); glBindTexture(GL_TEXTURE_BUFFER, mTextureObjectName); openGLRareError(); } + //! Bind the buffer part to change the data void bindBuffer() const { Buffer::bind(); } diff --git a/include/ACGL/OpenGL/Tools.hh b/include/ACGL/OpenGL/Tools.hh index 35c7ac2..14bae8e 100644 --- a/include/ACGL/OpenGL/Tools.hh +++ b/include/ACGL/OpenGL/Tools.hh @@ -95,8 +95,8 @@ bool doesSupportTessellationShader(); bool doesSupportComputeShader(); -// define the shader kinds for older GL versions so the file extension detection -// can work correctly +// Define the shader kinds for older and embedded GL versions so the file extension detection +// can work correctly. #ifndef GL_GEOMETRY_SHADER #define GL_GEOMETRY_SHADER 0x8DD9 #endif diff --git a/src/ACGL/OpenGL/Objects/Texture.cc b/src/ACGL/OpenGL/Objects/Texture.cc index 4be695f..056253a 100644 --- a/src/ACGL/OpenGL/Objects/Texture.cc +++ b/src/ACGL/OpenGL/Objects/Texture.cc @@ -9,7 +9,6 @@ using namespace ACGL::OpenGL; - #ifndef ACGL_OPENGLES_VERSION_20 void Texture::setWrapS( GLenum _wrapS ) { -- GitLab