diff --git a/samples/tcl/dimensions.tcl b/samples/tcl/dimensions.tcl index b56fdcc23b..d05f4736e7 100644 --- a/samples/tcl/dimensions.tcl +++ b/samples/tcl/dimensions.tcl @@ -59,7 +59,7 @@ vdimension ad_1 -angle -shapes as_38 as_49 -color black vdimension ad_2 -angle -shapes bs_24 bs_25 -color black vdimension ad_3 -angle -shapes as_48 as_43 -color black -puts "Changing text and arrow paramaters of dimensions..." +puts "Changing text and arrow parameters of dimensions..." foreach i $aList { vdimparam $i -text 3d sh 6 -arrowlength 4 -arrowangle $anArrAngle } diff --git a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx index 0d5e9c6885..086ac826d8 100644 --- a/src/ViewerTest/ViewerTest_OpenGlCommands.cxx +++ b/src/ViewerTest/ViewerTest_OpenGlCommands.cxx @@ -155,10 +155,7 @@ void VUserDrawObj::ComputeSelection (const Handle(SelectMgr_Selection)& theSelec 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(); @@ -167,19 +164,24 @@ void VUserDrawObj::Render(const Handle(OpenGl_Workspace)& theWorkspace) const 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 diff --git a/src/Xw/Xw_Window.cxx b/src/Xw/Xw_Window.cxx index c4bd6d3f73..3b221537f0 100644 --- a/src/Xw/Xw_Window.cxx +++ b/src/Xw/Xw_Window.cxx @@ -19,10 +19,13 @@ #include #include +#include +#include -#include - -IMPLEMENT_STANDARD_RTTIEXT(Xw_Window,Aspect_Window) +#if defined(HAVE_EGL) || defined(HAVE_GLES2) + #include +#else + #include namespace { @@ -52,6 +55,10 @@ namespace } +#endif + +IMPLEMENT_STANDARD_RTTIEXT(Xw_Window, Aspect_Window) + // ======================================================================= // function : Xw_Window // purpose : @@ -73,7 +80,6 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, myYBottom (thePxTop + thePxHeight), myIsOwnWin (Standard_True) { - int aDummy = 0; if (thePxWidth <= 0 || thePxHeight <= 0) { throw Aspect_WindowDefinitionError("Xw_Window, Coordinate(s) out of range"); @@ -83,17 +89,68 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, 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 @@ -128,23 +185,31 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, 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"); @@ -189,7 +254,6 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, myYBottom (512), myIsOwnWin (Standard_False) { - int aDummy = 0; if (theXWin == 0) { throw Aspect_WindowDefinitionError("Xw_Window, given invalid X window"); @@ -200,24 +264,25 @@ Xw_Window::Xw_Window (const Handle(Aspect_DisplayConnection)& theXDisplay, 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");