Skip to content

Commit 7f81902

Browse files
committed
Implement new graphics, system and window functions
1 parent 70397c6 commit 7f81902

File tree

18 files changed

+528
-81
lines changed

18 files changed

+528
-81
lines changed

include/CSFML/Graphics/RenderTexture.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <CSFML/Graphics/PrimitiveType.h>
3434
#include <CSFML/Graphics/Rect.h>
3535
#include <CSFML/Graphics/RenderStates.h>
36+
#include <CSFML/Graphics/StencilMode.h>
3637
#include <CSFML/Graphics/Types.h>
3738
#include <CSFML/Graphics/Vertex.h>
3839
#include <CSFML/System/Vector2.h>
@@ -108,6 +109,33 @@ CSFML_GRAPHICS_API void sfRenderTexture_display(sfRenderTexture* renderTexture);
108109
////////////////////////////////////////////////////////////
109110
CSFML_GRAPHICS_API void sfRenderTexture_clear(sfRenderTexture* renderTexture, sfColor color);
110111

112+
////////////////////////////////////////////////////////////
113+
/// \brief Clear the stencil buffer to a specific value
114+
///
115+
/// The specified value is truncated to the bit width of
116+
/// the current stencil buffer.
117+
///
118+
/// \param renderTexture Render texture object
119+
/// \param stencilValue Stencil value to clear to
120+
///
121+
////////////////////////////////////////////////////////////
122+
CSFML_GRAPHICS_API void sfRenderTexture_clearStencil(sfRenderTexture* renderTexture, sfStencilValue stencilValue);
123+
124+
////////////////////////////////////////////////////////////
125+
/// \brief Clear the entire target with a single color and stencil value
126+
///
127+
/// The specified stencil value is truncated to the bit
128+
/// width of the current stencil buffer.
129+
///
130+
/// \param renderTexture Render texture object
131+
/// \param color Fill color to use to clear the render target
132+
/// \param stencilValue Stencil value to clear to
133+
///
134+
////////////////////////////////////////////////////////////
135+
CSFML_GRAPHICS_API void sfRenderTexture_clearColorAndStencil(sfRenderTexture* renderTexture,
136+
sfColor color,
137+
sfStencilValue stencilValue);
138+
111139
////////////////////////////////////////////////////////////
112140
/// \brief Change the current active view of a render texture
113141
///
@@ -148,6 +176,22 @@ CSFML_GRAPHICS_API const sfView* sfRenderTexture_getDefaultView(const sfRenderTe
148176
////////////////////////////////////////////////////////////
149177
CSFML_GRAPHICS_API sfIntRect sfRenderTexture_getViewport(const sfRenderTexture* renderTexture, const sfView* view);
150178

179+
////////////////////////////////////////////////////////////
180+
/// \brief Get the scissor rectangle of a view, applied to this render target
181+
///
182+
/// The scissor rectangle is defined in the view as a ratio. This
183+
/// function simply applies this ratio to the current dimensions
184+
/// of the render target to calculate the pixels rectangle
185+
/// that the scissor rectangle actually covers in the target.
186+
///
187+
/// \param renderTexture Render texture object
188+
/// \param view The view for which we want to compute the scissor rectangle
189+
///
190+
/// \return Scissor rectangle, expressed in pixels
191+
///
192+
////////////////////////////////////////////////////////////
193+
CSFML_GRAPHICS_API sfIntRect sfRenderTexture_getScissor(const sfRenderTexture* renderTexture, const sfView* view);
194+
151195
////////////////////////////////////////////////////////////
152196
/// \brief Convert a point from texture coordinates to world coordinates
153197
///

include/CSFML/Graphics/RenderWindow.h

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
#include <CSFML/Graphics/PrimitiveType.h>
3434
#include <CSFML/Graphics/Rect.h>
3535
#include <CSFML/Graphics/RenderStates.h>
36+
#include <CSFML/Graphics/StencilMode.h>
3637
#include <CSFML/Graphics/Types.h>
3738
#include <CSFML/Graphics/Vertex.h>
39+
#include <CSFML/System/Time.h>
3840
#include <CSFML/System/Vector2.h>
3941
#include <CSFML/Window/Event.h>
4042
#include <CSFML/Window/VideoMode.h>
@@ -135,13 +137,28 @@ CSFML_GRAPHICS_API bool sfRenderWindow_pollEvent(sfRenderWindow* renderWindow, s
135137
////////////////////////////////////////////////////////////
136138
/// \brief Wait for an event and return it
137139
///
140+
/// This function is blocking: if there's no pending event then
141+
/// it will wait until an event is received or until the provided
142+
/// timeout elapses. Only if an error or a timeout occurs the
143+
/// returned event will be `std::nullopt`.
144+
/// This function is typically used when you have a thread that is
145+
/// dedicated to events handling: you want to make this thread sleep
146+
/// as long as no new event is received.
147+
/// \code
148+
/// while (sfRenderWindow_waitEvent(renderWindow, timeout, &event))
149+
/// {
150+
/// // process event...
151+
/// }
152+
/// \endcode
153+
///
138154
/// \param renderWindow Render window object
139-
/// \param event Event to fill
155+
/// \param timeout Maximum time to wait (`sfTime_Zero` for infinite)
156+
/// \param event Event to fill, if any
140157
///
141-
/// \return false if an error occurred
158+
/// \return true if an event was returned, false if event queue was empty
142159
///
143160
////////////////////////////////////////////////////////////
144-
CSFML_GRAPHICS_API bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfEvent* event);
161+
CSFML_GRAPHICS_API bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfTime timeout, sfEvent* event);
145162

