diff --git a/BUILD b/BUILD index 34fa5d0fa..4b524343e 100644 --- a/BUILD +++ b/BUILD @@ -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 + [ @@ -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, ) @@ -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"], ) @@ -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( diff --git a/engine/code/deepmind/headless_macos_glimp.c b/engine/code/deepmind/headless_macos_glimp.c new file mode 100644 index 000000000..659b704eb --- /dev/null +++ b/engine/code/deepmind/headless_macos_glimp.c @@ -0,0 +1,58 @@ +#include +#include +#include + +#include +#include + +#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); +}