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:
@@ -224,6 +224,33 @@ errorret_t shaderSetTextureGL(
|
||||
errorChain(errorGLCheck());
|
||||
glUniform1i(location, 0);
|
||||
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
|
||||
|
||||
errorOk();
|
||||
|
||||
@@ -13,28 +13,39 @@
|
||||
shaderdefinition_t SHADER_UNLIT_DEFINITION = {
|
||||
.vert =
|
||||
"#version 330 core\n"
|
||||
"layout(location = 0) in vec3 aPos;\n"
|
||||
"layout(location = 1) in vec2 aTexCoord;\n"
|
||||
"layout(location = 2) in vec4 aColor;\n"
|
||||
"layout(location = 0) in vec3 a_Pos;\n"
|
||||
"layout(location = 1) in vec2 a_TexCoord;\n"
|
||||
"layout(location = 2) in vec4 a_Color;\n"
|
||||
"uniform mat4 u_Proj;\n"
|
||||
"uniform mat4 u_View;\n"
|
||||
"uniform mat4 u_Model;\n"
|
||||
"out vec4 v_Color;\n"
|
||||
"out vec2 v_TexCoord;\n"
|
||||
"void main() {\n"
|
||||
" gl_Position = u_Proj * u_View * u_Model * vec4(aPos, 1.0);\n"
|
||||
" v_Color = aColor;\n"
|
||||
" v_TexCoord = aTexCoord;\n"
|
||||
" gl_Position = u_Proj * u_View * u_Model * vec4(a_Pos, 1.0);\n"
|
||||
" v_Color = a_Color;\n"
|
||||
" v_TexCoord = a_TexCoord;\n"
|
||||
"}\n",
|
||||
|
||||
.frag =
|
||||
"#version 330 core\n"
|
||||
"uniform sampler2D u_Texture;\n"
|
||||
"uniform uint u_Colors[256];\n"
|
||||
"uniform int u_ColorCount;\n"
|
||||
"in vec4 v_Color;\n"
|
||||
"in vec2 v_TexCoord;\n"
|
||||
"out vec4 FragColor;\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"
|
||||
};
|
||||
#endif
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "display/texture/texture.h"
|
||||
#include "assert/assert.h"
|
||||
#include "error/errorgl.h"
|
||||
#include "util/memory.h"
|
||||
|
||||
errorret_t textureInitGL(
|
||||
texturegl_t *texture,
|
||||
@@ -29,20 +30,32 @@ errorret_t textureInitGL(
|
||||
break;
|
||||
|
||||
case TEXTURE_FORMAT_PALETTE:
|
||||
assertNotNull(data.paletteData, "Palette texture data cannot be NULL");
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0, GL_COLOR_INDEX8_EXT,
|
||||
width, height,
|
||||
0, GL_COLOR_INDEX8_EXT,
|
||||
GL_UNSIGNED_BYTE, (void*)data.paletteData
|
||||
);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
// glColorTableEXT(
|
||||
// GL_TEXTURE_2D, GL_RGBA, data.palette.palette->colorCount, GL_RGBA,
|
||||
// GL_UNSIGNED_BYTE, (const void*)data.palette.palette->colors
|
||||
// );
|
||||
assertNotNull(data.paletted.indices, "Palette indices cannot be NULL");
|
||||
assertNotNull(data.paletted.palette, "Palette colors cannot be NULL");
|
||||
#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
|
||||
);
|
||||
errorChain(errorGLCheck());
|
||||
glColorTableEXT(
|
||||
GL_TEXTURE_2D, GL_RGBA, data.paletted.palette->count, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, (const void*)data.paletted.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;
|
||||
|
||||
default:
|
||||
@@ -69,5 +82,6 @@ errorret_t textureDisposeGL(texturegl_t *texture) {
|
||||
|
||||
glDeleteTextures(1, &texture->id);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -20,6 +20,10 @@ typedef struct {
|
||||
textureformatgl_t format;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
|
||||
union {
|
||||
palette_t *palette;
|
||||
};
|
||||
} texturegl_t;
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user