Some checks failed
Build Dusk / run-tests (push) Failing after 19s
Build Dusk / build-linux (push) Failing after 17s
Build Dusk / build-psp (push) Failing after 21s
Build Dusk / build-gamecube (push) Failing after 19s
Build Dusk / build-wii (push) Failing after 15s
92 lines
2.4 KiB
C
92 lines
2.4 KiB
C
/**
|
|
* Copyright (c) 2026 Dominic Masters
|
|
*
|
|
* This software is released under the MIT License.
|
|
* https://opensource.org/licenses/MIT
|
|
*/
|
|
|
|
#include "display/texture/texture.h"
|
|
#include "assert/assert.h"
|
|
#include "error/errorgl.h"
|
|
#include "util/memory.h"
|
|
|
|
errorret_t textureInitGL(
|
|
texturegl_t *texture,
|
|
const int32_t width,
|
|
const int32_t height,
|
|
const textureformatgl_t format,
|
|
const texturedata_t data
|
|
) {
|
|
glGenTextures(1, &texture->id);
|
|
errorChain(errorGLCheck());
|
|
glBindTexture(GL_TEXTURE_2D, texture->id);
|
|
errorChain(errorGLCheck());
|
|
|
|
switch(format) {
|
|
case TEXTURE_FORMAT_RGBA:
|
|
glTexImage2D(
|
|
GL_TEXTURE_2D, 0, format, width, height, 0,
|
|
format, GL_UNSIGNED_BYTE, (void*)data.rgbaColors
|
|
);
|
|
errorChain(errorGLCheck());
|
|
break;
|
|
|
|
case TEXTURE_FORMAT_PALETTE:
|
|
texture->palette = data.paletted.palette;
|
|
|
|
#ifdef DUSK_OPENGL_LEGACY
|
|
glTexImage2D(
|
|
GL_TEXTURE_2D,
|
|
0, GL_COLOR_INDEX8_EXT,
|
|
width, height,
|
|
0, GL_COLOR_INDEX8_EXT,
|
|
GL_UNSIGNED_BYTE, (void*)data.paletted.indices
|
|
);
|
|
|
|
glColorTableEXT(
|
|
GL_TEXTURE_2D, GL_RGBA, texture->palette->count, GL_RGBA,
|
|
GL_UNSIGNED_BYTE, (const void*)texture->palette->colors
|
|
);
|
|
errorChain(errorGLCheck());
|
|
|
|
#else
|
|
// For modern systems we send to only the R channel and the shader does
|
|
// the rest.
|
|
glTexImage2D(
|
|
GL_TEXTURE_2D, 0, GL_RED, width, height, 0,
|
|
GL_RED, GL_UNSIGNED_BYTE, (void*)data.paletted.indices
|
|
);
|
|
errorChain(errorGLCheck());
|
|
#endif
|
|
break;
|
|
|
|
default:
|
|
assertUnreachable("Unknown texture format");
|
|
break;
|
|
}
|
|
errorChain(errorGLCheck());
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
errorChain(errorGLCheck());
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
errorChain(errorGLCheck());
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
|
errorChain(errorGLCheck());
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
|
errorChain(errorGLCheck());
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
errorChain(errorGLCheck());
|
|
|
|
errorOk();
|
|
}
|
|
|
|
errorret_t textureDisposeGL(texturegl_t *texture) {
|
|
assertNotNull(texture, "Texture cannot be NULL");
|
|
assertTrue(texture->id != 0, "Texture ID must be valid");
|
|
|
|
glDeleteTextures(1, &texture->id);
|
|
errorChain(errorGLCheck());
|
|
|
|
errorOk();
|
|
} |