diff --git a/doc/opengl-mapping.dox b/doc/opengl-mapping.dox index 5ebc5dd65..dcec0aff7 100644 --- a/doc/opengl-mapping.dox +++ b/doc/opengl-mapping.dox @@ -299,7 +299,7 @@ OpenGL function | Matching API `GL_MAX_*_UNIFORM_BLOCKS`, \n @def_gl{MAX_COMBINED_UNIFORM_BLOCKS} | @ref Shader::maxUniformBlocks(), \n @ref Shader::maxCombinedUniformBlocks() `GL_MAX_*_UNIFORM_COMPONENTS`, \n @def_gl{MAX_VERTEX_UNIFORM_VECTORS}, \n @def_gl{MAX_FRAGMENT_UNIFORM_VECTORS} | @ref Shader::maxUniformComponents() `GL_MAX_COMBINED_*_UNIFORM_COMPONENTS` | @ref Shader::maxCombinedUniformComponents() -@def_gl{MAX_3D_TEXTURE_SIZE}, \n @def_gl{MAX_ARRAY_TEXTURE_LAYERS}, \n @def_gl{MAX_CUBE_MAP_TEXTURE_SIZE}, \n @def_gl{MAX_RECTANGLE_TEXTURE_SIZE}, \n @def_gl{MAX_TEXTURE_SIZE} | | +@def_gl{MAX_3D_TEXTURE_SIZE}, \n @def_gl{MAX_ARRAY_TEXTURE_LAYERS}, \n @def_gl{MAX_CUBE_MAP_TEXTURE_SIZE}, \n @def_gl{MAX_RECTANGLE_TEXTURE_SIZE}, \n @def_gl{MAX_TEXTURE_SIZE} | @ref Texture::maxSize(), \n @ref TextureArray::maxSize(), \n @ref CubeMapTexture::maxSize(), \n @ref CubeMapTextureArray::maxSize(), \n @ref RectangleTexture::maxSize(), \n @ref BufferTexture::maxSize(), \n @ref MultisampleTexture::maxSize() @def_gl{MAX_ATOMIC_COUNTER_BUFFER_SIZE} | @ref AbstractShaderProgram::maxAtomicCounterBufferSize() @def_gl{MAX_ATOMIC_COUNTER_BUFFER_BINDINGS} | @ref Buffer::maxAtomicCounterBindings() @def_gl{MAX_COLOR_ATTACHMENTS} | @ref Framebuffer::maxColorAttachments() diff --git a/doc/opengl-support.dox b/doc/opengl-support.dox index c5ca18e64..a8498f323 100644 --- a/doc/opengl-support.dox +++ b/doc/opengl-support.dox @@ -81,9 +81,9 @@ following: %Extension | Status -------------------------------------------- | ------ -@extension{ARB,texture_rectangle} | missing limit query +@extension{ARB,texture_rectangle} | done @extension{ARB,draw_instanced} | | -@extension{ARB,texture_buffer_object} | missing limit query +@extension{ARB,texture_buffer_object} | done @extension{ARB,uniform_buffer_object} | | @extension{ARB,copy_buffer} | done @extension{EXT,texture_snorm} | done diff --git a/src/Magnum/AbstractTexture.h b/src/Magnum/AbstractTexture.h index f6797bb02..64d75591b 100644 --- a/src/Magnum/AbstractTexture.h +++ b/src/Magnum/AbstractTexture.h @@ -104,7 +104,6 @@ functions do nothing. @todo Move constructor/assignment - how to avoid creation of empty texture and then deleting it immediately? @todo ES2 - proper support for pixel unpack buffer when extension is in headers -@todo `GL_MAX_3D_TEXTURE_SIZE`, `GL_MAX_ARRAY_TEXTURE_LAYERS`, `GL_MAX_CUBE_MAP_TEXTURE_SIZE`, `GL_MAX_RECTANGLE_TEXTURE_SIZE`, `GL_MAX_TEXTURE_SIZE`, `GL_MAX_TEXTURE_BUFFER_SIZE` enable them only where it makes sense? @todo `GL_NUM_COMPRESSED_TEXTURE_FORMATS` when compressed textures are implemented @todo `GL_MAX_SAMPLE_MASK_WORDS` when @extension{ARB,texture_multisample} is done @todo Query for immutable levels (@extension{ARB,ES3_compatibility}) diff --git a/src/Magnum/BufferTexture.cpp b/src/Magnum/BufferTexture.cpp index 1c91f129e..84b5ad87b 100644 --- a/src/Magnum/BufferTexture.cpp +++ b/src/Magnum/BufferTexture.cpp @@ -35,6 +35,18 @@ namespace Magnum { +Int BufferTexture::maxSize() { + if(!Context::current()->isExtensionSupported()) + return 0; + + GLint& value = Context::current()->state().texture->maxBufferSize; + + if(value == 0) + glGetIntegerv(GL_MAX_TEXTURE_BUFFER_SIZE, &value); + + return value; +} + Int BufferTexture::offsetAlignment() { if(!Context::current()->isExtensionSupported()) return 0; diff --git a/src/Magnum/BufferTexture.h b/src/Magnum/BufferTexture.h index a91d85879..987695d98 100644 --- a/src/Magnum/BufferTexture.h +++ b/src/Magnum/BufferTexture.h @@ -202,6 +202,16 @@ class MAGNUM_EXPORT BufferTexture: public AbstractTexture { friend struct Implementation::TextureState; public: + /** + * @brief Max supported buffer texture size + * + * The result is cached, repeated queries don't result in repeated + * OpenGL calls. If @extension{ARB,texture_buffer_object} (part of + * OpenGL 3.1) is not available, returns `0`. + * @see @fn_gl{Get} with @def_gl{MAX_TEXTURE_BUFFER_SIZE} + */ + static Int maxSize(); + /** * @brief Minimum required alignment for texture buffer offsets * @@ -229,8 +239,9 @@ class MAGNUM_EXPORT BufferTexture: public AbstractTexture { * Binds given buffer to this texture. The buffer itself can be then * filled with data of proper format at any time using @ref Buffer "Buffer"'s * own data setting functions. - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexBuffer} - * or @fn_gl_extension{TextureBuffer,EXT,direct_state_access} + * @see @ref maxSize(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @fn_gl{TexBuffer} or + * @fn_gl_extension{TextureBuffer,EXT,direct_state_access} */ BufferTexture& setBuffer(BufferTextureFormat internalFormat, Buffer& buffer); @@ -245,9 +256,10 @@ class MAGNUM_EXPORT BufferTexture: public AbstractTexture { * Binds range of given buffer to this texture. The buffer itself can * be then filled with data of proper format at any time using @ref Buffer "Buffer"'s * own data setting functions. + * @see @ref maxSize(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @fn_gl{TexBufferRange} or + * @fn_gl_extension{TextureBufferRange,EXT,direct_state_access} * @requires_gl43 %Extension @extension{ARB,texture_buffer_range} - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexBufferRange} - * or @fn_gl_extension{TextureBufferRange,EXT,direct_state_access} */ BufferTexture& setBuffer(BufferTextureFormat internalFormat, Buffer& buffer, GLintptr offset, GLsizeiptr size); diff --git a/src/Magnum/CMakeLists.txt b/src/Magnum/CMakeLists.txt index a9ef0bf8c..765addc03 100644 --- a/src/Magnum/CMakeLists.txt +++ b/src/Magnum/CMakeLists.txt @@ -35,6 +35,7 @@ set(Magnum_SRCS AbstractShaderProgram.cpp Buffer.cpp ColorFormat.cpp + CubeMapTexture.cpp Context.cpp DebugMessage.cpp DefaultFramebuffer.cpp @@ -49,6 +50,7 @@ set(Magnum_SRCS Resource.cpp Sampler.cpp Shader.cpp + Texture.cpp Timeline.cpp Version.cpp @@ -60,6 +62,7 @@ set(Magnum_SRCS Implementation/ShaderProgramState.cpp Implementation/State.cpp Implementation/TextureState.cpp + Implementation/maxTextureSize.cpp Implementation/setupDriverWorkarounds.cpp Trade/AbstractImageConverter.cpp @@ -130,6 +133,9 @@ if(NOT TARGET_GLES) RectangleTexture.h) set(Magnum_SRCS ${Magnum_SRCS} BufferTexture.cpp + CubeMapTextureArray.cpp + MultisampleTexture.cpp + RectangleTexture.cpp $) endif() @@ -139,7 +145,8 @@ if(NOT TARGET_GLES2) BufferImage.h TextureArray.h) set(Magnum_SRCS ${Magnum_SRCS} - BufferImage.cpp) + BufferImage.cpp + TextureArray.cpp) endif() # Files shared between main library and math unit test library diff --git a/src/Magnum/CubeMapTexture.cpp b/src/Magnum/CubeMapTexture.cpp new file mode 100644 index 000000000..f53d297d4 --- /dev/null +++ b/src/Magnum/CubeMapTexture.cpp @@ -0,0 +1,36 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "CubeMapTexture.h" + +#include "Implementation/maxTextureSize.h" + +namespace Magnum { + +Vector2i CubeMapTexture::maxSize() { + return Vector2i{Implementation::maxCubeMapTextureSideSize()}; +} + +} diff --git a/src/Magnum/CubeMapTexture.h b/src/Magnum/CubeMapTexture.h index b3b8f4574..b784d5104 100644 --- a/src/Magnum/CubeMapTexture.h +++ b/src/Magnum/CubeMapTexture.h @@ -79,7 +79,7 @@ which intersects one of the six sides of the cube map. See @ref Texture, @ref TextureArray, @ref RectangleTexture, @ref BufferTexture, @ref MultisampleTexture */ -class CubeMapTexture: public AbstractTexture { +class MAGNUM_EXPORT CubeMapTexture: public AbstractTexture { public: /** @brief Cube map coordinate */ enum class Coordinate: GLenum { @@ -91,6 +91,15 @@ class CubeMapTexture: public AbstractTexture { NegativeZ = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z /**< -Z cube side */ }; + /** + * @brief Max supported size of one side of cube map texture + * + * The result is cached, repeated queries don't result in repeated + * OpenGL calls. + * @see @fn_gl{Get} with @def_gl{MAX_CUBE_MAP_TEXTURE_SIZE} + */ + static Vector2i maxSize(); + /** * @brief Constructor * @@ -205,6 +214,7 @@ class CubeMapTexture: public AbstractTexture { * @brief Set storage * * See @ref Texture::setStorage() for more information. + * @see @ref maxSize() */ CubeMapTexture& setStorage(Int levels, TextureFormat internalFormat, const Vector2i& size) { DataHelper<2>::setStorage(*this, _target, levels, internalFormat, size); @@ -251,6 +261,7 @@ class CubeMapTexture: public AbstractTexture { * @return Reference to self (for method chaining) * * See @ref Texture::setImage() for more information. + * @see @ref maxSize() */ CubeMapTexture& setImage(Coordinate coordinate, Int level, TextureFormat internalFormat, const ImageReference2D& image) { DataHelper<2>::setImage(*this, GLenum(coordinate), level, internalFormat, image); diff --git a/src/Magnum/CubeMapTextureArray.cpp b/src/Magnum/CubeMapTextureArray.cpp new file mode 100644 index 000000000..6a0866716 --- /dev/null +++ b/src/Magnum/CubeMapTextureArray.cpp @@ -0,0 +1,45 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "CubeMapTextureArray.h" + +#ifndef MAGNUM_TARGET_GLES +#include "Magnum/Context.h" +#include "Magnum/Extensions.h" + +#include "Implementation/maxTextureSize.h" + +namespace Magnum { + +Vector3i CubeMapTextureArray::maxSize() { + if(!Context::current()->isExtensionSupported()) + return {}; + + return Vector3i{Vector2i{Implementation::maxCubeMapTextureSideSize()}, + Implementation::maxTextureArrayLayers()}; +} + +} +#endif diff --git a/src/Magnum/CubeMapTextureArray.h b/src/Magnum/CubeMapTextureArray.h index ddf173da8..f30f5b537 100644 --- a/src/Magnum/CubeMapTextureArray.h +++ b/src/Magnum/CubeMapTextureArray.h @@ -92,6 +92,17 @@ class CubeMapTextureArray: public AbstractTexture { */ explicit CubeMapTextureArray(): AbstractTexture(GL_TEXTURE_CUBE_MAP_ARRAY) {} + /** + * @brief Max supported size of one side of cube map texture array + * + * The result is cached, repeated queries don't result in repeated + * OpenGL calls. If @extension{ARB,texture_cube_map_array} (part of + * OpenGL 4.0) is not available, returns zero vector. + * @see @fn_gl{Get} with @def_gl{MAX_CUBE_MAP_TEXTURE_SIZE} and + * @def_gl{MAX_ARRAY_TEXTURE_LAYERS} + */ + static Vector3i maxSize(); + /** * @brief Set base mip level * @return Reference to self (for method chaining) @@ -230,6 +241,7 @@ class CubeMapTextureArray: public AbstractTexture { * * Z coordinate of @p size must be multiple of 6. See * @ref Texture::setStorage() for more information. + * @see @ref maxSize() */ CubeMapTextureArray& setStorage(Int levels, TextureFormat internalFormat, const Vector3i& size) { DataHelper<3>::setStorage(*this, _target, levels, internalFormat, size); @@ -274,6 +286,7 @@ class CubeMapTextureArray: public AbstractTexture { * images are in order of (+X, -X, +Y, -Y, +Z, -Z). * * See @ref Texture::setImage() for more information. + * @see @ref maxSize() */ CubeMapTextureArray& setImage(Int level, TextureFormat internalFormat, const ImageReference3D& image) { DataHelper<3>::setImage(*this, GL_TEXTURE_CUBE_MAP_ARRAY, level, internalFormat, image); diff --git a/src/Magnum/Implementation/TextureState.h b/src/Magnum/Implementation/TextureState.h index 28b5335d5..9e44a68aa 100644 --- a/src/Magnum/Implementation/TextureState.h +++ b/src/Magnum/Implementation/TextureState.h @@ -74,6 +74,14 @@ struct TextureState { void(BufferTexture::*setBufferRangeImplementation)(BufferTextureFormat, Buffer&, GLintptr, GLsizeiptr); #endif + GLint maxSize, + max3DSize, + maxArrayLayers, + maxCubeMapSize; + #ifndef MAGNUM_TARGET_GLES + GLint maxRectangleSize, + maxBufferSize; + #endif GLint maxTextureUnits; GLfloat maxLodBias, maxMaxAnisotropy; diff --git a/src/Magnum/Implementation/maxTextureSize.cpp b/src/Magnum/Implementation/maxTextureSize.cpp new file mode 100644 index 000000000..e43b78c70 --- /dev/null +++ b/src/Magnum/Implementation/maxTextureSize.cpp @@ -0,0 +1,77 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "maxTextureSize.h" + +#include "Magnum/Context.h" + +#include "State.h" +#include "TextureState.h" + +namespace Magnum { namespace Implementation { + +GLint maxTextureSideSize() { + GLint& value = Context::current()->state().texture->maxSize; + + if(value == 0) + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value); + + return value; +} + +GLint max3DTextureDepth() { + GLint& value = Context::current()->state().texture->max3DSize; + + if(value == 0) + #ifndef MAGNUM_TARGET_GLES2 + glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE, &value); + #else + glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_OES, &value); + #endif + + return value; +} + +#ifndef MAGNUM_TARGET_GLES2 +GLint maxTextureArrayLayers() { + GLint& value = Context::current()->state().texture->maxArrayLayers; + + if(value == 0) + glGetIntegerv(GL_MAX_ARRAY_TEXTURE_LAYERS, &value); + + return value; +} +#endif + +GLint maxCubeMapTextureSideSize() { + GLint& value = Context::current()->state().texture->maxCubeMapSize; + + if(value == 0) + glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE, &value); + + return value; +} + +}} diff --git a/src/Magnum/Implementation/maxTextureSize.h b/src/Magnum/Implementation/maxTextureSize.h new file mode 100644 index 000000000..b269c1463 --- /dev/null +++ b/src/Magnum/Implementation/maxTextureSize.h @@ -0,0 +1,39 @@ +#ifndef Magnum_Implementation_maxTextureSize_h +#define Magnum_Implementation_maxTextureSize_h +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Magnum/OpenGL.h" + +namespace Magnum { namespace Implementation { + +GLint maxTextureSideSize(); +GLint max3DTextureDepth(); +GLint maxTextureArrayLayers(); +GLint maxCubeMapTextureSideSize(); + +}} + +#endif diff --git a/src/Magnum/MultisampleTexture.cpp b/src/Magnum/MultisampleTexture.cpp new file mode 100644 index 000000000..7705168ce --- /dev/null +++ b/src/Magnum/MultisampleTexture.cpp @@ -0,0 +1,51 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "MultisampleTexture.h" + +#ifndef MAGNUM_TARGET_GLES +#include "Magnum/Context.h" +#include "Magnum/Extensions.h" + +#include "Implementation/maxTextureSize.h" + +namespace Magnum { namespace Implementation { + +template<> Vector2i MAGNUM_EXPORT maxMultisampleTextureSize<2>() { + if(!Context::current()->isExtensionSupported()) + return {}; + + return Vector2i{Implementation::maxTextureSideSize()}; +} + +template<> Vector3i MAGNUM_EXPORT maxMultisampleTextureSize<3>() { + if(!Context::current()->isExtensionSupported()) + return {}; + + return {Vector2i{Implementation::maxTextureSideSize()}, Implementation::max3DTextureDepth()}; +} + +}} +#endif diff --git a/src/Magnum/MultisampleTexture.h b/src/Magnum/MultisampleTexture.h index 1d3a9549f..882aaff60 100644 --- a/src/Magnum/MultisampleTexture.h +++ b/src/Magnum/MultisampleTexture.h @@ -42,6 +42,10 @@ namespace Implementation { template constexpr GLenum multisampleTextureTarget(); template<> inline constexpr GLenum multisampleTextureTarget<2>() { return GL_TEXTURE_2D_MULTISAMPLE; } template<> inline constexpr GLenum multisampleTextureTarget<3>() { return GL_TEXTURE_2D_MULTISAMPLE_ARRAY; } + + template typename DimensionTraits::VectorType maxMultisampleTextureSize(); + template<> Vector2i maxMultisampleTextureSize<2>(); + template<> Vector3i maxMultisampleTextureSize<3>(); } /** @@ -85,6 +89,19 @@ template class MultisampleTexture: public AbstractTextur public: static const UnsignedInt Dimensions = dimensions; /**< @brief %Texture dimension count */ + /** + * @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. + * @see @fn_gl{Get} with @def_gl{MAX_TEXTURE_SIZE} and + * @def_gl{MAX_3D_TEXTURE_SIZE} + */ + static typename DimensionTraits::VectorType maxSize() { + return Implementation::maxMultisampleTextureSize(); + } + /** * @brief Constructor * @@ -127,7 +144,7 @@ template class MultisampleTexture: public AbstractTextur * @extension{ARB,texture_storage} functionality (which unfortunately * doesn't have any DSA alternative, so the texture must be bound * to some texture unit before). - * @see @ref maxColorSamples(), @ref maxDepthSamples(), + * @see @ref maxSize(), @ref maxColorSamples(), @ref maxDepthSamples(), * @ref maxIntegerSamples(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} * and @fn_gl{TexStorage2DMultisample}/@fn_gl{TexStorage3DMultisample} * or @fn_gl_extension{TextureStorage2DMultisample,EXT,direct_state_access}/ diff --git a/src/Magnum/RectangleTexture.cpp b/src/Magnum/RectangleTexture.cpp new file mode 100644 index 000000000..8fcf6ec00 --- /dev/null +++ b/src/Magnum/RectangleTexture.cpp @@ -0,0 +1,50 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "RectangleTexture.h" + +#ifndef MAGNUM_TARGET_GLES +#include "Magnum/Context.h" +#include "Magnum/Extensions.h" + +#include "Implementation/State.h" +#include "Implementation/TextureState.h" + +namespace Magnum { + +Vector2i RectangleTexture::maxSize() { + if(!Context::current()->isExtensionSupported()) + return {}; + + GLint& value = Context::current()->state().texture->maxRectangleSize; + + if(value == 0) + glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE, &value); + + return Vector2i{value}; +} + +} +#endif diff --git a/src/Magnum/RectangleTexture.h b/src/Magnum/RectangleTexture.h index 452fdfe75..15bcbab2c 100644 --- a/src/Magnum/RectangleTexture.h +++ b/src/Magnum/RectangleTexture.h @@ -68,8 +68,18 @@ documentation for more information about usage in shaders. @requires_gl31 %Extension @extension{ARB,texture_rectangle} @requires_gl Rectangle textures are not available in OpenGL ES. */ -class RectangleTexture: public AbstractTexture { +class MAGNUM_EXPORT RectangleTexture: public AbstractTexture { public: + /** + * @brief Max supported rectangle texture size + * + * The result is cached, repeated queries don't result in repeated + * OpenGL calls. If @extension{ARB,texture_rectangle} (part of + * OpenGL 3.1) is not available, returns zero vector. + * @see @fn_gl{Get} with @def_gl{MAX_RECTANGLE_TEXTURE_SIZE} + */ + static Vector2i maxSize(); + /** * @brief Constructor * @@ -205,8 +215,9 @@ class RectangleTexture: public AbstractTexture { * @extension{ARB,texture_storage} (part of OpenGL 4.2), OpenGL ES 3.0 * or @es_extension{EXT,texture_storage} in OpenGL ES 2.0 is not * available, the feature is emulated with @ref setImage() call. - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexStorage2D} - * or @fn_gl_extension{TextureStorage2D,EXT,direct_state_access}, + * @see @ref maxSize(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @fn_gl{TexStorage2D} or + * @fn_gl_extension{TextureStorage2D,EXT,direct_state_access}, * eventually @fn_gl{TexImage2D} or * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}. */ @@ -263,8 +274,9 @@ class RectangleTexture: public AbstractTexture { * * If @extension{EXT,direct_state_access} is not available, the * texture is bound to some texture unit before the operation. - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and @fn_gl{TexImage2D} - * or @fn_gl_extension{TextureImage2D,EXT,direct_state_access} + * @see @ref maxSize(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @fn_gl{TexImage2D} or + * @fn_gl_extension{TextureImage2D,EXT,direct_state_access} */ RectangleTexture& setImage(TextureFormat internalFormat, const ImageReference2D& image) { DataHelper<2>::setImage(*this, _target, 0, internalFormat, image); diff --git a/src/Magnum/Texture.cpp b/src/Magnum/Texture.cpp new file mode 100644 index 000000000..a7566f218 --- /dev/null +++ b/src/Magnum/Texture.cpp @@ -0,0 +1,54 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "Texture.h" + +#include "Magnum/Context.h" +#include "Magnum/Extensions.h" + +#include "Implementation/maxTextureSize.h" +#include "Implementation/State.h" +#include "Implementation/TextureState.h" + +namespace Magnum { namespace Implementation { + +template typename DimensionTraits::VectorType maxTextureSize() { + return typename DimensionTraits::VectorType{Implementation::maxTextureSideSize()}; +} + +#ifndef MAGNUM_TARGET_GLES +template MAGNUM_EXPORT Math::Vector<1, Int> maxTextureSize<1>(); +#endif +template MAGNUM_EXPORT Vector2i maxTextureSize<2>(); + +template<> MAGNUM_EXPORT Vector3i maxTextureSize<3>() { + #ifdef MAGNUM_TARGET_GLES2 + if(!Context::current()->isExtensionSupported()) + return {}; + #endif + return {Vector2i(Implementation::maxTextureSideSize()), Implementation::max3DTextureDepth()}; +} + +}} diff --git a/src/Magnum/Texture.h b/src/Magnum/Texture.h index 85ad55cb6..3badc846c 100644 --- a/src/Magnum/Texture.h +++ b/src/Magnum/Texture.h @@ -51,6 +51,9 @@ namespace Implementation { return GL_TEXTURE_3D_OES; #endif } + + template typename DimensionTraits::VectorType maxTextureSize(); + template<> Vector3i maxTextureSize<3>(); } /** @@ -139,6 +142,20 @@ template class Texture: public AbstractTexture { #endif #endif + /** + * @brief Max supported texture size + * + * The result is cached, repeated queries don't result in repeated + * OpenGL calls. For 3D textures in OpenGL ES 2.0, if + * @es_extension{OES,texture_3D} extension is not available, returns + * zero vector. + * @see @fn_gl{Get} with @def_gl{MAX_TEXTURE_SIZE}, + * @def_gl{MAX_3D_TEXTURE_SIZE} + */ + static typename DimensionTraits::VectorType maxSize() { + return Implementation::maxTextureSize(); + } + /** * @brief Constructor * @@ -466,13 +483,14 @@ template class Texture: public AbstractTexture { * calls. * @todo allow the user to specify ColorType explicitly to avoid * issues in WebGL (see setSubImage()) - * @see @ref setMaxLevel(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} - * and @fn_gl{TexStorage1D}/@fn_gl{TexStorage2D}/@fn_gl{TexStorage3D} + * @see @ref maxSize(), @ref setMaxLevel(), @fn_gl{ActiveTexture}, + * @fn_gl{BindTexture} and + * @fn_gl{TexStorage1D}/@fn_gl{TexStorage2D}/@fn_gl{TexStorage3D} * or @fn_gl_extension{TextureStorage1D,EXT,direct_state_access}/ * @fn_gl_extension{TextureStorage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureStorage3D,EXT,direct_state_access}, - * eventually @fn_gl{TexImage1D}/@fn_gl{TexImage2D}/@fn_gl{TexImage3D} or - * @fn_gl_extension{TextureImage1D,EXT,direct_state_access}/ + * eventually @fn_gl{TexImage1D}/@fn_gl{TexImage2D}/@fn_gl{TexImage3D} + * or @fn_gl_extension{TextureImage1D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage3D,EXT,direct_state_access} */ @@ -537,7 +555,7 @@ template class Texture: public AbstractTexture { * * If @extension{EXT,direct_state_access} is not available, the * texture is bound to some texture unit before the operation. - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @see @ref maxSize(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and * @fn_gl{TexImage1D}/@fn_gl{TexImage2D}/@fn_gl{TexImage3D} or * @fn_gl_extension{TextureImage1D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ diff --git a/src/Magnum/TextureArray.cpp b/src/Magnum/TextureArray.cpp new file mode 100644 index 000000000..fafd9d47b --- /dev/null +++ b/src/Magnum/TextureArray.cpp @@ -0,0 +1,58 @@ +/* + This file is part of Magnum. + + Copyright © 2010, 2011, 2012, 2013, 2014 + Vladimír Vondruš + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +*/ + +#include "TextureArray.h" + +#ifndef MAGNUM_TARGET_GLES2 +#include "Magnum/Context.h" +#include "Magnum/Extensions.h" + +#include "Implementation/maxTextureSize.h" + +namespace Magnum { + +namespace { + template struct VectorOrScalar; + template<> struct VectorOrScalar<1> { typedef Int Type; }; + template<> struct VectorOrScalar<2> { typedef Vector2i Type; }; +} + +template typename DimensionTraits::VectorType TextureArray::maxSize() { + #ifndef MAGNUM_TARGET_GLES + if(!Context::current()->isExtensionSupported()) + return {}; + #endif + + return {typename VectorOrScalar::Type{Implementation::maxTextureSideSize()}, + Implementation::maxTextureArrayLayers()}; +} + +#ifndef MAGNUM_TARGET_GLES +template class MAGNUM_EXPORT TextureArray<1>; +#endif +template class MAGNUM_EXPORT TextureArray<2>; + +} +#endif diff --git a/src/Magnum/TextureArray.h b/src/Magnum/TextureArray.h index ce8413b60..8816425d9 100644 --- a/src/Magnum/TextureArray.h +++ b/src/Magnum/TextureArray.h @@ -95,6 +95,17 @@ template class TextureArray: public AbstractTexture { public: static const UnsignedInt Dimensions = dimensions; /**< @brief %Texture dimension count */ + /** + * @brief Max supported texture array size + * + * The result is cached, repeated queries don't result in repeated + * OpenGL calls. If extension @extension{EXT,texture_array} (part of + * OpenGL 3.0) is not available, returns zero vector. + * @see @fn_gl{Get} with @def_gl{MAX_TEXTURE_SIZE} and + * @def_gl{MAX_ARRAY_TEXTURE_LAYERS} + */ + static typename DimensionTraits::VectorType maxSize(); + /** * @brief Constructor * @@ -217,7 +228,7 @@ template class TextureArray: public AbstractTexture { * @extension{ARB,texture_storage} (part of OpenGL 4.2) or OpenGL ES * 3.0 is not available, the feature is emulated with sequence of * @ref setImage() calls. - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @see @ref maxSize(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and * @fn_gl{TexStorage2D}/@fn_gl{TexStorage3D} or * @fn_gl_extension{TextureStorage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureStorage3D,EXT,direct_state_access}, @@ -256,7 +267,7 @@ template class TextureArray: public AbstractTexture { * * If @extension{EXT,direct_state_access} is not available, the * texture is bound to some texture unit before the operation. - * @see @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and + * @see @ref maxSize(), @fn_gl{ActiveTexture}, @fn_gl{BindTexture} and * @fn_gl{TexImage2D}/@fn_gl{TexImage3D} or * @fn_gl_extension{TextureImage2D,EXT,direct_state_access}/ * @fn_gl_extension{TextureImage3D,EXT,direct_state_access}