2#include "absl/strings/str_format.h"
20 renderer_ = std::unique_ptr<SDL_Renderer, util::SDL_Deleter>(
21 SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED));
25 printf(
"SDL_CreateRenderer Error: %s\n", SDL_GetError());
30 SDL_SetRenderDrawBlendMode(
renderer_.get(), SDL_BLENDMODE_BLEND);
49 SDL_CreateTexture(
renderer_.get(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, width, height)
59 SDL_CreateTexture(
renderer_.get(), format, access, width, height)
68 SDL_Surface* surface = bitmap.
surface();
71 if (!texture || !surface || !surface->format) {
76 if (!surface->pixels || surface->w <= 0 || surface->h <= 0) {
81 auto converted_surface = std::unique_ptr<SDL_Surface, util::SDL_Surface_Deleter>(
82 SDL_ConvertSurfaceFormat(surface, SDL_PIXELFORMAT_RGBA8888, 0));
84 if (!converted_surface || !converted_surface->pixels) {
89 SDL_UpdateTexture(
static_cast<SDL_Texture*
>(texture),
nullptr, converted_surface->pixels, converted_surface->pitch);
97 SDL_DestroyTexture(
static_cast<SDL_Texture*
>(texture));
102 return SDL_LockTexture(
static_cast<SDL_Texture*
>(texture), rect, pixels, pitch) == 0;
106 SDL_UnlockTexture(
static_cast<SDL_Texture*
>(texture));
127 SDL_RenderCopy(
renderer_.get(),
static_cast<SDL_Texture*
>(texture), srcrect, dstrect);
134 SDL_SetRenderTarget(
renderer_.get(),
static_cast<SDL_Texture*
>(texture));
141 SDL_SetRenderDrawColor(
renderer_.get(), color.r, color.g, color.b, color.a);
Represents a bitmap image optimized for SNES ROM hacking.
SDL_Surface * surface() const
void SetDrawColor(SDL_Color color) override
Sets the draw color.
std::unique_ptr< SDL_Renderer, util::SDL_Deleter > renderer_
bool Initialize(SDL_Window *window) override
Initializes the SDL2 renderer. This function creates an accelerated SDL2 renderer and attaches it to ...
void DestroyTexture(TextureHandle texture) override
Destroys an SDL_Texture.
void UpdateTexture(TextureHandle texture, const Bitmap &bitmap) override
Updates an SDL_Texture with data from a Bitmap. This involves converting the bitmap's surface to the ...
void SetRenderTarget(TextureHandle texture) override
Sets the render target.
TextureHandle CreateTextureWithFormat(int width, int height, uint32_t format, int access) override
Creates an SDL_Texture with a specific pixel format and access pattern. This is useful for specialize...
TextureHandle CreateTexture(int width, int height) override
Creates an SDL_Texture. The texture is created with streaming access, which is suitable for textures ...
bool LockTexture(TextureHandle texture, SDL_Rect *rect, void **pixels, int *pitch) override
void UnlockTexture(TextureHandle texture) override
void Present() override
Presents the rendered frame to the screen.
void Clear() override
Clears the screen with the current draw color.
void Shutdown() override
Shuts down the renderer. The underlying SDL_Renderer is managed by a unique_ptr, so its destruction i...
void RenderCopy(TextureHandle texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect) override
Copies a texture to the render target.
void * TextureHandle
An abstract handle representing a texture.
Main namespace for the application.