Skip to content

Commit

Permalink
update OSMesa
Browse files Browse the repository at this point in the history
  • Loading branch information
ColleagueRiley committed Jan 5, 2025
1 parent 6ac8779 commit 3ca6614
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# RGFW_WAYLAND=1 -> use wayland
# NO_VULKAN=1 -> do not compile the vulkan example
# NO_GLES=1 -> do not compile the gles example (on by default for non-linux OSes)
# NO_OSMESA=1 -> do not compile the osmesa example (on by default for non-linux OSes)

CC = gcc
AR = ar
Expand All @@ -23,6 +24,7 @@ WARNINGS = -Wall -Wstrict-prototypes -Wextra -Wstrict-prototypes -Wold-style-de
OS_DIR = \\

NO_GLES = 1
NO_OSMESA = 1
detected_OS = windows

OBJ_FILE = .o
Expand All @@ -46,6 +48,7 @@ ifeq (,$(filter $(CC),x86_64-w64-mingw32-gcc i686-w64-mingw32-gcc x86_64-w64-min
LIB_EXT = .so
OS_DIR = /
NO_GLES = 0
NO_OSMESA = 0
endif
else
OS_DIR = /
Expand Down Expand Up @@ -79,6 +82,8 @@ else ifneq ($(CC),g++)
LIBS += -std=c99
endif

LIBS += -lOSMesa

EXAMPLE_OUTPUTS = \
examples/basic/basic \
examples/gamepad/gamepad \
Expand All @@ -93,6 +98,7 @@ EXAMPLE_OUTPUTS_CUSTOM = \
examples/gl33/gl33 \
examples/portableGL/pgl \
examples/gles2/gles2 \
examples/osmesa/osmesa \
examples/vk10/vk10 \
examples/dx11/dx11 \
examples/metal/metal \
Expand All @@ -116,6 +122,13 @@ else
@echo gles has been disabled
endif

examples/osmesa/osmesa: examples/osmesa/osmesa.c RGFW.h
ifneq ($(NO_GLES), 1)
$(CC) $(CFLAGS) -I. $< $(LIBS) $(LINK_GL2) -lOSMesa -o $@$(EXT)
else
@echo gles has been disabled
endif

examples/vk10/vk10: examples/vk10/vk10.c RGFW.h
ifneq ($(NO_VULKAN), 1)
glslangValidator -V examples/vk10/shaders/vert.vert -o examples/vk10/shaders/vert.h --vn vert_code
Expand Down Expand Up @@ -174,6 +187,9 @@ debug: all
ifneq ($(NO_GLES), 1)
./examples/gles2/gles2$(EXT)
endif
ifneq ($(NO_OSMESA), 1)
./examples/gles2/gles2$(EXT)
endif
ifneq ($(NO_VULKAN), 1)
./examples/vk10/vk10$(EXT)
endif
Expand Down
9 changes: 5 additions & 4 deletions RGFW.h
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,7 @@ RGFWDEF void RGFW_OSMesa_reorganize(RGFW_window* win);

/* reorganize buffer for osmesa */
void RGFW_OSMesa_reorganize(RGFW_window* win) {
return;
u8* row = (u8*) RGFW_MALLOC(RGFW_bufferSize.w * 3);

i32 half_height = RGFW_bufferSize.h / 2;
Expand Down Expand Up @@ -2485,8 +2486,8 @@ void RGFW_init_buffer(RGFW_window* win, XVisualInfo* vi) {
#endif

#ifdef RGFW_OSMESA
win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h);
win->src.ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, RGFW_bufferSize.w, RGFW_bufferSize.h);
#endif

win->src.bitmap = XCreateImage(
Expand Down Expand Up @@ -3990,8 +3991,8 @@ void RGFW_window_swapBuffers(RGFW_window* win) {
RGFW_OSMesa_reorganize(win);
#endif

#ifndef RGFW_X11_DONT_CONVERT_BGR
win->src.bitmap->data = (char*) win->buffer;
win->src.bitmap->data = (char*) win->buffer;
#if !defined(RGFW_X11_DONT_CONVERT_BGR) && !defined(RGFW_OSMESA)
u32 x, y;
for (y = 0; y < (u32)win->r.h; y++) {
for (x = 0; x < (u32)win->r.w; x++) {
Expand Down

0 comments on commit 3ca6614

Please sign in to comment.