Skip to content

Commit 739957a

Browse files
committed
Get SFML to be ABI compliant
1 parent 0332b04 commit 739957a

15 files changed

+427
-51
lines changed

CSFML/src/Graphics/BlendMode.hpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#pragma once
2+
////////////////////////////////////////////////////////////
3+
/// \brief Enumeration of the blending factors
4+
///
5+
////////////////////////////////////////////////////////////
6+
typedef enum {
7+
sfBlendFactorZero, ///< (0, 0, 0, 0)
8+
sfBlendFactorOne, ///< (1, 1, 1, 1)
9+
sfBlendFactorSrcColor, ///< (src.r, src.g, src.b, src.a)
10+
sfBlendFactorOneMinusSrcColor, ///< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a)
11+
sfBlendFactorDstColor, ///< (dst.r, dst.g, dst.b, dst.a)
12+
sfBlendFactorOneMinusDstColor, ///< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a)
13+
sfBlendFactorSrcAlpha, ///< (src.a, src.a, src.a, src.a)
14+
sfBlendFactorOneMinusSrcAlpha, ///< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a)
15+
sfBlendFactorDstAlpha, ///< (dst.a, dst.a, dst.a, dst.a)
16+
sfBlendFactorOneMinusDstAlpha ///< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a)
17+
} sfBlendFactor;
18+
19+
////////////////////////////////////////////////////////////
20+
/// \brief Enumeration of the blending equations
21+
///
22+
////////////////////////////////////////////////////////////
23+
typedef enum {
24+
sfBlendEquationAdd, ///< Pixel = Src * SrcFactor + Dst * DstFactor
25+
sfBlendEquationSubtract, ///< Pixel = Src * SrcFactor - Dst * DstFactor
26+
sfBlendEquationReverseSubtract, ///< Pixel = Dst * DstFactor - Src * SrcFactor
27+
sfBlendEquationMin, ///< Pixel = min(Dst, Src)
28+
sfBlendEquationMax ///< Pixel = max(Dst, Src)
29+
} sfBlendEquation;
30+
31+
////////////////////////////////////////////////////////////
32+
/// \brief Blending mode for drawing
33+
///
34+
////////////////////////////////////////////////////////////
35+
typedef struct
36+
{
37+
sfBlendFactor colorSrcFactor; ///< Source blending factor for the color channels
38+
sfBlendFactor colorDstFactor; ///< Destination blending factor for the color channels
39+
sfBlendEquation colorEquation; ///< Blending equation for the color channels
40+
sfBlendFactor alphaSrcFactor; ///< Source blending factor for the alpha channel
41+
sfBlendFactor alphaDstFactor; ///< Destination blending factor for the alpha channel
42+
sfBlendEquation alphaEquation; ///< Blending equation for the alpha channel
43+
} sfBlendMode;

CSFML/src/Graphics/CoordinateType.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
////////////////////////////////////////////////////////////
4+
/// \brief Types of texture coordinates that can be used for rendering.
5+
///
6+
////////////////////////////////////////////////////////////
7+
typedef enum {
8+
sfCoordinateTypeNormalized, ///< sfTexture coordinates in range [0 .. 1].
9+
sfCoordinateTypePixels ///< sfTexture coordinates in range [0 .. size].
10+
} sfCoordinateType;

CSFML/src/Graphics/PrimitiveType.hpp

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
typedef enum {
4+
sfPoints,
5+
sfLines,
6+
sfLineStrip,
7+
sfTriangles,
8+
sfTriangleStrip,
9+
sfTriangleFan,
10+
} sfPrimitiveType;

CSFML/src/Graphics/RenderStates.hpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
////////////////////////////////////////////////////////////
2+
/// \brief Define the states used for drawing to a RenderTarget
3+
///
4+
////////////////////////////////////////////////////////////
5+
#include "Graphics/BlendMode.hpp"
6+
#include "Graphics/CoordinateType.hpp"
7+
#include "Graphics/StencilMode.hpp"
8+
#include "Graphics/Transform.hpp"
9+
#include <SFML/Graphics/RenderStates.hpp>
10+
#include <SFML/Graphics/Texture.hpp>
11+
12+
typedef struct
13+
{
14+
sfBlendMode blendMode; ///< Blending mode
15+
sfStencilMode stencilMode; //!< Stencil mode
16+
sfTransform transform; ///< Transform
17+
sfCoordinateType coordinateType; //!< Texture coordinate type
18+
const sf::Texture *texture; ///< Texture
19+
const sf::Shader *shader; ///< Shader
20+
} sfRenderStates;

