mirror of
https://github.com/Perlmint/glew-cmake.git
synced 2024-11-26 08:31:56 +00:00
eglewInit takes EGLDisplay parameter, will do eglIntialize internally, for now
This commit is contained in:
parent
15881f0421
commit
4d9010864e
@ -27,6 +27,12 @@
|
||||
#include <KHR/khrplatform.h>
|
||||
#include <EGL/eglplatform.h>
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int32_t EGLint;
|
||||
|
||||
typedef unsigned int EGLBoolean;
|
||||
@ -79,8 +85,3 @@ struct EGLClientPixmapHI;
|
||||
#define EGL_DEFAULT_DISPLAY ((EGLNativeDisplayType)0)
|
||||
|
||||
EGLAPI __eglMustCastToProperFunctionPointerType EGLAPIENTRY eglGetProcAddress (const char *procname);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
GLEWAPI GLenum GLEWAPIENTRY eglewInit ();
|
||||
GLEWAPI GLenum GLEWAPIENTRY eglewInit (EGLDisplay display);
|
||||
GLEWAPI GLboolean GLEWAPIENTRY eglewIsSupported (const char *name);
|
||||
|
||||
#define EGLEW_GET_VAR(x) (*(const GLboolean*)&x)
|
||||
|
@ -1,7 +1,7 @@
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
GLboolean eglewGetExtension (const char* name)
|
||||
{
|
||||
{
|
||||
const GLubyte* start;
|
||||
const GLubyte* end;
|
||||
|
||||
@ -11,34 +11,25 @@ GLboolean eglewGetExtension (const char* name)
|
||||
return _glewSearchExtension(name, start, end);
|
||||
}
|
||||
|
||||
GLenum eglewInit ()
|
||||
GLenum eglewInit (EGLDisplay display)
|
||||
{
|
||||
GLuint dot;
|
||||
GLint major, minor;
|
||||
const GLubyte* version;
|
||||
EGLint major, minor;
|
||||
const GLubyte* extStart;
|
||||
const GLubyte* extEnd;
|
||||
PFNEGLGETDISPLAYPROC getDisplay = NULL;
|
||||
PFNEGLINITIALIZEPROC initialize = NULL;
|
||||
PFNEGLQUERYSTRINGPROC queryString = NULL;
|
||||
|
||||
/* Load necessary entry points */
|
||||
getDisplay = (PFNEGLGETDISPLAYPROC) glewGetProcAddress("eglGetDisplay");
|
||||
initialize = (PFNEGLINITIALIZEPROC) glewGetProcAddress("eglInitialize");
|
||||
queryString = (PFNEGLQUERYSTRINGPROC) glewGetProcAddress("eglQueryString");
|
||||
if (!getDisplay || !queryString)
|
||||
if (!initialize || !queryString)
|
||||
return 1;
|
||||
|
||||
/* query EGK version */
|
||||
major = 0;
|
||||
minor = 0;
|
||||
version = (const GLubyte*) queryString(getDisplay(EGL_DEFAULT_DISPLAY), EGL_VERSION);
|
||||
dot = _glewStrCLen(version, '.');
|
||||
if (dot != 0)
|
||||
{
|
||||
major = version[dot-1]-'0';
|
||||
minor = version[dot+1]-'0';
|
||||
}
|
||||
if (initialize(display, &major, &minor) != EGL_TRUE)
|
||||
return 1;
|
||||
|
||||
EGLEW_VERSION_1_5 = ( major > 1 ) || ( major == 1 && minor >= 5 ) ? GL_TRUE : GL_FALSE;
|
||||
EGLEW_VERSION_1_5 = ( major > 1 ) || ( major == 1 && minor >= 5 ) ? GL_TRUE : GL_FALSE;
|
||||
EGLEW_VERSION_1_4 = EGLEW_VERSION_1_5 == GL_TRUE || ( major == 1 && minor >= 4 ) ? GL_TRUE : GL_FALSE;
|
||||
EGLEW_VERSION_1_3 = EGLEW_VERSION_1_4 == GL_TRUE || ( major == 1 && minor >= 3 ) ? GL_TRUE : GL_FALSE;
|
||||
EGLEW_VERSION_1_2 = EGLEW_VERSION_1_3 == GL_TRUE || ( major == 1 && minor >= 2 ) ? GL_TRUE : GL_FALSE;
|
||||
@ -46,7 +37,7 @@ GLenum eglewInit ()
|
||||
EGLEW_VERSION_1_0 = EGLEW_VERSION_1_1 == GL_TRUE || ( major == 1 && minor >= 0 ) ? GL_TRUE : GL_FALSE;
|
||||
|
||||
/* query EGL extension string */
|
||||
extStart = (const GLubyte*) queryString(getDisplay(EGL_DEFAULT_DISPLAY), EGL_EXTENSIONS);
|
||||
extStart = (const GLubyte*) queryString(display, EGL_EXTENSIONS);
|
||||
if (extStart == 0)
|
||||
extStart = (const GLubyte *)"";
|
||||
extEnd = extStart + _glewStrLen(extStart);
|
||||
|
@ -35,10 +35,14 @@ GLboolean glewExperimental = GL_FALSE;
|
||||
GLenum GLEWAPIENTRY glewInit (void)
|
||||
{
|
||||
GLenum r;
|
||||
#if defined(GLEW_EGL)
|
||||
PFNEGLGETCURRENTDISPLAYPROC getCurrentDisplay = NULL;
|
||||
#endif
|
||||
r = glewContextInit();
|
||||
if ( r != 0 ) return r;
|
||||
#if defined(GLEW_EGL)
|
||||
return eglewInit();
|
||||
getCurrentDisplay = (PFNEGLGETCURRENTDISPLAYPROC) glewGetProcAddress("eglGetCurrentDisplay");
|
||||
return eglewInit(getCurrentDisplay());
|
||||
#elif defined(GLEW_OSMESA) || defined(__ANDROID__) || defined(__native_client__) || defined(__HAIKU__)
|
||||
return r;
|
||||
#elif defined(_WIN32)
|
||||
|
@ -159,47 +159,110 @@ EGLContext ctx;
|
||||
|
||||
GLboolean glewCreateContext (struct createParams *params)
|
||||
{
|
||||
EGLDeviceEXT devices[1];
|
||||
EGLint numDevices;
|
||||
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
|
||||
static const EGLint configAttribs[] = {
|
||||
EGL_RED_SIZE, 1,
|
||||
EGL_GREEN_SIZE, 1,
|
||||
EGL_BLUE_SIZE, 1,
|
||||
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
static const EGLint contextAttribs[] = {
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
static const EGLint pBufferAttribs[] = {
|
||||
EGL_WIDTH, 128,
|
||||
EGL_HEIGHT, 128,
|
||||
EGL_NONE
|
||||
};
|
||||
EGLConfig config;
|
||||
EGLint numConfig;
|
||||
EGLint error;
|
||||
|
||||
PFNEGLGETDISPLAYPROC getDisplay = NULL;
|
||||
PFNEGLINITIALIZEPROC initialize = NULL;
|
||||
PFNEGLBINDAPIPROC bindAPI = NULL;
|
||||
PFNEGLCHOOSECONFIGPROC chooseConfig = NULL;
|
||||
PFNEGLCREATEWINDOWSURFACEPROC createWindowSurface = NULL;
|
||||
PFNEGLCREATECONTEXTPROC createContext = NULL;
|
||||
PFNEGLMAKECURRENTPROC makeCurrent = NULL;
|
||||
PFNEGLQUERYDEVICESEXTPROC queryDevices = NULL;
|
||||
PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay = NULL;
|
||||
PFNEGLGETERRORPROC getError = NULL;
|
||||
PFNEGLGETDISPLAYPROC getDisplay = NULL;
|
||||
PFNEGLINITIALIZEPROC initialize = NULL;
|
||||
PFNEGLBINDAPIPROC bindAPI = NULL;
|
||||
PFNEGLCHOOSECONFIGPROC chooseConfig = NULL;
|
||||
PFNEGLCREATEWINDOWSURFACEPROC createWindowSurface = NULL;
|
||||
PFNEGLCREATECONTEXTPROC createContext = NULL;
|
||||
PFNEGLMAKECURRENTPROC makeCurrent = NULL;
|
||||
PFNEGLCREATEPBUFFERSURFACEPROC createPbufferSurface = NULL;
|
||||
|
||||
/* Load necessary entry points */
|
||||
getDisplay = (PFNEGLGETDISPLAYPROC) eglGetProcAddress("eglGetDisplay");
|
||||
initialize = (PFNEGLINITIALIZEPROC) eglGetProcAddress("eglInitialize");
|
||||
bindAPI = (PFNEGLBINDAPIPROC) eglGetProcAddress("eglBindAPI");
|
||||
chooseConfig = (PFNEGLCHOOSECONFIGPROC) eglGetProcAddress("eglChooseConfig");
|
||||
createWindowSurface = (PFNEGLCREATEWINDOWSURFACEPROC) eglGetProcAddress("eglCreateWindowSurface");
|
||||
createContext = (PFNEGLCREATECONTEXTPROC) eglGetProcAddress("eglCreateContext");
|
||||
makeCurrent = (PFNEGLMAKECURRENTPROC) eglGetProcAddress("eglMakeCurrent");
|
||||
if (!getDisplay || !initialize || !bindAPI || !chooseConfig || !createWindowSurface || !createContext || !makeCurrent)
|
||||
queryDevices = (PFNEGLQUERYDEVICESEXTPROC) eglGetProcAddress("eglQueryDevicesEXT");
|
||||
getPlatformDisplay = (PFNEGLGETPLATFORMDISPLAYEXTPROC) eglGetProcAddress("eglGetPlatformDisplayEXT");
|
||||
getError = (PFNEGLGETERRORPROC) eglGetProcAddress("eglGetError");
|
||||
getDisplay = (PFNEGLGETDISPLAYPROC) eglGetProcAddress("eglGetDisplay");
|
||||
initialize = (PFNEGLINITIALIZEPROC) eglGetProcAddress("eglInitialize");
|
||||
bindAPI = (PFNEGLBINDAPIPROC) eglGetProcAddress("eglBindAPI");
|
||||
chooseConfig = (PFNEGLCHOOSECONFIGPROC) eglGetProcAddress("eglChooseConfig");
|
||||
createWindowSurface = (PFNEGLCREATEWINDOWSURFACEPROC) eglGetProcAddress("eglCreateWindowSurface");
|
||||
createPbufferSurface = (PFNEGLCREATEPBUFFERSURFACEPROC) eglGetProcAddress("eglCreatePbufferSurface");
|
||||
createContext = (PFNEGLCREATECONTEXTPROC) eglGetProcAddress("eglCreateContext");
|
||||
makeCurrent = (PFNEGLMAKECURRENTPROC) eglGetProcAddress("eglMakeCurrent");
|
||||
if (!getError || !getDisplay || !initialize || !bindAPI || !chooseConfig || !createWindowSurface || !createContext || !makeCurrent)
|
||||
return GL_TRUE;
|
||||
|
||||
display = getDisplay((EGLNativeDisplayType) 0);
|
||||
if (!initialize(display, &majorVersion, &minorVersion))
|
||||
return GL_TRUE;
|
||||
bindAPI(EGL_OPENGL_API);
|
||||
if (!chooseConfig(display, attr, &config, 1, &numConfig) || (numConfig != 1))
|
||||
return GL_TRUE;
|
||||
surface = createWindowSurface(display, config, (EGLNativeWindowType) NULL, NULL);
|
||||
ctx = createContext(display, config, NULL, NULL);
|
||||
if (NULL == ctx) return GL_TRUE;
|
||||
makeCurrent(display, surface, surface, ctx);
|
||||
display = EGL_NO_DISPLAY;
|
||||
if (queryDevices && getPlatformDisplay)
|
||||
{
|
||||
queryDevices(1, devices, &numDevices);
|
||||
if (numDevices==1)
|
||||
{
|
||||
display = getPlatformDisplay(EGL_PLATFORM_DEVICE_EXT, devices[0], 0);
|
||||
}
|
||||
}
|
||||
if (display==EGL_NO_DISPLAY)
|
||||
{
|
||||
display = getDisplay(EGL_DEFAULT_DISPLAY);
|
||||
}
|
||||
if (display == EGL_NO_DISPLAY)
|
||||
return GL_TRUE;
|
||||
|
||||
eglewInit(display);
|
||||
|
||||
if (bindAPI(EGL_OPENGL_API) != EGL_TRUE)
|
||||
return GL_TRUE;
|
||||
|
||||
if (chooseConfig(display, configAttribs, &config, 1, &numConfig) != EGL_TRUE || (numConfig != 1))
|
||||
return GL_TRUE;
|
||||
|
||||
ctx = createContext(display, config, EGL_NO_CONTEXT, contextAttribs);
|
||||
if (NULL == ctx)
|
||||
return GL_TRUE;
|
||||
|
||||
surface = EGL_NO_SURFACE;
|
||||
/* Create a p-buffer surface if possible */
|
||||
if (createPbufferSurface)
|
||||
{
|
||||
surface = createPbufferSurface(display, config, pBufferAttribs);
|
||||
}
|
||||
/* Create a generic surface without a native window, if necessary */
|
||||
if (surface==EGL_NO_SURFACE)
|
||||
{
|
||||
surface = createWindowSurface(display, config, (EGLNativeWindowType) NULL, NULL);
|
||||
}
|
||||
if (surface == EGL_NO_SURFACE)
|
||||
return GL_TRUE;
|
||||
|
||||
if (makeCurrent(display, surface, surface, ctx) != EGL_TRUE)
|
||||
return GL_TRUE;
|
||||
|
||||
error = getError();
|
||||
if (error!=EGL_SUCCESS)
|
||||
{
|
||||
printf("eglGetError: %d\n", error);
|
||||
return GL_TRUE;
|
||||
}
|
||||
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user