Skip to content

Commit

Permalink
Headless renderer. Attempting something like in #76.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkoeppe committed Jul 22, 2019
1 parent 435a547 commit 15be743
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 19 deletions.
42 changes: 23 additions & 19 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,25 @@ cc_library(
deps = IOQ3_COMMON_DEPS,
)

cc_library(
name = "game_lib_headless_macos",
srcs = IOQ3_COMMON_SRCS + [
CODE_DIR + "/deepmind/dmlab_connect.c",
CODE_DIR + "/null/null_input.c",
CODE_DIR + "/null/null_snddma.c",

## OpenGL rendering
CODE_DIR + "/deepmind/headless_macos_glimp.c",
CODE_DIR + "/deepmind/glimp_common.h",
CODE_DIR + "/deepmind/glimp_common.c",
],
hdrs = ["public/dmlab.h"],
copts = IOQ3_COMMON_COPTS,
defines = IOQ3_COMMON_DEFINES,
linkopts = ["-framework OpenGL"],
deps = IOQ3_COMMON_DEPS,
)

cc_library(
name = "game_lib_headless_osmesa",
srcs = IOQ3_COMMON_SRCS + [
Expand Down Expand Up @@ -840,10 +859,7 @@ cc_library(
hdrs = ["public/dmlab.h"],
copts = IOQ3_COMMON_COPTS,
defines = IOQ3_COMMON_DEFINES,
linkopts = [
"-lGL",
"-lX11",
],
linkopts = ["-framework OpenGL"],
deps = IOQ3_COMMON_DEPS,
)

Expand All @@ -862,10 +878,7 @@ cc_library(
hdrs = ["public/dmlab.h"],
copts = IOQ3_COMMON_COPTS,
defines = IOQ3_COMMON_DEFINES,
linkopts = [
"-lEGL",
"-lGL",
],
linkopts = ["-framework OpenGL"],
deps = IOQ3_COMMON_DEPS + ["//third_party/GL/util:egl_util"],
)

Expand Down Expand Up @@ -894,27 +907,18 @@ config_setting(

cc_binary(
name = "libdmlab_headless_hw.so",
linkopts = ["-Wl,--version-script,$(location :dmlab.lds)"],
linkshared = 1,
linkstatic = 1,
visibility = ["//testing:__subpackages__"],
deps = [":dmlab.lds"] + select({
"dmlab_graphics_osmesa_or_egl": [":game_lib_headless_egl"],
"dmlab_graphics_osmesa_or_glx": [":game_lib_headless_glx"],
"//conditions:default": [":game_lib_headless_egl"],
}),
deps = [":game_lib_headless_macos"],
)

cc_binary(
name = "libdmlab_headless_sw.so",
linkopts = ["-Wl,--version-script,$(location :dmlab.lds)"],
linkshared = 1,
linkstatic = 1,
visibility = ["//testing:__subpackages__"],
deps = [
":dmlab.lds",
":game_lib_headless_osmesa",
],
deps = [":game_lib_headless_osmesa"],
)

cc_library(
Expand Down
58 changes: 58 additions & 0 deletions engine/code/deepmind/headless_macos_glimp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>

#include <OpenGL/OpenGL.h>
#include <OpenGL/gl3.h>

#include "glimp_common.h"

static CGLContextObj context;

void GLimp_MakeCurrent(void) {
}

void GLimp_Init(void) {
CGLPixelFormatObj pix;
GLint npix;
int attribs[] = {
kCGLPFAAccelerated, // no software rendering
kCGLPFAOpenGLProfile,
kCGLOGLPVersion_Legacy,
0
};

GLimp_CommonPreInit();

// NOTE: in headless mode there is no GUI, hence output to console instead of message boxes

if (CGLChoosePixelFormat((CGLPixelFormatAttribute*)attribs, &pix, &npix) != kCGLNoError) {
// Sys_Error("GLimp_Init - choose pixel format error!\n");
printf("GLimp_Init - choose pixel format error!\n");
exit(1);
}
if (CGLCreateContext(pix, NULL, &context) != kCGLNoError) {
// Sys_Error("GLimp_Init - create context error!\n");
printf("GLimp_Init - create context error!\n");
exit(1);
}
if (CGLSetCurrentContext(context) != kCGLNoError) {
// Sys_Error("GLimp_Init - set current context error!");
printf("GLimp_Init - set current context error!\n");
exit(1);
}
CGLDestroyPixelFormat(pix);

printf("Renderer: %s\nVersion: %s\n", glGetString(GL_RENDERER), glGetString(GL_VERSION));

GLimp_CommonPostInit();
}

void* GLimp_GetProcAddress(const char* func) {
return dlsym(RTLD_SELF, func);
}

void GLimp_Shutdown(void) {
CGLSetCurrentContext(NULL);
CGLDestroyContext(context);
}

0 comments on commit 15be743

Please sign in to comment.