/** * Copyright (c) 2024 Dominic Masters * * This software is released under the MIT License. * https://opensource.org/licenses/MIT */ #pragma once #include "dawn.h" #include "dawnopengl.h" extern int32_t TEXTURE_ACTIVE_COUNT; typedef GLuint textureslot_t; typedef enum { TEXTURE_FORMAT_R = GL_RED, TEXTURE_FORMAT_RG = GL_RG, TEXTURE_FORMAT_RGB = GL_RGB, TEXTURE_FORMAT_RGBA = GL_RGBA } textureformat_t; typedef enum { TEXTURE_WRAP_MODE_REPEAT = GL_REPEAT, TEXTURE_WRAP_MODE_MIRRORED_REPEAT = GL_MIRRORED_REPEAT, TEXTURE_WRAP_MODE_CLAMP_TO_EDGE = GL_CLAMP_TO_EDGE, } texturewrapmode_t; typedef enum { TEXTURE_FILTER_MODE_NEAREST = GL_NEAREST, TEXTURE_FILTER_MODE_LINEAR = GL_LINEAR } texturefiltermode_t; typedef enum { TEXTURE_DATA_FORMAT_UNSIGNED_BYTE = GL_UNSIGNED_BYTE, TEXTURE_DATA_FORMAT_FLOAT = GL_FLOAT } texturedataformat_t; typedef struct { GLuint id; int32_t width; int32_t height; textureformat_t format; texturedataformat_t dataFormat; texturewrapmode_t wrapModeX; texturewrapmode_t wrapModeY; texturefiltermode_t filterModeMin; texturefiltermode_t filterModeMag; size_t elementSize; } texture_t; /** * Initializes a texture to be read to be used. * * @param texture Texture to initialize. * @param width Width of the texture (in pixels). * @param height Height of the texture (in pixels). * @param format Data format of the texture to use. * @param dataFormat Data format of the texture to use. */ void textureInit( texture_t *texture, int32_t width, int32_t height, textureformat_t format, texturedataformat_t dataFormat ); /** * Binds the texture to the given slot (for use by the shaders). * * @param texture Texture to bind. * @param slot Slot to bind to. */ void textureBind(const texture_t *texture, const textureslot_t slot); /** * Buffers pixels on to the texture. Set data to NULL to fill with empty pixels * (black by default). * * @param texture Texture to buffer. * @param data Data to buffer. */ void textureBuffer(const texture_t *texture, const void *data); /** * Buffer sub data to this texture. * * @param texture Texture to buffer on to. * @param data Data to buffer. * @param offset Offset position to buffer on to. * @param length Length of the data you are buffering. */ void textureBufferSub( const texture_t *texture, const void *data, const size_t offset, const size_t length ); /** * Unloads a previously initialized texture. * * @param texture Texture to destroy. */ void textureDispose(const texture_t *texture);