Browse Source

Enabled 2D multisample textures in ES 3.1.

pull/68/head
Vladimír Vondruš 12 years ago
parent
commit
278877f8e3
  1. 8
      src/Magnum/AbstractTexture.cpp
  2. 10
      src/Magnum/AbstractTexture.h
  3. 4
      src/Magnum/CMakeLists.txt
  4. 2
      src/Magnum/Implementation/TextureState.cpp
  5. 4
      src/Magnum/Implementation/TextureState.h
  6. 4
      src/Magnum/Magnum.h
  7. 12
      src/Magnum/MultisampleTexture.cpp
  8. 36
      src/Magnum/MultisampleTexture.h
  9. 60
      src/Magnum/Test/MultisampleTextureGLTest.cpp

8
src/Magnum/AbstractTexture.cpp

@ -983,12 +983,16 @@ void AbstractTexture::storageMultisampleImplementationFallback(const GLenum targ
bindInternal();
glTexImage2DMultisample(target, samples, GLenum(internalFormat), size.x(), size.y(), fixedSampleLocations);
}
#endif
#ifndef MAGNUM_TARGET_GLES2
void AbstractTexture::storageMultisampleImplementationDefault(const GLenum target, const GLsizei samples, const TextureFormat internalFormat, const Vector2i& size, const GLboolean fixedSampleLocations) {
bindInternal();
glTexStorage2DMultisample(target, samples, GLenum(internalFormat), size.x(), size.y(), fixedSampleLocations);
}
#endif
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::storageMultisampleImplementationDSA(const GLenum target, const GLsizei samples, const TextureFormat internalFormat, const Vector2i& size, const GLboolean fixedSampleLocations) {
glTextureStorage2DMultisampleEXT(_id, target, samples, GLenum(internalFormat), size.x(), size.y(), fixedSampleLocations);
}
@ -1206,11 +1210,13 @@ void AbstractTexture::DataHelper<3>::setStorage(AbstractTexture& texture, const
(texture.*Context::current()->state().texture->storage3DImplementation)(target, levels, internalFormat, size);
}
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
void AbstractTexture::DataHelper<2>::setStorageMultisample(AbstractTexture& texture, const GLenum target, const GLsizei samples, const TextureFormat internalFormat, const Vector2i& size, const GLboolean fixedSampleLocations) {
(texture.*Context::current()->state().texture->storage2DMultisampleImplementation)(target, samples, internalFormat, size, fixedSampleLocations);
}
#endif
#ifndef MAGNUM_TARGET_GLES
void AbstractTexture::DataHelper<3>::setStorageMultisample(AbstractTexture& texture, const GLenum target, const GLsizei samples, const TextureFormat internalFormat, const Vector3i& size, const GLboolean fixedSampleLocations) {
(texture.*Context::current()->state().texture->storage3DMultisampleImplementation)(target, samples, internalFormat, size, fixedSampleLocations);
}

10
src/Magnum/AbstractTexture.h

