1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00

0029631: Samples: build AndroidQt sample together with OCCT on Windows platform

- _WIN32 definition provides functionality for sample on Windows
- CMake procedure is changed to have Qt5_FOUND variable defined before compilation modules. Searching of Qt packages is moved into qt.cmake.
This commit is contained in:
nds
2018-03-23 10:36:07 +03:00
parent 384db46a5a
commit 41ea50ac6f
10 changed files with 135 additions and 37 deletions

View File

@@ -11,13 +11,19 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <AndroidQt_Window.h>
#include <AndroidQt.h>
#include <AndroidQt_UserInteractionParameters.h>
#if defined(_WIN32)
#include <windows.h>
#endif
#include "AndroidQt.h"
#include "AndroidQt_UserInteractionParameters.h"
#include "AndroidQt_Window.h"
#include <AIS_Shape.hxx>
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
#include <Message.hxx>
#include <Message_Messenger.hxx>
#include <OpenGl_GraphicDriver.hxx>
#include <Quantity_Color.hxx>
#include <Standard_ErrorHandler.hxx>
@@ -25,6 +31,7 @@
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <UnitsAPI.hxx>
#include <WNT_Window.hxx>
#include <EGL/egl.h>
#include <QFileInfo>
@@ -36,7 +43,7 @@
AndroidQt::AndroidQt()
: myFitAllAction (false)
{
connect (this, SIGNAL(windowChanged(QQuickWindow*)), this, SLOT(handleWindowChanged(QQuickWindow*)));
connect (this, SIGNAL (windowChanged (QQuickWindow*)), this, SLOT (handleWindowChanged (QQuickWindow*)));
// set shaders location variable
QByteArray aDataRoot = "/data/data/org.qtproject.example.AndroidQt/files/opencascade/shared";
@@ -138,7 +145,7 @@ void AndroidQt::handleWindowChanged (QQuickWindow* theWin)
return;
}
connect(theWin, SIGNAL(beforeSynchronizing()), this, SLOT(sync()), Qt::DirectConnection);
connect (theWin, SIGNAL (beforeSynchronizing()), this, SLOT (sync()), Qt::DirectConnection);
theWin->setClearBeforeRendering (false);
}
@@ -151,28 +158,54 @@ void AndroidQt::sync()
{
myViewportSize = window()->size() * window()->devicePixelRatio();
Graphic3d_Vec2i aWinTopLeft (window()->x(), window()->y());
Graphic3d_Vec2i aWinSize (myViewportSize.width(), myViewportSize.height());
const bool isChangedLeft = (myWinTopLeft.x() != aWinTopLeft.x());
const bool isChangedTop = (myWinTopLeft.y() != aWinTopLeft.y());
myWinTopLeft = aWinTopLeft;
if (myViewer.IsNull())
{
initViewer();
connect (window(), SIGNAL(beforeRendering()), this, SLOT(paint()), Qt::DirectConnection);
initViewer (Aspect_Drawable (window()->winId()));
connect (window(), SIGNAL (beforeRendering()), this, SLOT (paint()), Qt::DirectConnection);
}
else
{
Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myViewer->Driver());
#ifdef __ANDROID__
if (aDriver->getRawGlContext() != eglGetCurrentContext())
{
initViewer();
initViewer (Aspect_Drawable (window()->winId()));
}
else
#endif
{
Handle(AndroidQt_Window) aWindow = Handle(AndroidQt_Window)::DownCast (myView->Window());
#ifdef __ANDROID__
Handle(AndroidQt_Window) aWindow = Handle(AndroidQt_Window)::DownCast(myView->Window());
aWindow->SetSize (myViewportSize.width(), myViewportSize.height());
//myView->MustBeResized(); // can be used instead of SetWindow() when EGLsurface has not been changed
EGLContext anEglContext = eglGetCurrentContext();
myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext);
#else
if (aWinSize.x() != myWinSize.x()
|| aWinSize.y() != myWinSize.y())
{
myView->MustBeResized();
myView->Invalidate();
}
else if (isChangedTop)
{
myView->MustBeResized();
}
else if (isChangedLeft)
{
myView->MustBeResized();
}
#endif
}
}
myWinSize = aWinSize;
}
// =======================================================================
@@ -183,7 +216,7 @@ void AndroidQt::paint()
{
myMutex.lock();
if (Abs(myTouchPoint.DevX()) + Abs(myTouchPoint.DevY()) > 1)
if (Abs (myTouchPoint.DevX()) + Abs (myTouchPoint.DevY()) > 1)
{
myView->StartRotation (myTouchPoint.X().first, myTouchPoint.Y().first);
myView->Rotation (myTouchPoint.X().second, myTouchPoint.Y().second);
@@ -206,10 +239,12 @@ void AndroidQt::paint()
// function : initViewer
// purpose :
// =======================================================================
bool AndroidQt::initViewer()
bool AndroidQt::initViewer (Aspect_Drawable theWin)
{
EGLint aCfgId = 0;
int aWidth = 0, aHeight = 0;
Handle(Aspect_DisplayConnection) aDisplayConnection;
#ifdef __ANDROID__
EGLint aCfgId = 0;
EGLDisplay anEglDisplay = eglGetCurrentDisplay();
EGLContext anEglContext = eglGetCurrentContext();
EGLSurface anEglSurf = eglGetCurrentSurface (EGL_DRAW);
@@ -232,6 +267,7 @@ bool AndroidQt::initViewer()
if (eglChooseConfig (anEglDisplay, aConfigAttribs, &anEglConfig, 1, &aNbConfigs) != EGL_TRUE)
{
Message::DefaultMessenger()->Send ("Error: EGL does not provide compatible configurations", Message_Fail);
release();
return false;
}
@@ -242,6 +278,7 @@ bool AndroidQt::initViewer()
Handle(AndroidQt_Window) aWindow = Handle(AndroidQt_Window)::DownCast (myView->Window());
if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig))
{
Message::DefaultMessenger()->Send ("Error: OpenGl_GraphicDriver can not be initialized", Message_Fail);
release();
return false;
}
@@ -251,15 +288,46 @@ bool AndroidQt::initViewer()
}
Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver (NULL, Standard_False);
aDriver->ChangeOptions().buffersNoSwap = Standard_True;
//aDriver->ChangeOptions().glslWarnings = Standard_True; // for GLSL shaders debug
if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig))
#elif defined(_WIN32)
HWND aWinHandle = (HWND)theWin;
HDC aWindowDC = wglGetCurrentDC();
HGLRC aRendCtx = wglGetCurrentContext();
if (aWinHandle == NULL
|| aWindowDC == NULL
|| aRendCtx == NULL)
{
Message::DefaultMessenger()->Send ("Error: No active WGL context!", Message_Fail);
release();
return false;
}
RECT aRect;
::GetClientRect (aWinHandle, &aRect);
aWidth = aRect.right - aRect.left;
aHeight = aRect.bottom - aRect.top;
myWinSize.x() = aWidth;
myWinSize.y() = aHeight;
if (!myViewer.IsNull())
{
Handle(WNT_Window) aWindow = new WNT_Window (aWinHandle);
myView->SetWindow (aWindow, (Aspect_RenderingContext)aRendCtx);
return true;
}
Handle(OpenGl_GraphicDriver) aDriver = new OpenGl_GraphicDriver (aDisplayConnection, Standard_False);
#endif
aDriver->ChangeOptions().buffersNoSwap = Standard_True;
//aDriver->ChangeOptions().glslWarnings = Standard_True; // for GLSL shaders debug
#ifdef __ANDROID__
if (!aDriver->InitEglContext (anEglDisplay, anEglContext, anEglConfig))
{
Message::DefaultMessenger()->Send ("Error: OpenGl_GraphicDriver can not be initialized", Message_Fail);
release();
return false;
}
#endif
// create viewer
myViewer = new V3d_Viewer (aDriver);
myViewer->SetDefaultBackgroundColor (AndroidQt_UserInteractionParameters::BgColor.Name());
@@ -270,10 +338,20 @@ bool AndroidQt::initViewer()
myContext = new AIS_InteractiveContext (myViewer);
myContext->SetDisplayMode (AIS_Shaded, false);
#ifdef __ANDROID__
Handle(AndroidQt_Window) aWindow = new AndroidQt_Window (aWidth, aHeight);
myView = myViewer->CreateView();
#elif defined(_WIN32)
Handle(WNT_Window) aWindow = new WNT_Window (aWinHandle);
#endif
myView = myViewer->CreateView();
myView->SetImmediateUpdate (Standard_False);
#ifdef __ANDROID__
myView->SetWindow (aWindow, (Aspect_RenderingContext )anEglContext);
#else
myView->SetWindow (aWindow, (Aspect_RenderingContext )aRendCtx);
#endif
myView->TriedronDisplay (Aspect_TOTP_RIGHT_LOWER, Quantity_NOC_WHITE, 0.08, V3d_ZBUFFER);
return true;

