Skip to content

Commit

Permalink
Update to use EGL_KHR_create_context extension with EGL_OPENGL_ES3_BI…
Browse files Browse the repository at this point in the history
…T_KHR

Dan and Javed, please review this change, if this turns out to be an
issue, we can back it out.
I tried with PowerVR v3.2, and it works.  It should work with other
platforms and simulators as well since there is a fallback mechanism to
the old way.
  • Loading branch information
bpurnomo committed Nov 16, 2013
1 parent 5119eb8 commit 896b84e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Common/Include/esUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#else
#include <GLES3/gl3.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#endif
#ifdef __cplusplus

Expand Down
41 changes: 41 additions & 0 deletions Common/Source/esUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <assert.h>
#include "esUtil.h"
#include "esUtil_win.h"

Expand Down Expand Up @@ -97,6 +98,29 @@ __attribute__ ( ( packed ) )
#endif

#ifndef __APPLE__

///
// IsEGLKHRCreateContextSupported()
//
// Check whether EGL_KHR_create_context extension is supported
//
EGLBoolean IsEGLKHRCreateContextSupported (const EGLDisplay *eglDisplay )
{
const char *extensions = eglQueryString ( eglDisplay, EGL_EXTENSIONS );

// check whether EGL_KHR_create_context is in the extension string
if ( strstr( extensions, "EGL_KHR_create_context" ) )
{
// extension is supported
return EGL_TRUE;
}
else
{
// extension is not supported
return EGL_FALSE;
}
}

///
// CreateEGLContext()
//
Expand All @@ -123,6 +147,18 @@ EGLBoolean CreateEGLContext ( EGLNativeWindowType eglNativeWindow, EGLNativeDisp
return EGL_FALSE;
}

// if EGL_KHR_create_context extension is supported, then we will use
// EGL_OPENGL_ES3_BIT_KHR instead of EGL_OPENGL_ES2_BIT in the attribute list
#ifdef EGL_KHR_create_context
if ( IsEGLKHRCreateContextSupported ( display ) )
{
// attribList[14] should be EGL_RENDERABLE_TYPE
assert ( attribList[14] == EGL_RENDERABLE_TYPE );

attribList[15] = EGL_OPENGL_ES3_BIT_KHR;
}
#endif

// Initialize EGL
if ( !eglInitialize ( display, &majorVersion, &minorVersion ) )
{
Expand Down Expand Up @@ -208,7 +244,12 @@ GLboolean ESUTIL_API esCreateWindow ( ESContext *esContext, const char *title, G
EGL_DEPTH_SIZE, ( flags & ES_WINDOW_DEPTH ) ? 8 : EGL_DONT_CARE,
EGL_STENCIL_SIZE, ( flags & ES_WINDOW_STENCIL ) ? 8 : EGL_DONT_CARE,
EGL_SAMPLE_BUFFERS, ( flags & ES_WINDOW_MULTISAMPLE ) ? 1 : 0,

// the 14th and 15th element of this array should not be changed to different attributes
// as in CreateEGLContext(), we will update the EGL_OPENGL_ES2_BIT with EGL_OPENGL_ES3_BIT_KHR
// if EGL_KHR_create_context extension is supported by the implementation
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,

EGL_NONE
};

Expand Down

0 comments on commit 896b84e

Please sign in to comment.