146163
////////////////////////////////////////////////////////////
147164
/// \brief Get the position of a render window
@@ -377,6 +394,31 @@ CSFML_GRAPHICS_API sfWindowHandle sfRenderWindow_getNativeHandle(const sfRenderW
377394
////////////////////////////////////////////////////////////
378395
CSFML_GRAPHICS_API void sfRenderWindow_clear(sfRenderWindow* renderWindow, sfColor color);
379396

397+
////////////////////////////////////////////////////////////
398+
/// \brief Clear the stencil buffer to a specific value
399+
///
400+
/// The specified value is truncated to the bit width of
401+
/// the current stencil buffer.
402+
///
403+
/// \param renderWindow Render window object
404+
/// \param stencilValue Stencil value to clear to
405+
///
406+
////////////////////////////////////////////////////////////
407+
CSFML_GRAPHICS_API void sfRenderWindow_clearStencil(sfRenderWindow* renderWindow, sfStencilValue stencilValue);
408+
409+
////////////////////////////////////////////////////////////
410+
/// \brief Clear the entire target with a single color and stencil value
411+
///
412+
/// The specified stencil value is truncated to the bit
413+
/// width of the current stencil buffer.
414+
///
415+
/// \param renderWindow Render window object
416+
/// \param color Fill color to use to clear the render target
417+
/// \param stencilValue Stencil value to clear to
418+
///
419+
////////////////////////////////////////////////////////////
420+
CSFML_GRAPHICS_API void sfRenderWindow_clearColorAndStencil(sfRenderWindow* renderWindow, sfColor color, sfStencilValue stencilValue);
421+
380422
////////////////////////////////////////////////////////////
381423
/// \brief Change the current active view of a render window
382424
///
@@ -417,6 +459,22 @@ CSFML_GRAPHICS_API const sfView* sfRenderWindow_getDefaultView(const sfRenderWin
417459
////////////////////////////////////////////////////////////
418460
CSFML_GRAPHICS_API sfIntRect sfRenderWindow_getViewport(const sfRenderWindow* renderWindow, const sfView* view);
419461

462+
////////////////////////////////////////////////////////////
463+
/// \brief Get the scissor rectangle of a view, applied to this render target
464+
///
465+
/// The scissor rectangle is defined in the view as a ratio. This
466+
/// function simply applies this ratio to the current dimensions
467+
/// of the render target to calculate the pixels rectangle
468+
/// that the scissor rectangle actually covers in the target.
469+
///
470+
/// \param renderWindow Render window object
471+
/// \param view The view for which we want to compute the scissor rectangle
472+
///
473+
/// \return Scissor rectangle, expressed in pixels
474+
///
475+
////////////////////////////////////////////////////////////
476+
CSFML_GRAPHICS_API sfIntRect sfRenderWindow_getScissor(const sfRenderWindow* renderWindow, const sfView* view);
477+
420478
////////////////////////////////////////////////////////////
421479
/// \brief Convert a point from window coordinates to world coordinates
422480
///
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
////////////////////////////////////////////////////////////
2+
//
3+
// SFML - Simple and Fast Multimedia Library
4+
// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org)
5+
//
6+
// This software is provided 'as-is', without any express or implied warranty.
7+
// In no event will the authors be held liable for any damages arising from the use of this software.
8+
//
9+
// Permission is granted to anyone to use this software for any purpose,
10+
// including commercial applications, and to alter it and redistribute it freely,
11+
// subject to the following restrictions:
12+
//
13+
// 1. The origin of this software must not be misrepresented;
14+
// you must not claim that you wrote the original software.
15+
// If you use this software in a product, an acknowledgment
16+
// in the product documentation would be appreciated but is not required.
17+
//
18+
// 2. Altered source versions must be plainly marked as such,
19+
// and must not be misrepresented as being the original software.
20+
//
21+
// 3. This notice may not be removed or altered from any source distribution.
22+
//
23+
////////////////////////////////////////////////////////////
24+
25+
#pragma once
26+
27+
////////////////////////////////////////////////////////////
28+
// Headers
29+
////////////////////////////////////////////////////////////
30+
#include <CSFML/Graphics/Export.h>
31+
32+
33+
////////////////////////////////////////////////////////
34+
/// \brief Enumeration of the stencil test comparisons that can be performed
35+
///
36+
/// The comparisons are mapped directly to their OpenGL equivalents,
37+
/// specified by `glStencilFunc()`.
38+
////////////////////////////////////////////////////////
39+
typedef enum
40+
{
41+
sfStencilComparisonNever, //!< The stencil test never passes
42+
sfStencilComparisonLess, //!< The stencil test passes if the new value is less than the value in the stencil buffer
43+
sfStencilComparisonLessEqual, //!< The stencil test passes if the new value is less than or equal to the value in the stencil buffer
44+
sfStencilComparisonGreater, //!< The stencil test passes if the new value is greater than the value in the stencil buffer
45+
sfStencilComparisonGreaterEqual, //!< The stencil test passes if the new value is greater than or equal to the value in the stencil buffer
46+
sfStencilComparisonEqual, //!< The stencil test passes if the new value is strictly equal to the value in the stencil buffer
47+
sfStencilComparisonNotEqual, //!< The stencil test passes if the new value is strictly unequal to the value in the stencil buffer
48+
sfStencilComparisonAlways //!< The stencil test always passes
49+
} sfStencilComparison;
50+
51+
52+
////////////////////////////////////////////////////////
53+
/// \brief Enumeration of the stencil buffer update operations
54+
///
55+
/// The update operations are mapped directly to their OpenGL equivalents,
56+
/// specified by `glStencilOp()`.
57+
////////////////////////////////////////////////////////
58+
typedef enum
59+
{
60+
sfStencilUpdateOperationKeep, //!< If the stencil test passes, the value in the stencil buffer is not modified
61+
sfStencilUpdateOperationZero, //!< If the stencil test passes, the value in the stencil buffer is set to zero
62+
sfStencilUpdateOperationReplace, //!< If the stencil test passes, the value in the stencil buffer is set to the new value
63+
sfStencilUpdateOperationIncrement, //!< If the stencil test passes, the value in the stencil buffer is incremented and if required clamped
64+
sfStencilUpdateOperationDecrement, //!< If the stencil test passes, the value in the stencil buffer is decremented and if required clamped
65+
sfStencilUpdateOperationInvert, //!< If the stencil test passes, the value in the stencil buffer is bitwise inverted
66+
} sfStencilUpdateOperation;
67+
68+
69+
////////////////////////////////////////////////////////
70+
/// \brief Stencil value type (also used as a mask)
71+
///
72+
////////////////////////////////////////////////////////
73+
typedef struct
74+
{
75+
unsigned int value; //!< The stored stencil value
76+
} sfStencilValue;
77+
78+
79+
////////////////////////////////////////////////////////////
80+
/// \brief Stencil modes for drawing
81+
///
82+
////////////////////////////////////////////////////////////
83+
typedef struct
84+
{
85+
sfStencilComparison stencilComparison; //!< The comparison we're performing the stencil test with
86+
sfStencilUpdateOperation stencilUpdateOperation; //!< The update operation to perform if the stencil test passes
87+
sfStencilValue stencilReference; //!< The reference value we're performing the stencil test with
88+
sfStencilValue stencilMask; //!< The mask to apply to both the reference value and the value in the stencil buffer
89+
bool stencilOnly; //!< Whether we should update the color buffer in addition to the stencil buffer
90+
} sfStencilMode;
91+
92+
////////////////////////////////////////////////////////////
93+
/// \brief Define the default values for a StencilMode
94+
///
95+
////////////////////////////////////////////////////////////
96+
CSFML_GRAPHICS_API const sfStencilMode sfStencilMode_default;

include/CSFML/Graphics/Texture.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ typedef enum
5757
////////////////////////////////////////////////////////////
5858
CSFML_GRAPHICS_API sfTexture* sfTexture_create(sfVector2u size);
5959

60+
////////////////////////////////////////////////////////////
61+
/// \brief Create a new sRGB-enabled texture
62+
///
63+
/// \param size Texture size
64+
///
65+
/// \return A new sfTexture object, or NULL if it failed
66+
///
67+
////////////////////////////////////////////////////////////
68+
CSFML_GRAPHICS_API sfTexture* sfTexture_createSrgb(sfVector2u size);
69+
6070
////////////////////////////////////////////////////////////
6171
/// \brief Create a new texture from a file
6272
///

include/CSFML/Graphics/View.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,29 @@ CSFML_GRAPHICS_API void sfView_setRotation(sfView* view, float angle);
117117
////////////////////////////////////////////////////////////
118118
CSFML_GRAPHICS_API void sfView_setViewport(sfView* view, sfFloatRect viewport);
119119

120+
////////////////////////////////////////////////////////////
121+
/// \brief Set the target scissor rectangle
122+
///
123+
/// The scissor rectangle, expressed as a factor (between 0 and 1) of
124+
/// the RenderTarget, specifies the region of the RenderTarget whose
125+
/// pixels are able to be modified by draw or clear operations.
126+
/// Any pixels which lie outside of the scissor rectangle will
127+
/// not be modified by draw or clear operations.
128+
/// For example, a scissor rectangle which only allows modifications
129+
/// to the right side of the target would be defined
130+
/// with `sfView_setScissor(view, {{0.5f, 0.f}, {0.5f, 1.f}})`.
131+
/// By default, a view has a scissor rectangle which allows
132+
/// modifications to the entire target. This is equivalent to
133+
/// disabling the scissor test entirely. Passing the default
134+
/// scissor rectangle to this function will also disable
135+
/// scissor testing.
136+
///
137+
/// \param view View object
138+
/// \param scissor New scissor rectangle
139+
///
140+
////////////////////////////////////////////////////////////
141+
CSFML_GRAPHICS_API void sfView_setScissor(sfView* view, sfFloatRect scissor);
142+
120143
////////////////////////////////////////////////////////////
121144
/// \brief Get the center of a view
122145
///
@@ -157,6 +180,16 @@ CSFML_GRAPHICS_API float sfView_getRotation(const sfView* view);
157180
////////////////////////////////////////////////////////////
158181
CSFML_GRAPHICS_API sfFloatRect sfView_getViewport(const sfView* view);
159182

183+
////////////////////////////////////////////////////////////
184+
/// \brief Get the scissor rectangle of the view
185+
///
186+
/// \param view View object
187+
///
188+
/// \return Scissor rectangle, expressed as a factor of the target size
189+
///
190+
////////////////////////////////////////////////////////////
191+
CSFML_GRAPHICS_API sfFloatRect sfView_getScissor(const sfView* view);
192+
160193
////////////////////////////////////////////////////////////
161194
/// \brief Move a view relatively to its current position
162195
///

0 commit comments

Comments
 (0)