|
| 1 | +#pragma once |
| 2 | +#include <SFML/Graphics/StencilMode.hpp> |
| 3 | + |
| 4 | +//////////////////////////////////////////////////////// |
| 5 | +/// \brief Enumeration of the stencil test comparisons that can be performed |
| 6 | +/// |
| 7 | +/// The comparisons are mapped directly to their OpenGL equivalents, |
| 8 | +/// specified by `glStencilFunc()`. |
| 9 | +//////////////////////////////////////////////////////// |
| 10 | +typedef enum { |
| 11 | + sfStencilComparisonNever, //!< The stencil test never passes |
| 12 | + sfStencilComparisonLess, //!< The stencil test passes if the new value is less than the value in the stencil buffer |
| 13 | + sfStencilComparisonLessEqual, //!< The stencil test passes if the new value is less than or equal to the value in the stencil buffer |
| 14 | + sfStencilComparisonGreater, //!< The stencil test passes if the new value is greater than the value in the stencil buffer |
| 15 | + sfStencilComparisonGreaterEqual, //!< The stencil test passes if the new value is greater than or equal to the value in the stencil buffer |
| 16 | + sfStencilComparisonEqual, //!< The stencil test passes if the new value is strictly equal to the value in the stencil buffer |
| 17 | + sfStencilComparisonNotEqual, //!< The stencil test passes if the new value is strictly unequal to the value in the stencil buffer |
| 18 | + sfStencilComparisonAlways //!< The stencil test always passes |
| 19 | +} sfStencilComparison; |
| 20 | + |
| 21 | +//////////////////////////////////////////////////////// |
| 22 | +/// \brief Enumeration of the stencil buffer update operations |
| 23 | +/// |
| 24 | +/// The update operations are mapped directly to their OpenGL equivalents, |
| 25 | +/// specified by `glStencilOp()`. |
| 26 | +//////////////////////////////////////////////////////// |
| 27 | +typedef enum { |
| 28 | + sfStencilUpdateOperationKeep, //!< If the stencil test passes, the value in the stencil buffer is not modified |
| 29 | + sfStencilUpdateOperationZero, //!< If the stencil test passes, the value in the stencil buffer is set to zero |
| 30 | + sfStencilUpdateOperationReplace, //!< If the stencil test passes, the value in the stencil buffer is set to the new value |
| 31 | + sfStencilUpdateOperationIncrement, //!< If the stencil test passes, the value in the stencil buffer is incremented and if required clamped |
| 32 | + sfStencilUpdateOperationDecrement, //!< If the stencil test passes, the value in the stencil buffer is decremented and if required clamped |
| 33 | + sfStencilUpdateOperationInvert, //!< If the stencil test passes, the value in the stencil buffer is bitwise inverted |
| 34 | +} sfStencilUpdateOperation; |
| 35 | + |
| 36 | +//////////////////////////////////////////////////////// |
| 37 | +/// \brief Stencil value type (also used as a mask) |
| 38 | +/// |
| 39 | +//////////////////////////////////////////////////////// |
| 40 | +typedef struct |
| 41 | +{ |
| 42 | + unsigned int value; //!< The stored stencil value |
| 43 | +} sfStencilValue; |
| 44 | + |
| 45 | +//////////////////////////////////////////////////////////// |
| 46 | +/// \brief Stencil modes for drawing |
| 47 | +/// |
| 48 | +//////////////////////////////////////////////////////////// |
| 49 | +typedef struct |
| 50 | +{ |
| 51 | + sfStencilComparison stencilComparison; //!< The comparison we're performing the stencil test with |
| 52 | + sfStencilUpdateOperation stencilUpdateOperation; //!< The update operation to perform if the stencil test passes |
| 53 | + sfStencilValue stencilReference; //!< The reference value we're performing the stencil test with |
| 54 | + sfStencilValue stencilMask; //!< The mask to apply to both the reference value and the value in the stencil buffer |
| 55 | + bool stencilOnly; //!< Whether we should update the color buffer in addition to the stencil buffer |
| 56 | +} sfStencilMode; |
| 57 | + |
| 58 | +//////////////////////////////////////////////////////////// |
| 59 | +// Convert sf::StencilValue to sfStencilValue |
| 60 | +//////////////////////////////////////////////////////////// |
| 61 | +[[nodiscard]] inline sfStencilValue convertStencilValue(const sf::StencilValue value) { |
| 62 | + return {value.value}; |
| 63 | +} |
| 64 | + |
| 65 | +//////////////////////////////////////////////////////////// |
| 66 | +// Convert sfStencilValue to sf::StencilValue |
| 67 | +//////////////////////////////////////////////////////////// |
| 68 | +[[nodiscard]] inline sf::StencilValue convertStencilValue(const sfStencilValue value) { |
| 69 | + return {value.value}; |
| 70 | +} |
| 71 | + |
| 72 | +//////////////////////////////////////////////////////////// |
| 73 | +// Convert sf::StencilMode to sfStencilMode |
| 74 | +//////////////////////////////////////////////////////////// |
| 75 | +[[nodiscard]] inline sfStencilMode convertStencilMode(const sf::StencilMode value) { |
| 76 | + return {static_cast<sfStencilComparison>(value.stencilComparison), |
| 77 | + static_cast<sfStencilUpdateOperation>(value.stencilUpdateOperation), |
| 78 | + convertStencilValue(value.stencilReference), |
| 79 | + convertStencilValue(value.stencilMask), |
| 80 | + value.stencilOnly}; |
| 81 | +} |
| 82 | + |
| 83 | +//////////////////////////////////////////////////////////// |
| 84 | +// Convert sfStencilMode to sf::StencilMode |
| 85 | +//////////////////////////////////////////////////////////// |
| 86 | +[[nodiscard]] inline sf::StencilMode convertStencilMode(const sfStencilMode value) { |
| 87 | + return {static_cast<sf::StencilComparison>(value.stencilComparison), |
| 88 | + static_cast<sf::StencilUpdateOperation>(value.stencilUpdateOperation), |
| 89 | + convertStencilValue(value.stencilReference), |
| 90 | + convertStencilValue(value.stencilMask), |
| 91 | + value.stencilOnly}; |
| 92 | +} |
0 commit comments