diff options
Diffstat (limited to 'src/plugins')
75 files changed, 509 insertions, 897 deletions
diff --git a/src/plugins/geometryloaders/configure.pri b/src/plugins/geometryloaders/configure.pri deleted file mode 100644 index 1e104f57e..000000000 --- a/src/plugins/geometryloaders/configure.pri +++ /dev/null @@ -1,20 +0,0 @@ -defineTest(qtConfLibrary_fbx) { - libdir = - - prefix = $$getenv(FBXSDK) - !isEmpty(prefix) { - !qtConfResolvePathIncs($${1}.includedir, $${prefix}/include, $$2): \ - return(false) - !win32: libdir += $${prefix}/lib - } - - libs = $$getenv(FBXSDK_LIBS) - isEmpty(libs): \ - libs = $$eval($${1}.libs) - - !qtConfResolvePathLibs($${1}.libs, $$libdir, $$libs): \ - return(false) - - return(true) -} - diff --git a/src/plugins/geometryloaders/default/basegeometryloader.cpp b/src/plugins/geometryloaders/default/basegeometryloader.cpp index 09e4ba3a8..802548994 100644 --- a/src/plugins/geometryloaders/default/basegeometryloader.cpp +++ b/src/plugins/geometryloaders/default/basegeometryloader.cpp @@ -12,10 +12,11 @@ QT_BEGIN_NAMESPACE -using namespace Qt3DCore; namespace Qt3DRender { +using namespace Qt3DCore; + Q_LOGGING_CATEGORY(BaseGeometryLoaderLog, "Qt3D.BaseGeometryLoader", QtWarningMsg) BaseGeometryLoader::BaseGeometryLoader() diff --git a/src/plugins/geometryloaders/default/default.pro b/src/plugins/geometryloaders/default/default.pro deleted file mode 100644 index c126b5844..000000000 --- a/src/plugins/geometryloaders/default/default.pro +++ /dev/null @@ -1,19 +0,0 @@ -TARGET = defaultgeometryloader -QT += core-private 3dcore 3dcore-private 3drender 3drender-private - -HEADERS += \ - basegeometryloader_p.h \ - -SOURCES += \ - main.cpp \ - basegeometryloader.cpp \ - objgeometryloader.cpp \ - plygeometryloader.cpp \ - stlgeometryloader.cpp \ - -DISTFILES += \ - default.json - -PLUGIN_TYPE = geometryloaders -PLUGIN_CLASS_NAME = DefaultGeometryLoaderPlugin -load(qt_plugin) diff --git a/src/plugins/geometryloaders/default/objgeometryloader.cpp b/src/plugins/geometryloaders/default/objgeometryloader.cpp index dc41ca492..e741426c1 100644 --- a/src/plugins/geometryloaders/default/objgeometryloader.cpp +++ b/src/plugins/geometryloaders/default/objgeometryloader.cpp @@ -66,10 +66,19 @@ bool ObjGeometryLoader::doLoad(QIODevice *ioDev, const QString &subMesh) if (lineSize > 0 && line[0] != '#') { if (line[lineSize - 1] == '\n') --lineSize; // chop newline + if (lineSize <= 0) + continue; + if (line[lineSize - 1] == '\r') --lineSize; // chop newline also for CRLF format - while (line[lineSize - 1] == ' ' || line[lineSize - 1] == '\t') + if (lineSize <= 0) + continue; + + while (lineSize > 0 && (line[lineSize - 1] == ' ' || line[lineSize - 1] == '\t')) { --lineSize; // chop trailing spaces + } + if (lineSize <= 0) + continue; const ByteArraySplitter tokens(line, line + lineSize, ' ', Qt::SkipEmptyParts); diff --git a/src/plugins/geometryloaders/fbx/fbx.pro b/src/plugins/geometryloaders/fbx/fbx.pro deleted file mode 100644 index a9c17d4e7..000000000 --- a/src/plugins/geometryloaders/fbx/fbx.pro +++ /dev/null @@ -1,19 +0,0 @@ -TARGET = fbxgeometryloader -QT += core-private 3dcore 3dcore-private 3drender 3drender-private - -HEADERS += \ - fbxgeometryloader.h \ - -SOURCES += \ - main.cpp \ - fbxgeometryloader.cpp \ - -DISTFILES += \ - fbx.json - -include($$OUT_PWD/../qtgeometryloaders-config.pri) -QMAKE_USE += fbx - -PLUGIN_TYPE = geometryloaders -PLUGIN_CLASS_NAME = fbxGeometryLoaderPlugin -load(qt_plugin) diff --git a/src/plugins/geometryloaders/geometryloaders.pro b/src/plugins/geometryloaders/geometryloaders.pro deleted file mode 100644 index 764c615da..000000000 --- a/src/plugins/geometryloaders/geometryloaders.pro +++ /dev/null @@ -1,4 +0,0 @@ -TEMPLATE = subdirs -qtConfig(regularexpression) : SUBDIRS += default -SUBDIRS += gltf -qtConfig(qt3d-fbxsdk) : SUBDIRS += fbx diff --git a/src/plugins/geometryloaders/gltf/gltf.pro b/src/plugins/geometryloaders/gltf/gltf.pro deleted file mode 100644 index 815226b4e..000000000 --- a/src/plugins/geometryloaders/gltf/gltf.pro +++ /dev/null @@ -1,16 +0,0 @@ -TARGET = gltfgeometryloader -QT += core-private 3dcore 3dcore-private 3drender 3drender-private - -HEADERS += \ - gltfgeometryloader.h \ - -SOURCES += \ - main.cpp \ - gltfgeometryloader.cpp \ - -DISTFILES += \ - gltf.json - -PLUGIN_TYPE = geometryloaders -PLUGIN_CLASS_NAME = GLTFGeometryLoaderPlugin -load(qt_plugin) diff --git a/src/plugins/geometryloaders/gltf/gltfgeometryloader.cpp b/src/plugins/geometryloaders/gltf/gltfgeometryloader.cpp index 4b2c6a916..16d5d7e5d 100644 --- a/src/plugins/geometryloaders/gltf/gltfgeometryloader.cpp +++ b/src/plugins/geometryloaders/gltf/gltfgeometryloader.cpp @@ -21,10 +21,11 @@ QT_BEGIN_NAMESPACE static_cast<const wchar_t*>(static_cast<const void*>(string.utf16())) #endif -using namespace Qt3DCore; namespace Qt3DRender { +using namespace Qt3DCore; + Q_LOGGING_CATEGORY(GLTFGeometryLoaderLog, "Qt3D.GLTFGeometryLoader", QtWarningMsg) #define KEY_ASSET QLatin1String("asset") diff --git a/src/plugins/renderers/dummy/dummy.pro b/src/plugins/renderers/dummy/dummy.pro deleted file mode 100644 index e69de29bb..000000000 --- a/src/plugins/renderers/dummy/dummy.pro +++ /dev/null diff --git a/src/plugins/renderers/opengl/CMakeLists.txt b/src/plugins/renderers/opengl/CMakeLists.txt index 9e1ccc329..82328d1f9 100644 --- a/src/plugins/renderers/opengl/CMakeLists.txt +++ b/src/plugins/renderers/opengl/CMakeLists.txt @@ -121,6 +121,9 @@ qt_internal_add_plugin(OpenGLRendererPlugin Qt::OpenGLPrivate ) +# QTransform conflicts +set_target_properties(OpenGLRendererPlugin PROPERTIES UNITY_BUILD OFF) + qt_internal_extend_target(OpenGLRendererPlugin CONDITION NOT INTEGRITY SOURCES debug/imguirenderer.cpp debug/imguirenderer_p.h diff --git a/src/plugins/renderers/opengl/debug/debug.pri b/src/plugins/renderers/opengl/debug/debug.pri deleted file mode 100644 index 38a056f6b..000000000 --- a/src/plugins/renderers/opengl/debug/debug.pri +++ /dev/null @@ -1,9 +0,0 @@ -INCLUDEPATH += $$PWD - -include($$QT3D_ROOT/src/3rdparty/imgui/imgui.pri) - -HEADERS += \ - $$PWD/imguirenderer_p.h - -SOURCES += \ - $$PWD/imguirenderer.cpp diff --git a/src/plugins/renderers/opengl/debug/imguirenderer.cpp b/src/plugins/renderers/opengl/debug/imguirenderer.cpp index 4a53117a0..e2ea3d203 100644 --- a/src/plugins/renderers/opengl/debug/imguirenderer.cpp +++ b/src/plugins/renderers/opengl/debug/imguirenderer.cpp @@ -29,16 +29,10 @@ #define GL_VERTEX_ARRAY_BINDING 0x85B5 #endif -#ifdef _MSC_VER -#pragma warning (disable: 4996) // 'This function or variable may be unsafe': strcpy, strdup, sprintf, vsnprintf, sscanf, fopen -#endif - QT_BEGIN_NAMESPACE -using namespace Qt3DRender; -using namespace Render; -using namespace Render::Debug; -using namespace Render::OpenGL; +namespace Qt3DRR = Qt3DRender::Render; +namespace Qt3DRRD = Qt3DRR::Debug; namespace { @@ -70,42 +64,69 @@ namespace { int vertexToPrimitiveCount(Qt3DRender::QGeometryRenderer::PrimitiveType primitiveType, int numVertices) { int nPrimitives = 0; switch (primitiveType) { - case QGeometryRenderer::Points: - case QGeometryRenderer::LineLoop: nPrimitives += numVertices; break; - case QGeometryRenderer::Triangles: nPrimitives += numVertices / 3; break; - case QGeometryRenderer::Lines: nPrimitives += numVertices / 2; break; - case QGeometryRenderer::TriangleFan: - case QGeometryRenderer::TriangleStrip: - case QGeometryRenderer::LineStrip: nPrimitives += numVertices - 1; break; - case QGeometryRenderer::TrianglesAdjacency: nPrimitives += numVertices / 6; break; - case QGeometryRenderer::TriangleStripAdjacency: - case QGeometryRenderer::LineStripAdjacency: nPrimitives += numVertices / 2 - 1; break; - case QGeometryRenderer::LinesAdjacency: nPrimitives += numVertices / 4; break; - case QGeometryRenderer::Patches: nPrimitives += 1; + case Qt3DRender::QGeometryRenderer::Points: + case Qt3DRender::QGeometryRenderer::LineLoop: + nPrimitives += numVertices; + break; + case Qt3DRender::QGeometryRenderer::Triangles: + nPrimitives += numVertices / 3; + break; + case Qt3DRender::QGeometryRenderer::Lines: + nPrimitives += numVertices / 2; + break; + case Qt3DRender::QGeometryRenderer::TriangleFan: + case Qt3DRender::QGeometryRenderer::TriangleStrip: + case Qt3DRender::QGeometryRenderer::LineStrip: + nPrimitives += numVertices - 1; + break; + case Qt3DRender::QGeometryRenderer::TrianglesAdjacency: + nPrimitives += numVertices / 6; + break; + case Qt3DRender::QGeometryRenderer::TriangleStripAdjacency: + case Qt3DRender::QGeometryRenderer::LineStripAdjacency: + nPrimitives += numVertices / 2 - 1; + break; + case Qt3DRender::QGeometryRenderer::LinesAdjacency: + nPrimitives += numVertices / 4; + break; + case Qt3DRender::QGeometryRenderer::Patches: + nPrimitives += 1; } return nPrimitives; } const char *primitiveTypeName(Qt3DRender::QGeometryRenderer::PrimitiveType primitiveType) { switch (primitiveType) { - case QGeometryRenderer::Points: return "Points"; - case QGeometryRenderer::LineLoop: return "LineLoop"; - case QGeometryRenderer::Triangles: return "Triangles"; - case QGeometryRenderer::TrianglesAdjacency: return "TriangleAdjacency"; - case QGeometryRenderer::TriangleFan: return "TriangleFan"; - case QGeometryRenderer::TriangleStrip: return "TriangleStrip"; - case QGeometryRenderer::TriangleStripAdjacency: return "TriangleStringAdjacency"; - case QGeometryRenderer::LineStrip: return "LineStrip"; - case QGeometryRenderer::LineStripAdjacency: return "LineStripAdjacency"; - case QGeometryRenderer::Lines: return "Lines"; - case QGeometryRenderer::LinesAdjacency: return "LinesAdjacency"; - case QGeometryRenderer::Patches: return "Patches"; + case Qt3DRender::QGeometryRenderer::Points: + return "Points"; + case Qt3DRender::QGeometryRenderer::LineLoop: + return "LineLoop"; + case Qt3DRender::QGeometryRenderer::Triangles: + return "Triangles"; + case Qt3DRender::QGeometryRenderer::TrianglesAdjacency: + return "TriangleAdjacency"; + case Qt3DRender::QGeometryRenderer::TriangleFan: + return "TriangleFan"; + case Qt3DRender::QGeometryRenderer::TriangleStrip: + return "TriangleStrip"; + case Qt3DRender::QGeometryRenderer::TriangleStripAdjacency: + return "TriangleStringAdjacency"; + case Qt3DRender::QGeometryRenderer::LineStrip: + return "LineStrip"; + case Qt3DRender::QGeometryRenderer::LineStripAdjacency: + return "LineStripAdjacency"; + case Qt3DRender::QGeometryRenderer::Lines: + return "Lines"; + case Qt3DRender::QGeometryRenderer::LinesAdjacency: + return "LinesAdjacency"; + case Qt3DRender::QGeometryRenderer::Patches: + return "Patches"; } return ""; } } -ImGuiRenderer::ImGuiRenderer(Qt3DRender::Render::OpenGL::Renderer *renderer) +Qt3DRRD::ImGuiRenderer::ImGuiRenderer(Qt3DRR::OpenGL::Renderer *renderer) : m_renderer(renderer) { ImGui::CreateContext(); @@ -132,9 +153,9 @@ ImGuiRenderer::ImGuiRenderer(Qt3DRender::Render::OpenGL::Renderer *renderer) m_jobsRange.first = m_jobsRange.second = 0.f; } -ImGuiRenderer::~ImGuiRenderer() = default; +Qt3DRRD::ImGuiRenderer::~ImGuiRenderer() = default; -void ImGuiRenderer::renderDebugOverlay(const std::vector<RenderView *> &renderViews, const RenderView *renderView, int jobsInLastFrame) +void Qt3DRRD::ImGuiRenderer::renderDebugOverlay(const std::vector<Qt3DRR::OpenGL::RenderView *> &renderViews, const Qt3DRR::OpenGL::RenderView *renderView, int jobsInLastFrame) { if (!newFrame(renderView)) return; @@ -162,7 +183,7 @@ void ImGuiRenderer::renderDebugOverlay(const std::vector<RenderView *> &renderVi { ImGui::Begin("Qt3D Profiling"); char caption[50]; - sprintf(caption, "Avg %.3f ms/frame (%.1f FPS)", static_cast<double>(1000.0f / ImGui::GetIO().Framerate), static_cast<double>(ImGui::GetIO().Framerate)); + snprintf(caption, sizeof(caption), "Avg %.3f ms/frame (%.1f FPS)", static_cast<double>(1000.0f / ImGui::GetIO().Framerate), static_cast<double>(ImGui::GetIO().Framerate)); ImGui::PlotLines("FPS", m_fpsLog, logIndex + 1, 0, caption, m_fpsRange.first, m_fpsRange.second, ImVec2(0, 80)); ImGui::PlotHistogram("Jobs", m_jobsLog, logIndex + 1, 0, nullptr, m_jobsRange.first, m_jobsRange.second, ImVec2(0, 80)); @@ -172,10 +193,10 @@ void ImGuiRenderer::renderDebugOverlay(const std::vector<RenderView *> &renderVi QSet<HGeometryRenderer> inUseGeometries; QSet<Qt3DCore::QNodeId> inUseTextures; for (int j=0; j<renderViewsCount; j++) { - RenderView *rv = renderViews.at(j); + Qt3DRR::OpenGL::RenderView *rv = renderViews.at(j); nCommands += rv->commandCount(); - rv->forEachCommand([&] (const RenderCommand &command) { - if (command.m_type != RenderCommand::Draw) + rv->forEachCommand([&](const Qt3DRR::OpenGL::RenderCommand &command) { + if (command.m_type != Qt3DRR::OpenGL::RenderCommand::Draw) return; nVertices += command.m_primitiveCount; nPrimitives += vertexToPrimitiveCount(command.m_primitiveType, command.m_primitiveCount); @@ -280,24 +301,24 @@ void ImGuiRenderer::renderDebugOverlay(const std::vector<RenderView *> &renderVi renderDrawList(ImGui::GetDrawData()); } -void ImGuiRenderer::setCapabilities(const QString &capabilities) +void Qt3DRRD::ImGuiRenderer::setCapabilities(const QString &capabilities) { m_capabilities = capabilities.toLatin1(); } -void ImGuiRenderer::showGLInfo() +void Qt3DRRD::ImGuiRenderer::showGLInfo() { ImGui::Begin("Open GL Details", &m_showGLInfoWindow); ImGui::Text("%s", m_capabilities.data()); ImGui::End(); } -void ImGuiRenderer::showRenderDetails(const std::vector<RenderView *> &renderViews) +void Qt3DRRD::ImGuiRenderer::showRenderDetails(const std::vector<Qt3DRR::OpenGL::RenderView *> &renderViews) { ImGui::Begin("Render Views", &m_showRenderDetailsWindow); int i = 1; - for (const RenderView *view: renderViews) { + for (const Qt3DRR::OpenGL::RenderView *view : renderViews) { QString label(QLatin1String("View ") + QString::number(i++)); if (ImGui::TreeNode(label.toLatin1().data())) { ImGui::Text("Viewport: (%.1f, %.1f, %.1f, %.1f)", view->viewport().x(), view->viewport().y(), @@ -311,7 +332,7 @@ void ImGuiRenderer::showRenderDetails(const std::vector<RenderView *> &renderVie ImGui::Text("Clear Stencil Value: %d", view->clearStencilValue()); int j = 1; - view->forEachCommand([&] (const RenderCommand &command) { + view->forEachCommand([&](const Qt3DRR::OpenGL::RenderCommand &command) { GeometryRenderer *rGeometryRenderer = m_renderer->nodeManagers()->data<GeometryRenderer, GeometryRendererManager>(command.m_geometryRenderer); QString label = QString(QLatin1String("Command %1 {%2}")).arg(QString::number(j++), QString::number(rGeometryRenderer->peerId().id())); if (ImGui::TreeNode(label.toLatin1().data())) { @@ -334,7 +355,7 @@ void ImGuiRenderer::showRenderDetails(const std::vector<RenderView *> &renderVie ImGui::End(); } -void ImGuiRenderer::renderDrawList(ImDrawData *draw_data) +void Qt3DRRD::ImGuiRenderer::renderDrawList(ImDrawData *draw_data) { // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates) ImGuiIO& io = ImGui::GetIO(); @@ -431,7 +452,7 @@ void ImGuiRenderer::renderDrawList(ImDrawData *draw_data) m_funcs->glScissor(last_scissor_box[0], last_scissor_box[1], static_cast<GLsizei>(last_scissor_box[2]), static_cast<GLsizei>(last_scissor_box[3])); } -bool ImGuiRenderer::createFontsTexture() +bool Qt3DRRD::ImGuiRenderer::createFontsTexture() { // Build texture atlas ImGuiIO& io = ImGui::GetIO(); @@ -457,7 +478,7 @@ bool ImGuiRenderer::createFontsTexture() return true; } -bool ImGuiRenderer::createDeviceObjects() +bool Qt3DRRD::ImGuiRenderer::createDeviceObjects() { auto *glContext = m_renderer->submissionContext()->openGLContext(); if (glContext->format().majorVersion() < 3) { @@ -575,7 +596,7 @@ bool ImGuiRenderer::createDeviceObjects() return true; } -bool ImGuiRenderer::newFrame(const RenderView *renderView) +bool Qt3DRRD::ImGuiRenderer::newFrame(const Qt3DRR::OpenGL::RenderView *renderView) { if (!m_funcs) m_funcs = m_renderer->submissionContext()->openGLContext()->extraFunctions(); @@ -611,7 +632,7 @@ bool ImGuiRenderer::newFrame(const RenderView *renderView) return true; } -void ImGuiRenderer::onMouseChange(QMouseEvent *event) +void Qt3DRRD::ImGuiRenderer::onMouseChange(QMouseEvent *event) { ImGuiIO& io = ImGui::GetIO(); io.MousePos = ImVec2(event->pos().x(), event->pos().y()); @@ -620,14 +641,14 @@ void ImGuiRenderer::onMouseChange(QMouseEvent *event) m_mousePressed[2] = event->buttons() & Qt::MiddleButton; } -void ImGuiRenderer::onWheel(QWheelEvent *event) +void Qt3DRRD::ImGuiRenderer::onWheel(QWheelEvent *event) { // 5 lines per unit m_mouseWheelH += event->pixelDelta().x() / (ImGui::GetTextLineHeight()); m_mouseWheel += event->pixelDelta().y() / (5.f * ImGui::GetTextLineHeight()); } -void ImGuiRenderer::onKeyPressRelease(QKeyEvent *event) +void Qt3DRRD::ImGuiRenderer::onKeyPressRelease(QKeyEvent *event) { ImGuiIO& io = ImGui::GetIO(); if (keyMap.contains(event->key())) @@ -652,7 +673,7 @@ void ImGuiRenderer::onKeyPressRelease(QKeyEvent *event) #endif } -void ImGuiRenderer::processEvent(QEvent *event) +void Qt3DRRD::ImGuiRenderer::processEvent(QEvent *event) { switch (event->type()) { case QEvent::MouseMove: diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicscontext.cpp b/src/plugins/renderers/opengl/graphicshelpers/graphicscontext.cpp index 6bcb3deb1..62c5d7d30 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicscontext.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicscontext.cpp @@ -28,9 +28,7 @@ #include <glshader_p.h> #if !QT_CONFIG(opengles2) -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include <QtOpenGL/QOpenGLVersionFunctionsFactory> -#endif #include <QOpenGLFunctions_2_0> #include <QOpenGLFunctions_3_2_Core> #include <QOpenGLFunctions_3_3_Core> @@ -48,13 +46,9 @@ #include <QSurface> #include <QWindow> #include <QOpenGLTexture> -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #ifdef QT_OPENGL_LIB #include <QtOpenGL/QOpenGLDebugLogger> #endif -#else -#include <QOpenGLDebugLogger> -#endif QT_BEGIN_NAMESPACE @@ -306,22 +300,6 @@ void GraphicsContext::loadShader(Shader *shaderNode, shaderNode->requestCacheRebuild(); } -void GraphicsContext::activateDrawBuffers(const AttachmentPack &attachments) -{ - const std::vector<int> &activeDrawBuffers = attachments.getGlDrawBuffers(); - - if (m_glHelper->checkFrameBufferComplete()) { - if (activeDrawBuffers.size() > 1) {// We need MRT - if (m_glHelper->supportsFeature(GraphicsHelperInterface::MRT)) { - // Set up MRT, glDrawBuffers... - m_glHelper->drawBuffers(GLsizei(activeDrawBuffers.size()), activeDrawBuffers.data()); - } - } - } else { - qWarning() << "FBO incomplete"; - } -} - void GraphicsContext::rasterMode(GLenum faceMode, GLenum rasterMode) { m_glHelper->rasterMode(faceMode, rasterMode); @@ -358,32 +336,16 @@ GraphicsHelperInterface *GraphicsContext::resolveHighestOpenGLFunctions() #if !QT_CONFIG(opengles2) else { QAbstractOpenGLFunctions *glFunctions = nullptr; -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) if ((glFunctions = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_4_3_Core>()) != nullptr) { -#else - if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_4_3_Core>()) != nullptr) { -#endif qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 4.3"; glHelper = new GraphicsHelperGL4(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) } else if ((glFunctions = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_3_3_Core>()) != nullptr) { -#else - } else if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_3_3_Core>()) != nullptr) { -#endif qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 3.3"; glHelper = new GraphicsHelperGL3_3(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) } else if ((glFunctions = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_3_2_Core>()) != nullptr) { -#else - } else if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_3_2_Core>()) != nullptr) { -#endif qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 3.2"; glHelper = new GraphicsHelperGL3_2(); -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) } else if ((glFunctions = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_2_0>()) != nullptr) { -#else - } else if ((glFunctions = m_gl->versionFunctions<QOpenGLFunctions_2_0>()) != nullptr) { -#endif qCDebug(Backend) << Q_FUNC_INFO << " Building OpenGL 2 Helper"; glHelper = new GraphicsHelperGL2(); } @@ -402,7 +364,7 @@ GraphicsHelperInterface *GraphicsContext::resolveHighestOpenGLFunctions() qCDebug(Backend) << "Qt3D: Enabling OpenGL debug logging"; m_debugLogger.reset(new QOpenGLDebugLogger); if (m_debugLogger->initialize()) { - QObject::connect(m_debugLogger.data(), &QOpenGLDebugLogger::messageLogged, &logOpenGLDebugMessage); + QObject::connect(m_debugLogger.data(), &QOpenGLDebugLogger::messageLogged, m_debugLogger.data(), &logOpenGLDebugMessage); const QString mode = QString::fromLocal8Bit(debugLoggingMode); m_debugLogger->startLogging(mode.startsWith(QLatin1String("sync"), Qt::CaseInsensitive) ? QOpenGLDebugLogger::SynchronousLogging @@ -748,7 +710,7 @@ void GraphicsContext::drawBuffer(GLenum mode) m_glHelper->drawBuffer(mode); } -void GraphicsContext::drawBuffers(GLsizei n, const int *bufs) +void GraphicsContext::drawBuffers(GLsizei n, const GLenum *bufs) { m_glHelper->drawBuffers(n, bufs); } diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicscontext_p.h b/src/plugins/renderers/opengl/graphicshelpers/graphicscontext_p.h index cdff6fa48..f2eeb479d 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicscontext_p.h +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicscontext_p.h @@ -134,14 +134,13 @@ public: void pointSize(bool programmable, GLfloat value); void readBuffer(GLenum mode); void drawBuffer(GLenum mode); - void drawBuffers(GLsizei n, const int *bufs); + void drawBuffers(GLsizei n, const GLenum *bufs); void setMSAAEnabled(bool enabled); void setAlphaCoverageEnabled(bool enabled); void setClipPlane(int clipPlane, const QVector3D &normal, float distance); void setSeamlessCubemap(bool enable); void setVerticesPerPatch(GLint verticesPerPatch); void memoryBarrier(QMemoryBarrier::Operations barriers); - void activateDrawBuffers(const AttachmentPack &attachments); void rasterMode(GLenum faceMode, GLenum rasterMode); // Helper methods diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes2.cpp b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes2.cpp index accc1e757..bd6c6a8f7 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes2.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes2.cpp @@ -513,7 +513,7 @@ bool GraphicsHelperES2::supportsFeature(GraphicsHelperInterface::Feature feature } } -void GraphicsHelperES2::drawBuffers(GLsizei, const int *) +void GraphicsHelperES2::drawBuffers(GLsizei, const GLenum *) { static bool showWarning = true; if (!showWarning) diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes2_p.h b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes2_p.h index 5c51cb013..fb237a4ab 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes2_p.h +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes2_p.h @@ -66,7 +66,7 @@ public: void drawArraysIndirect(GLenum mode,void *indirect) override; void drawArraysInstanced(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances) override; void drawArraysInstancedBaseInstance(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances, GLsizei baseInstance) override; - void drawBuffers(GLsizei n, const int *bufs) override; + void drawBuffers(GLsizei n, const GLenum *bufs) override; void drawElements(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLint baseVertex = 0) override; void drawElementsIndirect(GLenum mode, GLenum type, void *indirect) override; void drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLsizei instances, GLint baseVertex = 0, GLint baseInstance = 0) override; diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3.cpp b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3.cpp index 75876686c..486810143 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3.cpp @@ -310,13 +310,9 @@ bool GraphicsHelperES3::supportsFeature(GraphicsHelperInterface::Feature feature } } -void GraphicsHelperES3::drawBuffers(GLsizei n, const int *bufs) +void GraphicsHelperES3::drawBuffers(GLsizei n, const GLenum *bufs) { - QVarLengthArray<GLenum, 16> drawBufs(n); - - for (int i = 0; i < n; i++) - drawBufs[i] = GL_COLOR_ATTACHMENT0 + bufs[i]; - m_extraFuncs->glDrawBuffers(n, drawBufs.constData()); + m_extraFuncs->glDrawBuffers(n, bufs); } UniformType GraphicsHelperES3::uniformTypeFromGLType(GLenum glType) diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3_1.cpp b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3_1.cpp index bda79dc3a..d82403d7b 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3_1.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3_1.cpp @@ -118,7 +118,7 @@ namespace OpenGL { namespace { -GLbitfield memoryBarrierGLBitfield(QMemoryBarrier::Operations barriers) +GLbitfield memoryBarrierGL3Bitfield(QMemoryBarrier::Operations barriers) { GLbitfield bits = 0; @@ -204,7 +204,7 @@ void GraphicsHelperES3_1::dispatchCompute(GLuint wx, GLuint wy, GLuint wz) void GraphicsHelperES3_1::memoryBarrier(QMemoryBarrier::Operations barriers) { - m_extraFuncs->glMemoryBarrier(memoryBarrierGLBitfield(barriers)); + m_extraFuncs->glMemoryBarrier(memoryBarrierGL3Bitfield(barriers)); } void GraphicsHelperES3_1::drawArraysIndirect(GLenum mode, void *indirect) diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3_p.h b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3_p.h index 8fc12ca6d..f294decaf 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3_p.h +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperes3_p.h @@ -38,7 +38,7 @@ public: void bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) override; void blitFramebuffer(GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1, GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1, GLbitfield mask, GLenum filter) override; void buildUniformBuffer(const QVariant &v, const ShaderUniform &description, QByteArray &buffer) override; - void drawBuffers(GLsizei n, const int *bufs) override; + void drawBuffers(GLsizei n, const GLenum *bufs) override; void drawArraysInstanced(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances) override; void drawArraysInstancedBaseInstance(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances, GLsizei baseInstance) override; void drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLsizei instances, GLint baseVertex = 0, GLint baseInstance = 0) override; diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl2.cpp b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl2.cpp index 0f7195fbd..db3074cf1 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl2.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl2.cpp @@ -399,13 +399,9 @@ bool GraphicsHelperGL2::supportsFeature(GraphicsHelperInterface::Feature feature } } -void GraphicsHelperGL2::drawBuffers(GLsizei n, const int *bufs) +void GraphicsHelperGL2::drawBuffers(GLsizei n, const GLenum *bufs) { - QVarLengthArray<GLenum, 16> drawBufs(n); - - for (int i = 0; i < n; i++) - drawBufs[i] = GL_COLOR_ATTACHMENT0 + bufs[i]; - m_extraFunctions->glDrawBuffers(n, drawBufs.constData()); + m_extraFunctions->glDrawBuffers(n, bufs); } void GraphicsHelperGL2::bindFragDataLocation(GLuint, const QHash<QString, int> &) diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl2_p.h b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl2_p.h index 6ec59eef2..49a84cf8a 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl2_p.h +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl2_p.h @@ -66,7 +66,7 @@ public: void drawArraysIndirect(GLenum mode,void *indirect) override; void drawArraysInstanced(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances) override; void drawArraysInstancedBaseInstance(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances, GLsizei baseInstance) override; - void drawBuffers(GLsizei n, const int *bufs) override; + void drawBuffers(GLsizei n, const GLenum *bufs) override; void drawElements(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLint baseVertex = 0) override; void drawElementsIndirect(GLenum mode, GLenum type, void *indirect) override; void drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLsizei instances, GLint baseVertex = 0, GLint baseInstance = 0) override; diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_2.cpp b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_2.cpp index 82b9c7542..d0fb10d12 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_2.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_2.cpp @@ -493,14 +493,9 @@ bool GraphicsHelperGL3_2::supportsFeature(GraphicsHelperInterface::Feature featu } } -void GraphicsHelperGL3_2::drawBuffers(GLsizei n, const int *bufs) +void GraphicsHelperGL3_2::drawBuffers(GLsizei n, const GLenum *bufs) { - // Use QVarLengthArray here - QVarLengthArray<GLenum, 16> drawBufs(n); - - for (int i = 0; i < n; i++) - drawBufs[i] = GL_COLOR_ATTACHMENT0 + bufs[i]; - m_funcs->glDrawBuffers(n, drawBufs.constData()); + m_funcs->glDrawBuffers(n, bufs); } void GraphicsHelperGL3_2::bindFragDataLocation(GLuint shader, const QHash<QString, int> &outputs) diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_2_p.h b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_2_p.h index 6adaf97e2..92cd17f2d 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_2_p.h +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_2_p.h @@ -67,7 +67,7 @@ public: void drawArraysIndirect(GLenum mode,void *indirect) override; void drawArraysInstanced(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances) override; void drawArraysInstancedBaseInstance(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances, GLsizei baseInstance) override; - void drawBuffers(GLsizei n, const int *bufs) override; + void drawBuffers(GLsizei n, const GLenum *bufs) override; void drawElements(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLint baseVertex = 0) override; void drawElementsIndirect(GLenum mode, GLenum type, void *indirect) override; void drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLsizei instances, GLint baseVertex = 0, GLint baseInstance = 0) override; diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_3.cpp b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_3.cpp index c2802fae0..b46e3f500 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_3.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_3.cpp @@ -474,14 +474,9 @@ bool GraphicsHelperGL3_3::supportsFeature(GraphicsHelperInterface::Feature featu } } -void GraphicsHelperGL3_3::drawBuffers(GLsizei n, const int *bufs) +void GraphicsHelperGL3_3::drawBuffers(GLsizei n, const GLenum *bufs) { - // Use QVarLengthArray here - QVarLengthArray<GLenum, 16> drawBufs(n); - - for (int i = 0; i < n; i++) - drawBufs[i] = GL_COLOR_ATTACHMENT0 + bufs[i]; - m_funcs->glDrawBuffers(n, drawBufs.constData()); + m_funcs->glDrawBuffers(n, bufs); } void GraphicsHelperGL3_3::bindFragDataLocation(GLuint shader, const QHash<QString, int> &outputs) diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_3_p.h b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_3_p.h index ba4f6c76e..041c51aae 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_3_p.h +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl3_3_p.h @@ -67,7 +67,7 @@ public: void drawArraysIndirect(GLenum mode,void *indirect) override; void drawArraysInstanced(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances) override; void drawArraysInstancedBaseInstance(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances, GLsizei baseInstance) override; - void drawBuffers(GLsizei n, const int *bufs) override; + void drawBuffers(GLsizei n, const GLenum *bufs) override; void drawElements(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLint baseVertex = 0) override; void drawElementsIndirect(GLenum mode, GLenum type, void *indirect) override; void drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLsizei instances, GLint baseVertex = 0, GLint baseInstance = 0) override; diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl4.cpp b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl4.cpp index 706923298..6a559db50 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl4.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl4.cpp @@ -85,7 +85,7 @@ namespace OpenGL { namespace { -GLbitfield memoryBarrierGLBitfield(QMemoryBarrier::Operations barriers) +GLbitfield memoryBarrierGL4Bitfield(QMemoryBarrier::Operations barriers) { GLbitfield bits = 0; @@ -843,14 +843,9 @@ bool GraphicsHelperGL4::supportsFeature(GraphicsHelperInterface::Feature feature } } -void GraphicsHelperGL4::drawBuffers(GLsizei n, const int *bufs) +void GraphicsHelperGL4::drawBuffers(GLsizei n, const GLenum *bufs) { - // Use QVarLengthArray here - QVarLengthArray<GLenum, 16> drawBufs(n); - - for (int i = 0; i < n; i++) - drawBufs[i] = GL_COLOR_ATTACHMENT0 + bufs[i]; - m_funcs->glDrawBuffers(n, drawBufs.constData()); + m_funcs->glDrawBuffers(n, bufs); } void GraphicsHelperGL4::bindFragDataLocation(GLuint shader, const QHash<QString, int> &outputs) @@ -1306,7 +1301,7 @@ GLint GraphicsHelperGL4::maxClipPlaneCount() void GraphicsHelperGL4::memoryBarrier(QMemoryBarrier::Operations barriers) { - m_funcs->glMemoryBarrier(memoryBarrierGLBitfield(barriers)); + m_funcs->glMemoryBarrier(memoryBarrierGL4Bitfield(barriers)); } void GraphicsHelperGL4::enablePrimitiveRestart(int primitiveRestartIndex) diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl4_p.h b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl4_p.h index a0ca9faa4..69c0adae0 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl4_p.h +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpergl4_p.h @@ -66,7 +66,7 @@ public: void drawArraysIndirect(GLenum mode,void *indirect) override; void drawArraysInstanced(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances) override; void drawArraysInstancedBaseInstance(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances, GLsizei baseInstance) override; - void drawBuffers(GLsizei n, const int *bufs) override; + void drawBuffers(GLsizei n, const GLenum *bufs) override; void drawElements(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLint baseVertex = 0) override; void drawElementsIndirect(GLenum mode, GLenum type, void *indirect) override; void drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLsizei instances, GLint baseVertex = 0, GLint baseInstance = 0) override; diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperinterface_p.h b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperinterface_p.h index ff9de8c59..2443f6304 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelperinterface_p.h +++ b/src/plugins/renderers/opengl/graphicshelpers/graphicshelperinterface_p.h @@ -93,7 +93,7 @@ public: virtual void drawArraysIndirect(GLenum mode,void *indirect) = 0; virtual void drawArraysInstanced(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances) = 0; virtual void drawArraysInstancedBaseInstance(GLenum primitiveType, GLint first, GLsizei count, GLsizei instances, GLsizei baseinstance) = 0; - virtual void drawBuffers(GLsizei n, const int *bufs) = 0; + virtual void drawBuffers(GLsizei n, const GLenum *bufs) = 0; virtual void drawElements(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void * indices, GLint baseVertex) = 0; virtual void drawElementsIndirect(GLenum mode, GLenum type, void *indirect) = 0; virtual void drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void * indices, GLsizei instances, GLint baseVertex, GLint baseInstance) = 0; diff --git a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpers.pri b/src/plugins/renderers/opengl/graphicshelpers/graphicshelpers.pri deleted file mode 100644 index 3cfa445ce..000000000 --- a/src/plugins/renderers/opengl/graphicshelpers/graphicshelpers.pri +++ /dev/null @@ -1,33 +0,0 @@ -#DEFINES += QT3D_RENDER_ASPECT_OPENGL_DEBUG - -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/graphicscontext_p.h \ - $$PWD/graphicshelperinterface_p.h \ - $$PWD/graphicshelperes2_p.h \ - $$PWD/graphicshelperes3_p.h \ - $$PWD/graphicshelperes3_1_p.h \ - $$PWD/graphicshelperes3_2_p.h \ - $$PWD/graphicshelpergl2_p.h \ - $$PWD/graphicshelpergl3_3_p.h \ - $$PWD/graphicshelpergl4_p.h \ - $$PWD/graphicshelpergl3_2_p.h \ - $$PWD/imagesubmissioncontext_p.h \ - $$PWD/submissioncontext_p.h \ - $$PWD/texturesubmissioncontext_p.h \ - $$PWD/qgraphicsutils_p.h - -SOURCES += \ - $$PWD/graphicscontext.cpp \ - $$PWD/graphicshelperes2.cpp \ - $$PWD/graphicshelperes3.cpp \ - $$PWD/graphicshelperes3_1.cpp \ - $$PWD/graphicshelperes3_2.cpp \ - $$PWD/graphicshelpergl2.cpp \ - $$PWD/graphicshelpergl3_3.cpp \ - $$PWD/graphicshelpergl4.cpp \ - $$PWD/graphicshelpergl3_2.cpp \ - $$PWD/imagesubmissioncontext.cpp \ - $$PWD/submissioncontext.cpp \ - $$PWD/texturesubmissioncontext.cpp diff --git a/src/plugins/renderers/opengl/graphicshelpers/qgraphicsutils_p.h b/src/plugins/renderers/opengl/graphicshelpers/qgraphicsutils_p.h index 37d999eec..d10e9fa0e 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/qgraphicsutils_p.h +++ b/src/plugins/renderers/opengl/graphicshelpers/qgraphicsutils_p.h @@ -60,12 +60,7 @@ public: static QVarLengthArray<char, 64> array(16 * byteSize); memset(array.data(), 0, array.size()); -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) switch (v.metaType().id()) { -#else - switch (v.type()) { -#endif - // 1 byte case QMetaType::Bool: { T data = v.value<bool>(); @@ -300,11 +295,7 @@ public: } } else -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) qWarning() << Q_FUNC_INFO << "QVariant type conversion not handled for " << v.metaType().id(); -#else - qWarning() << Q_FUNC_INFO << "QVariant type conversion not handled for " << v.type(); -#endif break; } diff --git a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp index e2cee1fcd..4df426b57 100644 --- a/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp +++ b/src/plugins/renderers/opengl/graphicshelpers/submissioncontext.cpp @@ -47,13 +47,9 @@ #include <QSurface> #include <QWindow> #include <QOpenGLTexture> -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #ifdef QT_OPENGL_LIB #include <QtOpenGL/QOpenGLDebugLogger> #endif -#else -#include <QOpenGLDebugLogger> -#endif QT_BEGIN_NAMESPACE @@ -65,8 +61,6 @@ QT_BEGIN_NAMESPACE #define GL_DRAW_FRAMEBUFFER 0x8CA9 #endif -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace OpenGL { @@ -87,14 +81,14 @@ unsigned int nextFreeContextId() namespace { -GLBuffer::Type attributeTypeToGLBufferType(QAttribute::AttributeType type) +GLBuffer::Type attributeTypeToGLBufferType(Qt3DCore::QAttribute::AttributeType type) { switch (type) { - case QAttribute::VertexAttribute: + case Qt3DCore::QAttribute::VertexAttribute: return GLBuffer::ArrayBuffer; - case QAttribute::IndexAttribute: + case Qt3DCore::QAttribute::IndexAttribute: return GLBuffer::IndexBuffer; - case QAttribute::DrawIndirectAttribute: + case Qt3DCore::QAttribute::DrawIndirectAttribute: return GLBuffer::DrawIndirectBuffer; default: Q_UNREACHABLE(); @@ -339,6 +333,16 @@ GLint glAttachmentPoint(const QRenderTargetOutput::AttachmentPoint &attachmentPo return GL_DEPTH_ATTACHMENT; case QRenderTargetOutput::Stencil: return GL_STENCIL_ATTACHMENT; + case QRenderTargetOutput::Left: +#ifndef GL_BACK_LEFT: +# define GL_BACK_LEFT 0x0402 +#endif + return GL_BACK_LEFT; + case QRenderTargetOutput::Right: +#ifndef GL_BACK_RIGHT: +# define GL_BACK_RIGHT 0x0403 +#endif + return GL_BACK_RIGHT; default: Q_UNREACHABLE_RETURN(GL_NONE); } @@ -470,7 +474,19 @@ void SubmissionContext::endDrawing(bool swapBuffers) void SubmissionContext::activateRenderTarget(Qt3DCore::QNodeId renderTargetNodeId, const AttachmentPack &attachments, GLuint defaultFboId) { GLuint fboId = defaultFboId; // Default FBO - if (renderTargetNodeId) { + resolveRenderTargetFormat(); // Reset m_renderTargetFormat based on the default FBO + + // check if target buffer is GL_BACK_LEFT or GL_BACK_RIGHT, as they don't need an + // own fbo + auto allLeftOrRight = std::all_of(attachments.attachments().begin(), attachments.attachments().end(), + [](const Attachment& att){ + return att.m_point == QRenderTargetOutput::Left || att.m_point == QRenderTargetOutput::Right; + }); + + const bool allAttachmentsAreLeftOrRight = attachments.attachments().size() > 0 && allLeftOrRight; + const bool shouldCreateRenderTarget = !allAttachmentsAreLeftOrRight && renderTargetNodeId; + + if (shouldCreateRenderTarget) { // New RenderTarget if (!m_renderTargets.contains(renderTargetNodeId)) { if (m_defaultFBO && fboId == m_defaultFBO) { @@ -480,9 +496,10 @@ void SubmissionContext::activateRenderTarget(Qt3DCore::QNodeId renderTargetNodeI fboId = createRenderTarget(renderTargetNodeId, attachments); } } else { - fboId = updateRenderTarget(renderTargetNodeId, attachments, true); + fboId = updateRenderTarget(renderTargetNodeId, attachments, true); // Overwrites m_renderTargetFormat based on custom FBO } } + m_activeFBO = fboId; m_activeFBONodeId = renderTargetNodeId; m_glHelper->bindFrameBufferObject(m_activeFBO, GraphicsHelperInterface::FBODraw); @@ -612,6 +629,7 @@ QImage SubmissionContext::readFramebuffer(const QRect &rect) QImage::Format imageFormat; uint stride; + // m_renderTargetFormat is set when the current RV FBO is set in activateRenderTarget /* format value should match GL internalFormat */ GLenum internalFormat = m_renderTargetFormat; @@ -851,15 +869,23 @@ SubmissionContext::RenderTargetInfo SubmissionContext::bindFrameBufferAttachment void SubmissionContext::activateDrawBuffers(const AttachmentPack &attachments) { - const std::vector<int> &activeDrawBuffers = attachments.getGlDrawBuffers(); + const std::vector<QRenderTargetOutput::AttachmentPoint> &activeDrawBuffers = attachments.getDrawBuffers(); + + std::vector<GLenum> activeGlDrawBuffers; + activeGlDrawBuffers.reserve(activeDrawBuffers.size()); + for (const auto &attachmentPoint : activeDrawBuffers) + activeGlDrawBuffers.push_back(glAttachmentPoint(attachmentPoint)); if (m_glHelper->checkFrameBufferComplete()) { if (activeDrawBuffers.size() > 1) {// We need MRT if (m_glHelper->supportsFeature(GraphicsHelperInterface::MRT)) { // Set up MRT, glDrawBuffers... - m_glHelper->drawBuffers(GLsizei(activeDrawBuffers.size()), activeDrawBuffers.data()); + m_glHelper->drawBuffers(GLsizei(activeGlDrawBuffers.size()), activeGlDrawBuffers.data()); } } + else if (activeDrawBuffers.size() == 1){ + m_glHelper->drawBuffer(activeGlDrawBuffers.at(0)); + } } else { qCWarning(Backend) << "FBO incomplete"; } @@ -1605,7 +1631,7 @@ void SubmissionContext::blitFramebuffer(Qt3DCore::QNodeId inputRenderTargetId, if (!outputBufferIsDefault) { // Note that we use glDrawBuffers, not glDrawBuffer. The // latter is not available with GLES. - const int buf = outputAttachmentPoint; + const GLenum buf = glAttachmentPoint(outputAttachmentPoint); drawBuffers(1, &buf); } @@ -1619,7 +1645,7 @@ void SubmissionContext::blitFramebuffer(Qt3DCore::QNodeId inputRenderTargetId, // Reset draw buffer bindFramebuffer(lastDrawFboId, GraphicsHelperInterface::FBOReadAndDraw); if (outputAttachmentPoint != QRenderTargetOutput::Color0) { - const int buf = QRenderTargetOutput::Color0; + const GLenum buf = GL_COLOR_ATTACHMENT0; drawBuffers(1, &buf); } } diff --git a/src/plugins/renderers/opengl/io/io.pri b/src/plugins/renderers/opengl/io/io.pri deleted file mode 100644 index 462978c4d..000000000 --- a/src/plugins/renderers/opengl/io/io.pri +++ /dev/null @@ -1,8 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/glbuffer.cpp - -HEADERS += \ - $$PWD/glbuffer_p.h - diff --git a/src/plugins/renderers/opengl/managers/managers.pri b/src/plugins/renderers/opengl/managers/managers.pri deleted file mode 100644 index 97a4c2c45..000000000 --- a/src/plugins/renderers/opengl/managers/managers.pri +++ /dev/null @@ -1,8 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/gl_handle_types_p.h \ - $$PWD/glresourcemanagers_p.h - -SOURCES += \ - $$PWD/glresourcemanagers.cpp diff --git a/src/plugins/renderers/opengl/opengl.pri b/src/plugins/renderers/opengl/opengl.pri deleted file mode 100644 index 4308992e5..000000000 --- a/src/plugins/renderers/opengl/opengl.pri +++ /dev/null @@ -1,41 +0,0 @@ -QT += core-private gui-private 3dcore 3dcore-private 3drender 3drender-private opengl-private - -CONFIG += c++17 - -# Qt3D is free of Q_FOREACH - make sure it stays that way: -DEFINES += QT_NO_FOREACH -DEFINES += BUILD_QT3D_MODULE - -# For Q_AUTOTEST_EXPORT to work -DEFINES += QT_BUILDING_QT - -DISTFILES += \ - openglrenderer.json - -include (renderer/renderer.pri) -include (io/io.pri) -include (textures/textures.pri) -include (graphicshelpers/graphicshelpers.pri) -include (managers/managers.pri) - -!integrity: include (debug/debug.pri) - -INCLUDEPATH += $$PWD - -# Qt3D is free of Q_FOREACH - make sure it stays that way: -DEFINES += QT_NO_FOREACH - -gcov { - QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage - QMAKE_LFLAGS += -fprofile-arcs -ftest-coverage -} - -qtConfig(qt3d-simd-avx2) { - CONFIG += simd - QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_AVX2 -} - -qtConfig(qt3d-simd-sse2):!qtConfig(qt3d-simd-avx2) { - CONFIG += simd - QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_SSE2 -} diff --git a/src/plugins/renderers/opengl/opengl.pro b/src/plugins/renderers/opengl/opengl.pro deleted file mode 100644 index f098513e8..000000000 --- a/src/plugins/renderers/opengl/opengl.pro +++ /dev/null @@ -1,13 +0,0 @@ -TARGET = openglrenderer - -# We use QT_AUTOTEST_EXPORT to test the plug-ins, which needs QT_BUILDING_QT -DEFINES += QT_BUILDING_QT - -include(opengl.pri) - -SOURCES += \ - main.cpp - -PLUGIN_TYPE = renderers -PLUGIN_CLASS_NAME = OpenGLRendererPlugin -load(qt_plugin) diff --git a/src/plugins/renderers/opengl/renderer/glshader.cpp b/src/plugins/renderers/opengl/renderer/glshader.cpp index 7dbc89571..35cfef738 100644 --- a/src/plugins/renderers/opengl/renderer/glshader.cpp +++ b/src/plugins/renderers/opengl/renderer/glshader.cpp @@ -79,6 +79,7 @@ void GLShader::setGraphicsContext(GraphicsContext *context) if (m_graphicsContext) { m_contextConnection = QObject::connect(m_graphicsContext->openGLContext(), &QOpenGLContext::aboutToBeDestroyed, + m_graphicsContext->openGLContext(), [this] { setGraphicsContext(nullptr); }); } } @@ -332,7 +333,7 @@ void GLShader::initializeUniformBlocks(const std::vector<ShaderUniformBlock> &un const std::vector<ShaderUniform>::const_iterator uniformsEnd = m_uniforms.cend(); std::vector<QString>::const_iterator uniformNamesIt = m_uniformsNames.cbegin(); - const std::vector<QString>::const_iterator uniformNamesEnd = m_attributesNames.cend(); + const std::vector<QString>::const_iterator uniformNamesEnd = m_uniformsNames.cend(); QHash<QString, ShaderUniform> activeUniformsInBlock; diff --git a/src/plugins/renderers/opengl/renderer/renderer.cpp b/src/plugins/renderers/opengl/renderer/renderer.cpp index e9a2ffe48..fa2d27486 100644 --- a/src/plugins/renderers/opengl/renderer/renderer.cpp +++ b/src/plugins/renderers/opengl/renderer/renderer.cpp @@ -90,8 +90,6 @@ QT_BEGIN_NAMESPACE -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace OpenGL { @@ -322,7 +320,7 @@ void Renderer::setNodeManagers(NodeManagers *managers) m_computableEntityFilterJob->setManager(m_nodesManager->renderNodesManager()); } -void Renderer::setServices(QServiceLocator *services) +void Renderer::setServices(Qt3DCore::QServiceLocator *services) { m_services = services; @@ -439,12 +437,12 @@ void Renderer::initialize() qCWarning(Backend) << Q_FUNC_INFO << "OpenGL context creation failed"; m_ownedContext = true; - QObject::connect(m_glContext, &QOpenGLContext::aboutToBeDestroyed, + QObject::connect(m_glContext, &QOpenGLContext::aboutToBeDestroyed, m_glContext, [this] { m_frameProfiler.reset(); }); } else { // Context is not owned by us, so we need to know if it gets destroyed m_contextConnection = QObject::connect(m_glContext, &QOpenGLContext::aboutToBeDestroyed, - [this] { releaseGraphicsResources(); }); + m_glContext, [this] { releaseGraphicsResources(); }); } qCDebug(Backend) << "Qt3D shared context:" << m_glContext->shareContext(); @@ -678,12 +676,12 @@ void Renderer::render(bool swapBuffers) // RenderQueue is complete (but that means it may be of size 0) if (!queueIsEmpty) { - QTaskLogger submissionStatsPart1(m_services->systemInformation(), - {JobTypes::FrameSubmissionPart1, 0}, - QTaskLogger::Submission); - QTaskLogger submissionStatsPart2(m_services->systemInformation(), - {JobTypes::FrameSubmissionPart2, 0}, - QTaskLogger::Submission); + Qt3DCore::QTaskLogger submissionStatsPart1(m_services->systemInformation(), + { JobTypes::FrameSubmissionPart1, 0 }, + Qt3DCore::QTaskLogger::Submission); + Qt3DCore::QTaskLogger submissionStatsPart2(m_services->systemInformation(), + { JobTypes::FrameSubmissionPart2, 0 }, + Qt3DCore::QTaskLogger::Submission); { // Scoped to destroy surfaceLock QSurface *surface = nullptr; for (const RenderView *rv: renderViews) { @@ -979,10 +977,10 @@ void Renderer::lookForDirtyTextures() const std::vector<HTexture> &activeTextureHandles = textureManager->activeHandles(); for (const HTexture &handle: activeTextureHandles) { Texture *texture = textureManager->data(handle); - const QNodeIdVector imageIds = texture->textureImageIds(); + const Qt3DCore::QNodeIdVector imageIds = texture->textureImageIds(); // Does the texture reference any of the dirty texture images? - for (const QNodeId &imageId: imageIds) { + for (const Qt3DCore::QNodeId &imageId : imageIds) { if (dirtyImageIds.contains(imageId)) { texture->addDirtyFlag(Texture::DirtyImageGenerators); break; @@ -1010,7 +1008,7 @@ void Renderer::reloadDirtyShaders() // If api of the renderer matches the one from the technique if (technique->isCompatibleWithRenderer()) { const auto passIds = technique->renderPasses(); - for (const QNodeId &passId : passIds) { + for (const Qt3DCore::QNodeId &passId : passIds) { RenderPass *renderPass = m_nodesManager->renderPassManager()->lookupResource(passId); HShader shaderHandle = m_nodesManager->shaderManager()->lookupHandle(renderPass->shaderProgram()); Shader *shader = m_nodesManager->shaderManager()->data(shaderHandle); @@ -1073,7 +1071,7 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager) // the time needed to destroy the GLShader assoicated with it. if (!frontend) continue; - QShaderProgramPrivate *dFrontend = static_cast<decltype(dFrontend)>(QNodePrivate::get(frontend)); + QShaderProgramPrivate *dFrontend = static_cast<decltype(dFrontend)>(Qt3DCore::QNodePrivate::get(frontend)); s->unsetRequiresFrontendSync(); dFrontend->setStatus(s->status()); dFrontend->setLog(s->log()); @@ -1084,7 +1082,7 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager) const std::vector<ShaderBuilderUpdate> shaderBuilderUpdates = Qt3DCore::moveAndClear(m_shaderBuilderUpdates); for (const ShaderBuilderUpdate &update : shaderBuilderUpdates) { QShaderProgramBuilder *builder = static_cast<decltype(builder)>(manager->lookupNode(update.builderId)); - QShaderProgramBuilderPrivate *dBuilder = static_cast<decltype(dBuilder)>(QNodePrivate::get(builder)); + QShaderProgramBuilderPrivate *dBuilder = static_cast<decltype(dBuilder)>(Qt3DCore::QNodePrivate::get(builder)); dBuilder->setShaderCode(update.shaderCode, update.shaderType); } } @@ -1116,7 +1114,7 @@ void Renderer::sendTextureChangesToFrontend(Qt3DCore::QAspectManager *manager) texture->setFormat(properties.format); texture->blockNotifications(blocked); - QAbstractTexturePrivate *dTexture = static_cast<QAbstractTexturePrivate *>(QNodePrivate::get(texture)); + QAbstractTexturePrivate *dTexture = static_cast<QAbstractTexturePrivate *>(Qt3DCore::QNodePrivate::get(texture)); dTexture->setStatus(properties.status); dTexture->setHandleType(pair.first.handleType); @@ -1135,7 +1133,7 @@ void Renderer::sendSetFenceHandlesToFrontend(Qt3DCore::QAspectManager *manager) if (fgNode != nullptr) { // Node could have been deleted before we got a chance to notify it Q_ASSERT(fgNode->nodeType() == FrameGraphNode::SetFence); QSetFence *frontend = static_cast<decltype(frontend)>(manager->lookupNode(fgNode->peerId())); - QSetFencePrivate *dFrontend = static_cast<decltype(dFrontend)>(QNodePrivate::get(frontend)); + QSetFencePrivate *dFrontend = static_cast<decltype(dFrontend)>(Qt3DCore::QNodePrivate::get(frontend)); dFrontend->setHandleType(QSetFence::OpenGLFenceId); dFrontend->setHandle(QVariant::fromValue(pair.second)); } @@ -1267,7 +1265,7 @@ void Renderer::updateGLResources() // We want to upload textures data at this point as the SubmissionThread and // AspectThread are locked ensuring no races between Texture/TextureImage and // GLTexture - QNodeIdVector updatedTexturesForFrame; + Qt3DCore::QNodeIdVector updatedTexturesForFrame; if (m_submissionContext != nullptr) { GLTextureManager *glTextureManager = m_glResourceManagers->glTextureManager(); const std::vector<HGLTexture> &glTextureHandles = glTextureManager->activeHandles(); @@ -1281,7 +1279,7 @@ void Renderer::updateGLResources() // GLTexture creation provides us width/height/format ... information // for textures which had not initially specified these information (TargetAutomatic...) // Gather these information and store them to be distributed by a change next frame - const QNodeIdVector referenceTextureIds = { glTextureManager->texNodeIdForGLTexture.value(glTexture) }; + const Qt3DCore::QNodeIdVector referenceTextureIds = { glTextureManager->texNodeIdForGLTexture.value(glTexture) }; // Store properties and referenceTextureIds if (info.wasUpdated) { Texture::TextureUpdateInfo updateInfo; @@ -1307,7 +1305,7 @@ void Renderer::updateGLResources() // Remove destroyed FBOs { - const QNodeIdVector destroyedRenderTargetIds = m_nodesManager->renderTargetManager()->takeRenderTargetIdsToCleanup(); + const Qt3DCore::QNodeIdVector destroyedRenderTargetIds = m_nodesManager->renderTargetManager()->takeRenderTargetIdsToCleanup(); for (const Qt3DCore::QNodeId &renderTargetId : destroyedRenderTargetIds) m_submissionContext->releaseRenderTarget(renderTargetId); } @@ -1349,11 +1347,11 @@ void Renderer::updateTexture(Texture *texture) // Will make the texture requestUpload if (dirtyFlags.testFlag(Texture::DirtyImageGenerators)) { - const QNodeIdVector textureImageIds = texture->textureImageIds(); + const Qt3DCore::QNodeIdVector textureImageIds = texture->textureImageIds(); std::vector<GLTexture::Image> images; images.reserve(textureImageIds.size()); // TODO: Move this into GLTexture directly - for (const QNodeId &textureImageId : textureImageIds) { + for (const Qt3DCore::QNodeId &textureImageId : textureImageIds) { const TextureImage *img = m_nodesManager->textureImageManager()->lookupResource(textureImageId); if (img == nullptr) { qWarning() << Q_FUNC_INFO << "invalid TextureImage handle"; @@ -1609,7 +1607,7 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const std::vector Render::RenderCapture *renderCapture = static_cast<Render::RenderCapture*>(m_nodesManager->frameGraphManager()->lookupNode(renderView->renderCaptureNodeId())); renderCapture->addRenderCapture(request.captureId, image); - const QNodeId renderCaptureId = renderView->renderCaptureNodeId(); + const Qt3DCore::QNodeId renderCaptureId = renderView->renderCaptureNodeId(); QMutexLocker lock(&m_pendingRenderCaptureSendRequestsMutex); if (!Qt3DCore::contains(m_pendingRenderCaptureSendRequests, renderCaptureId)) m_pendingRenderCaptureSendRequests.push_back(renderView->renderCaptureNodeId()); @@ -1621,8 +1619,8 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const std::vector // Perform BlitFramebuffer operations if (renderView->hasBlitFramebufferInfo()) { const auto &blitFramebufferInfo = renderView->blitFrameBufferInfo(); - const QNodeId inputTargetId = blitFramebufferInfo.sourceRenderTargetId; - const QNodeId outputTargetId = blitFramebufferInfo.destinationRenderTargetId; + const Qt3DCore::QNodeId inputTargetId = blitFramebufferInfo.sourceRenderTargetId; + const Qt3DCore::QNodeId outputTargetId = blitFramebufferInfo.destinationRenderTargetId; const QRect inputRect = blitFramebufferInfo.sourceRect; const QRect outputRect = blitFramebufferInfo.destinationRect; const QRenderTargetOutput::AttachmentPoint inputAttachmentPoint = blitFramebufferInfo.sourceAttachmentPoint; @@ -1761,7 +1759,7 @@ bool Renderer::processKeyEvent(QObject *object, QKeyEvent *event) } // Jobs we may have to run even if no rendering will happen -std::vector<QAspectJobPtr> Renderer::preRenderingJobs() +std::vector<Qt3DCore::QAspectJobPtr> Renderer::preRenderingJobs() { if (m_sendBufferCaptureJob->hasRequests()) return {m_sendBufferCaptureJob}; @@ -1774,10 +1772,10 @@ std::vector<QAspectJobPtr> Renderer::preRenderingJobs() // for the rendering of the scene std::vector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs() { - std::vector<QAspectJobPtr> renderBinJobs; + std::vector<Qt3DCore::QAspectJobPtr> renderBinJobs; // Remove previous dependencies - m_cleanupJob->removeDependency(QWeakPointer<QAspectJob>()); + m_cleanupJob->removeDependency(QWeakPointer<Qt3DCore::QAspectJob>()); const bool dirtyParametersForCurrentFrame = m_dirtyBits.marked & AbstractRenderer::ParameterDirty; const BackendNodeDirtySet dirtyBitsForFrame = m_dirtyBits.marked | m_dirtyBits.remaining; @@ -1848,7 +1846,7 @@ std::vector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs() m_updatedDisableSubtreeEnablers.push_back(node->peerId()); } - int idealThreadCount = QAspectJobManager::idealThreadCount(); + int idealThreadCount = Qt3DCore::QAspectJobManager::idealThreadCount(); const size_t fgBranchCount = m_frameGraphLeaves.size(); if (fgBranchCount > 1) { @@ -1903,7 +1901,7 @@ std::vector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs() return renderBinJobs; } -QAbstractFrameAdvanceService *Renderer::frameAdvanceService() const +Qt3DCore::QAbstractFrameAdvanceService *Renderer::frameAdvanceService() const { return static_cast<Qt3DCore::QAbstractFrameAdvanceService *>(m_vsyncFrameAdvanceService.data()); } @@ -2139,7 +2137,7 @@ bool Renderer::updateVAOWithAttributes(Geometry *geometry, m_dirtyAttributes.reserve(m_dirtyAttributes.size() + geometry->attributes().size()); const auto attributeIds = geometry->attributes(); - for (QNodeId attributeId : attributeIds) { + for (Qt3DCore::QNodeId attributeId : attributeIds) { // TO DO: Improvement we could store handles and use the non locking policy on the attributeManager Attribute *attribute = m_nodesManager->attributeManager()->lookupResource(attributeId); @@ -2155,7 +2153,7 @@ bool Renderer::updateVAOWithAttributes(Geometry *geometry, // Index Attribute bool attributeWasDirty = false; - if (attribute->attributeType() == QAttribute::IndexAttribute) { + if (attribute->attributeType() == Qt3DCore::QAttribute::IndexAttribute) { if ((attributeWasDirty = attribute->isDirty()) == true || forceUpdate) m_submissionContext->specifyIndices(buffer); // Vertex Attribute @@ -2196,16 +2194,14 @@ bool Renderer::requiresVAOAttributeUpdate(Geometry *geometry, { const auto attributeIds = geometry->attributes(); - for (QNodeId attributeId : attributeIds) { + for (Qt3DCore::QNodeId attributeId : attributeIds) { // TO DO: Improvement we could store handles and use the non locking policy on the attributeManager Attribute *attribute = m_nodesManager->attributeManager()->lookupResource(attributeId); if (attribute == nullptr) continue; - if ((attribute->attributeType() == QAttribute::IndexAttribute && attribute->isDirty()) || - (Qt3DCore::contains(command->m_activeAttributes, attribute->nameId()) && - attribute->isDirty())) + if ((attribute->attributeType() == Qt3DCore::QAttribute::IndexAttribute && attribute->isDirty()) || (Qt3DCore::contains(command->m_activeAttributes, attribute->nameId()) && attribute->isDirty())) return true; } return false; diff --git a/src/plugins/renderers/opengl/renderer/renderer.pri b/src/plugins/renderers/opengl/renderer/renderer.pri deleted file mode 100644 index 5d0296523..000000000 --- a/src/plugins/renderers/opengl/renderer/renderer.pri +++ /dev/null @@ -1,29 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/gllights.cpp \ - $$PWD/openglvertexarrayobject.cpp \ - $$PWD/rendercommand.cpp \ - $$PWD/renderer.cpp \ - $$PWD/renderview.cpp \ - $$PWD/renderviewbuilder.cpp \ - $$PWD/shaderparameterpack.cpp \ - $$PWD/glshader.cpp \ - $$PWD/logging.cpp \ - $$PWD/commandexecuter.cpp - -HEADERS += \ - $$PWD/gllights_p.h \ - $$PWD/openglvertexarrayobject_p.h \ - $$PWD/rendercommand_p.h \ - $$PWD/renderer_p.h \ - $$PWD/renderview_p.h \ - $$PWD/renderviewbuilder_p.h \ - $$PWD/shaderparameterpack_p.h \ - $$PWD/shadervariables_p.h \ - $$PWD/glshader_p.h \ - $$PWD/glfence_p.h \ - $$PWD/logging_p.h \ - $$PWD/commandexecuter_p.h \ - $$PWD/frameprofiler_p.h - diff --git a/src/plugins/renderers/opengl/renderer/renderview.cpp b/src/plugins/renderers/opengl/renderer/renderview.cpp index 324e63af9..8cd22eaa2 100644 --- a/src/plugins/renderers/opengl/renderer/renderview.cpp +++ b/src/plugins/renderers/opengl/renderer/renderview.cpp @@ -1077,8 +1077,16 @@ void RenderView::updateRenderCommand(const EntityRenderCommandDataSubView &subVi void RenderView::updateMatrices() { if (m_renderCameraNode && m_renderCameraLens && m_renderCameraLens->isEnabled()) { - const Matrix4x4 cameraWorld = *(m_renderCameraNode->worldTransform()); - setViewMatrix(m_renderCameraLens->viewMatrix(cameraWorld)); + auto transform = m_renderCameraNode->renderComponent<Transform>(); + if (m_renderCameraNode->isParentLessTransform() && transform && transform->hasViewMatrix()) { + // optimization: if the entity is a QCamera and it doesn't have a parent with a transform component, + // then we use the frontend version of the viewMatrix to avoid extra calculations that may introduce + // rounding errors + setViewMatrix(transform->viewMatrix()); + } else { + const Matrix4x4 cameraWorld = *(m_renderCameraNode->worldTransform()); + setViewMatrix(m_renderCameraLens->viewMatrix(cameraWorld)); + } setViewProjectionMatrix(m_renderCameraLens->projection() * viewMatrix()); //To get the eyePosition of the camera, we need to use the inverse of the diff --git a/src/plugins/renderers/opengl/textures/gltexture.cpp b/src/plugins/renderers/opengl/textures/gltexture.cpp index f6bd38fc3..7f358b0e3 100644 --- a/src/plugins/renderers/opengl/textures/gltexture.cpp +++ b/src/plugins/renderers/opengl/textures/gltexture.cpp @@ -9,9 +9,7 @@ #include <private/qopengltexturehelper_p.h> #include <QDebug> #include <QOpenGLFunctions> -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) #include <QtOpenGL/QOpenGLVersionFunctionsFactory> -#endif #include <QOpenGLTexture> #include <QOpenGLPixelTransferOptions> #include <Qt3DRender/qtexture.h> @@ -30,8 +28,6 @@ QT_BEGIN_NAMESPACE -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace OpenGL { @@ -656,11 +652,7 @@ void GLTexture::introspectPropertiesFromSharedTextureId() if (ctxGLVersion.first > 4 || (ctxGLVersion.first == 4 && ctxGLVersion.second >= 5)) { // Only for GL 4.5+ #ifdef GL_TEXTURE_TARGET -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QOpenGLFunctions_4_5_Core *gl5 = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_4_5_Core>(); -#else - QOpenGLFunctions_4_5_Core *gl5 = ctx->versionFunctions<QOpenGLFunctions_4_5_Core>(); -#endif if (gl5 != nullptr) gl5->glGetTextureParameteriv(m_sharedTextureId, GL_TEXTURE_TARGET, reinterpret_cast<int *>(&m_properties.target)); #endif @@ -732,11 +724,7 @@ void GLTexture::introspectPropertiesFromSharedTextureId() #if !QT_CONFIG(opengles2) // Try to retrieve dimensions (not available on ES 2.0) if (!ctx->isOpenGLES()) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QOpenGLFunctions_3_1 *gl3 = QOpenGLVersionFunctionsFactory::get<QOpenGLFunctions_3_1>(); -#else - QOpenGLFunctions_3_1 *gl3 = ctx->versionFunctions<QOpenGLFunctions_3_1>(); -#endif if (!gl3) { qWarning() << "Failed to retrieve shared texture dimensions"; return; diff --git a/src/plugins/renderers/opengl/textures/textures.pri b/src/plugins/renderers/opengl/textures/textures.pri deleted file mode 100644 index e17abfbb3..000000000 --- a/src/plugins/renderers/opengl/textures/textures.pri +++ /dev/null @@ -1,9 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/gltexture.cpp \ - $$PWD/renderbuffer.cpp - -HEADERS += \ - $$PWD/gltexture_p.h \ - $$PWD/renderbuffer_p.h diff --git a/src/plugins/renderers/renderers.pro b/src/plugins/renderers/renderers.pro deleted file mode 100644 index f5399ce84..000000000 --- a/src/plugins/renderers/renderers.pro +++ /dev/null @@ -1,13 +0,0 @@ -TEMPLATE = subdirs - -# OpenGL renderer -include($$OUT_PWD/../../render/qt3drender-config.pri) -QT_FOR_CONFIG += 3drender-private - -#SUBDIRS += dummy - -qtConfig(qt3d-opengl-renderer): SUBDIRS += opengl - -qtConfig(qt3d-rhi-renderer): { - qtHaveModule(shadertools): SUBDIRS += rhi -} diff --git a/src/plugins/renderers/rhi/CMakeLists.txt b/src/plugins/renderers/rhi/CMakeLists.txt index 4e7febe57..9e0699a8d 100644 --- a/src/plugins/renderers/rhi/CMakeLists.txt +++ b/src/plugins/renderers/rhi/CMakeLists.txt @@ -56,7 +56,6 @@ if(QT_FEATURE_private_tests) target_compile_definitions(RhiRendererLib PRIVATE BUILD_QT3D_MODULE QT_BUILDING_QT - QT_NO_FOREACH ) endif() @@ -95,6 +94,9 @@ qt_internal_add_plugin(RhiRendererPlugin Qt::ShaderToolsPrivate ) +# QTransform conflicts +set_target_properties(RhiRendererPlugin PROPERTIES UNITY_BUILD OFF) + #### Keys ignored in scope 1:.:.:rhi.pro:<TRUE>: # DISTFILES = "rhirenderer.json" diff --git a/src/plugins/renderers/rhi/graphicshelpers/graphicshelpers.pri b/src/plugins/renderers/rhi/graphicshelpers/graphicshelpers.pri deleted file mode 100644 index e156d3ce5..000000000 --- a/src/plugins/renderers/rhi/graphicshelpers/graphicshelpers.pri +++ /dev/null @@ -1,9 +0,0 @@ -#DEFINES += QT3D_RENDER_ASPECT_OPENGL_DEBUG - -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/submissioncontext_p.h - -SOURCES += \ - $$PWD/submissioncontext.cpp diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp index 32fd7fcf2..f0dcb044f 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp +++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp @@ -41,46 +41,17 @@ #include <private/qdebug_p.h> #include <QSurface> #include <QWindow> -#include <QtShaderTools/private/qshaderbaker_p.h> +#include <rhi/qrhi.h> +#include <rhi/qshaderbaker.h> -#ifdef Q_OS_WIN -#include <QtGui/private/qrhid3d11_p.h> -#endif - -#if defined(Q_OS_MACOS) || defined(Q_OS_IOS) -#include <QtGui/private/qrhimetal_p.h> -#endif - -#ifndef QT_NO_OPENGL -#include <QtGui/private/qrhigles2_p.h> -#endif - -#if QT_CONFIG(vulkan) -#include <QtGui/private/qrhivulkan_p.h> -#endif #include <bitset> QT_BEGIN_NAMESPACE -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace Rhi { -static QHash<unsigned int, SubmissionContext *> static_contexts; - -unsigned int nextFreeContextId() noexcept -{ - for (unsigned int i = 0; i < 0xffff; ++i) { - if (!static_contexts.contains(i)) - return i; - } - - qFatal("Couldn't find free context ID"); - return 0; -} - namespace { //RHIBuffer::Type attributeTypeToGLBufferType(QAttribute::AttributeType type) noexcept @@ -442,6 +413,13 @@ void applyStateHelper(const StencilMask *state, QRhiGraphicsPipeline *gp) noexce gp->setStencilReadMask(std::get<1>(values)); } +void applyStateHelper(const LineWidth *state, QRhiGraphicsPipeline *gp) noexcept +{ + const auto values = state->values(); + gp->setLineWidth(std::get<0>(values)); + // no GL_LINE_SMOOTH equivalent on RHI +} + static QShader::Stage rhiShaderStage(QShaderProgram::ShaderType type) noexcept { switch (type) { @@ -468,7 +446,6 @@ SubmissionContext::SubmissionContext() : m_initialized(false), m_ownsRhiCtx(false), m_drivenExternally(false), - m_id(nextFreeContextId()), m_material(nullptr), m_renderer(nullptr), m_rhi(nullptr), @@ -481,7 +458,6 @@ SubmissionContext::SubmissionContext() m_fallbackSurface(nullptr) #endif { - static_contexts[m_id] = this; m_contextInfo.m_api = QGraphicsApiFilter::RHI; // We set those version numbers because QShaderGenerator wants major > 0 @@ -492,9 +468,6 @@ SubmissionContext::SubmissionContext() SubmissionContext::~SubmissionContext() { releaseResources(); - - Q_ASSERT(static_contexts[m_id] == this); - static_contexts.remove(m_id); } void SubmissionContext::initialize() @@ -1420,26 +1393,45 @@ void preprocessRHIShader(std::vector<QByteArray> &shaderCodes) } } -int glslVersionForFormat(const QSurfaceFormat &format) noexcept +QShaderVersion glslVersionForFormat(const QSurfaceFormat &format) noexcept { const int major = format.majorVersion(); const int minor = format.minorVersion(); - - static const QHash<std::pair<int, int>, int> glVersionToGLSLVersion = { - { { 4, 6 }, 460 }, { { 4, 5 }, 450 }, { { 4, 4 }, 440 }, { { 4, 3 }, 430 }, - { { 4, 2 }, 420 }, { { 4, 1 }, 410 }, { { 4, 0 }, 400 }, { { 3, 3 }, 330 }, - { { 3, 2 }, 150 }, { { 3, 2 }, 120 }, { { 3, 1 }, 120 }, - }; - - const auto it = glVersionToGLSLVersion.find({ major, minor }); - if (it == glVersionToGLSLVersion.end()) { - if (major < 3) { - return 120; + const auto type = format.renderableType(); + + if (type != QSurfaceFormat::OpenGLES) { + static const QHash<std::pair<int, int>, int> glVersionToGLSLVersion = { + { { 4, 6 }, 460 }, { { 4, 5 }, 450 }, { { 4, 4 }, 440 }, { { 4, 3 }, 430 }, + { { 4, 2 }, 420 }, { { 4, 1 }, 410 }, { { 4, 0 }, 400 }, { { 3, 3 }, 330 }, + { { 3, 2 }, 150 }, { { 3, 2 }, 120 }, { { 3, 1 }, 120 }, + }; + + const auto it = glVersionToGLSLVersion.find({ major, minor }); + if (it == glVersionToGLSLVersion.end()) { + if (major < 3) { + return 120; + } else { + return major * 100 + minor * 10; + } } else { - return major * 100 + minor * 10; + return *it; + } + } + else { + static const QHash<std::pair<int, int>, int> glVersionToGLSLVersion = { + { { 3, 2 }, 320 }, { { 3, 1 }, 310 }, { { 3, 0 }, 300 }, + }; + + const auto it = glVersionToGLSLVersion.find({ major, minor }); + if (it == glVersionToGLSLVersion.end()) { + if (major < 3) { + return {100, QShaderVersion::GlslEs}; + } else { + return {major * 100 + minor * 10, QShaderVersion::GlslEs}; + } + } else { + return {*it, QShaderVersion::GlslEs}; } - } else { - return *it; } } } @@ -1525,12 +1517,14 @@ void SubmissionContext::loadShader(Shader *shaderNode, ShaderManager *shaderMana const std::vector<Qt3DCore::QNodeId> &sharedShaderIds = rhiShaderManager->shaderIdsForProgram(rhiShader); if (sharedShaderIds.size() == 1) { - // Shader in the cache hasn't been loaded yet - // We want a copy of the QByteArray as preprocessRHIShader will - // modify them - std::vector<QByteArray> shaderCodes = shaderNode->shaderCode(); - preprocessRHIShader(shaderCodes); - rhiShader->setShaderCode(shaderCodes); + { + // Shader in the cache hasn't been loaded yet + // We want a copy of the QByteArray as preprocessRHIShader will + // modify them + std::vector<QByteArray> shaderCodes = shaderNode->shaderCode(); + preprocessRHIShader(shaderCodes); + rhiShader->setShaderCode(std::move(shaderCodes)); + } const ShaderCreationInfo loadResult = createShaderProgram(rhiShader); shaderNode->setStatus(loadResult.linkSucceeded ? QShaderProgram::Ready diff --git a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h index 350ed00b6..bb639ccfc 100644 --- a/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h +++ b/src/plugins/renderers/rhi/graphicshelpers/submissioncontext_p.h @@ -27,8 +27,8 @@ #include <shadervariables_p.h> #include <rhihandle_types_p.h> #include <QSurface> -#include <QtGui/private/qrhi_p.h> #include <QOffscreenSurface> +#include <rhi/qrhi.h> QT_BEGIN_NAMESPACE @@ -174,7 +174,6 @@ private: bool m_initialized; bool m_ownsRhiCtx; bool m_drivenExternally; - const unsigned int m_id; QHash<Qt3DCore::QNodeId, HRHIBuffer> m_renderBufferHash; diff --git a/src/plugins/renderers/rhi/io/io.pri b/src/plugins/renderers/rhi/io/io.pri deleted file mode 100644 index bac06ba95..000000000 --- a/src/plugins/renderers/rhi/io/io.pri +++ /dev/null @@ -1,8 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/rhibuffer.cpp - -HEADERS += \ - $$PWD/rhibuffer_p.h - diff --git a/src/plugins/renderers/rhi/io/rhibuffer.cpp b/src/plugins/renderers/rhi/io/rhibuffer.cpp index 868c49cfe..9607e8c32 100644 --- a/src/plugins/renderers/rhi/io/rhibuffer.cpp +++ b/src/plugins/renderers/rhi/io/rhibuffer.cpp @@ -3,7 +3,8 @@ #include "rhibuffer_p.h" #include <submissioncontext_p.h> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> + QT_BEGIN_NAMESPACE namespace Qt3DRender { diff --git a/src/plugins/renderers/rhi/managers/managers.pri b/src/plugins/renderers/rhi/managers/managers.pri deleted file mode 100644 index de3f29b30..000000000 --- a/src/plugins/renderers/rhi/managers/managers.pri +++ /dev/null @@ -1,8 +0,0 @@ -INCLUDEPATH += $$PWD - -HEADERS += \ - $$PWD/rhihandle_types_p.h \ - $$PWD/rhiresourcemanagers_p.h - -SOURCES += \ - $$PWD/rhiresourcemanagers.cpp diff --git a/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp b/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp index 598c32ef9..8cffaac4f 100644 --- a/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp +++ b/src/plugins/renderers/rhi/renderer/pipelineuboset.cpp @@ -10,7 +10,7 @@ #include <rhigraphicspipeline_p.h> #include <rhiresourcemanagers_p.h> #include <submissioncontext_p.h> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> #include <Qt3DRender/private/nodemanagers_p.h> #include <Qt3DRender/private/buffermanager_p.h> #include <Qt3DRender/private/stringtoint_p.h> @@ -243,7 +243,7 @@ std::vector<QRhiShaderResourceBinding> PipelineUBOSet::resourceBindings(const Re { RHITextureManager *textureManager = m_resourceManagers->rhiTextureManager(); RHIShader *shader = command.m_rhiShader; - const QRhiShaderResourceBinding::StageFlags stages = QRhiShaderResourceBinding::VertexStage|QRhiShaderResourceBinding::FragmentStage; + const QRhiShaderResourceBinding::StageFlags stages = QRhiShaderResourceBinding::ComputeStage|QRhiShaderResourceBinding::VertexStage|QRhiShaderResourceBinding::FragmentStage; std::vector<QRhiShaderResourceBinding> bindings = { QRhiShaderResourceBinding::uniformBuffer(0, stages, m_rvUBO.buffer->rhiBuffer()), }; @@ -323,9 +323,10 @@ std::vector<QRhiShaderResourceBinding> PipelineUBOSet::resourceBindings(const Re for (const BlockToSSBO &ssbo : command.m_parameterPack.shaderStorageBuffers()) { RHIBuffer *buffer = m_resourceManagers->rhiBufferManager()->lookupResource(ssbo.m_bufferID); if (buffer) { + Q_ASSERT(stages & QRhiShaderResourceBinding::ComputeStage); bindings.push_back(QRhiShaderResourceBinding::bufferLoadStore( ssbo.m_bindingIndex, - stages|QRhiShaderResourceBinding::ComputeStage, + stages, buffer->rhiBuffer())); } } @@ -597,7 +598,7 @@ void PipelineUBOSet::uploadUBOsForCommand(const RenderCommand &command, uploadUniform(uniforms, ubo, arrayStructMember, distanceToCommand, - i * blockVariable.size / arr0); + int(i * blockVariable.size / arr0)); } } } else { // Array of scalars diff --git a/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h b/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h index aa4ed00d2..55c3bbb60 100644 --- a/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h +++ b/src/plugins/renderers/rhi/renderer/pipelineuboset_p.h @@ -16,7 +16,7 @@ // #include <rhihandle_types_p.h> -#include <private/qrhi_p.h> +#include <rhi/qrhi.h> #include <shadervariables_p.h> #include <rhishader_p.h> diff --git a/src/plugins/renderers/rhi/renderer/rendercommand_p.h b/src/plugins/renderers/rhi/renderer/rendercommand_p.h index dc5d97f93..392650385 100644 --- a/src/plugins/renderers/rhi/renderer/rendercommand_p.h +++ b/src/plugins/renderers/rhi/renderer/rendercommand_p.h @@ -26,7 +26,7 @@ #include <QOpenGLShaderProgram> #include <QOpenGLTexture> #include <QMatrix4x4> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> #include <Qt3DCore/qattribute.h> #include <variant> @@ -57,8 +57,9 @@ struct CommandUBO float mvp[16]; float inverseModelViewProjectionMatrix[16]; float modelViewNormalMatrix[12]; + float skinningPalette[100 * 16]; }; -static_assert(sizeof(CommandUBO) == 6 * (16 * sizeof(float)) + 2 * (12 * sizeof(float)), +static_assert(sizeof(CommandUBO) == 6 * (16 * sizeof(float)) + 2 * (12 * sizeof(float)) + 100 * (16 * sizeof(float)), "UBO doesn't match std140"); struct Q_AUTOTEST_EXPORT AttributeInfo diff --git a/src/plugins/renderers/rhi/renderer/renderer.cpp b/src/plugins/renderers/rhi/renderer/renderer.cpp index 45485a6c7..4a25bb464 100644 --- a/src/plugins/renderers/rhi/renderer/renderer.cpp +++ b/src/plugins/renderers/rhi/renderer/renderer.cpp @@ -93,8 +93,6 @@ QT_BEGIN_NAMESPACE -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace Rhi { @@ -336,7 +334,7 @@ void Renderer::setNodeManagers(NodeManagers *managers) m_computableEntityFilterJob->setManager(m_nodesManager->renderNodesManager()); } -void Renderer::setServices(QServiceLocator *services) +void Renderer::setServices(Qt3DCore::QServiceLocator *services) { m_services = services; @@ -613,12 +611,12 @@ void Renderer::render(bool swapBuffers) // RenderQueue is complete (but that means it may be of size 0) if (!queueIsEmpty) { - QTaskLogger submissionStatsPart1(m_services->systemInformation(), - { JobTypes::FrameSubmissionPart1, 0 }, - QTaskLogger::Submission); - QTaskLogger submissionStatsPart2(m_services->systemInformation(), - { JobTypes::FrameSubmissionPart2, 0 }, - QTaskLogger::Submission); + Qt3DCore::QTaskLogger submissionStatsPart1(m_services->systemInformation(), + { JobTypes::FrameSubmissionPart1, 0 }, + Qt3DCore::QTaskLogger::Submission); + Qt3DCore::QTaskLogger submissionStatsPart2(m_services->systemInformation(), + { JobTypes::FrameSubmissionPart2, 0 }, + Qt3DCore::QTaskLogger::Submission); std::vector<RHIPassInfo> rhiPassesInfo; @@ -759,8 +757,8 @@ QSurfaceFormat Renderer::format() namespace { std::optional<QRhiVertexInputAttribute::Format> rhiAttributeType(Attribute *attr) { switch (attr->vertexBaseType()) { - case QAttribute::Byte: - case QAttribute::UnsignedByte: { + case Qt3DCore::QAttribute::Byte: + case Qt3DCore::QAttribute::UnsignedByte: { if (attr->vertexSize() == 1) return QRhiVertexInputAttribute::UNormByte; if (attr->vertexSize() == 2) @@ -769,7 +767,18 @@ std::optional<QRhiVertexInputAttribute::Format> rhiAttributeType(Attribute *attr return QRhiVertexInputAttribute::UNormByte4; break; } - case QAttribute::UnsignedInt: { + case Qt3DCore::QAttribute::Int: { + if (attr->vertexSize() == 1) + return QRhiVertexInputAttribute::SInt; + if (attr->vertexSize() == 2) + return QRhiVertexInputAttribute::SInt2; + if (attr->vertexSize() == 3) + return QRhiVertexInputAttribute::SInt3; + if (attr->vertexSize() == 4) + return QRhiVertexInputAttribute::SInt4; + break; + } + case Qt3DCore::QAttribute::UnsignedInt: { if (attr->vertexSize() == 1) return QRhiVertexInputAttribute::UInt; if (attr->vertexSize() == 2) @@ -780,7 +789,18 @@ std::optional<QRhiVertexInputAttribute::Format> rhiAttributeType(Attribute *attr return QRhiVertexInputAttribute::UInt4; break; } - case QAttribute::Float: { + case Qt3DCore::QAttribute::HalfFloat: { + if (attr->vertexSize() == 1) + return QRhiVertexInputAttribute::Half; + if (attr->vertexSize() == 2) + return QRhiVertexInputAttribute::Half2; + if (attr->vertexSize() == 3) + return QRhiVertexInputAttribute::Half3; + if (attr->vertexSize() >= 4) + return QRhiVertexInputAttribute::Half4; + break; + } + case Qt3DCore::QAttribute::Float: { if (attr->vertexSize() == 1) return QRhiVertexInputAttribute::Float; if (attr->vertexSize() == 2) @@ -1143,9 +1163,17 @@ void Renderer::createRenderTarget(RenderTarget *target) } }; + RHIRenderTarget::BackBuffer backBuffer = RHIRenderTarget::BackBuffer::None; + // Look up attachments to populate the RT description // Attachments are sorted by attachment point (Color0 is first) for (const Attachment &attachment : pack.attachments()) { + + if (attachment.m_point == QRenderTargetOutput::Left || attachment.m_point == QRenderTargetOutput::Right) { + backBuffer = attachment.m_point == QRenderTargetOutput::Left ? RHIRenderTarget::BackBuffer::Left : RHIRenderTarget::BackBuffer::Right; + break; + } + RHITexture *tex = texman->lookupResource(attachment.m_textureUuid); if (tex && tex->getRhiTexture()) { auto rhiTex = tex->getRhiTexture(); @@ -1185,6 +1213,12 @@ void Renderer::createRenderTarget(RenderTarget *target) } } + rhiTarget->backBuffer = backBuffer; + // If we are targeting one of the back buffers directly, don't create an offscreen RT + if (backBuffer != RHIRenderTarget::BackBuffer::None) + return; + + // Otherwise, create QRhiRenderBuffer and associated resources if (targetSize.width() <= 0 || targetSize.height() <= 0) { cleanAllocatedResources(); return; @@ -1234,6 +1268,12 @@ bool Renderer::setupRenderTarget(RenderView *rv, const auto &managers = *nodeManagers(); auto &renderTargetManager = *managers.renderTargetManager(); + auto useSwapchainForPipeline = [&]() { + Q_ASSERT(swapchain); + rhiPipeline->setRenderPassDescriptor(swapchain->renderPassDescriptor()); + rhiPipeline->setSampleCount(swapchain->sampleCount()); + }; + auto *renderTarget = renderTargetManager.lookupResource(rv->renderTargetId()); if (renderTarget) { // Render to texture @@ -1241,14 +1281,25 @@ bool Renderer::setupRenderTarget(RenderView *rv, RHIRenderTargetManager *rhiRenderTargetManager = m_RHIResourceManagers->rhiRenderTargetManager(); RHIRenderTarget *rhiTarget = rhiRenderTargetManager->lookupResource(renderTargetId); - if (!rhiTarget || !rhiTarget->renderTarget) { + if (!rhiTarget) { qWarning(Backend) << "Invalid RenderTarget " << renderTargetId << " for Pipeline"; return false; } - rhiPipeline->setRenderPassDescriptor(rhiTarget->renderPassDescriptor); - rhiPipeline->setSampleCount(rhiTarget->renderTarget->sampleCount()); + // The RenderTarget we reference might actually be referencing a swapchain back buffer + if (rhiTarget->backBuffer != RHIRenderTarget::BackBuffer::None) { + // Render to the default framebuffer on our swapchain + useSwapchainForPipeline(); + } else { + if (!rhiTarget->renderTarget) { + qWarning(Backend) << "Invalid RenderTarget " << renderTargetId << " for Pipeline"; + return false; + } + rhiPipeline->setRenderPassDescriptor(rhiTarget->renderPassDescriptor); + rhiPipeline->setSampleCount(rhiTarget->renderTarget->sampleCount()); + } return true; + } else if (m_submissionContext->defaultRenderTarget()) { // Use default RenderTarget if set Default FBO set by Scene3D QRhiRenderTarget *defaultTarget = m_submissionContext->defaultRenderTarget();; @@ -1256,10 +1307,8 @@ bool Renderer::setupRenderTarget(RenderView *rv, rhiPipeline->setSampleCount(defaultTarget->sampleCount()); return true; } else { - Q_ASSERT(swapchain); // Render to the default framebuffer on our swapchain - rhiPipeline->setRenderPassDescriptor(swapchain->renderPassDescriptor()); - rhiPipeline->setSampleCount(swapchain->sampleCount()); + useSwapchainForPipeline(); return true; } } @@ -1442,10 +1491,10 @@ void Renderer::lookForDirtyTextures() const std::vector<HTexture> &activeTextureHandles = textureManager->activeHandles(); for (const HTexture &handle : activeTextureHandles) { Texture *texture = textureManager->data(handle); - const QNodeIdVector imageIds = texture->textureImageIds(); + const Qt3DCore::QNodeIdVector imageIds = texture->textureImageIds(); // Does the texture reference any of the dirty texture images? - for (const QNodeId &imageId : imageIds) { + for (const Qt3DCore::QNodeId &imageId : imageIds) { if (dirtyImageIds.contains(imageId)) { texture->addDirtyFlag(Texture::DirtyImageGenerators); break; @@ -1475,7 +1524,7 @@ void Renderer::reloadDirtyShaders() // If api of the renderer matches the one from the technique if (technique->isCompatibleWithRenderer()) { const auto passIds = technique->renderPasses(); - for (const QNodeId &passId : passIds) { + for (const Qt3DCore::QNodeId &passId : passIds) { RenderPass *renderPass = m_nodesManager->renderPassManager()->lookupResource(passId); HShader shaderHandle = @@ -1536,7 +1585,7 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager) static_cast<decltype(frontend)>(manager->lookupNode(s->peerId())); if (frontend) { QShaderProgramPrivate *dFrontend = - static_cast<decltype(dFrontend)>(QNodePrivate::get(frontend)); + static_cast<decltype(dFrontend)>(Qt3DCore::QNodePrivate::get(frontend)); dFrontend->setStatus(s->status()); dFrontend->setLog(s->log()); s->unsetRequiresFrontendSync(); @@ -1552,7 +1601,7 @@ void Renderer::sendShaderChangesToFrontend(Qt3DCore::QAspectManager *manager) continue; QShaderProgramBuilderPrivate *dBuilder = - static_cast<decltype(dBuilder)>(QNodePrivate::get(builder)); + static_cast<decltype(dBuilder)>(Qt3DCore::QNodePrivate::get(builder)); dBuilder->setShaderCode(update.shaderCode, update.shaderType); } m_shaderBuilderUpdates.clear(); @@ -1588,7 +1637,7 @@ void Renderer::sendTextureChangesToFrontend(Qt3DCore::QAspectManager *manager) texture->blockNotifications(blocked); QAbstractTexturePrivate *dTexture = - static_cast<QAbstractTexturePrivate *>(QNodePrivate::get(texture)); + static_cast<QAbstractTexturePrivate *>(Qt3DCore::QNodePrivate::get(texture)); dTexture->setStatus(properties.status); dTexture->setHandleType(pair.first.handleType); dTexture->setHandle(pair.first.handle); @@ -1626,7 +1675,7 @@ bool Renderer::prepareGeometryInputBindings(const Geometry *geometry, const RHIS QHash<int, int> &attributeNameToBinding) { // shader requires no attributes - if (shader->attributes().size() == 0) + if (shader->attributes().empty()) return true; // QRhiVertexInputBinding -> specifies the stride of an attribute, @@ -1648,7 +1697,7 @@ bool Renderer::prepareGeometryInputBindings(const Geometry *geometry, const RHIS for (Qt3DCore::QNodeId attribute_id : attributesIds) { Attribute *attrib = m_nodesManager->attributeManager()->lookupResource(attribute_id); - if (attrib->attributeType() != QAttribute::VertexAttribute) + if (attrib->attributeType() != Qt3DCore::QAttribute::VertexAttribute) continue; const int location = locationForAttribute(attrib, shader); // In case the shader doesn't use the attribute, we would get no @@ -1662,20 +1711,20 @@ bool Renderer::prepareGeometryInputBindings(const Geometry *geometry, const RHIS ? QRhiVertexInputBinding::PerInstance : QRhiVertexInputBinding::PerVertex; - auto getAttributeByteSize = [] (const QAttribute::VertexBaseType type) { + auto getAttributeByteSize = [](const Qt3DCore::QAttribute::VertexBaseType type) { switch (type) { - case QAttribute::Byte: - case QAttribute::UnsignedByte: + case Qt3DCore::QAttribute::Byte: + case Qt3DCore::QAttribute::UnsignedByte: return 1; - case QAttribute::Short: - case QAttribute::UnsignedShort: - case QAttribute::HalfFloat: + case Qt3DCore::QAttribute::Short: + case Qt3DCore::QAttribute::UnsignedShort: + case Qt3DCore::QAttribute::HalfFloat: return 2; - case QAttribute::Int: - case QAttribute::UnsignedInt: - case QAttribute::Float: + case Qt3DCore::QAttribute::Int: + case Qt3DCore::QAttribute::UnsignedInt: + case Qt3DCore::QAttribute::Float: return 4; - case QAttribute::Double: + case Qt3DCore::QAttribute::Double: return 8; } return 0; @@ -1842,7 +1891,7 @@ void Renderer::updateResources() // for textures which had not initially specified these information // (TargetAutomatic...) Gather these information and store them to be distributed by // a change next frame - const QNodeIdVector referenceTextureIds = { rhiTextureManager->texNodeIdForRHITexture.value(rhiTexture) }; + const Qt3DCore::QNodeIdVector referenceTextureIds = { rhiTextureManager->texNodeIdForRHITexture.value(rhiTexture) }; // Store properties and referenceTextureIds Texture::TextureUpdateInfo updateInfo; updateInfo.properties = info.properties; @@ -1964,11 +2013,11 @@ void Renderer::updateTexture(Texture *texture) // Will make the texture requestUpload if (dirtyFlags.testFlag(Texture::DirtyImageGenerators)) { - const QNodeIdVector textureImageIds = texture->textureImageIds(); + const Qt3DCore::QNodeIdVector textureImageIds = texture->textureImageIds(); std::vector<RHITexture::Image> images; images.reserve(textureImageIds.size()); // TODO: Move this into RHITexture directly - for (const QNodeId &textureImageId : textureImageIds) { + for (const Qt3DCore::QNodeId &textureImageId : textureImageIds) { const TextureImage *img = m_nodesManager->textureImageManager()->lookupResource(textureImageId); if (img == nullptr) { @@ -2203,7 +2252,7 @@ void Renderer::jobsDone(Qt3DCore::QAspectManager *manager) } // Do we need to notify any texture about property changes? - if (m_updatedTextureProperties.size() > 0) + if (!m_updatedTextureProperties.empty()) sendTextureChangesToFrontend(manager); sendDisablesToFrontend(manager); @@ -2224,7 +2273,7 @@ bool Renderer::processKeyEvent(QObject *object, QKeyEvent *event) } // Jobs we may have to run even if no rendering will happen -std::vector<QAspectJobPtr> Renderer::preRenderingJobs() +std::vector<Qt3DCore::QAspectJobPtr> Renderer::preRenderingJobs() { if (m_sendBufferCaptureJob->hasRequests()) return { m_sendBufferCaptureJob }; @@ -2238,10 +2287,10 @@ std::vector<QAspectJobPtr> Renderer::preRenderingJobs() // for the rendering of the scene std::vector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs() { - std::vector<QAspectJobPtr> renderBinJobs; + std::vector<Qt3DCore::QAspectJobPtr> renderBinJobs; // Remove previous dependencies - m_cleanupJob->removeDependency(QWeakPointer<QAspectJob>()); + m_cleanupJob->removeDependency(QWeakPointer<Qt3DCore::QAspectJob>()); const bool dirtyParametersForCurrentFrame = m_dirtyBits.marked & AbstractRenderer::ParameterDirty; const BackendNodeDirtySet dirtyBitsForFrame = m_dirtyBits.marked | m_dirtyBits.remaining; @@ -2315,7 +2364,7 @@ std::vector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs() m_updatedDisableSubtreeEnablers.push_back(node->peerId()); } - int idealThreadCount = QAspectJobManager::idealThreadCount(); + int idealThreadCount = Qt3DCore::QAspectJobManager::idealThreadCount(); const size_t fgBranchCount = m_frameGraphLeaves.size(); if (fgBranchCount > 1) { @@ -2379,7 +2428,7 @@ std::vector<Qt3DCore::QAspectJobPtr> Renderer::renderBinJobs() return renderBinJobs; } -QAbstractFrameAdvanceService *Renderer::frameAdvanceService() const +Qt3DCore::QAbstractFrameAdvanceService *Renderer::frameAdvanceService() const { return static_cast<Qt3DCore::QAbstractFrameAdvanceService *>(m_vsyncFrameAdvanceService.data()); } @@ -2404,12 +2453,12 @@ bool Renderer::performCompute(QRhiCommandBuffer *cb, RenderCommand &command) return true; } -static auto rhiIndexFormat(QAttribute::VertexBaseType type) +static auto rhiIndexFormat(Qt3DCore::QAttribute::VertexBaseType type) { switch (type) { - case QAttribute::VertexBaseType ::UnsignedShort: + case Qt3DCore::QAttribute::VertexBaseType ::UnsignedShort: return QRhiCommandBuffer::IndexUInt16; - case QAttribute::VertexBaseType ::UnsignedInt: + case Qt3DCore::QAttribute::VertexBaseType ::UnsignedInt: return QRhiCommandBuffer::IndexUInt32; default: std::abort(); @@ -2481,7 +2530,7 @@ bool Renderer::uploadBuffersForCommand(RHIGraphicsPipeline* graphicsPipeline, Re Buffer *buffer = m_nodesManager->bufferManager()->lookupResource(attrib->bufferId()); RHIBuffer *hbuf = m_RHIResourceManagers->rhiBufferManager()->lookupResource(buffer->peerId()); switch (attrib->attributeType()) { - case QAttribute::VertexAttribute: { + case Qt3DCore::QAttribute::VertexAttribute: { if (!hbuf->bind(&*m_submissionContext, RHIBuffer::Type((int)RHIBuffer::Type::ArrayBuffer | (int)RHIBuffer::Type::ShaderStorageBuffer))) return false; assert(hbuf->rhiBuffer()); @@ -2494,7 +2543,7 @@ bool Renderer::uploadBuffersForCommand(RHIGraphicsPipeline* graphicsPipeline, Re command.vertex_input[bindingIndex] = { hbuf->rhiBuffer(), 0 }; break; } - case QAttribute::IndexAttribute: { + case Qt3DCore::QAttribute::IndexAttribute: { if (!hbuf->bind(&*m_submissionContext, RHIBuffer::Type::IndexBuffer)) return false; assert(hbuf->rhiBuffer()); @@ -2503,7 +2552,7 @@ bool Renderer::uploadBuffersForCommand(RHIGraphicsPipeline* graphicsPipeline, Re command.indexAttribute = attrib; break; } - case QAttribute::DrawIndirectAttribute: + case Qt3DCore::QAttribute::DrawIndirectAttribute: RHI_UNIMPLEMENTED; break; } @@ -2642,12 +2691,19 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) auto &renderTargetManager = *managers.rhiRenderTargetManager(); auto *renderTarget = renderTargetManager.lookupResource(passInfo.renderTargetId); - if (renderTarget) - rhiRenderTarget = renderTarget->renderTarget; - else if (m_submissionContext->defaultRenderTarget()) + if (renderTarget) { + // Is our RenderTarget targeting offscreen attachments? + if (renderTarget->backBuffer == RHIRenderTarget::BackBuffer::None) + rhiRenderTarget = renderTarget->renderTarget; + else // Or one of the back buffers? + rhiRenderTarget = m_submissionContext->currentSwapChain()->currentFrameRenderTarget(renderTarget->backBuffer == RHIRenderTarget::BackBuffer::Left + ? QRhiSwapChain::LeftBuffer + : QRhiSwapChain::RightBuffer); + } else if (m_submissionContext->defaultRenderTarget()) { rhiRenderTarget = m_submissionContext->defaultRenderTarget(); - else + } else { rhiRenderTarget = m_submissionContext->currentSwapChain()->currentFrameRenderTarget(); + } } auto executeDrawRenderView = [&] (RenderView* rv) { @@ -2707,7 +2763,6 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) // All the RVs in the current passinfo target the same RenderTarget // A single beginPass should take place, unless Computes RVs are intermingled - QRhiResourceUpdateBatch *inPassUpdates = nullptr; static const bool supportsCompute = m_submissionContext->rhi()->isFeatureSupported(QRhi::Compute); // Per Pass Global States @@ -2725,6 +2780,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) if (supportsCompute) { if (!inCompute) { cb->beginComputePass(m_submissionContext->m_currentUpdates); + m_submissionContext->m_currentUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch(); inCompute = true; } executeComputeRenderView(rv); @@ -2746,6 +2802,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) continue; } cb->beginPass(rhiRenderTarget, clearColor, clearDepthStencil, m_submissionContext->m_currentUpdates); + m_submissionContext->m_currentUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch(); inDraw = true; } @@ -2794,8 +2851,7 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) const QRhiColorAttachment *color0Att = desc.colorAttachmentAt(0); readbackDesc.setTexture(color0Att->texture()); } - inPassUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch(); - inPassUpdates->readBackTexture(readbackDesc, readBackResult); + m_submissionContext->m_currentUpdates->readBackTexture(readbackDesc, readBackResult); } else { qCWarning(Backend) << "Requested capture rectangle is outside framebuffer"; } @@ -2807,9 +2863,9 @@ bool Renderer::executeCommandsSubmission(const RHIPassInfo &passInfo) } if (Q_LIKELY(inDraw)) - cb->endPass(inPassUpdates); + cb->endPass(m_submissionContext->m_currentUpdates); else if (inCompute) - cb->endComputePass(); + cb->endComputePass(m_submissionContext->m_currentUpdates); m_submissionContext->m_currentUpdates = m_submissionContext->rhi()->nextResourceUpdateBatch(); diff --git a/src/plugins/renderers/rhi/renderer/renderer.pri b/src/plugins/renderers/rhi/renderer/renderer.pri deleted file mode 100644 index 5ff7d9d44..000000000 --- a/src/plugins/renderers/rhi/renderer/renderer.pri +++ /dev/null @@ -1,28 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/rendercommand.cpp \ - $$PWD/renderer.cpp \ - $$PWD/renderview.cpp \ - $$PWD/renderviewbuilder.cpp \ - $$PWD/rhigraphicspipeline.cpp \ - $$PWD/rhirendertarget.cpp \ - $$PWD/rhishader.cpp \ - $$PWD/shaderparameterpack.cpp \ - $$PWD/logging.cpp \ - $$PWD/commandexecuter.cpp \ - $$PWD/pipelineuboset.cpp - -HEADERS += \ - $$PWD/rendercommand_p.h \ - $$PWD/renderer_p.h \ - $$PWD/renderview_p.h \ - $$PWD/renderviewbuilder_p.h \ - $$PWD/rhigraphicspipeline_p.h \ - $$PWD/rhirendertarget_p.h \ - $$PWD/rhishader_p.h \ - $$PWD/shaderparameterpack_p.h \ - $$PWD/shadervariables_p.h \ - $$PWD/logging_p.h \ - $$PWD/commandexecuter_p.h \ - $$PWD/pipelineuboset_p.h diff --git a/src/plugins/renderers/rhi/renderer/renderer_p.h b/src/plugins/renderers/rhi/renderer/renderer_p.h index 463aec7d3..6f4590ef5 100644 --- a/src/plugins/renderers/rhi/renderer/renderer_p.h +++ b/src/plugins/renderers/rhi/renderer/renderer_p.h @@ -37,7 +37,7 @@ #include <Qt3DRender/private/renderercache_p.h> #include <Qt3DRender/private/renderviewinitializerjob_p.h> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> #include <shaderparameterpack_p.h> #include <logging_p.h> diff --git a/src/plugins/renderers/rhi/renderer/renderview.cpp b/src/plugins/renderers/rhi/renderer/renderview.cpp index 60a447ae6..c8ae4e7f1 100644 --- a/src/plugins/renderers/rhi/renderer/renderview.cpp +++ b/src/plugins/renderers/rhi/renderer/renderview.cpp @@ -1164,6 +1164,13 @@ void RenderView::updateRenderCommand(const EntityRenderCommandDataSubView &subVi memcpy(&command.m_commandUBO.inverseModelViewProjectionMatrix, &inverseModelViewProjection, sizeof(Matrix4x4)); copyNormalMatrix(command.m_commandUBO.modelViewNormalMatrix, modelViewNormalMatrix.constData()); + + const Armature *armature = entity->renderComponent<Armature>(); + if (armature) { + const UniformValue &skinningPalette = armature->skinningPaletteUniform(); + memcpy(&command.m_commandUBO.skinningPalette, skinningPalette.constData<float>(), + qMin<size_t>(skinningPalette.byteSize(), 100 * 16 * sizeof(float))); + } } }); } @@ -1172,8 +1179,16 @@ void RenderView::updateMatrices() { if (m_renderCameraNode && m_renderCameraLens && m_renderCameraLens->isEnabled()) { - const Matrix4x4 cameraWorld = *(m_renderCameraNode->worldTransform()); - setViewMatrix(m_renderCameraLens->viewMatrix(cameraWorld)); + auto transform = m_renderCameraNode->renderComponent<Transform>(); + if (m_renderCameraNode->isParentLessTransform() && transform && transform->hasViewMatrix()) { + // optimization: if the entity is a QCamera and it doesn't have a parent with a transform component, + // then we use the frontend version of the viewMatrix to avoid extra calculations that may introduce + // rounding errors + setViewMatrix(transform->viewMatrix()); + } else { + const Matrix4x4 cameraWorld = *(m_renderCameraNode->worldTransform()); + setViewMatrix(m_renderCameraLens->viewMatrix(cameraWorld)); + } setViewProjectionMatrix(m_renderCameraLens->projection() * viewMatrix()); // To get the eyePosition of the camera, we need to use the inverse of the @@ -1376,7 +1391,7 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, ParameterInfoList // only update values of uniforms that have changed // If parameters add been added/removed, the command would have been rebuild // and the parameter pack would be empty - const bool updateUniformsOnly = command->m_parameterPack.submissionUniformIndices().size() > 0; + const bool updateUniformsOnly = !command->m_parameterPack.submissionUniformIndices().empty(); if (!updateUniformsOnly) { // Builds the QUniformPack, sets shader standard uniforms and store attributes name / glname diff --git a/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h b/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h index 3f6c0c672..020d4583a 100644 --- a/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h +++ b/src/plugins/renderers/rhi/renderer/rhigraphicspipeline_p.h @@ -15,7 +15,7 @@ // We mean it. // -#include <private/qrhi_p.h> +#include <rhi/qrhi.h> #include <rhihandle_types_p.h> #include <pipelineuboset_p.h> #include <Qt3DCore/qnodeid.h> diff --git a/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h b/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h index bfb57568d..f699db687 100644 --- a/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h +++ b/src/plugins/renderers/rhi/renderer/rhirendertarget_p.h @@ -15,7 +15,7 @@ // We mean it. // -#include <private/qrhi_p.h> +#include <rhi/qrhi.h> #include <rhihandle_types_p.h> #include <private/attachmentpack_p.h> @@ -30,9 +30,16 @@ struct RHIRenderTarget { // Note: only used when rendering to a FBO // as we don't want to remove the default framebuffer's rendertarget // TODO: at some point separate render target and graphics pipeline as the former can be reused - QRhiRenderTarget *renderTarget{}; - QRhiRenderPassDescriptor *renderPassDescriptor{}; - QRhiRenderBuffer *depthStencilBuffer{}; + QRhiRenderTarget *renderTarget{ nullptr }; + QRhiRenderPassDescriptor *renderPassDescriptor{ nullptr }; + QRhiRenderBuffer *depthStencilBuffer{ nullptr }; + + enum class BackBuffer { + None, + Left, + Right, + }; + BackBuffer backBuffer{ BackBuffer::None }; ~RHIRenderTarget(); void cleanup(); diff --git a/src/plugins/renderers/rhi/renderer/rhishader.cpp b/src/plugins/renderers/rhi/renderer/rhishader.cpp index 5a308fa37..5c170346f 100644 --- a/src/plugins/renderers/rhi/renderer/rhishader.cpp +++ b/src/plugins/renderers/rhi/renderer/rhishader.cpp @@ -566,72 +566,71 @@ bool RHIShader::hasActiveVariables() const noexcept || !m_uniformBlockNamesIds.empty() || !m_shaderStorageBlockNamesIds.empty(); } -void RHIShader::setShaderCode(const std::vector<QByteArray> &shaderCode) +void RHIShader::setShaderCode(std::vector<QByteArray> shaderCode) { - m_shaderCode.clear(); - Qt3DCore::append(m_shaderCode, shaderCode); + m_shaderCode = std::move(shaderCode); } -void RHIShader::setFragOutputs(const QHash<QString, int> &fragOutputs) +void RHIShader::setFragOutputs(QHash<QString, int> fragOutputs) { { QMutexLocker lock(&m_mutex); - m_fragOutputs = fragOutputs; + m_fragOutputs = std::move(fragOutputs); } // updateDNA(); } -const QHash<QString, int> RHIShader::fragOutputs() const +const QHash<QString, int> &RHIShader::fragOutputs() const { QMutexLocker lock(&m_mutex); return m_fragOutputs; } -void RHIShader::initializeAttributes(const std::vector<ShaderAttribute> &attributesDescription) +void RHIShader::initializeAttributes(std::vector<ShaderAttribute> attributesDescription) { - m_attributes = attributesDescription; - m_attributesNames.resize(attributesDescription.size()); - m_attributeNamesIds.resize(attributesDescription.size()); - for (size_t i = 0, m = attributesDescription.size(); i < m; i++) { - m_attributesNames[i] = attributesDescription[i].m_name; + m_attributes = std::move(attributesDescription); + m_attributesNames.resize(m_attributes.size()); + m_attributeNamesIds.resize(m_attributes.size()); + for (size_t i = 0, m = m_attributes.size(); i < m; i++) { + m_attributesNames[i] = m_attributes[i].m_name; m_attributes[i].m_nameId = StringToInt::lookupId(m_attributesNames[i]); m_attributeNamesIds[i] = m_attributes[i].m_nameId; - qCDebug(Shaders) << "Active Attribute " << attributesDescription[i].m_name; + qCDebug(Shaders) << "Active Attribute " << m_attributes[i].m_name; } } -void RHIShader::initializeSamplers(const std::vector<ShaderAttribute> &samplersDescription) +void RHIShader::initializeSamplers(std::vector<ShaderAttribute> samplersDescription) { - m_samplers = samplersDescription; - m_samplerNames.resize(samplersDescription.size()); - m_samplerIds.resize(samplersDescription.size()); - for (size_t i = 0, m = samplersDescription.size(); i < m; i++) { - m_samplerNames[i] = samplersDescription[i].m_name; + m_samplers = std::move(samplersDescription); + m_samplerNames.resize(m_samplers.size()); + m_samplerIds.resize(m_samplers.size()); + for (size_t i = 0, m = m_samplers.size(); i < m; i++) { + m_samplerNames[i] = m_samplers[i].m_name; m_samplers[i].m_nameId = StringToInt::lookupId(m_samplerNames[i]); m_samplerIds[i] = m_samplers[i].m_nameId; - qCDebug(Shaders) << "Active sampler " << samplersDescription[i].m_name; + qCDebug(Shaders) << "Active sampler " << m_samplers[i].m_name; } } -void RHIShader::initializeImages(const std::vector<ShaderAttribute> &imagesDescription) +void RHIShader::initializeImages(std::vector<ShaderAttribute> imagesDescription) { - m_images = imagesDescription; - m_imageNames.resize(imagesDescription.size()); - m_imageIds.resize(imagesDescription.size()); - for (size_t i = 0, m = imagesDescription.size(); i < m; i++) { - m_imageNames[i] = imagesDescription[i].m_name; + m_images = std::move(imagesDescription); + m_imageNames.resize(m_images.size()); + m_imageIds.resize(m_images.size()); + for (size_t i = 0, m = m_images.size(); i < m; i++) { + m_imageNames[i] = m_images[i].m_name; m_images[i].m_nameId = StringToInt::lookupId(m_imageNames[i]); m_imageIds[i] = m_images[i].m_nameId; - qCDebug(Shaders) << "Active image " << imagesDescription[i].m_name; + qCDebug(Shaders) << "Active image " << m_images[i].m_name; } } -void RHIShader::initializeUniformBlocks(const std::vector<ShaderUniformBlock> &uniformBlockDescription) +void RHIShader::initializeUniformBlocks(std::vector<ShaderUniformBlock> uniformBlockDescription) { - m_uniformBlocks = uniformBlockDescription; - m_uniformBlockNames.resize(uniformBlockDescription.size()); - m_uniformBlockNamesIds.resize(uniformBlockDescription.size()); - for (size_t i = 0, m = uniformBlockDescription.size(); i < m; ++i) { + m_uniformBlocks = std::move(uniformBlockDescription); + m_uniformBlockNames.resize(m_uniformBlocks.size()); + m_uniformBlockNamesIds.resize(m_uniformBlocks.size()); + for (size_t i = 0, m = m_uniformBlocks.size(); i < m; ++i) { m_uniformBlockNames[i] = m_uniformBlocks[i].m_name; m_uniformBlockNamesIds[i] = StringToInt::lookupId(m_uniformBlockNames[i]); m_uniformBlocks[i].m_nameId = m_uniformBlockNamesIds[i]; @@ -647,7 +646,7 @@ void RHIShader::initializeUniformBlocks(const std::vector<ShaderUniformBlock> &u QHash<QString, ShaderUniform> activeUniformsInBlock; while (uniformsIt != uniformsEnd && uniformNamesIt != uniformNamesEnd) { - if (uniformsIt->m_blockIndex == uniformBlockDescription[i].m_index) { + if (uniformsIt->m_blockIndex == m_uniformBlocks[i].m_index) { QString uniformName = *uniformNamesIt; if (!m_uniformBlockNames[i].isEmpty() && !uniformName.startsWith(m_uniformBlockNames[i])) @@ -660,19 +659,19 @@ void RHIShader::initializeUniformBlocks(const std::vector<ShaderUniformBlock> &u ++uniformsIt; ++uniformNamesIt; } - m_uniformBlockIndexToShaderUniforms.insert(uniformBlockDescription[i].m_index, + m_uniformBlockIndexToShaderUniforms.insert(m_uniformBlocks[i].m_index, activeUniformsInBlock); } } void RHIShader::initializeShaderStorageBlocks( - const std::vector<ShaderStorageBlock> &shaderStorageBlockDescription) + std::vector<ShaderStorageBlock> shaderStorageBlockDescription) { - m_shaderStorageBlocks = shaderStorageBlockDescription; - m_shaderStorageBlockNames.resize(shaderStorageBlockDescription.size()); - m_shaderStorageBlockNamesIds.resize(shaderStorageBlockDescription.size()); + m_shaderStorageBlocks = std::move(shaderStorageBlockDescription); + m_shaderStorageBlockNames.resize(m_shaderStorageBlocks.size()); + m_shaderStorageBlockNamesIds.resize(m_shaderStorageBlocks.size()); - for (size_t i = 0, m = shaderStorageBlockDescription.size(); i < m; ++i) { + for (size_t i = 0, m = m_shaderStorageBlocks.size(); i < m; ++i) { m_shaderStorageBlockNames[i] = m_shaderStorageBlocks[i].m_name; m_shaderStorageBlockNamesIds[i] = StringToInt::lookupId(m_shaderStorageBlockNames[i]); m_shaderStorageBlocks[i].m_nameId = m_shaderStorageBlockNamesIds[i]; diff --git a/src/plugins/renderers/rhi/renderer/rhishader_p.h b/src/plugins/renderers/rhi/renderer/rhishader_p.h index ec46a39f8..f566f03ae 100644 --- a/src/plugins/renderers/rhi/renderer/rhishader_p.h +++ b/src/plugins/renderers/rhi/renderer/rhishader_p.h @@ -20,7 +20,7 @@ #include <Qt3DRender/qshaderprogram.h> #include <QMutex> #include <QtGui/private/qshader_p.h> -#include <QtGui/private/qrhi_p.h> +#include <rhi/qrhi.h> QT_BEGIN_NAMESPACE @@ -52,8 +52,8 @@ public: bool isLoaded() const { return m_isLoaded; } void setLoaded(bool loaded) { m_isLoaded = loaded; } - void setFragOutputs(const QHash<QString, int> &fragOutputs); - const QHash<QString, int> fragOutputs() const; + void setFragOutputs(QHash<QString, int> fragOutputs); + const QHash<QString, int> &fragOutputs() const; inline const std::vector<int> &uniformsNamesIds() const { return m_uniformsNamesIds; } inline const std::vector<int> &standardUniformNameIds() const { return m_standardUniformNamesIds; } @@ -94,7 +94,7 @@ public: bool hasUniform(int nameId) const noexcept; bool hasActiveVariables() const noexcept; - void setShaderCode(const std::vector<QByteArray> &shaderCode); + void setShaderCode(std::vector<QByteArray> shaderCode); const std::vector<QByteArray> &shaderCode() const; const QShader &shaderStage(QShader::Stage stage) const noexcept { return m_stages[stage]; } @@ -146,12 +146,11 @@ private: // Private so that only SubmissionContext can call it friend class SubmissionContext; - void initializeAttributes(const std::vector<ShaderAttribute> &attributesDescription); - void initializeUniformBlocks(const std::vector<ShaderUniformBlock> &uniformBlockDescription); - void - initializeShaderStorageBlocks(const std::vector<ShaderStorageBlock> &shaderStorageBlockDescription); - void initializeSamplers(const std::vector<ShaderAttribute> &samplerDescription); - void initializeImages(const std::vector<ShaderAttribute> &imageDescription); + void initializeAttributes(std::vector<Qt3DRender::Render::Rhi::ShaderAttribute> attributesDescription); + void initializeUniformBlocks(std::vector<ShaderUniformBlock> uniformBlockDescription); + void initializeShaderStorageBlocks(std::vector<ShaderStorageBlock> shaderStorageBlockDescription); + void initializeSamplers(std::vector<ShaderAttribute> samplerDescription); + void initializeImages(std::vector<ShaderAttribute> imageDescription); void recordAllUniforms(UBO_Member &uboMember, QString parentName); std::vector<UBO_Block> m_uboBlocks; diff --git a/src/plugins/renderers/rhi/rhi.pri b/src/plugins/renderers/rhi/rhi.pri deleted file mode 100644 index 5fdb77c00..000000000 --- a/src/plugins/renderers/rhi/rhi.pri +++ /dev/null @@ -1,16 +0,0 @@ - -include (renderer/renderer.pri) -include (io/io.pri) -include (textures/textures.pri) -include (graphicshelpers/graphicshelpers.pri) -include (managers/managers.pri) - -INCLUDEPATH += $$PWD - -# Qt3D is free of Q_FOREACH - make sure it stays that way: -DEFINES += QT_NO_FOREACH - -gcov { - QMAKE_CXXFLAGS += -fprofile-arcs -ftest-coverage - QMAKE_LFLAGS += -fprofile-arcs -ftest-coverage -} diff --git a/src/plugins/renderers/rhi/rhi.pro b/src/plugins/renderers/rhi/rhi.pro deleted file mode 100644 index a767223f4..000000000 --- a/src/plugins/renderers/rhi/rhi.pro +++ /dev/null @@ -1,36 +0,0 @@ -TARGET = rhirenderer - -PLUGIN_TYPE = renderers -PLUGIN_CLASS_NAME = RhiRendererPlugin -load(qt_plugin) - -QT += core-private gui-private 3dcore 3dcore-private 3drender 3drender-private - -greaterThan(QT_MAJOR_VERSION, 5) { - QT += shadertools shadertools-private -} - -# Qt3D is free of Q_FOREACH - make sure it stays that way: -DEFINES += QT_NO_FOREACH - -# We use QT_AUTOTEST_EXPORT to test the plug-ins, which needs QT_BUILDING_QT -DEFINES += QT_BUILDING_QT - -SOURCES += \ - main.cpp - -DISTFILES += \ - rhirenderer.json - -include(rhi.pri) - -qtConfig(qt3d-simd-avx2) { - CONFIG += simd - QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_AVX2 -} - -qtConfig(qt3d-simd-sse2):!qtConfig(qt3d-simd-avx2) { - CONFIG += simd - QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_SSE2 -} - diff --git a/src/plugins/renderers/rhi/textures/texture.cpp b/src/plugins/renderers/rhi/textures/texture.cpp index 6bbfb1d13..4561aa936 100644 --- a/src/plugins/renderers/rhi/textures/texture.cpp +++ b/src/plugins/renderers/rhi/textures/texture.cpp @@ -5,7 +5,7 @@ #include "texture_p.h" #include <private/qdebug_p.h> -#include <private/qrhi_p.h> +#include <rhi/qrhi.h> #include <QDebug> #include <Qt3DCore/private/vector_helper_p.h> #include <Qt3DRender/qtexture.h> @@ -19,8 +19,6 @@ QT_BEGIN_NAMESPACE -using namespace Qt3DCore; - namespace Qt3DRender { namespace Render { namespace Rhi { @@ -193,15 +191,12 @@ void filterLayersAndFaces(const QTextureImageData &data, F f) f(createUploadEntry(level, 0, data.data(0, 0, level))); } } else if (layers > 1 && faces == 1) { - qWarning() << Q_FUNC_INFO << "Unsupported case, see QTBUG-83343"; - /* for (int layer = 0; layer < data.layers(); layer++) { - for (int level = 0; level < mipLevels; level++) { + for (int level = 0; level < miplevels; level++) { f(createUploadEntry(level, layer, data.data(layer, 0, level))); } } - */ - } else if (faces > 1 && layers == 1) { + } else if (faces > 1 && layers == 1) { // Mip levels do not seem to be supported by cubemaps... for (int face = 0; face < data.faces(); face++) { f(createUploadEntry(0, face, data.data(0, face, 0))); @@ -218,8 +213,7 @@ void filterLayerAndFace(int layer, int face, F f) if (layer == 0 && face == 0) { f(0); } else if (layer > 0 && face == 0) { - qWarning() << Q_FUNC_INFO << "Unsupported case, see QTBUG-83343"; - // f(layer); + f(layer); } else if (layer == 0 && face > 0) { f(face); } else { @@ -632,7 +626,20 @@ QRhiTexture *RHITexture::buildRhiTexture(SubmissionContext *ctx) } } - QRhiTexture *rhiTexture = ctx->rhi()->newTexture(rhiFormat, pixelSize, sampleCount, rhiFlags); + if(actualTarget == QAbstractTexture::Target3D) + rhiFlags |= QRhiTexture::ThreeDimensional; + + QRhiTexture *rhiTexture = nullptr; + switch (m_properties.target) { + case QAbstractTexture::Target1DArray: + case QAbstractTexture::Target2DArray: + //This will setup the array flags correctly + rhiTexture = ctx->rhi()->newTextureArray(rhiFormat, m_properties.layers, pixelSize, sampleCount, rhiFlags); + break; + default: + rhiTexture = ctx->rhi()->newTexture(rhiFormat, pixelSize, sampleCount, rhiFlags); + break; + } if (!rhiTexture->create()) { qWarning() << Q_FUNC_INFO << "creating QRhiTexture failed"; @@ -721,7 +728,7 @@ void RHITexture::uploadRhiTextureData(SubmissionContext *ctx) }); } - if (uploadEntries.size() > 0) { + if (!uploadEntries.empty()) { QRhiTextureUploadDescription uploadDescription; uploadDescription.setEntries(uploadEntries.begin(), uploadEntries.end()); ctx->m_currentUpdates->uploadTexture(m_rhi, uploadDescription); diff --git a/src/plugins/renderers/rhi/textures/textures.pri b/src/plugins/renderers/rhi/textures/textures.pri deleted file mode 100644 index dd9e6404f..000000000 --- a/src/plugins/renderers/rhi/textures/textures.pri +++ /dev/null @@ -1,9 +0,0 @@ -INCLUDEPATH += $$PWD - -SOURCES += \ - $$PWD/renderbuffer.cpp \ - $$PWD/texture.cpp - -HEADERS += \ - $$PWD/renderbuffer_p.h \ - $$PWD/texture_p.h diff --git a/src/plugins/renderplugins/renderplugins.pro b/src/plugins/renderplugins/renderplugins.pro deleted file mode 100644 index 1bc2f6c6c..000000000 --- a/src/plugins/renderplugins/renderplugins.pro +++ /dev/null @@ -1,2 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS += scene2d diff --git a/src/plugins/renderplugins/scene2d/scene2d.pro b/src/plugins/renderplugins/scene2d/scene2d.pro deleted file mode 100644 index 2cb07756b..000000000 --- a/src/plugins/renderplugins/scene2d/scene2d.pro +++ /dev/null @@ -1,16 +0,0 @@ -TARGET = scene2d -QT += core-private 3dcore 3dcore-private 3drender 3drender-private 3dextras 3dquickscene2d 3dquickscene2d-private - -HEADERS += \ - scene2dplugin.h - -SOURCES += \ - main.cpp \ - scene2dplugin.cpp - -DISTFILES += \ - scene2dplugin.json - -PLUGIN_TYPE = renderplugins -PLUGIN_CLASS_NAME = Scene2DPlugin -load(qt_plugin) diff --git a/src/plugins/sceneparsers/CMakeLists.txt b/src/plugins/sceneparsers/CMakeLists.txt index f9c2801a4..abc33e92a 100644 --- a/src/plugins/sceneparsers/CMakeLists.txt +++ b/src/plugins/sceneparsers/CMakeLists.txt @@ -4,7 +4,7 @@ # Generated from sceneparsers.pro. add_subdirectory(gltf) -if(QT_FEATURE_qt3d_assimp AND NOT IOS AND NOT TVOS AND NOT QNX +if(QT_FEATURE_qt3d_assimp AND NOT QNX AND (CLANG OR GCC OR QT_FEATURE_qt3d_system_assimp OR (ANDROID AND CLANG) OR MSVC)) add_subdirectory(assimp) endif() diff --git a/src/plugins/sceneparsers/assimp/CMakeLists.txt b/src/plugins/sceneparsers/assimp/CMakeLists.txt index 773b0bf2e..1edc3cad7 100644 --- a/src/plugins/sceneparsers/assimp/CMakeLists.txt +++ b/src/plugins/sceneparsers/assimp/CMakeLists.txt @@ -25,6 +25,7 @@ qt_internal_add_plugin(AssimpSceneImportPlugin Qt::Core Qt::CorePrivate Qt::Gui + NO_UNITY_BUILD ) #### Keys ignored in scope 1:.:.:assimp.pro:<TRUE>: diff --git a/src/plugins/sceneparsers/assimp/assimp.pro b/src/plugins/sceneparsers/assimp/assimp.pro deleted file mode 100644 index f761db12e..000000000 --- a/src/plugins/sceneparsers/assimp/assimp.pro +++ /dev/null @@ -1,20 +0,0 @@ -TARGET = assimpsceneimport -QT += core-private 3dcore 3dcore-private 3drender 3drender-private 3dextras 3danimation - -include(../../../3rdparty/assimp/assimp_dependency.pri) - -HEADERS += \ - assimphelpers.h \ - assimpimporter.h - -SOURCES += \ - assimphelpers.cpp \ - main.cpp \ - assimpimporter.cpp - -DISTFILES += \ - assimp.json - -PLUGIN_TYPE = sceneparsers -PLUGIN_CLASS_NAME = AssimpSceneImportPlugin -load(qt_plugin) diff --git a/src/plugins/sceneparsers/assimp/assimpimporter.cpp b/src/plugins/sceneparsers/assimp/assimpimporter.cpp index 91763d156..4d32d1cc7 100644 --- a/src/plugins/sceneparsers/assimp/assimpimporter.cpp +++ b/src/plugins/sceneparsers/assimp/assimpimporter.cpp @@ -20,9 +20,8 @@ #include <Qt3DExtras/qdiffusespecularmapmaterial.h> #include <Qt3DExtras/qphongmaterial.h> #include <Qt3DExtras/qmorphphongmaterial.h> -#include <Qt3DExtras/qdiffusemapmaterial.h> -#include <Qt3DExtras/qdiffusespecularmapmaterial.h> -#include <Qt3DExtras/qphongmaterial.h> +#include <Qt3DExtras/qnormaldiffusemapmaterial.h> +#include <Qt3DExtras/qnormaldiffusespecularmapmaterial.h> #include <Qt3DAnimation/qkeyframeanimation.h> #include <Qt3DAnimation/qmorphinganimation.h> #include <QtCore/QFileInfo> @@ -36,11 +35,12 @@ QT_BEGIN_NAMESPACE -using namespace Qt3DCore; -using namespace Qt3DExtras; namespace Qt3DRender { +using namespace Qt3DCore; +using namespace Qt3DExtras; + /*! \class Qt3DRender::AssimpImporter \inmodule Qt3DRender @@ -69,6 +69,8 @@ const QString ASSIMP_MATERIAL_AMBIENT_TEXTURE = QLatin1String("ambientTex"); const QString ASSIMP_MATERIAL_SPECULAR_TEXTURE = QLatin1String("specularTexture"); const QString ASSIMP_MATERIAL_EMISSIVE_TEXTURE = QLatin1String("emissiveTex"); const QString ASSIMP_MATERIAL_NORMALS_TEXTURE = QLatin1String("normalsTex"); +// Keep the old "normalsTex" parameter name to keep backwards compatibility, add "normalTexture" as a new one +const QString ASSIMP_MATERIAL_NORMALS_TEXTURE2 = QLatin1String("normalTexture"); const QString ASSIMP_MATERIAL_OPACITY_TEXTURE = QLatin1String("opacityTex"); const QString ASSIMP_MATERIAL_REFLECTION_TEXTURE = QLatin1String("reflectionTex"); const QString ASSIMP_MATERIAL_HEIGHT_TEXTURE = QLatin1String("heightTex"); @@ -115,9 +117,14 @@ inline QString aiStringToQString(const aiString &str) QMaterial *createBestApproachingMaterial(const aiMaterial *assimpMaterial) { aiString path; // unused but necessary + const bool hasNormalTexture = (assimpMaterial->GetTexture(aiTextureType_NORMALS, 0, &path) == AI_SUCCESS); const bool hasDiffuseTexture = (assimpMaterial->GetTexture(aiTextureType_DIFFUSE, 0, &path) == AI_SUCCESS); const bool hasSpecularTexture = (assimpMaterial->GetTexture(aiTextureType_SPECULAR, 0, &path) == AI_SUCCESS); + if (hasNormalTexture && hasDiffuseTexture && hasSpecularTexture) + return QAbstractNodeFactory::createNode<QNormalDiffuseSpecularMapMaterial>("QNormalDiffuseSpecularMapMaterial"); + if (hasNormalTexture && hasDiffuseTexture) + return QAbstractNodeFactory::createNode<QNormalDiffuseMapMaterial>("QNormalDiffuseMapMaterial"); if (hasDiffuseTexture && hasSpecularTexture) return QAbstractNodeFactory::createNode<QDiffuseSpecularMapMaterial>("QDiffuseSpecularMapMaterial"); if (hasDiffuseTexture) @@ -810,11 +817,7 @@ QGeometryRenderer *AssimpImporter::loadMesh(uint meshIndex) = new Qt3DAnimation::QMorphingAnimation(geometryRenderer); QList<QString> names; -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QList<Qt3DAnimation::QMorphTarget *> targets; -#else - QVector<Qt3DAnimation::QMorphTarget *> targets; -#endif uint voff = 0; uint noff = 0; uint tanoff = 0; @@ -1131,11 +1134,7 @@ void AssimpImporter::loadAnimation(uint animationIndex) aiMesh *mesh = m_scene->m_aiScene->mMeshes[targetNode->mMeshes[0]]; Qt3DAnimation::QMorphingAnimation *morphingAnimation = new Qt3DAnimation::QMorphingAnimation; -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QList<float> positions; -#else - QVector<float> positions; -#endif positions.resize(morphAnim->mNumKeys); // set so that weights array is allocated to correct size in morphingAnimation morphingAnimation->setTargetPositions(positions); @@ -1143,11 +1142,7 @@ void AssimpImporter::loadAnimation(uint animationIndex) aiMeshMorphKey &key = morphAnim->mKeys[j]; positions[j] = key.mTime * tickScale; -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) QList<float> weights; -#else - QVector<float> weights; -#endif weights.resize(key.mNumValuesAndWeights); for (int k = 0; k < weights.size(); k++) { const unsigned int value = key.mValues[k]; @@ -1286,8 +1281,12 @@ void AssimpImporter::copyMaterialTextures(QMaterial *material, aiMaterial *assim tex->setWrapMode(wrapMode); qCDebug(AssimpImporterLog) << Q_FUNC_INFO << " Loaded Texture " << fullPath; - setParameterValue(m_scene->m_textureToParameterName[textureType[i]], - material, QVariant::fromValue(tex)); + const QString parameterName = m_scene->m_textureToParameterName[textureType[i]]; + setParameterValue(parameterName, material, QVariant::fromValue(tex)); + + if (parameterName == ASSIMP_MATERIAL_NORMALS_TEXTURE) { + setParameterValue(ASSIMP_MATERIAL_NORMALS_TEXTURE2, material, QVariant::fromValue(tex)); + } } } } diff --git a/src/plugins/sceneparsers/gltf/gltf.pro b/src/plugins/sceneparsers/gltf/gltf.pro deleted file mode 100644 index 8f0cc2fe0..000000000 --- a/src/plugins/sceneparsers/gltf/gltf.pro +++ /dev/null @@ -1,16 +0,0 @@ -TARGET = gltfsceneimport -QT += core-private 3dcore 3dcore-private 3drender 3drender-private 3dextras - -HEADERS += \ - gltfimporter.h - -SOURCES += \ - main.cpp \ - gltfimporter.cpp - -DISTFILES += \ - gltf.json - -PLUGIN_TYPE = sceneparsers -PLUGIN_CLASS_NAME = GLTFSceneImportPlugin -load(qt_plugin) diff --git a/src/plugins/sceneparsers/gltf/gltfimporter.cpp b/src/plugins/sceneparsers/gltf/gltfimporter.cpp index 69d4c8954..4f29cab06 100644 --- a/src/plugins/sceneparsers/gltf/gltfimporter.cpp +++ b/src/plugins/sceneparsers/gltf/gltfimporter.cpp @@ -239,8 +239,6 @@ QT_BEGIN_NAMESPACE -using namespace Qt3DCore; -using namespace Qt3DExtras; namespace { @@ -287,6 +285,9 @@ Qt3DRender::QFilterKey *buildFilterKey(const QString &key, const QJsonValue &val namespace Qt3DRender { +using namespace Qt3DCore; +using namespace Qt3DExtras; + Q_LOGGING_CATEGORY(GLTFImporterLog, "Qt3D.GLTFImport", QtWarningMsg); class GLTFRawTextureImage : public QAbstractTextureImage @@ -1050,9 +1051,9 @@ QMaterial *GLTFImporter::commonMaterial(const QJsonObject &jsonObj) } else { for (QVariantHash::const_iterator it = params.constBegin(), itEnd = params.constEnd(); it != itEnd; ++it) mat->setProperty(it.key().toUtf8(), it.value()); - } - renameFromJson(jsonObj, mat); + renameFromJson(jsonObj, mat); + } return mat; } @@ -1819,11 +1820,7 @@ void GLTFImporter::processJSONMesh(const QString &id, const QJsonObject &json) target->setProperty(propName.constData(), QVariant(size)); } } else { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) const QMetaType propType = target->property(propName.constData()).metaType(); -#else - const QMetaType propType(target->property(propName.constData()).type()); -#endif if (propType.id() == QMetaType::Int) { target->setProperty(propName.constData(), QVariant(it.value().toInt())); } else { diff --git a/src/plugins/sceneparsers/gltfexport/gltfexport.pro b/src/plugins/sceneparsers/gltfexport/gltfexport.pro deleted file mode 100644 index 9da330605..000000000 --- a/src/plugins/sceneparsers/gltfexport/gltfexport.pro +++ /dev/null @@ -1,16 +0,0 @@ -TARGET = gltfsceneexport -QT += core-private 3dcore 3dcore-private 3drender 3drender-private 3dextras - -HEADERS += \ - gltfexporter.h - -SOURCES += \ - main.cpp \ - gltfexporter.cpp - -DISTFILES += \ - gltfexport.json - -PLUGIN_TYPE = sceneparsers -PLUGIN_CLASS_NAME = GLTFSceneExportPlugin -load(qt_plugin) diff --git a/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp b/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp index 31808caa7..12c979019 100644 --- a/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp +++ b/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp @@ -186,11 +186,11 @@ inline void promoteColorsToRGBA(QJsonObject *obj) QT_BEGIN_NAMESPACE +namespace Qt3DRender { + using namespace Qt3DCore; using namespace Qt3DExtras; -namespace Qt3DRender { - Q_LOGGING_CATEGORY(GLTFExporterLog, "Qt3D.GLTFExport", QtWarningMsg) const QString MATERIAL_DIFFUSE_COLOR = QStringLiteral("kd"); @@ -627,11 +627,7 @@ void GLTFExporter::parseMaterials() if (material->effect()) { QList<QParameter *> parameters = material->effect()->parameters(); for (auto param : parameters) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) if (param->value().metaType().id() == QMetaType::QColor) { -#else - if (param->value().type() == QMetaType::QColor) { -#endif QColor color = param->value().value<QColor>(); if (param->name() == MATERIAL_AMBIENT_COLOR) { matInfo.colors.insert(QStringLiteral("ambient"), color); @@ -1768,11 +1764,7 @@ void GLTFExporter::exportParameter(QJsonObject &jsonObj, const QString &name, paramObj[typeStr] = GL_SAMPLER_2D; paramObj[valueStr] = m_textureIdMap.value(textureVariantToUrl(variant)); } else { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) switch (variant.metaType().id()) { -#else - switch (variant.type()) { -#endif case QMetaType::Bool: paramObj[typeStr] = GL_BOOL; paramObj[valueStr] = variant.toBool(); @@ -2044,11 +2036,7 @@ QString GLTFExporter::textureVariantToUrl(const QVariant &var) void GLTFExporter::setVarToJSonObject(QJsonObject &jsObj, const QString &key, const QVariant &var) { -#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) switch (var.metaType().id()) { -#else - switch (var.type()) { -#endif case QMetaType::Bool: jsObj[key] = var.toBool(); break; diff --git a/src/plugins/sceneparsers/sceneparsers.pro b/src/plugins/sceneparsers/sceneparsers.pro deleted file mode 100644 index 573a5ddad..000000000 --- a/src/plugins/sceneparsers/sceneparsers.pro +++ /dev/null @@ -1,12 +0,0 @@ -TEMPLATE = subdirs -# QNX is not supported, and Linux GCC 4.9 on ARM chokes on the assimp -# sources (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66964). -QT_FOR_CONFIG += 3dcore-private -!ios:!tvos:!qcc:qtConfig(qt3d-assimp):if(qtConfig(qt3d-system-assimp)|android-clang|clang|win32-msvc|gcc) { - SUBDIRS += assimp -} -SUBDIRS += gltf - -qtConfig(temporaryfile):qtConfig(regularexpression) { - SUBDIRS += gltfexport -} |