CSFML/src/Graphics/RenderTexture.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#include "Graphics/PrimitiveType.hpp"
12
#include "Graphics/Rect.hpp"
23
#include "Graphics/Color.hpp"
4+
#include "SFML/Graphics/PrimitiveType.hpp"
35
#include "SFML/Window/ContextSettings.hpp"
46
#include "System/Vector2.hpp"
57
#include <SFML/Graphics/RenderTarget.hpp>
@@ -105,8 +107,8 @@ extern "C" void sfRenderTexture_drawVertexBuffer(sf::RenderTexture *renderTextur
105107

106108
extern "C" void sfRenderTexture_drawPrimitives(sf::RenderTexture *renderTexture,
107109
const sf::Vertex *vertices, size_t vertexCount,
108-
sf::PrimitiveType type, const sf::RenderStates *states) {
109-
renderTexture->draw(vertices, vertexCount, type, *states);
110+
sfPrimitiveType type, const sf::RenderStates *states) {
111+
renderTexture->draw(vertices, vertexCount, static_cast<sf::PrimitiveType>(type), *states);
110112
}
111113

112114
extern "C" void sfRenderTexture_pushGLStates(sf::RenderTexture *renderTexture) {

CSFML/src/Graphics/RenderWindow.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
#include "Graphics/PrimitiveType.hpp"
12
#include "Graphics/Rect.hpp"
23
#include "Graphics/Color.hpp"
4+
#include "SFML/Graphics/PrimitiveType.hpp"
35
#include "System/Vector2.hpp"
46
#include "Window/Event.hpp"
57
#include "Window/VideoMode.hpp"
@@ -15,6 +17,8 @@
1517
#include <SFML/Window/Touch.hpp>
1618
#include <chrono>
1719
#include <cstddef>
20+
// Debug ONLY
21+
#include <iostream>
1822

1923
extern "C" sf::RenderWindow *sfRenderWindow_new_mtsss(sfVideoMode mode, const uint32_t *title, uint32_t style, sfState state, const sf::ContextSettings *settings) {
2024
// Convert video mode
@@ -197,8 +201,8 @@ extern "C" void sfRenderWindow_drawVertexBuffer(sf::RenderWindow *renderWindow,
197201

198202
extern "C" void sfRenderWindow_drawPrimitives(sf::RenderWindow *renderWindow,
199203
const sf::Vertex *vertices, size_t vertexCount,
200-
sf::PrimitiveType type, const sf::RenderStates *states) {
201-
renderWindow->draw(vertices, vertexCount, type, *states);
204+
sfPrimitiveType type, const sf::RenderStates *states) {
205+
renderWindow->draw(vertices, vertexCount, static_cast<sf::PrimitiveType>(type), *states);
202206
}
203207

204208
extern "C" void sfRenderWindow_pushGLStates(sf::RenderWindow *renderWindow) {

CSFML/src/Graphics/StencilMode.hpp

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
}

CSFML/src/Graphics/Transform.hpp

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
////////////////////////////////////////////////////////////
2+
/// \brief Encapsulate a 3x3 transform matrix
3+
///
4+
////////////////////////////////////////////////////////////
5+
#include <SFML/Graphics/Transform.hpp>
6+
typedef struct
7+
{
8+
float matrix[9];
9+
} sfTransform;
10+
11+
////////////////////////////////////////////////////////////
12+
// Convert sf::Transform to sfTransform
13+
////////////////////////////////////////////////////////////
14+
[[nodiscard]] inline sfTransform convertTransform(const sf::Transform &transform) {
15+
const float *m = transform.getMatrix();
16+
return {m[0], m[4], m[12], m[1], m[5], m[13], m[3], m[7], m[15]};
17+
}
18+
19+
////////////////////////////////////////////////////////////
20+
// Convert sfTransform to sf::Transform
21+
////////////////////////////////////////////////////////////
22+
[[nodiscard]] inline sf::Transform convertTransform(const sfTransform &transform) {
23+
const float *m = transform.matrix;
24+
25+
// clang-format off
26+
return {m[0], m[1], m[2],
27+
m[3], m[4], m[5],
28+
m[6], m[7], m[8]};
29+
// clang-format on
30+
}

CSFML/src/Graphics/VertexBuffer.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#include "Graphics/PrimitiveType.hpp"
2+
#include "SFML/Graphics/PrimitiveType.hpp"
13
#include "SFML/Graphics/RenderTarget.hpp"
24
#include <SFML/Graphics/VertexBuffer.hpp>
35
#include <cstddef>
@@ -38,12 +40,12 @@ extern "C" unsigned int sfVertexBuffer_getNativeHandle(const sf::VertexBuffer *v
3840
return vertexBuffer->getNativeHandle();
3941
}
4042

41-
extern "C" void sfVertexBuffer_setPrimitiveType(sf::VertexBuffer *vertexBuffer, sf::PrimitiveType type) {
42-
vertexBuffer->setPrimitiveType(type);
43+
extern "C" void sfVertexBuffer_setPrimitiveType(sf::VertexBuffer *vertexBuffer, sfPrimitiveType type) {
44+
vertexBuffer->setPrimitiveType(static_cast<sf::PrimitiveType>(type));
4345
}
4446

45-
extern "C" sf::PrimitiveType sfVertexBuffer_getPrimitiveType(const sf::VertexBuffer *vertexBuffer) {
46-
return vertexBuffer->getPrimitiveType();
47+
extern "C" sfPrimitiveType sfVertexBuffer_getPrimitiveType(const sf::VertexBuffer *vertexBuffer) {
48+
return static_cast<sfPrimitiveType>(vertexBuffer->getPrimitiveType());
4749
}
4850

4951
extern "C" void sfVertexBuffer_setUsage(sf::VertexBuffer *vertexBuffer, sf::VertexBuffer::Usage usage) {

0 commit comments

Comments
 (0)