Added initial implementation of the SDL Pixels category.
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
/** Renderers are used to render 2D graphics in SDL */
|
||||
namespace hdk::sdl {
|
||||
class Window;
|
||||
class Texture;
|
||||
/**
|
||||
* @brief Wraps the SDL_Renderer struct and related functions in a C++ class that uses shared_ptr for lifetime management.
|
||||
*
|
||||
@@ -16,6 +17,7 @@ namespace hdk::sdl {
|
||||
class Renderer : public hdk::grid::SharedPtrWrapper<SDL_Renderer> {
|
||||
public:
|
||||
friend class Window;
|
||||
friend class Texture;
|
||||
friend std::pair<Window, Renderer> CreateWindowAndRenderer(
|
||||
const char* title, int width, int height, SDL_WindowFlags window_flags);
|
||||
/** Inherit constructors from SharedPtrWrapper */
|
||||
@@ -39,17 +41,23 @@ namespace hdk::sdl {
|
||||
static Renderer CreateSoftware(SDL_Surface* surface) {
|
||||
return Renderer(get_or_cache(SDL_CreateSoftwareRenderer(surface), SDL_DestroyRenderer));
|
||||
}
|
||||
// https://wiki.libsdl.org/SDL3/SDL_CreateWindowAndRenderer
|
||||
// https://wiki.libsdl.org/SDL3/SDL_DestroyGPURenderState
|
||||
// https://wiki.libsdl.org/SDL3/SDL_DestroyRenderer
|
||||
/// @todo https://wiki.libsdl.org/SDL3/SDL_CreateWindowAndRenderer
|
||||
/// @todo https://wiki.libsdl.org/SDL3/SDL_DestroyGPURenderState
|
||||
/// @todo https://wiki.libsdl.org/SDL3/SDL_DestroyRenderer
|
||||
/// Implemented in `../render.hpp` to avoid circular dependency with Texture
|
||||
Texture CreateTexture(SDL_PixelFormat format, SDL_TextureAccess access, int w, int h) const;
|
||||
/// Implemented in `../render.hpp` to avoid circular dependency with Texture
|
||||
Texture CreateTextureFromSurface(SDL_Surface* surface) const;
|
||||
/// Implemented in `../render.hpp` to avoid circular dependency with Texture
|
||||
Texture CreateTextureWithProperties(SDL_PropertiesID properties) const;
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_FlushRenderer
|
||||
* @brief Flush the current rendering commands to the screen.
|
||||
* @return bool True if the renderer was successfully flushed, false otherwise.
|
||||
*/
|
||||
bool Flush() const { return SDL_FlushRenderer(*this); }
|
||||
// https://wiki.libsdl.org/SDL3/SDL_GDKResumeRenderer
|
||||
// https://wiki.libsdl.org/SDL3/SDL_GDKSuspendRenderer
|
||||
/** https://wiki.libsdl.org/SDL3/SDL_GetCurrentRenderOutputSize
|
||||
/// @todo https://wiki.libsdl.org/SDL3/SDL_GDKResumeRenderer
|
||||
/// @todo https://wiki.libsdl.org/SDL3/SDL_GDKSuspendRenderer
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetCurrentRenderOutputSize
|
||||
* @brief Get the output size in pixels of the current render target.
|
||||
* @param w A pointer to an int to be filled in with the width of the render output. If the renderer is invalid,
|
||||
* this will be set to 0.
|
||||
@@ -67,7 +75,7 @@ namespace hdk::sdl {
|
||||
bool GetDefaultTextureScaleMode(SDL_ScaleMode* scaleMode) const {
|
||||
return SDL_GetDefaultTextureScaleMode(*this, scaleMode);
|
||||
}
|
||||
// https://wiki.libsdl.org/SDL3/SDL_GetGPURendererDevice
|
||||
/// @todo https://wiki.libsdl.org/SDL3/SDL_GetGPURendererDevice
|
||||
// https://wiki.libsdl.org/SDL3/SDL_GetNumRenderDrivers
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetRenderClipRect
|
||||
* @brief Get the clip rectangle for the current rendering target.
|
||||
@@ -131,7 +139,7 @@ namespace hdk::sdl {
|
||||
* @param window The window to query
|
||||
* @return Renderer The renderer associated with the window
|
||||
*/
|
||||
static Renderer Get(SDL_Window* window) {
|
||||
static Renderer GetFromWindow(SDL_Window* window) {
|
||||
/** we may not have created the renderer we get back, if not we will not own it. */
|
||||
return Renderer(get_or_view(SDL_GetRenderer(window)));
|
||||
}
|
||||
|
||||
@@ -7,9 +7,12 @@
|
||||
#include <hdk/sdl/Properties.hpp>
|
||||
/** Textures are used to store pixel data that can be rendered by a renderer. */
|
||||
namespace hdk::sdl {
|
||||
/// Forward declare to avoid circular dependency with Renderer
|
||||
class Renderer;
|
||||
/** */
|
||||
class Texture : public hdk::grid::SharedPtrWrapper<SDL_Texture> {
|
||||
public:
|
||||
friend class Renderer;
|
||||
/** Inherit constructors from SharedPtrWrapper */
|
||||
using hdk::grid::SharedPtrWrapper<SDL_Texture>::SharedPtrWrapper;
|
||||
|
||||
@@ -99,6 +102,8 @@ namespace hdk::sdl {
|
||||
* @returns Properties associated with the texture.
|
||||
*/
|
||||
Properties GetProperties() const { return Properties(SDL_GetTextureProperties(*this)); }
|
||||
/// Implemented in `../render.hpp` to avoid circular dependency with Renderer
|
||||
Renderer GetRenderer() const;
|
||||
/** @see https://wiki.libsdl.org/SDL3/SDL_GetTextureScaleMode
|
||||
* @brief Get the scale mode for a texture.
|
||||
* @param scaleMode A pointer to an SDL_ScaleMode variable to be filled in
|
||||
|
||||
Reference in New Issue
Block a user