Skip to content

Commit d331d4b

Browse files
committed
Headless renderer. Attempting something like in #76.
1 parent cddcfa5 commit d331d4b

File tree

2 files changed

+82
-19
lines changed

2 files changed

+82
-19
lines changed

Diff for: BUILD

+24-19
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,26 @@ 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+
alwayslink = 1,
828+
)
829+
810830
cc_library(
811831
name = "game_lib_headless_osmesa",
812832
srcs = IOQ3_COMMON_SRCS + [
@@ -842,10 +862,7 @@ cc_library(
842862
hdrs = ["public/dmlab.h"],
843863
copts = IOQ3_COMMON_COPTS,
844864
defines = IOQ3_COMMON_DEFINES,
845-
linkopts = [
846-
"-lGL",
847-
"-lX11",
848-
],
865+
linkopts = ["-framework OpenGL"],
849866
deps = IOQ3_COMMON_DEPS,
850867
alwayslink = 1,
851868
)
@@ -865,10 +882,7 @@ cc_library(
865882
hdrs = ["public/dmlab.h"],
866883
copts = IOQ3_COMMON_COPTS,
867884
defines = IOQ3_COMMON_DEFINES,
868-
linkopts = [
869-
"-lEGL",
870-
"-lGL",
871-
],
885+
linkopts = ["-framework OpenGL"],
872886
deps = IOQ3_COMMON_DEPS + ["//third_party/GL/util:egl_util"],
873887
alwayslink = 1,
874888
)
@@ -898,27 +912,18 @@ config_setting(
898912

899913
cc_binary(
900914
name = "libdmlab_headless_hw.so",
901-
linkopts = ["-Wl,--version-script,$(location :dmlab.lds)"],
902915
linkshared = 1,
903916
linkstatic = 1,
904917
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-
}),
918+
deps = [":game_lib_headless_macos"],
910919
)
911920

912921
cc_binary(
913922
name = "libdmlab_headless_sw.so",
914-
linkopts = ["-Wl,--version-script,$(location :dmlab.lds)"],
915923
linkshared = 1,
916924
linkstatic = 1,
917925
visibility = ["//testing:__subpackages__"],
918-
deps = [
919-
":dmlab.lds",
920-
":game_lib_headless_osmesa",
921-
],
926+
deps = [":game_lib_headless_osmesa"],
922927
)
923928

924929
cc_library(

Diff for: engine/code/deepmind/headless_macos_glimp.c

+58
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)