Skip to content

Commit 2f55247

Browse files
committed
Headless renderer. Attempting something like in #76.
1 parent 483dfb0 commit 2f55247

File tree

2 files changed

+81
-19
lines changed

2 files changed

+81
-19
lines changed

Diff for: BUILD

+23-19
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,25 @@ cc_library(
806806
deps = IOQ3_COMMON_DEPS,
807807
)
808808

809+
cc_library(
810+
name = "game_lib_headless_macos",
811+
srcs = IOQ3_COMMON_SRCS + [
812+
CODE_DIR + "/deepmind/dmlab_connect.c",
813+
CODE_DIR + "/null/null_input.c",
814+
CODE_DIR + "/null/null_snddma.c",
815+
816+
## OpenGL rendering
817+
CODE_DIR + "/deepmind/headless_macos_glimp.c",
818+
CODE_DIR + "/deepmind/glimp_common.h",
819+
CODE_DIR + "/deepmind/glimp_common.c",
820+
],
821+
hdrs = ["public/dmlab.h"],
822+
copts = IOQ3_COMMON_COPTS,
823+
defines = IOQ3_COMMON_DEFINES,
824+
linkopts = ["-framework OpenGL"],
825+
deps = IOQ3_COMMON_DEPS,
826+
)
827+
809828
cc_library(
810829
name = "game_lib_headless_osmesa",
811830
srcs = IOQ3_COMMON_SRCS + [
@@ -840,10 +859,7 @@ cc_library(
840859
hdrs = ["public/dmlab.h"],
841860
copts = IOQ3_COMMON_COPTS,
842861
defines = IOQ3_COMMON_DEFINES,
843-
linkopts = [
844-
"-lGL",
845-
"-lX11",
846-
],
862+
linkopts = ["-framework OpenGL"],
847863
deps = IOQ3_COMMON_DEPS,
848864
)
849865

@@ -862,10 +878,7 @@ cc_library(
862878
hdrs = ["public/dmlab.h"],
863879
copts = IOQ3_COMMON_COPTS,
864880
defines = IOQ3_COMMON_DEFINES,
865-
linkopts = [
866-
"-lEGL",
867-
"-lGL",
868-
],
881+
linkopts = ["-framework OpenGL"],
869882
deps = IOQ3_COMMON_DEPS + ["//third_party/GL/util:egl_util"],
870883
)
871884

@@ -894,27 +907,18 @@ config_setting(
894907

895908
cc_binary(
896909
name = "libdmlab_headless_hw.so",
897-
linkopts = ["-Wl,--version-script,$(location :dmlab.lds)"],
898910
linkshared = 1,
899911
linkstatic = 1,
900912
visibility = ["//testing:__subpackages__"],
901-
deps = [":dmlab.lds"] + select({
902-
"dmlab_graphics_osmesa_or_egl": [":game_lib_headless_egl"],
903-
"dmlab_graphics_osmesa_or_glx": [":game_lib_headless_glx"],
904-
"//conditions:default": [":game_lib_headless_egl"],
905-
}),
913+
deps = [":game_lib_headless_macos"],
906914
)
907915

908916
cc_binary(
909917
name = "libdmlab_headless_sw.so",
910-
linkopts = ["-Wl,--version-script,$(location :dmlab.lds)"],
911918
linkshared = 1,
912919
linkstatic = 1,
913920
visibility = ["//testing:__subpackages__"],
914-
deps = [
915-
":dmlab.lds",
916-
":game_lib_headless_osmesa",
917-
],
921+
deps = [":game_lib_headless_osmesa"],
918922
)
919923

920924
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)