8000 Headless renderer. Attempting something like in #76. · google-deepmind/lab@09177b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 09177b5

Browse files
committed
Headless renderer. Attempting something like in #76.
1 parent 1fd4ab6 commit 09177b5

File tree

2 files changed

+78
-14
lines changed

2 files changed

+78
-14
lines changed

BUILD

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -802,10 +802,26 @@ cc_library(
802802
hdrs = ["public/dmlab.h"],
803803
copts = IOQ3_COMMON_COPTS,
804804
defines = IOQ3_COMMON_DEFINES,
805-
linkopts = [
806-
"-lGL",
807-
"-lrt",
805+
linkopts = ["-framework OpenGL"],
806+
deps = IOQ3_COMMON_DEPS,
807+
)
808+
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",
808820
],
821+
hdrs = ["public/dmlab.h"],
822+
copts = IOQ3_COMMON_COPTS,
823+
defines = IOQ3_COMMON_DEFINES,
824+
linkopts = ["-framework OpenGL"],
809825
deps = IOQ3_COMMON_DEPS,
810826
)
811827

@@ -897,27 +913,18 @@ config_setting(
897913

898914
cc_binary(
899915
name = "libdmlab_headless_hw.so",
900-
linkopts = ["-Wl,--version-script,$(location :dmlab.lds)"],
901916
linkshared = 1,
902917
linkstatic = 1,
903918
visibility = ["//testing:__subpackages__"],
904-
deps = [":dmlab.lds"] + select({
905-
"dmlab_graphics_osmesa_or_egl": [":game_lib_headless_egl"],
906-
"dmlab_graphics_osmesa_or_glx": [":game_lib_headless_glx"],
907-
"//conditions:default": [":game_lib_headless_egl"],
908-
}),
919+
deps = [":game_lib_headless_macos"],
909920
)
910921

911922
cc_binary(
912923
name = "libdmlab_headless_sw.so",
913-
linkopts = ["-Wl,--version-script,$(location :dmlab.lds)"],
914924
linkshared = 1,
915925
linkstatic = 1,
916926
visibility = ["//testing:__subpackages__"],
917-
deps = [
918-
":dmlab.lds",
919-
":game_lib_headless_osmesa",
920-
],
927+
deps = [":game_lib_headless_osmesa"],
921928
)
922929

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

0 commit comments

Comments
 (0)
0