Skip to content

Commit 3ca6614

Browse files
update OSMesa
1 parent 6ac8779 commit 3ca6614

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# RGFW_WAYLAND=1 -> use wayland
33
# NO_VULKAN=1 -> do not compile the vulkan example
44
# NO_GLES=1 -> do not compile the gles example (on by default for non-linux OSes)
5+
# NO_OSMESA=1 -> do not compile the osmesa example (on by default for non-linux OSes)
56

67
CC = gcc
78
AR = ar
@@ -23,6 +24,7 @@ WARNINGS = -Wall -Wstrict-prototypes -Wextra -Wstrict-prototypes -Wold-style-de
2324
OS_DIR = \\
2425

2526
NO_GLES = 1
27+
NO_OSMESA = 1
2628
detected_OS = windows
2729

2830
OBJ_FILE = .o
@@ -46,6 +48,7 @@ ifeq (,$(filter $(CC),x86_64-w64-mingw32-gcc i686-w64-mingw32-gcc x86_64-w64-min
4648
LIB_EXT = .so
4749
OS_DIR = /
4850
NO_GLES = 0
51+
NO_OSMESA = 0
4952
endif
5053
else
5154
OS_DIR = /
@@ -79,6 +82,8 @@ else ifneq ($(CC),g++)
7982
LIBS += -std=c99
8083
endif
8184

85+
LIBS += -lOSMesa
86+
8287
EXAMPLE_OUTPUTS = \
8388
examples/basic/basic \
8489
examples/gamepad/gamepad \
@@ -93,6 +98,7 @@ EXAMPLE_OUTPUTS_CUSTOM = \
9398
examples/gl33/gl33 \
9499
examples/portableGL/pgl \
95100
examples/gles2/gles2 \
101+
examples/osmesa/osmesa \
96102
examples/vk10/vk10 \
97103
examples/dx11/dx11 \
98104
examples/metal/metal \
@@ -116,6 +122,13 @@ else
116122
@echo gles has been disabled
117123
endif
118124

125+
examples/osmesa/osmesa: examples/osmesa/osmesa.c RGFW.h
126+
ifneq ($(NO_GLES), 1)
127+
$(CC) $(CFLAGS) -I. $< $(LIBS) $(LINK_GL2) -lOSMesa -o $@$(EXT)
128+
else
129+
@echo gles has been disabled
130+
endif
131+
119132
examples/vk10/vk10: examples/vk10/vk10.c RGFW.h
120133
ifneq ($(NO_VULKAN), 1)
121134
glslangValidator -V examples/vk10/shaders/vert.vert -o examples/vk10/shaders/vert.h --vn vert_code
@@ -174,6 +187,9 @@ debug: all
174187
ifneq ($(NO_GLES), 1)
175188
./examples/gles2/gles2$(EXT)
176189
endif
190+
ifneq ($(NO_OSMESA), 1)
191+
./examples/gles2/gles2$(EXT)
192+
endif
177193
ifneq ($(NO_VULKAN), 1)
178194
./examples/vk10/vk10$(EXT)
179195
endif

RGFW.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2242,6 +2242,7 @@ RGFWDEF void RGFW_OSMesa_reorganize(RGFW_window* win);
22422242

22432243
/* reorganize buffer for osmesa */
22442244
void RGFW_OSMesa_reorganize(RGFW_window* win) {
2245+
return;
22452246
u8* row = (u8*) RGFW_MALLOC(RGFW_bufferSize.w * 3);
22462247

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

24872488
#ifdef RGFW_OSMESA
2488-
win->src.ctx = OSMesaCreateContext(OSMESA_RGBA, NULL);
2489-
OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, win->r.w, win->r.h);
2489+
win->src.ctx = OSMesaCreateContext(OSMESA_BGRA, NULL);
2490+
OSMesaMakeCurrent(win->src.ctx, win->buffer, GL_UNSIGNED_BYTE, RGFW_bufferSize.w, RGFW_bufferSize.h);
24902491
#endif
24912492

24922493
win->src.bitmap = XCreateImage(
@@ -3990,8 +3991,8 @@ void RGFW_window_swapBuffers(RGFW_window* win) {
39903991
RGFW_OSMesa_reorganize(win);
39913992
#endif
39923993

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

0 commit comments

Comments
 (0)