void VUserDrawObj::Render(const Handle(OpenGl_Workspace)& theWorkspace) const
{
- // this sample does not use GLSL programs - make sure it is disabled
- Handle(OpenGl_Context) aCtx = theWorkspace->GetGlContext();
- aCtx->BindProgram (Handle(OpenGl_ShaderProgram)());
- aCtx->ShaderManager()->PushState (Handle(OpenGl_ShaderProgram)());
+ const Handle(OpenGl_Context)& aCtx = theWorkspace->GetGlContext();
// To test linking against OpenGl_Workspace and all aspect classes
const OpenGl_AspectMarker* aMA = theWorkspace->AspectMarker();
aTA->Aspect()->Font();
OpenGl_Vec4 aColor = theWorkspace->LineColor();
-#if !defined(GL_ES_VERSION_2_0)
+ aCtx->ShaderManager()->BindLineProgram (Handle(OpenGl_TextureSet)(), false, false, false, Handle(OpenGl_ShaderProgram)());
+ aCtx->SetColor4fv (aColor);
+
+ const OpenGl_Vec3 aVertArray[4] =
+ {
+ OpenGl_Vec3(myCoords[0], myCoords[1], myCoords[2]),
+ OpenGl_Vec3(myCoords[3], myCoords[4], myCoords[2]),
+ OpenGl_Vec3(myCoords[3], myCoords[4], myCoords[5]),
+ OpenGl_Vec3(myCoords[0], myCoords[1], myCoords[5]),
+ };
+ Handle(OpenGl_VertexBuffer) aVertBuffer = new OpenGl_VertexBuffer();
+ aVertBuffer->Init (aCtx, 3, 4, aVertArray[0].GetData());
+
// Finally draw something to make sure UserDraw really works
- glPushAttrib(GL_ENABLE_BIT);
- glDisable(GL_LIGHTING);
- glColor4fv(aColor.GetData());
- glBegin(GL_LINE_LOOP);
- glVertex3f(myCoords[0], myCoords[1], myCoords[2]);
- glVertex3f(myCoords[3], myCoords[4], myCoords[2]);
- glVertex3f(myCoords[3], myCoords[4], myCoords[5]);
- glVertex3f(myCoords[0], myCoords[1], myCoords[5]);
- glEnd();
- glPopAttrib();
-#endif
+ aVertBuffer->BindAttribute (aCtx, Graphic3d_TOA_POS);
+ glDrawArrays(GL_LINE_LOOP, 0, aVertBuffer->GetElemsNb());
+ aVertBuffer->UnbindAttribute(aCtx, Graphic3d_TOA_POS);
+ aVertBuffer->Release (aCtx.get());
}
} // end of anonymous namespace
#include <Aspect_Convert.hxx>
#include <Aspect_WindowDefinitionError.hxx>
+#include <Message.hxx>
+#include <Message_Messenger.hxx>
-#include <GL/glx.h>
-
-IMPLEMENT_STANDARD_RTTIEXT(Xw_Window,Aspect_Window)
+#if defined(HAVE_EGL) || defined(HAVE_GLES2)
+ #include <EGL/egl.h>
+#else
+ #include <GL/glx.h>
namespace
{
}
+#endif
+
+IMPLEMENT_STANDARD_RTTIEXT(Xw_Window, Aspect_Window)
+
// =======================================================================
// function : Xw_Window
// purpose :
myYBottom (thePxTop + thePxHeight),
myIsOwnWin (Standard_True)
{
- int aDummy = 0;
if (thePxWidth <= 0 || thePxHeight <= 0)
{
throw Aspect_WindowDefinitionError("Xw_Window, Coordinate(s) out of range");
throw Aspect_WindowDefinitionError("Xw_Window, X Display connection is undefined");
return;
}
- else if (!glXQueryExtension (myDisplay->GetDisplay(), &aDummy, &aDummy))
- {
- throw Aspect_WindowDefinitionError("Xw_Window, GLX extension is unavailable");
- return;
- }
Display* aDisp = myDisplay->GetDisplay();
int aScreen = DefaultScreen(aDisp);
Window aParent = RootWindow (aDisp, aScreen);
XVisualInfo* aVisInfo = NULL;
+#if defined(HAVE_EGL) || defined(HAVE_GLES2)
+ EGLDisplay anEglDisplay = eglGetDisplay (aDisp);
+ EGLint aVerMajor = 0; EGLint aVerMinor = 0;
+ XVisualInfo aVisInfoTmp; memset (&aVisInfoTmp, 0, sizeof(aVisInfoTmp));
+ if (anEglDisplay != EGL_NO_DISPLAY
+ && eglInitialize (anEglDisplay, &aVerMajor, &aVerMinor) == EGL_TRUE)
+ {
+ EGLint aConfigAttribs[] =
+ {
+ EGL_RED_SIZE, 8,
+ EGL_GREEN_SIZE, 8,
+ EGL_BLUE_SIZE, 8,
+ EGL_ALPHA_SIZE, 0,
+ EGL_DEPTH_SIZE, 24,
+ EGL_STENCIL_SIZE, 8,
+ #if defined(HAVE_GLES2)
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+ #else
+ EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,
+ #endif
+ EGL_NONE
+ };
+
+ EGLint aNbConfigs = 0;
+ void* anEglConfig = NULL;
+ if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) != EGL_TRUE
+ || anEglConfig == NULL)
+ {
+ eglGetError();
+ aConfigAttribs[4 * 2 + 1] = 16; // try config with smaller depth buffer
+ if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) != EGL_TRUE
+ || anEglConfig == NULL)
+ {
+ anEglConfig = NULL;
+ }
+ }
+
+ if (anEglConfig != NULL
+ && eglGetConfigAttrib (anEglDisplay, anEglConfig, EGL_NATIVE_VISUAL_ID, (EGLint* )&aVisInfoTmp.visualid) == EGL_TRUE)
+ {
+ int aNbVisuals = 0;
+ aVisInfoTmp.screen = DefaultScreen (aDisp);
+ aVisInfo = XGetVisualInfo (aDisp, VisualIDMask | VisualScreenMask, &aVisInfoTmp, &aNbVisuals);
+ }
+ }
+ if (aVisInfo == NULL)
+ {
+ Message::DefaultMessenger()->Send ("Warning: cannot choose Visual using EGL while creating Xw_Window", Message_Warning);
+ }
+#else
+ int aDummy = 0;
+ if (!glXQueryExtension (myDisplay->GetDisplay(), &aDummy, &aDummy))
+ {
+ throw Aspect_WindowDefinitionError("Xw_Window, GLX extension is unavailable");
+ return;
+ }
if (myFBConfig == NULL)
{
// FBConfigs were added in GLX version 1.3
throw Aspect_WindowDefinitionError("Xw_Window, couldn't find compatible Visual (RGBA, double-buffered)");
return;
}
+#endif
unsigned long aMask = 0;
XSetWindowAttributes aWinAttr;
memset(&aWinAttr, 0, sizeof(XSetWindowAttributes));
aWinAttr.event_mask = ExposureMask | StructureNotifyMask;
aMask |= CWEventMask;
- aWinAttr.colormap = XCreateColormap(aDisp, aParent, aVisInfo->visual, AllocNone);
+ if (aVisInfo != NULL)
+ {
+ aWinAttr.colormap = XCreateColormap(aDisp, aParent, aVisInfo->visual, AllocNone);
+ }
aWinAttr.border_pixel = 0;
aWinAttr.override_redirect = False;
myXWindow = XCreateWindow(aDisp, aParent,
myXLeft, myYTop, thePxWidth, thePxHeight,
- 0, aVisInfo->depth,
+ 0, aVisInfo != NULL ? aVisInfo->depth : CopyFromParent,
InputOutput,
- aVisInfo->visual,
+ aVisInfo != NULL ? aVisInfo->visual : CopyFromParent,
CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &aWinAttr);
- XFree (aVisInfo); aVisInfo = NULL;
+ if (aVisInfo != NULL)
+ {
+ XFree (aVisInfo);
+ aVisInfo = NULL;
+ }
if (myXWindow == 0)
{
throw Aspect_WindowDefinitionError("Xw_Window, Unable to create window");
myYBottom (512),
myIsOwnWin (Standard_False)
{
- int aDummy = 0;
if (theXWin == 0)
{
throw Aspect_WindowDefinitionError("Xw_Window, given invalid X window");
throw Aspect_WindowDefinitionError("Xw_Window, X Display connection is undefined");
return;
}
- else if (!glXQueryExtension (myDisplay->GetDisplay(), &aDummy, &aDummy))
+#if !defined(HAVE_EGL) && !defined(HAVE_GLES2)
+ int aDummy = 0;
+ if (!glXQueryExtension (myDisplay->GetDisplay(), &aDummy, &aDummy))
{
myXWindow = 0;
throw Aspect_WindowDefinitionError("Xw_Window, GLX extension is unavailable");
return;
}
+#endif
Display* aDisp = myDisplay->GetDisplay();
XWindowAttributes aWinAttr;
XGetWindowAttributes (aDisp, myXWindow, &aWinAttr);
- const int aScreen = DefaultScreen (aDisp);
- const long aVisInfoMask = VisualIDMask | VisualScreenMask;
XVisualInfo aVisInfoTmp;
aVisInfoTmp.visualid = aWinAttr.visual->visualid;
- aVisInfoTmp.screen = aScreen;
+ aVisInfoTmp.screen = DefaultScreen (aDisp);
int aNbItems = 0;
- XVisualInfo* aVisInfo = XGetVisualInfo (aDisp, aVisInfoMask, &aVisInfoTmp, &aNbItems);
+ XVisualInfo* aVisInfo = XGetVisualInfo (aDisp, VisualIDMask | VisualScreenMask, &aVisInfoTmp, &aNbItems);
if (aVisInfo == NULL)
{
throw Aspect_WindowDefinitionError("Xw_Window, Visual is unavailable");