From 300152424a15a9e52cc9ca8c34cfcd3db90fc3c5 Mon Sep 17 00:00:00 2001 From: Miron Alexandru Date: Sat, 5 Oct 2024 21:37:11 +0300 Subject: [PATCH] Align sfRenderStates with sf::RenderStates --- include/CSFML/Graphics/CoordinateType.h | 35 ++++++++++++++++++++++ include/CSFML/Graphics/RenderStates.h | 12 +++++--- include/CSFML/Graphics/Texture.h | 13 ++------ src/CSFML/Graphics/CMakeLists.txt | 1 + src/CSFML/Graphics/ConvertRenderStates.hpp | 25 ++++++++++------ src/CSFML/Graphics/RenderStates.cpp | 2 ++ src/CSFML/Graphics/Texture.cpp | 2 +- 7 files changed, 65 insertions(+), 25 deletions(-) create mode 100644 include/CSFML/Graphics/CoordinateType.h diff --git a/include/CSFML/Graphics/CoordinateType.h b/include/CSFML/Graphics/CoordinateType.h new file mode 100644 index 00000000..9bc6b563 --- /dev/null +++ b/include/CSFML/Graphics/CoordinateType.h @@ -0,0 +1,35 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#pragma once + +//////////////////////////////////////////////////////////// +/// \brief Types of texture coordinates that can be used for rendering. +/// +//////////////////////////////////////////////////////////// +typedef enum +{ + sfCoordinateTypeNormalized, ///< sfTexture coordinates in range [0 .. 1]. + sfCoordinateTypePixels ///< sfTexture coordinates in range [0 .. size]. +} sfCoordinateType; diff --git a/include/CSFML/Graphics/RenderStates.h b/include/CSFML/Graphics/RenderStates.h index 4bb0ff30..c1474a49 100644 --- a/include/CSFML/Graphics/RenderStates.h +++ b/include/CSFML/Graphics/RenderStates.h @@ -30,6 +30,8 @@ #include #include +#include +#include #include #include @@ -40,10 +42,12 @@ //////////////////////////////////////////////////////////// typedef struct { - sfBlendMode blendMode; ///< Blending mode - sfTransform transform; ///< Transform - const sfTexture* texture; ///< Texture - const sfShader* shader; ///< Shader + sfBlendMode blendMode; ///< Blending mode + sfStencilMode stencilMode; //!< Stencil mode + sfTransform transform; ///< Transform + sfCoordinateType coordinateType; //!< Texture coordinate type + const sfTexture* texture; ///< Texture + const sfShader* shader; ///< Shader } sfRenderStates; //////////////////////////////////////////////////////////// diff --git a/include/CSFML/Graphics/Texture.h b/include/CSFML/Graphics/Texture.h index 3fa50857..c9fde23e 100644 --- a/include/CSFML/Graphics/Texture.h +++ b/include/CSFML/Graphics/Texture.h @@ -29,6 +29,7 @@ //////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -37,16 +38,6 @@ #include -//////////////////////////////////////////////////////////// -/// \brief Types of texture coordinates that can be used for rendering. -/// -//////////////////////////////////////////////////////////// -typedef enum -{ - sfTextureNormalized, ///< sfTexture coordinates in range [0 .. 1]. - sfTexturePixels ///< sfTexture coordinates in range [0 .. size]. -} sfTextureCoordinateType; - //////////////////////////////////////////////////////////// /// \brief Create a new texture /// @@ -400,7 +391,7 @@ CSFML_GRAPHICS_API unsigned int sfTexture_getNativeHandle(const sfTexture* textu /// \param type Type of texture coordinates to use /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfTexture_bind(const sfTexture* texture, sfTextureCoordinateType type); +CSFML_GRAPHICS_API void sfTexture_bind(const sfTexture* texture, sfCoordinateType type); //////////////////////////////////////////////////////////// /// \brief Get the maximum texture size allowed diff --git a/src/CSFML/Graphics/CMakeLists.txt b/src/CSFML/Graphics/CMakeLists.txt index 83142015..e3e056ec 100644 --- a/src/CSFML/Graphics/CMakeLists.txt +++ b/src/CSFML/Graphics/CMakeLists.txt @@ -19,6 +19,7 @@ set(SRC ${SRCROOT}/ConvexShape.cpp ${SRCROOT}/ConvexShapeStruct.hpp ${INCROOT}/ConvexShape.h + ${INCROOT}/CoordinateType.h ${SRCROOT}/Font.cpp ${SRCROOT}/FontStruct.hpp ${INCROOT}/Font.h diff --git a/src/CSFML/Graphics/ConvertRenderStates.hpp b/src/CSFML/Graphics/ConvertRenderStates.hpp index 1937ca10..b23138ad 100644 --- a/src/CSFML/Graphics/ConvertRenderStates.hpp +++ b/src/CSFML/Graphics/ConvertRenderStates.hpp @@ -44,14 +44,21 @@ return {}; sf::RenderStates renderStates; - renderStates.blendMode.colorSrcFactor = static_cast(states->blendMode.colorSrcFactor); - renderStates.blendMode.colorDstFactor = static_cast(states->blendMode.colorDstFactor); - renderStates.blendMode.colorEquation = static_cast(states->blendMode.colorEquation); - renderStates.blendMode.alphaSrcFactor = static_cast(states->blendMode.alphaSrcFactor); - renderStates.blendMode.alphaDstFactor = static_cast(states->blendMode.alphaDstFactor); - renderStates.blendMode.alphaEquation = static_cast(states->blendMode.alphaEquation); - renderStates.transform = convertTransform(states->transform); - renderStates.texture = states->texture ? states->texture->This : nullptr; - renderStates.shader = states->shader; + renderStates.blendMode.colorSrcFactor = static_cast(states->blendMode.colorSrcFactor); + renderStates.blendMode.colorDstFactor = static_cast(states->blendMode.colorDstFactor); + renderStates.blendMode.colorEquation = static_cast(states->blendMode.colorEquation); + renderStates.blendMode.alphaSrcFactor = static_cast(states->blendMode.alphaSrcFactor); + renderStates.blendMode.alphaDstFactor = static_cast(states->blendMode.alphaDstFactor); + renderStates.blendMode.alphaEquation = static_cast(states->blendMode.alphaEquation); + renderStates.stencilMode.stencilComparison = static_cast(states->stencilMode.stencilComparison); + renderStates.stencilMode.stencilUpdateOperation = static_cast( + states->stencilMode.stencilUpdateOperation); + renderStates.stencilMode.stencilReference.value = states->stencilMode.stencilReference.value; + renderStates.stencilMode.stencilMask.value = states->stencilMode.stencilMask.value; + renderStates.stencilMode.stencilOnly = states->stencilMode.stencilOnly; + renderStates.transform = convertTransform(states->transform); + renderStates.coordinateType = static_cast(states->coordinateType); + renderStates.texture = states->texture ? states->texture->This : nullptr; + renderStates.shader = states->shader; return renderStates; } diff --git a/src/CSFML/Graphics/RenderStates.cpp b/src/CSFML/Graphics/RenderStates.cpp index d84b5c5d..ed5f83d0 100644 --- a/src/CSFML/Graphics/RenderStates.cpp +++ b/src/CSFML/Graphics/RenderStates.cpp @@ -31,7 +31,9 @@ //////////////////////////////////////////////////////////// const sfRenderStates sfRenderStates_default = { sfBlendAlpha, + sfStencilMode_default, sfTransform_Identity, + sfCoordinateTypePixels, nullptr, nullptr, }; diff --git a/src/CSFML/Graphics/Texture.cpp b/src/CSFML/Graphics/Texture.cpp index 113ca169..4ddc5cc3 100644 --- a/src/CSFML/Graphics/Texture.cpp +++ b/src/CSFML/Graphics/Texture.cpp @@ -299,7 +299,7 @@ unsigned int sfTexture_getNativeHandle(const sfTexture* texture) //////////////////////////////////////////////////////////// -void sfTexture_bind(const sfTexture* texture, sfTextureCoordinateType type) +void sfTexture_bind(const sfTexture* texture, sfCoordinateType type) { sf::Texture::bind(texture ? texture->This : nullptr, static_cast(type)); }