Commit f4abb657 authored by Nigel Stewart's avatar Nigel Stewart
Browse files

GLEW_EGL mode for loading functions via eglGetProcAddress

parent 4ee89ccb
......@@ -200,14 +200,14 @@ $(S.DEST)/glew.c: $(EXT)/.dummy
$(BIN)/make_list.pl $(GL_EXT_SPEC) >> $@
$(BIN)/make_list2.pl $(GL_EXT_SPEC) >> $@
echo -e "\n return GLEW_OK;\n}\n" >> $@
echo -e "\n#if defined(_WIN32) && ! defined(GLEW_OSMESA)" >> $@
echo -e "\n#if defined(_WIN32) && !defined(GLEW_EGL) && !defined(GLEW_OSMESA)" >> $@
$(BIN)/make_def_fun.pl WGL $(WGL_EXT_SPEC) >> $@
$(BIN)/make_def_var.pl WGL $(WGL_EXT_SPEC) >> $@
$(BIN)/make_init.pl WGL $(WGL_EXT_SPEC) >> $@
cat $(SRC)/glew_init_wgl.c >> $@
$(BIN)/make_list.pl $(WGL_EXT_SPEC) >> $@
echo -e "\n return GLEW_OK;\n}" >> $@;
echo -e "\n#elif !defined(GLEW_OSMESA) && !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))" >> $@
echo -e "\n#elif !defined(GLEW_EGL) && !defined(GLEW_OSMESA) && !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX))" >> $@
$(BIN)/make_def_fun.pl GLX $(GLX_CORE_SPEC) >> $@
$(BIN)/make_def_fun.pl GLX $(GLX_EXT_SPEC) >> $@
echo -e "\nGLboolean __GLXEW_VERSION_1_0 = GL_FALSE;" >> $@
......@@ -245,12 +245,14 @@ $(S.DEST)/glewinfo.c: $(EXT)/.dummy
cat $(SRC)/glewinfo_head.c >> $@
$(BIN)/make_info.pl $(GL_CORE_SPEC) >> $@
$(BIN)/make_info.pl $(GL_EXT_SPEC) >> $@
echo -e "#if !defined(GLEW_EGL)\n" >> $@
echo -e "#ifdef _WIN32\n" >> $@
$(BIN)/make_info.pl $(WGL_EXT_SPEC) >> $@
echo -e "#else /* _UNIX */\n" >> $@
$(BIN)/make_info.pl $(GLX_CORE_SPEC) >> $@
$(BIN)/make_info.pl $(GLX_EXT_SPEC) >> $@
echo -e "#endif /* _WIN32 */\n" >> $@
echo -e "#endif /* !defined(GLEW_EGL) */\n" >> $@
cat $(SRC)/glewinfo_gl.c >> $@
$(BIN)/make_info_list.pl $(GL_CORE_SPEC) >> $@
......
#include <GL/glew.h>
#if defined(GLEW_OSMESA)
#if defined(GLEW_EGL)
#elif defined(GLEW_OSMESA)
# define GLAPI extern
# include <GL/osmesa.h>
#elif defined(_WIN32)
......@@ -13,7 +14,9 @@
#include <stdlib.h> /* For bsearch */
#include <string.h> /* For memset */
#if defined(GLEW_REGAL)
#if defined(GLEW_EGL)
extern void * eglGetProcAddress (const char *procname);
#elif defined(GLEW_REGAL)
/* In GLEW_REGAL mode we call direcly into the linked
libRegal.so glGetProcAddressREGAL for looking up
......@@ -113,7 +116,9 @@ void* NSGLGetProcAddress (const GLubyte *name)
/*
* Define glewGetProcAddress.
*/
#if defined(GLEW_REGAL)
#if defined(GLEW_EGL)
# define glewGetProcAddress(name) eglGetProcAddress((const char *)name)
#elif defined(GLEW_REGAL)
# define glewGetProcAddress(name) regalGetProcAddress((const GLchar *)name)
#elif defined(GLEW_OSMESA)
# define glewGetProcAddress(name) OSMesaGetProcAddress((const char *)name)
......
......@@ -37,7 +37,7 @@ GLenum GLEWAPIENTRY glewInit (void)
GLenum r;
r = glewContextInit();
if ( r != 0 ) return r;
#if defined(GLEW_OSMESA) || defined(__ANDROID__) || defined(__native_client__) || defined(__HAIKU__)
#if defined(GLEW_EGL) || defined(GLEW_OSMESA) || defined(__ANDROID__) || defined(__native_client__) || defined(__HAIKU__)
return r;
#elif defined(_WIN32)
return wglewInit();
......
......@@ -4,7 +4,7 @@
return ret;
}
#elif !defined(GLEW_OSMESA) && !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
#elif !defined(GLEW_EGL) && !defined(GLEW_OSMESA) && !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
GLboolean glxewIsSupported (const char* name)
{
......
......@@ -4,7 +4,7 @@
return ret;
}
#if defined(_WIN32) && !defined(GLEW_OSMESA)
#if defined(_WIN32) && !defined(GLEW_EGL) && !defined(GLEW_OSMESA)
GLboolean GLEWAPIENTRY wglewIsSupported (const char* name)
{
......
}
#elif !defined(GLEW_OSMESA) /* _UNIX */
#elif !defined(GLEW_EGL) && !defined(GLEW_OSMESA) /* _UNIX */
static void glxewInfo ()
{
......@@ -2,7 +2,9 @@
#include <stdlib.h>
#include <string.h>
#include <GL/glew.h>
#if defined(GLEW_OSMESA)
#if defined(GLEW_EGL)
#include <EGL/egl.h>
#elif defined(GLEW_OSMESA)
#define GLAPI extern
#include <GL/osmesa.h>
#elif defined(_WIN32)
......@@ -25,7 +27,8 @@ static FILE* f;
struct createParams
{
#if defined(GLEW_OSMESA)
#if defined(GLEW_EGL)
#elif defined(GLEW_OSMESA)
#elif defined(_WIN32)
int pixelformat;
#elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX)
......
......@@ -7,9 +7,10 @@
int main (int argc, char** argv)
{
GLuint err;
struct createParams params =
struct createParams params =
{
#if defined(GLEW_OSMESA)
#if defined(GLEW_EGL)
#elif defined(GLEW_OSMESA)
#elif defined(_WIN32)
-1, /* pixelformat */
#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
......@@ -25,17 +26,18 @@ int main (int argc, char** argv)
if (glewParseArgs(argc-1, argv+1, &params))
{
fprintf(stderr, "Usage: glewinfo "
#if defined(GLEW_OSMESA)
#if defined(GLEW_EGL)
#elif defined(GLEW_OSMESA)
#elif defined(_WIN32)
"[-pf <pixelformat>] "
"[-pf <pixelformat>] "
#elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX)
"[-display <display>] "
"[-visual <visual id>] "
"[-display <display>] "
"[-visual <visual id>] "
#endif
"[-version <OpenGL version>] "
"[-profile core|compatibility] "
"[-flag debug|forward]"
"\n");
"[-version <OpenGL version>] "
"[-profile core|compatibility] "
"[-flag debug|forward]"
"\n");
return 1;
}
......@@ -68,18 +70,20 @@ 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(GLEW_OSMESA)
#if defined(GLEW_EGL)
#elif 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",
fprintf(f, "Reporting capabilities of display %s, visual 0x%x\n",
params.display == NULL ? getenv("DISPLAY") : params.display, params.visual);
#endif
fprintf(f, "Running on a %s from %s\n",
glGetString(GL_RENDERER), glGetString(GL_VENDOR));
fprintf(f, "Running on a %s from %s\n",
glGetString(GL_RENDERER), glGetString(GL_VENDOR));
fprintf(f, "OpenGL version %s is supported\n", glGetString(GL_VERSION));
glewInfo();
#if defined(GLEW_OSMESA)
#if defined(GLEW_EGL)
#elif defined(GLEW_OSMESA)
#elif defined(_WIN32)
wglewInfo();
#else
......@@ -118,7 +122,8 @@ GLboolean glewParseArgs (int argc, char** argv, struct createParams *params)
else return GL_TRUE;
++p;
}
#if defined(GLEW_OSMESA)
#if defined(GLEW_EGL)
#elif defined(GLEW_OSMESA)
#elif defined(_WIN32)
else if (!strcmp(argv[p], "-pf") || !strcmp(argv[p], "-pixelformat"))
{
......@@ -145,7 +150,44 @@ GLboolean glewParseArgs (int argc, char** argv, struct createParams *params)
/* ------------------------------------------------------------------------ */
#if defined(GLEW_OSMESA)
#if defined(GLEW_EGL)
EGLDisplay display;
EGLContext ctx;
/* See: http://stackoverflow.com/questions/12662227/opengl-es2-0-offscreen-context-for-fbo-rendering */
GLboolean glewCreateContext (struct createParams *params)
{
EGLSurface surface;
EGLint majorVersion, minorVersion;
const EGLint attr[] = {
EGL_BUFFER_SIZE, 32,
EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER,
EGL_CONFORMANT, EGL_OPENGL_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
EGL_NONE
};
EGLConfig config;
EGLint numConfig;
display = eglGetDisplay((EGLNativeDisplayType) 0);
if (!eglInitialize(display, &majorVersion, &minorVersion))
return GL_TRUE;
eglBindAPI(EGL_OPENGL_API);
if (!eglChooseConfig(display, attr, &config, 1, &numConfig) || (numConfig != 1))
return GL_TRUE;
surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType) NULL, NULL);
ctx = eglCreateContext(display, config, NULL, NULL);
if (NULL == ctx) return GL_TRUE;
eglMakeCurrent(display, surface, surface, ctx);
return GL_FALSE;
}
void glewDestroyContext ()
{
if (NULL != ctx) eglDestroyContext(display, ctx);
}
#elif defined(GLEW_OSMESA)
OSMesaContext ctx;
static const GLint osmFormat = GL_UNSIGNED_BYTE;
......@@ -190,7 +232,7 @@ GLboolean glewCreateContext (struct createParams* params)
wc.lpszClassName = "GLEW";
if (0 == RegisterClass(&wc)) return GL_TRUE;
/* create window */
wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
wnd = CreateWindow("GLEW", "GLEW", 0, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, NULL, NULL, GetModuleHandle(NULL), NULL);
if (NULL == wnd) return GL_TRUE;
/* get the device context */
......@@ -378,8 +420,8 @@ GLboolean glewCreateContext (struct createParams *params)
cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual, AllocNone);
swa.border_pixel = 0;
swa.colormap = cmap;
wnd = XCreateWindow(dpy, RootWindow(dpy, vi->screen),
0, 0, 1, 1, 0, vi->depth, InputOutput, vi->visual,
wnd = XCreateWindow(dpy, RootWindow(dpy, vi->screen),
0, 0, 1, 1, 0, vi->depth, InputOutput, vi->visual,
CWBorderPixel | CWColormap, &swa);
/* make context current */
if (!glXMakeCurrent(dpy, wnd, ctx)) return GL_TRUE;
......
......@@ -2,7 +2,7 @@
/* ------------------------------------------------------------------------ */
#if defined(_WIN32) && !defined(GLEW_OSMESA)
#if defined(_WIN32) && !defined(GLEW_EGL) && !defined(GLEW_OSMESA)
static void wglewInfo ()
{
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment