summaryrefslogtreecommitdiffstats
path: root/src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp')
-rw-r--r--src/plugins/renderers/rhi/graphicshelpers/submissioncontext.cpp108
1 files changed, 51 insertions, 57 deletions
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