Commit e758bf11 authored by Robert Menzel's avatar Robert Menzel
Browse files

more texture formats supported, FBO works with new Texture classes

parent 77c39515
...@@ -48,14 +48,14 @@ public: ...@@ -48,14 +48,14 @@ public:
inline FrameBufferObjectControl& colorTexture(const std::string& _name, const ConstSharedTexture& _texture) inline FrameBufferObjectControl& colorTexture(const std::string& _name, const ConstSharedTexture& _texture)
{ {
FrameBufferObject::Attachment attachment = {_name, _texture, SharedRenderBuffer(), (GLuint) mColorAttachments.size()}; FrameBufferObject::Attachment attachment = {_name, _texture, SharedRenderBuffer(), (GLuint) mColorAttachments.size(), Image()};
mColorAttachments.push_back(attachment); mColorAttachments.push_back(attachment);
return *this; return *this;
} }
inline FrameBufferObjectControl& colorRenderBuffer(const std::string& _name, const ConstSharedRenderBuffer& _renderBuffer) inline FrameBufferObjectControl& colorRenderBuffer(const std::string& _name, const ConstSharedRenderBuffer& _renderBuffer)
{ {
FrameBufferObject::Attachment attachment = {_name, SharedTexture(), _renderBuffer, (GLuint) mColorAttachments.size()}; FrameBufferObject::Attachment attachment = {_name, SharedTextureBase(), _renderBuffer, (GLuint) mColorAttachments.size(), Image()};
mColorAttachments.push_back(attachment); mColorAttachments.push_back(attachment);
return *this; return *this;
} }
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <ACGL/Base/Macros.hh> #include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh> #include <ACGL/OpenGL/GL.hh>
#include <ACGL/Math/Math.hh>
namespace ACGL{ namespace ACGL{
namespace OpenGL{ namespace OpenGL{
...@@ -59,6 +60,7 @@ public: ...@@ -59,6 +60,7 @@ public:
void setDepth (GLsizei _depth) { depth = _depth; } void setDepth (GLsizei _depth) { depth = _depth; }
void setFormat(GLenum _format) { format = _format; } void setFormat(GLenum _format) { format = _format; }
void setType (GLenum _type) { type = _type; } void setType (GLenum _type) { type = _type; }
void setSize (const glm::uvec3 &_size) { width = _size.x; height = _size.y; depth = _size.z; }
// ========================================================================================================= \/ // ========================================================================================================= \/
// ================================================================================================== FIELDS \/ // ================================================================================================== FIELDS \/
......
...@@ -48,12 +48,22 @@ class FrameBufferObject ...@@ -48,12 +48,22 @@ class FrameBufferObject
// ==================================================================================================== \/ // ==================================================================================================== \/
public: public:
//! An attachment can be a texture or a render buffer //! An attachment can be a texture or a render buffer
struct Attachment /*struct Attachment
{ {
std::string name; // user defined name that matches the fragment shader out std::string name; // user defined name that matches the fragment shader out
ConstSharedTexture texture; // attached color texture, or: ConstSharedTexture texture; // attached color texture, or:
ConstSharedRenderBuffer renderBuffer; // attached renderbuffer - only this or the texture should be set! ConstSharedRenderBuffer renderBuffer; // attached renderbuffer - only this or the texture should be set!
GLuint location; // the frag data location that maps to this attachment GLuint location; // the frag data location that maps to this attachment
};*/
//! An attachment can be a texture or a render buffer
struct Attachment
{
std::string name; // user defined name that matches the fragment shader out
ConstSharedTextureBase texture; // attached color texture, or:
ConstSharedRenderBuffer renderBuffer; // attached renderbuffer - only this or the texture should be set!
GLuint location; // the frag data location that maps to this attachment
Image image; // in case of a texture the image will define which part of the texture to use
}; };
// ===================================================================================================== \/ // ===================================================================================================== \/
...@@ -123,25 +133,25 @@ public: ...@@ -123,25 +133,25 @@ public:
*/ */
inline bool attachColorRenderBuffer(const std::string &_name, const ConstSharedRenderBuffer& _renderBuffer) inline bool attachColorRenderBuffer(const std::string &_name, const ConstSharedRenderBuffer& _renderBuffer)
{ {
Attachment a = {_name, SharedTexture(), _renderBuffer, 0xFFFFFFFF /*(GLuint) mColorAttachments.size()*/}; Attachment a = {_name, SharedTexture(), _renderBuffer, 0xFFFFFFFF, Image()};
return attachColorAttachment( a ); return attachColorAttachment( a );
} }
inline bool attachColorTexture(const std::string &_name, const ConstSharedTexture& _texture) inline bool attachColorTexture(const std::string &_name, const ConstSharedTextureBase& _texture, const Image _image = Image() )
{ {
Attachment a = {_name, _texture, SharedRenderBuffer(), 0xFFFFFFFF /*(GLuint) mColorAttachments.size()*/}; Attachment a = {_name, _texture, SharedRenderBuffer(), 0xFFFFFFFF, _image};
return attachColorAttachment( a ); return attachColorAttachment( a );
} }
inline bool attachColorRenderBuffer(const std::string &_name, const ConstSharedRenderBuffer& _renderBuffer, GLuint _location ) inline bool attachColorRenderBuffer(const std::string &_name, const ConstSharedRenderBuffer& _renderBuffer, GLuint _location )
{ {
Attachment a = {_name, SharedTexture(), _renderBuffer, _location}; Attachment a = {_name, SharedTexture(), _renderBuffer, _location, Image()};
return attachColorAttachment( a ); return attachColorAttachment( a );
} }
inline bool attachColorTexture(const std::string &_name, const ConstSharedTexture& _texture, GLuint _location ) inline bool attachColorTexture(const std::string &_name, const ConstSharedTextureBase& _texture, GLuint _location, const Image _image = Image() )
{ {
Attachment a = {_name, _texture, SharedRenderBuffer(), _location}; Attachment a = {_name, _texture, SharedRenderBuffer(), _location, _image};
return attachColorAttachment( a ); return attachColorAttachment( a );
} }
...@@ -169,7 +179,8 @@ public: ...@@ -169,7 +179,8 @@ public:
return true; return true;
} }
inline bool setDepthTexture(const ConstSharedTexture& _texture) //! todo: support mipmap levels
inline bool setDepthTexture(const ConstSharedTextureBase& _texture)
{ {
bind(); bind();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _texture->getTarget(), _texture->getObjectName(), 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _texture->getTarget(), _texture->getObjectName(), 0);
...@@ -187,6 +198,7 @@ public: ...@@ -187,6 +198,7 @@ public:
} }
//! x,y coordinate is the FBO size in pixels, z coordinate the number of color attachments. x,y are both 0 if the FBO has no useful size //! x,y coordinate is the FBO size in pixels, z coordinate the number of color attachments. x,y are both 0 if the FBO has no useful size
//! todo: support mipmap levels
glm::uvec3 getSize() const glm::uvec3 getSize() const
{ {
glm::uvec3 size; glm::uvec3 size;
......
...@@ -236,8 +236,8 @@ public: ...@@ -236,8 +236,8 @@ public:
#endif // OpenGL >= 4.0 #endif // OpenGL >= 4.0
//! sets a texture uniform to a given texture unit and also binds the texture to the same unit //! sets a texture uniform to a given texture unit and also binds the texture to the same unit
inline void setTexture (GLint _location, const ConstSharedTexture& _texture, GLint _unit) const { glUniform1i(_location, _unit); _texture->bind(_unit); } inline void setTexture (GLint _location, const ConstSharedTextureBase& _texture, GLint _unit) const { glUniform1i(_location, _unit); _texture->bind(_unit); }
inline void setTexture (const std::string& _nameInShader, const ConstSharedTexture& _texture, GLint _unit) const { setUniform( getUniformLocation(_nameInShader), (GLint) _unit); _texture->bind(_unit); } inline void setTexture (const std::string& _nameInShader, const ConstSharedTextureBase& _texture, GLint _unit) const { setUniform( getUniformLocation(_nameInShader), (GLint) _unit); _texture->bind(_unit); }
//! set the texture to the texture unit the uniform is set to. //! set the texture to the texture unit the uniform is set to.
//! Note: it is not guaranteed that all uniforms for textures are set to unique samplers by default after linking! //! Note: it is not guaranteed that all uniforms for textures are set to unique samplers by default after linking!
void setTexture( const std::string& _nameInShader, const ConstSharedTexture& _texture ) const { void setTexture( const std::string& _nameInShader, const ConstSharedTexture& _texture ) const {
......
...@@ -25,6 +25,13 @@ ...@@ -25,6 +25,13 @@
namespace ACGL{ namespace ACGL{
namespace OpenGL{ namespace OpenGL{
// the combination of Image and SharedTextureBase will identify a Rendertarget etc.:
struct Image {
Image() : mipmapLevel(0), layer(0), cubeMapFace(GL_INVALID_ENUM) {}
unsigned int mipmapLevel; // always 0 if texture has no mipmaps
unsigned int layer; // array layer or slice in a 3D texture, always 0 if texture is 1D or 2D
GLenum cubeMapFace; // GL_INVALID_ENUM if texture is not a cube map
};
/* /*
* A Texture consists of: * A Texture consists of:
...@@ -62,6 +69,20 @@ public: ...@@ -62,6 +69,20 @@ public:
} }
} }
TextureBase(GLenum _target, GLenum _internalFormat)
: mObjectName(0),
mTarget(_target),
mWidth(0),
mHeight(1),
mDepth(1),
mInternalFormat(_internalFormat)
{
glGenTextures(1, &mObjectName);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate texture!" << std::endl;
}
}
virtual ~TextureBase(void) virtual ~TextureBase(void)
{ {
// object name 0 will get ignored by OpenGL // object name 0 will get ignored by OpenGL
...@@ -172,49 +193,55 @@ protected: ...@@ -172,49 +193,55 @@ protected:
//! reserve memory, not to upload actual data! //! reserve memory, not to upload actual data!
GLenum getCompatibleFormat( GLenum _internalFormat ); GLenum getCompatibleFormat( GLenum _internalFormat );
GLenum getCompatibleType( GLenum _internalFormat ); GLenum getCompatibleType( GLenum _internalFormat );
//void texImage1D( const SharedTextureData &_data, const Image &_target );
//! to be used by subclasses, will not check if usage is meaningfull for the
//! texture target, this has to be checked by the subclass (this is why this
//! function is private here)
void texImage2D( const SharedTextureData &_data, GLint _mipmapLevel );
void texSubImage2D( const SharedTextureData &_data, GLint _mipmapLevel, glm::ivec2 _offset = glm::ivec2(0) );
void texImage3D( const SharedTextureData &_data, GLint _mipmapLevel );
void texSubImage3D( const SharedTextureData &_data, GLint _mipmapLevel, glm::ivec3 _offset = glm::ivec3(0) );
//! returns true if space for the texture was allocated
bool textureStorageIsAllocated()
{
return (mWidth*mHeight*mDepth != 0);
}
}; };
ACGL_SMARTPOINTER_TYPEDEFS(TextureBase) ACGL_SMARTPOINTER_TYPEDEFS(TextureBase)
// missing classes: // missing classes:
// GL_TEXTURE_1D // GL_TEXTURE_1D
// GL_TEXTURE_2D // GL_TEXTURE_2D x
// GL_TEXTURE_3D // GL_TEXTURE_3D
// GL_TEXTURE_1D_ARRAY // GL_TEXTURE_1D_ARRAY
// GL_TEXTURE_2D_ARRAY // GL_TEXTURE_2D_ARRAY x
// GL_TEXTURE_RECTANGLE // GL_TEXTURE_RECTANGLE x
// GL_TEXTURE_2D_MULTISAMPLE // GL_TEXTURE_2D_MULTISAMPLE
// GL_TEXTURE_2D_MULTISAMPLE_ARRAY // GL_TEXTURE_2D_MULTISAMPLE_ARRAY
// GL_TEXTURE_BINDING_CUBE_MAP // GL_TEXTURE_BINDING_CUBE_MAP x
// GL_TEXTURE_BINDING_CUBE_MAP_ARRAY // GL_TEXTURE_BINDING_CUBE_MAP_ARRAY
// the combination of Image and SharedTextureBase will identify a Rendertarget etc.:
struct Image {
unsigned int mipmapLevel; // always 0 if texture has no mipmaps
unsigned int layer; // array layer or slice in a 3D texture, always 0 if texture is 1D or 2D
GLenum cubeMapFace; // GL_INVALID_ENUM if texture is not a cube map
};
class TextureRectangle : public TextureBase class TextureRectangle : public TextureBase
{ {
public: public:
TextureRectangle( GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_RECTANGLE ) TextureRectangle( GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_RECTANGLE, _internalFormat )
{ {
mInternalFormat = _internalFormat; setMinFilter( GL_LINEAR ); // default would be MipMapped but that's not supported for Rect Textures!
// default would be MipMapped but that's not supported for Rect Textures!
setMinFilter( GL_LINEAR );
} }
TextureRectangle( const glm::uvec2 &_size, GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_RECTANGLE ) TextureRectangle( const glm::uvec2 &_size, GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_RECTANGLE, _internalFormat )
{ {
mInternalFormat = _internalFormat; setMinFilter( GL_LINEAR ); // default would be MipMapped but that's not supported for Rect Textures!
// default would be MipMapped but that's not supported for Rect Textures!
setMinFilter( GL_LINEAR );
resize( _size ); resize( _size );
} }
//! sets the content to the given TextureData, might resize the texture //! sets the content to the given TextureData, might resize the texture
//void setImageData( const SharedTextureData &_data ); void setImageData( const SharedTextureData &_data );
//! content of the texture is undefined after this, this texture will be bound to the active binding point //! content of the texture is undefined after this, this texture will be bound to the active binding point
//! nothing should be bound to the pixel unpack buffer when calling this //! nothing should be bound to the pixel unpack buffer when calling this
...@@ -225,22 +252,104 @@ private: ...@@ -225,22 +252,104 @@ private:
}; };
ACGL_SMARTPOINTER_TYPEDEFS(TextureRectangle) ACGL_SMARTPOINTER_TYPEDEFS(TextureRectangle)
class Texture2D : public TextureBase class Texture2D : public TextureBase
{ {
public: public:
Texture2D() : TextureBase( GL_TEXTURE_2D ) {} Texture2D( GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_2D, _internalFormat ) {}
Texture2D( const glm::uvec2 &_size, GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_2D, _internalFormat )
{
resize( _size );
}
//void setImageData( const SharedTextureData &_data, const Image &_target ); //! sets the content to the given TextureData, might resize the texture
void setImageData( const SharedTextureData &_data, uint32_t _mipmapLayer = 0 )
{
if (!textureStorageIsAllocated()) {
texImage2D( _data, _mipmapLayer );
} else {
texSubImage2D( _data, _mipmapLayer );
}
}
//! content of the texture is undefined after this, this texture will be bound to the active binding point
//! nothing should be bound to the pixel unpack buffer when calling this
void resize( const glm::uvec2 &_newSize );
}; };
ACGL_SMARTPOINTER_TYPEDEFS(Texture2D) ACGL_SMARTPOINTER_TYPEDEFS(Texture2D)
class Texture2DArray : public TextureBase class Texture2DArray : public TextureBase
{ {
public: public:
Texture2DArray() : TextureBase( GL_TEXTURE_2D_ARRAY ) {} Texture2DArray( GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_2D_ARRAY, _internalFormat ) {}
Texture2DArray( const glm::uvec3 &_size, GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_2D_ARRAY, _internalFormat )
{
resize( _size );
}
//! sets the content to the given TextureData, might resize the texture
void setImageData( const SharedTextureData &_data, uint32_t _arrayLayer = 0, uint32_t _mipmapLayer = 0 )
{
if (!textureStorageIsAllocated()) {
texImage3D( _data, _mipmapLayer );
} else {
glm::ivec3 offset = glm::ivec3(0,0,_arrayLayer); // the array layer is the offset in Z in a 3D texture
texSubImage3D( _data, _mipmapLayer, offset );
}
}
//! content of the texture is undefined after this, this texture will be bound to the active binding point
//! nothing should be bound to the pixel unpack buffer when calling this
void resize( const glm::uvec3 &_newSize );
}; };
ACGL_SMARTPOINTER_TYPEDEFS(Texture2DArray) ACGL_SMARTPOINTER_TYPEDEFS(Texture2DArray)
class TextureCubeMap : public TextureBase
{
public:
TextureCubeMap( GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_BINDING_CUBE_MAP, _internalFormat ) {}
TextureCubeMap( const glm::uvec2 &_size, GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_BINDING_CUBE_MAP, _internalFormat )
{
resize( _size );
}
//! sets the content to the given TextureData, might resize the texture
void setImageData( const SharedTextureData &_data, GLenum _cubeSide, uint32_t _mipmapLayer = 0 )
{
if (!textureStorageIsAllocated()) {
texImage2DCube( _data, _cubeSide, _mipmapLayer );
} else {
texSubImage2DCube( _data, _cubeSide, _mipmapLayer );
}
}
//! content of the texture is undefined after this, this texture will be bound to the active binding point
//! nothing should be bound to the pixel unpack buffer when calling this
void resize( const glm::uvec2 &_newSize );
private:
bool cubeSideIsValid( const GLenum _cubeSide ) const;
void texImage2DCube( const SharedTextureData &_data, GLenum _cubeSide, GLint _mipmapLevel );
void texSubImage2DCube( const SharedTextureData &_data, GLenum _cubeSide, GLint _mipmapLevel, glm::ivec2 _offset = glm::ivec2(0) );
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureCubeMap)
// //
// Full compatibility with the old Texture class: // Full compatibility with the old Texture class:
// //
......
...@@ -10,56 +10,6 @@ using namespace ACGL::OpenGL; ...@@ -10,56 +10,6 @@ using namespace ACGL::OpenGL;
SharedFrameBufferObject FrameBufferObjectControl::create(void) SharedFrameBufferObject FrameBufferObjectControl::create(void)
{ {
/*
SharedFrameBufferObject frameBuffer(new FrameBufferObject());
frameBuffer->bind();
#if (ACGL_OPENGL_VERSION >= 30)
if(mpShaderProgram)
{
std::vector<int_t> assignmentOrder(mColorAttachments.size());
for(std::vector<int_t>::size_type i = 0; i < assignmentOrder.size(); ++i) assignmentOrder[i] = -1;
for(FrameBufferObject::AttachmentVec::size_type i = 0; i < mColorAttachments.size(); ++i)
{
GLint location = mpShaderProgram->getFragmentDataLocation(mColorAttachments[i].name);
if (location < 0) {
ACGL::Utils::warning() << "ShaderProgram has no FragDataLocation named " << mColorAttachments[i].name << " - ignored" << std::endl;
}
assignmentOrder[location] = i;
}
for(std::vector<int_t>::size_type j = 0; j < assignmentOrder.size(); ++j)
{
if (assignmentOrder[j] < 0) continue;
if(mColorAttachments[assignmentOrder[j]].texture)
frameBuffer->attachColorTexture(mColorAttachments[assignmentOrder[j]].name, mColorAttachments[assignmentOrder[j]].texture);
else if(mColorAttachments[assignmentOrder[j]].renderBuffer)
frameBuffer->attachColorRenderBuffer(mColorAttachments[assignmentOrder[j]].name, mColorAttachments[assignmentOrder[j]].renderBuffer);
}
}
else
#endif
{
for(FrameBufferObject::AttachmentVec::size_type i = 0; i < mColorAttachments.size(); ++i)
{
if(mColorAttachments[i].texture)
frameBuffer->attachColorTexture(mColorAttachments[i].name, mColorAttachments[i].texture);
else if(mColorAttachments[i].renderBuffer)
frameBuffer->attachColorRenderBuffer(mColorAttachments[i].name, mColorAttachments[i].renderBuffer);
}
}
if(mDepthAttachment.texture)
frameBuffer->setDepthTexture(mDepthAttachment.texture);
else if(mDepthAttachment.renderBuffer)
frameBuffer->setDepthRenderBuffer(mDepthAttachment.renderBuffer);
return frameBuffer;
*/
SharedFrameBufferObject fbo = SharedFrameBufferObject(new FrameBufferObject()); SharedFrameBufferObject fbo = SharedFrameBufferObject(new FrameBufferObject());
// attach all defined color Textures and RenderBuffers // attach all defined color Textures and RenderBuffers
......
...@@ -129,7 +129,54 @@ bool FrameBufferObject::attachColorAttachment( const Attachment &_attachment ) ...@@ -129,7 +129,54 @@ bool FrameBufferObject::attachColorAttachment( const Attachment &_attachment )
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + realLocation, GL_RENDERBUFFER, _attachment.renderBuffer->getObjectName() ); glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + realLocation, GL_RENDERBUFFER, _attachment.renderBuffer->getObjectName() );
} else { } else {
// it's a texture // it's a texture
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + realLocation, _attachment.texture->getTarget(), _attachment.texture->getObjectName(), 0 ); GLenum textureTarget = _attachment.texture->getTarget();
int dimensionality = 0;
if (textureTarget == GL_TEXTURE_1D) {
dimensionality = 1;
} else if (textureTarget == GL_TEXTURE_2D || textureTarget == GL_TEXTURE_2D_MULTISAMPLE) {
dimensionality = 2;
} else if (textureTarget == GL_TEXTURE_3D) {
dimensionality = 3;
} else if (textureTarget == GL_TEXTURE_1D_ARRAY) {
dimensionality = 2;
} else if (textureTarget == GL_TEXTURE_2D_ARRAY || textureTarget == GL_TEXTURE_2D_MULTISAMPLE_ARRAY) {
dimensionality = 3;
} else if (textureTarget == GL_TEXTURE_RECTANGLE) {
dimensionality = 2;
} else if (textureTarget == GL_TEXTURE_BINDING_CUBE_MAP) {
dimensionality = 2;
textureTarget = _attachment.image.cubeMapFace;
} else if (textureTarget == GL_TEXTURE_BINDING_CUBE_MAP_ARRAY) {
dimensionality = 3;
textureTarget = _attachment.image.cubeMapFace;
} else {
Utils::error() << "attachColorAttachment failed, texture target not supported" << std::endl;
}
if (dimensionality == 1) {
glFramebufferTexture1D( GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0 + realLocation,
textureTarget,
_attachment.texture->getObjectName(),
_attachment.image.mipmapLevel );
} else if (dimensionality == 2) {
glFramebufferTexture2D( GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0 + realLocation,
textureTarget,
_attachment.texture->getObjectName(),
_attachment.image.mipmapLevel );
} else if (dimensionality == 3) {
glFramebufferTexture3D( GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0 + realLocation,
textureTarget,
_attachment.texture->getObjectName(),
_attachment.image.layer,
_attachment.image.mipmapLevel );
} else {
Utils::error() << "attachColorAttachment failed, texture target not supported" << std::endl;
}
//Utils::debug() << "glFramebufferTexture2D( " << _attachment.name << " to " << realLocation <<" )" << std::endl; //Utils::debug() << "glFramebufferTexture2D( " << _attachment.name << " to " << realLocation <<" )" << std::endl;
} }
if (openGLCommonErrorOccured()) if (openGLCommonErrorOccured())
......
...@@ -262,25 +262,198 @@ GLenum TextureBase::getCompatibleType( GLenum _internalFormat ) ...@@ -262,25 +262,198 @@ GLenum TextureBase::getCompatibleType( GLenum _internalFormat )
void TextureRectangle::resize( const glm::uvec2 &_newSize ) void TextureRectangle::resize( const glm::uvec2 &_newSize )
{ {
if (_newSize.x != (unsigned int)mWidth || _newSize.y != (unsigned int)mHeight) { if (_newSize.x != (unsigned int)mWidth || _newSize.y != (unsigned int)mHeight) {
mWidth = _newSize.x; SharedTextureData sTexData( new TextureData() );
mHeight = _newSize.y; sTexData->setData (NULL);
sTexData->setWidth (_newSize.x);
openGLCriticalErrorOccured(); sTexData->setHeight(_newSize.y);
bind(); sTexData->setFormat(getCompatibleFormat( mInternalFormat ));
glTexImage2D( sTexData->setType (getCompatibleType( mInternalFormat ));
mTarget, setImageData( sTexData );
0, // there are no mipmaps for Rect Textures!
mInternalFormat,
mWidth,
mHeight,
0, // no border
getCompatibleFormat( mInternalFormat ), // nothing gets uploaded, but this still has to be compatible with the internal format
getCompatibleType( mInternalFormat ), // nothing gets uploaded, but this still has to be compatible with the internal format
NULL );
openGLCriticalErrorOccured(); // the guess of compatible formats might be wrong so better test for errors!
} }
} }
void TextureRectangle::setImageData( const SharedTextureData &_data )
{
mWidth = _data->getWidth();
mHeight = _data->getHeight();