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 Oct 18, 2018
1 parent d92feb6 commit 9171163
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 14 deletions.
35 changes: 21 additions & 14 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,26 @@ cc_library(
hdrs = ["public/dmlab.h"],
copts = IOQ3_COMMON_COPTS,
defines = IOQ3_COMMON_DEFINES,
linkopts = [
"-lGL",
"-lrt",
linkopts = ["-framework OpenGL"],
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,
)

Expand Down Expand Up @@ -897,27 +913,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
57 changes: 57 additions & 0 deletions engine/code/deepmind/headless_macos_glimp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#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 NULL;
}

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

0 comments on commit 9171163

Please sign in to comment.