@ -420,9 +420,15 @@ class MAGNUM_EXPORT AbstractTexture: public AbstractObject {
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL storageMultisampleImplementationFallback(GLenum target, GLsizei samples, TextureFormat internalFormat, const Vector2i& size, GLboolean fixedsamplelocations);
#endif
#ifndef MAGNUM_TARGET_GLES2
void MAGNUM_LOCAL storageMultisampleImplementationDefault(GLenum target, GLsizei samples, TextureFormat internalFormat, const Vector2i& size, GLboolean fixedsamplelocations);
#endif
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL storageMultisampleImplementationDSA(GLenum target, GLsizei samples, TextureFormat internalFormat, const Vector2i& size, GLboolean fixedsamplelocations);
#endif
#ifndef MAGNUM_TARGET_GLES
void MAGNUM_LOCAL storageMultisampleImplementationFallback(GLenum target, GLsizei samples, TextureFormat internalFormat, const Vector3i& size, GLboolean fixedsamplelocations);
void MAGNUM_LOCAL storageMultisampleImplementationDefault(GLenum target, GLsizei samples, TextureFormat internalFormat, const Vector3i& size, GLboolean fixedsamplelocations);
void MAGNUM_LOCAL storageMultisampleImplementationDSA(GLenum target, GLsizei samples, TextureFormat internalFormat, const Vector3i& size, GLboolean fixedsamplelocations);
@ -524,7 +530,9 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<2> {
static void setStorage(AbstractTexture& texture, GLenum target, GLsizei levels, TextureFormat internalFormat, const Vector2i& size);
#ifndef MAGNUM_TARGET_GLES2
static void setStorageMultisample(AbstractTexture& texture, GLenum target, GLsizei samples, TextureFormat internalFormat, const Vector2i& size, GLboolean fixedSampleLocations);
#endif
static void setImage(AbstractTexture& texture, GLenum target, GLint level, TextureFormat internalFormat, const ImageReference2D& image);
#ifndef MAGNUM_TARGET_GLES2
@ -561,7 +569,9 @@ template<> struct MAGNUM_EXPORT AbstractTexture::DataHelper<3> {
static void setStorage(AbstractTexture& texture, GLenum target, GLsizei levels, TextureFormat internalFormat, const Vector3i& size);
#ifndef MAGNUM_TARGET_GLES
static void setStorageMultisample(AbstractTexture& texture, GLenum target, GLsizei samples, TextureFormat internalFormat, const Vector3i& size, GLboolean fixedSampleLocations);
#endif
static void setImage(AbstractTexture& texture, GLenum target, GLint level, TextureFormat internalFormat, const ImageReference3D& image);
#ifndef MAGNUM_TARGET_GLES2

4
src/Magnum/CMakeLists.txt

@ -143,12 +143,10 @@ if(NOT TARGET_GLES)
set(Magnum_HEADERS ${Magnum_HEADERS}
BufferTexture.h
CubeMapTextureArray.h
MultisampleTexture.h
RectangleTexture.h)
set(Magnum_SRCS ${Magnum_SRCS}
BufferTexture.cpp
CubeMapTextureArray.cpp
MultisampleTexture.cpp
RectangleTexture.cpp)
endif()
@ -156,9 +154,11 @@ endif()
if(NOT TARGET_GLES2)
set(Magnum_HEADERS ${Magnum_HEADERS}
BufferImage.h
MultisampleTexture.h
TextureArray.h)
set(Magnum_SRCS ${Magnum_SRCS}
BufferImage.cpp
MultisampleTexture.cpp
TextureArray.cpp)
endif()

2
src/Magnum/Implementation/TextureState.cpp

@ -218,6 +218,8 @@ TextureState::TextureState(Context& context, std::vector<std::string>& extension
storage2DMultisampleImplementation = &AbstractTexture::storageMultisampleImplementationFallback;
storage3DMultisampleImplementation = &AbstractTexture::storageMultisampleImplementationFallback;
}
#elif !defined(MAGNUM_TARGET_GLES2)
storage2DMultisampleImplementation = &AbstractTexture::storageMultisampleImplementationDefault;
#endif
/* Anisotropic filter implementation */

4
src/Magnum/Implementation/TextureState.h

@ -62,8 +62,10 @@ struct TextureState {
#endif
void(AbstractTexture::*storage2DImplementation)(GLenum, GLsizei, TextureFormat, const Vector2i&);
void(AbstractTexture::*storage3DImplementation)(GLenum, GLsizei, TextureFormat, const Vector3i&);
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
void(AbstractTexture::*storage2DMultisampleImplementation)(GLenum, GLsizei, TextureFormat, const Vector2i&, GLboolean);
#endif
#ifndef MAGNUM_TARGET_GLES
void(AbstractTexture::*storage3DMultisampleImplementation)(GLenum, GLsizei, TextureFormat, const Vector3i&, GLboolean);
void(AbstractTexture::*getImageImplementation)(GLenum, GLint, ColorFormat, ColorType, std::size_t, GLvoid*);
void(AbstractTexture::*image1DImplementation)(GLenum, GLint, TextureFormat, const Math::Vector<1, GLsizei>&, ColorFormat, ColorType, const GLvoid*);

4
src/Magnum/Magnum.h

@ -508,12 +508,14 @@ enum class MeshPrimitive: GLenum;
class Mesh;
class MeshView;
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
/* MultisampleTextureSampleLocations enum used only in the function */
template<UnsignedInt> class MultisampleTexture;
typedef MultisampleTexture<2> MultisampleTexture2D;
#ifndef MAGNUM_TARGET_GLES
typedef MultisampleTexture<3> MultisampleTexture2DArray;
#endif
#endif
/* AbstractQuery is not used directly */
class PrimitiveQuery;

12
src/Magnum/MultisampleTexture.cpp

@ -25,7 +25,7 @@
#include "MultisampleTexture.h"
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
#include "Magnum/Context.h"
#include "Magnum/Extensions.h"
@ -34,18 +34,24 @@
namespace Magnum { namespace Implementation {
template<> Vector2i MAGNUM_EXPORT maxMultisampleTextureSize<2>() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
return {};
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
#endif
return Vector2i{0};
return Vector2i{Implementation::maxTextureSideSize()};
}
#ifndef MAGNUM_TARGET_GLES
template<> Vector3i MAGNUM_EXPORT maxMultisampleTextureSize<3>() {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
return {};
return Vector3i{0};
return {Vector2i{Implementation::maxTextureSideSize()}, Implementation::max3DTextureDepth()};
}
#endif
}}
#endif

36
src/Magnum/MultisampleTexture.h

@ -25,7 +25,7 @@
DEALINGS IN THE SOFTWARE.
*/
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
/** @file
* @brief Class @ref Magnum::MultisampleTexture, typedef @ref Magnum::MultisampleTexture2D, @ref Magnum::MultisampleTexture2DArray
*/
@ -35,17 +35,21 @@
#include "Magnum/DimensionTraits.h"
#include "Magnum/Math/Vector3.h"
#ifndef MAGNUM_TARGET_GLES
#ifndef MAGNUM_TARGET_GLES2
namespace Magnum {
namespace Implementation {
template<UnsignedInt> constexpr GLenum multisampleTextureTarget();
template<> inline constexpr GLenum multisampleTextureTarget<2>() { return GL_TEXTURE_2D_MULTISAMPLE; }
#ifndef MAGNUM_TARGET_GLES
template<> inline constexpr GLenum multisampleTextureTarget<3>() { return GL_TEXTURE_2D_MULTISAMPLE_ARRAY; }
#endif
template<UnsignedInt dimensions> VectorTypeFor<dimensions, Int> maxMultisampleTextureSize();
template<> MAGNUM_EXPORT Vector2i maxMultisampleTextureSize<2>();
#ifndef MAGNUM_TARGET_GLES
template<> MAGNUM_EXPORT Vector3i maxMultisampleTextureSize<3>();
#endif
}
/**
@ -83,7 +87,10 @@ shaders.
@ref TextureArray, @ref CubeMapTexture, @ref CubeMapTextureArray,
@ref RectangleTexture, @ref BufferTexture
@requires_gl32 %Extension @extension{ARB,texture_multisample}
@requires_gl Multisample textures are not available in OpenGL ES.
@requires_gles31 Multisample textures are not available in OpenGL ES 3.0 and
older.
@requires_gl 2D array multisample textures are not available in OpenGL ES, only
2D ones.
*/
template<UnsignedInt dimensions> class MultisampleTexture: public AbstractTexture {
public:
@ -93,8 +100,9 @@ template<UnsignedInt dimensions> class MultisampleTexture: public AbstractTextur
* @brief Max supported multisample texture size
*
* The result is cached, repeated queries don't result in repeated
* OpenGL calls. If extension @extension{ARB,texture_multisample} (part
* of OpenGL 3.2) is not available, returns zero vector.
* OpenGL calls. If neither extension @extension{ARB,texture_multisample}
* (part of OpenGL 3.2) nor OpenGL ES 3.1 is available, returns zero
* vector.
* @see @fn_gl{Get} with @def_gl{MAX_TEXTURE_SIZE} and
* @def_gl{MAX_3D_TEXTURE_SIZE}
*/
@ -187,11 +195,25 @@ template<UnsignedInt dimensions> class MultisampleTexture: public AbstractTextur
#endif
};
/** @brief Two-dimensional multisample texture */
/**
@brief Two-dimensional multisample texture
@requires_gl32 %Extension @extension{ARB,texture_multisample}
@requires_gles31 Multisample textures are not available in OpenGL ES 3.0 and
older.
*/
typedef MultisampleTexture<2> MultisampleTexture2D;
/** @brief Two-dimensional multisample texture array */
#ifndef MAGNUM_TARGET_GLES
/**
@brief Two-dimensional multisample texture array
@requires_gl32 %Extension @extension{ARB,texture_multisample}
@requires_gl Only @ref Magnum::MultisampleTexture2D "MultisampleTexture2D" is
available in OpenGL ES.
*/
typedef MultisampleTexture<3> MultisampleTexture2DArray;
#endif
}
#else

60
src/Magnum/Test/MultisampleTextureGLTest.cpp

@ -37,41 +37,67 @@ class MultisampleTextureGLTest: public AbstractOpenGLTester {
explicit MultisampleTextureGLTest();
void construct2D();
#ifndef MAGNUM_TARGET_GLES
void construct2DArray();
#endif
void bind2D();
#ifndef MAGNUM_TARGET_GLES
void bind2DArray();
#endif
void storage2D();
#ifndef MAGNUM_TARGET_GLES
void storage2DArray();
#endif
void invalidateImage2D();
#ifndef MAGNUM_TARGET_GLES
void invalidateImage2DArray();
#endif
void invalidateSubImage2D();
#ifndef MAGNUM_TARGET_GLES
void invalidateSubImage2DArray();
#endif
};
MultisampleTextureGLTest::MultisampleTextureGLTest() {
addTests({&MultisampleTextureGLTest::construct2D,
#ifndef MAGNUM_TARGET_GLES
&MultisampleTextureGLTest::construct2DArray,
#endif
&MultisampleTextureGLTest::bind2D,
#ifndef MAGNUM_TARGET_GLES
&MultisampleTextureGLTest::bind2DArray,
#endif
&MultisampleTextureGLTest::storage2D,
#ifndef MAGNUM_TARGET_GLES
&MultisampleTextureGLTest::storage2DArray,
#endif
&MultisampleTextureGLTest::invalidateImage2D,
#ifndef MAGNUM_TARGET_GLES
&MultisampleTextureGLTest::invalidateImage2DArray,
#endif
&MultisampleTextureGLTest::invalidateSubImage2D,
&MultisampleTextureGLTest::invalidateSubImage2DArray});
#ifndef MAGNUM_TARGET_GLES
&MultisampleTextureGLTest::invalidateSubImage2DArray
#endif
});
}
void MultisampleTextureGLTest::construct2D() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported."));
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
CORRADE_SKIP("OpenGL ES 3.1 is not supported.");
#endif
{
MultisampleTexture2D texture;
@ -83,6 +109,7 @@ void MultisampleTextureGLTest::construct2D() {
MAGNUM_VERIFY_NO_ERROR();
}
#ifndef MAGNUM_TARGET_GLES
void MultisampleTextureGLTest::construct2DArray() {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported."));
@ -96,18 +123,26 @@ void MultisampleTextureGLTest::construct2DArray() {
MAGNUM_VERIFY_NO_ERROR();
}
#endif
void MultisampleTextureGLTest::bind2D() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported."));
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
CORRADE_SKIP("OpenGL ES 3.1 is not supported.");
#endif
MultisampleTexture2D texture;
#ifndef MAGNUM_TARGET_GLES
if(Context::current()->isExtensionSupported<Extensions::GL::ARB::multi_bind>()) {
CORRADE_EXPECT_FAIL("With ARB_multi_bind the texture must be associated with given target at least once before binding it.");
texture.setStorage(4, TextureFormat::RGBA8, {16, 16});
CORRADE_VERIFY(false);
}
#endif
texture.bind(15);
@ -122,6 +157,7 @@ void MultisampleTextureGLTest::bind2D() {
MAGNUM_VERIFY_NO_ERROR();
}
#ifndef MAGNUM_TARGET_GLES
void MultisampleTextureGLTest::bind2DArray() {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported."));
@ -146,10 +182,16 @@ void MultisampleTextureGLTest::bind2DArray() {
MAGNUM_VERIFY_NO_ERROR();
}
#endif
void MultisampleTextureGLTest::storage2D() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported."));
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
CORRADE_SKIP("OpenGL ES 3.1 is not supported.");
#endif
MultisampleTexture2D texture;
texture.setStorage(4, TextureFormat::RGBA8, {16, 16});
@ -161,6 +203,7 @@ void MultisampleTextureGLTest::storage2D() {
MAGNUM_VERIFY_NO_ERROR();
}
#ifndef MAGNUM_TARGET_GLES
void MultisampleTextureGLTest::storage2DArray() {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported."));
@ -174,10 +217,16 @@ void MultisampleTextureGLTest::storage2DArray() {
MAGNUM_VERIFY_NO_ERROR();
}
#endif
void MultisampleTextureGLTest::invalidateImage2D() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported."));
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
CORRADE_SKIP("OpenGL ES 3.1 is not supported.");
#endif
MultisampleTexture2D texture;
texture.setStorage(4, TextureFormat::RGBA8, {16, 16});
@ -186,6 +235,7 @@ void MultisampleTextureGLTest::invalidateImage2D() {
MAGNUM_VERIFY_NO_ERROR();
}
#ifndef MAGNUM_TARGET_GLES
void MultisampleTextureGLTest::invalidateImage2DArray() {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported."));
@ -196,10 +246,16 @@ void MultisampleTextureGLTest::invalidateImage2DArray() {
MAGNUM_VERIFY_NO_ERROR();
}
#endif
void MultisampleTextureGLTest::invalidateSubImage2D() {
#ifndef MAGNUM_TARGET_GLES
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported."));
#else
if(!Context::current()->isVersionSupported(Version::GLES310))
CORRADE_SKIP("OpenGL ES 3.1 is not supported.");
#endif
MultisampleTexture2D texture;
texture.setStorage(4, TextureFormat::RGBA8, {16, 16});
@ -208,6 +264,7 @@ void MultisampleTextureGLTest::invalidateSubImage2D() {
MAGNUM_VERIFY_NO_ERROR();
}
#ifndef MAGNUM_TARGET_GLES
void MultisampleTextureGLTest::invalidateSubImage2DArray() {
if(!Context::current()->isExtensionSupported<Extensions::GL::ARB::texture_multisample>())
CORRADE_SKIP(Extensions::GL::ARB::texture_multisample::string() + std::string(" is not supported."));
@ -218,6 +275,7 @@ void MultisampleTextureGLTest::invalidateSubImage2DArray() {
MAGNUM_VERIFY_NO_ERROR();
}
#endif
}}

Loading…
Cancel
Save