summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntti Määttä <antti.maatta@qt.io>2019-05-27 11:50:54 +0300
committerAntti Määttä <antti.maatta@qt.io>2019-06-05 14:37:14 +0300
commit6478ebedb1dd28d48dd73cbb9f8b99d2a83f02c7 (patch)
tree352f79a8a2317980b73082c64d9f81b29475dd3c
parent9908f37e55f2bc980d8c788290ee40e8ff4cb9cc (diff)
Support platform default fbo
Task-number: QT3DS-3531 Change-Id: Icd362a4dd1623e474d84e5f0bc07147332d9aa4c Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
-rw-r--r--src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp20
-rw-r--r--src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer_p.h2
-rw-r--r--src/Runtime/ogl-runtime/src/render/backends/gl/Q3DSRenderBackendGLES2.cpp6
-rw-r--r--src/Runtime/ogl-runtime/src/render/backends/gl/Qt3DSRenderBackendGL3.cpp2
-rw-r--r--src/Runtime/ogl-runtime/src/render/backends/gl/Qt3DSRenderBackendGLBase.cpp2
5 files changed, 23 insertions, 9 deletions
diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp
index d6074837..32ffb99a 100644
--- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp
+++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer.cpp
@@ -128,8 +128,7 @@ Q3DSSurfaceViewer::~Q3DSSurfaceViewer()
*/
bool Q3DSSurfaceViewer::create(QSurface *surface, QOpenGLContext *context)
{
- // #TODO: QT3DS-3531 Fix this to behave as in RT2
- return create(surface, context, 0);
+ return d_ptr->initialize(surface, context, 0, false);
}
@@ -147,7 +146,7 @@ bool Q3DSSurfaceViewer::create(QSurface *surface, QOpenGLContext *context)
*/
bool Q3DSSurfaceViewer::create(QSurface *surface, QOpenGLContext *context, GLuint fboId)
{
- return d_ptr->initialize(surface, context, fboId);
+ return d_ptr->initialize(surface, context, fboId, true);
}
/*!
@@ -444,7 +443,8 @@ void Q3DSSurfaceViewerPrivate::setUpdateInterval(int interval)
/*!
* \internal
*/
-bool Q3DSSurfaceViewerPrivate::initialize(QSurface *surface, QOpenGLContext *context, GLuint fboId)
+bool Q3DSSurfaceViewerPrivate::initialize(QSurface *surface, QOpenGLContext *context, GLuint fboId,
+ bool idValid)
{
Q_ASSERT(context);
Q_ASSERT(surface);
@@ -466,8 +466,8 @@ bool Q3DSSurfaceViewerPrivate::initialize(QSurface *surface, QOpenGLContext *con
m_surface = surface;
m_context = context;
- m_fboId = fboId;
- if (m_surface->surfaceClass() == QSurface::Window && fboId == 0)
+ m_fboId = idValid ? fboId : m_context->defaultFramebufferObject();
+ if (m_surface->surfaceClass() == QSurface::Window)
m_pixelRatio = static_cast<QWindow *>(m_surface)->devicePixelRatio();
surfaceObject()->installEventFilter(this);
@@ -528,7 +528,9 @@ void Q3DSSurfaceViewerPrivate::update()
setSize(m_surface->size());
m_viewerApp->Render();
- if (m_fboId == 0)
+ const uint defaultFbo = m_context->defaultFramebufferObject();
+
+ if (m_surface->surfaceClass() == QSurface::Window && m_fboId == defaultFbo)
m_context->swapBuffers(m_surface);
Q_EMIT q_ptr->frameUpdate();
@@ -569,8 +571,10 @@ QImage Q3DSSurfaceViewerPrivate::grab(const QRect &rect)
QImage fullGrab = qt_gl_read_framebuffer(fullSize, false, false);
// Also update the screen to match the grab, since we just rendered
- if (m_fboId == 0)
+ if (m_surface->surfaceClass() == QSurface::Window
+ && m_fboId == m_context->defaultFramebufferObject()) {
m_context->swapBuffers(m_surface);
+ }
if (captureRect.size() == fullSize)
image = fullGrab;
diff --git a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer_p.h b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer_p.h
index 624a368c..fba82e5a 100644
--- a/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer_p.h
+++ b/src/Runtime/ogl-runtime/src/api/studio3d/q3dssurfaceviewer_p.h
@@ -64,7 +64,7 @@ public:
void setSize(const QSize &size);
void setUpdateInterval(int interval);
- bool initialize(QSurface *surface, QOpenGLContext *context, GLuint fboId);
+ bool initialize(QSurface *surface, QOpenGLContext *context, GLuint fboId, bool idValid);
void update();
QImage grab(const QRect &rect);
diff --git a/src/Runtime/ogl-runtime/src/render/backends/gl/Q3DSRenderBackendGLES2.cpp b/src/Runtime/ogl-runtime/src/render/backends/gl/Q3DSRenderBackendGLES2.cpp
index d38c330c..b06c80f8 100644
--- a/src/Runtime/ogl-runtime/src/render/backends/gl/Q3DSRenderBackendGLES2.cpp
+++ b/src/Runtime/ogl-runtime/src/render/backends/gl/Q3DSRenderBackendGLES2.cpp
@@ -32,6 +32,8 @@
#include "render/backends/gl/Qt3DSRenderBackendRenderStatesGL.h"
#include "render/backends/gl/Qt3DSRenderBackendShaderProgramGL.h"
+#include <QtGui/qopenglcontext.h>
+
#ifdef RENDER_BACKEND_LOG_GL_ERRORS
#define RENDER_LOG_ERROR_PARAMS(x) checkGLError(#x, __FILE__, __LINE__)
#else
@@ -605,6 +607,8 @@ void NVRenderBackendGLES2Impl::RenderTargetAttach(NVRenderBackendRenderTargetObj
void NVRenderBackendGLES2Impl::SetRenderTarget(NVRenderBackendRenderTargetObject rto)
{
GLuint fboID = HandleToID_cast(GLuint, size_t, rto);
+ if (!fboID)
+ fboID = QT_PREPEND_NAMESPACE(QOpenGLContext)::currentContext()->defaultFramebufferObject();
GL_CALL_EXTRA_FUNCTION(glBindFramebuffer(GL_FRAMEBUFFER, fboID));
}
@@ -612,6 +616,8 @@ void NVRenderBackendGLES2Impl::SetRenderTarget(NVRenderBackendRenderTargetObject
void NVRenderBackendGLES2Impl::SetReadTarget(NVRenderBackendRenderTargetObject rto)
{
GLuint fboID = HandleToID_cast(GLuint, size_t, rto);
+ if (!fboID)
+ fboID = QT_PREPEND_NAMESPACE(QOpenGLContext)::currentContext()->defaultFramebufferObject();
GL_CALL_EXTRA_FUNCTION(glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID));
}
diff --git a/src/Runtime/ogl-runtime/src/render/backends/gl/Qt3DSRenderBackendGL3.cpp b/src/Runtime/ogl-runtime/src/render/backends/gl/Qt3DSRenderBackendGL3.cpp
index f49f3a16..061151ed 100644
--- a/src/Runtime/ogl-runtime/src/render/backends/gl/Qt3DSRenderBackendGL3.cpp
+++ b/src/Runtime/ogl-runtime/src/render/backends/gl/Qt3DSRenderBackendGL3.cpp
@@ -547,6 +547,8 @@ namespace render {
void NVRenderBackendGL3Impl::SetReadTarget(NVRenderBackendRenderTargetObject rto)
{
GLuint fboID = HandleToID_cast(GLuint, size_t, rto);
+ if (!fboID)
+ fboID = QT_PREPEND_NAMESPACE(QOpenGLContext)::currentContext()->defaultFramebufferObject();
GL_CALL_EXTRA_FUNCTION(glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID));
}
diff --git a/src/Runtime/ogl-runtime/src/render/backends/gl/Qt3DSRenderBackendGLBase.cpp b/src/Runtime/ogl-runtime/src/render/backends/gl/Qt3DSRenderBackendGLBase.cpp
index ba25ae7e..3598aced 100644
--- a/src/Runtime/ogl-runtime/src/render/backends/gl/Qt3DSRenderBackendGLBase.cpp
+++ b/src/Runtime/ogl-runtime/src/render/backends/gl/Qt3DSRenderBackendGLBase.cpp
@@ -790,6 +790,8 @@ namespace render {
void NVRenderBackendGLBase::SetRenderTarget(NVRenderBackendRenderTargetObject rto)
{
GLuint fboID = HandleToID_cast(GLuint, size_t, rto);
+ if (!fboID)
+ fboID = QT_PREPEND_NAMESPACE(QOpenGLContext)::currentContext()->defaultFramebufferObject();
GL_CALL_FUNCTION(glBindFramebuffer(GL_FRAMEBUFFER, fboID));
}