#ifndef PW_FB_H #define PW_FB_H #include #include "scale.h" #define PW_FB_WIDTH 128 #define PW_FB_HEIGHT 128 #define PW_FB_BYTES_PER_PIXEL 4 #define PW_FB_STRIDE (PW_FB_WIDTH * PW_FB_BYTES_PER_PIXEL) #define PW_FB_SIZE (PW_FB_STRIDE * PW_FB_HEIGHT) /** * A PICO-8 framebuffer. */ struct pw_framebuffer { enum pw_scale_mode mode; SDL_Texture *texture; SDL_FRect target; }; /** * Framebuffer coordinates. */ struct pw_coordinates { float x; float y; }; /** * Allocates and initializes the PICO-8 framebuffer. */ struct pw_framebuffer *pw_fb_init(SDL_Renderer *renderer, enum pw_scale_mode mode); /** * Cleanup and free the PICO-8 framebuffer. */ void pw_fb_free(struct pw_framebuffer *fb); /** * Handles SDL events to resize the framebuffer. */ bool pw_fb_iterate(struct pw_framebuffer *fb); /** * Projects window coordinates to framebuffer coordinates. * * The resulting coordinate components are guaranteed to fit in a 32-bit * integer, meaning it is safe to cast to `int32_t`. */ bool pw_fb_coordinates(struct pw_framebuffer *fb, float wx, float wy, bool relative, struct pw_coordinates *coords); /** * Locks the framebuffer for writing. */ uint8_t *pw_fb_lock(struct pw_framebuffer *fb, size_t *pitch); /** * Unlocks the framebuffer for writing. */ void pw_fb_unlock(struct pw_framebuffer *fb); /** * Renders the the framebuffer. */ bool pw_fb_render(struct pw_framebuffer *fb); #endif