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 Jan 14, 2021
1 parent d362e72 commit 1d0ab7f
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 5 deletions.
29 changes: 24 additions & 5 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,26 @@ cc_library(
alwayslink = 1,
)

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,
alwayslink = 1,
)

cc_library(
name = "game_lib_headless_osmesa",
srcs = IOQ3_COMMON_SRCS + [
Expand Down Expand Up @@ -956,11 +976,10 @@ cc_binary(
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 = [
":dmlab.lds",
":game_lib_headless_macos",
],
)

cc_binary(
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 1d0ab7f

Please sign in to comment.