diff --git a/src/glew.c b/src/glew.c index 8351f80..4eaf060 100644 --- a/src/glew.c +++ b/src/glew.c @@ -32,7 +32,10 @@ #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 @@ -170,7 +173,9 @@ void* NSGLGetProcAddress (const GLubyte *name) * Define glewGetProcAddress. */ #if defined(GLEW_REGAL) -# define glewGetProcAddress(name) regalGetProcAddress((const GLchar *) name) +# define glewGetProcAddress(name) regalGetProcAddress((const GLchar *)name) +#elif defined(GLEW_OSMESA) +# define glewGetProcAddress(name) OSMesaGetProcAddress((const char *)name) #elif defined(_WIN32) # define glewGetProcAddress(name) wglGetProcAddress((LPCSTR)name) #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX) @@ -11150,7 +11155,7 @@ GLenum GLEWAPIENTRY glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) } -#if defined(_WIN32) +#if defined(_WIN32) && ! defined(GLEW_OSMESA) #if !defined(GLEW_MX) @@ -12093,7 +12098,7 @@ GLenum GLEWAPIENTRY wglewInit (WGLEW_CONTEXT_ARG_DEF_LIST) return GLEW_OK; } -#elif !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX)) +#elif !defined(GLEW_OSMESA) && !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX)) PFNGLXGETCURRENTDISPLAYPROC __glewXGetCurrentDisplay = NULL; @@ -13204,9 +13209,11 @@ GLenum GLEWAPIENTRY glewInit (void) GLenum r; r = glewContextInit(); if ( r != 0 ) return r; -#if defined(_WIN32) +#if defined(GLEW_OSMESA) || defined(__ANDROID__) || defined(__native_client__) || defined(__HAIKU__) + return r; +#elif defined(_WIN32) return wglewInit(); -#elif !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX)) /* _UNIX */ +#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) /* _UNIX */ return glxewInit(); #else return r; @@ -17322,7 +17329,7 @@ GLboolean GLEWAPIENTRY glewIsSupported (const char* name) return ret; } -#if defined(_WIN32) +#if defined(_WIN32) && !defined(GLEW_OSMESA) #if defined(GLEW_MX) GLboolean GLEWAPIENTRY wglewContextIsSupported (const WGLEWContext* ctx, const char* name) @@ -17748,7 +17755,7 @@ GLboolean GLEWAPIENTRY wglewIsSupported (const char* name) return ret; } -#elif !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) +#elif !defined(GLEW_OSMESA) && !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) #if defined(GLEW_MX) GLboolean glxewContextIsSupported (const GLXEWContext* ctx, const char* name) diff --git a/src/glewinfo.c b/src/glewinfo.c index cddc63b..649f6c1 100644 --- a/src/glewinfo.c +++ b/src/glewinfo.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(__HAIKU__) || defined(GLEW_APPLE_GLX) #include @@ -53,10 +56,10 @@ static FILE* f; #ifdef GLEW_MX GLEWContext _glewctx; #define glewGetContext() (&_glewctx) -#ifdef _WIN32 +#if defined(_WIN32) WGLEWContext _wglewctx; #define wglewGetContext() (&_wglewctx) -#elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX) +#elif !defined(GLEW_OSMESA) && !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX) GLXEWContext _glxewctx; #define glxewGetContext() (&_glxewctx) #endif @@ -66,7 +69,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; @@ -10984,7 +10988,7 @@ static void glewInfo (void) /* ------------------------------------------------------------------------ */ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(GLEW_OSMESA) static void wglewInfo () { @@ -11152,7 +11156,7 @@ static void wglewInfo () #endif /* WGL_OML_sync_control */ } -#else /* _UNIX */ +#elif !defined(GLEW_OSMESA) /* _UNIX */ static void glxewInfo () { @@ -11371,7 +11375,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 */ @@ -11386,7 +11391,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 ] " @@ -11408,7 +11414,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()); @@ -11438,7 +11445,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", @@ -11448,7 +11456,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(); @@ -11486,7 +11495,8 @@ GLboolean glewParseArgs (int argc, char** argv, struct createParams *params) else return GL_TRUE; ++p; } -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +#elif defined(_WIN32) else if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat")) { if (++p >= argc) return GL_TRUE; @@ -11512,7 +11522,22 @@ GLboolean glewParseArgs (int argc, char** argv, struct createParams *params) /* ------------------------------------------------------------------------ */ -#if defined(_WIN32) +#if defined(GLEW_OSMESA) +OSMesaContext ctx; + +GLboolean glewCreateContext (struct createParams *params) +{ + 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;