diff --git a/include/SFML/Graphics/RenderTexture.h b/include/SFML/Graphics/RenderTexture.h index 754aacf..71a873e 100644 --- a/include/SFML/Graphics/RenderTexture.h +++ b/include/SFML/Graphics/RenderTexture.h @@ -316,4 +316,20 @@ CSFML_GRAPHICS_API void sfRenderTexture_setRepeated(sfRenderTexture* renderTextu //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfBool sfRenderTexture_isRepeated(const sfRenderTexture* renderTexture); +//////////////////////////////////////////////////////////// +/// \brief Generate a mipmap using the current texture data +/// +/// This function is similar to sfTexture_generateMipmap and operates +/// on the texture used as the target for drawing. +/// Be aware that any draw operation may modify the base level image data. +/// For this reason, calling this function only makes sense after all +/// drawing is completed and display has been called. Not calling display +/// after subsequent drawing will lead to undefined behavior if a mipmap +/// had been previously generated. +/// +/// \return sfTrue if mipmap generation was successful, sfFalse if unsuccessful +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfBool sfRenderTexture_generateMipmap(sfRenderTexture* renderTexture); + #endif // SFML_RENDERTEXTURE_H diff --git a/include/SFML/Graphics/Texture.h b/include/SFML/Graphics/Texture.h index 052bf1a..3c83527 100644 --- a/include/SFML/Graphics/Texture.h +++ b/include/SFML/Graphics/Texture.h @@ -264,6 +264,31 @@ CSFML_GRAPHICS_API void sfTexture_setRepeated(sfTexture* texture, sfBool repeate //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfBool sfTexture_isRepeated(const sfTexture* texture); +//////////////////////////////////////////////////////////// +/// \brief Generate a mipmap using the current texture data +/// +/// Mipmaps are pre-computed chains of optimized textures. Each +/// level of texture in a mipmap is generated by halving each of +/// the previous level's dimensions. This is done until the final +/// level has the size of 1x1. The textures generated in this process may +/// make use of more advanced filters which might improve the visual quality +/// of textures when they are applied to objects much smaller than they are. +/// This is known as minification. Because fewer texels (texture elements) +/// have to be sampled from when heavily minified, usage of mipmaps +/// can also improve rendering performance in certain scenarios. +/// +/// Mipmap generation relies on the necessary OpenGL extension being +/// available. If it is unavailable or generation fails due to another +/// reason, this function will return false. Mipmap data is only valid from +/// the time it is generated until the next time the base level image is +/// modified, at which point this function will have to be called again to +/// regenerate it. +/// +/// \return sfTrue if mipmap generation was successful, sfFalse if unsuccessful +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfBool sfTexture_generateMipmap(sfTexture* texture); + //////////////////////////////////////////////////////////// /// \brief Get the underlying OpenGL handle of the texture. /// diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index d80b13f..57b5554 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -281,3 +281,10 @@ sfBool sfRenderTexture_isRepeated(const sfRenderTexture* renderTexture) { CSFML_CALL_RETURN(renderTexture, isRepeated(), sfFalse); } + + +//////////////////////////////////////////////////////////// +sfBool sfRenderTexture_generateMipmap(sfRenderTexture* renderTexture) +{ + CSFML_CALL_RETURN(renderTexture, generateMipmap(), sfFalse); +} diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index ef440bb..a224351 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -256,6 +256,13 @@ sfBool sfTexture_isRepeated(const sfTexture* texture) } +//////////////////////////////////////////////////////////// +sfBool sfTexture_generateMipmap(sfTexture* texture) +{ + CSFML_CALL_PTR_RETURN(texture, generateMipmap(), sfFalse); +} + + //////////////////////////////////////////////////////////// unsigned int sfTexture_getNativeHandle(const sfTexture* texture) {