41 lines
1.3 KiB
C++
41 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
class Screen {
|
|
public:
|
|
// Meyers singleton: la destrucció ocorre durant la termianció estàtica
|
|
// (LIFO respecte a Resource::Cache). El SDL_Quit s'ha de registrar via
|
|
// std::atexit ABANS de la primera crida a get(); així Screen::~Screen
|
|
// (que crida SDL_Destroy*/SDL_QuitSubSystem) s'executa amb SDL encara viu.
|
|
static auto get() -> Screen&;
|
|
|
|
Screen(const Screen&) = delete;
|
|
Screen(Screen&&) = delete;
|
|
auto operator=(const Screen&) -> Screen& = delete;
|
|
auto operator=(Screen&&) -> Screen& = delete;
|
|
|
|
void clear(std::uint8_t r = 0, std::uint8_t g = 0, std::uint8_t b = 0);
|
|
void present();
|
|
|
|
[[nodiscard]] auto getRenderer() const -> SDL_Renderer* { return renderer_; }
|
|
[[nodiscard]] auto getCanvasArgb() -> std::uint32_t* { return canvas_.data(); }
|
|
[[nodiscard]] auto getCanvasWidth() const -> int { return canvas_width_; }
|
|
[[nodiscard]] auto getCanvasHeight() const -> int { return canvas_height_; }
|
|
|
|
private:
|
|
Screen();
|
|
~Screen();
|
|
|
|
SDL_Window* window_{nullptr};
|
|
SDL_Renderer* renderer_{nullptr};
|
|
SDL_Texture* game_texture_{nullptr};
|
|
|
|
int canvas_width_{0};
|
|
int canvas_height_{0};
|
|
std::vector<std::uint32_t> canvas_;
|
|
};
|