Browse Source

Pixel storage support, part 10: actually use the parameters now.

Pain and misery. Majority of functionality for 3D compressed images now
suddenly fails the test -- this is either very vaguely specified or I am
very bad at understanding things or there are bugs in my NVidia drivers.

This was awful feature. Kill me now.
pull/107/head
Vladimír Vondruš 11 years ago
parent
commit
3067bbcf7e
  1. 2
      doc/opengl-mapping.dox
  2. 7
      doc/opengl-support.dox
  3. 8
      src/Magnum/AbstractFramebuffer.cpp
  4. 146
      src/Magnum/AbstractTexture.cpp
  5. 19
      src/Magnum/AbstractTexture.h
  6. 50
      src/Magnum/CubeMapTexture.cpp
  7. 15
      src/Magnum/CubeMapTexture.h
  8. 8
      src/Magnum/Implementation/TextureState.h
  9. 1
      src/Magnum/Test/CMakeLists.txt
  10. 109
      src/Magnum/Test/CubeMapTextureArrayGLTest.cpp
  11. 147
      src/Magnum/Test/CubeMapTextureGLTest.cpp
  12. 18
      src/Magnum/Test/FramebufferGLTest.cpp
  13. 48
      src/Magnum/Test/RectangleTextureGLTest.cpp
  14. 149
      src/Magnum/Test/TextureArrayGLTest.cpp
  15. 252
      src/Magnum/Test/TextureGLTest.cpp
  16. 19
      src/Magnum/Texture.h
  17. 6
      src/Magnum/TextureArray.h

2
doc/opengl-mapping.dox

@ -281,7 +281,7 @@ OpenGL function | Matching API
--------------------------------------- | ------------
@fn_gl{PatchParameter} | |
@fn_gl{PauseTransformFeedback}, @fn_gl{ResumeTransformFeedback} | @ref TransformFeedback::pause(), @ref TransformFeedback::resume()
@fn_gl{PixelStore} | |
@fn_gl{PixelStore} | @ref Texture::setImage(), \n @ref TextureArray::setImage(), \n @ref CubeMapTexture::setImage(), \n @ref CubeMapTextureArray::setImage(), \n @ref RectangleTexture::setImage(), \n @ref Texture::setSubImage(), \n @ref TextureArray::setSubImage(), \n @ref CubeMapTexture::setSubImage(), \n @ref CubeMapTextureArray::setSubImage(), \n @ref RectangleTexture::setSubImage(), \n @ref Texture::image(), @ref TextureArray::image(), \n @ref CubeMapTexture::image(), \n @ref CubeMapTextureArray::image(), \n @ref RectangleTexture::image(), \n @ref Texture::subImage(), \n @ref TextureArray::subImage(), \n @ref CubeMapTexture::subImage(), \n @ref CubeMapTextureArray::subImage(), \n @ref RectangleTexture::subImage(), \n @ref Texture::setCompressedImage(), \n @ref TextureArray::setCompressedImage(), \n @ref CubeMapTexture::setCompressedImage(), \n @ref CubeMapTextureArray::setCompressedImage(), \n @ref Texture::setCompressedSubImage(), \n @ref TextureArray::setCompressedSubImage(), \n @ref CubeMapTexture::setCompressedSubImage(), \n @ref CubeMapTextureArray::setCompressedSubImage(), \n @ref RectangleTexture::setCompressedSubImage(), \n @ref Texture::compressedImage(), \n @ref TextureArray::compressedImage(), \n @ref CubeMapTexture::compressedImage(), \n @ref CubeMapTextureArray::compressedImage(), \n @ref RectangleTexture::compressedImage(), \n @ref DefaultFramebuffer::read(), \n @ref Framebuffer::read()
@fn_gl{PointParameter} | |
@fn_gl{PointSize} | @ref Renderer::setPointSize()
@fn_gl{PolygonMode} | @ref Renderer::setPolygonMode()

7
doc/opengl-support.dox

@ -39,7 +39,6 @@ listed below in @ref opengl-unsupported-features.
The core subset of OpenGL 2.1 should be fully implemented, except for the
following:
- Pixel store state (@fn_gl{PixelStore} function)
- Proxy textures
- Copying framebuffer to texture (@fn_gl{CopyTexImage2D} etc.)
- Some forgotten limit queries
@ -157,7 +156,7 @@ GLSL 4.20 | done
@extension{ARB,base_instance} | done
@extension{ARB,shading_language_420pack} | done (shading language only)
@extension{ARB,transform_feedback_instanced} | |
@extension{ARB,compressed_texture_pixel_storage} | |
@extension{ARB,compressed_texture_pixel_storage} | done
@extension{ARB,conservative_depth} | done (shading language only)
@extension{ARB,internalformat_query} | |
@extension{ARB,map_buffer_alignment} | done
@ -301,7 +300,7 @@ Extension | Status
@es_extension{EXT,discard_framebuffer} | done
@es_extension2{EXT,blend_minmax,blend_minmax} | done
@es_extension{EXT,shader_texture_lod} | done (shading language only)
@es_extension{EXT,unpack_subimage} | |
@es_extension{EXT,unpack_subimage} | done
@es_extension{EXT,occlusion_query_boolean} | done
@es_extension{EXT,shadow_samplers} | done
@es_extension{EXT,texture_rg} | done
@ -314,7 +313,7 @@ Extension | Status
@es_extension{NV,draw_buffers} | done
@es_extension{NV,fbo_color_attachments} | done
@es_extension{NV,read_buffer} | done
@es_extension{NV,pack_subimage} | |
@es_extension{NV,pack_subimage} | done
@es_extension{NV,draw_instanced} | done
@es_extension{NV,framebuffer_blit} | done
@es_extension{NV,framebuffer_multisample} | done

8
src/Magnum/AbstractFramebuffer.cpp

@ -290,7 +290,12 @@ void AbstractFramebuffer::read(const Range2Di& rectangle, Image2D& image) {
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
#endif
(Context::current()->state().framebuffer->readImplementation)(rectangle, image.format(), image.type(), data.size(), data);
image.storage().applyPack();
(Context::current()->state().framebuffer->readImplementation)(rectangle, image.format(), image.type(), data.size(), data
#ifdef MAGNUM_TARGET_GLES2
+ Implementation::pixelStorageSkipOffsetFor(image, rectangle.size())
#endif
);
image.setData(image.storage(), image.format(), image.type(), rectangle.size(), std::move(data));
}
@ -311,6 +316,7 @@ void AbstractFramebuffer::read(const Range2Di& rectangle, BufferImage2D& image,
image.setData(image.storage(), image.format(), image.type(), rectangle.size(), nullptr, usage);
image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
(Context::current()->state().framebuffer->readImplementation)(rectangle, image.format(), image.type(), dataSize, nullptr);
}

146
src/Magnum/AbstractTexture.cpp

