// Copyright (c) 2021 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #pragma once #include "../libs.h" #define TEXTURE_SLOTS_MAX 8 /** Texture slot that a texture can be bound to */ typedef GLuint textureslot_t; /** * Structure detailing information about a texture. * Because we plan to upload the pixels of a texture into the GPU, we don't * store the pixels in memory because we don't need to! */ typedef struct { /** Width (in pixels) of the texture */ int32_t width; /** Height (in pixels) of the texture */ int32_t height; /** Texture ID on the GPU */ GLuint id; } texture_t; /** Information about a single pixel. */ typedef struct { /** RGBA Color values */ uint8_t r, g, b, a; } pixel_t; #define PIXEL_COLOR_WHITE ((pixel_t){ .r = 255, .g = 255, .b = 255, .a = 255 }) #define PIXEL_COLOR_RED ((pixel_t){ .r = 255, .g = 0, .b = 0, .a = 255 }) #define PIXEL_COLOR_GREEN ((pixel_t){ .r = 0, .g = 255, .b = 0, .a = 255 }) #define PIXEL_COLOR_BLUE ((pixel_t){ .r = 0, .g = 0, .b = 255, .a = 255 }) #define PIXEL_COLOR_BLACK ((pixel_t){ .r = 0, .g = 0, .b = 0, .a = 255 }) #define PIXEL_COLOR_TRANSPARENT ((pixel_t){ .r = 0, .g = 0, .b = 0, .a = 0 }) /** * Initializes a texture that can be written in to. * * @param texture Texture to initialize. * @param width Width of the texture (in pixels). * @param height Height of the texture (in pixels). * @param pixels Default pixel array, set to NULL to set all pixel data to 0. */ void textureInit(texture_t *texture, int32_t width, int32_t height, pixel_t *pixels ); /** * Bind a texture on to a given texture slot. * * @param texture Texture to bind. * @param slot Slot to bind the texture to. */ void textureBind(texture_t *texture, textureslot_t slot); /** * Buffer pixel data onto the GPU. Pixel buffering is rather costly so avoid * doing this too often. * * @param texture Texture to buffer in to. * @param x X coordinate in texture space to render to. * @param y Y coordinate in texture space to render to. * @param width Width of the pixel region you're buffering. * @param height Height of the pixel region you're buffering. * @param pixels Array of pixels to buffer onto the GPU. */ void textureBufferPixels(texture_t *texture, int32_t x, int32_t y, int32_t width, int32_t height, pixel_t *pixels ); /** * Clean a previously created texture. * * @param texture Texture to clean up. */ void textureDispose(texture_t *texture);