#include <Standard_ProgramError.hxx>
-#if defined(_WIN32)
+#if defined(HAVE_EGL)
+ #include <EGL/egl.h>
+ #ifdef _MSC_VER
+ #pragma comment(lib, "libEGL.lib")
+ #endif
+#elif defined(_WIN32)
//
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
#include <dlfcn.h>
// =======================================================================
Standard_Boolean OpenGl_Context::IsCurrent() const
{
-#if defined(_WIN32)
+#if defined(HAVE_EGL)
+ if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY
+ || (EGLSurface )myWindow == EGL_NO_SURFACE
+ || (EGLContext )myGContext == EGL_NO_CONTEXT)
+ {
+ return Standard_False;
+ }
+
+ return (((EGLDisplay )myDisplay == eglGetCurrentDisplay())
+ && ((EGLContext )myGContext == eglGetCurrentContext())
+ && ((EGLSurface )myWindow == eglGetCurrentSurface (EGL_DRAW)));
+#elif defined(_WIN32)
if (myWindowDC == NULL || myGContext == NULL)
{
return Standard_False;
// =======================================================================
Standard_Boolean OpenGl_Context::MakeCurrent()
{
-#if defined(_WIN32)
+#if defined(HAVE_EGL)
+ if ((EGLDisplay )myDisplay == EGL_NO_DISPLAY
+ || (EGLSurface )myWindow == EGL_NO_SURFACE
+ || (EGLContext )myGContext == EGL_NO_CONTEXT)
+ {
+ Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
+ return Standard_False;
+ }
+
+ if (eglMakeCurrent ((EGLDisplay )myDisplay, (EGLSurface )myWindow, (EGLSurface )myWindow, (EGLContext )myGContext) != EGL_TRUE)
+ {
+ // if there is no current context it might be impossible to use glGetError() correctly
+ PushMessage (GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB, GL_DEBUG_TYPE_ERROR_ARB, 0, GL_DEBUG_SEVERITY_HIGH_ARB,
+ "eglMakeCurrent() has failed!");
+ myIsInitialized = Standard_False;
+ return Standard_False;
+ }
+#elif defined(_WIN32)
if (myWindowDC == NULL || myGContext == NULL)
{
Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called before!");
// =======================================================================
void OpenGl_Context::SwapBuffers()
{
-#if defined(_WIN32)
+#if defined(HAVE_EGL)
+ if ((EGLSurface )myWindow != EGL_NO_SURFACE)
+ {
+ eglSwapBuffers ((EGLDisplay )myDisplay, (EGLSurface )myWindow);
+ }
+#elif defined(_WIN32)
if ((HDC )myWindowDC != NULL)
{
::SwapBuffers ((HDC )myWindowDC);
// =======================================================================
void* OpenGl_Context::findProc (const char* theFuncName)
{
-#if defined(_WIN32)
+#if defined(HAVE_EGL)
+ return (void* )eglGetProcAddress (theFuncName);
+#elif defined(_WIN32)
return wglGetProcAddress (theFuncName);
#elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
return (myGlLibHandle != NULL) ? dlsym (myGlLibHandle, theFuncName) : NULL;
return Standard_True;
}
-#if defined(_WIN32)
+#if defined(HAVE_EGL)
+ myDisplay = (Aspect_Display )eglGetCurrentDisplay();
+ myGContext = (Aspect_RenderingContext )eglGetCurrentContext();
+ myWindow = (Aspect_Drawable )eglGetCurrentSurface(EGL_DRAW);
+#elif defined(_WIN32)
myWindowDC = (Aspect_Handle )wglGetCurrentDC();
myGContext = (Aspect_RenderingContext )wglGetCurrentContext();
#else
// function : Init
// purpose :
// =======================================================================
-#if defined(_WIN32)
+#if defined(HAVE_EGL)
+Standard_Boolean OpenGl_Context::Init (const Aspect_Drawable theEglSurface,
+ const Aspect_Display theEglDisplay,
+ const Aspect_RenderingContext theEglContext)
+#elif defined(_WIN32)
Standard_Boolean OpenGl_Context::Init (const Aspect_Handle theWindow,
const Aspect_Handle theWindowDC,
const Aspect_RenderingContext theGContext)
#endif
{
Standard_ProgramError_Raise_if (myIsInitialized, "OpenGl_Context::Init() should be called only once!");
-#if defined(_WIN32)
+#if defined(HAVE_EGL)
+ myWindow = theEglSurface;
+ myGContext = theEglContext;
+ myDisplay = theEglDisplay;
+#elif defined(_WIN32)
myWindow = theWindow;
myGContext = theGContext;
myWindowDC = theWindowDC;
#define FindProcShort(theFunc) FindProc(#theFunc, myFuncs->theFunc)
// retrieve platform-dependent extensions
-#ifdef _WIN32
+#if defined(_WIN32) && !defined(HAVE_EGL)
if (FindProcShort (wglGetExtensionsStringARB))
{
const char* aWglExts = myFuncs->wglGetExtensionsStringARB (wglGetCurrentDC());
return myIsInitialized;
}
-#if defined(_WIN32)
+#if defined(HAVE_EGL)
+ //! Initialize class from specified surface and rendering context. Method should be called only once.
+ //! @return false if OpenGL context can not be bound to specified surface
+ Standard_EXPORT Standard_Boolean Init (const Aspect_Drawable theEglSurface,
+ const Aspect_Display theEglDisplay,
+ const Aspect_RenderingContext theEglContext);
+#elif defined(_WIN32)
//! Initialize class from specified window and rendering context. Method should be called only once.
//! @return false if OpenGL context can not be bound to specified window
Standard_EXPORT Standard_Boolean Init (const Aspect_Handle theWindow,
private: // system-dependent fields
-#if defined(_WIN32)
+#if defined(HAVE_EGL)
+ Aspect_Drawable myWindow; //!< EGL surface : EGLSurface
+ Aspect_Display myDisplay; //!< EGL connection to the Display : EGLDisplay
+ Aspect_RenderingContext myGContext; //!< EGL rendering context : EGLContext
+#elif defined(_WIN32)
Aspect_Handle myWindow; //!< window handle (owner of GL context) : HWND
Aspect_Handle myWindowDC; //!< Device Descriptor handle : HDC
Aspect_RenderingContext myGContext; //!< Rendering Context handle : HGLRC