@ -1363,17 +1363,17 @@ void AbstractTexture::subImageImplementationDefault(GLint level, const Math::Vec
glTexSubImage1D(_target, level, offset[0], size[0], GLenum(format), GLenum(type), data);
}
void AbstractTexture::compressedSubImageImplementationDefault(const GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
void AbstractTexture::compressedSubImageImplementationDefault(const GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
bindInternal();
glCompressedTexSubImage1D(_target, level, offset[0], size[0], GLenum(format), data.size(), data);
glCompressedTexSubImage1D(_target, level, offset[0], size[0], GLenum(format), dataSize, data);
}
void AbstractTexture::subImageImplementationDSA(const GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, const PixelFormat format, const PixelType type, const GLvoid* const data) {
glTextureSubImage1D(_id, level, offset[0], size[0], GLenum(format), GLenum(type), data);
}
void AbstractTexture::compressedSubImageImplementationDSA(const GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
glCompressedTextureSubImage1D(_id, level, offset[0], size[0], GLenum(format), data.size(), data);
void AbstractTexture::compressedSubImageImplementationDSA(const GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
glCompressedTextureSubImage1D(_id, level, offset[0], size[0], GLenum(format), dataSize, data);
}
void AbstractTexture::subImageImplementationDSAEXT(GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, PixelFormat format, PixelType type, const GLvoid* data) {
@ -1381,9 +1381,9 @@ void AbstractTexture::subImageImplementationDSAEXT(GLint level, const Math::Vect
glTextureSubImage1DEXT(_id, _target, level, offset[0], size[0], GLenum(format), GLenum(type), data);
}
void AbstractTexture::compressedSubImageImplementationDSAEXT(const GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
void AbstractTexture::compressedSubImageImplementationDSAEXT(const GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
_flags |= ObjectFlag::Created;
glCompressedTextureSubImage1DEXT(_id, _target, level, offset[0], size[0], GLenum(format), data.size(), data);
glCompressedTextureSubImage1DEXT(_id, _target, level, offset[0], size[0], GLenum(format), dataSize, data);
}
#endif
@ -1392,9 +1392,9 @@ void AbstractTexture::subImageImplementationDefault(GLint level, const Vector2i&
glTexSubImage2D(_target, level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), GLenum(type), data);
}
void AbstractTexture::compressedSubImageImplementationDefault(const GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
void AbstractTexture::compressedSubImageImplementationDefault(const GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
bindInternal();
glCompressedTexSubImage2D(_target, level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), data.size(), data);
glCompressedTexSubImage2D(_target, level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), dataSize, data);
}
#ifndef MAGNUM_TARGET_GLES
@ -1402,8 +1402,8 @@ void AbstractTexture::subImageImplementationDSA(const GLint level, const Vector2
glTextureSubImage2D(_id, level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), GLenum(type), data);
}
void AbstractTexture::compressedSubImageImplementationDSA(const GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
glCompressedTextureSubImage2D(_id, level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), data.size(), data);
void AbstractTexture::compressedSubImageImplementationDSA(const GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
glCompressedTextureSubImage2D(_id, level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), dataSize, data);
}
void AbstractTexture::subImageImplementationDSAEXT(GLint level, const Vector2i& offset, const Vector2i& size, PixelFormat format, PixelType type, const GLvoid* data) {
@ -1411,9 +1411,9 @@ void AbstractTexture::subImageImplementationDSAEXT(GLint level, const Vector2i&
glTextureSubImage2DEXT(_id, _target, level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), GLenum(type), data);
}
void AbstractTexture::compressedSubImageImplementationDSAEXT(GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, Corrade::Containers::ArrayView< const GLvoid > data) {
void AbstractTexture::compressedSubImageImplementationDSAEXT(GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
_flags |= ObjectFlag::Created;
glCompressedTextureSubImage2DEXT(_id, _target, level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), data.size(), data);
glCompressedTextureSubImage2DEXT(_id, _target, level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), dataSize, data);
}
#endif
@ -1435,12 +1435,12 @@ void AbstractTexture::subImageImplementationDefault(GLint level, const Vector3i&
#endif
}
void AbstractTexture::compressedSubImageImplementationDefault(const GLint level, const Vector3i& offset, const Vector3i& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
void AbstractTexture::compressedSubImageImplementationDefault(const GLint level, const Vector3i& offset, const Vector3i& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
bindInternal();
#ifndef MAGNUM_TARGET_GLES2
glCompressedTexSubImage3D(_target, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), GLenum(format), data.size(), data);
glCompressedTexSubImage3D(_target, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), GLenum(format), dataSize, data);
#elif !defined(CORRADE_TARGET_NACL)
glCompressedTexSubImage3DOES(_target, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), GLenum(format), data.size(), data);
glCompressedTexSubImage3DOES(_target, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), GLenum(format), dataSize, data);
#else
static_cast<void>(level);
static_cast<void>(offset);
@ -1457,8 +1457,8 @@ void AbstractTexture::subImageImplementationDSA(const GLint level, const Vector3
glTextureSubImage3D(_id, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), GLenum(format), GLenum(type), data);
}
void AbstractTexture::compressedSubImageImplementationDSA(const GLint level, const Vector3i& offset, const Vector3i& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
glCompressedTextureSubImage3D(_id, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), GLenum(format), data.size(), data);
void AbstractTexture::compressedSubImageImplementationDSA(const GLint level, const Vector3i& offset, const Vector3i& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
glCompressedTextureSubImage3D(_id, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), GLenum(format), dataSize, data);
}
void AbstractTexture::subImageImplementationDSAEXT(GLint level, const Vector3i& offset, const Vector3i& size, PixelFormat format, PixelType type, const GLvoid* data) {
@ -1466,9 +1466,9 @@ void AbstractTexture::subImageImplementationDSAEXT(GLint level, const Vector3i&
glTextureSubImage3DEXT(_id, _target, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), GLenum(format), GLenum(type), data);
}
void AbstractTexture::compressedSubImageImplementationDSAEXT(const GLint level, const Vector3i& offset, const Vector3i& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
void AbstractTexture::compressedSubImageImplementationDSAEXT(const GLint level, const Vector3i& offset, const Vector3i& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
_flags |= ObjectFlag::Created;
glCompressedTextureSubImage3DEXT(_id, _target, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), GLenum(format), data.size(), data);
glCompressedTextureSubImage3DEXT(_id, _target, level, offset.x(), offset.y(), offset.z(), size.x(), size.y(), size.z(), GLenum(format), dataSize, data);
}
#endif
@ -1502,6 +1502,7 @@ template<UnsignedInt dimensions> void AbstractTexture::image(GLint level, Image<
data = Containers::Array<char>{dataSize};
Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
(this->*Context::current()->state().texture->getImageImplementation)(level, image.format(), image.type(), data.size(), data);
image.setData(image.storage(), image.format(), image.type(), size, std::move(data));
}
@ -1521,6 +1522,7 @@ template<UnsignedInt dimensions> void AbstractTexture::image(GLint level, Buffer
image.setData(image.storage(), image.format(), image.type(), size, nullptr, usage);
image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
(this->*Context::current()->state().texture->getImageImplementation)(level, image.format(), image.type(), dataSize, nullptr);
}
@ -1542,6 +1544,7 @@ template<UnsignedInt dimensions> void AbstractTexture::compressedImage(const GLi
data = Containers::Array<char>{dataSize};
Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
(this->*Context::current()->state().texture->getCompressedImageImplementation)(level, data.size(), data);
image.setData(image.storage(), CompressedPixelFormat(format), size, std::move(data));
}
@ -1565,6 +1568,7 @@ template<UnsignedInt dimensions> void AbstractTexture::compressedImage(const GLi
image.setData(image.storage(), CompressedPixelFormat(format), size, nullptr, usage);
image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
(this->*Context::current()->state().texture->getCompressedImageImplementation)(level, dataSize, nullptr);
}
@ -1586,6 +1590,7 @@ template<UnsignedInt dimensions> void AbstractTexture::subImage(const GLint leve
data = Containers::Array<char>{dataSize};
Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
glGetTextureSubImage(_id, level, paddedOffset.x(), paddedOffset.y(), paddedOffset.z(), paddedSize.x(), paddedSize.y(), paddedSize.z(), GLenum(image.format()), GLenum(image.type()), data.size(), data);
image.setData(image.storage(), image.format(), image.type(), size, std::move(data));
}
@ -1609,6 +1614,7 @@ template<UnsignedInt dimensions> void AbstractTexture::subImage(const GLint leve
image.setData(image.storage(), image.format(), image.type(), size, nullptr, usage);
image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
glGetTextureSubImage(_id, level, paddedOffset.x(), paddedOffset.y(), paddedOffset.z(), paddedSize.x(), paddedSize.y(), paddedSize.z(), GLenum(image.format()), GLenum(image.type()), dataSize, nullptr);
}
@ -1677,46 +1683,54 @@ void AbstractTexture::DataHelper<3>::setStorageMultisample(AbstractTexture& text
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::DataHelper<1>::setImage(AbstractTexture& texture, const GLint level, const TextureFormat internalFormat, const ImageView1D& image) {
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
texture.bindInternal();
glTexImage1D(texture._target, level, GLint(internalFormat), image.size()[0], 0, GLenum(image.format()), GLenum(image.type()), image.data());
}
void AbstractTexture::DataHelper<1>::setCompressedImage(AbstractTexture& texture, const GLint level, const CompressedImageView1D& image) {
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
texture.bindInternal();
glCompressedTexImage1D(texture._target, level, GLenum(image.format()), image.size()[0], 0, image.data().size(), image.data());
glCompressedTexImage1D(texture._target, level, GLenum(image.format()), image.size()[0], 0, Implementation::occupiedCompressedImageDataSize(image, image.data().size()), image.data());
}
void AbstractTexture::DataHelper<1>::setImage(AbstractTexture& texture, const GLint level, const TextureFormat internalFormat, BufferImage1D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
texture.bindInternal();
glTexImage1D(texture._target, level, GLint(internalFormat), image.size()[0], 0, GLenum(image.format()), GLenum(image.type()), nullptr);
}
void AbstractTexture::DataHelper<1>::setCompressedImage(AbstractTexture& texture, const GLint level, CompressedBufferImage1D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
texture.bindInternal();
glCompressedTexImage1D(texture._target, level, GLenum(image.format()), image.size()[0], 0, image.dataSize(), nullptr);
glCompressedTexImage1D(texture._target, level, GLenum(image.format()), image.size()[0], 0, Implementation::occupiedCompressedImageDataSize(image, image.dataSize()), nullptr);
}
void AbstractTexture::DataHelper<1>::setSubImage(AbstractTexture& texture, const GLint level, const Math::Vector<1, GLint>& offset, const ImageView1D& image) {
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
(texture.*Context::current()->state().texture->subImage1DImplementation)(level, offset, image.size(), image.format(), image.type(), image.data());
}
void AbstractTexture::DataHelper<1>::setCompressedSubImage(AbstractTexture& texture, const GLint level, const Math::Vector<1, GLint>& offset, const CompressedImageView1D& image) {
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
(texture.*Context::current()->state().texture->compressedSubImage1DImplementation)(level, offset, image.size(), image.format(), image.data());
image.storage().applyUnpack();
(texture.*Context::current()->state().texture->compressedSubImage1DImplementation)(level, offset, image.size(), image.format(), image.data(), Implementation::occupiedCompressedImageDataSize(image, image.data().size()));
}
void AbstractTexture::DataHelper<1>::setSubImage(AbstractTexture& texture, const GLint level, const Math::Vector<1, GLint>& offset, BufferImage1D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
(texture.*Context::current()->state().texture->subImage1DImplementation)(level, offset, image.size(), image.format(), image.type(), nullptr);
}
void AbstractTexture::DataHelper<1>::setCompressedSubImage(AbstractTexture& texture, const GLint level, const Math::Vector<1, GLint>& offset, CompressedBufferImage1D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
(texture.*Context::current()->state().texture->compressedSubImage1DImplementation)(level, offset, image.size(), image.format(), {nullptr, image.dataSize()});
image.storage().applyUnpack();
(texture.*Context::current()->state().texture->compressedSubImage1DImplementation)(level, offset, image.size(), image.format(), nullptr, Implementation::occupiedCompressedImageDataSize(image, image.dataSize()));
}
#endif
@ -1724,29 +1738,45 @@ void AbstractTexture::DataHelper<2>::setImage(AbstractTexture& texture, const GL
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
#endif
image.storage().applyUnpack();
texture.bindInternal();
glTexImage2D(target, level, GLint(internalFormat), image.size().x(), image.size().y(), 0, GLenum(image.format()), GLenum(image.type()), image.data());
glTexImage2D(target, level, GLint(internalFormat), image.size().x(), image.size().y(), 0, GLenum(image.format()), GLenum(image.type()), image.data()
#ifdef MAGNUM_TARGET_GLES2
+ Implementation::pixelStorageSkipOffset(image)
#endif
);
}
void AbstractTexture::DataHelper<2>::setCompressedImage(AbstractTexture& texture, const GLenum target, const GLint level, const CompressedImageView2D& image) {
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
#endif
#ifndef MAGNUM_TARGET_GLES
/* Pixel storage is completely ignored for compressed images on ES, no need
to reset anything */
image.storage().applyUnpack();
#endif
texture.bindInternal();
glCompressedTexImage2D(target, level, GLenum(image.format()), image.size().x(), image.size().y(), 0, image.data().size(), image.data());
glCompressedTexImage2D(target, level, GLenum(image.format()), image.size().x(), image.size().y(), 0, Implementation::occupiedCompressedImageDataSize(image, image.data().size()), image.data());
}
#ifndef MAGNUM_TARGET_GLES2
void AbstractTexture::DataHelper<2>::setImage(AbstractTexture& texture, const GLenum target, const GLint level, const TextureFormat internalFormat, BufferImage2D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
texture.bindInternal();
glTexImage2D(target, level, GLint(internalFormat), image.size().x(), image.size().y(), 0, GLenum(image.format()), GLenum(image.type()), nullptr);
}
void AbstractTexture::DataHelper<2>::setCompressedImage(AbstractTexture& texture, const GLenum target, const GLint level, CompressedBufferImage2D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
#ifndef MAGNUM_TARGET_GLES
/* Pixel storage is completely ignored for compressed images on ES, no need
to reset anything */
image.storage().applyUnpack();
#endif
texture.bindInternal();
glCompressedTexImage2D(target, level, GLenum(image.format()), image.size().x(), image.size().y(), 0, image.dataSize(), nullptr);
glCompressedTexImage2D(target, level, GLenum(image.format()), image.size().x(), image.size().y(), 0, Implementation::occupiedCompressedImageDataSize(image, image.dataSize()), nullptr);
}
#endif
@ -1754,25 +1784,41 @@ void AbstractTexture::DataHelper<2>::setSubImage(AbstractTexture& texture, const
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
#endif
(texture.*Context::current()->state().texture->subImage2DImplementation)(level, offset, image.size(), image.format(), image.type(), image.data());
image.storage().applyUnpack();
(texture.*Context::current()->state().texture->subImage2DImplementation)(level, offset, image.size(), image.format(), image.type(), image.data()
#ifdef MAGNUM_TARGET_GLES2
+ Implementation::pixelStorageSkipOffset(image)
#endif
);
}
void AbstractTexture::DataHelper<2>::setCompressedSubImage(AbstractTexture& texture, const GLint level, const Vector2i& offset, const CompressedImageView2D& image) {
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
#endif
(texture.*Context::current()->state().texture->compressedSubImage2DImplementation)(level, offset, image.size(), image.format(), image.data());
#ifndef MAGNUM_TARGET_GLES
/* Pixel storage is completely ignored for compressed images on ES, no need
to reset anything */
image.storage().applyUnpack();
#endif
(texture.*Context::current()->state().texture->compressedSubImage2DImplementation)(level, offset, image.size(), image.format(), image.data(), Implementation::occupiedCompressedImageDataSize(image, image.data().size()));
}
#ifndef MAGNUM_TARGET_GLES2
void AbstractTexture::DataHelper<2>::setSubImage(AbstractTexture& texture, const GLint level, const Vector2i& offset, BufferImage2D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
(texture.*Context::current()->state().texture->subImage2DImplementation)(level, offset, image.size(), image.format(), image.type(), nullptr);
}
void AbstractTexture::DataHelper<2>::setCompressedSubImage(AbstractTexture& texture, const GLint level, const Vector2i& offset, CompressedBufferImage2D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
(texture.*Context::current()->state().texture->compressedSubImage2DImplementation)(level, offset, image.size(), image.format(), {nullptr, image.dataSize()});
#ifndef MAGNUM_TARGET_GLES
/* Pixel storage is completely ignored for compressed images on ES, no need
to reset anything */
image.storage().applyUnpack();
#endif
(texture.*Context::current()->state().texture->compressedSubImage2DImplementation)(level, offset, image.size(), image.format(), nullptr, Implementation::occupiedCompressedImageDataSize(image, image.dataSize()));
}
#endif
@ -1781,11 +1827,12 @@ void AbstractTexture::DataHelper<3>::setImage(AbstractTexture& texture, const GL
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
#endif
image.storage().applyUnpack();
texture.bindInternal();
#ifndef MAGNUM_TARGET_GLES2
glTexImage3D(texture._target, level, GLint(internalFormat), image.size().x(), image.size().y(), image.size().z(), 0, GLenum(image.format()), GLenum(image.type()), image.data());
#elif !defined(CORRADE_TARGET_NACL)
glTexImage3DOES(texture._target, level, GLint(internalFormat), image.size().x(), image.size().y(), image.size().z(), 0, GLenum(image.format()), GLenum(image.type()), image.data());
glTexImage3DOES(texture._target, level, GLint(internalFormat), image.size().x(), image.size().y(), image.size().z(), 0, GLenum(image.format()), GLenum(image.type()), image.data() + Implementation::pixelStorageSkipOffset(image));
#else
static_cast<void>(level);
static_cast<void>(internalFormat);
@ -1798,11 +1845,16 @@ void AbstractTexture::DataHelper<3>::setCompressedImage(AbstractTexture& texture
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
#endif
#ifndef MAGNUM_TARGET_GLES
/* Pixel storage is completely ignored for compressed images on ES, no need
to reset anything */
image.storage().applyUnpack();
#endif
texture.bindInternal();
#ifndef MAGNUM_TARGET_GLES2
glCompressedTexImage3D(texture._target, level, GLenum(image.format()), image.size().x(), image.size().y(), image.size().z(), 0, image.data().size(), image.data());
glCompressedTexImage3D(texture._target, level, GLenum(image.format()), image.size().x(), image.size().y(), image.size().z(), 0, Implementation::occupiedCompressedImageDataSize(image, image.data().size()), image.data());
#elif !defined(CORRADE_TARGET_NACL)
glCompressedTexImage3DOES(texture._target, level, GLenum(image.format()), image.size().x(), image.size().y(), image.size().z(), 0, image.data().size(), image.data());
glCompressedTexImage3DOES(texture._target, level, GLenum(image.format()), image.size().x(), image.size().y(), image.size().z(), 0, Implementation::occupiedCompressedImageDataSize(image, image.data().size()), image.data());
#else
static_cast<void>(level);
static_cast<void>(image);
@ -1814,14 +1866,20 @@ void AbstractTexture::DataHelper<3>::setCompressedImage(AbstractTexture& texture
#ifndef MAGNUM_TARGET_GLES2
void AbstractTexture::DataHelper<3>::setImage(AbstractTexture& texture, const GLint level, const TextureFormat internalFormat, BufferImage3D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
texture.bindInternal();
glTexImage3D(texture._target, level, GLint(internalFormat), image.size().x(), image.size().y(), image.size().z(), 0, GLenum(image.format()), GLenum(image.type()), nullptr);
}
void AbstractTexture::DataHelper<3>::setCompressedImage(AbstractTexture& texture, const GLint level, CompressedBufferImage3D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
#ifndef MAGNUM_TARGET_GLES
/* Pixel storage is completely ignored for compressed images on ES, no need
to reset anything */
image.storage().applyUnpack();
#endif
texture.bindInternal();
glCompressedTexImage3D(texture._target, level, GLenum(image.format()), image.size().x(), image.size().y(), image.size().z(), 0, image.dataSize(), nullptr);
glCompressedTexImage3D(texture._target, level, GLenum(image.format()), image.size().x(), image.size().y(), image.size().z(), 0, Implementation::occupiedCompressedImageDataSize(image, image.dataSize()), nullptr);
}
#endif
@ -1830,26 +1888,42 @@ void AbstractTexture::DataHelper<3>::setSubImage(AbstractTexture& texture, const
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
#endif
(texture.*Context::current()->state().texture->subImage3DImplementation)(level, offset, image.size(), image.format(), image.type(), image.data());
image.storage().applyUnpack();
(texture.*Context::current()->state().texture->subImage3DImplementation)(level, offset, image.size(), image.format(), image.type(), image.data()
#ifdef MAGNUM_TARGET_GLES2
+ Implementation::pixelStorageSkipOffset(image)
#endif
);
}
void AbstractTexture::DataHelper<3>::setCompressedSubImage(AbstractTexture& texture, const GLint level, const Vector3i& offset, const CompressedImageView3D& image) {
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
#endif
(texture.*Context::current()->state().texture->compressedSubImage3DImplementation)(level, offset, image.size(), image.format(), image.data());
#ifndef MAGNUM_TARGET_GLES
/* Pixel storage is completely ignored for compressed images on ES, no need
to reset anything */
image.storage().applyUnpack();
#endif
(texture.*Context::current()->state().texture->compressedSubImage3DImplementation)(level, offset, image.size(), image.format(), image.data(), Implementation::occupiedCompressedImageDataSize(image, image.data().size()));
}
#endif
#ifndef MAGNUM_TARGET_GLES2
void AbstractTexture::DataHelper<3>::setSubImage(AbstractTexture& texture, const GLint level, const Vector3i& offset, BufferImage3D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
(texture.*Context::current()->state().texture->subImage3DImplementation)(level, offset, image.size(), image.format(), image.type(), nullptr);
}
void AbstractTexture::DataHelper<3>::setCompressedSubImage(AbstractTexture& texture, const GLint level, const Vector3i& offset, CompressedBufferImage3D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
(texture.*Context::current()->state().texture->compressedSubImage3DImplementation)(level, offset, image.size(), image.format(), {nullptr, image.dataSize()});
#ifndef MAGNUM_TARGET_GLES
/* Pixel storage is completely ignored for compressed images on ES, no need
to reset anything */
image.storage().applyUnpack();
#endif
(texture.*Context::current()->state().texture->compressedSubImage3DImplementation)(level, offset, image.size(), image.format(), nullptr, Implementation::occupiedCompressedImageDataSize(image, image.dataSize()));
}
#endif

19
src/Magnum/AbstractTexture.h

@ -127,7 +127,6 @@ in order to preserve the data. If running on OpenGL ES or extension
functions do nothing.
@todo all texture [level] parameters, global texture parameters
@todo Add glPixelStore encapsulation
@todo Texture copying
@todo `GL_MAX_SAMPLE_MASK_WORDS` when @extension{ARB,texture_multisample} is done
@todo Query for immutable levels (@extension{ARB,ES3_compatibility})
@ -538,29 +537,29 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
void MAGNUM_LOCAL subImageImplementationDSA(GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, PixelFormat format, PixelType type, const GLvoid* data);
void MAGNUM_LOCAL subImageImplementationDSAEXT(GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, PixelFormat format, PixelType type, const GLvoid* data);
void MAGNUM_LOCAL compressedSubImageImplementationDefault(GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDSA(GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDSAEXT(GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDefault(GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
void MAGNUM_LOCAL compressedSubImageImplementationDSA(GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
void MAGNUM_LOCAL compressedSubImageImplementationDSAEXT(GLint level, const Math::Vector<1, GLint>& offset, const Math::Vector<1, GLsizei>& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
#endif
void MAGNUM_LOCAL subImageImplementationDefault(GLint level, const Vector2i& offset, const Vector2i& size, PixelFormat format, PixelType type, const GLvoid* data);
void MAGNUM_LOCAL compressedSubImageImplementationDefault(GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDefault(GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL subImageImplementationDSA(GLint level, const Vector2i& offset, const Vector2i& size, PixelFormat format, PixelType type, const GLvoid* data);
void MAGNUM_LOCAL subImageImplementationDSAEXT(GLint level, const Vector2i& offset, const Vector2i& size, PixelFormat format, PixelType type, const GLvoid* data);
void MAGNUM_LOCAL compressedSubImageImplementationDSA(GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDSAEXT(GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDSA(GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
void MAGNUM_LOCAL compressedSubImageImplementationDSAEXT(GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
#endif
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void MAGNUM_LOCAL subImageImplementationDefault(GLint level, const Vector3i& offset, const Vector3i& size, PixelFormat format, PixelType type, const GLvoid* data);
void MAGNUM_LOCAL compressedSubImageImplementationDefault(GLint level, const Vector3i& offset, const Vector3i& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDefault(GLint level, const Vector3i& offset, const Vector3i& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
#endif
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL subImageImplementationDSA(GLint level, const Vector3i& offset, const Vector3i& size, PixelFormat format, PixelType type, const GLvoid* data);
void MAGNUM_LOCAL subImageImplementationDSAEXT(GLint level, const Vector3i& offset, const Vector3i& size, PixelFormat format, PixelType type, const GLvoid* data);
void MAGNUM_LOCAL compressedSubImageImplementationDSA(GLint level, const Vector3i& offset, const Vector3i& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDSAEXT(GLint level, const Vector3i& offset, const Vector3i& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDSA(GLint level, const Vector3i& offset, const Vector3i& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
void MAGNUM_LOCAL compressedSubImageImplementationDSAEXT(GLint level, const Vector3i& offset, const Vector3i& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
#endif
void MAGNUM_LOCAL invalidateImageImplementationNoOp(GLint level);

50
src/Magnum/CubeMapTexture.cpp

@ -68,6 +68,7 @@ void CubeMapTexture::image(const Int level, Image3D& image) {
data = Containers::Array<char>{dataSize};
Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
glGetTextureImage(_id, level, GLenum(image.format()), GLenum(image.type()), data.size(), data);
image.setData(image.storage(), image.format(), image.type(), size, std::move(data));
}
@ -90,6 +91,7 @@ void CubeMapTexture::image(const Int level, BufferImage3D& image, const BufferUs
image.setData(image.storage(), image.format(), image.type(), size, nullptr, usage);
image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
glGetTextureImage(_id, level, GLenum(image.format()), GLenum(image.type()), dataSize, nullptr);
}
@ -114,6 +116,7 @@ void CubeMapTexture::compressedImage(const Int level, CompressedImage3D& image)
data = Containers::Array<char>{dataSize};
Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
glGetCompressedTextureImage(_id, level, data.size(), data);
image.setData(image.storage(), CompressedPixelFormat(format), size, std::move(data));
}
@ -140,6 +143,7 @@ void CubeMapTexture::compressedImage(const Int level, CompressedBufferImage3D& i
image.setData(image.storage(), CompressedPixelFormat(format), size, nullptr, usage);
image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
glGetCompressedTextureImage(_id, level, dataSize, nullptr);
}
@ -158,6 +162,7 @@ void CubeMapTexture::image(const Coordinate coordinate, const Int level, Image2D
data = Containers::Array<char>{dataSize};
Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
(this->*Context::current()->state().texture->getCubeImageImplementation)(coordinate, level, size, image.format(), image.type(), data.size(), data);
image.setData(image.storage(), image.format(), image.type(), size, std::move(data));
}
@ -178,6 +183,7 @@ void CubeMapTexture::image(const Coordinate coordinate, const Int level, BufferI
image.setData(image.storage(), image.format(), image.type(), size, nullptr, usage);
image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
(this->*Context::current()->state().texture->getCubeImageImplementation)(coordinate, level, size, image.format(), image.type(), dataSize, nullptr);
}
@ -200,6 +206,7 @@ void CubeMapTexture::compressedImage(const Coordinate coordinate, const Int leve
data = Containers::Array<char>{dataSize};
Buffer::unbindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
(this->*Context::current()->state().texture->getCompressedCubeImageImplementation)(coordinate, level, size, data.size(), data);
image.setData(image.storage(), CompressedPixelFormat(format), size, std::move(data));
}
@ -224,6 +231,7 @@ void CubeMapTexture::compressedImage(const Coordinate coordinate, const Int leve
image.setData(image.storage(), CompressedPixelFormat(format), size, nullptr, usage);
image.buffer().bindInternal(Buffer::TargetHint::PixelPack);
image.storage().applyPack();
(this->*Context::current()->state().texture->getCompressedCubeImageImplementation)(coordinate, level, size, dataSize, nullptr);
}
@ -246,6 +254,7 @@ CubeMapTexture& CubeMapTexture::setSubImage(const Int level, const Vector3i& off
createIfNotAlready();
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
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;
}
@ -254,6 +263,7 @@ CubeMapTexture& CubeMapTexture::setSubImage(const Int level, const Vector3i& off
createIfNotAlready();
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
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;
}
@ -262,7 +272,8 @@ CubeMapTexture& CubeMapTexture::setCompressedSubImage(const Int level, const Vec
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());
image.storage().applyUnpack();
glCompressedTextureSubImage3D(_id, level, offset.x(), offset.y(), offset.z(), image.size().x(), image.size().y(), image.size().z(), GLenum(image.format()), Implementation::occupiedCompressedImageDataSize(image, image.data().size()), image.data());
return *this;
}
@ -270,7 +281,8 @@ CubeMapTexture& CubeMapTexture::setCompressedSubImage(const Int level, const Vec
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);
image.storage().applyUnpack();
glCompressedTextureSubImage3D(_id, level, offset.x(), offset.y(), offset.z(), image.size().x(), image.size().y(), image.size().z(), GLenum(image.format()), Implementation::occupiedCompressedImageDataSize(image, image.dataSize()), nullptr);
return *this;
}
#endif
@ -279,13 +291,19 @@ CubeMapTexture& CubeMapTexture::setSubImage(const Coordinate coordinate, const I
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
#endif
(this->*Context::current()->state().texture->cubeSubImageImplementation)(coordinate, level, offset, image.size(), image.format(), image.type(), image.data());
image.storage().applyUnpack();
(this->*Context::current()->state().texture->cubeSubImageImplementation)(coordinate, level, offset, image.size(), image.format(), image.type(), image.data()
#ifdef MAGNUM_TARGET_GLES2
+ Implementation::pixelStorageSkipOffset(image)
#endif
);
return *this;
}
#ifndef MAGNUM_TARGET_GLES2
CubeMapTexture& CubeMapTexture::setSubImage(const Coordinate coordinate, const Int level, const Vector2i& offset, BufferImage2D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
image.storage().applyUnpack();
(this->*Context::current()->state().texture->cubeSubImageImplementation)(coordinate, level, offset, image.size(), image.format(), image.type(), nullptr);
return *this;
}
@ -295,14 +313,24 @@ CubeMapTexture& CubeMapTexture::setCompressedSubImage(const Coordinate coordinat
#ifndef MAGNUM_TARGET_GLES2
Buffer::unbindInternal(Buffer::TargetHint::PixelUnpack);
#endif
(this->*Context::current()->state().texture->cubeCompressedSubImageImplementation)(coordinate, level, offset, image.size(), image.format(), image.data());
#ifndef MAGNUM_TARGET_GLES
/* Pixel storage is completely ignored for compressed images on ES, no need
to reset anything */
image.storage().applyUnpack();
#endif
(this->*Context::current()->state().texture->cubeCompressedSubImageImplementation)(coordinate, level, offset, image.size(), image.format(), image.data(), Implementation::occupiedCompressedImageDataSize(image, image.data().size()));
return *this;
}
#ifndef MAGNUM_TARGET_GLES2
CubeMapTexture& CubeMapTexture::setCompressedSubImage(const Coordinate coordinate, const Int level, const Vector2i& offset, CompressedBufferImage2D& image) {
image.buffer().bindInternal(Buffer::TargetHint::PixelUnpack);
(this->*Context::current()->state().texture->cubeCompressedSubImageImplementation)(coordinate, level, offset, image.size(), image.format(), {nullptr, image.dataSize()});
#ifndef MAGNUM_TARGET_GLES
/* Pixel storage is completely ignored for compressed images on ES, no need
to reset anything */
image.storage().applyUnpack();
#endif
(this->*Context::current()->state().texture->cubeCompressedSubImageImplementation)(coordinate, level, offset, image.size(), image.format(), nullptr, Implementation::occupiedCompressedImageDataSize(image, image.dataSize()));
return *this;
}
#endif
@ -379,9 +407,9 @@ void CubeMapTexture::subImageImplementationDefault(const Coordinate coordinate,
glTexSubImage2D(GLenum(coordinate), level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), GLenum(type), data);
}
void CubeMapTexture::compressedSubImageImplementationDefault(const Coordinate coordinate, const GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
void CubeMapTexture::compressedSubImageImplementationDefault(const Coordinate coordinate, const GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
bindInternal();
glCompressedTexSubImage2D(GLenum(coordinate), level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), data.size(), data);
glCompressedTexSubImage2D(GLenum(coordinate), level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), dataSize, data);
}
#ifndef MAGNUM_TARGET_GLES
@ -389,8 +417,8 @@ void CubeMapTexture::subImageImplementationDSA(const Coordinate coordinate, cons
glTextureSubImage3D(_id, level, offset.x(), offset.y(), GLenum(coordinate) - GL_TEXTURE_CUBE_MAP_POSITIVE_X, size.x(), size.y(), 1, GLenum(format), GLenum(type), data);
}
void CubeMapTexture::compressedSubImageImplementationDSA(const Coordinate coordinate, const GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
glCompressedTextureSubImage3D(_id, level, offset.x(), offset.y(), GLenum(coordinate) - GL_TEXTURE_CUBE_MAP_POSITIVE_X, size.x(), size.y(), 1, GLenum(format), data.size(), data);
void CubeMapTexture::compressedSubImageImplementationDSA(const Coordinate coordinate, const GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
glCompressedTextureSubImage3D(_id, level, offset.x(), offset.y(), GLenum(coordinate) - GL_TEXTURE_CUBE_MAP_POSITIVE_X, size.x(), size.y(), 1, GLenum(format), dataSize, data);
}
void CubeMapTexture::subImageImplementationDSAEXT(const Coordinate coordinate, const GLint level, const Vector2i& offset, const Vector2i& size, const PixelFormat format, const PixelType type, const GLvoid* const data) {
@ -398,9 +426,9 @@ void CubeMapTexture::subImageImplementationDSAEXT(const Coordinate coordinate, c
glTextureSubImage2DEXT(_id, GLenum(coordinate), level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), GLenum(type), data);
}
void CubeMapTexture::compressedSubImageImplementationDSAEXT(const Coordinate coordinate, const GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const Containers::ArrayView<const GLvoid> data) {
void CubeMapTexture::compressedSubImageImplementationDSAEXT(const Coordinate coordinate, const GLint level, const Vector2i& offset, const Vector2i& size, const CompressedPixelFormat format, const GLvoid* const data, const GLsizei dataSize) {
_flags |= ObjectFlag::Created;
glTextureSubImage2DEXT(_id, GLenum(coordinate), level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), data.size(), data);
glTextureSubImage2DEXT(_id, GLenum(coordinate), level, offset.x(), offset.y(), size.x(), size.y(), GLenum(format), dataSize, data);
}
#endif

15
src/Magnum/CubeMapTexture.h

@ -446,7 +446,7 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture {
* The operation is protected from buffer overflow.
* @see @fn_gl2{GetTextureLevelParameter,GetTexLevelParameter} with
* @def_gl{TEXTURE_WIDTH}, @def_gl{TEXTURE_HEIGHT}, then
* @fn_gl2{GetTextureImage,GetTexImage}
* @fn_gl{PixelStore}, then @fn_gl2{GetTextureImage,GetTexImage}
* @requires_gl45 Extension @extension{ARB,direct_state_access}
* @requires_gl Texture image queries are not available in OpenGL ES or
* WebGL. See @ref Framebuffer::read() for possible workaround.
@ -551,8 +551,8 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture {
* @fn_gl_extension{GetTextureLevelParameter,EXT,direct_state_access},
* eventually @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and
* @fn_gl{GetTexLevelParameter} with @def_gl{TEXTURE_WIDTH},
* @def_gl{TEXTURE_HEIGHT}, then @fn_gl{GetTextureSubImage},
* @fn_gl_extension{GetnTexImage,ARB,robustness},
* @def_gl{TEXTURE_HEIGHT}, then @fn_gl{PixelStore}, then
* @fn_gl{GetTextureSubImage}, @fn_gl_extension{GetnTexImage,ARB,robustness},
* @fn_gl_extension{GetTextureImage,EXT,direct_state_access},
* eventually @fn_gl{GetTexImage}
* @requires_gl Texture image queries are not available in OpenGL ES or
@ -610,7 +610,8 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture {
* eventually @fn_gl{GetTexLevelParameter} with
* @def_gl{TEXTURE_COMPRESSED_IMAGE_SIZE},
* @def_gl{TEXTURE_INTERNAL_FORMAT}, @def_gl{TEXTURE_WIDTH},
* @def_gl{TEXTURE_HEIGHT}, then @fn_gl{GetCompressedTextureSubImage},
* @def_gl{TEXTURE_HEIGHT}, then @fn_gl{PixelStore}, then
* @fn_gl{GetCompressedTextureSubImage},
* @fn_gl_extension{GetnCompressedTexImage,ARB,robustness},
* @fn_gl_extension{GetCompressedTextureImage,EXT,direct_state_access},
* eventually @fn_gl{GetCompressedTexImage}
@ -969,10 +970,10 @@ class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture {
void MAGNUM_LOCAL subImageImplementationDSAEXT(Coordinate coordinate, GLint level, const Vector2i& offset, const Vector2i& size, PixelFormat format, PixelType type, const GLvoid* data);
#endif
void MAGNUM_LOCAL compressedSubImageImplementationDefault(Coordinate coordinate, GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDefault(Coordinate coordinate, GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL compressedSubImageImplementationDSA(Coordinate coordinate, GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDSAEXT(Coordinate coordinate, GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, Containers::ArrayView<const GLvoid> data);
void MAGNUM_LOCAL compressedSubImageImplementationDSA(Coordinate coordinate, GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
void MAGNUM_LOCAL compressedSubImageImplementationDSAEXT(Coordinate coordinate, GLint level, const Vector2i& offset, const Vector2i& size, CompressedPixelFormat format, const GLvoid* data, GLsizei dataSize);
#endif
};

8
src/Magnum/Implementation/TextureState.h

@ -74,13 +74,13 @@ struct TextureState {
#endif
#ifndef MAGNUM_TARGET_GLES
void(AbstractTexture::*subImage1DImplementation)(GLint, const Math::Vector<1, GLint>&, const Math::Vector<1, GLsizei>&, PixelFormat, PixelType, const GLvoid*);
void(AbstractTexture::*compressedSubImage1DImplementation)(GLint, const Math::Vector<1, GLint>&, const Math::Vector<1, GLsizei>&, CompressedPixelFormat, Containers::ArrayView<const GLvoid>);
void(AbstractTexture::*compressedSubImage1DImplementation)(GLint, const Math::Vector<1, GLint>&, const Math::Vector<1, GLsizei>&, CompressedPixelFormat, const GLvoid*, GLsizei);
#endif
void(AbstractTexture::*subImage2DImplementation)(GLint, const Vector2i&, const Vector2i&, PixelFormat, PixelType, const GLvoid*);
void(AbstractTexture::*compressedSubImage2DImplementation)(GLint, const Vector2i&, const Vector2i&, CompressedPixelFormat, Containers::ArrayView<const GLvoid>);
void(AbstractTexture::*compressedSubImage2DImplementation)(GLint, const Vector2i&, const Vector2i&, CompressedPixelFormat, const GLvoid*, GLsizei);
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))
void(AbstractTexture::*subImage3DImplementation)(GLint, const Vector3i&, const Vector3i&, PixelFormat, PixelType, const GLvoid*);
void(AbstractTexture::*compressedSubImage3DImplementation)(GLint, const Vector3i&, const Vector3i&, CompressedPixelFormat, Containers::ArrayView<const GLvoid>);
void(AbstractTexture::*compressedSubImage3DImplementation)(GLint, const Vector3i&, const Vector3i&, CompressedPixelFormat, const GLvoid*, GLsizei);
#endif
void(AbstractTexture::*invalidateImageImplementation)(GLint);
void(AbstractTexture::*invalidateSubImageImplementation)(GLint, const Vector3i&, const Vector3i&);
@ -98,7 +98,7 @@ struct TextureState {
void(CubeMapTexture::*getCompressedCubeImageImplementation)(CubeMapTexture::Coordinate, GLint, const Vector2i&, std::size_t, GLvoid*);
#endif
void(CubeMapTexture::*cubeSubImageImplementation)(CubeMapTexture::Coordinate, GLint, const Vector2i&, const Vector2i&, PixelFormat, PixelType, const GLvoid*);
void(CubeMapTexture::*cubeCompressedSubImageImplementation)(CubeMapTexture::Coordinate, GLint, const Vector2i&, const Vector2i&, CompressedPixelFormat, Containers::ArrayView<const GLvoid>);
void(CubeMapTexture::*cubeCompressedSubImageImplementation)(CubeMapTexture::Coordinate, GLint, const Vector2i&, const Vector2i&, CompressedPixelFormat, const GLvoid*, GLsizei);
GLint maxSize,
#if !(defined(MAGNUM_TARGET_WEBGL) && defined(MAGNUM_TARGET_GLES2))

1
src/Magnum/Test/CMakeLists.txt

@ -57,6 +57,7 @@ if(BUILD_GL_TESTS)
corrade_add_test(DebugOutputGLTest DebugOutputGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES})
corrade_add_test(FramebufferGLTest FramebufferGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES})
corrade_add_test(MeshGLTest MeshGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES})
corrade_add_test(PixelStorageGLTest PixelStorageGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES})
corrade_add_test(RenderbufferGLTest RenderbufferGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES})
corrade_add_test(SampleQueryGLTest SampleQueryGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES})
corrade_add_test(TextureGLTest TextureGLTest.cpp LIBRARIES ${GL_TEST_LIBRARIES})

109
src/Magnum/Test/CubeMapTextureArrayGLTest.cpp

@ -73,6 +73,12 @@ struct CubeMapTextureArrayGLTest: AbstractOpenGLTester {
void invalidateImage();
void invalidateSubImage();
private:
#ifndef MAGNUM_TARGET_GLES
CompressedPixelStorage _compressedDataStorage, _compressedSubDataStorage;
#endif
std::size_t _compressedDataOffset, _compressedSubDataOffset;
};
CubeMapTextureArrayGLTest::CubeMapTextureArrayGLTest() {
@ -110,6 +116,30 @@ CubeMapTextureArrayGLTest::CubeMapTextureArrayGLTest() {
&CubeMapTextureArrayGLTest::invalidateImage,
&CubeMapTextureArrayGLTest::invalidateSubImage});
#ifndef MAGNUM_TARGET_GLES
if(Context::current()->isExtensionSupported<Extensions::GL::ARB::compressed_texture_pixel_storage>())
{
_compressedDataStorage = _compressedSubDataStorage = CompressedPixelStorage{}
.setCompressedBlockSize({4, 4, 1})
.setCompressedBlockDataSize(16)
.setSkip({0, 0, 4});
_compressedDataOffset = _compressedSubDataOffset = 16*4;
} else
#endif
{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage = _compressedSubDataStorage = {};
#endif
_compressedDataOffset = _compressedSubDataOffset = 0;
}
}
namespace {
template<std::size_t size, class T> Containers::ArrayView<const T> unsafeSuffix(const T(&data)[size], std::size_t offset) {
static_assert(sizeof(T) == 1, "");
return {data - offset, size + offset};
}
}
void CubeMapTextureArrayGLTest::construct() {
@ -358,6 +388,9 @@ namespace {
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f
};
const auto DataStorage = PixelStorage{}.setSkip({0, 0, 1});
const auto DataOffset = 16;
/* Just 4x4 0x00 - 0x3f compressed using RGBA DXT3 by the driver, repeated
six times */
constexpr UnsignedByte CompressedData[] = {
@ -388,19 +421,19 @@ void CubeMapTextureArrayGLTest::image() {
CubeMapTextureArray texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, Data));
ImageView3D{DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, unsafeSuffix(Data, DataOffset)});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte});
Image3D image = texture.image(0, {DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(DataOffset)),
Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
#endif
}
@ -417,19 +450,22 @@ void CubeMapTextureArrayGLTest::compressedImage() {
CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported."));
CubeMapTextureArray texture;
texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3,
{4, 4, 6}, CompressedData});
texture.setCompressedImage(0, CompressedImageView3D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 6}, unsafeSuffix(CompressedData, _compressedDataOffset)});
MAGNUM_VERIFY_NO_ERROR();
#ifndef MAGNUM_TARGET_GLES
CompressedImage3D image = texture.compressedImage(0, {});
CompressedImage3D image = texture.compressedImage(0, {_compressedDataStorage});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6}));
CORRADE_COMPARE_AS(
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(_compressedDataOffset)),
Containers::ArrayView<const UnsignedByte>{CompressedData}, TestSuite::Compare::Container);
#endif
}
@ -444,20 +480,21 @@ void CubeMapTextureArrayGLTest::imageBuffer() {
#endif
CubeMapTextureArray texture;
texture.setImage(0, TextureFormat::RGBA8,
BufferImage3D(PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, Data, BufferUsage::StaticDraw));
texture.setImage(0, TextureFormat::RGBA8, BufferImage3D{DataStorage,
PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 6}, unsafeSuffix(Data, DataOffset), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage3D image = texture.image(0, {DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(DataOffset),
Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
#endif
}
@ -473,20 +510,24 @@ void CubeMapTextureArrayGLTest::compressedImageBuffer() {
CORRADE_SKIP(Extensions::GL::EXT::texture_compression_s3tc::string() + std::string(" is not supported."));
CubeMapTextureArray texture;
texture.setCompressedImage(0, CompressedBufferImage3D{CompressedPixelFormat::RGBAS3tcDxt3,
{4, 4, 6}, CompressedData, BufferUsage::StaticDraw});
texture.setCompressedImage(0, CompressedBufferImage3D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 6}, unsafeSuffix(CompressedData, _compressedDataOffset), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
CompressedBufferImage3D image = texture.compressedImage(0, {}, BufferUsage::StaticRead);
CompressedBufferImage3D image = texture.compressedImage(0, {_compressedDataStorage}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6}));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{CompressedData}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset),
Containers::ArrayView<const UnsignedByte>{CompressedData}, TestSuite::Compare::Container);
#endif
}
@ -510,6 +551,9 @@ namespace {
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
};
const auto SubDataStorage = PixelStorage{}.setSkip({0, 0, 1});
const std::size_t SubDataOffset = 16;
/* Just 4x4x4 0x00 - 0xff compressed using RGBA DXT3 by the driver */
constexpr UnsignedByte CompressedSubData[] = {
0, 17, 17, 34, 34, 51, 51, 67,
@ -628,8 +672,8 @@ void CubeMapTextureArrayGLTest::subImage() {
CubeMapTextureArray texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 6}, Zero));
texture.setSubImage(0, Vector3i(1),
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 4}, SubData));
texture.setSubImage(0, Vector3i(1), ImageView3D{SubDataStorage,
PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 4}, unsafeSuffix(SubData, SubDataOffset)});
MAGNUM_VERIFY_NO_ERROR();
@ -641,7 +685,7 @@ void CubeMapTextureArrayGLTest::subImage() {
CORRADE_COMPARE(image.size(), Vector3i(4, 4, 6));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}),
Containers::ArrayView<const UnsignedByte>{SubDataComplete}, TestSuite::Compare::Container);
#endif
}
@ -660,8 +704,11 @@ void CubeMapTextureArrayGLTest::compressedSubImage() {
CubeMapTextureArray texture;
texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3,
{12, 12, 6}, CompressedZero});
texture.setCompressedSubImage(0, {4, 4, 1},
CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, CompressedSubData});
texture.setCompressedSubImage(0, {4, 4, 1}, CompressedImageView3D{
#ifndef MAGNUM_TARGET_GLES
_compressedSubDataStorage,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, unsafeSuffix(CompressedSubData, _compressedSubDataOffset)});
MAGNUM_VERIFY_NO_ERROR();
@ -689,8 +736,8 @@ void CubeMapTextureArrayGLTest::subImageBuffer() {
CubeMapTextureArray texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, {4, 4, 6}, Zero));
texture.setSubImage(0, Vector3i(1),
BufferImage3D(PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 4}, SubData, BufferUsage::StaticDraw));
texture.setSubImage(0, Vector3i(1), BufferImage3D{SubDataStorage,
PixelFormat::RGBA, PixelType::UnsignedByte, {2, 2, 4}, unsafeSuffix(SubData, SubDataOffset), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
@ -720,8 +767,11 @@ void CubeMapTextureArrayGLTest::compressedSubImageBuffer() {
CubeMapTextureArray texture;
texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3,
{12, 12, 6}, CompressedZero});
texture.setCompressedSubImage(0, {4, 4, 1},
CompressedBufferImage3D(CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, CompressedSubData, BufferUsage::StaticDraw));
texture.setCompressedSubImage(0, {4, 4, 1}, CompressedBufferImage3D{
#ifndef MAGNUM_TARGET_GLES
_compressedSubDataStorage,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, unsafeSuffix(CompressedSubData, _compressedSubDataOffset), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
@ -750,13 +800,14 @@ void CubeMapTextureArrayGLTest::subImageQuery() {
MAGNUM_VERIFY_NO_ERROR();
Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, {2, 2, 4}), {PixelFormat::RGBA, PixelType::UnsignedByte});
Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, {2, 2, 4}),
{SubDataStorage, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2, 2, 4));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(SubDataOffset)),
Containers::ArrayView<const UnsignedByte>{SubData}, TestSuite::Compare::Container);
}
@ -772,13 +823,15 @@ void CubeMapTextureArrayGLTest::subImageQueryBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, {2, 2, 4}), {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, {2, 2, 4}),
{SubDataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2, 2, 4));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{SubData}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(SubDataOffset),
Containers::ArrayView<const UnsignedByte>{SubData}, TestSuite::Compare::Container);
}
#endif

