#pragma once /** * @file render.hpp * @brief HDK sdl Renderer subsystem. Glues together Texture & Renderer which have circular dependencies */ #include #include namespace hdk::sdl { /** @see https://wiki.libsdl.org/SDL3/SDL_GetRendererFromTexture * @return Renderer The renderer associated with the texture */ inline Renderer Texture::GetRenderer() const { /** we may not have created the renderer we get back, if not we will not own it. */ return Renderer(Renderer::get_or_view(SDL_GetRendererFromTexture(*this))); } /** @see https://wiki.libsdl.org/SDL3/SDL_CreateTexture * @brief Create a texture for a rendering context. * @param format The pixel format of the texture * @param access The access pattern for the texture * @param w The width of the texture in pixels * @param h The height of the texture in pixels * @return Texture The created texture. If the creation fails, returns an invalid texture. */ inline Texture Renderer::CreateTexture(SDL_PixelFormat format, SDL_TextureAccess access, int w, int h) const { return Texture(Texture::get_or_cache(SDL_CreateTexture(*this, format, access, w, h), SDL_DestroyTexture)); } /** @see https://wiki.libsdl.org/SDL3/SDL_CreateTextureFromSurface * @brief Create a texture from an existing surface. * @param surface The surface to create the texture from. * @return Texture The created texture. If the creation fails, returns an invalid texture. */ inline Texture Renderer::CreateTextureFromSurface(SDL_Surface* surface) const { return Texture(Texture::get_or_cache(SDL_CreateTextureFromSurface(*this, surface), SDL_DestroyTexture)); } /** @see https://wiki.libsdl.org/SDL3/SDL_CreateTextureWithProperties * @brief Create a texture for a rendering context with specific properties. * @param properties The properties to create the texture with. * @return Texture The created texture. If the creation fails, returns an invalid texture. */ inline Texture Renderer::CreateTextureWithProperties(SDL_PropertiesID properties) const { return Texture(Texture::get_or_cache(SDL_CreateTextureWithProperties(*this, properties), SDL_DestroyTexture)); } }