From d2af6d39188246bbe0481019e39748aef8c0551a Mon Sep 17 00:00:00 2001 From: Julian Squires Date: Tue, 24 Jun 2014 11:03:28 -0400 Subject: [PATCH] Hack in crude OSMesa support Mostly this is quick, "do nothing" ifdefs when built with SYSTEM=linux-osmesa, to support the off-screen rendering mode of Mesa in headless tests. Support in glewinfo and visualinfo is enough to get them compile, but insufficient for them to run successfully. --- auto/Makefile | 3 ++- auto/src/glew_head.c | 9 +++++++-- auto/src/glew_init_tail.c | 2 ++ auto/src/glew_str_wgl.c | 3 ++- auto/src/glewinfo_head.c | 11 ++++++++--- auto/src/glewinfo_tail.c | 32 ++++++++++++++++++++++++++------ auto/src/glewinfo_wgl.c | 3 ++- config/Makefile.linux-osmesa | 36 ++++++++++++++++++++++++++++++++++++ src/visualinfo.c | 33 +++++++++++++++++++++++++++++---- 9 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 config/Makefile.linux-osmesa diff --git a/auto/Makefile b/auto/Makefile index 91b68ed..af66a8e 100644 --- a/auto/Makefile +++ b/auto/Makefile @@ -204,7 +204,8 @@ $(S.DEST)/glew.c: $(EXT)/.dummy $(BIN)/make_list.pl $(GL_CORE_SPEC) | grep -v '\"GL_VERSION' >> $@ $(BIN)/make_list.pl $(GL_EXT_SPEC) >> $@ echo -e "\n return GLEW_OK;\n}\n" >> $@ - echo -e "\n#if defined(_WIN32)" >> $@ + echo -e "\n#if defined(GLEW_OSMESA)" >> $@ + echo -e "\n#elif defined(_WIN32)" >> $@ echo -e "\n#if !defined(GLEW_MX)" >> $@ $(BIN)/make_def_fun.pl WGL $(WGL_EXT_SPEC) >> $@ $(BIN)/make_def_var.pl WGL $(WGL_EXT_SPEC) >> $@ diff --git a/auto/src/glew_head.c b/auto/src/glew_head.c index e945bcd..fd9c0d3 100644 --- a/auto/src/glew_head.c +++ b/auto/src/glew_head.c @@ -1,6 +1,9 @@ #include -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +# define GLAPI extern +# include +#elif defined(_WIN32) # include #elif !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX)) # include @@ -137,7 +140,9 @@ void* NSGLGetProcAddress (const GLubyte *name) /* * Define glewGetProcAddress. */ -#if defined(GLEW_REGAL) +#if defined(GLEW_OSMESA) +# define glewGetProcAddress(name) OSMesaGetProcAddress((const char *)name) +#elif defined(GLEW_REGAL) # define glewGetProcAddress(name) regalGetProcAddress((const GLchar *) name) #elif defined(_WIN32) # define glewGetProcAddress(name) wglGetProcAddress((LPCSTR)name) diff --git a/auto/src/glew_init_tail.c b/auto/src/glew_init_tail.c index cc3a34f..0ef2ad8 100644 --- a/auto/src/glew_init_tail.c +++ b/auto/src/glew_init_tail.c @@ -39,6 +39,8 @@ GLenum GLEWAPIENTRY glewInit (void) GLenum r; r = glewContextInit(); if ( r != 0 ) return r; +#if defined(GLEW_OSMESA) + return r; #if defined(_WIN32) return wglewInit(); #elif !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX)) /* _UNIX */ diff --git a/auto/src/glew_str_wgl.c b/auto/src/glew_str_wgl.c index 5463ef7..4fd37fd 100644 --- a/auto/src/glew_str_wgl.c +++ b/auto/src/glew_str_wgl.c @@ -4,7 +4,8 @@ return ret; } -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) #if defined(GLEW_MX) GLboolean GLEWAPIENTRY wglewContextIsSupported (const WGLEWContext* ctx, const char* name) diff --git a/auto/src/glewinfo_head.c b/auto/src/glewinfo_head.c index 37ff44d..96108e8 100644 --- a/auto/src/glewinfo_head.c +++ b/auto/src/glewinfo_head.c @@ -2,7 +2,10 @@ #include #include #include -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +#define GLAPI extern +#include +#elif defined(_WIN32) #include #elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX) #include @@ -21,7 +24,8 @@ static FILE* f; #ifdef GLEW_MX GLEWContext _glewctx; #define glewGetContext() (&_glewctx) -#ifdef _WIN32 +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) WGLEWContext _wglewctx; #define wglewGetContext() (&_wglewctx) #elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX) @@ -34,7 +38,8 @@ GLXEWContext _glxewctx; struct createParams { -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) int pixelformat; #elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX) const char* display; diff --git a/auto/src/glewinfo_tail.c b/auto/src/glewinfo_tail.c index a5e9232..56814e8 100644 --- a/auto/src/glewinfo_tail.c +++ b/auto/src/glewinfo_tail.c @@ -9,7 +9,8 @@ int main (int argc, char** argv) GLuint err; struct createParams params = { -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) -1, /* pixelformat */ #elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) "", /* display */ @@ -24,7 +25,8 @@ int main (int argc, char** argv) if (glewParseArgs(argc-1, argv+1, ¶ms)) { fprintf(stderr, "Usage: glewinfo " -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) "[-pf ] " #elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) "[-display ] " @@ -46,7 +48,8 @@ int main (int argc, char** argv) glewExperimental = GL_TRUE; #ifdef GLEW_MX err = glewContextInit(glewGetContext()); -#ifdef _WIN32 +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) err = err || wglewContextInit(wglewGetContext()); #elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) err = err || glxewContextInit(glxewGetContext()); @@ -76,7 +79,8 @@ int main (int argc, char** argv) fprintf(f, " GLEW Extension Info\n"); fprintf(f, "---------------------------\n\n"); fprintf(f, "GLEW version %s\n", glewGetString(GLEW_VERSION)); -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) fprintf(f, "Reporting capabilities of pixelformat %d\n", params.pixelformat); #elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) fprintf(f, "Reporting capabilities of display %s, visual 0x%x\n", @@ -86,7 +90,8 @@ int main (int argc, char** argv) glGetString(GL_RENDERER), glGetString(GL_VENDOR)); fprintf(f, "OpenGL version %s is supported\n", glGetString(GL_VERSION)); glewInfo(); -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) wglewInfo(); #else glxewInfo(); @@ -150,7 +155,22 @@ GLboolean glewParseArgs (int argc, char** argv, struct createParams *params) /* ------------------------------------------------------------------------ */ -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +OSMesaContext ctx; + +GLboolean glewCreateContext () +{ + ctx = OSMesaCreateContext(OSMESA_RGBA, NULL); + if (NULL == ctx) return GL_TRUE; + return GL_FALSE; +} + +void glewDestroyContext () +{ + if (NULL != ctx) OSMesaDestroyContext(ctx); +} + +#elif defined(_WIN32) HWND wnd = NULL; HDC dc = NULL; diff --git a/auto/src/glewinfo_wgl.c b/auto/src/glewinfo_wgl.c index 61f101a..b2c2242 100644 --- a/auto/src/glewinfo_wgl.c +++ b/auto/src/glewinfo_wgl.c @@ -2,7 +2,8 @@ /* ------------------------------------------------------------------------ */ -#ifdef _WIN32 +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) static void wglewInfo () { diff --git a/config/Makefile.linux-osmesa b/config/Makefile.linux-osmesa new file mode 100644 index 0000000..c8d1e95 --- /dev/null +++ b/config/Makefile.linux-osmesa @@ -0,0 +1,36 @@ +NAME = $(GLEW_NAME) +CC = cc +LD = cc +M_ARCH ?= $(shell uname -m) +ARCH64 = false +ifeq (x86_64,${M_ARCH}) + ARCH64 = true +endif +ifeq (ppc64,${M_ARCH}) + ARCH64 = true +endif +ifeq (${ARCH64},true) + LDFLAGS.EXTRA = -L/usr/lib64 + LIBDIR = $(GLEW_DEST)/lib64 +else + LDFLAGS.EXTRA = -L/usr/lib + LIBDIR = $(GLEW_DEST)/lib +endif +LDFLAGS.GL = -lOSMesa +LDFLAGS.STATIC = -Wl,-Bstatic +LDFLAGS.DYNAMIC = -Wl,-Bdynamic +NAME = GLEW +WARN = -Wall -W +POPT = -O2 +CFLAGS.EXTRA += -fPIC -DGLEW_OSMESA +BIN.SUFFIX = +LIB.SONAME = lib$(NAME).so.$(SO_MAJOR) +LIB.DEVLNK = lib$(NAME).so +LIB.SHARED = lib$(NAME).so.$(SO_VERSION) +LIB.STATIC = lib$(NAME).a +LDFLAGS.SO = -shared -Wl,-soname=$(LIB.SONAME) +LIB.SONAME.MX = lib$(NAME)mx.so.$(SO_MAJOR) +LIB.DEVLNK.MX = lib$(NAME)mx.so +LIB.SHARED.MX = lib$(NAME)mx.so.$(SO_VERSION) +LIB.STATIC.MX = lib$(NAME)mx.a +LDFLAGS.SO.MX = -shared -Wl,-soname=$(LIB.SONAME.MX) diff --git a/src/visualinfo.c b/src/visualinfo.c index fd27c7b..eb89fd9 100644 --- a/src/visualinfo.c +++ b/src/visualinfo.c @@ -34,7 +34,10 @@ #include #include #include -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +#define GLAPI extern +#include +#elif defined(_WIN32) #include #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX) #include @@ -57,7 +60,9 @@ GLXEWContext _glxewctx; typedef struct GLContextStruct { -#ifdef _WIN32 +#if defined(GLEW_OSMESA) + OSMesaContext ctx; +#elif defined(_WIN32) HWND wnd; HDC dc; HGLRC rc; @@ -180,7 +185,8 @@ main (int argc, char** argv) /* ---------------------------------------------------------------------- */ /* extensions string */ -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) /* WGL extensions */ if (WGLEW_ARB_extensions_string || WGLEW_EXT_extensions_string) { @@ -1003,7 +1009,26 @@ VisualInfo (GLContext* ctx) /* ------------------------------------------------------------------------ */ -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +void InitContext (GLContext* ctx) +{ + ctx->ctx = NULL; +} + +GLboolean CreateContext (GLContext* ctx) +{ + if (NULL == ctx) return GL_TRUE; + ctx->ctx = OSMesaCreateContext(OSMESA_RGBA, NULL); + if (NULL == ctx->ctx) return GL_TRUE; + return GL_FALSE; +} + +void DestroyContext (GLContext* ctx) +{ + if (NULL == ctx) return; + if (NULL != ctx->ctx) OSMesaDestroyContext(ctx->ctx); +} +#elif defined(_WIN32) void InitContext (GLContext* ctx) {