diff --git a/src/dusk/display/display.c b/src/dusk/display/display.c index 1e080e9..b9009ce 100644 --- a/src/dusk/display/display.c +++ b/src/dusk/display/display.c @@ -24,6 +24,11 @@ display_t DISPLAY = { 0 }; texture_t TEXTURE; +uint8_t indices[2 * 2] = { + 0, 1, + 2, 3 +}; + errorret_t displayInit(void) { memoryZero(&DISPLAY, sizeof(DISPLAY)); @@ -44,15 +49,9 @@ errorret_t displayInit(void) { 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( &TEXTURE, - 4, 4, + 2, 2, TEXTURE_FORMAT_PALETTE, (texturedata_t){ .paletted = { @@ -81,8 +80,6 @@ errorret_t displayUpdate(void) { SCREEN.background ); - errorChain(shaderBind(&SHADER_UNLIT)); - camera_t camera; // cameraInitOrthographic(&camera); // camera.orthographic.left = 0.0f; @@ -99,6 +96,7 @@ errorret_t displayUpdate(void) { cameraGetViewMatrix(&camera, view); glm_mat4_identity(model); + errorChain(shaderBind(&SHADER_UNLIT)); errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_PROJECTION, proj)); errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_VIEW, view)); errorChain(shaderSetMatrix(&SHADER_UNLIT, SHADER_UNLIT_MODEL, model)); diff --git a/src/dusk/display/texture/palette.h b/src/dusk/display/texture/palette.h index 25c7c8c..92fe39b 100644 --- a/src/dusk/display/texture/palette.h +++ b/src/dusk/display/texture/palette.h @@ -8,12 +8,12 @@ #pragma once #include "display/color.h" -#define PALETTE_COLOR_COUNT 256 +#define PALETTE_COLOR_COUNT 0xFF #define PALETTE_COUNT 6 typedef struct { - color_t colors[PALETTE_COLOR_COUNT]; uint8_t count; + color_t colors[PALETTE_COLOR_COUNT]; } palette_t; extern palette_t PALETTES[PALETTE_COUNT]; \ No newline at end of file diff --git a/src/dusk/display/texture/texture.c b/src/dusk/display/texture/texture.c index 49c6d65..99b2894 100644 --- a/src/dusk/display/texture/texture.c +++ b/src/dusk/display/texture/texture.c @@ -23,6 +23,18 @@ errorret_t textureInit( assertTrue(width == mathNextPowTwo(width), "Width must be a power of 2."); assertTrue(height == mathNextPowTwo(height), "Height must be a power of 2."); + if(texture->format == TEXTURE_FORMAT_RGBA) { + assertNotNull(data.rgbaColors, "RGBA color data cannot be NULL"); + } else if(texture->format == TEXTURE_FORMAT_PALETTE) { + assertNotNull(data.paletted.indices, "Palette indices cannot be NULL"); + assertNotNull(data.paletted.palette, "Palette colors cannot be NULL"); + assertTrue( + data.paletted.palette->count == + mathNextPowTwo(data.paletted.palette->count), + "Palette color count must be a power of 2" + ); + } + memoryZero(texture, sizeof(texture_t)); texture->width = width; texture->height = height; diff --git a/src/dusk/display/texture/texture.h b/src/dusk/display/texture/texture.h index ba4fb45..cb6f202 100644 --- a/src/dusk/display/texture/texture.h +++ b/src/dusk/display/texture/texture.h @@ -20,13 +20,11 @@ typedef textureformatplatform_t textureformat_t; typedef textureplatform_t texture_t; -typedef struct { - uint8_t *indices; - palette_t *palette; -} texturepalettedata_t; - typedef union texturedata_u { - texturepalettedata_t paletted; + struct { + uint8_t *indices; + palette_t *palette; + } paletted; color_t *rgbaColors; } texturedata_t; diff --git a/src/duskgl/display/displaygl.c b/src/duskgl/display/displaygl.c index e8b2420..cec37a0 100644 --- a/src/duskgl/display/displaygl.c +++ b/src/duskgl/display/displaygl.c @@ -9,20 +9,33 @@ errorret_t displayOpenGLInit(void) { glDisable(GL_CULL_FACE); - // glDisable(GL_LIGHTING);// PSP defaults this on? - // glShadeModel(GL_SMOOTH); // Fixes color on PSP? errorChain(errorGLCheck()); + #if DUSK_OPENGL_LEGACY + glDisable(GL_LIGHTING);// PSP defaults this on? + errorChain(errorGLCheck()); + glShadeModel(GL_SMOOTH); // Fixes color on PSP? + errorChain(errorGLCheck()); + #endif + glEnable(GL_DEPTH_TEST); + errorChain(errorGLCheck()); glDepthFunc(GL_LEQUAL); + errorChain(errorGLCheck()); glClearDepth(1.0f); errorChain(errorGLCheck()); glEnable(GL_BLEND); + 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()); + glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); + glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); + glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); errorOk(); } \ No newline at end of file diff --git a/src/duskgl/display/mesh/meshgl.c b/src/duskgl/display/mesh/meshgl.c index c931868..b325a73 100644 --- a/src/duskgl/display/mesh/meshgl.c +++ b/src/duskgl/display/mesh/meshgl.c @@ -27,7 +27,9 @@ errorret_t meshInitGL( #ifdef DUSK_OPENGL_LEGACY // Nothing needed. glEnableClientState(GL_COLOR_ARRAY); + errorChain(errorGLCheck()); glEnableClientState(GL_TEXTURE_COORD_ARRAY); + errorChain(errorGLCheck()); glEnableClientState(GL_VERTEX_ARRAY); errorChain(errorGLCheck()); #else diff --git a/src/duskgl/display/shader/shadergl.c b/src/duskgl/display/shader/shadergl.c index 31f1bdb..e7fa82a 100644 --- a/src/duskgl/display/shader/shadergl.c +++ b/src/duskgl/display/shader/shadergl.c @@ -213,7 +213,10 @@ errorret_t shaderSetTextureGL( assertStrLenMin(name, 1, "Uniform name cannot be empty"); #ifdef DUSK_OPENGL_LEGACY - assertUnreachable("Cannot set textures on legacy opengl."); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, texture->id); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + #else GLint location; errorChain(shaderParamGetLocationGL(shader, name, &location)); @@ -244,13 +247,7 @@ errorret_t shaderSetTextureGL( glUniform1uiv(location, texture->palette->count, paletteData); errorChain(errorGLCheck()); } - - // PALETTE TEST - // errorChain(shaderParamGetLocationGL(shader, "u_Palette", &location)); - // glActiveTexture(GL_TEXTURE1); - // errorChain(errorGLCheck()); - - + #endif errorOk(); diff --git a/src/duskgl/display/texture/texturegl.c b/src/duskgl/display/texture/texturegl.c index 1bd3564..d694383 100644 --- a/src/duskgl/display/texture/texturegl.c +++ b/src/duskgl/display/texture/texturegl.c @@ -18,6 +18,7 @@ errorret_t textureInitGL( const texturedata_t data ) { glGenTextures(1, &texture->id); + errorChain(errorGLCheck()); glBindTexture(GL_TEXTURE_2D, texture->id); errorChain(errorGLCheck()); @@ -27,11 +28,12 @@ errorret_t textureInitGL( GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, (void*)data.rgbaColors ); + errorChain(errorGLCheck()); break; case TEXTURE_FORMAT_PALETTE: - assertNotNull(data.paletted.indices, "Palette indices cannot be NULL"); - assertNotNull(data.paletted.palette, "Palette colors cannot be NULL"); + texture->palette = data.paletted.palette; + #ifdef DUSK_OPENGL_LEGACY glTexImage2D( GL_TEXTURE_2D, @@ -40,12 +42,13 @@ errorret_t textureInitGL( 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 + 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. @@ -54,7 +57,6 @@ errorret_t textureInitGL( GL_RED, GL_UNSIGNED_BYTE, (void*)data.paletted.indices ); errorChain(errorGLCheck()); - texture->palette = data.paletted.palette; #endif break; @@ -65,8 +67,11 @@ errorret_t textureInitGL( 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()); diff --git a/src/dusksdl2/display/displaysdl2.c b/src/dusksdl2/display/displaysdl2.c index c34d8f8..cd68331 100644 --- a/src/dusksdl2/display/displaysdl2.c +++ b/src/dusksdl2/display/displaysdl2.c @@ -21,11 +21,9 @@ errorret_t displaySDL2Init(void) { // Set OpenGL attributes (Needs to be done now or later?) SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - // SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); - // SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); #ifdef DUSK_OPENGL_LEGACY - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + // SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); #else SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); @@ -91,9 +89,8 @@ errorret_t displaySDL2Update(void) { } SDL_GL_MakeCurrent(DISPLAY.window, DISPLAY.glContext); - + errorChain(errorGLCheck()); // errorChain(shaderPaletteTextureBindGL(&testShader)); - errorOk(); }