DEbug not working so moving pcs

This commit is contained in:
2026-02-15 16:41:33 -06:00
parent 92a753560b
commit 99d030003c
20 changed files with 634 additions and 127 deletions

View File

@@ -17,11 +17,8 @@
#include "display/text.h"
#include "assert/assert.h"
#include "util/memory.h"
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include "util/string.h"
#include "asset/asset.h"
display_t DISPLAY = { 0 };
@@ -79,6 +76,36 @@ errorret_t displayInit(void) {
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
// Get and validate GL state.
GLenum err = glGetError();
if(err != GL_NO_ERROR) {
assertUnreachable("GL Error before checking support");
}
// Check if paletted textures are supported.
#if PSP
DISPLAY.usingShaderedPalettes = false;
#else
GLint mask = 0;
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
if(mask & GL_CONTEXT_CORE_PROFILE_BIT) {
GLint numExtens = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &numExtens);
for(GLint i = 0; i < numExtens; ++i) {
const char* e = (const char*)glGetStringi(GL_EXTENSIONS, i);
if(!e) continue;
if(stringCompare(e, "GL_EXT_paletted_texture") != 0) continue;
DISPLAY.usingShaderedPalettes = false;
break;
}
} else {
const char* ext = (const char*)glGetString(GL_EXTENSIONS);
DISPLAY.usingShaderedPalettes = (
ext && strstr(ext, "GL_EXT_paletted_texture")
);
}
#endif
#elif DOLPHIN
VIDEO_Init();
DISPLAY.screenMode = VIDEO_GetPreferredMode(NULL);
@@ -155,6 +182,7 @@ errorret_t displayInit(void) {
frameBufferInitBackbuffer();
spriteBatchInit();
errorChain(textInit());
errorChain(assetLoad("main_palette.dpf", &PALETTES[0]));
screenInit();
errorOk();

View File

@@ -15,6 +15,7 @@ typedef struct {
#if DISPLAY_SDL2
SDL_Window *window;
SDL_GLContext glContext;
bool_t usingShaderedPalettes;
#elif DOLPHIN
void *frameBuffer[2];// Double-Bufferred

View File

@@ -5,4 +5,39 @@
* https://opensource.org/licenses/MIT
*/
#include "palette.h"
#include "palette.h"
#include "assert/assert.h"
#include "util/memory.h"
palette_t PALETTES[PALETTE_COUNT_MAX] = { 0 };
void paletteInit(
palette_t *palette,
const uint8_t colorCount,
const color_t *colors
) {
assertNotNull(palette, "Palette cannot be NULL");
assertTrue(colorCount > 0, "Color count must be greater than 0");
assertNotNull(colors, "Colors array cannot be NULL");
assertTrue(colorCount <= PALETTE_COLOR_COUNT_MAX, "Color count too big");
assertTrue(
palette - PALETTES < PALETTE_COUNT_MAX,
"Palette index out of range"
);
memoryZero(palette, sizeof(palette_t));
palette->colorCount = colorCount;
memoryCopy(colors, palette->colors, colorCount * sizeof(color_t));
}
void paletteBind(palette_t *palette, const uint8_t slot) {
assertNotNull(palette, "Palette cannot be NULL");
assertTrue(slot < PALETTE_COUNT_MAX, "Palette slot out of range");
// Nothing yet.
}
void paletteDispose(palette_t *palette) {
assertNotNull(palette, "Palette cannot be NULL");
}

View File

@@ -8,11 +8,40 @@
#pragma once
#include "display/color.h"
#define PALETTE_COUNT 4
#define PALETTE_COUNT_MAX 4
#define PALETTE_COLOR_COUNT_MAX 0xFF
typedef struct {
const uint8_t colorCount;
const color_t *colors;
uint8_t colorCount;
color_t colors[PALETTE_COLOR_COUNT_MAX];
} palette_t;
extern palette_t PALETTES[PALETTE_COUNT];
extern palette_t PALETTES[PALETTE_COUNT_MAX];
/**
* Initializes a palette with the given colors.
*
* @param palette The palette to initialize.
* @param colorCount The number of colors in the palette.
* @param colors An array of colors for the palette.
*/
void paletteInit(
palette_t *palette,
const uint8_t colorCount,
const color_t *colors
);
/**
* Binds a palette for use in rendering.
*
* @param palette The palette to bind.
* @param slot The slot to bind the palette to.
*/
void paletteBind(palette_t *palette, const uint8_t slot);
/**
* Disposes of a palette, freeing any associated resources.
*
* @param palette The palette to dispose.
*/
void paletteDispose(palette_t *palette);

View File

@@ -16,6 +16,7 @@ tileset_t DEFAULT_FONT_TILESET;
errorret_t textInit(void) {
errorChain(assetLoad("ui/minogram.dpt", &DEFAULT_FONT_TEXTURE));
errorChain(assetLoad("ui/minogram.dtf", &DEFAULT_FONT_TILESET));
errorOk();
}

View File

@@ -9,8 +9,7 @@
#include "assert/assert.h"
#include "util/memory.h"
#include "util/math.h"
#include "util/string.h"
#include "debug/debug.h"
#include "display/display.h"
const texture_t *TEXTURE_BOUND = NULL;
@@ -44,98 +43,21 @@ void textureInit(
);
break;
// case TEXTURE_FORMAT_ALPHA: {
// assertNotNull(data.alpha.data, "Alpha texture data cannot be NULL");
// #if PSP
// // PSP kinda broken with alpha textures, so we convert it to paletted
// // texture here. We also crunch the amount of alpha values.
// #define PSP_ALPHA_PALETTE_CRUNCH 4
// #define PSP_ALPHA_PALETTE_COUNT (256 / PSP_ALPHA_PALETTE_CRUNCH)
// color_t paletteColors[PSP_ALPHA_PALETTE_COUNT];
// for(uint8_t i = 0; i < PSP_ALPHA_PALETTE_COUNT; i++) {
// paletteColors[i].r = 0xFF;
// paletteColors[i].g = 0xFF;
// paletteColors[i].b = 0xFF;
// paletteColors[i].a = i * PSP_ALPHA_PALETTE_CRUNCH;
// }
// // Generate indexes, crunching the alpha values to fit.
// uint8_t indexes[width * height];
// for(int32_t i = 0; i < width * height; i++) {
// uint8_t alpha = data.alpha.data[i] / PSP_ALPHA_PALETTE_CRUNCH;;
// indexes[i] = alpha;
// }
// palette_t palette = {
// .colorCount = PSP_ALPHA_PALETTE_COUNT,
// .colors = paletteColors
// };
// return textureInit(
// texture, width, height, TEXTURE_FORMAT_PALETTE,
// (texturedata_t){
// .palette = { .palette = &palette, .data = indexes }
// }
// );
// #else
// glTexImage2D(
// GL_TEXTURE_2D, 0, format, width, height, 0,
// format, GL_UNSIGNED_BYTE, (void*)data.alpha.data
// );
// #endif
// break;
// }
case TEXTURE_FORMAT_PALETTE:
assertNotNull(data.paletteData, "Palette texture data cannot be NULL");
// Get and validate the palette.
GLenum err = glGetError();
if(err != GL_NO_ERROR) {
assertUnreachable("GL Error before setting color table");
}
// Do we support paletted textures?
bool_t havePalTex = false;
#if PSP
havePalTex = true;
#else
GLint mask = 0;
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
if(mask & GL_CONTEXT_CORE_PROFILE_BIT) {
GLint numExtens = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &numExtens);
for(GLint i = 0; i < numExtens; ++i) {
const char* e = (const char*)glGetStringi(GL_EXTENSIONS, i);
if(!e) continue;
if(stringCompare(e, "GL_EXT_paletted_texture") != 0) continue;
havePalTex = true;
break;
}
} else {
const char* ext = (const char*)glGetString(GL_EXTENSIONS);
havePalTex = ext && strstr(ext, "GL_EXT_paletted_texture");
if(DISPLAY.usingShaderedPalettes) {
// Palette textures not supported, convert to GL_RED style texture
// so shader can perform the lookup.
uint8_t formatted[width * height];
for(int32_t i = 0; i < width * height; i++) {
uint8_t index = data.paletteData[i];
formatted[i] = index;
}
#endif
if(!havePalTex) {
assertUnreachable("Paletted textures not supported on this platform");
// Not supported, convert to RGBA using lookup
// color_t formatted[width * height];
// for(int32_t i = 0; i < width * height; i++) {
// uint8_t index = data..data[i];
// assertTrue(
// index < data.palette.palette->colorCount,
// "Palette index out of range"
// );
// formatted[i] = data.palette.palette->colors[index];
// }
// glTexImage2D(
// GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0,
// GL_RGBA, GL_UNSIGNED_BYTE, (void*)formatted
// );
glTexImage2D(
GL_TEXTURE_2D, 0, GL_R, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, (void*)formatted
);
} else {
glTexImage2D(
GL_TEXTURE_2D,