Test paletted stuff
Some checks failed
Build Dusk / run-tests (push) Failing after 26s
Build Dusk / build-linux (push) Failing after 25s
Build Dusk / build-psp (push) Failing after 18s
Build Dusk / build-gamecube (push) Failing after 18s
Build Dusk / build-wii (push) Failing after 18s
Some checks failed
Build Dusk / run-tests (push) Failing after 26s
Build Dusk / build-linux (push) Failing after 25s
Build Dusk / build-psp (push) Failing after 18s
Build Dusk / build-gamecube (push) Failing after 18s
Build Dusk / build-wii (push) Failing after 18s
This commit is contained in:
@@ -50,7 +50,10 @@ errorret_t assetTextureLoad(assetentire_t entire) {
|
|||||||
assetData->height,
|
assetData->height,
|
||||||
TEXTURE_FORMAT_PALETTE,
|
TEXTURE_FORMAT_PALETTE,
|
||||||
(texturedata_t){
|
(texturedata_t){
|
||||||
.paletteData = assetData->palette
|
.paletted = {
|
||||||
|
.indices = NULL,
|
||||||
|
.palette = NULL
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -38,16 +38,27 @@ errorret_t displayInit(void) {
|
|||||||
errorChain(textInit());
|
errorChain(textInit());
|
||||||
errorChain(screenInit());
|
errorChain(screenInit());
|
||||||
|
|
||||||
color_t pixels[2 * 2] = {
|
PALETTES[0].colors[0] = COLOR_RED;
|
||||||
COLOR_RED, COLOR_GREEN,
|
PALETTES[0].colors[1] = COLOR_GREEN;
|
||||||
COLOR_BLUE, COLOR_WHITE
|
PALETTES[0].colors[2] = COLOR_BLUE;
|
||||||
|
PALETTES[0].colors[3] = COLOR_WHITE;
|
||||||
|
PALETTES[0].count = 4;
|
||||||
|
|
||||||
|
uint8_t indices[4 * 4] = {
|
||||||
|
0, 1, 2, 3,
|
||||||
|
3, 2, 1, 0,
|
||||||
|
0, 1, 2, 3,
|
||||||
|
3, 2, 1, 0,
|
||||||
};
|
};
|
||||||
errorChain(textureInit(
|
errorChain(textureInit(
|
||||||
&TEXTURE,
|
&TEXTURE,
|
||||||
2, 2,
|
4, 4,
|
||||||
TEXTURE_FORMAT_RGBA,
|
TEXTURE_FORMAT_PALETTE,
|
||||||
(texturedata_t){
|
(texturedata_t){
|
||||||
.rgbaColors = pixels
|
.paletted = {
|
||||||
|
.indices = indices,
|
||||||
|
.palette = &PALETTES[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -79,9 +90,9 @@ errorret_t displayUpdate(void) {
|
|||||||
// camera.orthographic.top = SCREEN.height;
|
// camera.orthographic.top = SCREEN.height;
|
||||||
// camera.orthographic.bottom = 0.0f;
|
// camera.orthographic.bottom = 0.0f;
|
||||||
cameraInitPerspective(&camera);
|
cameraInitPerspective(&camera);
|
||||||
camera.lookat.position[0] = 10.0f;
|
camera.lookat.position[0] = 3.0f;
|
||||||
camera.lookat.position[1] = 10.0f;
|
camera.lookat.position[1] = 3.0f;
|
||||||
camera.lookat.position[2] = 10.0f;
|
camera.lookat.position[2] = 3.0f;
|
||||||
|
|
||||||
mat4 proj, view, model;
|
mat4 proj, view, model;
|
||||||
cameraGetProjectionMatrix(&camera, proj);
|
cameraGetProjectionMatrix(&camera, proj);
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ target_sources(${DUSK_LIBRARY_TARGET_NAME}
|
|||||||
PUBLIC
|
PUBLIC
|
||||||
tileset.c
|
tileset.c
|
||||||
texture.c
|
texture.c
|
||||||
|
palette.c
|
||||||
)
|
)
|
||||||
10
src/dusk/display/texture/palette.c
Normal file
10
src/dusk/display/texture/palette.c
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "palette.h"
|
||||||
|
|
||||||
|
palette_t PALETTES[PALETTE_COUNT];
|
||||||
19
src/dusk/display/texture/palette.h
Normal file
19
src/dusk/display/texture/palette.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include "display/color.h"
|
||||||
|
|
||||||
|
#define PALETTE_COLOR_COUNT 256
|
||||||
|
#define PALETTE_COUNT 6
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
color_t colors[PALETTE_COLOR_COUNT];
|
||||||
|
uint8_t count;
|
||||||
|
} palette_t;
|
||||||
|
|
||||||
|
extern palette_t PALETTES[PALETTE_COUNT];
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "error/error.h"
|
#include "error/error.h"
|
||||||
#include "display/color.h"
|
#include "display/texture/palette.h"
|
||||||
#include "display/texture/textureplatform.h"
|
#include "display/texture/textureplatform.h"
|
||||||
|
|
||||||
#ifndef textureInitPlatform
|
#ifndef textureInitPlatform
|
||||||
@@ -20,8 +20,13 @@
|
|||||||
typedef textureformatplatform_t textureformat_t;
|
typedef textureformatplatform_t textureformat_t;
|
||||||
typedef textureplatform_t texture_t;
|
typedef textureplatform_t texture_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t *indices;
|
||||||
|
palette_t *palette;
|
||||||
|
} texturepalettedata_t;
|
||||||
|
|
||||||
typedef union texturedata_u {
|
typedef union texturedata_u {
|
||||||
uint8_t *paletteData;
|
texturepalettedata_t paletted;
|
||||||
color_t *rgbaColors;
|
color_t *rgbaColors;
|
||||||
} texturedata_t;
|
} texturedata_t;
|
||||||
|
|
||||||
|
|||||||
@@ -224,6 +224,33 @@ errorret_t shaderSetTextureGL(
|
|||||||
errorChain(errorGLCheck());
|
errorChain(errorGLCheck());
|
||||||
glUniform1i(location, 0);
|
glUniform1i(location, 0);
|
||||||
errorChain(errorGLCheck());
|
errorChain(errorGLCheck());
|
||||||
|
|
||||||
|
if(texture->format == TEXTURE_FORMAT_PALETTE) {
|
||||||
|
shaderParamGetLocationGL(shader, "u_ColorCount", &location);
|
||||||
|
glUniform1i(location, texture->palette->count);
|
||||||
|
errorChain(errorGLCheck());
|
||||||
|
|
||||||
|
shaderParamGetLocationGL(shader, "u_Colors", &location);
|
||||||
|
GLuint paletteData[texture->palette->count];
|
||||||
|
for(size_t i = 0; i < texture->palette->count; i++) {
|
||||||
|
color_t color = texture->palette->colors[i];
|
||||||
|
paletteData[i] = (
|
||||||
|
((uint32_t)color.r << 24) |
|
||||||
|
((uint32_t)color.g << 16) |
|
||||||
|
((uint32_t)color.b << 8) |
|
||||||
|
((uint32_t)color.a << 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
glUniform1uiv(location, texture->palette->count, paletteData);
|
||||||
|
errorChain(errorGLCheck());
|
||||||
|
}
|
||||||
|
|
||||||
|
// PALETTE TEST
|
||||||
|
// errorChain(shaderParamGetLocationGL(shader, "u_Palette", &location));
|
||||||
|
// glActiveTexture(GL_TEXTURE1);
|
||||||
|
// errorChain(errorGLCheck());
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
|
|||||||
@@ -13,28 +13,39 @@
|
|||||||
shaderdefinition_t SHADER_UNLIT_DEFINITION = {
|
shaderdefinition_t SHADER_UNLIT_DEFINITION = {
|
||||||
.vert =
|
.vert =
|
||||||
"#version 330 core\n"
|
"#version 330 core\n"
|
||||||
"layout(location = 0) in vec3 aPos;\n"
|
"layout(location = 0) in vec3 a_Pos;\n"
|
||||||
"layout(location = 1) in vec2 aTexCoord;\n"
|
"layout(location = 1) in vec2 a_TexCoord;\n"
|
||||||
"layout(location = 2) in vec4 aColor;\n"
|
"layout(location = 2) in vec4 a_Color;\n"
|
||||||
"uniform mat4 u_Proj;\n"
|
"uniform mat4 u_Proj;\n"
|
||||||
"uniform mat4 u_View;\n"
|
"uniform mat4 u_View;\n"
|
||||||
"uniform mat4 u_Model;\n"
|
"uniform mat4 u_Model;\n"
|
||||||
"out vec4 v_Color;\n"
|
"out vec4 v_Color;\n"
|
||||||
"out vec2 v_TexCoord;\n"
|
"out vec2 v_TexCoord;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n"
|
" gl_Position = u_Proj * u_View * u_Model * vec4(a_Pos, 1.0);\n"
|
||||||
" v_Color = aColor;\n"
|
" v_Color = a_Color;\n"
|
||||||
" v_TexCoord = aTexCoord;\n"
|
" v_TexCoord = a_TexCoord;\n"
|
||||||
"}\n",
|
"}\n",
|
||||||
|
|
||||||
.frag =
|
.frag =
|
||||||
"#version 330 core\n"
|
"#version 330 core\n"
|
||||||
"uniform sampler2D u_Texture;\n"
|
"uniform sampler2D u_Texture;\n"
|
||||||
|
"uniform uint u_Colors[256];\n"
|
||||||
|
"uniform int u_ColorCount;\n"
|
||||||
"in vec4 v_Color;\n"
|
"in vec4 v_Color;\n"
|
||||||
"in vec2 v_TexCoord;\n"
|
"in vec2 v_TexCoord;\n"
|
||||||
"out vec4 FragColor;\n"
|
"out vec4 FragColor;\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" FragColor = texture(u_Texture, v_TexCoord) * v_Color;\n"
|
" vec4 texColor = texture(u_Texture, v_TexCoord);\n"
|
||||||
|
" uint index = uint(floor(texColor.r * 255.0));\n"
|
||||||
|
" uint palColor = u_Colors[index];\n"
|
||||||
|
" float r = float((palColor >> 24) & 0xFFu) / 255.0;\n"
|
||||||
|
" float g = float((palColor >> 16) & 0xFFu) / 255.0;\n"
|
||||||
|
" float b = float((palColor >> 8) & 0xFFu) / 255.0;\n"
|
||||||
|
" float a = float((palColor >> 0) & 0xFFu) / 255.0;\n"
|
||||||
|
" vec4 paletteColor = vec4(r, g, b, a);\n"
|
||||||
|
" FragColor = paletteColor;\n"
|
||||||
|
// " FragColor = paletteColor * v_Color;\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "display/texture/texture.h"
|
#include "display/texture/texture.h"
|
||||||
#include "assert/assert.h"
|
#include "assert/assert.h"
|
||||||
#include "error/errorgl.h"
|
#include "error/errorgl.h"
|
||||||
|
#include "util/memory.h"
|
||||||
|
|
||||||
errorret_t textureInitGL(
|
errorret_t textureInitGL(
|
||||||
texturegl_t *texture,
|
texturegl_t *texture,
|
||||||
@@ -29,20 +30,32 @@ errorret_t textureInitGL(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case TEXTURE_FORMAT_PALETTE:
|
case TEXTURE_FORMAT_PALETTE:
|
||||||
assertNotNull(data.paletteData, "Palette texture data cannot be NULL");
|
assertNotNull(data.paletted.indices, "Palette indices cannot be NULL");
|
||||||
|
assertNotNull(data.paletted.palette, "Palette colors cannot be NULL");
|
||||||
|
#ifdef DUSK_OPENGL_LEGACY
|
||||||
glTexImage2D(
|
glTexImage2D(
|
||||||
GL_TEXTURE_2D,
|
GL_TEXTURE_2D,
|
||||||
0, GL_COLOR_INDEX8_EXT,
|
0, GL_COLOR_INDEX8_EXT,
|
||||||
width, height,
|
width, height,
|
||||||
0, GL_COLOR_INDEX8_EXT,
|
0, GL_COLOR_INDEX8_EXT,
|
||||||
GL_UNSIGNED_BYTE, (void*)data.paletteData
|
GL_UNSIGNED_BYTE, (void*)data.paletted.indices
|
||||||
);
|
);
|
||||||
errorChain(errorGLCheck());
|
errorChain(errorGLCheck());
|
||||||
|
glColorTableEXT(
|
||||||
// glColorTableEXT(
|
GL_TEXTURE_2D, GL_RGBA, data.paletted.palette->count, GL_RGBA,
|
||||||
// GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA,
|
GL_UNSIGNED_BYTE, (const void*)data.paletted.palette->colors
|
||||||
// GL_UNSIGNED_BYTE, (const void*)data.palette.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());
|
||||||
|
texture->palette = data.paletted.palette;
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -69,5 +82,6 @@ errorret_t textureDisposeGL(texturegl_t *texture) {
|
|||||||
|
|
||||||
glDeleteTextures(1, &texture->id);
|
glDeleteTextures(1, &texture->id);
|
||||||
errorChain(errorGLCheck());
|
errorChain(errorGLCheck());
|
||||||
|
|
||||||
errorOk();
|
errorOk();
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,10 @@ typedef struct {
|
|||||||
textureformatgl_t format;
|
textureformatgl_t format;
|
||||||
int32_t width;
|
int32_t width;
|
||||||
int32_t height;
|
int32_t height;
|
||||||
|
|
||||||
|
union {
|
||||||
|
palette_t *palette;
|
||||||
|
};
|
||||||
} texturegl_t;
|
} texturegl_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user