/** * Copyright (c) 2026 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #include "texture.h" #include "assert/assert.h" #include "util/memory.h" #include "util/math.h" #include "display/display.h" texture_t TEXTURE_WHITE; color_t TEXTURE_WHITE_PIXELS[4*4] = { COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, COLOR_WHITE, }; texture_t TEXTURE_TEST; color_t TEXTURE_TEST_PIXELS[4*4] = { COLOR_BLACK, COLOR_MAGENTA, COLOR_BLACK, COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK, COLOR_MAGENTA, COLOR_BLACK, COLOR_BLACK, COLOR_MAGENTA, COLOR_BLACK, COLOR_MAGENTA, COLOR_MAGENTA, COLOR_BLACK, COLOR_MAGENTA, COLOR_BLACK, }; errorret_t textureInit( texture_t *texture, const int32_t width, const int32_t height, const textureformat_t format, const texturedata_t data ) { assertNotNull(texture, "Texture cannot be NULL"); assertTrue(width > 0 && height > 0, "width/height must be greater than 0"); assertTrue(width == mathNextPowTwo(width), "Width must be a power of 2."); assertTrue(height == mathNextPowTwo(height), "Height must be a power of 2."); if(texture->format == TEXTURE_FORMAT_RGBA) { assertNotNull(data.rgbaColors, "RGBA color data cannot be NULL"); } else if(texture->format == TEXTURE_FORMAT_PALETTE) { assertNotNull(data.paletted.indices, "Palette indices cannot be NULL"); assertNotNull(data.paletted.palette, "Palette colors cannot be NULL"); assertTrue( data.paletted.palette->count == mathNextPowTwo(data.paletted.palette->count), "Palette color count must be a power of 2" ); } memoryZero(texture, sizeof(texture_t)); texture->width = width; texture->height = height; texture->format = format; errorChain(textureInitPlatform(texture, width, height, format, data)); errorOk(); } errorret_t textureDispose(texture_t *texture) { assertNotNull(texture, "Texture cannot be NULL"); errorChain(textureDisposePlatform(texture)); errorOk(); }