147
src/Magnum/Test/CubeMapTextureGLTest.cpp

@ -96,6 +96,15 @@ struct CubeMapTextureGLTest: AbstractOpenGLTester {
void invalidateImage();
void invalidateSubImage();
private:
PixelStorage _dataStorage;
std::size_t _dataOffset;
#ifndef MAGNUM_TARGET_GLES
CompressedPixelStorage _compressedDataStorage, _compressedFullDataStorage;
#endif
std::size_t _compressedDataOffset, _compressedFullDataOffset;
};
CubeMapTextureGLTest::CubeMapTextureGLTest() {
@ -153,6 +162,47 @@ CubeMapTextureGLTest::CubeMapTextureGLTest() {
&CubeMapTextureGLTest::invalidateImage,
&CubeMapTextureGLTest::invalidateSubImage});
_dataStorage = PixelStorage{}.setSkip({0, 1, 0});
_dataOffset = 8;
#ifdef MAGNUM_TARGET_GLES2
#ifndef MAGNUM_TARGET_WEBGL
if(!Context::current()->isExtensionSupported<Extensions::GL::EXT::unpack_subimage>())
#endif
{
_dataStorage = {};
_dataOffset = 0;
}
#endif
#ifndef MAGNUM_TARGET_GLES
if(Context::current()->isExtensionSupported<Extensions::GL::ARB::compressed_texture_pixel_storage>())
{
_compressedDataStorage = CompressedPixelStorage{}
.setCompressedBlockSize({4, 4, 1})
.setCompressedBlockDataSize(16)
.setSkip({0, 4, 0});
_compressedFullDataStorage = CompressedPixelStorage{}
.setCompressedBlockSize({4, 4, 1})
.setCompressedBlockDataSize(16)
.setSkip({0, 0, 4});
_compressedDataOffset = 16;
_compressedFullDataOffset = 16*4;
} else
#endif
{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage = {};
#endif
_compressedDataOffset = 0;
}
}
namespace {
template<std::size_t size, class T> Containers::ArrayView<const T> unsafeSuffix(const T(&data)[size], std::size_t offset) {
static_assert(sizeof(T) == 1, "");
return {data - offset, size + offset};
}
}
void CubeMapTextureGLTest::construct() {
@ -382,19 +432,20 @@ namespace {
void CubeMapTextureGLTest::image() {
CubeMapTexture texture;
texture.setImage(CubeMapTexture::Coordinate::PositiveX, 0, TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data));
ImageView2D{_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, _dataOffset)});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0, {PixelFormat::RGBA, PixelType::UnsignedByte});
Image2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0,
{_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i(2));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(_dataOffset)),
Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
#endif
}
@ -409,19 +460,22 @@ void CubeMapTextureGLTest::compressedImage() {
#endif
CubeMapTexture texture;
texture.setCompressedImage(CubeMapTexture::Coordinate::PositiveX, 0,
CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, CompressedData});
texture.setCompressedImage(CubeMapTexture::Coordinate::PositiveX, 0, CompressedImageView2D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData, _compressedDataOffset)});
MAGNUM_VERIFY_NO_ERROR();
#ifndef MAGNUM_TARGET_GLES
CompressedImage2D image = texture.compressedImage(CubeMapTexture::Coordinate::PositiveX, 0, {});
CompressedImage2D image = texture.compressedImage(CubeMapTexture::Coordinate::PositiveX, 0, {_compressedDataStorage});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i{4});
CORRADE_COMPARE_AS(
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}).suffix(_compressedDataOffset),
Containers::ArrayView<const UnsignedByte>{CompressedData}, TestSuite::Compare::Container);
#endif
}
@ -429,20 +483,22 @@ void CubeMapTextureGLTest::compressedImage() {
#ifndef MAGNUM_TARGET_GLES2
void CubeMapTextureGLTest::imageBuffer() {
CubeMapTexture texture;
texture.setImage(CubeMapTexture::Coordinate::PositiveX, 0, TextureFormat::RGBA8,
BufferImage2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data, BufferUsage::StaticDraw));
texture.setImage(CubeMapTexture::Coordinate::PositiveX, 0, TextureFormat::RGBA8, BufferImage2D{
_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, _dataOffset), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage2D image = texture.image(CubeMapTexture::Coordinate::PositiveX, 0,
{_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i(2));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_dataOffset),
Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
#endif
}
@ -456,20 +512,24 @@ void CubeMapTextureGLTest::compressedImageBuffer() {
#endif
CubeMapTexture texture;
texture.setCompressedImage(CubeMapTexture::Coordinate::PositiveX, 0,
CompressedBufferImage2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, CompressedData, BufferUsage::StaticDraw});
texture.setCompressedImage(CubeMapTexture::Coordinate::PositiveX, 0, CompressedBufferImage2D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData, _compressedDataOffset), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
#ifndef MAGNUM_TARGET_GLES
CompressedBufferImage2D image = texture.compressedImage(CubeMapTexture::Coordinate::PositiveX, 0,
{}, BufferUsage::StaticRead);
{_compressedDataStorage}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i{4});
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{CompressedData}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset),
Containers::ArrayView<const UnsignedByte>{CompressedData}, TestSuite::Compare::Container);
#endif
}
#endif
@ -506,6 +566,9 @@ namespace {
0x58, 0x59, 0x5a, 0x5b,
0x5c, 0x5d, 0x5e, 0x5f };
const auto FullDataStorage = PixelStorage{}.setSkip({0, 0, 1});
const auto FullDataOffset = 16;
/* Just 4x4 0x00 - 0x3f compressed using RGBA DXT3 by the driver, repeated
six times */
constexpr UnsignedByte CompressedFullData[] = {
@ -535,13 +598,14 @@ void CubeMapTextureGLTest::fullImageQuery() {
MAGNUM_VERIFY_NO_ERROR();
Image3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte});
Image3D image = texture.image(0,
{FullDataStorage, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(FullDataOffset)),
Containers::ArrayView<const UnsignedByte>{FullData}, TestSuite::Compare::Container);
}
@ -557,13 +621,13 @@ void CubeMapTextureGLTest::compressedFullImageQuery() {
MAGNUM_VERIFY_NO_ERROR();
CompressedImage3D image = texture.compressedImage(0, {});
CompressedImage3D image = texture.compressedImage(0, {_compressedFullDataStorage});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6}));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.data().size()),
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.data().size()).suffix(_compressedFullDataOffset),
Containers::ArrayView<const UnsignedByte>{CompressedFullData}, TestSuite::Compare::Container);
}
@ -577,13 +641,15 @@ void CubeMapTextureGLTest::fullImageQueryBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage3D image = texture.image(0,
{FullDataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2, 2, 6));
const auto imageData = image.buffer().data<UnsignedByte>();
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{FullData}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(FullDataOffset),
Containers::ArrayView<const UnsignedByte>{FullData}, TestSuite::Compare::Container);
}
void CubeMapTextureGLTest::compressedFullImageQueryBuffer() {
@ -598,13 +664,14 @@ void CubeMapTextureGLTest::compressedFullImageQueryBuffer() {
MAGNUM_VERIFY_NO_ERROR();
CompressedBufferImage3D image = texture.compressedImage(0, {}, BufferUsage::StaticRead);
CompressedBufferImage3D image = texture.compressedImage(0, {_compressedFullDataStorage}, BufferUsage::StaticRead);
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 6}));
const auto imageData = image.buffer().data<UnsignedByte>();
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{CompressedFullData}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_compressedFullDataOffset),
Containers::ArrayView<const UnsignedByte>{CompressedFullData}, TestSuite::Compare::Container);
}
#endif
@ -650,8 +717,8 @@ void CubeMapTextureGLTest::subImage() {
CubeMapTexture texture;
texture.setImage(CubeMapTexture::Coordinate::PositiveX, 0, TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero));
texture.setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i(1),
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data));
texture.setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i(1), ImageView2D{
_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, _dataOffset)});
MAGNUM_VERIFY_NO_ERROR();
@ -663,7 +730,7 @@ void CubeMapTextureGLTest::subImage() {
CORRADE_COMPARE(image.size(), Vector2i(4));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}),
Containers::ArrayView<const UnsignedByte>{SubDataComplete}, TestSuite::Compare::Container);
#endif
}
@ -680,8 +747,11 @@ void CubeMapTextureGLTest::compressedSubImage() {
CubeMapTexture texture;
texture.setCompressedImage(CubeMapTexture::Coordinate::PositiveX, 0,
CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero});
texture.setCompressedSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i{4},
CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, CompressedData});
texture.setCompressedSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i{4}, CompressedImageView2D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData, _compressedDataOffset)});
MAGNUM_VERIFY_NO_ERROR();
@ -702,8 +772,8 @@ void CubeMapTextureGLTest::subImageBuffer() {
CubeMapTexture texture;
texture.setImage(CubeMapTexture::Coordinate::PositiveX, 0, TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero));
texture.setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i(1),
BufferImage2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data, BufferUsage::StaticDraw));
texture.setSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i(1), BufferImage2D{
_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, _dataOffset), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
@ -731,8 +801,11 @@ void CubeMapTextureGLTest::compressedSubImageBuffer() {
CubeMapTexture texture;
texture.setCompressedImage(CubeMapTexture::Coordinate::PositiveX, 0,
CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{12}, CompressedZero});
texture.setCompressedSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i{4},
CompressedBufferImage2D{CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, CompressedData, BufferUsage::StaticDraw});
texture.setCompressedSubImage(CubeMapTexture::Coordinate::PositiveX, 0, Vector2i{4}, CompressedBufferImage2D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData, _compressedDataOffset), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
@ -763,13 +836,14 @@ void CubeMapTextureGLTest::subImageQuery() {
MAGNUM_VERIFY_NO_ERROR();
Image3D image = texture.subImage(0, Range3Di::fromSize({1, 1, 0}, {2, 2, 1}), {PixelFormat::RGBA, PixelType::UnsignedByte});
Image3D image = texture.subImage(0, Range3Di::fromSize({1, 1, 0}, {2, 2, 1}),
{_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2, 2, 1));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}).suffix(_dataOffset),
Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
}
@ -786,13 +860,14 @@ void CubeMapTextureGLTest::subImageQueryBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage3D image = texture.subImage(0, Range3Di::fromSize({1, 1, 0}, {2, 2, 1}), {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage3D image = texture.subImage(0, Range3Di::fromSize({1, 1, 0}, {2, 2, 1}),
{_dataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2, 2, 1));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_dataOffset), Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
}
#endif

