Fixed GLES support (partially), PSP still not working
This commit is contained in:
@@ -28,6 +28,7 @@ target_link_libraries(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
target_compile_definitions(${DUSK_LIBRARY_TARGET_NAME} PUBLIC
|
||||
DUSK_SDL2
|
||||
DUSK_OPENGL
|
||||
# DUSK_OPENGL_LEGACY
|
||||
DUSK_LINUX
|
||||
DUSK_DISPLAY_SIZE_DYNAMIC
|
||||
DUSK_DISPLAY_WIDTH_DEFAULT=640
|
||||
|
||||
@@ -44,34 +44,52 @@ errorret_t displayInit(void) {
|
||||
PALETTES[0].colors[1] = COLOR_GREEN;
|
||||
PALETTES[0].colors[2] = COLOR_BLUE;
|
||||
PALETTES[0].colors[3] = COLOR_WHITE;
|
||||
PALETTES[0].count = 4;
|
||||
PALETTES[0].colors[4] = COLOR_MAGENTA;
|
||||
PALETTES[0].colors[5] = COLOR_CYAN;
|
||||
PALETTES[0].colors[6] = COLOR_YELLOW;
|
||||
PALETTES[0].colors[7] = COLOR_BLACK;
|
||||
PALETTES[0].count = 8;
|
||||
|
||||
uint8_t indices[64] = {
|
||||
0,0,0,0,0,0,0,0,
|
||||
1,1,1,1,1,1,1,1,
|
||||
2,2,2,2,2,2,2,2,
|
||||
3,3,3,3,3,3,3,3,
|
||||
4,4,4,4,4,4,4,4,
|
||||
5,5,5,5,5,5,5,5,
|
||||
6,6,6,6,6,6,6,6,
|
||||
7,7,7,7,7,7,7,7
|
||||
};
|
||||
|
||||
errorChain(textureInit(
|
||||
&PALETTE_TEXTURE,
|
||||
2, 2,
|
||||
8, 8,
|
||||
TEXTURE_FORMAT_PALETTE,
|
||||
(texturedata_t){
|
||||
.paletted = {
|
||||
.indices = (uint8_t[]){
|
||||
0, 1,
|
||||
2, 3
|
||||
},
|
||||
.indices = indices,
|
||||
.palette = &PALETTES[0]
|
||||
}
|
||||
}
|
||||
));
|
||||
|
||||
errorChain(textureInit(
|
||||
&UNCOMPRESSED_TEXTURE,
|
||||
2, 2,
|
||||
TEXTURE_FORMAT_RGBA,
|
||||
(texturedata_t){
|
||||
.rgbaColors = (color_t[]){
|
||||
COLOR_RED, COLOR_GREEN,
|
||||
COLOR_BLUE, COLOR_WHITE
|
||||
}
|
||||
}
|
||||
));
|
||||
// errorChain(textureInit(
|
||||
// &UNCOMPRESSED_TEXTURE,
|
||||
// 8, 8,
|
||||
// TEXTURE_FORMAT_RGBA,
|
||||
// (texturedata_t){
|
||||
// .rgbaColors = (color_t[]){
|
||||
// COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK,
|
||||
// COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK, COLOR_RED,
|
||||
// COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK, COLOR_RED, COLOR_GREEN,
|
||||
// COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE,
|
||||
// COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE,
|
||||
// COLOR_CYAN, COLOR_YELLOW, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA,
|
||||
// COLOR_YELLOW, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN,
|
||||
// COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_BLUE, COLOR_WHITE, COLOR_MAGENTA, COLOR_CYAN, COLOR_YELLOW
|
||||
// }
|
||||
// }
|
||||
// ));
|
||||
|
||||
errorOk();
|
||||
}
|
||||
@@ -112,7 +130,7 @@ errorret_t displayUpdate(void) {
|
||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj));
|
||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view));
|
||||
errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model));
|
||||
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, &UNCOMPRESSED_TEXTURE));
|
||||
errorChain(shaderSetTexture(&SHADER_UNLIT, SHADER_UNLIT_TEXTURE, &PALETTE_TEXTURE));
|
||||
errorChain(spriteBatchPush(
|
||||
0.0f, 0.0f,
|
||||
1.0f, 1.0f,
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
#define PALETTE_COUNT 6
|
||||
|
||||
typedef struct {
|
||||
uint8_t count;
|
||||
color_t colors[PALETTE_COLOR_COUNT];
|
||||
uint8_t count;
|
||||
} palette_t;
|
||||
|
||||
extern palette_t PALETTES[PALETTE_COUNT];
|
||||
@@ -29,8 +29,6 @@ errorret_t displayOpenGLInit(void) {
|
||||
errorChain(errorGLCheck());
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
errorChain(errorGLCheck());
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
errorChain(errorGLCheck());
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
|
||||
@@ -221,7 +221,7 @@ errorret_t shaderSetTextureGL(
|
||||
name,
|
||||
SHADER_UNLIT_TEXTURE,
|
||||
"Only one texture supported in legacy opengl."
|
||||
)
|
||||
);
|
||||
|
||||
if(texture == NULL) {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
@@ -233,8 +233,6 @@ errorret_t shaderSetTextureGL(
|
||||
errorChain(errorGLCheck());
|
||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||
errorChain(errorGLCheck());
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
#else
|
||||
if(shader->setTexture == NULL) {
|
||||
|
||||
@@ -47,6 +47,9 @@
|
||||
|
||||
// Set texture type
|
||||
if(texture->format == TEXTURE_FORMAT_PALETTE) {
|
||||
glUniform1i(locType, 2);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
shaderParamGetLocationGL(shader, "u_ColorCount", &locColorCount);
|
||||
glUniform1i(locColorCount, texture->palette->count);
|
||||
errorChain(errorGLCheck());
|
||||
@@ -75,7 +78,24 @@
|
||||
shaderdefinition_t SHADER_UNLIT_DEFINITION = {
|
||||
.vert =
|
||||
#ifdef DUSK_OPENGL_ES
|
||||
|
||||
"#version 300 es\n"
|
||||
"precision mediump float;\n"
|
||||
// Attributes
|
||||
"layout(location = 0) in vec3 a_Pos;\n"
|
||||
"layout(location = 1) in vec2 a_TexCoord;\n"
|
||||
"layout(location = 2) in vec4 a_Color;\n"
|
||||
// Uniforms
|
||||
"uniform mat4 u_Proj;\n"
|
||||
"uniform mat4 u_View;\n"
|
||||
"uniform mat4 u_Model;\n"
|
||||
// Vertex shader outputs
|
||||
"out vec4 v_Color;\n"
|
||||
"out vec2 v_TexCoord;\n"
|
||||
"void main() {\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",
|
||||
#else
|
||||
"#version 330 core\n"
|
||||
// Attributes
|
||||
@@ -97,7 +117,36 @@
|
||||
#endif
|
||||
.frag =
|
||||
#ifdef DUSK_OPENGL_ES
|
||||
|
||||
"#version 300 es\n"
|
||||
"precision mediump float;\n"
|
||||
// Uniforms
|
||||
"uniform sampler2D u_Texture;\n"
|
||||
"uniform int u_TextureType;\n"
|
||||
"uniform vec4 u_Colors[256];\n"// For paletted textures.
|
||||
"uniform int u_ColorCount;\n"
|
||||
// Fragment shader inputs
|
||||
"in vec4 v_Color;\n"
|
||||
"in vec2 v_TexCoord;\n"
|
||||
// Fragment shader output
|
||||
"out vec4 FragColor;\n"
|
||||
"void main() {\n"
|
||||
" if(u_TextureType == 0) {\n"// No texture
|
||||
" FragColor = v_Color;\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
" if(u_TextureType == 1) {\n"// Regular texture
|
||||
" FragColor = texture(u_Texture, v_TexCoord) * v_Color;\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
" if(u_TextureType == 2) {\n"// Paletted texture
|
||||
" vec4 texColor = texture(u_Texture, v_TexCoord);\n"
|
||||
" int index = int(floor(texColor.r * 255.0));\n"
|
||||
" vec4 paletteColor = u_Colors[index];\n"
|
||||
" FragColor = paletteColor;\n"
|
||||
" return;\n"
|
||||
" }\n"
|
||||
" FragColor = v_Color;\n"// Unknown texture type?
|
||||
"}\n",
|
||||
#else
|
||||
"#version 330 core\n"
|
||||
// Uniforms
|
||||
|
||||
@@ -17,16 +17,33 @@ errorret_t textureInitGL(
|
||||
const textureformatgl_t format,
|
||||
const texturedata_t data
|
||||
) {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
errorChain(errorGLCheck());
|
||||
glGenTextures(1, &texture->id);
|
||||
errorChain(errorGLCheck());
|
||||
glBindTexture(GL_TEXTURE_2D, texture->id);
|
||||
errorChain(errorGLCheck());
|
||||
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
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());
|
||||
|
||||
#ifdef DUSK_OPENGL_LEGACY
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
#endif
|
||||
|
||||
switch(format) {
|
||||
case TEXTURE_FORMAT_RGBA:
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D, 0, format, width, height, 0,
|
||||
format, GL_UNSIGNED_BYTE, (void*)data.rgbaColors
|
||||
GL_TEXTURE_2D, 0, 4, width, height, 0,
|
||||
GL_RGBA, GL_UNSIGNED_BYTE, (void*)data.rgbaColors
|
||||
);
|
||||
errorChain(errorGLCheck());
|
||||
break;
|
||||
@@ -34,7 +51,20 @@ errorret_t textureInitGL(
|
||||
case TEXTURE_FORMAT_PALETTE:
|
||||
texture->palette = data.paletted.palette;
|
||||
|
||||
assertTrue(
|
||||
texture->palette == &PALETTES[0],
|
||||
"Only the first palette is supported in legacy opengl."
|
||||
);
|
||||
|
||||
printf("sizeof(color_t)=%zu\n", sizeof(color_t));
|
||||
printf("count=%u\n", texture->palette->count);
|
||||
|
||||
#ifdef DUSK_OPENGL_LEGACY
|
||||
glColorTableEXT(
|
||||
GL_TEXTURE_2D, GL_RGBA, texture->palette->count, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, (const void*)texture->palette->colors
|
||||
);
|
||||
errorChain(errorGLCheck());
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0, GL_COLOR_INDEX8_EXT,
|
||||
@@ -42,13 +72,7 @@ errorret_t textureInitGL(
|
||||
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.
|
||||
@@ -65,15 +89,6 @@ errorret_t textureInitGL(
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user