Skip to content

Commit bb70309

Browse files
committed
Headless renderer. Attempting something like in #76.
1 parent 7b4278d commit bb70309

File tree

2 files changed

+81
-19
lines changed

2 files changed

+81
-19
lines changed

BUILD

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,25 @@ cc_library(
807807
alwayslink = 1,
808808
)
809809

810+
cc_library(
811+
name = "game_lib_headless_macos",
812+
srcs = IOQ3_COMMON_SRCS + [
813+
CODE_DIR + "/deepmind/dmlab_connect.c",
814+
CODE_DIR + "/null/null_input.c",
815+
CODE_DIR + "/null/null_snddma.c",
816+
817+
## OpenGL rendering
818+
CODE_DIR + "/deepmind/headless_macos_glimp.c",
819+
CODE_DIR + "/deepmind/glimp_common.h",
820+
CODE_DIR + "/deepmind/glimp_common.c",
821+
],
822+
hdrs = ["public/dmlab.h"],
823+
copts = IOQ3_COMMON_COPTS,
824+
defines = IOQ3_COMMON_DEFINES,
825+
linkopts = ["-framework OpenGL"],
826+
deps = IOQ3_COMMON_DEPS,
827+
)
828+
810829
cc_library(
811830
name = "game_lib_headless_osmesa",
812831
srcs = IOQ3_COMMON_SRCS + [
@@ -842,10 +861,7 @@ cc_library(
842861
hdrs = ["public/dmlab.h"],
843862
copts = IOQ3_COMMON_COPTS,
844863
defines = IOQ3_COMMON_DEFINES,
845-
linkopts = [
846-
"-lGL",
847-
"-lX11",
848-
],
864+
linkopts = ["-framework OpenGL"],
849865
deps = IOQ3_COMMON_DEPS,
850866
alwayslink = 1,
851867
)
@@ -865,10 +881,7 @@ cc_library(
865881
hdrs = ["public/dmlab.h"],
866882
copts = IOQ3_COMMON_COPTS,
867883
defines = IOQ3_COMMON_DEFINES,
868-
linkopts = [
869-
"-lEGL",
870-
"-lGL",
871-
],
884+
linkopts = ["-framework OpenGL"],
872885
deps = IOQ3_COMMON_DEPS + ["//third_party/GL/util:egl_util"],
873886
alwayslink = 1,
874887
)
@@ -898,27 +911,18 @@ config_setting(
898911

899912
cc_binary(
900913
name = "libdmlab_headless_hw.so",
901-
linkopts = ["-Wl,--version-script,$(location :dmlab.lds)"],
902914
linkshared = 1,
903915
linkstatic = 1,
904916
visibility = ["//testing:__subpackages__"],
905-
deps = [":dmlab.lds"] + select({
906-
"dmlab_graphics_osmesa_or_egl": [":game_lib_headless_egl"],
907-
"dmlab_graphics_osmesa_or_glx": [":game_lib_headless_glx"],
908-
"//conditions:default": [":game_lib_headless_egl"],
909-
}),
917+
deps = [":game_lib_headless_macos"],
910918
)
911919

912920
cc_binary(
913921
name = "libdmlab_headless_sw.so",
914-
linkopts = ["-Wl,--version-script,$(location :dmlab.lds)"],
915922
linkshared = 1,
916923
linkstatic = 1,
917924
visibility = ["//testing:__subpackages__"],
918-
deps = [
919-
":dmlab.lds",
920-
":game_lib_headless_osmesa",
921-
],
925+
deps = [":game_lib_headless_osmesa"],
922926
)
923927

924928
cc_library(
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include <dlfcn.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
#include <OpenGL/OpenGL.h>
6+
#include <OpenGL/gl3.h>
7+
8+
#include "glimp_common.h"
9+
10+
static CGLContextObj context;
11+
12+
void GLimp_MakeCurrent(void) {
13+
}
14+
15+
void GLimp_Init(void) {
16+
CGLPixelFormatObj pix;
17+
GLint npix;
18+
int attribs[] = {
19+
kCGLPFAAccelerated, // no software rendering
20+
kCGLPFAOpenGLProfile,
21+
kCGLOGLPVersion_Legacy,
22+
0
23+
};
24+
25+
GLimp_CommonPreInit();
26+
27+
// NOTE: in headless mode there is no GUI, hence output to console instead of message boxes
28+
29+
if (CGLChoosePixelFormat((CGLPixelFormatAttribute*)attribs, &pix, &npix) != kCGLNoError) {
30+
// Sys_Error("GLimp_Init - choose pixel format error!\n");
31+
printf("GLimp_Init - choose pixel format error!\n");
32+
exit(1);
33+
}
34+
if (CGLCreateContext(pix, NULL, &context) != kCGLNoError) {
35+
// Sys_Error("GLimp_Init - create context error!\n");
36+
printf("GLimp_Init - create context error!\n");
37+
exit(1);
38+
}
39+
if (CGLSetCurrentContext(context) != kCGLNoError) {
40+
// Sys_Error("GLimp_Init - set current context error!");
41+
printf("GLimp_Init - set current context error!\n");
42+
exit(1);
43+
}
44+
CGLDestroyPixelFormat(pix);
45+
46+
printf("Renderer: %s\nVersion: %s\n", glGetString(GL_RENDERER), glGetString(GL_VERSION));
47+
48+
GLimp_CommonPostInit();
49+
}
50+
51+
void* GLimp_GetProcAddress(const char* func) {
52+
return dlsym(RTLD_SELF, func);
53+
}
54+
55+
void GLimp_Shutdown(void) {
56+
CGLSetCurrentContext(NULL);
57+
CGLDestroyContext(context);
58+
}

0 commit comments

Comments
 (0)