18
src/Magnum/Test/FramebufferGLTest.cpp

@ -811,6 +811,11 @@ void FramebufferGLTest::invalidateSub() {
}
#endif
namespace {
const auto DataStorage = PixelStorage{}.setSkip({0, 16, 0});
const std::size_t DataOffset = 16*8;
}
void FramebufferGLTest::read() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::framebuffer_object>())
@ -860,11 +865,13 @@ void FramebufferGLTest::read() {
Renderer::setClearStencil(67);
framebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth|FramebufferClear::Stencil);
Image2D colorImage = framebuffer.read(Range2Di::fromSize({16, 8}, {8, 16}), {PixelFormat::RGBA, PixelType::UnsignedByte});
Image2D colorImage = framebuffer.read(Range2Di::fromSize({16, 8}, {8, 16}),
{DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(colorImage.size(), Vector2i(8, 16));
CORRADE_COMPARE(colorImage.data<Color4ub>()[0], Color4ub(128, 64, 32, 17));
CORRADE_COMPARE(colorImage.data().size(), (DataOffset + 8*16)*sizeof(Color4ub));
CORRADE_COMPARE(colorImage.data<Color4ub>()[DataOffset], Color4ub(128, 64, 32, 17));
#ifdef MAGNUM_TARGET_GLES
if(Context::current()->isExtensionSupported<Extensions::GL::NV::read_depth>())
@ -937,15 +944,16 @@ void FramebufferGLTest::readBuffer() {
Renderer::setClearStencil(67);
framebuffer.clear(FramebufferClear::Color|FramebufferClear::Depth|FramebufferClear::Stencil);
BufferImage2D colorImage = framebuffer.read(Range2Di::fromSize({16, 8}, {8, 16}), {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage2D colorImage = framebuffer.read(Range2Di::fromSize({16, 8}, {8, 16}),
{DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
CORRADE_COMPARE(colorImage.size(), Vector2i(8, 16));
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
const auto colorData = colorImage.buffer().data<Color4ub>();
CORRADE_COMPARE(colorData.size(), 8*16);
CORRADE_COMPARE(colorData[0], Color4ub(128, 64, 32, 17));
CORRADE_COMPARE(colorData.size(), DataOffset + 8*16);
CORRADE_COMPARE(colorData[DataOffset], Color4ub(128, 64, 32, 17));
#endif
}
#endif

48
src/Magnum/Test/RectangleTextureGLTest.cpp

@ -101,6 +101,13 @@ RectangleTextureGLTest::RectangleTextureGLTest() {
&RectangleTextureGLTest::invalidateSubImage});
}
namespace {
template<std::size_t size, class T> Containers::ArrayView<const T> unsafeSuffix(const T(&data)[size], std::size_t offset) {
static_assert(sizeof(T) == 1, "");
return {data - offset, size + offset};
}
}
void RectangleTextureGLTest::construct() {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_rectangle>())
CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported."));
@ -253,6 +260,9 @@ namespace {
0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b,
0x0c, 0x0d, 0x0e, 0x0f };
const auto DataStorage = PixelStorage{}.setSkip({0, 1, 0});
const auto DataOffset = 8;
}
void RectangleTextureGLTest::image() {
@ -260,18 +270,18 @@ void RectangleTextureGLTest::image() {
CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported."));
RectangleTexture texture;
texture.setImage(TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data));
texture.setImage(TextureFormat::RGBA8, ImageView2D{
DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, DataOffset)});
MAGNUM_VERIFY_NO_ERROR();
Image2D image = texture.image({PixelFormat::RGBA, PixelType::UnsignedByte});
Image2D image = texture.image({DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i(2));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.data().size()).suffix(DataOffset),
Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
}
@ -284,18 +294,19 @@ void RectangleTextureGLTest::imageBuffer() {
CORRADE_SKIP(Extensions::GL::ARB::texture_rectangle::string() + std::string(" is not supported."));
RectangleTexture texture;
texture.setImage(TextureFormat::RGBA8,
BufferImage2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data, BufferUsage::StaticDraw));
texture.setImage(TextureFormat::RGBA8, BufferImage2D{
DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, DataOffset), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
BufferImage2D image = texture.image({PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage2D image = texture.image({DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i(2));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(DataOffset),
Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
}
void RectangleTextureGLTest::compressedImageBuffer() {
@ -320,8 +331,8 @@ void RectangleTextureGLTest::subImage() {
RectangleTexture texture;
texture.setImage(TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero));
texture.setSubImage(Vector2i(1),
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data));
texture.setSubImage(Vector2i(1), ImageView2D{
DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, DataOffset)});
MAGNUM_VERIFY_NO_ERROR();
@ -331,7 +342,7 @@ void RectangleTextureGLTest::subImage() {
CORRADE_COMPARE(image.size(), Vector2i(4));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.data().size()),
Containers::ArrayView<const UnsignedByte>{SubDataComplete}, TestSuite::Compare::Container);
}
@ -346,8 +357,8 @@ void RectangleTextureGLTest::subImageBuffer() {
RectangleTexture texture;
texture.setImage(TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero));
texture.setSubImage(Vector2i(1),
BufferImage2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data, BufferUsage::StaticDraw));
texture.setSubImage(Vector2i(1), BufferImage2D{
DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data, DataOffset), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
@ -376,13 +387,14 @@ void RectangleTextureGLTest::subImageQuery() {
MAGNUM_VERIFY_NO_ERROR();
Image2D image = texture.subImage(Range2Di::fromSize(Vector2i{1}, Vector2i{2}), {PixelFormat::RGBA, PixelType::UnsignedByte});
Image2D image = texture.subImage(Range2Di::fromSize(Vector2i{1}, Vector2i{2}),
{DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i{2});
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.data().size()).suffix(DataOffset),
Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
}
@ -398,13 +410,15 @@ void RectangleTextureGLTest::subImageQueryBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage2D image = texture.subImage(Range2Di::fromSize(Vector2i{1}, Vector2i{2}), {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage2D image = texture.subImage(Range2Di::fromSize(Vector2i{1}, Vector2i{2}),
{DataStorage, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i{2});
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(DataOffset),
Containers::ArrayView<const UnsignedByte>{Data}, TestSuite::Compare::Container);
}
void RectangleTextureGLTest::invalidateImage() {

149
src/Magnum/Test/TextureArrayGLTest.cpp

@ -142,6 +142,11 @@ struct TextureArrayGLTest: AbstractOpenGLTester {
void invalidateSubImage1D();
#endif
void invalidateSubImage2D();
#ifndef MAGNUM_TARGET_GLES
CompressedPixelStorage _compressedDataStorage2D;
#endif
std::size_t _compressedDataOffset2D;
};
TextureArrayGLTest::TextureArrayGLTest() {
@ -246,6 +251,30 @@ TextureArrayGLTest::TextureArrayGLTest() {
#endif
&TextureArrayGLTest::invalidateSubImage2D
});
#ifndef MAGNUM_TARGET_GLES
if(Context::current()->isExtensionSupported<Extensions::GL::ARB::compressed_texture_pixel_storage>())
{
_compressedDataStorage2D = CompressedPixelStorage{}
.setCompressedBlockSize({4, 4, 1})
.setCompressedBlockDataSize(16)
.setSkip({0, 0, 1});
_compressedDataOffset2D = 16;
} else
#endif
{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage2D = {};
#endif
_compressedDataOffset2D = 0;
}
}
namespace {
template<std::size_t size, class T> Containers::ArrayView<const T> unsafeSuffix(const T(&data)[size], std::size_t offset) {
static_assert(sizeof(T) == 1, "");
return {data - offset, size + offset};
}
}
#ifndef MAGNUM_TARGET_GLES
@ -658,6 +687,9 @@ namespace {
0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b,
0x0c, 0x0d, 0x0e, 0x0f };
const auto DataStorage1D = PixelStorage{}.setSkip({0, 1, 0});
const std::size_t DataOffset1D = 8;
}
#ifndef MAGNUM_TARGET_GLES
@ -666,18 +698,18 @@ void TextureArrayGLTest::image1D() {
CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported."));
Texture1DArray texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data1D));
texture.setImage(0, TextureFormat::RGBA8, ImageView2D{DataStorage1D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data1D, DataOffset1D)});
MAGNUM_VERIFY_NO_ERROR();
Image2D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte});
Image2D image = texture.image(0, {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i(2));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(DataOffset1D)),
Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
}
@ -690,18 +722,20 @@ void TextureArrayGLTest::image1DBuffer() {
CORRADE_SKIP(Extensions::GL::EXT::texture_array::string() + std::string(" is not supported."));
Texture1DArray texture;
texture.setImage(0, TextureFormat::RGBA8,
BufferImage2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data1D, BufferUsage::StaticDraw));
texture.setImage(0, TextureFormat::RGBA8, BufferImage2D{DataStorage1D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data1D, DataOffset1D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
BufferImage2D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage2D image = texture.image(0,
{DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i(2));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(DataOffset1D),
Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
}
void TextureArrayGLTest::compressedImage1DBuffer() {
@ -719,6 +753,9 @@ namespace {
0x18, 0x19, 0x1a, 0x1b,
0x1c, 0x1d, 0x1e, 0x1f };
const auto DataStorage2D = PixelStorage{}.setSkip({0, 0, 1});
const std::size_t DataOffset2D = 16;
/* Just 4x4x2 0x00 - 0x7f compressed using RGBA DXT3 by the driver */
constexpr UnsignedByte CompressedData2D[] = {
0, 17, 17, 34, 34, 51, 51, 67,
@ -735,20 +772,20 @@ void TextureArrayGLTest::image2D() {
#endif
Texture2DArray texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), Data2D));
texture.setImage(0, TextureFormat::RGBA8, ImageView3D{DataStorage2D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data2D, DataOffset2D)});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte});
Image3D image = texture.image(0, {DataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(DataOffset2D)),
Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
#endif
}
@ -767,19 +804,22 @@ void TextureArrayGLTest::compressedImage2D() {
#endif
Texture2DArray texture;
texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3,
{4, 4, 2}, CompressedData2D});
texture.setCompressedImage(0, CompressedImageView3D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage2D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)});
MAGNUM_VERIFY_NO_ERROR();
#ifndef MAGNUM_TARGET_GLES
CompressedImage3D image = texture.compressedImage(0, {});
CompressedImage3D image = texture.compressedImage(0, {_compressedDataStorage2D});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 2}));
CORRADE_COMPARE_AS(
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(_compressedDataOffset2D)),
Containers::ArrayView<const UnsignedByte>{CompressedData2D}, TestSuite::Compare::Container);
#endif
}
@ -791,20 +831,21 @@ void TextureArrayGLTest::image2DBuffer() {
#endif
Texture2DArray texture;
texture.setImage(0, TextureFormat::RGBA8,
BufferImage3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), Data2D, BufferUsage::StaticDraw));
texture.setImage(0, TextureFormat::RGBA8, BufferImage3D{DataStorage2D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data2D, DataOffset2D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage3D image = texture.image(0, {DataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(DataOffset2D),
Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
#endif
}
@ -822,19 +863,23 @@ void TextureArrayGLTest::compressedImage2DBuffer() {
#endif
Texture2DArray texture;
texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3,
{4, 4, 2}, CompressedData2D});
texture.setCompressedImage(0, CompressedImageView3D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage2D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)});
MAGNUM_VERIFY_NO_ERROR();
#ifndef MAGNUM_TARGET_GLES
CompressedBufferImage3D image = texture.compressedImage(0, {}, BufferUsage::StaticRead);
CompressedBufferImage3D image = texture.compressedImage(0, {_compressedDataStorage2D}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), (Vector3i{4, 4, 2}));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{CompressedData2D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset2D),
Containers::ArrayView<const UnsignedByte>{CompressedData2D}, TestSuite::Compare::Container);
#endif
}
@ -856,8 +901,8 @@ void TextureArrayGLTest::subImage1D() {
Texture1DArray texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero1D));
texture.setSubImage(0, Vector2i(1),
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data1D));
texture.setSubImage(0, Vector2i(1), ImageView2D{DataStorage1D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data1D, DataOffset1D)});
MAGNUM_VERIFY_NO_ERROR();
@ -867,7 +912,7 @@ void TextureArrayGLTest::subImage1D() {
CORRADE_COMPARE(image.size(), Vector2i(4));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}),
Containers::ArrayView<const UnsignedByte>{SubData1DComplete}, TestSuite::Compare::Container);
}
@ -882,8 +927,8 @@ void TextureArrayGLTest::subImage1DBuffer() {
Texture1DArray texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero1D));
texture.setSubImage(0, Vector2i(1),
BufferImage2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data1D, BufferUsage::StaticDraw));
texture.setSubImage(0, Vector2i(1), BufferImage2D{DataStorage1D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data1D, DataOffset1D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
@ -912,13 +957,14 @@ void TextureArrayGLTest::subImage1DQuery() {
MAGNUM_VERIFY_NO_ERROR();
Image2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}), {PixelFormat::RGBA, PixelType::UnsignedByte});
Image2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}),
{DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i{2});
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()), Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(DataOffset1D)), Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
}
void TextureArrayGLTest::subImage1DQueryBuffer() {
@ -933,13 +979,15 @@ void TextureArrayGLTest::subImage1DQueryBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}), {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}),
{DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i{2});
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(DataOffset1D),
Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
}
#endif
@ -1012,8 +1060,8 @@ void TextureArrayGLTest::subImage2D() {
Texture2DArray texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero2D));
texture.setSubImage(0, Vector3i(1),
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), Data2D));
texture.setSubImage(0, Vector3i(1), ImageView3D{DataStorage2D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data2D, DataOffset2D)});
MAGNUM_VERIFY_NO_ERROR();
@ -1025,7 +1073,7 @@ void TextureArrayGLTest::subImage2D() {
CORRADE_COMPARE(image.size(), Vector3i(4));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()), Containers::ArrayView<const UnsignedByte>{SubData2DComplete}, TestSuite::Compare::Container);
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}), Containers::ArrayView<const UnsignedByte>{SubData2DComplete}, TestSuite::Compare::Container);
#endif
}
@ -1045,8 +1093,11 @@ void TextureArrayGLTest::compressedSubImage2D() {
Texture2DArray texture;
texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3,
Vector3i{12, 4, 4}, CompressedZero2D});
texture.setCompressedSubImage(0, {4, 0, 1}, CompressedImageView3D(CompressedPixelFormat::RGBAS3tcDxt3,
{4, 4, 2}, CompressedData2D));
texture.setCompressedSubImage(0, {4, 0, 1}, CompressedImageView3D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage2D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)});
MAGNUM_VERIFY_NO_ERROR();
@ -1070,8 +1121,8 @@ void TextureArrayGLTest::subImage2DBuffer() {
Texture2DArray texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero2D));
texture.setSubImage(0, Vector3i(1),
BufferImage3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), Data2D, BufferUsage::StaticDraw));
texture.setSubImage(0, Vector3i(1), BufferImage3D{DataStorage2D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data2D, DataOffset2D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
@ -1103,8 +1154,11 @@ void TextureArrayGLTest::compressedSubImage2DBuffer() {
Texture2DArray texture;
texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3,
Vector3i{12, 4, 4}, CompressedZero2D});
texture.setCompressedSubImage(0, {4, 0, 1}, CompressedImageView3D(CompressedPixelFormat::RGBAS3tcDxt3,
{4, 4, 2}, CompressedData2D));
texture.setCompressedSubImage(0, {4, 0, 1}, CompressedImageView3D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage2D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, {4, 4, 2}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)});
MAGNUM_VERIFY_NO_ERROR();
@ -1132,13 +1186,14 @@ void TextureArrayGLTest::subImage2DQuery() {
MAGNUM_VERIFY_NO_ERROR();
Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), {PixelFormat::RGBA, PixelType::UnsignedByte});
Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}),
{DataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i{2});
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()), Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(DataOffset2D)), Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
}
void TextureArrayGLTest::subImage2DQueryBuffer() {
@ -1153,13 +1208,15 @@ void TextureArrayGLTest::subImage2DQueryBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}),
{DataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i{2});
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(DataOffset2D),
Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
}
void TextureArrayGLTest::generateMipmap1D() {

252
src/Magnum/Test/TextureGLTest.cpp

@ -179,6 +179,14 @@ struct TextureGLTest: AbstractOpenGLTester {
#endif
void invalidateSubImage2D();
void invalidateSubImage3D();
PixelStorage _dataStorage2D, _dataStorage3D;
std::size_t _dataOffset2D, _dataOffset3D;
#ifndef MAGNUM_TARGET_GLES
CompressedPixelStorage _compressedDataStorage2D, _compressedDataStorage3D;
#endif
std::size_t _compressedDataOffset2D, _compressedDataOffset3D;
};
TextureGLTest::TextureGLTest() {
@ -319,6 +327,49 @@ TextureGLTest::TextureGLTest() {
&TextureGLTest::invalidateSubImage2D,
&TextureGLTest::invalidateSubImage3D,
});
_dataStorage2D = PixelStorage{}.setSkip({0, 1, 0});
_dataStorage3D = PixelStorage{}.setSkip({0, 0, 1});
_dataOffset2D = 8;
_dataOffset3D = 16;
#ifdef MAGNUM_TARGET_GLES2
#ifndef MAGNUM_TARGET_WEBGL
if(!Context::current()->isExtensionSupported<Extensions::GL::EXT::unpack_subimage>())
#endif
{
_dataStorage2D = _dataStorage3D = {};
_dataOffset2D = _dataOffset3D = 0;
}
#endif
#ifndef MAGNUM_TARGET_GLES
if(Context::current()->isExtensionSupported<Extensions::GL::ARB::compressed_texture_pixel_storage>())
{
_compressedDataStorage2D = CompressedPixelStorage{}
.setCompressedBlockSize({4, 4, 1})
.setCompressedBlockDataSize(16)
.setSkip({0, 4, 0});
_compressedDataStorage3D = CompressedPixelStorage{}
.setCompressedBlockSize({4, 4, 4})
.setCompressedBlockDataSize(16*4)
.setSkip({0, 0, 4});
_compressedDataOffset2D = 16;
_compressedDataOffset3D = 16*4;
} else
#endif
{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage2D = _compressedDataStorage3D = {};
#endif
_compressedDataOffset2D = _compressedDataOffset3D = 0;
}
}
namespace {
template<std::size_t size, class T> Containers::ArrayView<const T> unsafeSuffix(const T(&data)[size], std::size_t offset) {
static_assert(sizeof(T) == 1, "");
return {data - offset, size + offset};
}
}
#ifndef MAGNUM_TARGET_GLES
@ -901,23 +952,26 @@ void TextureGLTest::storage3D() {
namespace {
constexpr UnsignedByte Data1D[] = { 0x00, 0x01, 0x02, 0x03,
0x04, 0x05, 0x06, 0x07 };
const auto DataStorage1D = PixelStorage{}.setSkip({1, 0, 0});
const std::size_t DataOffset1D = 4;
}
#ifndef MAGNUM_TARGET_GLES
void TextureGLTest::image1D() {
Texture1D texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView1D(PixelFormat::RGBA, PixelType::UnsignedByte, 2, Data1D));
texture.setImage(0, TextureFormat::RGBA8, ImageView1D{DataStorage1D,
PixelFormat::RGBA, PixelType::UnsignedByte, 2, unsafeSuffix(Data1D, DataOffset1D)});
MAGNUM_VERIFY_NO_ERROR();
Image1D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte});
Image1D image = texture.image(0, {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), 2);
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(DataOffset1D)),
Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
}
@ -927,18 +981,20 @@ void TextureGLTest::compressedImage1D() {
void TextureGLTest::image1DBuffer() {
Texture1D texture;
texture.setImage(0, TextureFormat::RGBA8,
BufferImage1D(PixelFormat::RGBA, PixelType::UnsignedByte, 2, Data1D, BufferUsage::StaticDraw));
texture.setImage(0, TextureFormat::RGBA8, BufferImage1D{DataStorage1D,
PixelFormat::RGBA, PixelType::UnsignedByte, 2, unsafeSuffix(Data1D, DataOffset1D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
BufferImage1D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticDraw);
BufferImage1D image = texture.image(0,
{DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticDraw);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), 2);
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(DataOffset1D),
Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
}
void TextureGLTest::compressedImage1DBuffer() {
@ -961,20 +1017,20 @@ namespace {
void TextureGLTest::image2D() {
Texture2D texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data2D));
texture.setImage(0, TextureFormat::RGBA8, ImageView2D{_dataStorage2D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data2D, _dataOffset2D)});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image2D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte});
Image2D image = texture.image(0, {_dataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i(2));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(_dataOffset2D)),
Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
#endif
}
@ -989,20 +1045,23 @@ void TextureGLTest::compressedImage2D() {
#endif
Texture2D texture;
texture.setCompressedImage(0, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3,
Vector2i{4}, CompressedData2D});
texture.setCompressedImage(0, CompressedImageView2D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage2D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)});
MAGNUM_VERIFY_NO_ERROR();
#ifndef MAGNUM_TARGET_GLES
CompressedImage2D image = texture.compressedImage(0, {});
CompressedImage2D image = texture.compressedImage(0, {_compressedDataStorage2D});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i{4});
CORRADE_COMPARE_AS(
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(_compressedDataOffset2D)),
Containers::ArrayView<const UnsignedByte>{CompressedData2D}, TestSuite::Compare::Container);
#endif
}
@ -1010,20 +1069,22 @@ void TextureGLTest::compressedImage2D() {
#ifndef MAGNUM_TARGET_GLES2
void TextureGLTest::image2DBuffer() {
Texture2D texture;
texture.setImage(0, TextureFormat::RGBA8,
BufferImage2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data2D, BufferUsage::StaticDraw));
texture.setImage(0, TextureFormat::RGBA8, BufferImage2D{_dataStorage2D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data2D, _dataOffset2D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage2D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage2D image = texture.image(0,
{_dataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i(2));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_dataOffset2D),
Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
#endif
}
@ -1037,19 +1098,23 @@ void TextureGLTest::compressedImage2DBuffer() {
#endif
Texture2D texture;
texture.setCompressedImage(0, CompressedBufferImage2D{CompressedPixelFormat::RGBAS3tcDxt3,
Vector2i{4}, CompressedData2D, BufferUsage::StaticDraw});
texture.setCompressedImage(0, CompressedBufferImage2D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage2D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
#ifndef MAGNUM_TARGET_GLES
CompressedBufferImage2D image = texture.compressedImage(0, {}, BufferUsage::StaticRead);
CompressedBufferImage2D image = texture.compressedImage(0, {_compressedDataStorage2D}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i{4});
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{CompressedData2D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset2D),
Containers::ArrayView<const UnsignedByte>{CompressedData2D}, TestSuite::Compare::Container);
#endif
}
#endif
@ -1084,20 +1149,20 @@ void TextureGLTest::image3D() {
#endif
Texture3D texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), Data3D));
texture.setImage(0, TextureFormat::RGBA8, ImageView3D{_dataStorage3D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data3D, _dataOffset3D)});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
Image3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte});
Image3D image = texture.image(0, {_dataStorage3D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.data().size()).suffix(_dataOffset3D),
Containers::ArrayView<const UnsignedByte>{Data3D}, TestSuite::Compare::Container);
#endif
}
@ -1116,19 +1181,22 @@ void TextureGLTest::compressedImage3D() {
#endif
Texture3D texture;
texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3,
Vector3i{4}, CompressedData3D});
texture.setCompressedImage(0, CompressedImageView3D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage3D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, unsafeSuffix(CompressedData3D, _compressedDataOffset3D)});
MAGNUM_VERIFY_NO_ERROR();
#ifndef MAGNUM_TARGET_GLES
CompressedImage3D image = texture.compressedImage(0, {});
CompressedImage3D image = texture.compressedImage(0, {_compressedDataStorage3D});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i{4});
CORRADE_COMPARE_AS(
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(_compressedDataOffset3D)),
Containers::ArrayView<const UnsignedByte>{CompressedData3D}, TestSuite::Compare::Container);
#endif
}
@ -1136,20 +1204,22 @@ void TextureGLTest::compressedImage3D() {
#ifndef MAGNUM_TARGET_GLES2
void TextureGLTest::image3DBuffer() {
Texture3D texture;
texture.setImage(0, TextureFormat::RGBA8,
BufferImage3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), Data3D, BufferUsage::StaticDraw));
texture.setImage(0, TextureFormat::RGBA8, BufferImage3D{_dataStorage3D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data3D, _dataOffset3D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
/** @todo How to test this on ES? */
#ifndef MAGNUM_TARGET_GLES
BufferImage3D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage3D image = texture.image(0,
{_dataStorage3D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i(2));
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data3D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_dataOffset3D),
Containers::ArrayView<const UnsignedByte>{Data3D}, TestSuite::Compare::Container);
#endif
}
@ -1163,19 +1233,23 @@ void TextureGLTest::compressedImage3DBuffer() {
#endif
Texture3D texture;
texture.setCompressedImage(0, CompressedBufferImage3D{CompressedPixelFormat::RGBAS3tcDxt3,
Vector3i{4}, CompressedData3D, BufferUsage::StaticDraw});
texture.setCompressedImage(0, CompressedBufferImage3D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage3D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, unsafeSuffix(CompressedData3D, _compressedDataOffset3D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
#ifndef MAGNUM_TARGET_GLES
CompressedBufferImage3D image = texture.compressedImage(0, {}, BufferUsage::StaticRead);
CompressedBufferImage3D image = texture.compressedImage(0, {_compressedDataStorage3D}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i{4});
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{CompressedData3D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_compressedDataOffset3D),
Containers::ArrayView<const UnsignedByte>{CompressedData3D}, TestSuite::Compare::Container);
#endif
}
#endif
@ -1192,18 +1266,18 @@ void TextureGLTest::subImage1D() {
Texture1D texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView1D(PixelFormat::RGBA, PixelType::UnsignedByte, 4, Zero1D));
texture.setSubImage(0, 1,
ImageView1D(PixelFormat::RGBA, PixelType::UnsignedByte, 2, Data1D));
texture.setSubImage(0, 1, ImageView1D{DataStorage1D,
PixelFormat::RGBA, PixelType::UnsignedByte, 2, unsafeSuffix(Data1D, DataOffset1D)});
MAGNUM_VERIFY_NO_ERROR();
Image1D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte});
Image1D image = texture.image(0, {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), 4);
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(DataOffset1D)),
Containers::ArrayView<const UnsignedByte>{SubData1DComplete}, TestSuite::Compare::Container);
}
@ -1215,18 +1289,19 @@ void TextureGLTest::subImage1DBuffer() {
Texture1D texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView1D(PixelFormat::RGBA, PixelType::UnsignedByte, 4, Zero1D));
texture.setSubImage(0, 1,
BufferImage1D(PixelFormat::RGBA, PixelType::UnsignedByte, 2, Data1D, BufferUsage::StaticDraw));
texture.setSubImage(0, 1, BufferImage1D{DataStorage1D,
PixelFormat::RGBA, PixelType::UnsignedByte, 2, unsafeSuffix(Data1D, DataOffset1D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
BufferImage1D image = texture.image(0, {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage1D image = texture.image(0, {DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), 4);
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{SubData1DComplete}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(DataOffset1D),
Containers::ArrayView<const UnsignedByte>{SubData1DComplete}, TestSuite::Compare::Container);
}
void TextureGLTest::compressedSubImage1DBuffer() {
@ -1243,13 +1318,14 @@ void TextureGLTest::subImage1DQuery() {
MAGNUM_VERIFY_NO_ERROR();
Image1D image = texture.subImage(0, Range1Di::fromSize(1, 2), {PixelFormat::RGBA, PixelType::UnsignedByte});
Image1D image = texture.subImage(0, Range1Di::fromSize(1, 2),
{DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), 2);
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()), Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(DataOffset1D)), Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
}
void TextureGLTest::subImage1DQueryBuffer() {
@ -1262,13 +1338,15 @@ void TextureGLTest::subImage1DQueryBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage1D image = texture.subImage(0, Range1Di::fromSize(1, 2), {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage1D image = texture.subImage(0, Range1Di::fromSize(1, 2),
{DataStorage1D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), 2);
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(DataOffset1D),
Containers::ArrayView<const UnsignedByte>{Data1D}, TestSuite::Compare::Container);
}
#endif
@ -1300,8 +1378,8 @@ void TextureGLTest::subImage2D() {
Texture2D texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero2D));
texture.setSubImage(0, Vector2i(1),
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data2D));
texture.setSubImage(0, Vector2i(1), ImageView2D{_dataStorage2D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data2D, _dataOffset2D)});
MAGNUM_VERIFY_NO_ERROR();
@ -1313,7 +1391,7 @@ void TextureGLTest::subImage2D() {
CORRADE_COMPARE(image.size(), Vector2i(4));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}),
Containers::ArrayView<const UnsignedByte>{SubData2DComplete}, TestSuite::Compare::Container);
#endif
}
@ -1330,8 +1408,11 @@ void TextureGLTest::compressedSubImage2D() {
Texture2D texture;
texture.setCompressedImage(0, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3,
{12, 4}, CompressedZero2D});
texture.setCompressedSubImage(0, {4, 0}, CompressedImageView2D(CompressedPixelFormat::RGBAS3tcDxt3,
Vector2i{4}, CompressedData2D));
texture.setCompressedSubImage(0, {4, 0}, CompressedImageView2D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage2D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D)});
MAGNUM_VERIFY_NO_ERROR();
@ -1352,8 +1433,8 @@ void TextureGLTest::subImage2DBuffer() {
Texture2D texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(4), Zero2D));
texture.setSubImage(0, Vector2i(1),
BufferImage2D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), Data2D, BufferUsage::StaticDraw));
texture.setSubImage(0, Vector2i(1), BufferImage2D{_dataStorage2D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector2i(2), unsafeSuffix(Data2D, _dataOffset2D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
@ -1381,8 +1462,11 @@ void TextureGLTest::compressedSubImage2DBuffer() {
Texture2D texture;
texture.setCompressedImage(0, CompressedImageView2D{CompressedPixelFormat::RGBAS3tcDxt3,
{12, 4}, CompressedZero2D});
texture.setCompressedSubImage(0, {4, 0}, CompressedBufferImage2D{CompressedPixelFormat::RGBAS3tcDxt3,
Vector2i{4}, CompressedData2D, BufferUsage::StaticDraw});
texture.setCompressedSubImage(0, {4, 0}, CompressedBufferImage2D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage2D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector2i{4}, unsafeSuffix(CompressedData2D, _compressedDataOffset2D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
@ -1409,13 +1493,14 @@ void TextureGLTest::subImage2DQuery() {
MAGNUM_VERIFY_NO_ERROR();
Image2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}), {PixelFormat::RGBA, PixelType::UnsignedByte});
Image2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}),
{_dataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i{2});
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()), Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(_dataOffset2D)), Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
}
void TextureGLTest::subImage2DQueryBuffer() {
@ -1428,13 +1513,15 @@ void TextureGLTest::subImage2DQueryBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}), {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage2D image = texture.subImage(0, Range2Di::fromSize(Vector2i{1}, Vector2i{2}),
{_dataStorage2D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector2i{2});
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_dataOffset2D),
Containers::ArrayView<const UnsignedByte>{Data2D}, TestSuite::Compare::Container);
}
#endif
@ -1508,8 +1595,8 @@ void TextureGLTest::subImage3D() {
Texture3D texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero3D));
texture.setSubImage(0, Vector3i(1),
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), Data3D));
texture.setSubImage(0, Vector3i(1), ImageView3D{_dataStorage3D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data3D, _dataOffset3D)});
MAGNUM_VERIFY_NO_ERROR();
@ -1521,7 +1608,7 @@ void TextureGLTest::subImage3D() {
CORRADE_COMPARE(image.size(), Vector3i(4));
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()),
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}),
Containers::ArrayView<const UnsignedByte>{SubData3DComplete}, TestSuite::Compare::Container);
#endif
}
@ -1542,8 +1629,11 @@ void TextureGLTest::compressedSubImage3D() {
Texture3D texture;
texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3,
{12, 4, 4}, CompressedZero3D});
texture.setCompressedSubImage(0, {4, 0, 0}, CompressedImageView3D(CompressedPixelFormat::RGBAS3tcDxt3,
Vector3i{4}, CompressedData3D));
texture.setCompressedSubImage(0, {4, 0, 0}, CompressedImageView3D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage3D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, unsafeSuffix(CompressedData3D, _compressedDataOffset3D)});
MAGNUM_VERIFY_NO_ERROR();
@ -1564,8 +1654,8 @@ void TextureGLTest::subImage3DBuffer() {
Texture3D texture;
texture.setImage(0, TextureFormat::RGBA8,
ImageView3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(4), Zero3D));
texture.setSubImage(0, Vector3i(1),
BufferImage3D(PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), Data3D, BufferUsage::StaticDraw));
texture.setSubImage(0, Vector3i(1), BufferImage3D{_dataStorage3D,
PixelFormat::RGBA, PixelType::UnsignedByte, Vector3i(2), unsafeSuffix(Data3D, _dataOffset3D), BufferUsage::StaticDraw});
MAGNUM_VERIFY_NO_ERROR();
@ -1593,8 +1683,11 @@ void TextureGLTest::compressedSubImage3DBuffer() {
Texture3D texture;
texture.setCompressedImage(0, CompressedImageView3D{CompressedPixelFormat::RGBAS3tcDxt3,
{12, 4, 4}, CompressedZero3D});
texture.setCompressedSubImage(0, {4, 0, 0}, CompressedImageView3D(CompressedPixelFormat::RGBAS3tcDxt3,
Vector3i{4}, CompressedData3D));
texture.setCompressedSubImage(0, {4, 0, 0}, CompressedImageView3D{
#ifndef MAGNUM_TARGET_GLES
_compressedDataStorage3D,
#endif
CompressedPixelFormat::RGBAS3tcDxt3, Vector3i{4}, unsafeSuffix(CompressedData3D, _compressedDataOffset3D)});
MAGNUM_VERIFY_NO_ERROR();
@ -1621,13 +1714,14 @@ void TextureGLTest::subImage3DQuery() {
MAGNUM_VERIFY_NO_ERROR();
Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), {PixelFormat::RGBA, PixelType::UnsignedByte});
Image3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}),
{_dataStorage3D, PixelFormat::RGBA, PixelType::UnsignedByte});
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i{2});
CORRADE_COMPARE_AS(
Containers::ArrayView<const UnsignedByte>(image.data<UnsignedByte>(), image.pixelSize()*image.size().product()), Containers::ArrayView<const UnsignedByte>{Data3D}, TestSuite::Compare::Container);
(Containers::ArrayView<const UnsignedByte>{image.data<UnsignedByte>(), image.data().size()}.suffix(_dataOffset3D)), Containers::ArrayView<const UnsignedByte>{Data3D}, TestSuite::Compare::Container);
}
void TextureGLTest::subImage3DQueryBuffer() {
@ -1640,13 +1734,15 @@ void TextureGLTest::subImage3DQueryBuffer() {
MAGNUM_VERIFY_NO_ERROR();
BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}), {PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
BufferImage3D image = texture.subImage(0, Range3Di::fromSize(Vector3i{1}, Vector3i{2}),
{_dataStorage3D, PixelFormat::RGBA, PixelType::UnsignedByte}, BufferUsage::StaticRead);
const auto imageData = image.buffer().data<UnsignedByte>();
MAGNUM_VERIFY_NO_ERROR();
CORRADE_COMPARE(image.size(), Vector3i{2});
CORRADE_COMPARE_AS(imageData, Containers::ArrayView<const UnsignedByte>{Data3D}, TestSuite::Compare::Container);
CORRADE_COMPARE_AS(imageData.suffix(_dataOffset3D),
Containers::ArrayView<const UnsignedByte>{Data3D}, TestSuite::Compare::Container);
}
void TextureGLTest::generateMipmap1D() {

19
src/Magnum/Texture.h

@ -653,7 +653,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* eventually @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and
* @fn_gl{GetTexLevelParameter} with @def_gl{TEXTURE_WIDTH},
* @def_gl{TEXTURE_HEIGHT}, @def_gl{TEXTURE_DEPTH}, then
* @fn_gl2{GetTextureImage,GetTexImage},
* @fn_gl{PixelStore}, then @fn_gl2{GetTextureImage,GetTexImage},
* @fn_gl_extension{GetnTexImage,ARB,robustness},
* @fn_gl_extension{GetTextureImage,EXT,direct_state_access},
* eventually @fn_gl{GetTexImage}
@ -723,6 +723,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* @def_gl{TEXTURE_COMPRESSED_IMAGE_SIZE},
* @def_gl{TEXTURE_INTERNAL_FORMAT}, @def_gl{TEXTURE_WIDTH},
* @def_gl{TEXTURE_HEIGHT}, @def_gl{TEXTURE_DEPTH}, then
* @fn_gl{PixelStore}, then
* @fn_gl2{GetCompressedTextureImage,GetCompressedTexImage},
* @fn_gl_extension{GetnCompressedTexImage,ARB,robustness},
* @fn_gl_extension{GetCompressedTextureImage,EXT,direct_state_access},
@ -841,8 +842,9 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* and has better performance characteristics. This call also has no
* equivalent in @extension{ARB,direct_state_access}, thus the texture
* needs to be bound to some texture unit before the operation.
* @see @ref maxSize(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and
* @fn_gl{TexImage1D} / @fn_gl{TexImage2D} / @fn_gl{TexImage3D}
* @see @ref maxSize(), @fn_gl{PixelStore}, then @fn_gl{ActiveTexture},
* @fn_gl{BindTexture} and @fn_gl{TexImage1D} / @fn_gl{TexImage2D}
* / @fn_gl{TexImage3D}
* @deprecated_gl Prefer to use @ref setStorage() and @ref setSubImage()
* instead.
*/
@ -891,9 +893,9 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* also has no equivalent in @extension{ARB,direct_state_access}, thus
* the texture needs to be bound to some texture unit before the
* operation.
* @see @ref maxSize(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and
* @fn_gl{CompressedTexImage1D} / @fn_gl{CompressedTexImage2D} /
* @fn_gl{CompressedTexImage3D}
* @see @ref maxSize(), @fn_gl{PixelStore}, then @fn_gl{ActiveTexture},
* @fn_gl{BindTexture} and @fn_gl{CompressedTexImage1D} /
* @fn_gl{CompressedTexImage2D} / @fn_gl{CompressedTexImage3D}
* @deprecated_gl Prefer to use @ref setStorage() and
* @ref setCompressedSubImage() instead.
*/
@ -941,7 +943,7 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* nor @extension{EXT,direct_state_access} desktop extension is
* available, the texture is bound before the operation (if not
* already).
* @see @ref setStorage(), @fn_gl2{TextureSubImage1D,TexSubImage1D} /
* @see @ref setStorage(), @fn_gl{PixelStore}, @fn_gl2{TextureSubImage1D,TexSubImage1D} /
* @fn_gl2{TextureSubImage2D,TexSubImage2D} / @fn_gl2{TextureSubImage3D,TexSubImage3D},
* @fn_gl_extension{TextureSubImage1D,EXT,direct_state_access} /
* @fn_gl_extension{TextureSubImage2D,EXT,direct_state_access} /
@ -994,7 +996,8 @@ template<UnsignedInt dimensions> class Texture: public AbstractTexture {
* nor @extension{EXT,direct_state_access} desktop extension is
* available, the texture is bound before the operation (if not
* already).
* @see @ref setStorage(), @fn_gl2{CompressedTextureSubImage1D,CompressedTexSubImage1D} /
* @see @ref setStorage(), @fn_gl{PixelStore},
* @fn_gl2{CompressedTextureSubImage1D,CompressedTexSubImage1D} /
* @fn_gl2{CompressedTextureSubImage2D,CompressedTexSubImage2D} /
* @fn_gl2{CompressedTextureSubImage3D,CompressedTexSubImage3D},
* @fn_gl_extension{CompressedTextureSubImage1D,EXT,direct_state_access} /

6
src/Magnum/TextureArray.h

@ -599,7 +599,8 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
* nor @extension{EXT,direct_state_access} desktop extension is
* available, the texture is bound before the operation (if not
* already).
* @see @ref setStorage(), @fn_gl2{TextureSubImage2D,TexSubImage2D}/
* @see @ref setStorage(), @fn_gl{PixelStore}, then
* @fn_gl2{TextureSubImage2D,TexSubImage2D}/
* @fn_gl2{TextureSubImage3D,TexSubImage3D},
* @fn_gl_extension{TextureSubImage2D,EXT,direct_state_access}/
* @fn_gl_extension{TextureSubImage3D,EXT,direct_state_access},
@ -634,7 +635,8 @@ template<UnsignedInt dimensions> class TextureArray: public AbstractTexture {
* nor @extension{EXT,direct_state_access} desktop extension is
* available, the texture is bound before the operation (if not
* already).
* @see @ref setStorage(), @fn_gl2{CompressedTextureSubImage2D,CompressedTexSubImage2D}/
* @see @ref setStorage(), @fn_gl{PixelStore}, then
* @fn_gl2{CompressedTextureSubImage2D,CompressedTexSubImage2D}/
* @fn_gl2{CompressedTextureSubImage3D,CompressedTexSubImage3D},
* @fn_gl_extension{CompressedTextureSubImage2D,EXT,direct_state_access}/
* @fn_gl_extension{CompressedTextureSubImage3D,EXT,direct_state_access},

Loading…
Cancel
Save