Commit e758bf11 authored by Robert Menzel's avatar Robert Menzel

more texture formats supported, FBO works with new Texture classes

parent 77c39515
......@@ -48,14 +48,14 @@ public:
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);
return *this;
}
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);
return *this;
}
......
......@@ -16,6 +16,7 @@
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/Math/Math.hh>
namespace ACGL{
namespace OpenGL{
......@@ -59,6 +60,7 @@ public:
void setDepth (GLsizei _depth) { depth = _depth; }
void setFormat(GLenum _format) { format = _format; }
void setType (GLenum _type) { type = _type; }
void setSize (const glm::uvec3 &_size) { width = _size.x; height = _size.y; depth = _size.z; }
// ========================================================================================================= \/
// ================================================================================================== FIELDS \/
......
......@@ -48,12 +48,22 @@ class FrameBufferObject
// ==================================================================================================== \/
public:
//! 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
ConstSharedTexture 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
};*/
//! 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:
*/
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 );
}
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 );
}
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 );
}
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 );
}
......@@ -169,7 +179,8 @@ public:
return true;
}
inline bool setDepthTexture(const ConstSharedTexture& _texture)
//! todo: support mipmap levels
inline bool setDepthTexture(const ConstSharedTextureBase& _texture)
{
bind();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _texture->getTarget(), _texture->getObjectName(), 0);
......@@ -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
//! todo: support mipmap levels
glm::uvec3 getSize() const
{
glm::uvec3 size;
......
......@@ -236,8 +236,8 @@ public:
#endif // OpenGL >= 4.0
//! 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 (const std::string& _nameInShader, const ConstSharedTexture& _texture, GLint _unit) const { setUniform( getUniformLocation(_nameInShader), (GLint) _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 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.
//! 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 {
......
......@@ -25,6 +25,13 @@
namespace ACGL{
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:
......@@ -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)
{
// object name 0 will get ignored by OpenGL
......@@ -172,49 +193,55 @@ protected:
//! reserve memory, not to upload actual data!
GLenum getCompatibleFormat( 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)
// missing classes:
// GL_TEXTURE_1D
// GL_TEXTURE_2D
// GL_TEXTURE_2D x
// GL_TEXTURE_3D
// GL_TEXTURE_1D_ARRAY
// GL_TEXTURE_2D_ARRAY
// GL_TEXTURE_RECTANGLE
// GL_TEXTURE_2D_ARRAY x
// GL_TEXTURE_RECTANGLE x
// GL_TEXTURE_2D_MULTISAMPLE
// GL_TEXTURE_2D_MULTISAMPLE_ARRAY
// GL_TEXTURE_BINDING_CUBE_MAP
// GL_TEXTURE_BINDING_CUBE_MAP x
// 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
{
public:
TextureRectangle( GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_RECTANGLE )
TextureRectangle( GLenum _internalFormat = GL_RGBA ) : TextureBase( GL_TEXTURE_RECTANGLE, _internalFormat )
{
mInternalFormat = _internalFormat;
// default would be MipMapped but that's not supported for Rect Textures!
setMinFilter( GL_LINEAR );
setMinFilter( GL_LINEAR ); // default would be MipMapped but that's not supported for Rect Textures!
}
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;
// default would be MipMapped but that's not supported for Rect Textures!
setMinFilter( GL_LINEAR );
setMinFilter( GL_LINEAR ); // default would be MipMapped but that's not supported for Rect Textures!
resize( _size );
}
//! 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
//! nothing should be bound to the pixel unpack buffer when calling this
......@@ -225,22 +252,104 @@ private:
};
ACGL_SMARTPOINTER_TYPEDEFS(TextureRectangle)
class Texture2D : public TextureBase
{
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)
class Texture2DArray : public TextureBase
{
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)
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:
//
......
......@@ -10,56 +10,6 @@ using namespace ACGL::OpenGL;
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());
// attach all defined color Textures and RenderBuffers
......
......@@ -129,7 +129,54 @@ bool FrameBufferObject::attachColorAttachment( const Attachment &_attachment )
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + realLocation, GL_RENDERBUFFER, _attachment.renderBuffer->getObjectName() );
} else {
// 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;
}
if (openGLCommonErrorOccured())
......
......@@ -262,25 +262,198 @@ GLenum TextureBase::getCompatibleType( GLenum _internalFormat )
void TextureRectangle::resize( const glm::uvec2 &_newSize )
{
if (_newSize.x != (unsigned int)mWidth || _newSize.y != (unsigned int)mHeight) {
mWidth = _newSize.x;
mHeight = _newSize.y;
openGLCriticalErrorOccured();
bind();
glTexImage2D(
mTarget,
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!
SharedTextureData sTexData( new TextureData() );
sTexData->setData (NULL);
sTexData->setWidth (_newSize.x);
sTexData->setHeight(_newSize.y);
sTexData->setFormat(getCompatibleFormat( mInternalFormat ));
sTexData->setType (getCompatibleType( mInternalFormat ));
setImageData( sTexData );
}
}
void TextureRectangle::setImageData( const SharedTextureData &_data )
{
mWidth = _data->getWidth();
mHeight = _data->getHeight();
openGLCriticalErrorOccured();
bind();
glTexImage2D(
mTarget,
0, // there are no mipmaps for Rect Textures!
mInternalFormat,
mWidth, mHeight,
0, // no border
_data->getFormat(),
_data->getType(),
_data->getData() );
if (openGLCriticalErrorOccured()) // the guess of compatible formats might be wrong so better test for errors!
{
std::cerr << "foo" << std::endl;
}
}
void Texture2D::resize( const glm::uvec2 &_newSize )
{
if (_newSize.x != (unsigned int)mWidth || _newSize.y != (unsigned int)mHeight) {
SharedTextureData sTexData( new TextureData() );
sTexData->setData (NULL);
sTexData->setWidth (_newSize.x);
sTexData->setHeight(_newSize.y);
sTexData->setFormat(getCompatibleFormat( mInternalFormat ));
sTexData->setType (getCompatibleType( mInternalFormat ));
texImage2D( sTexData, 0 );
}
}
void Texture2DArray::resize( const glm::uvec3 &_newSize )
{
if (_newSize.x != (unsigned int)mWidth || _newSize.y != (unsigned int)mHeight || _newSize.z != (unsigned int)mDepth) {
SharedTextureData sTexData( new TextureData() );
sTexData->setData (NULL);
sTexData->setWidth (_newSize.x);
sTexData->setHeight(_newSize.y);
sTexData->setDepth (_newSize.z);
sTexData->setFormat(getCompatibleFormat( mInternalFormat ));
sTexData->setType (getCompatibleType( mInternalFormat ));
texImage3D( sTexData, 0 );
}
}
void TextureCubeMap::resize( const glm::uvec2 &_newSize )
{
if (_newSize.x != (unsigned int)mWidth || _newSize.y != (unsigned int)mHeight) {
SharedTextureData sTexData( new TextureData() );
sTexData->setData (NULL);
sTexData->setWidth (_newSize.x);
sTexData->setHeight(_newSize.y);
sTexData->setFormat(getCompatibleFormat( mInternalFormat ));
sTexData->setType (getCompatibleType( mInternalFormat ));
texImage2DCube( sTexData, GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0 );
texImage2DCube( sTexData, GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0 );
texImage2DCube( sTexData, GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0 );
texImage2DCube( sTexData, GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0 );
texImage2DCube( sTexData, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0 );
texImage2DCube( sTexData, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0 );
}
}
bool TextureCubeMap::cubeSideIsValid( const GLenum _cubeSide ) const
{
if ( _cubeSide == GL_TEXTURE_CUBE_MAP_POSITIVE_X || _cubeSide == GL_TEXTURE_CUBE_MAP_NEGATIVE_X
|| _cubeSide == GL_TEXTURE_CUBE_MAP_POSITIVE_Y || _cubeSide == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
|| _cubeSide == GL_TEXTURE_CUBE_MAP_POSITIVE_Z || _cubeSide == GL_TEXTURE_CUBE_MAP_NEGATIVE_Z ) return true;
return false;
}
void TextureCubeMap::texImage2DCube( const SharedTextureData &_data, GLenum _cubeSide, GLint _mipmapLevel )
{
mWidth = _data->getWidth();
mHeight = _data->getHeight();
bind();
glTexImage2D(
_cubeSide,
_mipmapLevel,
mInternalFormat,
mWidth, mHeight,
0, // no border
_data->getFormat(),
_data->getType(),
_data->getData() );
openGLRareErrorOccured();
}
void TextureCubeMap::texSubImage2DCube( const SharedTextureData &_data, GLenum _cubeSide, GLint _mipmapLevel, glm::ivec2 _offset )
{
bind();
glTexSubImage2D(
_cubeSide,
_mipmapLevel,
_offset.x, _offset.y,
mWidth, mHeight,
_data->getFormat(),
_data->getType(),
_data->getData() );
openGLRareErrorOccured();
}
void TextureBase::texImage2D( const SharedTextureData &_data, GLint _mipmapLevel )
{
mWidth = _data->getWidth();
mHeight = _data->getHeight();
bind();
glTexImage2D(
mTarget,
_mipmapLevel,
mInternalFormat,
mWidth, mHeight,
0, // no border
_data->getFormat(),
_data->getType(),
_data->getData() );
openGLRareErrorOccured();
}
void TextureBase::texSubImage2D( const SharedTextureData &_data, GLint _mipmapLevel, glm::ivec2 _offset )
{
// TODO: test if the size is correct?
bind();
glTexSubImage2D(
mTarget,
_mipmapLevel,
_offset.x, _offset.y,
mWidth, mHeight,
_data->getFormat(),
_data->getType(),
_data->getData() );
openGLRareErrorOccured();
}
void TextureBase::texImage3D( const SharedTextureData &_data, GLint _mipmapLevel )
{
mWidth = _data->getWidth();
mHeight = _data->getHeight();
mDepth = _data->getDepth();
bind();
glTexImage3D(
mTarget,
_mipmapLevel,
mInternalFormat,
mWidth, mHeight, mDepth,
0, // no border
_data->getFormat(),
_data->getType(),
_data->getData() );
openGLRareErrorOccured();
}
void TextureBase::texSubImage3D( const SharedTextureData &_data, GLint _mipmapLevel, glm::ivec3 _offset )
{
bind();
glTexSubImage3D(
mTarget,
_mipmapLevel,
_offset.x, _offset.y, _offset.z,
mWidth, mHeight, mDepth,
_data->getFormat(),
_data->getType(),
_data->getData() );
openGLRareErrorOccured();
}
//////////////////////////////////////////////////////////////////////////
//
......
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