Browse Source

Properly create cube map texture before calling ARB_DSA functions.

It might happen that the user is calling ARB_DSA-only functions like
CubeMapTexture::subImage() the texture was created using glGenTextures()
and not using ARB_DSA, for example because the extension was disabled
and then not bound or used at all, which makes the texture "not created
yet". This is not needed for internal (...ImplementationDSA()) functions
because these are always called only if the texture was also created
using glCreateTextures(). Basically doing the same that's in
AbstractTexture itself but for some reason was omitted here.

The internal ...ImplementationDSA() functions might break in case the
object is created externally using glGen*(), not bound or used at all and
then the class is created using ::wrap(), but that's highly unprobable
(why would anyone do that?).
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
ae70a62644
  1. 4
      src/Magnum/AbstractTexture.h
  2. 16
      src/Magnum/CubeMapTexture.cpp

4
src/Magnum/AbstractTexture.h

@ -350,6 +350,8 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
AbstractTexture& setLabelInternal(Containers::ArrayView<const char> label);
#endif
void MAGNUM_LOCAL createIfNotAlready();
/* Unlike bind() this also sets the texture binding unit as active */
void MAGNUM_LOCAL bindInternal();
@ -429,8 +431,6 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
void MAGNUM_LOCAL createImplementationDSA();
#endif
void MAGNUM_LOCAL createIfNotAlready();
void MAGNUM_LOCAL bindImplementationDefault(GLint textureUnit);
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL bindImplementationMulti(GLint textureUnit);

16
src/Magnum/CubeMapTexture.cpp

@ -57,6 +57,8 @@ Vector2i CubeMapTexture::imageSize(const Int level) {
#ifndef MAGNUM_TARGET_GLES
void CubeMapTexture::image(const Int level, Image3D& image) {
createIfNotAlready();
const Vector3i size{imageSize(level), 6};
const std::size_t dataSize = image.dataSize(size);
char* data = new char[dataSize];
@ -71,6 +73,8 @@ Image3D CubeMapTexture::image(const Int level, Image3D&& image) {
}
void CubeMapTexture::image(const Int level, BufferImage3D& image, const BufferUsage usage) {
createIfNotAlready();
const Vector3i size{imageSize(level), 6};
const std::size_t dataSize = image.dataSize(size);
if(image.size() != size)
@ -86,6 +90,8 @@ BufferImage3D CubeMapTexture::image(const Int level, BufferImage3D&& image, cons
}
void CubeMapTexture::compressedImage(const Int level, CompressedImage3D& image) {
createIfNotAlready();
const Vector3i size{imageSize(level), 6};
GLint dataSize;
(this->*Context::current()->state().texture->getLevelParameterivImplementation)(level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &dataSize);
@ -104,6 +110,8 @@ CompressedImage3D CubeMapTexture::compressedImage(const Int level, CompressedIma
}
void CubeMapTexture::compressedImage(const Int level, CompressedBufferImage3D& image, const BufferUsage usage) {
createIfNotAlready();
const Vector3i size{imageSize(level), 6};
GLint dataSize;
(this->*Context::current()->state().texture->getLevelParameterivImplementation)(level, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &dataSize);
@ -196,24 +204,32 @@ BufferImage3D CubeMapTexture::subImage(const Int level, const Range3Di& range, B
}
CubeMapTexture& CubeMapTexture::setSubImage(const Int level, const Vector3i& offset, const ImageView3D& image) {
createIfNotAlready();
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
glTextureSubImage3D(_id, level, offset.x(), offset.y(), offset.z(), image.size().x(), image.size().y(), image.size().z(), GLenum(image.format()), GLenum(image.type()), image.data());
return *this;
}
CubeMapTexture& CubeMapTexture::setSubImage(const Int level, const Vector3i& offset, BufferImage3D& image) {
createIfNotAlready();
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
glTextureSubImage3D(_id, level, offset.x(), offset.y(), offset.z(), image.size().x(), image.size().y(), image.size().z(), GLenum(image.format()), GLenum(image.type()), nullptr);
return *this;
}
CubeMapTexture& CubeMapTexture::setCompressedSubImage(const Int level, const Vector3i& offset, const CompressedImageView3D& image) {
createIfNotAlready();
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
glCompressedTextureSubImage3D(_id, level, offset.x(), offset.y(), offset.z(), image.size().x(), image.size().y(), image.size().z(), GLenum(image.format()), image.data().size(), image.data());
return *this;
}
CubeMapTexture& CubeMapTexture::setCompressedSubImage(const Int level, const Vector3i& offset, CompressedBufferImage3D& image) {
createIfNotAlready();
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
glCompressedTextureSubImage3D(_id, level, offset.x(), offset.y(), offset.z(), image.size().x(), image.size().y(), image.size().z(), GLenum(image.format()), image.dataSize(), nullptr);
return *this;

Loading…
Cancel
Save