Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions skeleton/BASE/Shaders/real-gameboy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ minarch_shader2_srctype = source
minarch_shader2_scaletype = source
minarch_shader2_upscale = screen
minarch_scale_filter = NEAREST
gambatte_gb_internal_palette = TWB64 - Pack 2
gambatte_gb_palette_twb64_2 = TWB64 163 - Classic LCD
gambatte_gb_colorization = internal
gambatte_gbc_color_correction = always
Expand Down
24 changes: 15 additions & 9 deletions workspace/all/minarch/minarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -1858,7 +1858,7 @@ static void Config_syncFrontend(char* key, int value) {
option->value = value;
}

char** list_files_in_folder(const char* folderPath, int* fileCount) {
char** list_files_in_folder(const char* folderPath, int* fileCount, const char* extensionFilter) {
DIR* dir = opendir(folderPath);
if (!dir) {
perror("opendir");
Expand All @@ -1875,10 +1875,16 @@ char** list_files_in_folder(const char* folderPath, int* fileCount) {
snprintf(fullPath, sizeof(fullPath), "%s/%s", folderPath, entry->d_name);

if (stat(fullPath, &fileStat) == 0 && S_ISREG(fileStat.st_mode)) {
char** temp = realloc(fileList, sizeof(char*) * (*fileCount + 2)); // +1 for new file, +1 for NULL
if (extensionFilter) {
const char* ext = strrchr(entry->d_name, '.');
if (!ext || strcmp(ext, extensionFilter) != 0) {
continue;
}
}

char** temp = realloc(fileList, sizeof(char*) * (*fileCount + 2));
if (!temp) {
perror("realloc");
// free previously allocated strings
for (int i = 0; i < *fileCount; ++i) {
free(fileList[i]);
}
Expand All @@ -1888,14 +1894,14 @@ char** list_files_in_folder(const char* folderPath, int* fileCount) {
}
fileList = temp;
fileList[*fileCount] = strdup(entry->d_name);
fileList[*fileCount + 1] = NULL; // maintain NULL-termination
fileList[*fileCount + 1] = NULL;
(*fileCount)++;
}
}

closedir(dir);

// Inline alphabetical sort
// Alphabetical sort
for (int i = 0; i < *fileCount - 1; ++i) {
for (int j = i + 1; j < *fileCount; ++j) {
if (strcmp(fileList[i], fileList[j]) > 0) {
Expand Down Expand Up @@ -1990,9 +1996,9 @@ static void Config_init(void) {

// populate shader options
int filecount;
char** filelist = list_files_in_folder(SHADERS_FOLDER "/glsl", &filecount);
char** filelist = list_files_in_folder(SHADERS_FOLDER "/glsl", &filecount,NULL);
int preset_filecount;
char** preset_filelist = list_files_in_folder(SHADERS_FOLDER, &preset_filecount);
char** preset_filelist = list_files_in_folder(SHADERS_FOLDER, &preset_filecount,".cfg");

config.shaders.options[SH_SHADER1].values = filelist;
config.shaders.options[SH_SHADER2].values = filelist;
Expand All @@ -2011,7 +2017,7 @@ static void Config_init(void) {

char overlaypath[255];
snprintf(overlaypath, sizeof(overlaypath), "%s/%s", OVERLAYS_FOLDER, core.tag);
char** overlaylist = list_files_in_folder(overlaypath, &filecount);
char** overlaylist = list_files_in_folder(overlaypath, &filecount,NULL);

if (overlaylist) {
int newcount = filecount + 1;
Expand Down Expand Up @@ -5321,7 +5327,7 @@ static int OptionShaders_openMenu(MenuList* list, int i) {


int filecount;
char** filelist = list_files_in_folder(SHADERS_FOLDER "/glsl", &filecount);
char** filelist = list_files_in_folder(SHADERS_FOLDER "/glsl", &filecount,NULL);

// Check if folder read failed or no files found
if (!filelist || filecount == 0) {
Expand Down
7 changes: 4 additions & 3 deletions workspace/macos/platform/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ static char* overlay_path = NULL;
GLuint link_program(GLuint vertex_shader, GLuint fragment_shader, const char* cache_key) {
char cache_path[512];
snprintf(cache_path, sizeof(cache_path), "/mnt/SDCARD/.shadercache/%s.bin", cache_key);


GLuint program = glCreateProgram();
GLint success;
Expand Down Expand Up @@ -496,7 +497,7 @@ char* load_shader_source(const char* filename) {

GLuint load_shader_from_file(GLenum type, const char* filename, const char* path) {
char filepath[256];
snprintf(filepath, sizeof(filepath), "%s/glsl/%s", path,filename);
snprintf(filepath, sizeof(filepath), "%s/%s", path,filename);
char* source = load_shader_source(filepath);
if (!source) return 0;

Expand Down Expand Up @@ -807,8 +808,8 @@ void PLAT_updateShader(int i, const char *filename, int *scale, int *filter, int
if (filename != NULL) {
SDL_GL_MakeCurrent(vid.window, vid.gl_context);
LOG_info("loading shader \n");
GLuint vertex_shader1 = load_shader_from_file(GL_VERTEX_SHADER, filename,SHADERS_FOLDER);
GLuint fragment_shader1 = load_shader_from_file(GL_FRAGMENT_SHADER, filename,SHADERS_FOLDER);
GLuint vertex_shader1 = load_shader_from_file(GL_VERTEX_SHADER, filename,SHADERS_FOLDER "/glsl");
GLuint fragment_shader1 = load_shader_from_file(GL_FRAGMENT_SHADER, filename,SHADERS_FOLDER "/glsl");

// Link the shader program
if (shader->shader_p != 0) {
Expand Down
6 changes: 3 additions & 3 deletions workspace/tg5040/platform/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ char* load_shader_source(const char* filename) {

GLuint load_shader_from_file(GLenum type, const char* filename, const char* path) {
char filepath[256];
snprintf(filepath, sizeof(filepath), "%s/glsl/%s", path,filename);
snprintf(filepath, sizeof(filepath), "%s/%s", path,filename);
char* source = load_shader_source(filepath);
if (!source) return 0;

Expand Down Expand Up @@ -522,8 +522,8 @@ void PLAT_updateShader(int i, const char *filename, int *scale, int *filter, int
if (filename != NULL) {
SDL_GL_MakeCurrent(vid.window, vid.gl_context);
LOG_info("loading shader \n");
GLuint vertex_shader1 = load_shader_from_file(GL_VERTEX_SHADER, filename,SHADERS_FOLDER);
GLuint fragment_shader1 = load_shader_from_file(GL_FRAGMENT_SHADER, filename,SHADERS_FOLDER);
GLuint vertex_shader1 = load_shader_from_file(GL_VERTEX_SHADER, filename,SHADERS_FOLDER "/glsl");
GLuint fragment_shader1 = load_shader_from_file(GL_FRAGMENT_SHADER, filename,SHADERS_FOLDER "/glsl");

// Link the shader program
if (shader->shader_p != 0) {
Expand Down