75 lines
1.4 KiB
C
75 lines
1.4 KiB
C
/**
|
|
* Copyright (c) 2025 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#pragma once
|
|
#include "display/color.h"
|
|
#include "display/displaydefs.h"
|
|
|
|
typedef enum {
|
|
#if DISPLAY_SDL2
|
|
TEXTURE_FORMAT_RGBA = GL_RGBA,
|
|
TEXTURE_FORMAT_ALPHA = GL_ALPHA,
|
|
TEXTURE_FORMAT_PALETTE = GL_COLOR_INDEX8_EXT,
|
|
#endif
|
|
} textureformat_t;
|
|
|
|
typedef struct {
|
|
#if DISPLAY_SDL2
|
|
GLuint id;
|
|
#endif
|
|
|
|
int32_t width;
|
|
int32_t height;
|
|
} texture_t;
|
|
|
|
typedef union {
|
|
struct {
|
|
color_t *colors;
|
|
} rgba;
|
|
|
|
struct {
|
|
uint8_t palette;
|
|
uint8_t *data;
|
|
} palette;
|
|
|
|
struct {
|
|
uint8_t *data;
|
|
} alpha;
|
|
} texturedata_t;
|
|
|
|
extern const texture_t *TEXTURE_BOUND;
|
|
|
|
/**
|
|
* Initializes a texture.
|
|
*
|
|
* @param texture The texture to initialize.
|
|
* @param width The width of the texture.
|
|
* @param height The height of the texture.
|
|
* @param format The format of the texture (e.g., GL_RGBA, GL_ALPHA).
|
|
* @param data The data for the texture, the format changes per format.
|
|
*/
|
|
void textureInit(
|
|
texture_t *texture,
|
|
const int32_t width,
|
|
const int32_t height,
|
|
const textureformat_t format,
|
|
const texturedata_t data
|
|
);
|
|
|
|
/**
|
|
* Binds a texture for rendering. Providing NULL will unbind any texture.
|
|
*
|
|
* @param texture The texture to bind.
|
|
*/
|
|
void textureBind(const texture_t *texture);
|
|
|
|
/**
|
|
* Disposes a texture.
|
|
*
|
|
* @param texture The texture to dispose.
|
|
*/
|
|
void textureDispose(texture_t *texture); |