Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
669b230
gles2 take 2??
cobaltgit Jun 22, 2026
98d72c2
remove remnants
cobaltgit Jun 22, 2026
c3c4f3e
forgot to guard some vertex array calls...
cobaltgit Jun 22, 2026
4f93c84
less hacky GLES2 fallback...but
cobaltgit Jun 22, 2026
151f9b8
glDestroy: guard deletevertexarrays
cobaltgit Jun 22, 2026
75acecf
better GLES 3 check
cobaltgit Jun 22, 2026
dedafbf
stuff
cobaltgit Jun 22, 2026
bffe4a9
(hackily) stub out shaders on gles2
cobaltgit Jun 22, 2026
549ec8e
fix VAO check for GLES3
cobaltgit Jun 22, 2026
dc607af
better gles3 check
cobaltgit Jun 23, 2026
2330cce
fix sdl2/3 sharting the bed when compiling a shader in gles3 mode
cobaltgit Jun 23, 2026
aa41496
slim shady
cobaltgit Jun 23, 2026
ced0235
power of two texparameteri
cobaltgit Jun 23, 2026
3e1cde9
blegh
cobaltgit Jun 23, 2026
dd7f5ed
fixy fixy
cobaltgit Jun 23, 2026
48190c6
force off VAOs for GLES2 for now and move up SDL GLES2 fallback
cobaltgit Jun 23, 2026
e611047
try bring back VAOs for GLES2 systems that have the VAO extension
cobaltgit Jun 23, 2026
6ec0c73
also add vao extension to GLES glad
cobaltgit Jun 23, 2026
3006ad1
remember you're semicolons
cobaltgit Jun 23, 2026
592cd27
gate fallback vao functions behind gles
cobaltgit Jun 23, 2026
6e94ec5
better vao check + fix web build
cobaltgit Jun 23, 2026
69da76c
stuff
cobaltgit Jun 23, 2026
477b947
society if the web build was dropped
cobaltgit Jun 23, 2026
ab65a08
screw you *unfalls your back*
cobaltgit Jun 23, 2026
532dd46
and here
cobaltgit Jun 23, 2026
5d8c823
Make the modern GL renderer compatible with OpenGL 2.1
cobaltgit Jun 24, 2026
c6b1b06
Merge pull request #3 from cobaltgit/modern-gl2
cobaltgit Jun 24, 2026
f2cea3d
fix glfw2
cobaltgit Jun 24, 2026
8fb010e
fix web
cobaltgit Jun 24, 2026
561c68f
)
cobaltgit Jun 24, 2026
32992ca
FBO runtime check
cobaltgit Jun 24, 2026
eb33b72
wip: check for gles at runtime instead of compile-time
cobaltgit Jun 25, 2026
f4548bd
gles runtime check except it doesn't work
cobaltgit Jun 25, 2026
8be83ca
fix build, make shaders work with opengl 3.0
cobaltgit Jun 25, 2026
e7ddcfd
remove unused gl funcs
cobaltgit Jun 25, 2026
6e8cbe1
fix glfw2
cobaltgit Jun 25, 2026
da1d85b
what
cobaltgit Jun 25, 2026
a98d7c1
cobalt poopensharten
cobaltgit Jun 25, 2026
6674181
wipe ENABLE_GLES from the face of the earth...still need to fix the p…
cobaltgit Jun 25, 2026
f3f4a8c
proper gl runtime fallback blegh someone test glfw2 with both renderers
cobaltgit Jun 25, 2026
c4c6a5e
glfw3: use the damn title
cobaltgit Jun 25, 2026
26d4ba1
match glfw gl context errors to sdl
cobaltgit Jun 25, 2026
7d680e8
shithousery to get opengl 2.0 shaders working
cobaltgit Jun 25, 2026
5d3fc4a
blegh
cobaltgit Jun 25, 2026
24516c4
safeStrdup
cobaltgit Jun 25, 2026
0bbc770
merge upstream
cobaltgit Jun 25, 2026
b72df77
manually reset GL attributes on SDL 2.0.0/2.0.1
cobaltgit Jun 25, 2026
7b15b18
merge again grrr
cobaltgit Jun 25, 2026
e6cbd3d
use SDL_VERSION_ATLEAST
cobaltgit Jun 25, 2026
dacb734
only reset touched attributes
cobaltgit Jun 25, 2026
0470041
cleanup
cobaltgit Jun 25, 2026
9925b61
DNDEBUG
cobaltgit Jun 25, 2026
3bf7c2d
stuff
cobaltgit Jun 25, 2026
7355e7c
better fbo check
cobaltgit Jun 25, 2026
5a1399c
nvm
cobaltgit Jun 25, 2026
1140d52
no guard
cobaltgit Jun 25, 2026
0f3d3f0
get rid of stray ifdefs in glfw2
cobaltgit Jun 25, 2026
c83e886
camelCase
cobaltgit Jun 25, 2026
2c02a2d
GLFW_OPENGL_ES_API
cobaltgit Jun 25, 2026
ff53dcf
GLFW_CLIENT_API
cobaltgit Jun 25, 2026
e24f1ba
remove gles from glfw2
cobaltgit Jun 25, 2026
65ec943
camelcase
cobaltgit Jun 25, 2026
58705d0
cleanup
cobaltgit Jun 25, 2026
fdf6c5c
dedent
cobaltgit Jun 25, 2026
861783e
fix legacy-gl
cobaltgit Jun 25, 2026
bd823cd
software
cobaltgit Jun 25, 2026
a1dba77
stuff
cobaltgit Jun 25, 2026
eac0579
stuff, use glgetstringi for opengl 3+
cobaltgit Jun 26, 2026
4ecdd79
-werror count your days
cobaltgit Jun 26, 2026
c526a58
grrrr
cobaltgit Jun 26, 2026
575d7c5
what
cobaltgit Jun 26, 2026
4677521
stupid wasm target
cobaltgit Jun 26, 2026
0df732c
i am literally half-asleep doing this
cobaltgit Jun 26, 2026
6f3ca20
crapple
cobaltgit Jun 26, 2026
8068993
ufo: *flies past*
cobaltgit Jun 26, 2026
79a5b19
sdl3 fix stoopid
cobaltgit Jun 26, 2026
777b3d8
remove core profile, better fbo/vao checks
cobaltgit Jun 26, 2026
7d515cd
also remove core from glfw2 for the <5 people who use that windowing …
cobaltgit Jun 26, 2026
395ffd3
remove possibly unused defines
cobaltgit Jun 26, 2026
c48ce24
comment
cobaltgit Jun 26, 2026
82362f9
legacy-gl: bail if FBOs unsupported
cobaltgit Jun 26, 2026
5c4b620
legacy-gl: change fbo error message
cobaltgit Jun 26, 2026
558bb2f
fix ps3
cobaltgit Jun 26, 2026
6ee0c55
shut up and merge: gaiden
cobaltgit Jun 26, 2026
8d7cea8
fix ps3 2: electric boogaloo
cobaltgit Jun 26, 2026
7a14b4a
fix compilers older than myself
cobaltgit Jun 26, 2026
7492a2d
cast mallocs
cobaltgit Jun 26, 2026
78eca22
forgot one
cobaltgit Jun 26, 2026
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
17 changes: 2 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ endif()
# Platform specific files builds
file(GLOB PLATFORM_SOURCES src/${PLATFORM}/*.c)

# OpenGL ES 3.0 / WebGL2 compatibility
option(ENABLE_GLES "Build the gl_renderer against OpenGL ES 3.0 / WebGL2 instead of desktop GL 4.1 Core" OFF)
if (ENABLE_GLES AND ENABLE_LEGACY_GL)
set(ENABLE_LEGACY_GL OFF)
endif()

add_executable(butterscotch ${SOURCES} ${PLATFORM_SOURCES} ${AUDIO_SOURCES})
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src)

Expand Down Expand Up @@ -220,14 +214,8 @@ if(PLATFORM STREQUAL "desktop")
endif()

# GLAD
if(ENABLE_GLES)
add_compile_definitions(ENABLE_GLES)
add_library(glad STATIC vendor/glad-gles/src/glad.c)
target_include_directories(glad PUBLIC vendor/glad-gles/include)
else()
add_library(glad STATIC vendor/glad/src/glad.c)
target_include_directories(glad PUBLIC vendor/glad/include)
endif()
add_library(glad STATIC vendor/glad/src/glad.c)
target_include_directories(glad PUBLIC vendor/glad/include)

# stb_image
target_include_directories(butterscotch PUBLIC vendor/stb/image)
Expand Down Expand Up @@ -318,7 +306,6 @@ elseif(PLATFORM STREQUAL "web")
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/gl_common)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/image)
add_compile_definitions(ENABLE_GLES)

# stb_image
target_include_directories(butterscotch PUBLIC vendor/stb/image)
Expand Down
11 changes: 0 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,11 @@ ENABLE_GLAD := 1
endif

ifndef DISABLE_LEGACY_GL
ifndef ENABLE_GLES
DEFINES += -DENABLE_LEGACY_GL
SRCS += $(wildcard src/gl_legacy/*.c)
INCLUDES += -Isrc/gl_legacy
HEADERS += $(wildcard src/gl_legacy/*.h) $(wildcard src/gl/*.h)
endif
endif

ifndef DISABLE_MODERN_GL
DEFINES += -DENABLE_MODERN_GL
Expand All @@ -124,10 +122,6 @@ $(error must enable at least 1 renderer)
endif
endif

ifdef ENABLE_GLES
DEFINES += -DENABLE_GLES
endif

ifeq ($(AUDIO_BACKEND),miniaudio)
INCLUDES += -Isrc/audio/miniaudio -Ivendor/miniaudio
DEFINES += -DUSE_MINIAUDIO
Expand All @@ -150,14 +144,9 @@ endif
endif

ifdef ENABLE_GLAD
ifdef ENABLE_GLES
SRCS += vendor/glad-gles/src/glad.c
INCLUDES += -Ivendor/glad-gles/include
else
SRCS += vendor/glad/src/glad.c
INCLUDES += -Ivendor/glad/include
endif
endif

ifeq ($(OS),Windows)
LIBS += -static -lwinmm
Expand Down
78 changes: 38 additions & 40 deletions src/desktop/backends/glfw2.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,43 @@

static Runner *g_runner;

static bool tryOpenWindow(int reqW, int reqH) {
#ifdef GLFW_OPENGL_VERSION_MAJOR
Comment thread
Un1q32 marked this conversation as resolved.
if (gfx == SOFTWARE || gfx == LEGACY_GL) {
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 1);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, (gfx == SOFTWARE) ? 0 : 1);
return glfwOpenWindow(reqW, reqH, 8, 8, 8, 8, 24, 8, GLFW_WINDOW) != 0;
}

for (size_t i = 0; i < sizeof(GLCommon_versions)/sizeof(GLCommon_versions[0]); i++) {
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, GLCommon_versions[i].major);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, GLCommon_versions[i].minor);

if (GLCommon_versions[i].major >= 3) {
if (GLCommon_versions[i].major == 3 && GLCommon_versions[i].minor == 2) {
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
} else {
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
}
} else {
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, 0);
}

#ifndef NDEBUG
glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
#endif
if (glfwOpenWindow(reqW, reqH, 8, 8, 8, 8, 24, 8, GLFW_WINDOW) != 0) {
return true;
}
glfwCloseWindow();
}

return false;
#else
return glfwOpenWindow(reqW, reqH, 8, 8, 8, 8, 24, 8, GLFW_WINDOW) != 0;
#endif
}

void platformSetWindowTitle(const char* title) {
char windowTitle[256];
snprintf(windowTitle, sizeof(windowTitle), "Butterscotch - %s", title);
Expand Down Expand Up @@ -152,52 +189,13 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless)
return false;
}

#ifdef GLFW_OPENGL_VERSION_MAJOR
if (gfx == SOFTWARE) {
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 1);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 0);
} else if (gfx == LEGACY_GL) {
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 1);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
} else {
#ifdef ENABLE_GLES
glfwOpenWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 0);
#else
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
#endif
}
#endif

// Init GLFW
if (!glfwInit()) {
fprintf(stderr, "Failed to initialize GLFW\n");
return false;
}

#ifdef GLFW_OPENGL_VERSION_MAJOR
if (gfx == SOFTWARE) {
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 1);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 0);
} else if (gfx == LEGACY_GL) {
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 1);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
} else {
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwOpenWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
}
#endif

int window = glfwOpenWindow(reqW, reqH, 8, 8, 8, 8, 24, 8, GLFW_WINDOW);
if (!window) {
if (!tryOpenWindow(reqW, reqH)) {
fprintf(stderr, "Failed to create GLFW window\n");
glfwTerminate();
return false;
Expand Down
72 changes: 51 additions & 21 deletions src/desktop/backends/glfw3.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,56 @@ static void framebufferToLogical(float xs, float ys, int fbW, int fbH, int* outW
*outH = (ys > 0.0f) ? (int) ceilf((float) fbH / ys) : fbH;
}

static GLFWwindow *tryOpenWindow(int reqW, int reqH, const char* title) {
if (gfx == SOFTWARE || gfx == LEGACY_GL) {
glfwDefaultWindowHints();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, (gfx == SOFTWARE) ? 0 : 1);

#ifndef NDEBUG
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
#endif

return glfwCreateWindow(reqW, reqH, title, NULL, NULL);
}

for (size_t i = 0; i < sizeof(GLCommon_versions)/sizeof(GLCommon_versions[0]); i++) {
GLFWwindow *window;

glfwDefaultWindowHints();

#ifndef NDEBUG
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
#endif

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, GLCommon_versions[i].major);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, GLCommon_versions[i].minor);

if (GLCommon_versions[i].gles) {
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
} else {
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_API);
if (GLCommon_versions[i].major >= 3) {
if (GLCommon_versions[i].major == 3 && GLCommon_versions[i].minor == 2) {
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
} else {
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
}
} else {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
}
}

window = glfwCreateWindow(reqW, reqH, title, NULL, NULL);
if (window) {
return window;
}

}

return NULL;
}

void platformSetWindowTitle(const char* title) {
char windowTitle[256];
snprintf(windowTitle, sizeof(windowTitle), "Butterscotch - %s", title);
Expand Down Expand Up @@ -177,26 +227,6 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless)
return false;
}

if (gfx == SOFTWARE) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
} else if (gfx == LEGACY_GL) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 1);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
} else {
#ifdef ENABLE_GLES
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
#else
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
#endif
}

// init gamepad mappings
const char* dbPath = "gamecontrollerdb.txt";
FILE* f = fopen(dbPath, "r");
Expand Down Expand Up @@ -224,7 +254,7 @@ bool platformInit(int32_t reqW, int32_t reqH, const char *title, bool headless)
if (headless)
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);

window = glfwCreateWindow(reqW, reqH, title, nullptr, nullptr);
window = tryOpenWindow(reqW, reqH, title);
if (!window) {
fprintf(stderr, "Failed to create GLFW window\n");
glfwTerminate();
Expand Down
Loading
Loading