Skip to content

Commit eb0f297

Browse files
MarioalexsanChrisThrasher
authored andcommitted
Implement new graphics, system and window functions
1 parent 70397c6 commit eb0f297

File tree

18 files changed

+538
-85
lines changed

18 files changed

+538
-85
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: 69 additions & 5 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>
@@ -122,26 +124,47 @@ CSFML_GRAPHICS_API bool sfRenderWindow_isOpen(const sfRenderWindow* renderWindow
122124
CSFML_GRAPHICS_API sfContextSettings sfRenderWindow_getSettings(const sfRenderWindow* renderWindow);
123125

124126
////////////////////////////////////////////////////////////
125-
/// \brief Get the event on top of event queue of a render window, if any, and pop it
127+
/// \brief Pop the event on top of event queue, if any, and return it
128+
///
129+
/// This function is not blocking: if there's no pending event then
130+
/// it will return false and leave \a event unmodified.
131+
/// Note that more than one event may be present in the event queue,
132+
/// thus you should always call this function in a loop
133+
/// to make sure that you process every pending event.
126134
///
127135
/// \param renderWindow Render window object
128136
/// \param event Event to fill, if any
129137
///
130-
/// \return true if an event was returned, false if event queue was empty
138+
/// \return true if an event was returned, or false if the event queue was empty
131139
///
132140
////////////////////////////////////////////////////////////
133141
CSFML_GRAPHICS_API bool sfRenderWindow_pollEvent(sfRenderWindow* renderWindow, sfEvent* event);
134142

135143
////////////////////////////////////////////////////////////
136144
/// \brief Wait for an event and return it
137145
///
146+
/// This function is blocking: if there's no pending event then
147+
/// it will wait until an event is received or until the provided
148+
/// timeout elapses. Only if an error or a timeout occurs the
149+
/// function returns `false`.
150+
/// This function is typically used when you have a thread that is
151+
/// dedicated to events handling: you want to make this thread sleep
152+
/// as long as no new event is received.
153+
/// \code
154+
/// while (sfRenderWindow_waitEvent(renderWindow, timeout, &event))
155+
/// {
156+
/// // process event...
157+
/// }
158+
/// \endcode
159+
///
138160
/// \param renderWindow Render window object
139-
/// \param event Event to fill
161+
/// \param timeout Maximum time to wait (`sfTime_Zero` for infinite)
162+
/// \param event Event to fill, if any
140163
///
141-
/// \return false if an error occurred
164+
/// \return true if an event was returned, false if event queue was empty or function timed out
142165
///
143166
////////////////////////////////////////////////////////////
144-
CSFML_GRAPHICS_API bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfEvent* event);
167+
CSFML_GRAPHICS_API bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfTime timeout, sfEvent* event);
145168

146169
////////////////////////////////////////////////////////////
147170
/// \brief Get the position of a render window
@@ -377,6 +400,31 @@ CSFML_GRAPHICS_API sfWindowHandle sfRenderWindow_getNativeHandle(const sfRenderW
377400
////////////////////////////////////////////////////////////
378401
CSFML_GRAPHICS_API void sfRenderWindow_clear(sfRenderWindow* renderWindow, sfColor color);
379402

403+
////////////////////////////////////////////////////////////
404+
/// \brief Clear the stencil buffer to a specific value
405+
///
406+
/// The specified value is truncated to the bit width of
407+
/// the current stencil buffer.
408+
///
409+
/// \param renderWindow Render window object
410+
/// \param stencilValue Stencil value to clear to
411+
///
412+
////////////////////////////////////////////////////////////
413+
CSFML_GRAPHICS_API void sfRenderWindow_clearStencil(sfRenderWindow* renderWindow, sfStencilValue stencilValue);
414+
415+
////////////////////////////////////////////////////////////
416+
/// \brief Clear the entire target with a single color and stencil value
417+
///
418+
/// The specified stencil value is truncated to the bit
419+
/// width of the current stencil buffer.
420+
///
421+
/// \param renderWindow Render window object
422+
/// \param color Fill color to use to clear the render target
423+
/// \param stencilValue Stencil value to clear to
424+
///
425+
////////////////////////////////////////////////////////////
426+
CSFML_GRAPHICS_API void sfRenderWindow_clearColorAndStencil(sfRenderWindow* renderWindow, sfColor color, sfStencilValue stencilValue);
427+
380428
////////////////////////////////////////////////////////////
381429
/// \brief Change the current active view of a render window
382430
///
@@ -417,6 +465,22 @@ CSFML_GRAPHICS_API const sfView* sfRenderWindow_getDefaultView(const sfRenderWin
417465
////////////////////////////////////////////////////////////
418466
CSFML_GRAPHICS_API sfIntRect sfRenderWindow_getViewport(const sfRenderWindow* renderWindow, const sfView* view);
419467

468+
////////////////////////////////////////////////////////////
469+
/// \brief Get the scissor rectangle of a view, applied to this render target
470+
///
471+
/// The scissor rectangle is defined in the view as a ratio. This
472+
/// function simply applies this ratio to the current dimensions
473+
/// of the render target to calculate the pixels rectangle
474+
/// that the scissor rectangle actually covers in the target.
475+
///
476+
/// \param renderWindow Render window object
477+
/// \param view The view for which we want to compute the scissor rectangle
478+
///
479+
/// \return Scissor rectangle, expressed in pixels
480+
///
481+
////////////////////////////////////////////////////////////
482+
CSFML_GRAPHICS_API sfIntRect sfRenderWindow_getScissor(const sfRenderWindow* renderWindow, const sfView* view);
483+
420484
////////////////////////////////////////////////////////////
421485
/// \brief Convert a point from window coordinates to world coordinates
422486
///
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, (sfFloatRect){{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)