Skip to content

Commit 1d0ab7f

Browse files
committed
Headless renderer. Attempting something like in #76.
1 parent d362e72 commit 1d0ab7f

File tree

2 files changed

+82
-5
lines changed

2 files changed

+82
-5
lines changed

BUILD

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,26 @@ cc_library(
827827
alwayslink = 1,
828828
)
829829

830+
cc_library(
831+
name = "game_lib_headless_macos",
832+
srcs = IOQ3_COMMON_SRCS + [
833+
CODE_DIR + "/deepmind/dmlab_connect.c",
834+
CODE_DIR + "/null/null_input.c",
835+
CODE_DIR + "/null/null_snddma.c",
836+
837+
## OpenGL rendering
838+
CODE_DIR + "/deepmind/headless_macos_glimp.c",
839+
CODE_DIR + "/deepmind/glimp_common.h",
840+
CODE_DIR + "/deepmind/glimp_common.c",
841+
],
842+
hdrs = ["public/dmlab.h"],
843+
copts = IOQ3_COMMON_COPTS,
844+
defines = IOQ3_COMMON_DEFINES,
845+
linkopts = ["-framework OpenGL"],
846+
deps = IOQ3_COMMON_DEPS,
847+
alwayslink = 1,
848+
)
849+
830850
cc_library(
831851
name = "game_lib_headless_osmesa",
832852
srcs = IOQ3_COMMON_SRCS + [
@@ -956,11 +976,10 @@ cc_binary(
956976
linkshared = 1,
957977
linkstatic = 1,
958978
visibility = ["//testing:__subpackages__"],
959-
deps = [":dmlab.lds"] + select({
960-
"dmlab_graphics_osmesa_or_egl": [":game_lib_headless_egl"],
961-
"dmlab_graphics_osmesa_or_glx": [":game_lib_headless_glx"],
962-
"//conditions:default": [":game_lib_headless_egl"],
963-
}),
979+
deps = [
980+
":dmlab.lds",
981+
":game_lib_headless_macos",
982+
],
964983
)
965984

966985
cc_binary(
Lines changed: 58 additions & 0 deletions
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)