View File

@@ -29,7 +29,7 @@
#include <QMutex>
#include <AndroidQt_TouchParameters.h>
#include "AndroidQt_TouchParameters.h"
//! QML item with embedded OCCT viewer.
class AndroidQt : public QQuickItem
@@ -67,7 +67,8 @@ private slots:
private:
//! (Re-)initialize viewer on OpenGL context change.
bool initViewer();
//! \param theWin handle to GUI window
bool initViewer (Aspect_Drawable theWin);
//! Close viewer
void release();
@@ -77,6 +78,8 @@ private:
Handle(V3d_Viewer) myViewer; //!< 3D viewer
Handle(V3d_View) myView; //!< 3D view
Handle(AIS_InteractiveContext) myContext; //!< interactive context
Graphic3d_Vec2i myWinTopLeft; //!< cached window position (top-left)
Graphic3d_Vec2i myWinSize; //!< cached window width-height
QMutex myMutex; //!< mutex for interconnection with rendering thread
QSize myViewportSize; //!< QML item size

View File

@@ -11,7 +11,7 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <AndroidQt_TouchParameters.h>
#include "AndroidQt_TouchParameters.h"
// =======================================================================
// function : AndroidQt_TouchParameters

View File

@@ -11,7 +11,7 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <AndroidQt_Window.h>
#include "AndroidQt_Window.h"
IMPLEMENT_STANDARD_RTTIEXT(AndroidQt_Window, Aspect_Window)

View File

@@ -14,10 +14,18 @@
#include <QApplication>
#include <QQmlApplicationEngine>
#include <AndroidQt.h>
#include "AndroidQt.h"
#include <OSD_Environment.hxx>
int main(int argc, char *argv[])
{
#if defined(_WIN32) && (QT_VERSION > 0x050000)
TCollection_AsciiString aPlugindsDirName = OSD_Environment ("QTDIR").Value();
if (!aPlugindsDirName.IsEmpty())
QApplication::addLibraryPath (QString (aPlugindsDirName.ToCString()) + "/plugins");
#endif
QApplication app(argc, argv);
qmlRegisterType<AndroidQt>("AndroidQt", 1, 0, "AndroidQt");