Created
January 17, 2014 03:37
-
-
Save prabindh/8467984 to your computer and use it in GitHub Desktop.
Usage of eglswapinterval in OpenGL ES2.0. Taken from https://github.com/prabindh/sgxperf/blob/master/sgxperf_gles20_vg.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//egl init | |
int common_eglinit(int testID, int surfaceType, NATIVE_PIXMAP_STRUCT** pNativePixmapPtr) | |
{ | |
EGLint iMajorVersion, iMinorVersion; | |
EGLint ai32ContextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; | |
eglDisplay = eglGetDisplay((int)0); | |
if (!eglInitialize(eglDisplay, &iMajorVersion, &iMinorVersion)) | |
return 1; | |
if(testID == 9) | |
eglBindAPI(EGL_OPENVG_API); | |
else | |
eglBindAPI(EGL_OPENGL_ES_API); | |
if (!TestEGLError("eglBindAPI")) | |
return 1; | |
EGLint pi32ConfigAttribs[5]; | |
pi32ConfigAttribs[0] = EGL_SURFACE_TYPE; | |
pi32ConfigAttribs[1] = EGL_WINDOW_BIT | EGL_PIXMAP_BIT; | |
pi32ConfigAttribs[2] = EGL_RENDERABLE_TYPE; | |
if(testID == 9) | |
pi32ConfigAttribs[3] = EGL_OPENVG_BIT; | |
else | |
pi32ConfigAttribs[3] = EGL_OPENGL_ES2_BIT; | |
pi32ConfigAttribs[4] = EGL_NONE; | |
int iConfigs; | |
if (!eglChooseConfig(eglDisplay, pi32ConfigAttribs, &eglConfig, 1, &iConfigs) || (iConfigs != 1)) | |
{ | |
SGXPERF_ERR_printf("Error: eglChooseConfig() failed.\n"); | |
return 1; | |
} | |
if(surfaceType == SGXPERF_SURFACE_TYPE_WINDOW) | |
eglSurface = eglCreateWindowSurface(eglDisplay, eglConfig, (void*) NULL, NULL); | |
else if(surfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_16) | |
{ | |
common_create_native_pixmap(SGXPERF_RGB565, | |
inTextureWidth, inTextureHeight, pNativePixmapPtr); | |
eglSurface = eglCreatePixmapSurface(eglDisplay, eglConfig, *pNativePixmapPtr, NULL); | |
} | |
else if(surfaceType == SGXPERF_SURFACE_TYPE_PIXMAP_32) | |
{ | |
common_create_native_pixmap(SGXPERF_ARGB8888, | |
inTextureWidth, inTextureHeight, pNativePixmapPtr); | |
eglSurface = eglCreatePixmapSurface(eglDisplay, eglConfig, *pNativePixmapPtr, NULL); | |
} | |
else | |
return 999; | |
if (!TestEGLError("eglCreateSurface")) | |
return 1; | |
if(testID == 14) //Create one pixmap surface for context switch latency check | |
{ | |
common_create_native_pixmap(SGXPERF_RGB565, | |
inTextureWidth, inTextureHeight, pNativePixmapPtr); | |
eglSurface2 = eglCreatePixmapSurface(eglDisplay, eglConfig, *pNativePixmapPtr, NULL); | |
} | |
if (!TestEGLError("eglCreateSurface")) | |
return 1; | |
if(testID == 9) | |
eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, NULL); | |
else | |
eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, ai32ContextAttribs); | |
if (!TestEGLError("eglCreateContext")) | |
return 1; | |
eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext); | |
if (!TestEGLError("eglMakeCurrent")) | |
return 1; | |
eglSwapInterval(eglDisplay, 1); | |
if (!TestEGLError("eglSwapInterval")) | |
return 1; | |
eglQuerySurface(eglDisplay, eglSurface, EGL_WIDTH, &windowWidth); | |
eglQuerySurface(eglDisplay, eglSurface, EGL_HEIGHT, &windowHeight); | |
SGXPERF_printf("Window width=%d, Height=%d\n", windowWidth, windowHeight); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment