diff options
Diffstat (limited to 'src/render')
65 files changed, 2752 insertions, 1896 deletions
diff --git a/src/render/backend/commandexecuter.cpp b/src/render/backend/commandexecuter.cpp index 92f44c511..2f13b27ea 100644 --- a/src/render/backend/commandexecuter.cpp +++ b/src/render/backend/commandexecuter.cpp @@ -251,13 +251,9 @@ QJsonObject parameterPackToJson(const Render::ShaderParameterPack &pack) for (auto it = uniforms.cbegin(), end = uniforms.cend(); it != end; ++it) { QJsonObject uniformObj; uniformObj.insert(QLatin1String("name"), Render::StringToInt::lookupString(it.key())); - const Render::QUniformValue::UniformType type = it.value().type(); - uniformObj.insert(QLatin1String("value"), - type == Render::QUniformValue::Value - ? typeToJsonValue(it.value().value()) - : typeToJsonValue(it.value().textureId())); + const Render::UniformValue::ValueType type = it.value().valueType(); uniformObj.insert(QLatin1String("type"), - type == Render::QUniformValue::Value + type == Render::UniformValue::ScalarValue ? QLatin1String("value") : QLatin1String("texture")); uniformsArray.push_back(uniformObj); diff --git a/src/render/backend/render-backend.pri b/src/render/backend/render-backend.pri index 256cba78e..a55a72d8b 100644 --- a/src/render/backend/render-backend.pri +++ b/src/render/backend/render-backend.pri @@ -7,7 +7,6 @@ HEADERS += \ $$PWD/renderthread_p.h \ $$PWD/renderconfiguration_p.h \ $$PWD/renderer_p.h \ - $$PWD/quniformvalue_p.h \ $$PWD/renderview_p.h \ $$PWD/rendercommand_p.h \ $$PWD/renderqueue_p.h \ @@ -36,13 +35,14 @@ HEADERS += \ $$PWD/stringtoint_p.h \ $$PWD/backendnode_p.h \ $$PWD/rendertargetoutput_p.h \ - $$PWD/commandexecuter_p.h + $$PWD/commandexecuter_p.h \ + $$PWD/uniform_p.h \ + $$PWD/shaderparameterpack_p.h SOURCES += \ $$PWD/renderthread.cpp \ $$PWD/renderconfiguration.cpp \ $$PWD/renderer.cpp \ - $$PWD/quniformvalue.cpp \ $$PWD/renderview.cpp \ $$PWD/rendercommand.cpp \ $$PWD/renderqueue.cpp \ @@ -66,5 +66,7 @@ SOURCES += \ $$PWD/rendertargetoutput.cpp \ $$PWD/attachmentpack.cpp \ $$PWD/commandexecuter.cpp \ - $$PWD/openglvertexarrayobject.cpp + $$PWD/openglvertexarrayobject.cpp \ + $$PWD/uniform.cpp \ + $$PWD/shaderparameterpack.cpp diff --git a/src/render/backend/rendercommand_p.h b/src/render/backend/rendercommand_p.h index dc65ac7ed..012cdbe9a 100644 --- a/src/render/backend/rendercommand_p.h +++ b/src/render/backend/rendercommand_p.h @@ -53,7 +53,7 @@ // #include <qglobal.h> -#include <Qt3DRender/private/quniformvalue_p.h> +#include <Qt3DRender/private/shaderparameterpack_p.h> #include <Qt3DRender/private/handle_types_p.h> #include <Qt3DRender/qgeometryrenderer.h> #include <QOpenGLShaderProgram> diff --git a/src/render/backend/renderer.cpp b/src/render/backend/renderer.cpp index ca60b8e33..7f53d3c99 100644 --- a/src/render/backend/renderer.cpp +++ b/src/render/backend/renderer.cpp @@ -919,6 +919,12 @@ Renderer::ViewSubmissionResultData Renderer::submitRenderViews(const QVector<Ren frameElapsed = timer.elapsed(); } + // Bind lastBoundFBOId back. Needed also in threaded mode. + // lastBoundFBOId != m_graphicsContext->activeFBO() when the last FrameGraph leaf node/renderView + // contains RenderTargetSelector/RenderTarget + if (lastBoundFBOId != m_graphicsContext->activeFBO()) + m_graphicsContext->bindFramebuffer(lastBoundFBOId); + // Reset state and call doneCurrent if the surface // is valid and was actually activated if (surface && m_graphicsContext->hasValidGLHelper()) { diff --git a/src/render/backend/renderer_p.h b/src/render/backend/renderer_p.h index da3d4e1e9..ffc60273a 100644 --- a/src/render/backend/renderer_p.h +++ b/src/render/backend/renderer_p.h @@ -54,7 +54,7 @@ #include <Qt3DRender/qrenderaspect.h> #include <Qt3DRender/qtechnique.h> -#include <Qt3DRender/private/quniformvalue_p.h> +#include <Qt3DRender/private/shaderparameterpack_p.h> #include <Qt3DRender/private/handle_types_p.h> #include <Qt3DRender/private/abstractrenderer_p.h> #include <Qt3DCore/qaspectjob.h> diff --git a/src/render/backend/renderview.cpp b/src/render/backend/renderview.cpp index 552e66f6d..df165e2d0 100644 --- a/src/render/backend/renderview.cpp +++ b/src/render/backend/renderview.cpp @@ -133,80 +133,80 @@ RenderView::StandardUniformsPFuncsHash RenderView::initializeStandardUniformSett return setters; } -QUniformValue RenderView::modelMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::modelMatrix(const QMatrix4x4 &model) const { - return QUniformValue(QVariant::fromValue(model)); + return UniformValue(model); } -QUniformValue RenderView::viewMatrix(const QMatrix4x4 &) const +UniformValue RenderView::viewMatrix(const QMatrix4x4 &) const { - return QUniformValue(QVariant::fromValue(m_data.m_viewMatrix)); + return UniformValue(m_data.m_viewMatrix); } -QUniformValue RenderView::projectionMatrix(const QMatrix4x4 &) const +UniformValue RenderView::projectionMatrix(const QMatrix4x4 &) const { - return QUniformValue(QVariant::fromValue(m_data.m_renderCameraLens->projection())); + return UniformValue(m_data.m_renderCameraLens->projection()); } -QUniformValue RenderView::modelViewMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::modelViewMatrix(const QMatrix4x4 &model) const { - return QUniformValue(QVariant::fromValue(m_data.m_viewMatrix * model)); + return UniformValue(m_data.m_viewMatrix * model); } -QUniformValue RenderView::viewProjectionMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::viewProjectionMatrix(const QMatrix4x4 &model) const { Q_UNUSED(model); - return QUniformValue(QVariant::fromValue(m_data.m_renderCameraLens->projection() * m_data.m_viewMatrix)); + return UniformValue(m_data.m_renderCameraLens->projection() * m_data.m_viewMatrix); } -QUniformValue RenderView::modelViewProjectionMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::modelViewProjectionMatrix(const QMatrix4x4 &model) const { - return QUniformValue(QVariant::fromValue(m_data.m_viewProjectionMatrix * model)); + return UniformValue(m_data.m_viewProjectionMatrix * model); } -QUniformValue RenderView::inverseModelMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::inverseModelMatrix(const QMatrix4x4 &model) const { - return QUniformValue(QVariant::fromValue(model.inverted())); + return UniformValue(model.inverted()); } -QUniformValue RenderView::inverseViewMatrix(const QMatrix4x4 &) const +UniformValue RenderView::inverseViewMatrix(const QMatrix4x4 &) const { - return QUniformValue(QVariant::fromValue(m_data.m_viewMatrix.inverted())); + return UniformValue(m_data.m_viewMatrix.inverted()); } -QUniformValue RenderView::inverseProjectionMatrix(const QMatrix4x4 &) const +UniformValue RenderView::inverseProjectionMatrix(const QMatrix4x4 &) const { QMatrix4x4 projection; if (m_data.m_renderCameraLens) projection = m_data.m_renderCameraLens->projection(); - return QUniformValue(QVariant::fromValue(projection.inverted())); + return UniformValue(projection.inverted()); } -QUniformValue RenderView::inverseModelViewMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::inverseModelViewMatrix(const QMatrix4x4 &model) const { - return QUniformValue(QVariant::fromValue((m_data.m_viewMatrix * model).inverted())); + return UniformValue((m_data.m_viewMatrix * model).inverted()); } -QUniformValue RenderView::inverseViewProjectionMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::inverseViewProjectionMatrix(const QMatrix4x4 &model) const { Q_UNUSED(model); const auto viewProjectionMatrix = m_data.m_renderCameraLens->projection() * m_data.m_viewMatrix; - return QUniformValue(QVariant::fromValue(viewProjectionMatrix.inverted())); + return UniformValue(viewProjectionMatrix.inverted()); } -QUniformValue RenderView::inverseModelViewProjectionMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::inverseModelViewProjectionMatrix(const QMatrix4x4 &model) const { - return QUniformValue(QVariant::fromValue((m_data.m_viewProjectionMatrix * model).inverted(0))); + return UniformValue((m_data.m_viewProjectionMatrix * model).inverted(0)); } -QUniformValue RenderView::modelNormalMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::modelNormalMatrix(const QMatrix4x4 &model) const { - return QUniformValue(QVariant::fromValue(model.normalMatrix())); + return UniformValue(model.normalMatrix()); } -QUniformValue RenderView::modelViewNormalMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::modelViewNormalMatrix(const QMatrix4x4 &model) const { - return QUniformValue(QVariant::fromValue((m_data.m_viewMatrix * model).normalMatrix())); + return UniformValue((m_data.m_viewMatrix * model).normalMatrix()); } // TODO: Move this somewhere global where GraphicsContext::setViewport() can use it too @@ -218,38 +218,38 @@ static QRectF resolveViewport(const QRectF &fractionalViewport, const QSize &sur fractionalViewport.height() * surfaceSize.height()); } -QUniformValue RenderView::viewportMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::viewportMatrix(const QMatrix4x4 &model) const { // TODO: Can we avoid having to pass the model matrix in to these functions? Q_UNUSED(model); QMatrix4x4 viewportMatrix; viewportMatrix.viewport(resolveViewport(m_viewport, m_surfaceSize)); - return QUniformValue(QVariant::fromValue(viewportMatrix)); + return UniformValue(viewportMatrix); } -QUniformValue RenderView::inverseViewportMatrix(const QMatrix4x4 &model) const +UniformValue RenderView::inverseViewportMatrix(const QMatrix4x4 &model) const { Q_UNUSED(model); QMatrix4x4 viewportMatrix; viewportMatrix.viewport(resolveViewport(m_viewport, m_surfaceSize)); QMatrix4x4 inverseViewportMatrix = viewportMatrix.inverted(); - return QUniformValue(QVariant::fromValue(inverseViewportMatrix)); + return UniformValue(inverseViewportMatrix); } -QUniformValue RenderView::time(const QMatrix4x4 &model) const +UniformValue RenderView::time(const QMatrix4x4 &model) const { Q_UNUSED(model); qint64 time = m_renderer->time(); float t = time / 1000000000.0f; - return QUniformValue(QVariant(t)); + return UniformValue(t); } -QUniformValue RenderView::eyePosition(const QMatrix4x4 &model) const +UniformValue RenderView::eyePosition(const QMatrix4x4 &model) const { Q_UNUSED(model); - return QUniformValue(QVariant::fromValue(m_data.m_eyePos)); + return UniformValue(m_data.m_eyePos); } RenderView::RenderView() @@ -326,7 +326,7 @@ void RenderView::sort() // sharing the same material (shader) are rendered, we can't have the case // where two uniforms, referencing the same texture eventually have 2 different // texture unit values - const QUniformValue refValue = cachedUniforms.value(it.key()); + const UniformValue refValue = cachedUniforms.value(it.key()); if (it.value() == refValue) { it = uniforms.erase(it); } else { @@ -532,27 +532,24 @@ void RenderView::updateMatrices() } } -void RenderView::setUniformValue(ShaderParameterPack &uniformPack, int nameId, const QVariant &value) const +void RenderView::setUniformValue(ShaderParameterPack &uniformPack, int nameId, const UniformValue &value) const { - Texture *tex = nullptr; // At this point a uniform value can only be a scalar type // or a Qt3DCore::QNodeId corresponding to a Texture // ShaderData/Buffers would be handled as UBO/SSBO and would therefore // not be in the default uniform block - if (static_cast<QMetaType::Type>(value.userType()) == qNodeIdTypeId) { - // Speed up conversion to avoid using QVariant::value() - const Qt3DCore::QNodeId texId = variant_value<Qt3DCore::QNodeId>(value); + if (value.valueType() == UniformValue::NodeId) { + Texture *tex = nullptr; + const Qt3DCore::QNodeId texId = *value.constData<Qt3DCore::QNodeId>(); if ((tex = m_manager->textureManager()->lookupResource(texId)) != nullptr) { uniformPack.setTexture(nameId, tex->peerId()); - //TextureUniform *texUniform = m_allocator->allocate<TextureUniform>(); - QUniformValue texUniform; - texUniform.setType(QUniformValue::TextureSampler); - texUniform.setTextureId(tex->peerId()); - uniformPack.setUniform(nameId, texUniform); + UniformValue::Texture textureValue; + textureValue.nodeId = texId; + uniformPack.setUniform(nameId, UniformValue(textureValue)); } } else { - uniformPack.setUniform(nameId, QUniformValue(value)); + uniformPack.setUniform(nameId, value); } } @@ -564,14 +561,14 @@ void RenderView::setStandardUniformValue(ShaderParameterPack &uniformPack, int g void RenderView::setUniformBlockValue(ShaderParameterPack &uniformPack, Shader *shader, const ShaderUniformBlock &block, - const QVariant &value) const + const UniformValue &value) const { Q_UNUSED(shader) - if (static_cast<QMetaType::Type>(value.userType()) == qNodeIdTypeId) { + if (value.valueType() == UniformValue::NodeId) { Buffer *buffer = nullptr; - if ((buffer = m_manager->bufferManager()->lookupResource(variant_value<Qt3DCore::QNodeId>(value))) != nullptr) { + if ((buffer = m_manager->bufferManager()->lookupResource(*value.constData<Qt3DCore::QNodeId>())) != nullptr) { BlockToUBO uniformBlockUBO; uniformBlockUBO.m_blockIndex = block.m_index; uniformBlockUBO.m_bufferID = buffer->peerId(); @@ -634,12 +631,12 @@ void RenderView::setUniformBlockValue(ShaderParameterPack &uniformPack, void RenderView::setShaderStorageValue(ShaderParameterPack &uniformPack, Shader *shader, const ShaderStorageBlock &block, - const QVariant &value) const + const UniformValue &value) const { Q_UNUSED(shader) - if (static_cast<QMetaType::Type>(value.userType()) == qNodeIdTypeId) { + if (value.valueType() == UniformValue::NodeId) { Buffer *buffer = nullptr; - if ((buffer = m_manager->bufferManager()->lookupResource(variant_value<Qt3DCore::QNodeId>(value))) != nullptr) { + if ((buffer = m_manager->bufferManager()->lookupResource(*value.constData<Qt3DCore::QNodeId>())) != nullptr) { BlockToSSBO shaderStorageBlock; shaderStorageBlock.m_blockIndex = block.m_index; shaderStorageBlock.m_bufferID = buffer->peerId(); @@ -654,10 +651,8 @@ void RenderView::setDefaultUniformBlockShaderDataValue(ShaderParameterPack &unif UniformBlockValueBuilder *builder = m_localData.localData(); builder->activeUniformNamesToValue.clear(); - // updates transformed properties; - // Fix me: this will lead to races when having multiple cameras - shaderData->updateViewTransform(m_data.m_viewMatrix); - + // Set the view matrix to be used to transform "Transformed" properties in the ShaderData + builder->viewMatrix = m_data.m_viewMatrix; // Force to update the whole block builder->updatedPropertiesOnly = false; // Retrieve names and description of each active uniforms in the uniform block @@ -668,8 +663,9 @@ void RenderView::setDefaultUniformBlockShaderDataValue(ShaderParameterPack &unif QHash<int, QVariant>::const_iterator activeValuesIt = builder->activeUniformNamesToValue.constBegin(); const QHash<int, QVariant>::const_iterator activeValuesEnd = builder->activeUniformNamesToValue.constEnd(); + // TO DO: Make the ShaderData store UniformValue while (activeValuesIt != activeValuesEnd) { - setUniformValue(uniformPack, activeValuesIt.key(), activeValuesIt.value()); + setUniformValue(uniformPack, activeValuesIt.key(), UniformValue::fromVariant(activeValuesIt.value())); ++activeValuesIt; } } @@ -769,10 +765,10 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass, } else if (shaderStorageBlockNamesIds.indexOf(it->nameId) != -1) { // Parameters is a SSBO setShaderStorageValue(command->m_parameterPack, shader, shader->storageBlockForBlockNameId(it->nameId), it->value); } else { // Parameter is a struct - const QVariant &v = it->value; + const UniformValue &v = it->value; ShaderData *shaderData = nullptr; - if (static_cast<QMetaType::Type>(v.userType()) == qNodeIdTypeId && - (shaderData = m_manager->shaderDataManager()->lookupResource(variant_value<Qt3DCore::QNodeId>(v))) != nullptr) { + if (v.valueType() == UniformValue::NodeId && + (shaderData = m_manager->shaderDataManager()->lookupResource(*v.constData<Qt3DCore::QNodeId>())) != nullptr) { // Try to check if we have a struct or array matching a QShaderData parameter setDefaultUniformBlockShaderDataValue(command->m_parameterPack, shader, shaderData, StringToInt::lookupString(it->nameId)); } @@ -797,11 +793,15 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass, if (lightIdx == MAX_LIGHTS) break; + // Note: implicit conversion of values to UniformValue setUniformValue(command->m_parameterPack, LIGHT_POSITION_NAMES[lightIdx], worldPos); setUniformValue(command->m_parameterPack, LIGHT_TYPE_NAMES[lightIdx], int(QAbstractLight::PointLight)); setUniformValue(command->m_parameterPack, LIGHT_COLOR_NAMES[lightIdx], QVector3D(1.0f, 1.0f, 1.0f)); setUniformValue(command->m_parameterPack, LIGHT_INTENSITY_NAMES[lightIdx], 0.5f); + // There is no risk in doing that even if multithreaded + // since we are sure that a shaderData is unique for a given light + // and won't ever be referenced as a Component either QMatrix4x4 *worldTransform = lightEntity->worldTransform(); if (worldTransform) shaderData->updateWorldTransform(*worldTransform); @@ -812,9 +812,10 @@ void RenderView::setShaderAndUniforms(RenderCommand *command, RenderPass *rPass, } if (uniformNamesIds.contains(LIGHT_COUNT_NAME_ID)) - setUniformValue(command->m_parameterPack, LIGHT_COUNT_NAME_ID, qMax(1, lightIdx)); + setUniformValue(command->m_parameterPack, LIGHT_COUNT_NAME_ID, UniformValue(qMax(1, lightIdx))); if (activeLightSources.isEmpty()) { + // Note: implicit conversion of values to UniformValue setUniformValue(command->m_parameterPack, LIGHT_POSITION_NAMES[0], QVector3D(10.0f, 10.0f, 0.0f)); setUniformValue(command->m_parameterPack, LIGHT_TYPE_NAMES[0], int(QAbstractLight::PointLight)); setUniformValue(command->m_parameterPack, LIGHT_COLOR_NAMES[0], QVector3D(1.0f, 1.0f, 1.0f)); diff --git a/src/render/backend/renderview_p.h b/src/render/backend/renderview_p.h index f974741aa..41b0192c0 100644 --- a/src/render/backend/renderview_p.h +++ b/src/render/backend/renderview_p.h @@ -279,39 +279,39 @@ private: QHash<Qt3DCore::QNodeId, QVector<RenderPassParameterData>> m_parameters; - typedef QHash<int, QUniformValue (RenderView::*)(const QMatrix4x4& model) const> StandardUniformsPFuncsHash; + typedef QHash<int, UniformValue (RenderView::*)(const QMatrix4x4& model) const> StandardUniformsPFuncsHash; static StandardUniformsPFuncsHash ms_standardUniformSetters; static StandardUniformsPFuncsHash initializeStandardUniformSetters(); - QUniformValue modelMatrix(const QMatrix4x4& model) const; - QUniformValue viewMatrix(const QMatrix4x4&) const; - QUniformValue projectionMatrix(const QMatrix4x4 &) const; - QUniformValue modelViewMatrix(const QMatrix4x4 &model) const; - QUniformValue viewProjectionMatrix(const QMatrix4x4 &model) const; - QUniformValue modelViewProjectionMatrix(const QMatrix4x4 &model) const; - QUniformValue inverseModelMatrix(const QMatrix4x4 &model) const; - QUniformValue inverseViewMatrix(const QMatrix4x4 &) const; - QUniformValue inverseProjectionMatrix(const QMatrix4x4 &) const; - QUniformValue inverseModelViewMatrix(const QMatrix4x4 &model) const; - QUniformValue inverseViewProjectionMatrix(const QMatrix4x4 &model) const; - QUniformValue inverseModelViewProjectionMatrix(const QMatrix4x4 &model) const; - QUniformValue modelNormalMatrix(const QMatrix4x4 &model) const; - QUniformValue modelViewNormalMatrix(const QMatrix4x4 &model) const; - QUniformValue viewportMatrix(const QMatrix4x4 &model) const; - QUniformValue inverseViewportMatrix(const QMatrix4x4 &model) const; - QUniformValue time(const QMatrix4x4 &model) const; - QUniformValue eyePosition(const QMatrix4x4 &model) const; - - void setUniformValue(ShaderParameterPack &uniformPack, int nameId, const QVariant &value) const; + UniformValue modelMatrix(const QMatrix4x4& model) const; + UniformValue viewMatrix(const QMatrix4x4&) const; + UniformValue projectionMatrix(const QMatrix4x4 &) const; + UniformValue modelViewMatrix(const QMatrix4x4 &model) const; + UniformValue viewProjectionMatrix(const QMatrix4x4 &model) const; + UniformValue modelViewProjectionMatrix(const QMatrix4x4 &model) const; + UniformValue inverseModelMatrix(const QMatrix4x4 &model) const; + UniformValue inverseViewMatrix(const QMatrix4x4 &) const; + UniformValue inverseProjectionMatrix(const QMatrix4x4 &) const; + UniformValue inverseModelViewMatrix(const QMatrix4x4 &model) const; + UniformValue inverseViewProjectionMatrix(const QMatrix4x4 &model) const; + UniformValue inverseModelViewProjectionMatrix(const QMatrix4x4 &model) const; + UniformValue modelNormalMatrix(const QMatrix4x4 &model) const; + UniformValue modelViewNormalMatrix(const QMatrix4x4 &model) const; + UniformValue viewportMatrix(const QMatrix4x4 &model) const; + UniformValue inverseViewportMatrix(const QMatrix4x4 &model) const; + UniformValue time(const QMatrix4x4 &model) const; + UniformValue eyePosition(const QMatrix4x4 &model) const; + + void setUniformValue(ShaderParameterPack &uniformPack, int nameId, const UniformValue &value) const; void setStandardUniformValue(ShaderParameterPack &uniformPack, int glslNameId, int nameId, const QMatrix4x4 &worldTransform) const; void setUniformBlockValue(ShaderParameterPack &uniformPack, Shader *shader, const ShaderUniformBlock &block, - const QVariant &value) const; + const UniformValue &value) const; void setShaderStorageValue(ShaderParameterPack &uniformPack, Shader *shader, const ShaderStorageBlock &block, - const QVariant &value) const; + const UniformValue &value) const; void setDefaultUniformBlockShaderDataValue(ShaderParameterPack &uniformPack, Shader *shader, ShaderData *shaderData, diff --git a/src/render/backend/quniformvalue.cpp b/src/render/backend/shaderparameterpack.cpp index 09327c213..01a977aee 100644 --- a/src/render/backend/quniformvalue.cpp +++ b/src/render/backend/shaderparameterpack.cpp @@ -37,7 +37,7 @@ ** ****************************************************************************/ -#include "quniformvalue_p.h" +#include "shaderparameterpack_p.h" #include <Qt3DRender/private/graphicscontext_p.h> #include <Qt3DRender/private/texture_p.h> @@ -55,42 +55,12 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { namespace Render { -void QUniformValue::apply(GraphicsContext *ctx, const ShaderUniform &description) const -{ - switch (m_type) { - case Value: - ctx->bindUniform(m_var, description); - break; - - case TextureSampler: - // We assume that the texture has been successfully bound and attache to a texture unit - if (m_textureIdUnit.m_textureUnit != -1) { - ctx->bindUniform(m_textureIdUnit.m_textureUnit, description); -#if defined(QT3D_RENDER_ASPECT_OPENGL_DEBUG) - int err = ctx->openGLContext()->functions()->glGetError(); - if (err) { - qCWarning(Render::Backend, "Error %d after setting uniform \"%s\" at location %d", - err, qUtf8Printable(description.m_name), description.m_location); - } -#endif - } else { - qCWarning(Render::Backend, "Invalid texture unit supplied for \"%s\"", - qUtf8Printable(description.m_nameId)); - } - break; - - default: - break; - } -} - - ShaderParameterPack::~ShaderParameterPack() { m_uniforms.clear(); } -void ShaderParameterPack::setUniform(const int glslNameId, const QUniformValue &val) +void ShaderParameterPack::setUniform(const int glslNameId, const UniformValue &val) { m_uniforms.insert(glslNameId, val); } diff --git a/src/render/backend/quniformvalue_p.h b/src/render/backend/shaderparameterpack_p.h index fb8158d84..c0ab05e57 100644 --- a/src/render/backend/quniformvalue_p.h +++ b/src/render/backend/shaderparameterpack_p.h @@ -37,8 +37,8 @@ ** ****************************************************************************/ -#ifndef QT3DRENDER_RENDER_QUNIFORMVALUE_H -#define QT3DRENDER_RENDER_QUNIFORMVALUE_H +#ifndef QT3DRENDER_RENDER_SHADERPARAMETERPACK_P_H +#define QT3DRENDER_RENDER_SHADERPARAMETERPACK_P_H // // W A R N I N G @@ -58,6 +58,7 @@ #include <Qt3DCore/qnodeid.h> #include <Qt3DRender/private/renderlogging_p.h> #include <Qt3DRender/private/shadervariables_p.h> +#include <Qt3DRender/private/uniform_p.h> QT_BEGIN_NAMESPACE @@ -72,118 +73,6 @@ namespace Render { class GraphicsContext; -class QUniformValue -{ -public: - enum UniformType { - Value, - TextureSampler, - Unknown - }; - - QUniformValue() - : m_type(Unknown) - , m_var() - { - } - - explicit QUniformValue(const QVariant &var, UniformType type = Value) - : m_type(type) - , m_var(var) - { - } - - void setType(UniformType type) Q_DECL_NOTHROW { m_type = type; } - UniformType type() const Q_DECL_NOTHROW { return m_type; } - bool isTexture() const Q_DECL_NOTHROW { return m_type == TextureSampler; } - - void setValue(const QVariant &value) - { - Q_ASSERT(m_type == Value); - m_var = value; - } - - QVariant value() const - { - Q_ASSERT(m_type == Value); - return m_var; - } - - void setTextureUnit(int textureUnit) - { - Q_ASSERT(m_type == TextureSampler); - m_textureIdUnit.m_textureUnit = textureUnit; - } - - int textureUnit() const - { - Q_ASSERT(m_type == TextureSampler); - return m_textureIdUnit.m_textureUnit; - } - - void setTextureId(Qt3DCore::QNodeId textureId) - { - Q_ASSERT(m_type == TextureSampler); - m_textureIdUnit.m_textureId = textureId; - } - - Qt3DCore::QNodeId textureId() const - { - Q_ASSERT(m_type == TextureSampler); - return m_textureIdUnit.m_textureId; - } - - bool operator ==(const QUniformValue &other) - { - if (other.m_type != m_type) - return false; - - switch (m_type) { - case Value: - return other.m_var == m_var; - case TextureSampler: - return other.m_textureIdUnit == m_textureIdUnit; - default: - break; - } - return false; - } - - bool operator !=(const QUniformValue &other) - { - return !operator ==(other); - } - - void apply(GraphicsContext *ctx, const ShaderUniform &description) const; - -protected: - struct TextureIdUnit { - Qt3DCore::QNodeId m_textureId; - int m_textureUnit; - - TextureIdUnit() - : m_textureId() - , m_textureUnit(-1) - {} - - bool operator == (const TextureIdUnit &other) const Q_DECL_NOTHROW - { - return (other.m_textureId == m_textureId) && (other.m_textureUnit == m_textureUnit); - } - - bool operator !=(const TextureIdUnit &other) const Q_DECL_NOTHROW - { - return !operator ==(other); - } - }; - - // TODO: Replace QVariant with our own union of GLSL types as we don't - // need the full flexibility of QVariant on the backend - UniformType m_type; - QVariant m_var; - TextureIdUnit m_textureIdUnit; -}; - struct BlockToUBO { int m_blockIndex; Qt3DCore::QNodeId m_bufferID; @@ -199,14 +88,14 @@ struct BlockToSSBO { QT3D_DECLARE_TYPEINFO_2(Qt3DRender, Render, BlockToSSBO, Q_PRIMITIVE_TYPE) -typedef QHash<int, QUniformValue> PackUniformHash; +typedef QHash<int, UniformValue> PackUniformHash; class ShaderParameterPack { public: ~ShaderParameterPack(); - void setUniform(const int glslNameId, const QUniformValue &val); + void setUniform(const int glslNameId, const UniformValue &val); void setTexture(const int glslNameId, Qt3DCore::QNodeId id); void setUniformBuffer(BlockToUBO blockToUBO); void setShaderStorageBuffer(BlockToSSBO blockToSSBO); @@ -214,7 +103,7 @@ public: inline PackUniformHash &uniforms() { return m_uniforms; } inline const PackUniformHash &uniforms() const { return m_uniforms; } - QUniformValue uniform(const int glslNameId) const { return m_uniforms.value(glslNameId); } + UniformValue uniform(const int glslNameId) const { return m_uniforms.value(glslNameId); } struct NamedTexture { @@ -249,4 +138,4 @@ QT3D_DECLARE_TYPEINFO_2(Qt3DRender, Render, ShaderParameterPack::NamedTexture, Q QT_END_NAMESPACE -#endif // QT3DRENDER_RENDER_QUNIFORMVALUE_H +#endif // QT3DRENDER_RENDER_SHADERPARAMETERPACK_P_H diff --git a/src/render/backend/uniform.cpp b/src/render/backend/uniform.cpp new file mode 100644 index 000000000..3bc1f78ce --- /dev/null +++ b/src/render/backend/uniform.cpp @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "uniform_p.h" + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { + +namespace { + +const int qNodeIdTypeId = qMetaTypeId<Qt3DCore::QNodeId>(); + +} + +UniformValue UniformValue::fromVariant(const QVariant &variant) +{ + // Texture/Buffer case + if (variant.userType() == qNodeIdTypeId) + return UniformValue(variant.value<Qt3DCore::QNodeId>()); + + UniformValue v; + switch (variant.userType()) { + case QMetaType::Bool: + v.m_data.ivec[0] = variant.toBool(); + break; + case QMetaType::Int: + case QMetaType::UInt: + case QMetaType::Long: + case QMetaType::LongLong: + case QMetaType::Short: + case QMetaType::ULong: + case QMetaType::ULongLong: + case QMetaType::UShort: + case QMetaType::Char: + case QMetaType::UChar: + v.m_data.ivec[0] = variant.toInt(); + break; + case QMetaType::Float: + case QMetaType::Double: // Convert double to floats + v.m_data.fvec[0] = variant.toFloat(); + break; + case QMetaType::QPoint: { + const QPoint p = variant.toPoint(); + v.m_data.ivec[0] = p.x(); + v.m_data.ivec[1] = p.y(); + break; + } + case QMetaType::QSize: { + const QSize s = variant.toSize(); + v.m_data.ivec[0] = s.width(); + v.m_data.ivec[1] = s.height(); + break; + } + case QMetaType::QRect: { + const QRect r = variant.toRect(); + v.m_data.ivec[0] = r.x(); + v.m_data.ivec[1] = r.y(); + v.m_data.ivec[2] = r.width(); + v.m_data.ivec[3] = r.height(); + break; + } + case QMetaType::QSizeF: { + const QSizeF s = variant.toSize(); + v.m_data.fvec[0] = s.width(); + v.m_data.fvec[1] = s.height(); + break; + } + case QMetaType::QPointF: { + const QPointF p = variant.toPointF(); + v.m_data.fvec[0] = p.x(); + v.m_data.fvec[1] = p.y(); + break; + } + case QMetaType::QRectF: { + const QRectF r = variant.toRect(); + v.m_data.fvec[0] = r.x(); + v.m_data.fvec[1] = r.y(); + v.m_data.fvec[2] = r.width(); + v.m_data.fvec[3] = r.height(); + break; + } + case QMetaType::QVector2D: { + const QVector2D vec2 = variant.value<QVector2D>(); + v.m_data.fvec[0] = vec2.x(); + v.m_data.fvec[1] = vec2.y(); + break; + } + case QMetaType::QVector3D: { + const QVector3D vec3 = variant.value<QVector3D>(); + v.m_data.fvec[0] = vec3.x(); + v.m_data.fvec[1] = vec3.y(); + v.m_data.fvec[2] = vec3.z(); + break; + } + case QMetaType::QVector4D: { + const QVector4D vec4 = variant.value<QVector4D>(); + v.m_data.fvec[0] = vec4.x(); + v.m_data.fvec[1] = vec4.y(); + v.m_data.fvec[2] = vec4.z(); + v.m_data.fvec[3] = vec4.w(); + break; + } + case QMetaType::QColor: { + const QColor col = variant.value<QColor>(); + v.m_data.fvec[0] = col.redF(); + v.m_data.fvec[1] = col.greenF(); + v.m_data.fvec[2] = col.blueF(); + v.m_data.fvec[3] = col.alphaF(); + break; + } + case QMetaType::QMatrix4x4: { + const QMatrix4x4 mat44 = variant.value<QMatrix4x4>(); + // Use constData because we want column-major layout + memcpy(v.data<float>(), mat44.constData(), sizeof(16 * sizeof(float))); + break; + } + default: + Q_UNREACHABLE(); + } + return v; +} + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE diff --git a/src/render/backend/uniform_p.h b/src/render/backend/uniform_p.h new file mode 100644 index 000000000..aa4b06bf9 --- /dev/null +++ b/src/render/backend/uniform_p.h @@ -0,0 +1,208 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT3DRENDER_RENDER_UNIFORM_P_H +#define QT3DRENDER_RENDER_UNIFORM_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <qt3drender_global.h> +#include <Qt3DCore/qnodeid.h> + +#include <QMatrix4x4> +#include <QVector2D> +#include <QVector3D> +#include <QColor> + +#include <QDebug> +#include <string.h> + +QT_BEGIN_NAMESPACE + +namespace Qt3DRender { +namespace Render { + +enum UniformType { + Float = 0, + Vec2, + Vec3, + Vec4, + Double, + DVec2, + DVec3, + DVec4, + Int, + IVec2, + IVec3, + IVec4, + UInt, + UIVec2, + UIVec3, + UIVec4, + Bool, + BVec2, + BVec3, + BVec4, + Mat2, + Mat3, + Mat4, + Mat2x3, + Mat3x2, + Mat2x4, + Mat4x2, + Mat3x4, + Mat4x3, + Sampler, + Unknown +}; + +class Q_AUTOTEST_EXPORT UniformValue +{ +public: + enum ValueType { + ScalarValue, + NodeId, + TextureValue, + BufferValue + }; + + struct Texture { + int textureId = 0; // Set first so that glUniform1iv will work + Qt3DCore::QNodeId nodeId; + }; + + // UniformValue implicitely converts doubles to floats to ensure + // correct rendering behavior for the cases where Qt3D parameters created from + // a double or QVariant(double) are used to fill uniform values that in reality + // should be floats. This occur especially with QML where qreal might be double + // and not float. Otherwise, at when filling the uniforms, calling constData<float> + // on something that contains a double will result in wrong values + + UniformValue() {} + UniformValue(int i) { m_data.ivec[0] = i; } + UniformValue(uint i) { m_data.ivec[0] = i; } + UniformValue(float f) { m_data.fvec[0] = f; } + UniformValue(double d) { m_data.fvec[0] = d; } // Double to float conversion + UniformValue(bool b) { m_data.ivec[0] = b; } + UniformValue(const QVector2D &vec2) { memcpy(&m_data, &vec2, sizeof(QVector2D)); } + UniformValue(const QVector3D &vec3) { memcpy(&m_data, &vec3, sizeof(QVector3D)); } + UniformValue(const QVector4D &vec4) { memcpy(&m_data, &vec4, sizeof(QVector4D)); } + + UniformValue(const QMatrix3x3 &mat33) + { + // Use constData because we want column-major layout + memcpy(&m_data, mat33.constData(), 9 * sizeof(float)); + } + + UniformValue(const QMatrix4x4 &mat44) + { + // Use constData because we want column-major layout + memcpy(&m_data, mat44.constData(), 16 * sizeof(float)); + } + + // For nodes which will later be replaced by a Texture or Buffer + UniformValue(Qt3DCore::QNodeId id) + { + m_valueType = NodeId; + memcpy(&m_data, &id, sizeof(Qt3DCore::QNodeId)); + } + + // For textures + UniformValue(UniformValue::Texture t) + { + m_valueType = TextureValue; + memcpy(&m_data, &t, sizeof(Texture)); + } + + ValueType valueType() const { return m_valueType; } + + static UniformValue fromVariant(const QVariant &variant); + + template<typename T> + const T *constData() const + { + return reinterpret_cast<const T *>(&m_data); + } + + template<typename T> + T *data() + { + return reinterpret_cast<T *>(&m_data); + } + + bool operator==(const UniformValue &other) const + { + return memcmp(&m_data, &other.m_data, sizeof(u_Uniform)) == 0; + } + + bool operator!=(const UniformValue &other) const + { + return !(*this == other); + } +private: + union u_Uniform { + int ivec[4]; // store uint/ints/bools + float fvec[16]; // for matrix4 (note: we could have a special case for matrices) + + u_Uniform() + { + memset(this, 0, sizeof(u_Uniform)); + } + } m_data; + + ValueType m_valueType = ScalarValue; +}; + +} // namespace Render +} // namespace Qt3DRender + +QT_END_NAMESPACE + +Q_DECLARE_METATYPE(Qt3DRender::Render::UniformType) + +#endif // QT3DRENDER_RENDER_UNIFORM_P_H diff --git a/src/render/framegraph/qcameraselector.cpp b/src/render/framegraph/qcameraselector.cpp index a9188cd99..c7d299b9b 100644 --- a/src/render/framegraph/qcameraselector.cpp +++ b/src/render/framegraph/qcameraselector.cpp @@ -48,13 +48,15 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { /*! - \class Qt3DRender::QCameraSelector - \inmodule Qt3DRender - \since 5.5 - \ingroup framegraph + \class Qt3DRender::QCameraSelector + \inmodule Qt3DRender + \since 5.5 + \ingroup framegraph - \brief Class to allow for selection of camera to be used + \brief Class to allow for selection of camera to be used + A Qt3DRender::QCameraSelector can be used to select the camera, which is used + by the FrameGraph when drawing the entities. */ /*! @@ -63,9 +65,25 @@ namespace Qt3DRender { \instantiates Qt3DRender::QCameraSelector \inherits FrameGraphNode \since 5.5 - \qmlabstract + \brief Class to allow for selection of camera to be used + + A CameraSelector can be used to select the camera, which is used + by the FrameGraph when drawing the entities. +*/ + +/*! + \qmlproperty Entity Qt3D.Render::CameraSelector::camera + + Holds the currently selected camera. */ +/*! + \property Qt3DRender::QCameraSelector::camera + + Holds the currently selected camera. +*/ + + /*! \internal */ QCameraSelector::QCameraSelector(QCameraSelectorPrivate &dd, QNode *parent) : QFrameGraphNode(dd, parent) @@ -91,14 +109,6 @@ QCameraSelector::~QCameraSelector() { } -/*! - \property Qt3DRender::QCameraSelector::camera -*/ - -/*! - \qmlproperty Entity Qt3D.Render::CameraSelector::camera - -*/ void QCameraSelector::setCamera(Qt3DCore::QEntity *camera) { Q_D(QCameraSelector); diff --git a/src/render/framegraph/qclearbuffers.cpp b/src/render/framegraph/qclearbuffers.cpp index 1e8a5c6e3..6fec60364 100644 --- a/src/render/framegraph/qclearbuffers.cpp +++ b/src/render/framegraph/qclearbuffers.cpp @@ -45,12 +45,14 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { /*! - \class Qt3DRender::QClearBuffers - \inmodule Qt3DRender - \since 5.7 - \ingroup framegraph + \class Qt3DRender::QClearBuffers + \inmodule Qt3DRender + \since 5.7 + \ingroup framegraph + \brief Class to clear buffers - \brief Class to clear buffers + A Qt3DRender::QClearBuffers FrameGraph node enables clearing of the specific + render target buffers with specific values. */ /*! @@ -59,21 +61,24 @@ namespace Qt3DRender { \instantiates Qt3DRender::QClearBuffers \inherits FrameGraphNode \since 5.7 - \qmlabstract + \brief Class to clear buffers + + A Qt3DRender::QClearBuffers FrameGraph node enables clearing of the specific + render target buffers with specific values. */ /*! \enum QClearBuffers::BufferType This enum type describes types of buffer to be cleared. - \value None - \value ColorBuffer - \value DepthBuffer - \value StencilBuffer - \value DepthStencilBuffer - \value ColorDepthBuffer - \value ColorDepthStencilBuffer - \value AllBuffers + \value None No buffers will be cleared + \value ColorBuffer Clear color buffers + \value DepthBuffer Clear depth buffer + \value StencilBuffer Clear stencil buffer + \value DepthStencilBuffer Clear depth and stencil buffers + \value ColorDepthBuffer Clear color and depth buffers + \value ColorDepthStencilBuffer Clear color, depth and stencil buffers + \value AllBuffers Clear all buffers */ QClearBuffersPrivate::QClearBuffersPrivate() @@ -86,7 +91,7 @@ QClearBuffersPrivate::QClearBuffersPrivate() } /*! - The constructor creates an instance with the specified \a parent. + The constructor creates an instance with the specified \a parent. */ QClearBuffers::QClearBuffers(QNode *parent) : QFrameGraphNode(*new QClearBuffersPrivate, parent) @@ -141,8 +146,8 @@ QRenderTargetOutput *QClearBuffers::colorBuffer() const */ /*! - \qmlproperty BufferType Qt3D.Render::ClearBuffers::buffers - + \qmlproperty enumeration Qt3D.Render::ClearBuffers::buffers + Specifies the buffer type to be used. */ void QClearBuffers::setBuffers(QClearBuffers::BufferType buffers) { @@ -158,8 +163,8 @@ void QClearBuffers::setBuffers(QClearBuffers::BufferType buffers) Specifies the clear color to be used. */ /*! - \qmlproperty Color Qt3D.Render::ClearBuffers::color - + \qmlproperty color Qt3D.Render::ClearBuffers::color + Specifies the clear color to be used. */ void QClearBuffers::setClearColor(const QColor &color) { @@ -176,8 +181,8 @@ void QClearBuffers::setClearColor(const QColor &color) Specifies the clear depth value to be used. */ /*! - \qmlproperty float Qt3D.Render::ClearBuffers::clearDepthValue - + \qmlproperty real Qt3D.Render::ClearBuffers::clearDepthValue + Specifies the clear depth value to be used. */ void QClearBuffers::setClearDepthValue(float clearDepthValue) { @@ -196,8 +201,8 @@ void QClearBuffers::setClearDepthValue(float clearDepthValue) Specifies the stencil value to be used. */ /*! - \qmlproperty int Qt3D.Render::ClearBuffers::clearStencilValue - + \qmlproperty int Qt3D.Render::ClearBuffers::clearStencilValue + Specifies the stencil value to be used. */ void QClearBuffers::setClearStencilValue(int clearStencilValue) { @@ -214,8 +219,9 @@ void QClearBuffers::setClearStencilValue(int clearStencilValue) ColorBuffer flag is set, all color buffers will be cleared. */ /*! - \qmlproperty Qt3D.Render::RenderTargetOutput Qt3D.Render::ClearBuffers::colorbuffer - + \qmlproperty RenderTargetOutput Qt3D.Render::ClearBuffers::colorbuffer + Specifies a specific color buffer to clear. If set to NULL (default), and + ColorBuffer flag is set, all color buffers will be cleared. */ void QClearBuffers::setColorBuffer(QRenderTargetOutput *buffer) { diff --git a/src/render/framegraph/qframegraphnode.cpp b/src/render/framegraph/qframegraphnode.cpp index add8fc75d..c60c859ac 100644 --- a/src/render/framegraph/qframegraphnode.cpp +++ b/src/render/framegraph/qframegraphnode.cpp @@ -50,14 +50,57 @@ QFrameGraphNodePrivate::QFrameGraphNodePrivate() } /*! - \class Qt3DRender::QFrameGraphNode - \inmodule Qt3DRender - \since 5.5 - - \brief Base class of all FrameGraph configuration nodes. + \class Qt3DRender::QFrameGraphNode + \inmodule Qt3DRender + \since 5.5 - This is an abstract class so it cannot be instanced directly - but rather through one of its subclasses. + \brief Base class of all FrameGraph configuration nodes. + + This is an abstract class so it cannot be instanced directly + but rather through one of its subclasses. + + The subclasses are: + \table + \header + \li class + \li description + \row + \li Qt3DRender::QCameraSelector + \li Select camera from all available cameras in the scene + \row + \li Qt3DRender::QClearBuffers + \li Specify which buffers to clear and to what values + \row + \li Qt3DRender::QDispatchCompute + \li Specify Compute operation kernels + \row + \li Qt3DRender::QFrustumCulling + \li Enable frustum culling + \row + \li Qt3DRender::QLayerFilter + \li Select which layers to draw + \row + \li Qt3DRender::QNoDraw + \li Disable drawing + \row + \li Qt3DRender::QRenderPassFilter + \li Select which render passes to draw + \row + \li Qt3DRender::QRenderStateSet + \li Set render states + \row + \li Qt3DRender::QRenderSurfaceSelector + \li Select which surface to draw to + \row + \li Qt3DRender::QSortPolicy + \li Specify how entities are sorted to determine draw order + \row + \li Qt3DRender::QTechniqueFilter + \li Select which techniques to draw + \row + \li Qt3DRender::QViewport + \li Specify viewport + \endtable */ @@ -67,11 +110,57 @@ QFrameGraphNodePrivate::QFrameGraphNodePrivate() \instantiates Qt3DRender::QFrameGraphNode \inherits Node \since 5.5 - \qmlabstract + \brief Base class of all FrameGraph configuration nodes. + + This is an abstract class so it cannot be instanced directly + but rather through one of its subclasses. + + The subclasses are: + \table + \header + \li class + \li description + \row + \li CameraSelector + \li Select camera from all available cameras in the scene + \row + \li ClearBuffers + \li Specify which buffers to clear and to what values + \row + \li DispatchCompute + \li Specify Compute operation kernels + \row + \li FrustumCulling + \li Enable frustum culling + \row + \li LayerFilter + \li Select which layers to draw + \row + \li NoDraw + \li Disable drawing + \row + \li RenderPassFilter + \li Select which render passes to draw + \row + \li RenderStateSet + \li Set render states + \row + \li RenderSurfaceSelector + \li Select which surface to draw to + \row + \li SortPolicy + \li Specify how entities are sorted to determine draw order + \row + \li TechniqueFilter + \li Select which techniques to draw + \row + \li Viewport + \li Specify viewport + \endtable */ /*! - The constructor creates an instance with the specified \a parent. + The constructor creates an instance with the specified \a parent. */ QFrameGraphNode::QFrameGraphNode(QNode *parent) : QNode(*new QFrameGraphNodePrivate, parent) @@ -84,7 +173,7 @@ QFrameGraphNode::~QFrameGraphNode() } /*! - Returns a pointer to the parent. + Returns a pointer to the parent. */ QFrameGraphNode *QFrameGraphNode::parentFrameGraphNode() const { diff --git a/src/render/framegraph/qlayerfilter.cpp b/src/render/framegraph/qlayerfilter.cpp index 92c1e1266..f7f4dd12c 100644 --- a/src/render/framegraph/qlayerfilter.cpp +++ b/src/render/framegraph/qlayerfilter.cpp @@ -59,7 +59,10 @@ QLayerFilterPrivate::QLayerFilterPrivate() \since 5.5 \brief Controls layers Drawn in a frame graph branch. - A QLayerFiler can be used to instruct the renderer as to which layer(s) to draw in that branch of the frame graph. + A Qt3DRender::QLayerFilter can be used to instruct the renderer as to which layer(s) + to draw in that branch of the frame graph. The Qt3DRender::QLayerFilter selects which + entities to draw based on the Qt3DRender::QLayer instances added to the QLayerFilter + and as components to the \l Qt3DCore::QEntity. */ /*! @@ -70,12 +73,20 @@ QLayerFilterPrivate::QLayerFilterPrivate() \since 5.5 \brief Controls layers Drawn in a frame graph branch. - A QLayerFiler can be used to instruct the renderer as to which layer(s) to draw in that branch of the frame graph. + A LayerFilter can be used to instruct the renderer as to which layer(s) + to draw in that branch of the frame graph. The LayerFilter selects which + entities to draw based on the \l Layer instances added to the LayerFilter + and as components to the \l Entity. */ +/*! + \qmlproperty list<Layer> Qt3D.Render::LayerFilter::layers + Holds a list of layers specifying the layers to select for drawing. + \readonly + */ /*! - The constructor creates an instance with the specified \a parent. + The constructor creates an instance with the specified \a parent. */ QLayerFilter::QLayerFilter(QNode *parent) : QFrameGraphNode(*new QLayerFilterPrivate, parent) @@ -94,16 +105,7 @@ QLayerFilter::~QLayerFilter() } /*! - \property Qt3DRender::QLayerFilter::layers - - */ - -/*! - \qmlproperty stringlist Qt3D.Render::LayerFilter::layers - -*/ -/*! - Add \a layer to the current list of layers + Add \a layer to the current list of layers */ void QLayerFilter::addLayer(QLayer *layer) { @@ -131,7 +133,7 @@ void QLayerFilter::addLayer(QLayer *layer) } /*! - Remove \a layer from the current list of layers + Remove \a layer from the current list of layers */ void QLayerFilter::removeLayer(QLayer *layer) { @@ -148,7 +150,7 @@ void QLayerFilter::removeLayer(QLayer *layer) } /*! - \return the current list of layers + \return the current list of layers */ QVector<QLayer *> QLayerFilter::layers() const { diff --git a/src/render/framegraph/qrendercapture.h b/src/render/framegraph/qrendercapture.h index 810cedb99..f3be273f3 100644 --- a/src/render/framegraph/qrendercapture.h +++ b/src/render/framegraph/qrendercapture.h @@ -79,7 +79,7 @@ class QT3DRENDERSHARED_EXPORT QRenderCapture : public QFrameGraphNode public: explicit QRenderCapture(Qt3DCore::QNode *parent = nullptr); - Q_INVOKABLE QRenderCaptureReply *requestCapture(int captureId); + Q_INVOKABLE Qt3DRender::QRenderCaptureReply *requestCapture(int captureId); protected: void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) Q_DECL_OVERRIDE; diff --git a/src/render/framegraph/qrendersurfaceselector.cpp b/src/render/framegraph/qrendersurfaceselector.cpp index 4063f4997..905669ff9 100644 --- a/src/render/framegraph/qrendersurfaceselector.cpp +++ b/src/render/framegraph/qrendersurfaceselector.cpp @@ -52,57 +52,70 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { /*! - * \class Qt3DRender::QRenderSurfaceSelector - * \inmodule Qt3DRender - * \brief Provides a way of specifying the render surface - * \since 5.7 - * - * \inherits Qt3DRender::QFrameGraphNode - * - * Qt3DRender::QRenderSurfaceSelector specifies which window should be used for - * the rendering of a FrameGraph branch. In some cases you may also want to - * specify the size of what needs to be drawn when rendering with a frame - * buffer object. In such cases, the externalRenderTargetSize should be set and - * updated accordingly. If it is not set, the renderer will assume it should use - * the surface's size. - * + \class Qt3DRender::QRenderSurfaceSelector + \inmodule Qt3DRender + \brief Provides a way of specifying the render surface + \since 5.7 + + The Qt3DRender::QRenderSurfaceSelector can be used to select the surface, where + Qt3D renders the content. The surface can either be window surface or offscreen + surface. The externalRenderTargetSize is used to specify the actual size of the + surface when offscreen surface is used. + + When DPI scaling is used by the system, the logical surface size, which is used + by mouse events, and the actual 'physical' size of the surface can differ. + The surfacePixelRatio is the factor to convert the logical size to the physical + size. + + \sa QWindow, QOffscreenSurface, QSurface */ /*! - * \qmltype RenderSurfaceSelector - * \inqmlmodule Qt3D.Render - * \since 5.7 - * \ingroup - * \instantiates Qt3DRender::QRenderSurfaceSelector - * \brief Provides a way of specifying the render surface - * - * RenderSurfaceSelector specifies which window should be used for - * the rendering of a FrameGraph branch. In some cases you may also want to - * specify the size of what needs to be drawn when rendering with a frame - * buffer object. In such cases, the externalRenderTargetSize should be set and - * updated accordingly. If it is not set, the renderer will assume it should use - * the surface's size. - * + \qmltype RenderSurfaceSelector + \inqmlmodule Qt3D.Render + \since 5.7 + \instantiates Qt3DRender::QRenderSurfaceSelector + \inherits FrameGraphNode + \brief Provides a way of specifying the render surface + + The RenderSurfaceSelector can be used to select the surface, where + Qt3D renders the content. The surface can either be window surface or offscreen + surface. The externalRenderTargetSize is used to specify the actual size of the + render target when offscreen surface is used. + + When DPI scaling is used by the system, the logical surface size, which is used + by mouse events, and the actual 'physical' size of the surface can differ. + The surfacePixelRatio is the factor to convert the logical size to the physical + size. */ /*! \qmlproperty QSurface Qt3D.Render::RenderSurfaceSelector::surface - * - * Holds the surface. + Holds the surface. */ -/*! - * \property QRenderSurfaceSelector::surface - * Holds the surface +/*! \qmlproperty size Qt3D.Render::RenderSurfaceSelector::externalRenderTargetSize + + Holds the size of the external render target. + */ + +/*! \qmlproperty real Qt3D.Render::RenderSurfaceSelector::surfacePixelRatio + + Holds the surfacePixelRatio of the surface. */ -/*! \qmlproperty QSize Qt3D.Render::RenderSurfaceSelector::externalRenderTargetSize - * - * Holds the size of the external render target. +/*! + \property QRenderSurfaceSelector::surface + Holds the surface */ /*! - * \property QRenderSurfaceSelector::externalRenderTargetSize - * Holds the size of the external render target. + \property QRenderSurfaceSelector::externalRenderTargetSize + Holds the size of the external render target. + */ + +/*! \property QRenderSurfaceSelector::surfacePixelRatio + + Holds the surfacePixelRatio of the surface. */ QRenderSurfaceSelectorPrivate::QRenderSurfaceSelectorPrivate() @@ -150,7 +163,7 @@ void QRenderSurfaceSelectorPrivate::setExternalRenderTargetSize(const QSize &siz } /*! - * Constructs QRenderSurfaceSelector with given \a parent. + Constructs QRenderSurfaceSelector with given \a parent. */ QRenderSurfaceSelector::QRenderSurfaceSelector(Qt3DCore::QNode *parent) : Qt3DRender::QFrameGraphNode(*new QRenderSurfaceSelectorPrivate, parent) @@ -158,14 +171,14 @@ QRenderSurfaceSelector::QRenderSurfaceSelector(Qt3DCore::QNode *parent) } /*! - * \internal + \internal */ QRenderSurfaceSelector::~QRenderSurfaceSelector() { } /*! - * \internal + \internal */ QRenderSurfaceSelector::QRenderSurfaceSelector(QRenderSurfaceSelectorPrivate &dd, Qt3DCore::QNode *parent) : Qt3DRender::QFrameGraphNode(dd, parent) @@ -192,9 +205,8 @@ QObject *QRenderSurfaceSelector::surface() const return surfaceObj; } -/*! \property QRenderSurfaceSelector::surface - * - * Sets \a surface. +/*! + Sets \a surfaceObject. */ void QRenderSurfaceSelector::setSurface(QObject *surfaceObject) { @@ -211,7 +223,7 @@ void QRenderSurfaceSelector::setSurface(QObject *surfaceObject) surface = static_cast<QSurface *>(offscreen); } - Q_ASSERT_X(surface, Q_FUNC_INFO, "surfaceObject is not a valid QSurface * object"); + Q_ASSERT_X(surface, Q_FUNC_INFO, "surfaceObject is not a valid QSurface object"); } if (d->m_surface == surface) @@ -299,8 +311,8 @@ float QRenderSurfaceSelector::surfacePixelRatio() const return d->m_surfacePixelRatio; } /*! - * Sets render target \a size if different than underlying surface size. - * Tells picking the correct size. + Sets render target \a size if different than underlying surface size. + Tells picking the correct size. */ void QRenderSurfaceSelector::setExternalRenderTargetSize(const QSize &size) { diff --git a/src/render/framegraph/qsortpolicy.cpp b/src/render/framegraph/qsortpolicy.cpp index 50fcae50f..a20ebd201 100644 --- a/src/render/framegraph/qsortpolicy.cpp +++ b/src/render/framegraph/qsortpolicy.cpp @@ -53,23 +53,34 @@ QSortPolicyPrivate::QSortPolicyPrivate() } /*! - * \class Qt3DRender::QSortPolicy - * \inmodule Qt3DRender - * \brief Provides storage for the sort types to be used - * \since 5.7 - * - * \inherits Qt3DRender::QFrameGraphNode - * + \class Qt3DRender::QSortPolicy + \inmodule Qt3DRender + \brief Provides storage for the sort types to be used + \since 5.7 + + \inherits Qt3DRender::QFrameGraphNode + + A Qt3DRender::QSortPolicy class stores the sorting type used by the FrameGraph. + The sort types determine how drawable entities are sorted before drawing to + determine the drawing order. When QSortPolicy is present in the FrameGraph, + the sorting mechanism is determined by the SortTypes list. Multiple sort types + can be used simultanously. If QSortPolicy is not present in the FrameGraph, + entities are drawn in the order they appear in the entity hierarchy. */ /*! - * \qmltype SortPolicy - * \inqmlmodule Qt3D.Render - * \since 5.7 - * \ingroup - * \instantiates Qt3DRender::QSortPolicy - * \brief Provides storage for the sort types to be used - * + \qmltype SortPolicy + \inqmlmodule Qt3D.Render + \since 5.7 + \instantiates Qt3DRender::QSortPolicy + \brief Provides storage for the sort types to be used + + A SortPolicy class stores the sorting type used by the FrameGraph. + The sort types determine how drawable entities are sorted before drawing to + determine the drawing order. When SortPolicy is present in the FrameGraph, + the sorting mechanism is determined by the SortTypes list. Multiple sort + types can be used simultanously. If SortPolicy is not present in the FrameGraph, + entities are drawn in the order they appear in the entity hierarchy. */ /*! @@ -82,7 +93,17 @@ QSortPolicyPrivate::QSortPolicyPrivate() */ /*! - * Constructs QSortPolicy with given \a parent. + \property QSortPolicy::sortTypes + Specifies the sorting types to be used. +*/ + +/*! + \qmlproperty QVariantList SortPolicy::sortTypes + Specifies the sorting types to be used. +*/ + +/*! + Constructs QSortPolicy with given \a parent. */ QSortPolicy::QSortPolicy(QNode *parent) : QFrameGraphNode(*new QSortPolicyPrivate, parent) @@ -110,17 +131,7 @@ QNodeCreatedChangeBasePtr QSortPolicy::createNodeCreationChange() const } /*! - \property Qt3DRender::QSortPolicy::sortTypes - Specifies the sorting types to be used. -*/ - -/*! - \qmlproperty QVariantList Qt3D.Render::QSortPolicy::sortTypes - Specifies the sorting types to be used. - -*/ -/*! - * \return the current sort types in use + \return the current sort types in use */ QVector<QSortPolicy::SortType> QSortPolicy::sortTypes() const { diff --git a/src/render/framegraph/qviewport.cpp b/src/render/framegraph/qviewport.cpp index c68ff141f..cf7667289 100644 --- a/src/render/framegraph/qviewport.cpp +++ b/src/render/framegraph/qviewport.cpp @@ -53,27 +53,39 @@ QViewportPrivate::QViewportPrivate() } /*! - * \class Qt3DRender::QViewport - * \inmodule Qt3DRender - * \brief A viewport on the Qt3D Scene - * \since 5.7 - * - * \inherits Qt3DRender::QFrameGraphNode - * + \class Qt3DRender::QViewport + \inmodule Qt3DRender + \brief A viewport on the Qt3D Scene + \since 5.7 + + \inherits Qt3DRender::QFrameGraphNode + + Qt3DRender::QViewport of the scene specifies at which portion of the render surface Qt3D + is rendering to. Area outside the viewport is left untouched. */ /*! - * \qmltype Viewport - * \inqmlmodule Qt3D.Render - * \since 5.7 - * \ingroup - * \instantiates Qt3DRender::QViewport - * \brief A viewport on the Qt3D Scene - * + \qmltype Viewport + \inqmlmodule Qt3D.Render + \since 5.7 + \ingroup + \instantiates Qt3DRender::QViewport + \brief A viewport on the Qt3D Scene + + Viewport of the scene specifies at which portion of the render surface Qt3D is + rendering to. Area outside the viewport is left untouched. */ /*! - * Constructs QViewport with given \a parent. + \qmlproperty rect Viewport::normalizedRect + + Specifies the normalised rectangle for the viewport, i.e. the viewport rectangle + is specified relative to the render surface size. Whole surface sized viewport + is specified as [0.0, 0.0, 1.0, 1.0], which is the default. + */ + +/*! + Constructs QViewport with given \a parent. */ QViewport::QViewport(QNode *parent) : QFrameGraphNode(*new QViewportPrivate, parent) @@ -99,14 +111,12 @@ QRectF QViewport::normalizedRect() const } /*! - \property Qt3DRender::QViewport::normalizedRect - Specifies the normalise rect for the viewport -*/ - -/*! - \qmlproperty QRectF Qt3D.Render::QViewport::normalizedRect + \property QViewport::normalizedRect -*/ + Specifies the normalised rectangle for the viewport, i.e. the viewport rectangle + is specified relative to the render surface size. Whole surface sized viewport + is specified as [0.0, 0.0, 1.0, 1.0], which is the default. + */ void QViewport::setNormalizedRect(const QRectF &normalizedRect) { Q_D(QViewport); diff --git a/src/render/frontend/qabstractfunctor.cpp b/src/render/frontend/qabstractfunctor.cpp index f3367a2b5..817d06a27 100644 --- a/src/render/frontend/qabstractfunctor.cpp +++ b/src/render/frontend/qabstractfunctor.cpp @@ -43,8 +43,44 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { +/*! + \class Qt3DRender::QAbstractFunctor + \inmodule Qt3DRender + \since 5.7 + \brief QAbstractFunctor is an abstract base class for all functors. + + The QAbstractFunctor is used as a base class for all functors and data + generators in Qt3DRender module. + + When user defines a new functor or generator, they need to implement the + \l QAbstractFunctor::id() method, which should be done using the \c {QT3D_FUNCTOR} + macro in the class definition. + */ +/*! + \fn qintptr QAbstractFunctor::id() const + */ +/*! + \macro QT3D_FUNCTOR(Class) + \relates Qt3DRender::QAbstractFunctor + + This macro assigns functor id to the \a Class, which is used by QAbstractFunctor::functor_cast + to determine if the cast can be done. + */ + +/*! + \fn const T *QAbstractFunctor::functor_cast(const QAbstractFunctor *other) const + + This method is used to cast functor \a other to type T if the other is of + type T (or of subclass); otherwise returns 0. This method works similarly + to \l QObject::qobject_cast, except with functors derived from QAbstractFunctor. + + \warning If T was not declared with \l QT3D_FUNCTOR macro, then the results are undefined. + */ + +/*! Desctructor */ QAbstractFunctor::~QAbstractFunctor() { + } } // Qt3D diff --git a/src/render/frontend/qcamera.cpp b/src/render/frontend/qcamera.cpp index b28d3bbbb..7a1f133a8 100644 --- a/src/render/frontend/qcamera.cpp +++ b/src/render/frontend/qcamera.cpp @@ -78,6 +78,298 @@ QCameraPrivate::QCameraPrivate() */ /*! + * \enum Qt3DRender::QCamera::CameraTranslationOption + * + * This enum specifies how camera view center is translated + * \value TranslateViewCenter Translate the view center causing the view direction to remain the same + * \value DontTranslateViewCenter Don't translate the view center causing the view direction to change + */ + +/*! + * \qmlmethod quaternion Qt3D.Render::Camera::tiltRotation(real angle) + * + * Returns the calculated tilt rotation in relation to the \a angle in degrees taken in + * to adjust the camera's tilt or up/down rotation on the X axis. + */ + +/*! + * \qmlmethod quaternion Qt3D.Render::Camera::panRotation(real angle) + * + * Returns the calculated pan rotation in relation to the \a angle in degrees taken in + * to adjust the camera's pan or left/right rotation on the Y axis. + */ + +/*! + * \qmlmethod quaternion Qt3D.Render::Camera::rollRotation(real angle) + * + * Returns the calculated roll rotation in relation to the \a angle in degrees taken in + * to adjust the camera's roll or lean left/right rotation on the Z axis. + */ + +/*! + * \qmlmethod quaternion Qt3D.Render::Camera::rotation(real angle, vector3d axis) + * + * Returns the calculated rotation in relation to the \a angle in degrees and + * chosen \a axis taken in. + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::translate(vector3d vLocal, enumeration option) + * + * Translates the camera's position and its view vector by \a vLocal in local coordinates. + * The \a option allows for toggling whether the view center should be translated. + * \list + * \li Camera.TranslateViewCenter + * \li Camera.DontTranslateViewCenter + * \endlist + * \sa Qt3DRender::QCamera::CameraTranslationOption + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::translateWorld(vector3d vWorld, enumeration option) + * + * Translates the camera's position and its view vector by \a vWorld in world coordinates. + * The \a option allows for toggling whether the view center should be translated. + * \list + * \li Camera.TranslateViewCenter + * \li Camera.DontTranslateViewCenter + * \endlist + * \sa Qt3DRender::QCamera::CameraTranslationOption + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::tilt(real angle) + * + * Adjusts the tilt angle of the camera by \a angle in degrees. + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::pan(real angle) + * + * Adjusts the pan angle of the camera by \a angle in degrees. + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::pan(real angle, vector3d axis) + * + * Adjusts the camera pan about view center by \a angle in degrees on \a axis. + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::roll(real angle) + * + * Adjusts the camera roll by \a angle in degrees. + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::tiltAboutViewCenter(real angle) + * + * Adjusts the camera tilt about view center by \a angle in degrees. + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::panAboutViewCenter(real angle) + * + * Adjusts the camera pan about view center by \a angle in degrees. + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::panAboutViewCenter(real angle, vector3d axis) + * + * Adjusts the camera pan about view center by \a angle in degrees on \a axis. + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::rollAboutViewCenter(real angle) + * + * Adjusts the camera roll about view center by \a angle in degrees. + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::rotate(quaternion q) + * + * Rotates the camera with the use of a Quaternion in \a q. + */ + +/*! + * \qmlmethod void Qt3D.Render::Camera::rotateAboutViewCenter(quaternion q) + * + * Rotates the camera about the view center with the use of a Quaternion in \a q. + */ + +/*! + * \qmlproperty enumeration Qt3D.Render::Camera::projectionType + * + * Holds the type of the camera projection. + * + * \list + * \li CameraLens.OrthographicProjection + * \li CameraLens.PerspectiveProjection + * \li CameraLens.FrustumProjection + * \li CameraLens.CustomProjection + * \endlist + * \sa Qt3DRender::QCameraLens::ProjectionType + */ + +/*! + * \qmlproperty real Qt3D.Render::Camera::nearPlane + * Holds the current camera near plane of the camera. + */ + +/*! + * \qmlproperty real Qt3D.Render::Camera::farPlane + * Holds the current camera far plane of the camera. + */ + +/*! + * \qmlproperty real Qt3D.Render::Camera::fieldOfView + * Holds the current field of view of the camera in degrees. + */ + +/*! + * \qmlproperty real Qt3D.Render::Camera::aspectRatio + * Holds the current aspect ratio of the camera. + */ + +/*! + *\qmlproperty real Qt3D.Render::Camera::left + * Holds the current left of the camera. + */ + +/*! + * \qmlproperty real Qt3D.Render::Camera::right + * Holds the current right of the camera. + */ + +/*! + * \qmlproperty real Qt3D.Render::Camera::bottom + * Holds the current bottom of the camera. + */ + +/*! + * \qmlproperty real Qt3D.Render::Camera::top + * Holds the current top of the camera. + */ + +/*! + * \qmlproperty matrix4x4 Qt3D.Render::Camera::projectionMatrix + * Holds the current projection matrix of the camera. + */ + + +/*! + * \qmlproperty vector3d Qt3D.Render::Camera::position + * Holds the current position of the camera. + */ + +/*! + * \qmlproperty vector3d Qt3D.Render::Camera::upVector + * Holds the current up vector of the camera. + */ + +/*! + * \qmlproperty vector3d Qt3D.Render::Camera::viewCenter + * Holds the current view center of the camera. + * \readonly + */ + +/*! + * \qmlproperty vector3d Qt3D.Render::Camera::viewVector + * Holds the camera's view vector. + * \readonly + */ + +/*! + * \qmlproperty matrix4x4 Qt3D.Render::Camera::viewMatrix + * Holds the camera's view matrix. + * \readonly + */ + +/*! + * \property QCamera::projectionType + * + * Holds the type of the camera projection. + * + * \list + * \li CameraLens.OrthographicProjection + * \li CameraLens.PerspectiveProjection + * \li CameraLens.FrustumProjection + * \li CameraLens.CustomProjection + * \endlist + * \sa Qt3DRender::QCameraLens::ProjectionType + */ + +/*! + * \property QCamera::nearPlane + * Holds the current camera near plane. + */ + +/*! + * \property QCamera::farPlane + * Holds the current camera far plane. + */ + +/*! + * \property QCamera::fieldOfView + * Holds the current field of view in degrees. + */ + +/*! + * \property QCamera::aspectRatio + * Holds the current aspect ratio. + */ + +/*! + *\property QCamera::left + * Holds the current left of the camera. + */ + +/*! + * \property QCamera::right + * Holds the current right of the camera. + */ + +/*! + * \property QCamera::bottom + * Holds the current bottom of the camera. + */ + +/*! + * \property QCamera::top + * Holds the current top of the camera. + */ + +/*! + * \property QCamera::projectionMatrix + * Holds the current projection matrix of the camera. + */ + +/*! + * \property QCamera::position + * Holds the camera's position. + */ + +/*! + * \property QCamera::upVector + * Holds the camera's up vector. + */ + +/*! + * \property QCamera::viewCenter + * Holds the camera's view center. + */ + +/*! + * \property QCamera::viewVector + * Holds the camera's view vector. + */ + +/*! + * \property QCamera::viewMatrix + * Holds the camera's view matrix. + */ + +/*! * Creates a new QCamera instance with the * specified \a parent. */ @@ -202,8 +494,8 @@ void QCamera::translateWorld(const QVector3D &vWorld, CameraTranslationOption op } /*! - * Returns the calculated tilt rotation in relation to the \a angle taken in to adjust the camera's - * tilt or up/down rotation on the X axis. + * Returns the calculated tilt rotation in relation to the \a angle in degrees taken in + * to adjust the camera's tilt or up/down rotation on the X axis. */ QQuaternion QCamera::tiltRotation(float angle) const { @@ -213,8 +505,8 @@ QQuaternion QCamera::tiltRotation(float angle) const } /*! - * Returns the calculated pan rotation in relation to the \a angle taken in to adjust the camera's - * pan or left/right rotation on the Y axis. + * Returns the calculated pan rotation in relation to the \a angle in degrees taken in + * to adjust the camera's pan or left/right rotation on the Y axis. */ QQuaternion QCamera::panRotation(float angle) const { @@ -222,8 +514,8 @@ QQuaternion QCamera::panRotation(float angle) const } /*! - * Returns the calculated roll rotation in relation to the \a angle taken in to adjust the camera's - * roll or lean left/right rotation on the Z axis. + * Returns the calculated roll rotation in relation to the \a angle in degrees taken in + * to adjust the camera's roll or lean left/right rotation on the Z axis. */ QQuaternion QCamera::rollRotation(float angle) const { @@ -232,7 +524,8 @@ QQuaternion QCamera::rollRotation(float angle) const } /*! - * Returns the calculated rotation in relation to the \a angle and chosen \a axis taken in. + * Returns the calculated rotation in relation to the \a angle in degrees and + * chosen \a axis taken in. */ QQuaternion QCamera::rotation(float angle, const QVector3D &axis) const { @@ -240,7 +533,7 @@ QQuaternion QCamera::rotation(float angle, const QVector3D &axis) const } /*! - * Adjusts the tilt angle of the camera by \a angle. + * Adjusts the tilt angle of the camera by \a angle in degrees. */ void QCamera::tilt(float angle) { @@ -249,7 +542,7 @@ void QCamera::tilt(float angle) } /*! - * Adjusts the pan angle of the camera by \a angle. + * Adjusts the pan angle of the camera by \a angle in degrees. */ void QCamera::pan(float angle) { @@ -258,7 +551,7 @@ void QCamera::pan(float angle) } /*! - * Adjusts the pan angle of the camera by \a angle on a chosen \a axis. + * Adjusts the pan angle of the camera by \a angle in degrees on a chosen \a axis. */ void QCamera::pan(float angle, const QVector3D &axis) { @@ -267,7 +560,7 @@ void QCamera::pan(float angle, const QVector3D &axis) } /*! - * Adjusts the camera roll by \a angle. + * Adjusts the camera roll by \a angle in degrees. */ void QCamera::roll(float angle) { @@ -276,7 +569,7 @@ void QCamera::roll(float angle) } /*! - * Adjusts the camera tilt about view center by \a angle. + * Adjusts the camera tilt about view center by \a angle in degrees. */ void QCamera::tiltAboutViewCenter(float angle) { @@ -285,7 +578,7 @@ void QCamera::tiltAboutViewCenter(float angle) } /*! - * Adjusts the camera pan about view center by \a angle. + * Adjusts the camera pan about view center by \a angle in degrees. */ void QCamera::panAboutViewCenter(float angle) { @@ -294,7 +587,7 @@ void QCamera::panAboutViewCenter(float angle) } /*! - * Adjusts the camera pan about view center by \a angle on \a axis. + * Adjusts the camera pan about view center by \a angle in degrees on \a axis. */ void QCamera::panAboutViewCenter(float angle, const QVector3D &axis) { @@ -303,7 +596,7 @@ void QCamera::panAboutViewCenter(float angle, const QVector3D &axis) } /*! - * Adjusts the camera roll about view center by \a angle. + * Adjusts the camera roll about view center by \a angle in degrees. */ void QCamera::rollAboutViewCenter(float angle) { @@ -344,14 +637,6 @@ void QCamera::setProjectionType(QCameraLens::ProjectionType type) d->m_lens->setProjectionType(type); } -/*! - * \qmlproperty enumeration Qt3DCore::Camera::projectionType - * - * Holds the type of the camera projection (orthogonal or perspective). - * - * \value CameraLens.OrthographicProjection Orthographic projection - * \value CameraLens.PerspectiveProjection Perspective projection - */ QCameraLens::ProjectionType QCamera::projectionType() const { Q_D(const QCamera); @@ -367,10 +652,6 @@ void QCamera::setNearPlane(float nearPlane) d->m_lens->setNearPlane(nearPlane); } -/*! - * \qmlproperty float Qt3DCore::Camera::nearPlane - * The current camera near plane. - */ float QCamera::nearPlane() const { Q_D(const QCamera); @@ -386,10 +667,6 @@ void QCamera::setFarPlane(float farPlane) d->m_lens->setFarPlane(farPlane); } -/*! - * \qmlproperty float Qt3DCore::Camera::farPlane - * The current camera far plane. - */ float QCamera::farPlane() const { Q_D(const QCamera); @@ -397,7 +674,7 @@ float QCamera::farPlane() const } /*! - * Sets the camera's field of view to \a fiedOfView. + * Sets the camera's field of view to \a fieldOfView in degrees. */ void QCamera::setFieldOfView(float fieldOfView) { @@ -405,10 +682,6 @@ void QCamera::setFieldOfView(float fieldOfView) d->m_lens->setFieldOfView(fieldOfView); } -/*! - * \qmlproperty float Qt3DCore::Camera::fieldOfView - * The current field of view. - */ float QCamera::fieldOfView() const { Q_D(const QCamera); @@ -424,10 +697,6 @@ void QCamera::setAspectRatio(float aspectRatio) d->m_lens->setAspectRatio(aspectRatio); } -/*! - * \qmlproperty float Qt3DCore::Camera::aspectRatio - * The current aspect ratio. - */ float QCamera::aspectRatio() const { Q_D(const QCamera); @@ -443,10 +712,6 @@ void QCamera::setLeft(float left) d->m_lens->setLeft(left); } -/*! - *\qmlproperty float Qt3DCore::Camera::left - * The current left of the camera. - */ float QCamera::left() const { Q_D(const QCamera); @@ -462,10 +727,6 @@ void QCamera::setRight(float right) d->m_lens->setRight(right); } -/*! - * \qmlproperty float Qt3DCore::Camera::right - * The current right of the camera. - */ float QCamera::right() const { Q_D(const QCamera); @@ -481,10 +742,6 @@ void QCamera::setBottom(float bottom) d->m_lens->setBottom(bottom); } -/*! - * \qmlproperty float Qt3DCore::Camera::bottom - * The current bottom of the camera. - */ float QCamera::bottom() const { Q_D(const QCamera); @@ -500,10 +757,6 @@ void QCamera::setTop(float top) d->m_lens->setTop(top); } -/*! - * \qmlproperty float Qt3DCore::Camera::top - * The current top of the camera. - */ float QCamera::top() const { Q_D(const QCamera); @@ -511,7 +764,7 @@ float QCamera::top() const } /*! - * Sets the camera's projection matrix. + * Sets the camera's projection matrix to \a projectionMatrix. */ void QCamera::setProjectionMatrix(const QMatrix4x4 &projectionMatrix) { @@ -519,10 +772,6 @@ void QCamera::setProjectionMatrix(const QMatrix4x4 &projectionMatrix) d->m_lens->setProjectionMatrix(projectionMatrix); } -/*! - * \qmlproperty QMatri4x4 Qt3DCore::Camera:projectionMatrix - * The current projection matrix of the camera. - */ QMatrix4x4 QCamera::projectionMatrix() const { Q_D(const QCamera); @@ -545,10 +794,6 @@ void QCamera::setPosition(const QVector3D &position) } } -/*! - * \qmlproperty vector3d Qt3DCore::Camera::position - * The camera's position. - */ QVector3D QCamera::position() const { Q_D(const QCamera); @@ -569,10 +814,6 @@ void QCamera::setUpVector(const QVector3D &upVector) } } -/*! - * \qmlproperty vector3d Qt3DCore::Camera::upVector - * The camera's up vector. - */ QVector3D QCamera::upVector() const { Q_D(const QCamera); @@ -595,30 +836,18 @@ void QCamera::setViewCenter(const QVector3D &viewCenter) } } -/*! - * \qmlproperty vector3d Qt3DCore::Camera::viewCenter - * The camera's view center. - */ QVector3D QCamera::viewCenter() const { Q_D(const QCamera); return d->m_viewCenter; } -/*! - * \qmlproperty vector3d Qt3DCore::Camera::viewVector - * The camera's view vector. - */ QVector3D QCamera::viewVector() const { Q_D(const QCamera); return d->m_cameraToCenter; } -/*! - * \qmlproperty matrix4x4 Qt3DCore::Camera::viewMatrix - * The camera's view matrix. - */ QMatrix4x4 QCamera::viewMatrix() const { Q_D(const QCamera); diff --git a/src/render/frontend/qcameralens.cpp b/src/render/frontend/qcameralens.cpp index 8c730c763..4725251b5 100644 --- a/src/render/frontend/qcameralens.cpp +++ b/src/render/frontend/qcameralens.cpp @@ -45,8 +45,164 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { /*! - \internal -*/ + * \class Qt3DRender::QCameraLens + * \inmodule Qt3DRender + * + * \brief Qt3DRender::QCameraLens specifies the projection matrix that will be used to + * define a Camera for a 3D scene. + * + * \since 5.5 + */ + +/*! + * \qmltype CameraLens + * \instantiates Qt3DRender::QCameraLens + * \inqmlmodule Qt3D.Render + * \inherits Component3D + * \since 5.5 + * \brief Provides the projection matrix that is used to define a Camera for 3D scene. + */ + +/*! + * \enum Qt3DRender::QCameraLens::ProjectionType + * + * Specifies which parameters of Qt3DRender::QCameraLens are used to compute the projection matrix. + * + * \value OrthographicProjection Orthogonal projection + * \value PerspectiveProjection Perspective projection + * \value FrustumProjection Frustum projection + * \value CustomProjection Custom user-defined projection + */ + +/*! + * \qmlproperty enumeration CameraLens::projectionType + * + * Holds the type of the camera projection. + * + * \list + * \li CameraLens.OrthographicProjection + * \li CameraLens.PerspectiveProjection + * \li CameraLens.FrustumProjection + * \li CameraLens.CustomProjection + * \endlist + * \sa Qt3DRender::QCameraLens::ProjectionType + */ + +/*! + * \qmlproperty real CameraLens::nearPlane + * Holds the current near plane of the camera lens. + */ + +/*! + * \qmlproperty real CameraLens::farPlane + * Holds the current near plane of the camera lens. + */ + +/*! + * \qmlproperty real CameraLens::fieldOfView + * Holds the current field of view of the camera lens in degrees. + */ + +/*! + * \qmlproperty real CameraLens::aspectRatio + * Holds the current aspect ratio of the camera lens. + */ + +/*! + * \qmlproperty real CameraLens::left + * Holds the current left plane of the camera lens. + */ + +/*! + * \qmlproperty real CameraLens::right + * Holds the current right plane of the camera lens. + */ + +/*! + * \qmlproperty real CameraLens::bottom + * Holds the current bottom plane of the camera lens. + */ + +/*! + * \qmlproperty real CameraLens::top + * Holds the current top plane of the camera lens. + */ + +/*! + * \qmlproperty matrix4x4 CameraLens::projectionMatrix + * Holds the current projection matrix of the camera lens. + * \readonly + */ + + +/*! + * \property QCameraLens::projectionType + * + * Holds the type of the camera projection. + * \sa Qt3DRender::QCameraLens::ProjectionType + */ + +/*! + * \property QCameraLens::nearPlane + * Holds the current near plane of the camera lens. + */ + +/*! + * \property QCameraLens::farPlane + * Holds the current near plane of the camera lens. + */ + +/*! + * \property QCameraLens::fieldOfView + * Holds the current field of view of the camera lens. + * \note: The return value may be undefined if the projection type is not + * Qt3DRender::QCameraLens::PerspectiveProjection. + */ + +/*! + * \property QCameraLens::aspectRatio + * Holds the current aspect ratio of the camera lens. + * \note: The return value may be undefined if the projection type is not + * Qt3DRender::QCameraLens::PerspectiveProjection. + */ + +/*! + * \property QCameraLens::left + * Holds the current left plane of the camera lens. + * \note The return value may be undefined if the projection type is + * Qt3DRender::QCameraLens::PerspectiveProjection. + */ + +/*! + * \property QCameraLens::right + * Holds the current right plane of the camera lens. + * \note The return value may be undefined if the projection type is + * Qt3DRender::QCameraLens::PerspectiveProjection. + */ + +/*! + * \property QCameraLens::bottom + * Holds the current bottom plane of the camera lens. + * \note The return value may be undefined if the projection type is + * Qt3DRender::QCameraLens::PerspectiveProjection. + */ + +/*! + * \property QCameraLens::top + * Holds the current top plane of the camera lens. + * \note The return value may be undefined if the projection type is + * Qt3DRender::QCameraLens::PerspectiveProjection. + */ + +/*! + * \property QCameraLens::projectionMatrix + * Holds the current projection matrix of the camera lens. + * \readonly + */ + +/*! + * \internal + */ QCameraLensPrivate::QCameraLensPrivate() : Qt3DCore::QComponentPrivate() , m_projectionType(QCameraLens::PerspectiveProjection) @@ -61,6 +217,9 @@ QCameraLensPrivate::QCameraLensPrivate() { } +/*! + * Constructs a QCameraLens with given \a parent + */ QCameraLens::QCameraLens(QNode *parent) : Qt3DCore::QComponent(*new QCameraLensPrivate, parent) { @@ -73,14 +232,6 @@ QCameraLens::~QCameraLens() { } -/*! \class Qt3DRender::QCameraLens - * \inmodule Qt3DCore - * - * \brief Qt3DRender::QCameraLens specifies the projection matrix that will be used to - * define a Camera for a 3D scene. - * - * \since 5.5 - */ QCameraLens::QCameraLens(QCameraLensPrivate &dd, QNode *parent) : QComponent(dd, parent) { @@ -89,17 +240,6 @@ QCameraLens::QCameraLens(QCameraLensPrivate &dd, QNode *parent) } /*! - * \enum Qt3DRender::QCameraLens::ProjectionType - * - * Specifies which parameters of Qt3DRender::QCameraLens are used to compute the projection matrix. - * - * \value OrthographicProjection - * \value PerspectiveProjection - * \value FrustumProjection - * \value CustomProjection - */ - -/*! * Sets the lens' projection type \a projectionType. * * \note Qt3DRender::QCameraLens::Frustum and @@ -120,9 +260,6 @@ void QCameraLens::setProjectionType(QCameraLens::ProjectionType projectionType) } } -/*! - * Returns the lens' projection type. - */ QCameraLens::ProjectionType QCameraLens::projectionType() const { Q_D(const QCameraLens); @@ -207,9 +344,6 @@ void QCameraLens::setNearPlane(float nearPlane) d->updateProjectionMatrix(); } -/*! - * Returns the projection's near plane. - */ float QCameraLens::nearPlane() const { Q_D(const QCameraLens); @@ -234,9 +368,6 @@ void QCameraLens::setFarPlane(float farPlane) d->updateProjectionMatrix(); } -/*! - * Returns the projection's far plane. - */ float QCameraLens::farPlane() const { Q_D(const QCameraLens); @@ -264,12 +395,6 @@ void QCameraLens::setFieldOfView(float fieldOfView) d->updateProjectionMatrix(); } -/*! - * Returns the projection's field of view in degrees. - * - * \note: The return value may be undefined if the projection type is not - * Qt3DRender::QCameraLens::PerspectiveProjection. - */ float QCameraLens::fieldOfView() const { Q_D(const QCameraLens); @@ -297,12 +422,6 @@ void QCameraLens::setAspectRatio(float aspectRatio) d->updateProjectionMatrix(); } -/*! - * Returns the projection's aspect ratio. - * - * \note: The return value may be undefined if the projection type is not - * Qt3DRender::QCameraLens::PerspectiveProjection. - */ float QCameraLens::aspectRatio() const { Q_D(const QCameraLens); @@ -330,12 +449,6 @@ void QCameraLens::setLeft(float left) d->updateProjectionMatrix(); } -/*! - * Returns the lower left window coordinate of the projection. - * - * \note The return value may be undefined if the projection type is - * Qt3DRender::QCameraLens::PerspectiveProjection. - */ float QCameraLens::left() const { Q_D(const QCameraLens); @@ -363,12 +476,6 @@ void QCameraLens::setRight(float right) d->updateProjectionMatrix(); } -/*! - * Returns the upper right window coordinate of the projection. - * - * \note The return value may be undefined if the projection type is - * Qt3DRender::QCameraLens::PerspectiveProjection. - */ float QCameraLens::right() const { Q_D(const QCameraLens); @@ -396,12 +503,6 @@ void QCameraLens::setBottom(float bottom) d->updateProjectionMatrix(); } -/*! - * Returns the bottom window coordinate of the projection. - * - * \note The return value may be undefined if the projection type is - * Qt3DRender::QCameraLens::PerspectiveProjection. - */ float QCameraLens::bottom() const { Q_D(const QCameraLens); @@ -429,12 +530,6 @@ void QCameraLens::setTop(float top) d->updateProjectionMatrix(); } -/*! - * Returns the bottom window coordinate of the projection. - * - * \note The return value may be undefined if the projection type is - * Qt3DRender::QCameraLens::PerspectiveProjection. - */ float QCameraLens::top() const { Q_D(const QCameraLens); @@ -442,7 +537,7 @@ float QCameraLens::top() const } /*! - * Sets the project matrix. + * Sets the project matrix to \a projectionMatrix. * * \note This will set the projection type to Qt3DRender::QCameraLens::CustomProjection and thus * ignore all other camera parameters that might have been specified. @@ -457,9 +552,6 @@ void QCameraLens::setProjectionMatrix(const QMatrix4x4 &projectionMatrix) emit projectionMatrixChanged(projectionMatrix); } -/*! - * Returns the projection matrix. - */ QMatrix4x4 QCameraLens::projectionMatrix() const { Q_D(const QCameraLens); @@ -476,59 +568,4 @@ Qt3DCore::QNodeCreatedChangeBasePtr QCameraLens::createNodeCreationChange() cons } // Qt3DRender -/*! - \qmltype CameraLens - \instantiates Qt3DRender::QCameraLens - \inqmlmodule Qt3D.Core - \inherits Component3D - \since 5.5 - \brief Provides the projection matrix that is used to define a Camera for 3D scene. -*/ - -/*! - \qmlproperty enumeration Qt3DCore::CameraLens::projectionType - - Holds the type of the camera projection (orthogonal or perspective). - - \value CameraLens.OrthographicProjection Orthogonal projection - \value CameraLens.PerspectiveProjection Perspective projection -*/ - -/*! - \qmlproperty float Qt3DCore::CameraLens::nearPlane -*/ - -/*! - \qmlproperty float Qt3DCore::CameraLens::farPlane -*/ - -/*! - \qmlproperty float Qt3DCore::CameraLens::fieldOfView -*/ - -/*! - \qmlproperty float Qt3DCore::CameraLens::aspectRatio -*/ - -/*! - \qmlproperty float Qt3DCore::CameraLens::left -*/ - -/*! - \qmlproperty float Qt3DCore::CameraLens::right -*/ - -/*! - \qmlproperty float Qt3DCore::CameraLens::bottom -*/ - -/*! - \qmlproperty float Qt3DCore::CameraLens::top -*/ - -/*! - \qmlproperty matrix4x4 Qt3DCore::CameraLens::projectionMatrix - \readonly -*/ - QT_END_NAMESPACE diff --git a/src/render/frontend/qpickingsettings.cpp b/src/render/frontend/qpickingsettings.cpp index 2805ec5a8..c1524547c 100644 --- a/src/render/frontend/qpickingsettings.cpp +++ b/src/render/frontend/qpickingsettings.cpp @@ -45,12 +45,25 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { /*! - * \class Qt3DRender::QPickingSettings - * \brief The QPickingSettings class specifies the current framegraph to be used - * by the renderer and specifies whether rendering is always active or updated - * only on changes. - * \since 5.7 - * \inmodule Qt3DRender + \class Qt3DRender::QPickingSettings + \brief The QPickingSettings class specifies how entity picking is handled. + \since 5.7 + \inmodule Qt3DRender + \inherits Qt3DCore::QNode + + The picking settings determine how the entity picking is handled. For more details about + entity picking, see QObjectPicker component documentation. + */ + +/*! + \qmltype PickingSettings + \brief The PickingSettings class specifies how entity picking is handled. + \since 5.7 + \inqmlmodule Qt3D.Render + \instantiates Qt3DRender::QPickingSettings + + The picking settings determine how the entity picking is handled. For more details about + entity picking, see Qt3DRender::QObjectPicker component documentation. */ QPickingSettingsPrivate::QPickingSettingsPrivate() @@ -61,11 +74,6 @@ QPickingSettingsPrivate::QPickingSettingsPrivate() { } -/*! - * The constructor creates a new Qt3DRender::QPickingSettings - * instance with the specified \a parent. - * \param parent - */ QPickingSettings::QPickingSettings(Qt3DCore::QNode *parent) : Qt3DCore::QNode(*new QPickingSettingsPrivate, parent) { @@ -82,18 +90,12 @@ QPickingSettings::QPickingSettings(QPickingSettingsPrivate &dd, Qt3DCore::QNode { } -/*! - * \return the current pick method. - */ QPickingSettings::PickMethod QPickingSettings::pickMethod() const { Q_D(const QPickingSettings); return d->m_pickMethod; } -/*! - * \return the current pick result mode. - */ QPickingSettings::PickResultMode QPickingSettings::pickResultMode() const { Q_D(const QPickingSettings); @@ -112,16 +114,31 @@ QPickingSettings::FaceOrientationPickingMode QPickingSettings::faceOrientationPi /*! * \enum Qt3DRender::QPickingSettings::PickMethod * - * Specifies which parameters of Qt3DRender::QPickingSettings are used. + * Specifies the picking method. * - * \value BoundingVolumePicking - * \value TrianglePicking + * \value BoundingVolumePicking An entity is considered picked if the picking ray intersects + * the bounding volume of the entity. + * \value TrianglePicking An entity is considered picked if the picking ray intersects with + * any triangle of the entity's mesh component. */ /*! - * Sets the pick method to \a pickMethod - * \param pickMethod - */ + \qmlproperty enumeration PickingSettings::pickMethod + + Holds the current pick method. + + \list + \li PickingSettings.BoundingVolumePicking + \li PickingSettings.TrianglePicking + \endlist + + \sa Qt3DRender::QPickingSettings::PickMethod +*/ +/*! + \property QPickingSettings::pickMethod + + Holds the current pick method. +*/ void QPickingSettings::setPickMethod(QPickingSettings::PickMethod pickMethod) { Q_D(QPickingSettings); @@ -135,16 +152,30 @@ void QPickingSettings::setPickMethod(QPickingSettings::PickMethod pickMethod) /*! * \enum Qt3DRender::QPickingSettings::PickResultMode * - * Specifies which parameters of Qt3DRender::PickResultMode are used. + * Specifies what is included into the picking results. * - * \value NearestPick - * \value AllPicks + * \value NearestPick Only the nearest entity to picking ray origin intersected by the picking ray + * is picked. + * \value AllPicks All entities that intersect the picking ray are picked. */ /*! - * Sets the pick result mode to \a pickResultMode - * \param pickResultMode - */ + \qmlproperty enumeration PickingSettings::pickResultMode + + Holds the current pick results mode. + + \list + \li PickingSettings.NearestPick + \li PickingSettings.AllPicks + \endlist + + \sa Qt3DRender::QPickingSettings::PickResultMode +*/ +/*! + \property QPickingSettings::pickResultMode + + Holds the current pick results mode. +*/ void QPickingSettings::setPickResultMode(QPickingSettings::PickResultMode pickResultMode) { Q_D(QPickingSettings); diff --git a/src/render/frontend/qrendersettings.cpp b/src/render/frontend/qrendersettings.cpp index c15a7810c..616c3a64e 100644 --- a/src/render/frontend/qrendersettings.cpp +++ b/src/render/frontend/qrendersettings.cpp @@ -46,10 +46,29 @@ QT_BEGIN_NAMESPACE namespace Qt3DRender { /*! - * \class Qt3DRender::QRenderSettings - * \brief The QRenderSettings class - * \since 5.7 - * \inmodule Qt3DRender + \class Qt3DRender::QRenderSettings + \brief The QRenderSettings class holds settings related to rendering process and host the active + \l{Qt 3D Render Framegraph}{FrameGraph}. + \since 5.7 + \inmodule Qt3DRender + \inherits Qt3DCore::QComponent + + The QRenderSettings component must be set as a component of the scene root entity. It specifies + render policy and picking settings, as well as hosts the active + \l{Qt 3D Render Framegraph}{FrameGraph}. + */ + +/*! + \qmltype RenderSettings + \brief The RenderSettings type holds settings related to rendering process and host the active + \l{Qt 3D Render Framegraph}{FrameGraph}. + \since 5.7 + \inqmlmodule Qt3D.Render + \instantiates Qt3DRender::QRenderSettings + + The RenderSettings component must be set as a component of the scene root entity. It specifies + render policy and picking settings, as well as hosts the active + \l{Qt 3D Render Framegraph}{FrameGraph}. */ /*! \internal */ @@ -69,7 +88,7 @@ void QRenderSettingsPrivate::init() QObject::connect(&m_pickingSettings, SIGNAL(pickResultModeChanged(QPickingSettings::PickResultMode)), q, SLOT(_q_onPickResultModeChanged(QPickingSettings::PickResultMode))); QObject::connect(&m_pickingSettings, SIGNAL(faceOrientationPickingModeChanged(QPickingSettings::FaceOrientationPickingMode)), - q, SLOT(_q_onFaceOrientationPickingMode(QPickingSettings::FaceOrientationPickingMode))); + q, SLOT(_q_onFaceOrientationPickingModeChanged(QPickingSettings::FaceOrientationPickingMode))); } /*! \internal */ @@ -85,16 +104,11 @@ void QRenderSettingsPrivate::_q_onPickResultModeChanged(QPickingSettings::PickRe } /*! \internal */ -void QRenderSettingsPrivate::_q_onFaceOrientationPickingModeChanged(bool faceOrientationPickingMode) +void QRenderSettingsPrivate::_q_onFaceOrientationPickingModeChanged(QPickingSettings::FaceOrientationPickingMode faceOrientationPickingMode) { notifyPropertyChange("faceOrientationPickingMode", faceOrientationPickingMode); } -/*! - * The constructor creates a new QRenderSettings::QRenderSettings instance with the - * specified \a parent. - * \param parent - */ QRenderSettings::QRenderSettings(Qt3DCore::QNode *parent) : QRenderSettings(*new QRenderSettingsPrivate, parent) {} @@ -112,8 +126,19 @@ QRenderSettings::~QRenderSettings() } /*! - * \return the current picking settings. - */ + \qmlproperty PickingSettings RenderSettings::pickingSettings + + Holds the current pick settings for the \l{Qt 3D Render Framegraph}{FrameGraph}. + + \readonly +*/ +/*! + \property QRenderSettings::pickingSettings + + Holds the current pick settings for the \l{Qt 3D Render Framegraph}{FrameGraph}. + + \readonly +*/ QPickingSettings *QRenderSettings::pickingSettings() { Q_D(QRenderSettings); @@ -121,27 +146,56 @@ QPickingSettings *QRenderSettings::pickingSettings() } /*! - * \return the current active framegraph. - */ + \qmlproperty FrameGraphNode RenderSettings::activeFrameGraph + + Holds the currently active \l{Qt 3D Render Framegraph}{FrameGraph}. +*/ +/*! + \property QRenderSettings::activeFrameGraph + + Holds the currently active \l{Qt 3D Render Framegraph}{FrameGraph}. +*/ QFrameGraphNode *QRenderSettings::activeFrameGraph() const { Q_D(const QRenderSettings); return d->m_activeFrameGraph; } + /*! - * \return the current render policy - */ + \enum QRenderSettings::RenderPolicy + + The render policy. + + \value OnDemand The \l{Qt 3D Render Framegraph}{FrameGraph} is rendered only when something + changes. + \value Always The \l{Qt 3D Render Framegraph}{FrameGraph} is rendered continuously, even if + nothing has changed. +*/ + +/*! + \qmlproperty enumeration RenderSettings::renderPolicy + + Holds the current render policy. + + \list + \li RenderSettings.OnDemand + \li RenderSettings.Always + \endlist + + \sa Qt3DRender::QRenderSettings::RenderPolicy +*/ +/*! + \property QRenderSettings::renderPolicy + + Holds the current render policy. +*/ QRenderSettings::RenderPolicy QRenderSettings::renderPolicy() const { Q_D(const QRenderSettings); return d->m_renderPolicy; } -/*! - * Sets the active framegraph to \a activeFrameGraph. - * \param activeFrameGraph - */ void QRenderSettings::setActiveFrameGraph(QFrameGraphNode *activeFrameGraph) { Q_D(QRenderSettings); @@ -163,10 +217,6 @@ void QRenderSettings::setActiveFrameGraph(QFrameGraphNode *activeFrameGraph) emit activeFrameGraphChanged(activeFrameGraph); } -/*! - * Sets the render policy to \a renderPolicy. - * \param renderPolicy - */ void QRenderSettings::setRenderPolicy(QRenderSettings::RenderPolicy renderPolicy) { Q_D(QRenderSettings); diff --git a/src/render/frontend/qrendersettings.h b/src/render/frontend/qrendersettings.h index 55fe3007a..68e8f8d7f 100644 --- a/src/render/frontend/qrendersettings.h +++ b/src/render/frontend/qrendersettings.h @@ -89,6 +89,7 @@ protected: private: Q_PRIVATE_SLOT(d_func(), void _q_onPickingMethodChanged(QPickingSettings::PickMethod)) Q_PRIVATE_SLOT(d_func(), void _q_onPickResultModeChanged(QPickingSettings::PickResultMode)) + Q_PRIVATE_SLOT(d_func(), void _q_onFaceOrientationPickingModeChanged(QPickingSettings::FaceOrientationPickingMode)) Qt3DCore::QNodeCreatedChangeBasePtr createNodeCreationChange() const Q_DECL_OVERRIDE; }; diff --git a/src/render/frontend/qrendersettings_p.h b/src/render/frontend/qrendersettings_p.h index b590ada00..f05124296 100644 --- a/src/render/frontend/qrendersettings_p.h +++ b/src/render/frontend/qrendersettings_p.h @@ -72,7 +72,7 @@ public: void _q_onPickingMethodChanged(QPickingSettings::PickMethod pickMethod); void _q_onPickResultModeChanged(QPickingSettings::PickResultMode pickResultMode); - void _q_onFaceOrientationPickingModeChanged(bool faceOrientationPickingMode); + void _q_onFaceOrientationPickingModeChanged(QPickingSettings::FaceOrientationPickingMode faceOrientationPickingMode); Q_DECLARE_PUBLIC(QRenderSettings) }; diff --git a/src/render/graphicshelpers/graphicscontext.cpp b/src/render/graphicshelpers/graphicscontext.cpp index acec8edf6..4c2d902f1 100644 --- a/src/render/graphicshelpers/graphicscontext.cpp +++ b/src/render/graphicshelpers/graphicscontext.cpp @@ -852,6 +852,11 @@ void GraphicsContext::alphaTest(GLenum mode1, GLenum mode2) m_glHelper->alphaTest(mode1, mode2); } +void GraphicsContext::bindFramebuffer(GLuint fbo) +{ + m_glHelper->bindFrameBufferObject(fbo); +} + void GraphicsContext::depthTest(GLenum mode) { m_glHelper->depthTest(mode); @@ -874,11 +879,6 @@ void GraphicsContext::bindFragOutputs(GLuint shader, const QHash<QString, int> & m_glHelper->bindFragDataLocation(shader, outputs); } -void GraphicsContext::bindUniform(const QVariant &v, const ShaderUniform &description) -{ - m_glHelper->bindUniform(v, description); -} - void GraphicsContext::bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) { m_glHelper->bindUniformBlock(programId, uniformBlockIndex, uniformBlockBinding); @@ -1079,12 +1079,12 @@ void GraphicsContext::setParameters(ShaderParameterPack ¶meterPack) for (int i = 0; i < parameterPack.textures().size(); ++i) { const ShaderParameterPack::NamedTexture &namedTex = parameterPack.textures().at(i); Texture *t = manager->lookupResource<Texture, TextureManager>(namedTex.texId); - // TO DO : Rework the way textures are loaded if (t != nullptr) { int texUnit = activateTexture(TextureScopeMaterial, t); if (uniformValues.contains(namedTex.glslNameId)) { - QUniformValue &texUniform = uniformValues[namedTex.glslNameId]; - texUniform.setTextureUnit(texUnit); + UniformValue &texUniform = uniformValues[namedTex.glslNameId]; + Q_ASSERT(texUniform.valueType() == UniformValue::TextureValue); + texUniform.data<UniformValue::Texture>()->textureId = texUnit; } } } @@ -1140,8 +1140,7 @@ void GraphicsContext::setParameters(ShaderParameterPack ¶meterPack) for (const ShaderUniform &uniform : activeUniforms) { // We can use [] as we are sure the the uniform wouldn't // be un activeUniforms if there wasn't a matching value - const QUniformValue &value = values[uniform.m_nameId]; - value.apply(this, uniform); + applyUniform(uniform, values[uniform.m_nameId]); } } @@ -1171,6 +1170,109 @@ void GraphicsContext::disableAttribute(const GraphicsContext::VAOVertexAttribute prog->disableAttributeArray(attr.location); } +void GraphicsContext::applyUniform(const ShaderUniform &description, const UniformValue &v) +{ + const UniformType type = m_glHelper->uniformTypeFromGLType(description.m_type); + + switch (type) { + case UniformType::Float: + applyUniformHelper<UniformType::Float>(description.m_location, v); + break; + case UniformType::Vec2: + applyUniformHelper<UniformType::Vec2>(description.m_location, v); + break; + case UniformType::Vec3: + applyUniformHelper<UniformType::Vec3>(description.m_location, v); + break; + case UniformType::Vec4: + applyUniformHelper<UniformType::Vec4>(description.m_location, v); + break; + + case UniformType::Double: + applyUniformHelper<UniformType::Double>(description.m_location, v); + break; + case UniformType::DVec2: + applyUniformHelper<UniformType::DVec2>(description.m_location, v); + break; + case UniformType::DVec3: + applyUniformHelper<UniformType::DVec3>(description.m_location, v); + break; + case UniformType::DVec4: + applyUniformHelper<UniformType::DVec4>(description.m_location, v); + break; + + case UniformType::Sampler: + case UniformType::Int: + applyUniformHelper<UniformType::Int>(description.m_location, v); + break; + case UniformType::IVec2: + applyUniformHelper<UniformType::IVec2>(description.m_location, v); + break; + case UniformType::IVec3: + applyUniformHelper<UniformType::IVec3>(description.m_location, v); + break; + case UniformType::IVec4: + applyUniformHelper<UniformType::IVec4>(description.m_location, v); + break; + + case UniformType::UInt: + applyUniformHelper<UniformType::Int>(description.m_location, v); + break; + case UniformType::UIVec2: + applyUniformHelper<UniformType::IVec2>(description.m_location, v); + break; + case UniformType::UIVec3: + applyUniformHelper<UniformType::IVec3>(description.m_location, v); + break; + case UniformType::UIVec4: + applyUniformHelper<UniformType::IVec4>(description.m_location, v); + break; + + case UniformType::Bool: + applyUniformHelper<UniformType::Bool>(description.m_location, v); + break; + case UniformType::BVec2: + applyUniformHelper<UniformType::BVec2>(description.m_location, v); + break; + case UniformType::BVec3: + applyUniformHelper<UniformType::BVec3>(description.m_location, v); + break; + case UniformType::BVec4: + applyUniformHelper<UniformType::BVec4>(description.m_location, v); + break; + + case UniformType::Mat2: + applyUniformHelper<UniformType::Mat2>(description.m_location, v); + break; + case UniformType::Mat3: + applyUniformHelper<UniformType::Mat3>(description.m_location, v); + break; + case UniformType::Mat4: + applyUniformHelper<UniformType::Mat4>(description.m_location, v); + break; + case UniformType::Mat2x3: + applyUniformHelper<UniformType::Mat2x3>(description.m_location, v); + break; + case UniformType::Mat3x2: + applyUniformHelper<UniformType::Mat3x2>(description.m_location, v); + break; + case UniformType::Mat2x4: + applyUniformHelper<UniformType::Mat2x4>(description.m_location, v); + break; + case UniformType::Mat4x2: + applyUniformHelper<UniformType::Mat4x2>(description.m_location, v); + case UniformType::Mat3x4: + applyUniformHelper<UniformType::Mat3x4>(description.m_location, v); + break; + case UniformType::Mat4x3: + applyUniformHelper<UniformType::Mat4x3>(description.m_location, v); + break; + + default: + break; + } +} + // Note: needs to be called while VAO is bound void GraphicsContext::specifyAttribute(const Attribute *attribute, Buffer *buffer, int location) { @@ -1452,6 +1554,37 @@ QImage GraphicsContext::readFramebuffer(QSize size) return qt_gl_read_framebuffer(size, true, true); } +QT3D_UNIFORM_TYPE_IMPL(UniformType::Float, float, glUniform1fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Vec2, float, glUniform2fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Vec3, float, glUniform3fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Vec4, float, glUniform4fv) + +// OpenGL expects int* as values for booleans +QT3D_UNIFORM_TYPE_IMPL(UniformType::Bool, int, glUniform1iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::BVec2, int, glUniform2iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::BVec3, int, glUniform3iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::BVec4, int, glUniform4iv) + +QT3D_UNIFORM_TYPE_IMPL(UniformType::Int, int, glUniform1iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::IVec2, int, glUniform2iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::IVec3, int, glUniform3iv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::IVec4, int, glUniform4iv) + +QT3D_UNIFORM_TYPE_IMPL(UniformType::UInt, uint, glUniform1uiv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::UIVec2, uint, glUniform2uiv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::UIVec3, uint, glUniform3uiv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::UIVec4, uint, glUniform4uiv) + +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat2, float, glUniformMatrix2fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat3, float, glUniformMatrix3fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat4, float, glUniformMatrix4fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat2x3, float, glUniformMatrix2x3fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat3x2, float, glUniformMatrix3x2fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat2x4, float, glUniformMatrix2x4fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat4x2, float, glUniformMatrix4x2fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat3x4, float, glUniformMatrix3x4fv) +QT3D_UNIFORM_TYPE_IMPL(UniformType::Mat4x3, float, glUniformMatrix4x3fv) + } // namespace Render } // namespace Qt3DRender of namespace diff --git a/src/render/graphicshelpers/graphicscontext_p.h b/src/render/graphicshelpers/graphicscontext_p.h index d1b21a1d6..647db9e47 100644 --- a/src/render/graphicshelpers/graphicscontext_p.h +++ b/src/render/graphicshelpers/graphicscontext_p.h @@ -60,7 +60,7 @@ #include <QMatrix4x4> #include <QBitArray> #include <QImage> -#include <Qt3DRender/private/quniformvalue_p.h> +#include <Qt3DRender/private/shaderparameterpack_p.h> #include <Qt3DRender/qclearbuffers.h> #include <Qt3DRender/private/shader_p.h> #include <Qt3DRender/private/glbuffer_p.h> @@ -68,6 +68,7 @@ #include <Qt3DRender/private/handle_types_p.h> #include <Qt3DRender/private/qgraphicsapifilter_p.h> #include <Qt3DRender/private/shadercache_p.h> +#include <Qt3DRender/private/uniform_p.h> QT_BEGIN_NAMESPACE @@ -183,10 +184,10 @@ public: // Wrapper methods void alphaTest(GLenum mode1, GLenum mode2); + void bindFramebuffer(GLuint fbo); void bindBufferBase(GLenum target, GLuint bindingIndex, GLuint buffer); void bindFragOutputs(GLuint shader, const QHash<QString, int> &outputs); void bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding); - void bindUniform(const QVariant &v, const ShaderUniform &description); void bindShaderStorageBlock(GLuint programId, GLuint shaderStorageBlockIndex, GLuint shaderStorageBlockBinding); void blendEquation(GLenum mode); void blendFunci(GLuint buf, GLenum sfactor, GLenum dfactor); @@ -314,8 +315,59 @@ private: void enableAttribute(const VAOVertexAttribute &attr); void disableAttribute(const VAOVertexAttribute &attr); + + void applyUniform(const ShaderUniform &description, const UniformValue &v); + + template<UniformType> + void applyUniformHelper(int, const UniformValue &) const + { + Q_ASSERT_X(false, Q_FUNC_INFO, "Uniform: Didn't provide specialized apply() implementation"); + } }; +#define QT3D_UNIFORM_TYPE_PROTO(UniformTypeEnum, BaseType, Func) \ +template<> \ +void GraphicsContext::applyUniformHelper<UniformTypeEnum>(int location, const UniformValue &value) const; + +#define QT3D_UNIFORM_TYPE_IMPL(UniformTypeEnum, BaseType, Func) \ + template<> \ + void GraphicsContext::applyUniformHelper<UniformTypeEnum>(int location, const UniformValue &value) const \ +{ \ + m_glHelper->Func(location, 1, value.constData<BaseType>()); \ +} + + +QT3D_UNIFORM_TYPE_PROTO(UniformType::Float, float, glUniform1fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Vec2, float, glUniform2fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Vec3, float, glUniform3fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Vec4, float, glUniform4fv) + +// OpenGL expects int* as values for booleans +QT3D_UNIFORM_TYPE_PROTO(UniformType::Bool, int, glUniform1iv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::BVec2, int, glUniform2iv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::BVec3, int, glUniform3iv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::BVec4, int, glUniform4iv) + +QT3D_UNIFORM_TYPE_PROTO(UniformType::Int, int, glUniform1iv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::IVec2, int, glUniform2iv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::IVec3, int, glUniform3iv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::IVec4, int, glUniform4iv) + +QT3D_UNIFORM_TYPE_PROTO(UniformType::UInt, uint, glUniform1uiv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::UIVec2, uint, glUniform2uiv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::UIVec3, uint, glUniform3uiv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::UIVec4, uint, glUniform4uiv) + +QT3D_UNIFORM_TYPE_PROTO(UniformType::Mat2, float, glUniformMatrix2fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Mat3, float, glUniformMatrix3fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Mat4, float, glUniformMatrix4fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Mat2x3, float, glUniformMatrix2x3fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Mat3x2, float, glUniformMatrix3x2fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Mat2x4, float, glUniformMatrix2x4fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Mat4x2, float, glUniformMatrix4x2fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Mat3x4, float, glUniformMatrix3x4fv) +QT3D_UNIFORM_TYPE_PROTO(UniformType::Mat4x3, float, glUniformMatrix4x3fv) + } // namespace Render } // namespace Qt3DRender diff --git a/src/render/graphicshelpers/graphicshelperes2.cpp b/src/render/graphicshelpers/graphicshelperes2.cpp index bf26fcc63..3a268cb5f 100644 --- a/src/render/graphicshelpers/graphicshelperes2.cpp +++ b/src/render/graphicshelpers/graphicshelperes2.cpp @@ -359,108 +359,6 @@ void GraphicsHelperES2::drawBuffers(GLsizei, const int *) qWarning() << "drawBuffers is not supported by ES 2.0"; } -void GraphicsHelperES2::bindUniform(const QVariant &v, const ShaderUniform &description) -{ - switch (description.m_type) { - - case GL_FLOAT: - m_funcs->glUniform1fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 1)); - break; - - case GL_FLOAT_VEC2: - m_funcs->glUniform2fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 2)); - break; - - case GL_FLOAT_VEC3: - m_funcs->glUniform3fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 3)); - break; - - case GL_FLOAT_VEC4: - m_funcs->glUniform4fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 4)); - break; - - case GL_FLOAT_MAT2: - m_funcs->glUniformMatrix2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 4)); - break; - - case GL_FLOAT_MAT3: - m_funcs->glUniformMatrix3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 9)); - break; - - case GL_FLOAT_MAT4: - m_funcs->glUniformMatrix4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 16)); - break; - - case GL_INT: - m_funcs->glUniform1iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 1)); - break; - - case GL_INT_VEC2: - m_funcs->glUniform2iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 2)); - break; - - case GL_INT_VEC3: - m_funcs->glUniform3iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 3)); - break; - - case GL_INT_VEC4: - m_funcs->glUniform4iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 4)); - break; - - case GL_BOOL: - m_funcs->glUniform1iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 1)); - break; - - case GL_BOOL_VEC2: - m_funcs->glUniform2iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 2)); - break; - - case GL_BOOL_VEC3: - m_funcs->glUniform3iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 3)); - break; - - case GL_BOOL_VEC4: - m_funcs->glUniform4iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 4)); - break; - - case GL_SAMPLER_2D: - case GL_SAMPLER_CUBE: { - Q_ASSERT(description.m_size == 1); - m_funcs->glUniform1i(description.m_location, v.toInt()); - break; - } - - // ES 3.0+ - case GL_SAMPLER_3D: - case GL_SAMPLER_2D_SHADOW: - case GL_SAMPLER_CUBE_SHADOW: - case GL_SAMPLER_2D_ARRAY: - case GL_SAMPLER_2D_ARRAY_SHADOW: - qWarning() << Q_FUNC_INFO << "ES 3.0 uniform type" << description.m_type << "for" - << description.m_name << "is not supported in ES 2.0"; - break; - - default: - qWarning() << Q_FUNC_INFO << "unsupported uniform type:" << description.m_type << "for " << description.m_name; - break; - } -} - void GraphicsHelperES2::bindFragDataLocation(GLuint , const QHash<QString, int> &) { qCritical() << "bindFragDataLocation is not supported by ES 2.0"; @@ -760,6 +658,49 @@ void GraphicsHelperES2::glUniformMatrix4x3fv(GLint , GLsizei , const GLfloat *) qWarning() << "glUniformMatrix4x3fv not supported by ES 2"; } +UniformType GraphicsHelperES2::uniformTypeFromGLType(GLenum type) +{ + switch (type) { + case GL_FLOAT: + return UniformType::Float; + case GL_FLOAT_VEC2: + return UniformType::Vec2; + case GL_FLOAT_VEC3: + return UniformType::Vec3; + case GL_FLOAT_VEC4: + return UniformType::Vec4; + case GL_FLOAT_MAT2: + return UniformType::Mat2; + case GL_FLOAT_MAT3: + return UniformType::Mat3; + case GL_FLOAT_MAT4: + return UniformType::Mat4; + case GL_INT: + return UniformType::Int; + case GL_INT_VEC2: + return UniformType::IVec2; + case GL_INT_VEC3: + return UniformType::IVec3; + case GL_INT_VEC4: + return UniformType::IVec4; + case GL_BOOL: + return UniformType::Bool; + case GL_BOOL_VEC2: + return UniformType::BVec2; + case GL_BOOL_VEC3: + return UniformType::BVec3; + case GL_BOOL_VEC4: + return UniformType::BVec4; + + case GL_SAMPLER_2D: + case GL_SAMPLER_CUBE: + return UniformType::Sampler; + default: + Q_UNREACHABLE(); + return UniformType::Float; + } +} + } // namespace Render } // namespace Qt3DRender diff --git a/src/render/graphicshelpers/graphicshelperes2_p.h b/src/render/graphicshelpers/graphicshelperes2_p.h index 0fd510a4d..52d68f691 100644 --- a/src/render/graphicshelpers/graphicshelperes2_p.h +++ b/src/render/graphicshelpers/graphicshelperes2_p.h @@ -74,7 +74,6 @@ public: void bindFrameBufferObject(GLuint frameBufferId) Q_DECL_OVERRIDE; void bindShaderStorageBlock(GLuint programId, GLuint shaderStorageBlockIndex, GLuint shaderStorageBlockBinding) Q_DECL_OVERRIDE; void bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) Q_DECL_OVERRIDE; - void bindUniform(const QVariant &v, const ShaderUniform &description) Q_DECL_OVERRIDE; void blendEquation(GLenum mode) Q_DECL_OVERRIDE; void blendFunci(GLuint buf, GLenum sfactor, GLenum dfactor) Q_DECL_OVERRIDE; void blendFuncSeparatei(GLuint buf, GLenum sRGB, GLenum dRGB, GLenum sAlpha, GLenum dAlpha) Q_DECL_OVERRIDE; @@ -144,6 +143,8 @@ public: void glUniformMatrix3x4fv(GLint location, GLsizei count, const GLfloat *value) Q_DECL_OVERRIDE; void glUniformMatrix4x3fv(GLint location, GLsizei count, const GLfloat *value) Q_DECL_OVERRIDE; + UniformType uniformTypeFromGLType(GLenum glType) Q_DECL_OVERRIDE; + protected: QOpenGLFunctions *m_funcs; }; diff --git a/src/render/graphicshelpers/graphicshelperes3.cpp b/src/render/graphicshelpers/graphicshelperes3.cpp index fe39d9d3f..eb492e98d 100644 --- a/src/render/graphicshelpers/graphicshelperes3.cpp +++ b/src/render/graphicshelpers/graphicshelperes3.cpp @@ -150,20 +150,17 @@ void GraphicsHelperES3::drawBuffers(GLsizei n, const int *bufs) m_extraFuncs->glDrawBuffers(n, drawBufs.constData()); } -void GraphicsHelperES3::bindUniform(const QVariant &v, const ShaderUniform &description) +UniformType GraphicsHelperES3::uniformTypeFromGLType(GLenum glType) { - switch (description.m_type) { + switch (glType) { case GL_SAMPLER_3D: case GL_SAMPLER_2D_SHADOW: case GL_SAMPLER_CUBE_SHADOW: case GL_SAMPLER_2D_ARRAY: case GL_SAMPLER_2D_ARRAY_SHADOW: - Q_ASSERT(description.m_size == 1); - m_funcs->glUniform1i(description.m_location, v.toInt()); - break; + return UniformType::Sampler; default: - GraphicsHelperES2::bindUniform(v, description); - break; + return GraphicsHelperES2::uniformTypeFromGLType(glType); } } diff --git a/src/render/graphicshelpers/graphicshelperes3_p.h b/src/render/graphicshelpers/graphicshelperes3_p.h index e5bb51c53..2844c140d 100644 --- a/src/render/graphicshelpers/graphicshelperes3_p.h +++ b/src/render/graphicshelpers/graphicshelperes3_p.h @@ -67,12 +67,14 @@ public: // QGraphicHelperInterface interface virtual void bindFrameBufferAttachment(QOpenGLTexture *texture, const Attachment &attachment) Q_DECL_OVERRIDE; - virtual void bindUniform(const QVariant &v, const ShaderUniform &description) Q_DECL_OVERRIDE; virtual void drawBuffers(GLsizei n, const int *bufs) Q_DECL_OVERRIDE; virtual void drawElementsInstancedBaseVertexBaseInstance(GLenum primitiveType, GLsizei primitiveCount, GLint indexType, void *indices, GLsizei instances, GLint baseVertex = 0, GLint baseInstance = 0) Q_DECL_OVERRIDE; virtual void initializeHelper(QOpenGLContext *context, QAbstractOpenGLFunctions *functions) Q_DECL_OVERRIDE; virtual bool supportsFeature(Feature feature) const Q_DECL_OVERRIDE; virtual void vertexAttribDivisor(GLuint index, GLuint divisor) Q_DECL_OVERRIDE; + + UniformType uniformTypeFromGLType(GLenum glType) Q_DECL_OVERRIDE; + protected: QOpenGLExtraFunctions *m_extraFuncs = Q_NULLPTR; }; diff --git a/src/render/graphicshelpers/graphicshelpergl2.cpp b/src/render/graphicshelpers/graphicshelpergl2.cpp index 6ab69b491..1315b4ab8 100644 --- a/src/render/graphicshelpers/graphicshelpergl2.cpp +++ b/src/render/graphicshelpers/graphicshelpergl2.cpp @@ -58,7 +58,7 @@ GraphicsHelperGL2::GraphicsHelperGL2() } void GraphicsHelperGL2::initializeHelper(QOpenGLContext *context, - QAbstractOpenGLFunctions *functions) + QAbstractOpenGLFunctions *functions) { Q_UNUSED(context); m_funcs = static_cast<QOpenGLFunctions_2_0*>(functions); @@ -95,9 +95,9 @@ void GraphicsHelperGL2::drawElementsInstancedBaseVertexBaseInstance(GLenum primi } void GraphicsHelperGL2::drawArraysInstanced(GLenum primitiveType, - GLint first, - GLsizei count, - GLsizei instances) + GLint first, + GLsizei count, + GLsizei instances) { for (GLint i = 0; i < instances; i++) drawArrays(primitiveType, @@ -116,10 +116,10 @@ void GraphicsHelperGL2::drawArraysInstancedBaseInstance(GLenum primitiveType, GL } void GraphicsHelperGL2::drawElements(GLenum primitiveType, - GLsizei primitiveCount, - GLint indexType, - void *indices, - GLint baseVertex) + GLsizei primitiveCount, + GLint indexType, + void *indices, + GLint baseVertex) { if (baseVertex != 0) qWarning() << "glDrawElementsBaseVertex is not supported with OpenGL 2"; @@ -131,8 +131,8 @@ void GraphicsHelperGL2::drawElements(GLenum primitiveType, } void GraphicsHelperGL2::drawArrays(GLenum primitiveType, - GLint first, - GLsizei count) + GLint first, + GLsizei count) { m_funcs->glDrawArrays(primitiveType, first, @@ -211,7 +211,7 @@ QVector<ShaderStorageBlock> GraphicsHelperGL2::programShaderStorageBlocks(GLuint } void GraphicsHelperGL2::vertexAttribDivisor(GLuint index, - GLuint divisor) + GLuint divisor) { Q_UNUSED(index); Q_UNUSED(divisor); @@ -358,98 +358,6 @@ void GraphicsHelperGL2::bindFragDataLocation(GLuint, const QHash<QString, int> & qCritical() << "bindFragDataLocation is not supported by GL 2.0"; } -void GraphicsHelperGL2::bindUniform(const QVariant &v, const ShaderUniform &description) -{ - switch (description.m_type) { - - case GL_FLOAT: - m_funcs->glUniform1fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 1)); - break; - - case GL_FLOAT_VEC2: - m_funcs->glUniform2fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 2)); - break; - - case GL_FLOAT_VEC3: - m_funcs->glUniform3fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 3)); - break; - - case GL_FLOAT_VEC4: - m_funcs->glUniform4fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 4)); - break; - - case GL_FLOAT_MAT2: - m_funcs->glUniformMatrix2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 4)); - break; - - case GL_FLOAT_MAT3: - m_funcs->glUniformMatrix3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 9)); - break; - - case GL_FLOAT_MAT4: - m_funcs->glUniformMatrix4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 16)); - break; - - case GL_INT: - m_funcs->glUniform1iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 1)); - break; - - case GL_INT_VEC2: - m_funcs->glUniform2iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 2)); - break; - - case GL_INT_VEC3: - m_funcs->glUniform3iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 3)); - break; - - case GL_INT_VEC4: - m_funcs->glUniform4iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 4)); - break; - - case GL_BOOL: - m_funcs->glUniform1iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 1)); - break; - - case GL_BOOL_VEC2: - m_funcs->glUniform2iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 2)); - break; - - case GL_BOOL_VEC3: - m_funcs->glUniform3iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 3)); - break; - - case GL_BOOL_VEC4: - m_funcs->glUniform4iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 4)); - break; - - case GL_SAMPLER_2D: - case GL_SAMPLER_CUBE: { - Q_ASSERT(description.m_size == 1); - m_funcs->glUniform1i(description.m_location, v.toInt()); - break; - } - - default: - qWarning() << Q_FUNC_INFO << "unsupported uniform type:" << description.m_type << "for " << description.m_name; - break; - } -} - void GraphicsHelperGL2::bindFrameBufferObject(GLuint frameBufferId) { if (m_fboFuncs != nullptr) @@ -775,6 +683,54 @@ void GraphicsHelperGL2::glUniformMatrix4x3fv(GLint , GLsizei , const GLfloat *) qWarning() << "glUniformMatrix4x3fv not supported by GL 2"; } +UniformType GraphicsHelperGL2::uniformTypeFromGLType(GLenum type) +{ + switch (type) { + case GL_FLOAT: + return UniformType::Float; + case GL_FLOAT_VEC2: + return UniformType::Vec2; + case GL_FLOAT_VEC3: + return UniformType::Vec3; + case GL_FLOAT_VEC4: + return UniformType::Vec4; + case GL_FLOAT_MAT2: + return UniformType::Mat2; + case GL_FLOAT_MAT3: + return UniformType::Mat3; + case GL_FLOAT_MAT4: + return UniformType::Mat4; + case GL_INT: + return UniformType::Int; + case GL_INT_VEC2: + return UniformType::IVec2; + case GL_INT_VEC3: + return UniformType::IVec3; + case GL_INT_VEC4: + return UniformType::IVec4; + case GL_BOOL: + return UniformType::Bool; + case GL_BOOL_VEC2: + return UniformType::BVec2; + case GL_BOOL_VEC3: + return UniformType::BVec3; + case GL_BOOL_VEC4: + return UniformType::BVec4; + + case GL_SAMPLER_1D: + case GL_SAMPLER_1D_SHADOW: + case GL_SAMPLER_2D: + case GL_SAMPLER_2D_SHADOW: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_3D: + return UniformType::Sampler; + + default: + Q_UNREACHABLE(); + return UniformType::Float; + } +} + } // namespace Render } // namespace Qt3DRender diff --git a/src/render/graphicshelpers/graphicshelpergl2_p.h b/src/render/graphicshelpers/graphicshelpergl2_p.h index 3b9c1e881..0352c77d3 100644 --- a/src/render/graphicshelpers/graphicshelpergl2_p.h +++ b/src/render/graphicshelpers/graphicshelpergl2_p.h @@ -76,7 +76,6 @@ public: void bindFrameBufferObject(GLuint frameBufferId) Q_DECL_OVERRIDE; void bindShaderStorageBlock(GLuint programId, GLuint shaderStorageBlockIndex, GLuint shaderStorageBlockBinding) Q_DECL_OVERRIDE; void bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) Q_DECL_OVERRIDE; - void bindUniform(const QVariant &v, const ShaderUniform &description) Q_DECL_OVERRIDE; void blendEquation(GLenum mode) Q_DECL_OVERRIDE; void blendFunci(GLuint buf, GLenum sfactor, GLenum dfactor) Q_DECL_OVERRIDE; void blendFuncSeparatei(GLuint buf, GLenum sRGB, GLenum dRGB, GLenum sAlpha, GLenum dAlpha) Q_DECL_OVERRIDE; @@ -146,6 +145,8 @@ public: void glUniformMatrix3x4fv(GLint location, GLsizei count, const GLfloat *value) Q_DECL_OVERRIDE; void glUniformMatrix4x3fv(GLint location, GLsizei count, const GLfloat *value) Q_DECL_OVERRIDE; + UniformType uniformTypeFromGLType(GLenum glType) Q_DECL_OVERRIDE; + private: QOpenGLFunctions_2_0 *m_funcs; QOpenGLExtension_ARB_framebuffer_object *m_fboFuncs; diff --git a/src/render/graphicshelpers/graphicshelpergl3.cpp b/src/render/graphicshelpers/graphicshelpergl3.cpp index 52028b1c9..da1b95db8 100644 --- a/src/render/graphicshelpers/graphicshelpergl3.cpp +++ b/src/render/graphicshelpers/graphicshelpergl3.cpp @@ -410,182 +410,6 @@ void GraphicsHelperGL3::bindFragDataLocation(GLuint shader, const QHash<QString, m_funcs->glBindFragDataLocation(shader, it.value(), it.key().toStdString().c_str()); } -void GraphicsHelperGL3::bindUniform(const QVariant &v, const ShaderUniform &description) -{ - switch (description.m_type) { - - case GL_FLOAT: - m_funcs->glUniform1fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 1)); - break; - - case GL_FLOAT_VEC2: - m_funcs->glUniform2fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 2)); - break; - - case GL_FLOAT_VEC3: - m_funcs->glUniform3fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 3)); - break; - - case GL_FLOAT_VEC4: - m_funcs->glUniform4fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 4)); - break; - - case GL_FLOAT_MAT2: - m_funcs->glUniformMatrix2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 4)); - break; - - case GL_FLOAT_MAT2x3: - m_funcs->glUniformMatrix2x3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 6)); - break; - - case GL_FLOAT_MAT2x4: - m_funcs->glUniformMatrix2x4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 8)); - break; - - case GL_FLOAT_MAT3: - m_funcs->glUniformMatrix3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 9)); - break; - - case GL_FLOAT_MAT3x2: - m_funcs->glUniformMatrix3x2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 6)); - break; - - case GL_FLOAT_MAT3x4: - m_funcs->glUniformMatrix3x4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 12)); - break; - - case GL_FLOAT_MAT4: - m_funcs->glUniformMatrix4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 16)); - break; - - case GL_FLOAT_MAT4x2: - m_funcs->glUniformMatrix4x2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 8)); - break; - - case GL_FLOAT_MAT4x3: - m_funcs->glUniformMatrix4x3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 12)); - break; - - case GL_INT: - m_funcs->glUniform1iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 1)); - break; - - case GL_INT_VEC2: - m_funcs->glUniform2iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 2)); - break; - - case GL_INT_VEC3: - m_funcs->glUniform3iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 3)); - break; - - case GL_INT_VEC4: - m_funcs->glUniform4iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 4)); - break; - - case GL_UNSIGNED_INT: - m_funcs->glUniform1uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 1)); - break; - - case GL_UNSIGNED_INT_VEC2: - m_funcs->glUniform2uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 2)); - break; - - case GL_UNSIGNED_INT_VEC3: - m_funcs->glUniform3uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 3)); - break; - - case GL_UNSIGNED_INT_VEC4: - m_funcs->glUniform4uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 4)); - break; - - case GL_BOOL: - m_funcs->glUniform1iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 1)); - break; - - case GL_BOOL_VEC2: - m_funcs->glUniform2iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 2)); - break; - - case GL_BOOL_VEC3: - m_funcs->glUniform3iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 3)); - break; - - case GL_BOOL_VEC4: - m_funcs->glUniform4iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 4)); - break; - - case GL_SAMPLER_1D: - case GL_SAMPLER_2D: - case GL_SAMPLER_3D: - case GL_SAMPLER_CUBE: - case GL_SAMPLER_BUFFER: - case GL_SAMPLER_2D_RECT: - case GL_INT_SAMPLER_1D: - case GL_INT_SAMPLER_2D: - case GL_INT_SAMPLER_3D: - case GL_INT_SAMPLER_CUBE: - case GL_INT_SAMPLER_BUFFER: - case GL_INT_SAMPLER_2D_RECT: - case GL_UNSIGNED_INT_SAMPLER_1D: - case GL_UNSIGNED_INT_SAMPLER_2D: - case GL_UNSIGNED_INT_SAMPLER_3D: - case GL_UNSIGNED_INT_SAMPLER_CUBE: - case GL_UNSIGNED_INT_SAMPLER_BUFFER: - case GL_UNSIGNED_INT_SAMPLER_2D_RECT: - case GL_SAMPLER_1D_SHADOW: - case GL_SAMPLER_2D_SHADOW: - case GL_SAMPLER_CUBE_SHADOW: - case GL_SAMPLER_1D_ARRAY: - case GL_SAMPLER_2D_ARRAY: - case GL_INT_SAMPLER_1D_ARRAY: - case GL_INT_SAMPLER_2D_ARRAY: - case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: - case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: - case GL_SAMPLER_1D_ARRAY_SHADOW: - case GL_SAMPLER_2D_ARRAY_SHADOW: - case GL_SAMPLER_2D_RECT_SHADOW: - case GL_SAMPLER_2D_MULTISAMPLE: - case GL_INT_SAMPLER_2D_MULTISAMPLE: - case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: - case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: - case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: - case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: { - Q_ASSERT(description.m_size == 1); - m_funcs->glUniform1i(description.m_location, v.toInt()); - break; - } - - default: - qWarning() << Q_FUNC_INFO << "unsupported uniform type:" << description.m_type << "for " << description.m_name; - break; - } -} - void GraphicsHelperGL3::bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) { m_funcs->glUniformBlockBinding(programId, uniformBlockIndex, uniformBlockBinding); @@ -1139,6 +963,88 @@ void GraphicsHelperGL3::glUniformMatrix4x3fv(GLint location, GLsizei count, cons m_funcs->glUniformMatrix4x3fv(location, count, false, values); } +UniformType GraphicsHelperGL3::uniformTypeFromGLType(GLenum type) +{ + switch (type) { + case GL_FLOAT: + return UniformType::Float; + case GL_FLOAT_VEC2: + return UniformType::Vec2; + case GL_FLOAT_VEC3: + return UniformType::Vec3; + case GL_FLOAT_VEC4: + return UniformType::Vec4; + case GL_FLOAT_MAT2: + return UniformType::Mat2; + case GL_FLOAT_MAT3: + return UniformType::Mat3; + case GL_FLOAT_MAT4: + return UniformType::Mat4; + case GL_FLOAT_MAT2x3: + return UniformType::Mat2x3; + case GL_FLOAT_MAT3x2: + return UniformType::Mat3x2; + case GL_FLOAT_MAT2x4: + return UniformType::Mat2x4; + case GL_FLOAT_MAT4x2: + return UniformType::Mat4x2; + case GL_FLOAT_MAT3x4: + return UniformType::Mat3x4; + case GL_FLOAT_MAT4x3: + return UniformType::Mat4x3; + case GL_INT: + return UniformType::Int; + case GL_INT_VEC2: + return UniformType::IVec2; + case GL_INT_VEC3: + return UniformType::IVec3; + case GL_INT_VEC4: + return UniformType::IVec4; + case GL_BOOL: + return UniformType::Bool; + case GL_BOOL_VEC2: + return UniformType::BVec2; + case GL_BOOL_VEC3: + return UniformType::BVec3; + case GL_BOOL_VEC4: + return UniformType::BVec4; + + case GL_SAMPLER_1D: + case GL_SAMPLER_1D_SHADOW: + case GL_SAMPLER_2D: + case GL_SAMPLER_2D_RECT: + case GL_SAMPLER_2D_SHADOW: + case GL_SAMPLER_2D_RECT_SHADOW: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_CUBE_SHADOW: + case GL_SAMPLER_2D_ARRAY: + case GL_SAMPLER_2D_ARRAY_SHADOW: + case GL_SAMPLER_2D_MULTISAMPLE: + case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: + case GL_SAMPLER_3D: + case GL_INT_SAMPLER_1D: + case GL_INT_SAMPLER_2D: + case GL_INT_SAMPLER_3D: + case GL_INT_SAMPLER_CUBE: + case GL_INT_SAMPLER_1D_ARRAY: + case GL_INT_SAMPLER_2D_ARRAY: + case GL_INT_SAMPLER_2D_MULTISAMPLE: + case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_1D: + case GL_UNSIGNED_INT_SAMPLER_2D: + case GL_UNSIGNED_INT_SAMPLER_3D: + case GL_UNSIGNED_INT_SAMPLER_CUBE: + case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: + case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: + return UniformType::Sampler; + default: + Q_UNREACHABLE(); + return UniformType::Float; + } +} + } // namespace Render } // namespace Qt3DRender diff --git a/src/render/graphicshelpers/graphicshelpergl3_3.cpp b/src/render/graphicshelpers/graphicshelpergl3_3.cpp index e701887a9..53b89bdef 100644 --- a/src/render/graphicshelpers/graphicshelpergl3_3.cpp +++ b/src/render/graphicshelpers/graphicshelpergl3_3.cpp @@ -76,6 +76,10 @@ GraphicsHelperGL3_3::GraphicsHelperGL3_3() { } +GraphicsHelperGL3_3::~GraphicsHelperGL3_3() +{ +} + void GraphicsHelperGL3_3::initializeHelper(QOpenGLContext *context, QAbstractOpenGLFunctions *functions) { @@ -383,6 +387,7 @@ bool GraphicsHelperGL3_3::supportsFeature(GraphicsHelperInterface::Feature featu case PrimitiveRestart: case RenderBufferDimensionRetrieval: case TextureDimensionRetrieval: + case BindableFragmentOutputs: return true; case Tessellation: return !m_tessFuncs.isNull(); @@ -407,182 +412,6 @@ void GraphicsHelperGL3_3::bindFragDataLocation(GLuint shader, const QHash<QStrin m_funcs->glBindFragDataLocation(shader, it.value(), it.key().toStdString().c_str()); } -void GraphicsHelperGL3_3::bindUniform(const QVariant &v, const ShaderUniform &description) -{ - switch (description.m_type) { - - case GL_FLOAT: - m_funcs->glUniform1fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 1)); - break; - - case GL_FLOAT_VEC2: - m_funcs->glUniform2fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 2)); - break; - - case GL_FLOAT_VEC3: - m_funcs->glUniform3fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 3)); - break; - - case GL_FLOAT_VEC4: - m_funcs->glUniform4fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 4)); - break; - - case GL_FLOAT_MAT2: - m_funcs->glUniformMatrix2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 4)); - break; - - case GL_FLOAT_MAT2x3: - m_funcs->glUniformMatrix2x3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 6)); - break; - - case GL_FLOAT_MAT2x4: - m_funcs->glUniformMatrix2x4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 8)); - break; - - case GL_FLOAT_MAT3: - m_funcs->glUniformMatrix3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 9)); - break; - - case GL_FLOAT_MAT3x2: - m_funcs->glUniformMatrix3x2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 6)); - break; - - case GL_FLOAT_MAT3x4: - m_funcs->glUniformMatrix3x4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 12)); - break; - - case GL_FLOAT_MAT4: - m_funcs->glUniformMatrix4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 16)); - break; - - case GL_FLOAT_MAT4x2: - m_funcs->glUniformMatrix4x2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 8)); - break; - - case GL_FLOAT_MAT4x3: - m_funcs->glUniformMatrix4x3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 12)); - break; - - case GL_INT: - m_funcs->glUniform1iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 1)); - break; - - case GL_INT_VEC2: - m_funcs->glUniform2iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 2)); - break; - - case GL_INT_VEC3: - m_funcs->glUniform3iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 3)); - break; - - case GL_INT_VEC4: - m_funcs->glUniform4iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 4)); - break; - - case GL_UNSIGNED_INT: - m_funcs->glUniform1uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 1)); - break; - - case GL_UNSIGNED_INT_VEC2: - m_funcs->glUniform2uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 2)); - break; - - case GL_UNSIGNED_INT_VEC3: - m_funcs->glUniform3uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 3)); - break; - - case GL_UNSIGNED_INT_VEC4: - m_funcs->glUniform4uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 4)); - break; - - case GL_BOOL: - m_funcs->glUniform1iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 1)); - break; - - case GL_BOOL_VEC2: - m_funcs->glUniform2iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 2)); - break; - - case GL_BOOL_VEC3: - m_funcs->glUniform3iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 3)); - break; - - case GL_BOOL_VEC4: - m_funcs->glUniform4iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 4)); - break; - - case GL_SAMPLER_1D: - case GL_SAMPLER_2D: - case GL_SAMPLER_3D: - case GL_SAMPLER_CUBE: - case GL_SAMPLER_BUFFER: - case GL_SAMPLER_2D_RECT: - case GL_INT_SAMPLER_1D: - case GL_INT_SAMPLER_2D: - case GL_INT_SAMPLER_3D: - case GL_INT_SAMPLER_CUBE: - case GL_INT_SAMPLER_BUFFER: - case GL_INT_SAMPLER_2D_RECT: - case GL_UNSIGNED_INT_SAMPLER_1D: - case GL_UNSIGNED_INT_SAMPLER_2D: - case GL_UNSIGNED_INT_SAMPLER_3D: - case GL_UNSIGNED_INT_SAMPLER_CUBE: - case GL_UNSIGNED_INT_SAMPLER_BUFFER: - case GL_UNSIGNED_INT_SAMPLER_2D_RECT: - case GL_SAMPLER_1D_SHADOW: - case GL_SAMPLER_2D_SHADOW: - case GL_SAMPLER_CUBE_SHADOW: - case GL_SAMPLER_1D_ARRAY: - case GL_SAMPLER_2D_ARRAY: - case GL_INT_SAMPLER_1D_ARRAY: - case GL_INT_SAMPLER_2D_ARRAY: - case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: - case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: - case GL_SAMPLER_1D_ARRAY_SHADOW: - case GL_SAMPLER_2D_ARRAY_SHADOW: - case GL_SAMPLER_2D_RECT_SHADOW: - case GL_SAMPLER_2D_MULTISAMPLE: - case GL_INT_SAMPLER_2D_MULTISAMPLE: - case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: - case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: - case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: - case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: { - Q_ASSERT(description.m_size == 1); - m_funcs->glUniform1i(description.m_location, v.toInt()); - break; - } - - default: - qWarning() << Q_FUNC_INFO << "unsupported uniform type:" << description.m_type << "for " << description.m_name; - break; - } -} - void GraphicsHelperGL3_3::bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) { m_funcs->glUniformBlockBinding(programId, uniformBlockIndex, uniformBlockBinding); @@ -1138,6 +967,100 @@ void GraphicsHelperGL3_3::glUniformMatrix4x3fv(GLint location, GLsizei count, co m_funcs->glUniformMatrix4x3fv(location, count, false, values); } +UniformType GraphicsHelperGL3_3::uniformTypeFromGLType(GLenum type) +{ + switch (type) { + case GL_FLOAT: + return UniformType::Float; + case GL_FLOAT_VEC2: + return UniformType::Vec2; + case GL_FLOAT_VEC3: + return UniformType::Vec3; + case GL_FLOAT_VEC4: + return UniformType::Vec4; + case GL_FLOAT_MAT2: + return UniformType::Mat2; + case GL_FLOAT_MAT3: + return UniformType::Mat3; + case GL_FLOAT_MAT4: + return UniformType::Mat4; + case GL_FLOAT_MAT2x3: + return UniformType::Mat2x3; + case GL_FLOAT_MAT3x2: + return UniformType::Mat3x2; + case GL_FLOAT_MAT2x4: + return UniformType::Mat2x4; + case GL_FLOAT_MAT4x2: + return UniformType::Mat4x2; + case GL_FLOAT_MAT3x4: + return UniformType::Mat3x4; + case GL_FLOAT_MAT4x3: + return UniformType::Mat4x3; + case GL_INT: + return UniformType::Int; + case GL_INT_VEC2: + return UniformType::IVec2; + case GL_INT_VEC3: + return UniformType::IVec3; + case GL_INT_VEC4: + return UniformType::IVec4; + case GL_UNSIGNED_INT: + return UniformType::UInt; + case GL_UNSIGNED_INT_VEC2: + return UniformType::UIVec2; + case GL_UNSIGNED_INT_VEC3: + return UniformType::UIVec3; + case GL_UNSIGNED_INT_VEC4: + return UniformType::UIVec4; + case GL_BOOL: + return UniformType::Bool; + case GL_BOOL_VEC2: + return UniformType::BVec2; + case GL_BOOL_VEC3: + return UniformType::BVec3; + case GL_BOOL_VEC4: + return UniformType::BVec4; + + case GL_SAMPLER_BUFFER: + case GL_SAMPLER_1D: + case GL_SAMPLER_1D_SHADOW: + case GL_SAMPLER_1D_ARRAY: + case GL_SAMPLER_2D: + case GL_SAMPLER_2D_RECT: + case GL_SAMPLER_2D_SHADOW: + case GL_SAMPLER_2D_RECT_SHADOW: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_CUBE_SHADOW: + case GL_SAMPLER_2D_ARRAY: + case GL_SAMPLER_2D_ARRAY_SHADOW: + case GL_SAMPLER_2D_MULTISAMPLE: + case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: + case GL_SAMPLER_3D: + case GL_INT_SAMPLER_BUFFER: + case GL_INT_SAMPLER_1D: + case GL_INT_SAMPLER_2D: + case GL_INT_SAMPLER_3D: + case GL_INT_SAMPLER_CUBE: + case GL_INT_SAMPLER_1D_ARRAY: + case GL_INT_SAMPLER_2D_ARRAY: + case GL_INT_SAMPLER_2D_MULTISAMPLE: + case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_BUFFER: + case GL_UNSIGNED_INT_SAMPLER_1D: + case GL_UNSIGNED_INT_SAMPLER_2D: + case GL_UNSIGNED_INT_SAMPLER_3D: + case GL_UNSIGNED_INT_SAMPLER_CUBE: + case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: + case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: + return UniformType::Sampler; + default: + Q_UNREACHABLE(); + return UniformType::Float; + } +} + } // namespace Render } // namespace Qt3DRender diff --git a/src/render/graphicshelpers/graphicshelpergl3_3_p.h b/src/render/graphicshelpers/graphicshelpergl3_3_p.h index de26f86f7..bbea8806a 100644 --- a/src/render/graphicshelpers/graphicshelpergl3_3_p.h +++ b/src/render/graphicshelpers/graphicshelpergl3_3_p.h @@ -64,10 +64,11 @@ class QOpenGLExtension_ARB_tessellation_shader; namespace Qt3DRender { namespace Render { -class GraphicsHelperGL3_3 : public GraphicsHelperInterface +class Q_AUTOTEST_EXPORT GraphicsHelperGL3_3 : public GraphicsHelperInterface { public: GraphicsHelperGL3_3(); + ~GraphicsHelperGL3_3(); // QGraphicHelperInterface interface void alphaTest(GLenum mode1, GLenum mode2) Q_DECL_OVERRIDE; @@ -77,7 +78,6 @@ public: void bindFrameBufferObject(GLuint frameBufferId) Q_DECL_OVERRIDE; void bindShaderStorageBlock(GLuint programId, GLuint shaderStorageBlockIndex, GLuint shaderStorageBlockBinding) Q_DECL_OVERRIDE; void bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) Q_DECL_OVERRIDE; - void bindUniform(const QVariant &v, const ShaderUniform &description) Q_DECL_OVERRIDE; void blendEquation(GLenum mode) Q_DECL_OVERRIDE; void blendFunci(GLuint buf, GLenum sfactor, GLenum dfactor) Q_DECL_OVERRIDE; void blendFuncSeparatei(GLuint buf, GLenum sRGB, GLenum dRGB, GLenum sAlpha, GLenum dAlpha) Q_DECL_OVERRIDE; @@ -147,6 +147,8 @@ public: void glUniformMatrix3x4fv(GLint location, GLsizei count, const GLfloat *value) Q_DECL_OVERRIDE; void glUniformMatrix4x3fv(GLint location, GLsizei count, const GLfloat *value) Q_DECL_OVERRIDE; + UniformType uniformTypeFromGLType(GLenum glType) Q_DECL_OVERRIDE; + private: QOpenGLFunctions_3_3_Core *m_funcs; QScopedPointer<QOpenGLExtension_ARB_tessellation_shader> m_tessFuncs; diff --git a/src/render/graphicshelpers/graphicshelpergl3_p.h b/src/render/graphicshelpers/graphicshelpergl3_p.h index 559b4c97d..3cc58bd26 100644 --- a/src/render/graphicshelpers/graphicshelpergl3_p.h +++ b/src/render/graphicshelpers/graphicshelpergl3_p.h @@ -77,7 +77,6 @@ public: void bindFrameBufferObject(GLuint frameBufferId) Q_DECL_OVERRIDE; void bindShaderStorageBlock(GLuint programId, GLuint shaderStorageBlockIndex, GLuint shaderStorageBlockBinding) Q_DECL_OVERRIDE; void bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) Q_DECL_OVERRIDE; - void bindUniform(const QVariant &v, const ShaderUniform &description) Q_DECL_OVERRIDE; void blendEquation(GLenum mode) Q_DECL_OVERRIDE; void blendFunci(GLuint buf, GLenum sfactor, GLenum dfactor) Q_DECL_OVERRIDE; void blendFuncSeparatei(GLuint buf, GLenum sRGB, GLenum dRGB, GLenum sAlpha, GLenum dAlpha) Q_DECL_OVERRIDE; @@ -147,6 +146,8 @@ public: void glUniformMatrix3x4fv(GLint location, GLsizei count, const GLfloat *value) Q_DECL_OVERRIDE; void glUniformMatrix4x3fv(GLint location, GLsizei count, const GLfloat *value) Q_DECL_OVERRIDE; + UniformType uniformTypeFromGLType(GLenum glType) Q_DECL_OVERRIDE; + private: QOpenGLFunctions_3_2_Core *m_funcs; QScopedPointer<QOpenGLExtension_ARB_tessellation_shader> m_tessFuncs; diff --git a/src/render/graphicshelpers/graphicshelpergl4.cpp b/src/render/graphicshelpers/graphicshelpergl4.cpp index cd63bcd82..230b02a63 100644 --- a/src/render/graphicshelpers/graphicshelpergl4.cpp +++ b/src/render/graphicshelpers/graphicshelpergl4.cpp @@ -371,6 +371,105 @@ void GraphicsHelperGL4::glUniformMatrix4x3fv(GLint location, GLsizei count, cons m_funcs->glUniformMatrix4x3fv(location, count, false, values); } +UniformType GraphicsHelperGL4::uniformTypeFromGLType(GLenum type) +{ + switch (type) { + case GL_FLOAT: + return UniformType::Float; + case GL_FLOAT_VEC2: + return UniformType::Vec2; + case GL_FLOAT_VEC3: + return UniformType::Vec3; + case GL_FLOAT_VEC4: + return UniformType::Vec4; + case GL_FLOAT_MAT2: + return UniformType::Mat2; + case GL_FLOAT_MAT3: + return UniformType::Mat3; + case GL_FLOAT_MAT4: + return UniformType::Mat4; + case GL_FLOAT_MAT2x3: + return UniformType::Mat2x3; + case GL_FLOAT_MAT3x2: + return UniformType::Mat3x2; + case GL_FLOAT_MAT2x4: + return UniformType::Mat2x4; + case GL_FLOAT_MAT4x2: + return UniformType::Mat4x2; + case GL_FLOAT_MAT3x4: + return UniformType::Mat3x4; + case GL_FLOAT_MAT4x3: + return UniformType::Mat4x3; + case GL_INT: + return UniformType::Int; + case GL_INT_VEC2: + return UniformType::IVec2; + case GL_INT_VEC3: + return UniformType::IVec3; + case GL_INT_VEC4: + return UniformType::IVec4; + case GL_UNSIGNED_INT: + return UniformType::UInt; + case GL_UNSIGNED_INT_VEC2: + return UniformType::UIVec2; + case GL_UNSIGNED_INT_VEC3: + return UniformType::UIVec3; + case GL_UNSIGNED_INT_VEC4: + return UniformType::UIVec4; + case GL_BOOL: + return UniformType::Bool; + case GL_BOOL_VEC2: + return UniformType::BVec2; + case GL_BOOL_VEC3: + return UniformType::BVec3; + case GL_BOOL_VEC4: + return UniformType::BVec4; + + case GL_SAMPLER_1D: + case GL_SAMPLER_1D_ARRAY: + case GL_SAMPLER_1D_SHADOW: + case GL_SAMPLER_2D: + case GL_SAMPLER_2D_RECT: + case GL_SAMPLER_2D_SHADOW: + case GL_SAMPLER_2D_RECT_SHADOW: + case GL_SAMPLER_CUBE: + case GL_SAMPLER_CUBE_SHADOW: + case GL_SAMPLER_CUBE_MAP_ARRAY: + case GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW: + case GL_SAMPLER_2D_ARRAY: + case GL_SAMPLER_2D_ARRAY_SHADOW: + case GL_SAMPLER_2D_MULTISAMPLE: + case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: + case GL_SAMPLER_3D: + case GL_SAMPLER_BUFFER: + case GL_INT_SAMPLER_1D: + case GL_INT_SAMPLER_2D: + case GL_INT_SAMPLER_3D: + case GL_INT_SAMPLER_BUFFER: + case GL_INT_SAMPLER_CUBE: + case GL_INT_SAMPLER_CUBE_MAP_ARRAY: + case GL_INT_SAMPLER_1D_ARRAY: + case GL_INT_SAMPLER_2D_ARRAY: + case GL_INT_SAMPLER_2D_MULTISAMPLE: + case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_1D: + case GL_UNSIGNED_INT_SAMPLER_2D: + case GL_UNSIGNED_INT_SAMPLER_3D: + case GL_UNSIGNED_INT_SAMPLER_BUFFER: + case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: + case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: + case GL_UNSIGNED_INT_SAMPLER_CUBE: + case GL_UNSIGNED_INT_SAMPLER_CUBE_MAP_ARRAY: + return UniformType::Sampler; + default: + // TO DO: Add support for Doubles and Images + Q_UNREACHABLE(); + return UniformType::Float; + } +} + void GraphicsHelperGL4::blendEquation(GLenum mode) { m_funcs->glBlendEquation(mode); @@ -480,6 +579,8 @@ bool GraphicsHelperGL4::supportsFeature(GraphicsHelperInterface::Feature feature case MRT: case Tessellation: case UniformBufferObject: + case BindableFragmentOutputs: + case PrimitiveRestart: case RenderBufferDimensionRetrieval: case TextureDimensionRetrieval: case ShaderStorageObject: @@ -507,182 +608,6 @@ void GraphicsHelperGL4::bindFragDataLocation(GLuint shader, const QHash<QString, m_funcs->glBindFragDataLocation(shader, it.value(), it.key().toStdString().c_str()); } -void GraphicsHelperGL4::bindUniform(const QVariant &v, const ShaderUniform &description) -{ - switch (description.m_type) { - - case GL_FLOAT: - m_funcs->glUniform1fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 1)); - break; - - case GL_FLOAT_VEC2: - m_funcs->glUniform2fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 2)); - break; - - case GL_FLOAT_VEC3: - m_funcs->glUniform3fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 3)); - break; - - case GL_FLOAT_VEC4: - m_funcs->glUniform4fv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 4)); - break; - - case GL_FLOAT_MAT2: - m_funcs->glUniformMatrix2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 4)); - break; - - case GL_FLOAT_MAT2x3: - m_funcs->glUniformMatrix2x3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 6)); - break; - - case GL_FLOAT_MAT2x4: - m_funcs->glUniformMatrix2x4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 8)); - break; - - case GL_FLOAT_MAT3: - m_funcs->glUniformMatrix3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 9)); - break; - - case GL_FLOAT_MAT3x2: - m_funcs->glUniformMatrix3x2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 6)); - break; - - case GL_FLOAT_MAT3x4: - m_funcs->glUniformMatrix3x4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 12)); - break; - - case GL_FLOAT_MAT4: - m_funcs->glUniformMatrix4fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 16)); - break; - - case GL_FLOAT_MAT4x2: - m_funcs->glUniformMatrix4x2fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 8)); - break; - - case GL_FLOAT_MAT4x3: - m_funcs->glUniformMatrix4x3fv(description.m_location, description.m_size, GL_FALSE, - QGraphicsUtils::valueArrayFromVariant<GLfloat>(v, description.m_size, 12)); - break; - - case GL_INT: - m_funcs->glUniform1iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 1)); - break; - - case GL_INT_VEC2: - m_funcs->glUniform2iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 2)); - break; - - case GL_INT_VEC3: - m_funcs->glUniform3iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 3)); - break; - - case GL_INT_VEC4: - m_funcs->glUniform4iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 4)); - break; - - case GL_UNSIGNED_INT: - m_funcs->glUniform1uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 1)); - break; - - case GL_UNSIGNED_INT_VEC2: - m_funcs->glUniform2uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 2)); - break; - - case GL_UNSIGNED_INT_VEC3: - m_funcs->glUniform3uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 3)); - break; - - case GL_UNSIGNED_INT_VEC4: - m_funcs->glUniform4uiv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLuint>(v, description.m_size, 4)); - break; - - case GL_BOOL: - m_funcs->glUniform1iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 1)); - break; - - case GL_BOOL_VEC2: - m_funcs->glUniform2iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 2)); - break; - - case GL_BOOL_VEC3: - m_funcs->glUniform3iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 3)); - break; - - case GL_BOOL_VEC4: - m_funcs->glUniform4iv(description.m_location, description.m_size, - QGraphicsUtils::valueArrayFromVariant<GLint>(v, description.m_size, 4)); - break; - - case GL_SAMPLER_1D: - case GL_SAMPLER_2D: - case GL_SAMPLER_3D: - case GL_SAMPLER_CUBE: - case GL_SAMPLER_BUFFER: - case GL_SAMPLER_2D_RECT: - case GL_INT_SAMPLER_1D: - case GL_INT_SAMPLER_2D: - case GL_INT_SAMPLER_3D: - case GL_INT_SAMPLER_CUBE: - case GL_INT_SAMPLER_BUFFER: - case GL_INT_SAMPLER_2D_RECT: - case GL_UNSIGNED_INT_SAMPLER_1D: - case GL_UNSIGNED_INT_SAMPLER_2D: - case GL_UNSIGNED_INT_SAMPLER_3D: - case GL_UNSIGNED_INT_SAMPLER_CUBE: - case GL_UNSIGNED_INT_SAMPLER_BUFFER: - case GL_UNSIGNED_INT_SAMPLER_2D_RECT: - case GL_SAMPLER_1D_SHADOW: - case GL_SAMPLER_2D_SHADOW: - case GL_SAMPLER_CUBE_SHADOW: - case GL_SAMPLER_1D_ARRAY: - case GL_SAMPLER_2D_ARRAY: - case GL_INT_SAMPLER_1D_ARRAY: - case GL_INT_SAMPLER_2D_ARRAY: - case GL_UNSIGNED_INT_SAMPLER_1D_ARRAY: - case GL_UNSIGNED_INT_SAMPLER_2D_ARRAY: - case GL_SAMPLER_1D_ARRAY_SHADOW: - case GL_SAMPLER_2D_ARRAY_SHADOW: - case GL_SAMPLER_2D_RECT_SHADOW: - case GL_SAMPLER_2D_MULTISAMPLE: - case GL_INT_SAMPLER_2D_MULTISAMPLE: - case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE: - case GL_SAMPLER_2D_MULTISAMPLE_ARRAY: - case GL_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: - case GL_UNSIGNED_INT_SAMPLER_2D_MULTISAMPLE_ARRAY: { - Q_ASSERT(description.m_size == 1); - m_funcs->glUniform1i(description.m_location, v.toInt()); - break; - } - - default: - qWarning() << Q_FUNC_INFO << "unsupported uniform type:" << description.m_type << "for " << description.m_name; - break; - } -} - void GraphicsHelperGL4::bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) { m_funcs->glUniformBlockBinding(programId, uniformBlockIndex, uniformBlockBinding); diff --git a/src/render/graphicshelpers/graphicshelpergl4_p.h b/src/render/graphicshelpers/graphicshelpergl4_p.h index 0333b4258..ad4875f2e 100644 --- a/src/render/graphicshelpers/graphicshelpergl4_p.h +++ b/src/render/graphicshelpers/graphicshelpergl4_p.h @@ -76,7 +76,6 @@ public: void bindFrameBufferObject(GLuint frameBufferId) Q_DECL_OVERRIDE; void bindShaderStorageBlock(GLuint programId, GLuint shaderStorageBlockIndex, GLuint shaderStorageBlockBinding) Q_DECL_OVERRIDE; void bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) Q_DECL_OVERRIDE; - void bindUniform(const QVariant &v, const ShaderUniform &description) Q_DECL_OVERRIDE; void blendEquation(GLenum mode) Q_DECL_OVERRIDE; void blendFunci(GLuint buf, GLenum sfactor, GLenum dfactor) Q_DECL_OVERRIDE; void blendFuncSeparatei(GLuint buf, GLenum sRGB, GLenum dRGB, GLenum sAlpha, GLenum dAlpha) Q_DECL_OVERRIDE; @@ -146,6 +145,8 @@ public: void glUniformMatrix3x4fv(GLint location, GLsizei count, const GLfloat *value) Q_DECL_OVERRIDE; void glUniformMatrix4x3fv(GLint location, GLsizei count, const GLfloat *value) Q_DECL_OVERRIDE; + UniformType uniformTypeFromGLType(GLenum glType) Q_DECL_OVERRIDE; + private: QOpenGLFunctions_4_3_Core *m_funcs; }; diff --git a/src/render/graphicshelpers/graphicshelperinterface_p.h b/src/render/graphicshelpers/graphicshelperinterface_p.h index 355c8f429..1a7199a2c 100644 --- a/src/render/graphicshelpers/graphicshelperinterface_p.h +++ b/src/render/graphicshelpers/graphicshelperinterface_p.h @@ -55,6 +55,7 @@ #include <QOpenGLTexture> #include <QVector> #include <Qt3DRender/private/shadervariables_p.h> +#include <Qt3DRender/private/uniform_p.h> QT_BEGIN_NAMESPACE @@ -87,7 +88,6 @@ public: virtual void bindFrameBufferObject(GLuint frameBufferId) = 0; virtual void bindShaderStorageBlock(GLuint programId, GLuint shaderStorageBlockIndex, GLuint shaderStorageBlockBinding) = 0; virtual void bindUniformBlock(GLuint programId, GLuint uniformBlockIndex, GLuint uniformBlockBinding) = 0; - virtual void bindUniform(const QVariant &v, const ShaderUniform &description) = 0; virtual void blendEquation(GLenum mode) = 0; virtual void blendFunci(GLuint buf, GLenum sfactor, GLenum dfactor) = 0; virtual void blendFuncSeparatei(GLuint buf, GLenum sRGB, GLenum dRGB, GLenum sAlpha, GLenum dAlpha) = 0; @@ -157,6 +157,7 @@ public: virtual void glUniformMatrix3x4fv(GLint location, GLsizei count, const GLfloat *value) = 0; virtual void glUniformMatrix4x3fv(GLint location, GLsizei count, const GLfloat *value) = 0; + virtual UniformType uniformTypeFromGLType(GLenum glType) = 0; }; diff --git a/src/render/io/qsceneloader.cpp b/src/render/io/qsceneloader.cpp index 69bd8528b..9cb067161 100644 --- a/src/render/io/qsceneloader.cpp +++ b/src/render/io/qsceneloader.cpp @@ -51,44 +51,36 @@ using namespace Qt3DCore; namespace Qt3DRender { -QSceneLoaderPrivate::QSceneLoaderPrivate() - : QComponentPrivate() - , m_status(QSceneLoader::None) - , m_subTreeRoot(nullptr) -{ - m_shareable = false; -} - /*! - \class Qt3DRender::QSceneLoader - \inmodule Qt3DRender - \since 5.7 - \ingroup io + \class Qt3DRender::QSceneLoader + \inmodule Qt3DRender + \since 5.7 + \ingroup io - \brief Provides the facility to load an existing Scene + \brief Provides the facility to load an existing Scene - Given a 3D source file, the Qt3DRender::QSceneLoader will try to parse it and - build a tree of Qt3DCore::QEntity with proper Qt3DRender::QGeometryRenderer - Qt3DCore::QTransform and QtRender::QMaterial components. + Given a 3D source file, the Qt3DRender::QSceneLoader will try to parse it and + build a tree of Qt3DCore::QEntity objects with proper Qt3DRender::QGeometryRenderer, + Qt3DCore::QTransform and Qt3DRender::QMaterial components. - The loader will try to determine the best material to be used based on the properties - of the model file. If you wish to use a custom material, you will have to traverse - the tree and replace the default associated materials with yours. + The loader will try to determine the best material to be used based on the properties + of the model file. If you wish to use a custom material, you will have to traverse + the tree and replace the default associated materials with yours. - As the name implies, Qt3DRender::QSceneLoader loads a complete scene subtree. - If you wish to load a single piece of geometry, you should rather be using - the Qt3DRender::QMesh instead. + As the name implies, Qt3DRender::QSceneLoader loads a complete scene subtree. + If you wish to load a single piece of geometry, you should rather use + the Qt3DRender::QMesh instead. - Qt3DRender::QSceneLoader internally relies on the use of plugins to support a - wide variety of 3D file formats. \l - {http://www.assimp.org/main_features_formats.html}{Here} is a list of formats - that are supported by Qt3D. + Qt3DRender::QSceneLoader internally relies on the use of plugins to support a + wide variety of 3D file formats. \l + {http://www.assimp.org/main_features_formats.html}{Here} is a list of formats + that are supported by Qt3D. - \note this component shouldn't be shared among several Qt3DCore::QEntity instances. - Undefined behavior will result. + \note this component shouldn't be shared among several Qt3DCore::QEntity instances. + Undefined behavior will result. - \sa Qt3DRender::QMesh - \sa Qt3DRender::QGeometryRenderer + \sa Qt3DRender::QMesh + \sa Qt3DRender::QGeometryRenderer */ /*! @@ -97,10 +89,10 @@ QSceneLoaderPrivate::QSceneLoaderPrivate() \instantiates Qt3DRender::QSceneLoader \inherits Component \since 5.7 - \qmlabstract Provides the facility to load an existing Scene + \brief Provides the facility to load an existing Scene Given a 3D source file, the SceneLoader will try to parse it and build a - tree of Entity with proper GeometryRenderer, Transform and Material + tree of Entity objects with proper GeometryRenderer, Transform and Material components. The loader will try to determine the best material to be used based on the @@ -109,7 +101,7 @@ QSceneLoaderPrivate::QSceneLoaderPrivate() with yours. As the name implies, SceneLoader loads a complete scene subtree. If you - wish to load a single piece of geometry, you should rather be using the + wish to load a single piece of geometry, you should rather use the Mesh instead. SceneLoader internally relies on the use of plugins to support a wide @@ -122,7 +114,7 @@ QSceneLoaderPrivate::QSceneLoaderPrivate() \sa Mesh \sa GeometryRenderer -*/ + */ /*! \enum QSceneLoader::Status @@ -132,10 +124,58 @@ QSceneLoaderPrivate::QSceneLoaderPrivate() \value Loading The Qt3DRender::QSceneLoader is currently loading the scene file. \value Ready The Qt3DRender::QSceneLoader successfully loaded the scene file. \value Error The Qt3DRender::QSceneLoader encountered an error while loading the scene file. -*/ + */ + +/*! + \qmlproperty url SceneLoader::source + + Holds the url to the source to be loaded. + */ /*! - The constructor creates an instance with the specified \a parent. + \qmlproperty enumeration SceneLoader::status + + Holds the status of scene loading. + \list + \li SceneLoader.None + \li SceneLoader.Loading + \li SceneLoader.Ready + \li SceneLoader.Error + \endlist + \sa Qt3DRender::QSceneLoader::Status + \readonly + */ + +/*! + \property QSceneLoader::source + + Holds the url to the source to be loaded. + */ + +/*! + \property QSceneLoader::status + + Holds the status of scene loading. + \list + \li SceneLoader.None + \li SceneLoader.Loading + \li SceneLoader.Ready + \li SceneLoader.Error + \endlist + \sa Qt3DRender::QSceneLoader::Status + */ + +/*! \internal */ +QSceneLoaderPrivate::QSceneLoaderPrivate() + : QComponentPrivate() + , m_status(QSceneLoader::None) + , m_subTreeRoot(nullptr) +{ + m_shareable = false; +} + +/*! + The constructor creates an instance with the specified \a parent. */ QSceneLoader::QSceneLoader(QNode *parent) : Qt3DCore::QComponent(*new QSceneLoaderPrivate, parent) @@ -190,15 +230,6 @@ QUrl QSceneLoader::source() const return d->m_source; } -/*! - \property Qt3DRender::QSceneLoader::source - Specifies the url for the source to be loaded. -*/ - -/*! - \qmlproperty QUrl Qt3D.Render::SceneLoader::source - -*/ void QSceneLoader::setSource(const QUrl &arg) { Q_D(QSceneLoader); @@ -208,15 +239,6 @@ void QSceneLoader::setSource(const QUrl &arg) } } -/*! - \property Qt3DRender::QSceneLoader::status - Indicates the status of scene loading. -*/ - -/*! - \qmlproperty Status Qt3D.Render::SceneLoader::status - -*/ QSceneLoader::Status QSceneLoader::status() const { Q_D(const QSceneLoader); diff --git a/src/render/jobs/loadscenejob.cpp b/src/render/jobs/loadscenejob.cpp index 3111e1ba3..701942976 100644 --- a/src/render/jobs/loadscenejob.cpp +++ b/src/render/jobs/loadscenejob.cpp @@ -60,6 +60,26 @@ LoadSceneJob::LoadSceneJob(const QUrl &source, Qt3DCore::QNodeId m_sceneComponen SET_JOB_RUN_STAT_TYPE(this, JobTypes::LoadScene, 0); } +NodeManagers *LoadSceneJob::nodeManagers() const +{ + return m_managers; +} + +QList<QSceneIOHandler *> LoadSceneJob::sceneIOHandlers() const +{ + return m_sceneIOHandlers; +} + +QUrl LoadSceneJob::source() const +{ + return m_source; +} + +Qt3DCore::QNodeId LoadSceneJob::sceneComponentId() const +{ + return m_sceneComponent; +} + void LoadSceneJob::run() { // Iterate scene IO handlers until we find one that can handle this file type @@ -70,9 +90,11 @@ void LoadSceneJob::run() // Reset status scene->setStatus(QSceneLoader::None); + QSceneLoader::Status finalStatus = QSceneLoader::None; // Perform the loading only if the source wasn't explicitly set to empty if (!m_source.isEmpty()) { + finalStatus = QSceneLoader::Error; for (QSceneIOHandler *sceneIOHandler : qAsConst(m_sceneIOHandlers)) { if (!sceneIOHandler->isFileTypeSupported(m_source)) continue; @@ -82,15 +104,11 @@ void LoadSceneJob::run() // File type is supported, try to load it sceneIOHandler->setSource(m_source); - Qt3DCore::QEntity *sub = sceneIOHandler->scene(); - if (sub) { - sceneSubTree = sub; + sceneSubTree = sceneIOHandler->scene(); + if (sceneSubTree != nullptr) { // Successfully built a subtree - scene->setStatus(QSceneLoader::Ready); + finalStatus = QSceneLoader::Ready; break; - } else { - // Tree wasn't build so something went wrong obviously - scene->setStatus(QSceneLoader::Error); } } } @@ -100,6 +118,10 @@ void LoadSceneJob::run() // Set clone of sceneTree in sceneComponent. This will move the sceneSubTree // to the QCoreApplication thread which is where the frontend object tree lives. scene->setSceneSubtree(sceneSubTree); + + // Note: the status is set after the subtree so that bindinds depending on the status + // in the frontend will be consistent + scene->setStatus(finalStatus); } } // namespace Render diff --git a/src/render/jobs/loadscenejob_p.h b/src/render/jobs/loadscenejob_p.h index bc122d705..0ed0d2c83 100644 --- a/src/render/jobs/loadscenejob_p.h +++ b/src/render/jobs/loadscenejob_p.h @@ -66,14 +66,18 @@ namespace Render { class NodeManagers; -class LoadSceneJob : public Qt3DCore::QAspectJob +class Q_AUTOTEST_EXPORT LoadSceneJob : public Qt3DCore::QAspectJob { public: explicit LoadSceneJob(const QUrl &source, Qt3DCore::QNodeId sceneComponent); void setNodeManagers(NodeManagers *managers) { m_managers = managers; } void setSceneIOHandlers(const QList<QSceneIOHandler *> sceneIOHandlers) { m_sceneIOHandlers = sceneIOHandlers; } -protected: + NodeManagers *nodeManagers() const; + QList<QSceneIOHandler *> sceneIOHandlers() const; + QUrl source() const; + Qt3DCore::QNodeId sceneComponentId() const; + void run() Q_DECL_OVERRIDE; private: diff --git a/src/render/jobs/renderviewjobutils.cpp b/src/render/jobs/renderviewjobutils.cpp index e5b763fcf..3face7197 100644 --- a/src/render/jobs/renderviewjobutils.cpp +++ b/src/render/jobs/renderviewjobutils.cpp @@ -391,7 +391,7 @@ void addParametersForIds(ParameterInfoList *params, ParameterManager *manager, Parameter *param = manager->lookupResource(paramId); ParameterInfoList::iterator it = std::lower_bound(params->begin(), params->end(), param->nameId()); if (it == params->end() || it->nameId != param->nameId()) - params->insert(it, ParameterInfo(param->nameId(), param->value())); + params->insert(it, ParameterInfo(param->nameId(), param->uniformValue())); } } @@ -438,7 +438,7 @@ UniformBlockValueBuilder::~UniformBlockValueBuilder() { } -void UniformBlockValueBuilder::buildActiveUniformNameValueMapHelper(const QString &blockName, const QString &qmlPropertyName, const QVariant &value) +void UniformBlockValueBuilder::buildActiveUniformNameValueMapHelper(ShaderData *currentShaderData, const QString &blockName, const QString &qmlPropertyName, const QVariant &value) { // In the end, values are either scalar or a scalar array // Composed elements (structs, structs array) are simplified into simple scalars @@ -471,27 +471,36 @@ void UniformBlockValueBuilder::buildActiveUniformNameValueMapHelper(const QStrin QString varName = blockName + QLatin1Char('.') + qmlPropertyName; if (uniforms.contains(varName)) { qCDebug(Shaders) << "UBO scalar member " << varName << " set for update"; - activeUniformNamesToValue.insert(StringToInt::lookupId(varName), value); + + // If the property needs to be transformed, we transform it here as + // the shaderdata cannot hold transformed properties for multiple + // thread contexts at once + if (currentShaderData->propertyTransformType(qmlPropertyName) != ShaderData::NoTransform) + activeUniformNamesToValue.insert(StringToInt::lookupId(varName), + currentShaderData->getTransformedProperty(qmlPropertyName, viewMatrix)); + else + activeUniformNamesToValue.insert(StringToInt::lookupId(varName), value); } } } void UniformBlockValueBuilder::buildActiveUniformNameValueMapStructHelper(ShaderData *rShaderData, const QString &blockName, const QString &qmlPropertyName) { - const QHash<QString, QVariant> &properties = updatedPropertiesOnly ? rShaderData->updatedProperties() : rShaderData->properties(); + const QHash<QString, QVariant> &properties = rShaderData->properties(); QHash<QString, QVariant>::const_iterator it = properties.begin(); const QHash<QString, QVariant>::const_iterator end = properties.end(); while (it != end) { const auto prefix = qmlPropertyName.isEmpty() ? QLatin1String("") : QLatin1String("."); - buildActiveUniformNameValueMapHelper(blockName + prefix + qmlPropertyName, + buildActiveUniformNameValueMapHelper(rShaderData, + blockName + prefix + qmlPropertyName, it.key(), it.value()); ++it; } } -ParameterInfo::ParameterInfo(const int nameId, const QVariant &value) +ParameterInfo::ParameterInfo(const int nameId, const UniformValue &value) : nameId(nameId) , value(value) {} diff --git a/src/render/jobs/renderviewjobutils_p.h b/src/render/jobs/renderviewjobutils_p.h index 7f70690d7..c08083494 100644 --- a/src/render/jobs/renderviewjobutils_p.h +++ b/src/render/jobs/renderviewjobutils_p.h @@ -55,6 +55,8 @@ #include <Qt3DCore/qnodeid.h> #include <QtCore/qhash.h> #include <QtCore/qvariant.h> +#include <QMatrix4x4> +#include <Qt3DRender/private/uniform_p.h> QT_BEGIN_NAMESPACE @@ -106,10 +108,10 @@ Q_AUTOTEST_EXPORT inline T variant_value(const QVariant &v) struct ParameterInfo { - explicit ParameterInfo(const int nameId = -1, const QVariant &value = QVariant()); + explicit ParameterInfo(const int nameId = -1, const UniformValue &value = UniformValue()); int nameId; - QVariant value; + UniformValue value; bool operator<(const int otherNameId) const Q_DECL_NOEXCEPT; bool operator<(const ParameterInfo &other) const Q_DECL_NOEXCEPT; @@ -157,7 +159,8 @@ struct Q_AUTOTEST_EXPORT UniformBlockValueBuilder UniformBlockValueBuilder(); ~UniformBlockValueBuilder(); - void buildActiveUniformNameValueMapHelper(const QString &blockName, + void buildActiveUniformNameValueMapHelper(ShaderData *currentShaderData, + const QString &blockName, const QString &qmlPropertyName, const QVariant &value); void buildActiveUniformNameValueMapStructHelper(ShaderData *rShaderData, @@ -168,6 +171,7 @@ struct Q_AUTOTEST_EXPORT UniformBlockValueBuilder QHash<QString, ShaderUniform> uniforms; UniformBlockValueBuilderHash activeUniformNamesToValue; ShaderDataManager *shaderDataManager; + QMatrix4x4 viewMatrix; }; } // namespace Render diff --git a/src/render/materialsystem/material_p.h b/src/render/materialsystem/material_p.h index b415e2975..fe2707549 100644 --- a/src/render/materialsystem/material_p.h +++ b/src/render/materialsystem/material_p.h @@ -54,7 +54,7 @@ #include <QVariant> #include <Qt3DRender/private/backendnode_p.h> -#include <Qt3DRender/private/quniformvalue_p.h> +#include <Qt3DRender/private/shaderparameterpack_p.h> #include <Qt3DRender/private/parameterpack_p.h> QT_BEGIN_NAMESPACE diff --git a/src/render/materialsystem/parameter.cpp b/src/render/materialsystem/parameter.cpp index b13c0d5ae..2cd026422 100644 --- a/src/render/materialsystem/parameter.cpp +++ b/src/render/materialsystem/parameter.cpp @@ -68,7 +68,7 @@ void Parameter::initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &ch const auto &data = typedChange->data; m_name = data.name; m_nameId = StringToInt::lookupId(m_name); - m_value = data.backendValue; + m_uniformValue = UniformValue::fromVariant(data.backendValue); } void Parameter::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) @@ -80,7 +80,7 @@ void Parameter::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) m_name = propertyChange->value().toString(); m_nameId = StringToInt::lookupId(m_name); } else if (propertyChange->propertyName() == QByteArrayLiteral("value")) { - m_value = propertyChange->value(); + m_uniformValue = UniformValue::fromVariant(propertyChange->value()); } markDirty(AbstractRenderer::AllDirty); } @@ -93,14 +93,14 @@ QString Parameter::name() const return m_name; } -QVariant Parameter::value() const +int Parameter::nameId() const Q_DECL_NOTHROW { - return m_value; + return m_nameId; } -int Parameter::nameId() const Q_DECL_NOTHROW +UniformValue Parameter::uniformValue() const { - return m_nameId; + return m_uniformValue; } } // namespace Render diff --git a/src/render/materialsystem/parameter_p.h b/src/render/materialsystem/parameter_p.h index c5c94243d..c6861ca36 100644 --- a/src/render/materialsystem/parameter_p.h +++ b/src/render/materialsystem/parameter_p.h @@ -52,6 +52,7 @@ // #include <Qt3DRender/private/backendnode_p.h> +#include <Qt3DRender/private/uniform_p.h> #include <QVariant> QT_BEGIN_NAMESPACE @@ -72,14 +73,14 @@ public: void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE; QString name() const; - QVariant value() const; int nameId() const Q_DECL_NOTHROW; + UniformValue uniformValue() const; private: void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_FINAL; QString m_name; - QVariant m_value; + UniformValue m_uniformValue; int m_nameId; }; diff --git a/src/render/materialsystem/qeffect.cpp b/src/render/materialsystem/qeffect.cpp index 70810676c..7778b5621 100644 --- a/src/render/materialsystem/qeffect.cpp +++ b/src/render/materialsystem/qeffect.cpp @@ -58,12 +58,17 @@ QEffectPrivate::QEffectPrivate() } /*! - \class Qt3DRender::QEffect - \inmodule Qt3DRender - \since 5.7 - \brief The base class for effects in a Qt 3D scene. + \class Qt3DRender::QEffect + \inmodule Qt3DRender + \inherits Qt3DCore::QNode + \since 5.7 + \brief The base class for effects in a Qt 3D scene. - */ + The QEffect class combines a set of techniques and parameters used by those techniques to + produce a rendering effect for a material. + + \sa QMaterial, QTechnique, QParameter +*/ /*! \qmltype Effect @@ -72,18 +77,18 @@ QEffectPrivate::QEffectPrivate() \inqmlmodule Qt3D.Render \since 5.7 \brief The base class for effects in a Qt 3D scene. + + The Effect type combines a set of techniques and parameters used by those techniques to + produce a rendering effect for a material. + + \sa Material, Technique, Parameter */ -/*! - \fn Qt3DRender::QEffect::QEffect(Qt3DCore::QNode *parent) - Constructs a new QEffect with the specified \a parent. - */ QEffect::QEffect(QNode *parent) : QNode(*new QEffectPrivate, parent) { } -/*! \internal */ QEffect::~QEffect() { } @@ -95,8 +100,21 @@ QEffect::QEffect(QEffectPrivate &dd, QNode *parent) } /*! + \qmlproperty list<Technique> Effect::techniques + + Holds the list of techniques used by this effect. +*/ +/*! + \qmlproperty list<Parameter> Effect::parameters + + Holds the list of parameters used by this effect. + A parameter is used to set a corresponding uniform value in the shader used by this effect. +*/ + +/*! * Adds \a parameter to the effect. It sends a QPropertyNodeAddedChange to the backend. - * The \a parameter will be used to set a corresponding uniform value in the shader used by this effect. + * The \a parameter will be used to set a corresponding uniform value in the shader used + * by this effect. */ void QEffect::addParameter(QParameter *parameter) { diff --git a/src/render/materialsystem/qfilterkey.cpp b/src/render/materialsystem/qfilterkey.cpp index d4bc26515..547c56d26 100644 --- a/src/render/materialsystem/qfilterkey.cpp +++ b/src/render/materialsystem/qfilterkey.cpp @@ -55,8 +55,12 @@ QFilterKeyPrivate::QFilterKeyPrivate() /*! \class Qt3DRender::QFilterKey \inmodule Qt3DRender + \inherits Qt3DCore::QNode \since 5.5 - \brief The QFilterKey class provides storage for filter keys and their values + \brief The QFilterKey class provides storage for filter keys and their values. + + Filter keys are used by QTechnique and QRenderPass to specify at which stage of rendering the + technique or the render pass is used. */ /*! @@ -65,18 +69,18 @@ QFilterKeyPrivate::QFilterKeyPrivate() \inherits Node \inqmlmodule Qt3D.Render \since 5.5 - \brief For storing filter keys and their value + \brief Stores filter keys and their values. + + A FilterKey is a storage type for filter key and value pair. + Filter keys are used by Technique and RenderPass to specify at which stage of rendering the + technique or the render pass is used. */ -/*! - The constructor creates a new QFilterKey under \a parent. - */ QFilterKey::QFilterKey(QNode *parent) : QNode(*new QFilterKeyPrivate, parent) { } -/*! \internal */ QFilterKey::~QFilterKey() { } @@ -100,13 +104,15 @@ void QFilterKey::setName(const QString &name) } /*! - \property QFilterKey::value - Specifies the value of the filter key + \property QFilterKey::value + + Holds the value of the filter key. */ /*! - \qmlproperty variant Qt3D.Render::Annotation::value - Specifies the value of the filter key + \qmlproperty variant FilterKey::value + + Holds the value of the filter key. */ QVariant QFilterKey::value() const @@ -116,14 +122,16 @@ QVariant QFilterKey::value() const } /*! - \property QFilterKey::name - Specifies the name of the filter key - */ + \property QFilterKey::name + + Holds the name of the filter key. +*/ /*! - \qmlproperty string Qt3D.Render::Annotation::name - Specifies the name of the filter key - */ + \qmlproperty string FilterKey::name + + Holds the name of the filter key. +*/ QString QFilterKey::name() const { diff --git a/src/render/materialsystem/qmaterial.cpp b/src/render/materialsystem/qmaterial.cpp index 5b3fe63af..ca0f86463 100644 --- a/src/render/materialsystem/qmaterial.cpp +++ b/src/render/materialsystem/qmaterial.cpp @@ -48,29 +48,37 @@ #include <Qt3DCore/qpropertynoderemovedchange.h> /*! - * \qmltype Material - * \instantiates Qt3DRender::QMaterial - * \inqmlmodule Qt3D.Render - * \brief Non-creatable abstract base for materials. - * \inherits Component - */ + \qmltype Material + \instantiates Qt3DRender::QMaterial + \inqmlmodule Qt3D.Render + \brief Non-creatable abstract base for materials. + \since 5.5 + + Material provides a way to specify the rendering of an \l{Qt3D.Core::Entity}{entity}. + Any aspect can define its own subtype of Material so that a + Material can be used to describe a visual element; for example, the way + sound should reflect off an element, the temperature of a surface, + and so on. + + \sa Effect +*/ /*! - * \class Qt3DRender::QMaterial - * \inmodule Qt3DRender - * - * - * \brief Provides an abstract class that should be the base of all - * Material component classes in a scene. - * - * QMaterial provides a way to specify the rendering of an Entity. - * Any aspect can define its own subclass of QMaterial so that a - * Material can be used to describe a visual element; for example, the way - * sound should reflect off an element, the temperature of a surface, - * and so on. - * - * \sa QEffect, QMesh, {Qt3DCore::}{QComponent} - */ + \class Qt3DRender::QMaterial + \inmodule Qt3DRender + \inherits Qt3DCore::QComponent + \brief Provides an abstract class that should be the base of all material component classes + in a scene. + \since 5.5 + + QMaterial provides a way to specify the rendering of an \l{Qt3DCore::QEntity}{entity}. + Any aspect can define its own subclass of QMaterial so that a + Material can be used to describe a visual element; for example, the way + sound should reflect off an element, the temperature of a surface, + and so on. + + \sa QEffect +*/ QT_BEGIN_NAMESPACE @@ -88,16 +96,11 @@ QMaterialPrivate::~QMaterialPrivate() { } -/*! - \fn Qt3DRender::QMaterial::QMaterial(Qt3DCore::QNode *parent) - Constructs a new QMaterial with the specified \a parent. - */ QMaterial::QMaterial(QNode *parent) : QComponent(*new QMaterialPrivate, parent) { } -/*! \internal */ QMaterial::~QMaterial() { } @@ -109,16 +112,20 @@ QMaterial::QMaterial(QMaterialPrivate &dd, QNode *parent) } /*! - \qmlproperty QEffect Qt3D.Render::Material::effect - Specifies the effect to be used with the material + \qmlproperty list<Parameter> Material::parameters + + Holds the list of parameters used by the material. */ /*! - \property Qt3DRender::QMaterial::effect - Specifies the effect to be used with the material - */ + \qmlproperty Effect Material::effect + + Specifies the effect to be used with the material. +*/ /*! - * Sets the \a effect to be used with the Material. + \property QMaterial::effect + + Specifies the effect to be used with the material. */ void QMaterial::setEffect(QEffect *effect) { @@ -144,9 +151,6 @@ void QMaterial::setEffect(QEffect *effect) } } -/*! - * Returns the effect used by the Material. - */ QEffect *QMaterial::effect() const { Q_D(const QMaterial); @@ -154,7 +158,7 @@ QEffect *QMaterial::effect() const } /*! - * Add \a parameter to the Materials parameter. + * Add a \a parameter to the material's parameters. */ void QMaterial::addParameter(QParameter *parameter) { @@ -182,7 +186,7 @@ void QMaterial::addParameter(QParameter *parameter) } /*! - * Remove \a parameter from the Material parameters. + * Remove a \a parameter from the material's parameters. */ void QMaterial::removeParameter(QParameter *parameter) { @@ -197,7 +201,7 @@ void QMaterial::removeParameter(QParameter *parameter) } /*! - * Returns a vector of the materials current parameters + * Returns a vector of the material's current parameters */ QVector<QParameter *> QMaterial::parameters() const { diff --git a/src/render/materialsystem/qrenderpass.cpp b/src/render/materialsystem/qrenderpass.cpp index b10660730..dd6363816 100644 --- a/src/render/materialsystem/qrenderpass.cpp +++ b/src/render/materialsystem/qrenderpass.cpp @@ -60,19 +60,65 @@ QRenderPassPrivate::QRenderPassPrivate() { } /*! - * \qmltype RenderPass - * \instantiates Qt3DRender::QRenderPass - * \inqmlmodule Qt3D.Render - * \brief Encapsulates a Render Pass. + \qmltype RenderPass + \instantiates Qt3DRender::QRenderPass + \inqmlmodule Qt3D.Render + \inherits Node + \since 5.7 + \brief Encapsulates a Render Pass. + + A RenderPass specifies a single rendering pass - an instance of shader program + execution - used by Technique. A Render pass consists of a ShaderProgram and + a list of FilterKey objects, a list of RenderState objects and a list + of \l Parameter objects. + + RenderPass executes the ShaderProgram using the given render states and parameters + when its filter keys match the filter keys in RenderPassFilter or when no filter + keys are specified and no RenderPassFilter is present in the FrameGraph. */ /*! - * \class Qt3DRender::QRenderPass - * \inmodule Qt3DRender - * - * \inherits Node - * - * \brief Encapsulates a Render Pass. + \class Qt3DRender::QRenderPass + \inmodule Qt3DRender + \since 5.7 + \brief Encapsulates a Render Pass. + + A Qt3DRender::QRenderPass specifies a single rendering pass - an instance of shader + program execution - used by Qt3DRender::QTechnique. Render pass consists + of a Qt3DRender::QShaderProgram and a list of Qt3DRender::QFilterKey objects, + a list of Qt3DRender::QRenderState objects and a list of Qt3DRender::QParameter objects. + + QRenderPass executes the QShaderProgram using the given render states and parameters + when its filter keys match the filter keys in Qt3DRender::QRenderPassFilter or + when no filter keys are specified and no QRenderPassFilter is present + in the FrameGraph. + */ +/*! + \typedef ParameterList + \relates Qt3DRender::QRenderPass + + A list of Qt3DRender::QParameter parameters. +*/ +/*! + \qmlproperty ShaderProgram Qt3D.Render::RenderPass::shaderProgram + Holds the shader program to be used for this render pass. +*/ +/*! + \qmlproperty list<FilterKey> Qt3D.Render::RenderPass::filterKeys + Holds the filter keys enabling the use of this render pass. +*/ +/*! + \qmlproperty list<RenderState> Qt3D.Render::RenderPass::renderStates + Holds the render states used by the render pass. +*/ +/*! + \qmlproperty list<Parameter> Qt3D.Render::RenderPass::parameters + Holds the shader parameter values used by the render pass. +*/ + +/*! + \property Qt3DRender::QRenderPass::shaderProgram + Specifies the shader program to be used for this render pass. */ /*! @@ -95,18 +141,6 @@ QRenderPass::QRenderPass(QRenderPassPrivate &dd, QNode *parent) { } -/*! - \qmlproperty ShaderProgram Qt3D.Render::RenderPass::shaderProgram - Specifies the shader program to be used for this render pass -*/ - -/*! - \property Qt3DRender::QRenderPass::shaderProgram - Specifies the shader program to be used for this render pass - */ -/*! - * Sets the pass' \a shaderProgram. - */ void QRenderPass::setShaderProgram(QShaderProgram *shaderProgram) { Q_D(QRenderPass); @@ -145,7 +179,7 @@ QShaderProgram *QRenderPass::shaderProgram() const } /*! - * Adds \a filterKey from to the Qt3DRender::QRenderPass local filter keys. + Adds \a filterKey to the Qt3DRender::QRenderPass local filter keys. */ void QRenderPass::addFilterKey(QFilterKey *filterKey) { @@ -173,7 +207,7 @@ void QRenderPass::addFilterKey(QFilterKey *filterKey) } /*! - * Removes \a filterKey from the Qt3DRender::QRenderPass local filter keys. + Removes \a filterKey from the Qt3DRender::QRenderPass local filter keys. */ void QRenderPass::removeFilterKey(QFilterKey *filterKey) { @@ -190,8 +224,8 @@ void QRenderPass::removeFilterKey(QFilterKey *filterKey) } /*! - * Returns the list of Qt3DCore::QFilterKey key objects making up the filter keys - * of the Qt3DRender::QRenderPass. + Returns the list of Qt3DRender::QFilterKey key objects making up the filter keys + of the Qt3DRender::QRenderPass. */ QVector<QFilterKey *> QRenderPass::filterKeys() const { @@ -200,12 +234,12 @@ QVector<QFilterKey *> QRenderPass::filterKeys() const } /*! - * Adds a Qt3DCore::QRenderState \a state to the rendering pass. That implies that - * when the pass is executed at render time, the globally set render state will - * be modifed by the states defined locally by the Qt3DRender::QRenderPass. - * - * \note not defining any Qt3DCore::QRenderState in a pass will result in the pass using - * the globally set render state for a given FrameGraph branch execution path. + Adds a render \a state to the rendering pass. That implies that + when the pass is executed at render time, the globally set render state will + be modifed by the states defined locally by the Qt3DRender::QRenderPass. + + \note not defining any Qt3DRender::QRenderState in a pass will result in the pass using + the globally set render state for a given FrameGraph branch execution path. */ void QRenderPass::addRenderState(QRenderState *state) { @@ -229,7 +263,7 @@ void QRenderPass::addRenderState(QRenderState *state) } /*! - * Removes \a state from the Qt3DRender::QRenderPass local render state. + Removes \a state from the Qt3DRender::QRenderPass local render state. */ void QRenderPass::removeRenderState(QRenderState *state) { @@ -246,8 +280,8 @@ void QRenderPass::removeRenderState(QRenderState *state) } /*! - * Returns the list of Qt3DCore::QRenderState state objects making up the render - * state of the Qt3DRender::QRenderPass. + Returns the list of Qt3DRender::QRenderState state objects making up the render + state of the Qt3DRender::QRenderPass. */ QVector<QRenderState *> QRenderPass::renderStates() const { @@ -256,7 +290,7 @@ QVector<QRenderState *> QRenderPass::renderStates() const } /*! - * Add \a parameter to the render pass' parameters. + Add \a parameter to the render pass' parameters. */ void QRenderPass::addParameter(QParameter *parameter) { @@ -284,7 +318,7 @@ void QRenderPass::addParameter(QParameter *parameter) } /*! - * Remove \a parameter from the render pass' parameters. + Remove \a parameter from the render pass' parameters. */ void QRenderPass::removeParameter(QParameter *parameter) { @@ -301,9 +335,9 @@ void QRenderPass::removeParameter(QParameter *parameter) } /*! - * Returns a vector of the render pass' current parameters + Returns a vector of the render pass' current parameters */ -QVector<QParameter *> QRenderPass::parameters() const +ParameterList QRenderPass::parameters() const { Q_D(const QRenderPass); return d->m_parameters; diff --git a/src/render/materialsystem/qrenderpass.h b/src/render/materialsystem/qrenderpass.h index e2eb96a9a..9c608d0c4 100644 --- a/src/render/materialsystem/qrenderpass.h +++ b/src/render/materialsystem/qrenderpass.h @@ -70,8 +70,8 @@ public: QShaderProgram *shaderProgram() const; - void addFilterKey(QFilterKey*filterKey); - void removeFilterKey(QFilterKey*filterKey); + void addFilterKey(QFilterKey *filterKey); + void removeFilterKey(QFilterKey *filterKey); QVector<QFilterKey*> filterKeys() const; void addRenderState(QRenderState *state); diff --git a/src/render/materialsystem/qshaderprogram.cpp b/src/render/materialsystem/qshaderprogram.cpp index da954210b..522f021aa 100644 --- a/src/render/materialsystem/qshaderprogram.cpp +++ b/src/render/materialsystem/qshaderprogram.cpp @@ -47,29 +47,37 @@ #include <QUrl> /*! - * \qmltype ShaderProgram - * \instantiates Qt3DRender::QShaderProgram - * \inqmlmodule Qt3D.Render - * \brief Encapsulates a Shader Program. - */ + \class Qt3DRender::QShaderProgram + \inmodule Qt3DRender + \brief Encapsulates a Shader Program. + \inherits Qt3DCore::QNode + \since 5.5 + + A shader program consists of several different shaders, such as vertex and fragment shaders. +*/ /*! - * \class Qt3DRender::QShaderProgram - * \inmodule Qt3DRender - * - * \brief Encapsulates a Shader Program. - */ + \qmltype ShaderProgram + \instantiates Qt3DRender::QShaderProgram + \inqmlmodule Qt3D.Render + \brief Encapsulates a Shader Program. + \since 5.5 + + ShaderProgram class encapsulates a shader program. A shader program consists of several + different shaders, such as vertex and fragment shaders. +*/ /*! \enum QShaderProgram::ShaderType - This enum identifies the type of shader used - \value Vertex - \value Fragment - \value TessellationControl - \value TessellationEvaluation - \value Geometry - \value Compute + This enum identifies the type of shader used. + + \value Vertex Vertex shader + \value Fragment Fragment shader + \value TessellationControl Tesselation control shader + \value TessellationEvaluation Tesselation evaluation shader + \value Geometry Geometry shader + \value Compute Compute shader */ QT_BEGIN_NAMESPACE @@ -81,16 +89,11 @@ QShaderProgramPrivate::QShaderProgramPrivate() { } -/*! - \fn Qt3DRender::QShaderProgram::QShaderProgram(Qt3DCore::QNode *parent) - Constructs a new QShaderProgram with the specified \a parent. - */ QShaderProgram::QShaderProgram(QNode *parent) : QNode(*new QShaderProgramPrivate, parent) { } -/*! \internal */ QShaderProgram::~QShaderProgram() { } @@ -102,14 +105,15 @@ QShaderProgram::QShaderProgram(QShaderProgramPrivate &dd, QNode *parent) } /*! - \qmlproperty QByteArray Qt3D.Render::ShaderProgram::vertexShaderCode - Specifies the vertex shader code to be used -*/ + \qmlproperty string ShaderProgram::vertexShaderCode + Holds the vertex shader code used by this shader program. +*/ /*! - \property Qt3DRender::QShaderProgram::vertexShaderCode - Specifies the vertex shader code to be used - */ + \property QShaderProgram::vertexShaderCode + + Holds the vertex shader code used by this shader program. +*/ void QShaderProgram::setVertexShaderCode(const QByteArray &vertexShaderCode) { Q_D(QShaderProgram); @@ -126,14 +130,15 @@ QByteArray QShaderProgram::vertexShaderCode() const } /*! - \qmlproperty QByteArray Qt3D.Render::ShaderProgram::tessellationControlShaderCode - Specifies the tessellation control shader code to be used -*/ + \qmlproperty string ShaderProgram::tessellationControlShaderCode + Holds the tesselation control shader code used by this shader program. +*/ /*! - \property Qt3DRender::QShaderProgram::tessellationControlShaderCode - Specifies the tessellation control shader code to be used - */ + \property QShaderProgram::tessellationControlShaderCode + + Holds the tesselation control shader code used by this shader program. +*/ void QShaderProgram::setTessellationControlShaderCode(const QByteArray &tessellationControlShaderCode) { Q_D(QShaderProgram); @@ -150,14 +155,15 @@ QByteArray QShaderProgram::tessellationControlShaderCode() const } /*! - \qmlproperty QByteArray Qt3D.Render::ShaderProgram::tessellationEvaluationShaderCode - Specifies the tessellation evaluation shader code to be used -*/ + \qmlproperty string ShaderProgram::tessellationEvaluationShaderCode + Holds the tesselation evaluation shader code used by this shader program. +*/ /*! - \property Qt3DRender::QShaderProgram::tessellationEvaluationShaderCode - Specifies the tessellation evaluation shader code to be used - */ + \property QShaderProgram::tessellationEvaluationShaderCode + + Holds the tesselation evaluation shader code used by this shader program. +*/ void QShaderProgram::setTessellationEvaluationShaderCode(const QByteArray &tessellationEvaluationShaderCode) { Q_D(QShaderProgram); @@ -174,14 +180,15 @@ QByteArray QShaderProgram::tessellationEvaluationShaderCode() const } /*! - \qmlproperty QByteArray Qt3D.Render::ShaderProgram::geometryShaderCode - Specifies the geometry shader code to be used -*/ + \qmlproperty string ShaderProgram::geometryShaderCode + Holds the geometry shader code used by this shader program. +*/ /*! - \property Qt3DRender::QShaderProgram::geometryShaderCode - Specifies the geometry shader code to be used - */ + \property QShaderProgram::geometryShaderCode + + Holds the geometry shader code used by this shader program. +*/ void QShaderProgram::setGeometryShaderCode(const QByteArray &geometryShaderCode) { Q_D(QShaderProgram); @@ -198,14 +205,15 @@ QByteArray QShaderProgram::geometryShaderCode() const } /*! - \qmlproperty QByteArray Qt3D.Render::ShaderProgram::fragmentShaderCode - Specifies the fragment shader code to be used -*/ + \qmlproperty string ShaderProgram::fragmentShaderCode + Holds the fragment shader code used by this shader program. +*/ /*! - \property Qt3DRender::QShaderProgram::fragmentShaderCode - Specifies the fragment shader code to be used - */ + \property QShaderProgram::fragmentShaderCode + + Holds the fragment shader code used by this shader program. +*/ void QShaderProgram::setFragmentShaderCode(const QByteArray &fragmentShaderCode) { Q_D(QShaderProgram); @@ -222,14 +230,15 @@ QByteArray QShaderProgram::fragmentShaderCode() const } /*! - \qmlproperty QByteArray Qt3D.Render::ShaderProgram::computeShaderCode - Specifies the compute shader code to be used -*/ + \qmlproperty string ShaderProgram::computeShaderCode + Holds the compute shader code used by this shader program. +*/ /*! - \property Qt3DRender::QShaderProgram::computeShaderCode - Specifies the compute shader code to be used - */ + \property QShaderProgram::computeShaderCode + + Holds the compute shader code used by this shader program. +*/ void QShaderProgram::setComputeShaderCode(const QByteArray &computeShaderCode) { Q_D(QShaderProgram); @@ -247,8 +256,8 @@ QByteArray QShaderProgram::computeShaderCode() const /*! - * Sets the \a type shader from raw data in \a shaderCode. - */ + Sets the shader code for \a type of shader to the \a shaderCode. +*/ void QShaderProgram::setShaderCode(ShaderType type, const QByteArray &shaderCode) { switch (type) { @@ -276,8 +285,8 @@ void QShaderProgram::setShaderCode(ShaderType type, const QByteArray &shaderCode } /*! - * Returns the \a type shader code. - */ + Returns the shader code for \a type. +*/ QByteArray QShaderProgram::shaderCode(ShaderType type) const { Q_D(const QShaderProgram); @@ -332,13 +341,13 @@ static QByteArray deincludify(const QString &filePath) } /*! - \qmlmethod QByteArray ShaderProgram::loadSource(const QUrl &sourceUrl) + \qmlmethod string ShaderProgram::loadSource(url sourceUrl) Returns the shader code loaded from \a sourceUrl. */ /*! - * Returns the shader code loaded from \a sourceUrl. - */ + Returns the shader code loaded from \a sourceUrl. +*/ QByteArray QShaderProgram::loadSource(const QUrl &sourceUrl) { // TO DO: Handle remote path diff --git a/src/render/materialsystem/qtechnique.cpp b/src/render/materialsystem/qtechnique.cpp index f114e2754..74505bfbd 100644 --- a/src/render/materialsystem/qtechnique.cpp +++ b/src/render/materialsystem/qtechnique.cpp @@ -61,25 +61,62 @@ QTechniquePrivate::~QTechniquePrivate() } /*! - * \qmltype Technique - * \instantiates Qt3DRender::QTechnique - * \inqmlmodule Qt3D.Render - * \brief Encapsulates a Technique. + \qmltype Technique + \instantiates Qt3DRender::QTechnique + \inqmlmodule Qt3D.Render + \inherits Qt3DCore::QNode + \since 5.7 + \brief Encapsulates a Technique. + + A Technique specifies a set of RenderPass objects, FilterKey objects, Parameter objects + and a GraphicsApiFilter, which together define a rendering technique the given + graphics API can render. The filter keys are used by TechniqueFilter + to select specific techinques at specific parts of the FrameGraph. + If the same parameter is specified both in Technique and RenderPass, the one + in Technique overrides the one used in the RenderPass. + + \sa Qt3D.Render::Effect */ /*! - * \class Qt3DRender::QTechnique - * \inmodule Qt3DRender - * - * \inherits Node - * - * \brief Encapsulates a Technique. + \class Qt3DRender::QTechnique + \inmodule Qt3DRender + \inherits Node + \since 5.7 + \brief Encapsulates a Technique. + + A Qt3DRender::QTechnique specifies a set of Qt3DRender::QRenderPass objects, + Qt3DRender::QFilterKey objects, Qt3DRender::QParameter objects and + a Qt3DRender::QGraphicsApiFilter, which together define a rendering technique the given + graphics API can render. The filter keys are used by Qt3DRender::QTechniqueFilter + to select specific techinques at specific parts of the FrameGraph. + If the same parameter is specified both in QTechnique and QRenderPass, the one + in QTechnique overrides the one used in the QRenderPass. + + \sa Qt3DRender::QEffect */ /*! - \fn Qt3DRender::QTechnique::QTechnique(Qt3DCore::QNode *parent) - Constructs a new QTechnique with the specified \a parent. + \qmlproperty GraphicsApiFilter Qt3D.Render::Technique::graphicsApiFilter + Specifies the graphics API filter being used +*/ +/*! + \qmlproperty list<FilterKey> Qt3D.Render::Technique::filterKeys + Specifies the list of filter keys enabling this technique +*/ +/*! + \qmlproperty list<RenderPass> Qt3D.Render::Technique::renderPasses + Specifies the render passes used by the tehcnique +*/ +/*! + \qmlproperty list<Parameter> Qt3D.Render::Technique::parameters + Specifies the parameters used by the technique +*/ +/*! + \property Qt3DRender::QTechnique::graphicsApiFilter + Specifies the graphics API filter being used */ + QTechnique::QTechnique(QNode *parent) : QNode(*new QTechniquePrivate, parent) { @@ -112,7 +149,7 @@ void QTechniquePrivate::_q_graphicsApiFilterChanged() } /*! - * Add \a filterKey to the Qt3DRender::QTechnique local filter keys. + Add \a filterKey to the Qt3DRender::QTechnique local filter keys. */ void QTechnique::addFilterKey(QFilterKey *filterKey) { @@ -140,7 +177,7 @@ void QTechnique::addFilterKey(QFilterKey *filterKey) } /*! - * Removes \a filterKey from the Qt3DRender::QTechnique local filter keys. + Removes \a filterKey from the Qt3DRender::QTechnique local filter keys. */ void QTechnique::removeFilterKey(QFilterKey *filterKey) { @@ -157,8 +194,8 @@ void QTechnique::removeFilterKey(QFilterKey *filterKey) } /*! - * Returns the list of Qt3DCore::QFilterKey key objects making up the filter keys - * of the Qt3DRender::QTechnique. + Returns the list of Qt3DCore::QFilterKey key objects making up the filter keys + of the Qt3DRender::QTechnique. */ QVector<QFilterKey *> QTechnique::filterKeys() const { @@ -167,7 +204,7 @@ QVector<QFilterKey *> QTechnique::filterKeys() const } /*! - * Add \a parameter to the techniques parameters. + Add \a parameter to the technique's parameters. */ void QTechnique::addParameter(QParameter *parameter) { @@ -195,7 +232,7 @@ void QTechnique::addParameter(QParameter *parameter) } /*! - * Remove \a parameter from the techniques parameters. + Remove \a parameter from the technique's parameters. */ void QTechnique::removeParameter(QParameter *parameter) { @@ -212,7 +249,7 @@ void QTechnique::removeParameter(QParameter *parameter) } /*! - * Appends a \a pass to the technique. + Appends a \a pass to the technique. */ void QTechnique::addRenderPass(QRenderPass *pass) { @@ -240,14 +277,14 @@ void QTechnique::addRenderPass(QRenderPass *pass) } /*! - * Removes a \a pass from the technique. + Removes a \a pass from the technique. */ void QTechnique::removeRenderPass(QRenderPass *pass) { Q_ASSERT(pass); Q_D(QTechnique); if (d->m_changeArbiter) { - const auto change = QPropertyNodeAddedChangePtr::create(id(), pass); + const auto change = QPropertyNodeRemovedChangePtr::create(id(), pass); change->setPropertyName("pass"); d->notifyObservers(change); } @@ -257,7 +294,7 @@ void QTechnique::removeRenderPass(QRenderPass *pass) } /*! - * Returns the list of render passes contained in the technique. + Returns the list of render passes contained in the technique. */ QVector<QRenderPass *> QTechnique::renderPasses() const { @@ -266,7 +303,7 @@ QVector<QRenderPass *> QTechnique::renderPasses() const } /*! - * Returns a vector of the techniques current parameters + Returns a vector of the techniques current parameters */ QVector<QParameter *> QTechnique::parameters() const { @@ -274,15 +311,6 @@ QVector<QParameter *> QTechnique::parameters() const return d->m_parameters; } -/*! - \qmlproperty QByteArray Qt3D.Render::Technique::graphicsApiFilter - Specifies the graphics API filter being used -*/ - -/*! - \property Qt3DRender::QTechnique::graphicsApiFilter - Specifies the graphics API filter being used - */ QGraphicsApiFilter *QTechnique::graphicsApiFilter() { Q_D(QTechnique); diff --git a/src/render/materialsystem/shader_p.h b/src/render/materialsystem/shader_p.h index 1382e287e..283e5a94c 100644 --- a/src/render/materialsystem/shader_p.h +++ b/src/render/materialsystem/shader_p.h @@ -52,7 +52,7 @@ // #include <Qt3DRender/private/backendnode_p.h> -#include <Qt3DRender/private/quniformvalue_p.h> +#include <Qt3DRender/private/shaderparameterpack_p.h> #include <Qt3DRender/private/shadervariables_p.h> #include <QMutex> #include <QVector> diff --git a/src/render/materialsystem/shaderdata.cpp b/src/render/materialsystem/shaderdata.cpp index 1f68bed13..e7c8a1c37 100644 --- a/src/render/materialsystem/shaderdata.cpp +++ b/src/render/materialsystem/shaderdata.cpp @@ -94,7 +94,6 @@ void ShaderData::initializeFromPeer(const QNodeCreatedChangeBasePtr &change) const QVariant &propertyValue = entry.second; const QString propertyName = QString::fromLatin1(entry.first); - m_properties.insert(propertyName, propertyValue); m_originalProperties.insert(propertyName, propertyValue); // We check if the property is a QNodeId or QVector<QNodeId> so that we can @@ -108,14 +107,15 @@ void ShaderData::initializeFromPeer(const QNodeCreatedChangeBasePtr &change) } } - // We look for transformed properties - QHash<QString, QVariant>::iterator it = m_properties.begin(); - const QHash<QString, QVariant>::iterator end = m_properties.end(); + // We look for transformed properties once the complete hash of + // originalProperties is available + QHash<QString, QVariant>::iterator it = m_originalProperties.begin(); + const QHash<QString, QVariant>::iterator end = m_originalProperties.end(); while (it != end) { if (static_cast<QMetaType::Type>(it.value().type()) == QMetaType::QVector3D) { // if there is a matching QShaderData::TransformType propertyTransformed - QVariant value = m_properties.value(it.key() + QLatin1String("Transformed")); + QVariant value = m_originalProperties.value(it.key() + QLatin1String("Transformed")); // if that's the case, we apply a space transformation to the property if (value.isValid() && value.type() == QVariant::Int) m_transformedProperties.insert(it.key(), static_cast<TransformType>(value.toInt())); @@ -138,135 +138,67 @@ ShaderData *ShaderData::lookupResource(QNodeId id) // Call by cleanup job (single thread) void ShaderData::clearUpdatedProperties() { - m_updatedProperties.clear(); - const QHash<QString, QVariant>::const_iterator end = m_nestedShaderDataProperties.end(); - QHash<QString, QVariant>::const_iterator it = m_nestedShaderDataProperties.begin(); - - while (it != end) { - if (it.value().userType() == QMetaType::QVariantList) { - const auto values = it.value().value<QVariantList>(); - for (const QVariant &v : values) { - ShaderData *nested = lookupResource(v.value<QNodeId>()); - if (nested != nullptr) - nested->clearUpdatedProperties(); - } - } else { - ShaderData *nested = lookupResource(it.value().value<QNodeId>()); - if (nested != nullptr) - nested->clearUpdatedProperties(); - } - ++it; - } + // DISABLED: Is only useful when building UBO from a ShaderData, which is disable since 5.7 + // const QHash<QString, QVariant>::const_iterator end = m_nestedShaderDataProperties.end(); + // QHash<QString, QVariant>::const_iterator it = m_nestedShaderDataProperties.begin(); + + // while (it != end) { + // if (it.value().userType() == QMetaType::QVariantList) { + // const auto values = it.value().value<QVariantList>(); + // for (const QVariant &v : values) { + // ShaderData *nested = lookupResource(v.value<QNodeId>()); + // if (nested != nullptr) + // nested->clearUpdatedProperties(); + // } + // } else { + // ShaderData *nested = lookupResource(it.value().value<QNodeId>()); + // if (nested != nullptr) + // nested->clearUpdatedProperties(); + // } + // ++it; + // } } void ShaderData::cleanup(NodeManagers *managers) { - for (Qt3DCore::QNodeId id : qAsConst(m_updatedShaderData)) { - ShaderData *shaderData = ShaderData::lookupResource(managers, id); - if (shaderData) - shaderData->clearUpdatedProperties(); - } + Q_UNUSED(managers) + // DISABLED: Is only useful when building UBO from a ShaderData, which is disable since 5.7 + // for (Qt3DCore::QNodeId id : qAsConst(m_updatedShaderData)) { + // ShaderData *shaderData = ShaderData::lookupResource(managers, id); + // if (shaderData) + // shaderData->clearUpdatedProperties(); + // } m_updatedShaderData.clear(); } -// Called by renderview jobs (several concurrent threads) -/*! - \internal - Lookup if the current ShaderData or a nested ShaderData has updated properties. - UpdateProperties contains either the value of the propertie of a QNodeId if it's another ShaderData. - Transformed properties are updated for all of ShaderData that have ones at the point. - - \note This needs to be performed for every top level ShaderData every time it is used. - As we don't know if the transformed properties use the same viewMatrix for all RenderViews. - */ -bool ShaderData::updateViewTransform(const QMatrix4x4 &viewMatrix) +QVariant ShaderData::getTransformedProperty(const QString &name, const QMatrix4x4 &viewMatrix) { - // We can't perform this only once as we don't know if we would be call as the root or a - // nested ShaderData - QMutexLocker lock(&m_mutex); - - // Update transformed properties - // We check the matrices and decide if the transform has changed since the previous call to needsUpdate - if (m_viewMatrix != viewMatrix) { - m_viewMatrix = viewMatrix; - const QHash<QString, TransformType>::const_iterator transformedEnd = m_transformedProperties.end(); - QHash<QString, TransformType>::const_iterator transformedIt = m_transformedProperties.begin(); - - while (transformedIt != transformedEnd) { - if (transformedIt.value() == ModelToEye) { - m_updatedProperties.insert(transformedIt.key(), m_viewMatrix * m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); - m_properties.insert(transformedIt.key(), m_viewMatrix * m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); - } - ++transformedIt; + // Note protecting m_worldMatrix at this point as we assume all world updates + // have been performed when reaching this point + auto it = m_transformedProperties.find(name); + if (it != m_transformedProperties.end()) { + const TransformType transformType = it.value(); + switch (transformType) { + case ModelToEye: + return QVariant::fromValue(viewMatrix * m_worldMatrix * m_originalProperties.value(name).value<QVector3D>()); + case ModelToWorld: + return QVariant::fromValue(m_worldMatrix * m_originalProperties.value(it.key()).value<QVector3D>()); + case ModelToWorldDirection: + return QVariant::fromValue((m_worldMatrix * QVector4D(m_originalProperties.value(it.key()).value<QVector3D>(), 0.0f)).toVector3D()); + case NoTransform: + break; } } - const QHash<QString, QVariant>::const_iterator end = m_nestedShaderDataProperties.end(); - QHash<QString, QVariant>::const_iterator it = m_nestedShaderDataProperties.begin(); - - while (it != end) { - const int userType = it.value().userType(); - - if (userType == QMetaType::QVariantList) { - QVariantList updatedNodes; - bool nestedNeedsUpdate = false; - const QVariantList values = variant_value<QVariantList>(it.value()); - for (const QVariant &v : values) { - if (v.userType() != qNodeIdTypeId) - continue; - - const Qt3DCore::QNodeId nestedId = variant_value<Qt3DCore::QNodeId>(v); - ShaderData *nested = lookupResource(nestedId); - if (nested != nullptr) { - // We need to add the nested nodes to the updated property list - // as we need to maintain order - // if node[0] doesn't need update but node[1] does, - // if we only have a single element, the renderer would update element [0] - nestedNeedsUpdate |= nested->updateViewTransform(viewMatrix); - updatedNodes << v; - } - } - // Of course we only add all the nodes if at least one of the nested nodes required and update - if (nestedNeedsUpdate && !updatedNodes.empty()) - m_updatedProperties.insert(it.key(), updatedNodes); - } else if (userType == qNodeIdTypeId) { - const Qt3DCore::QNodeId nestedId = variant_value<Qt3DCore::QNodeId>(it.value()); - ShaderData *nested = lookupResource(nestedId); - if (nested != nullptr && nested->updateViewTransform(viewMatrix)) - m_updatedProperties.insert(it.key(), it.value()); - } - ++it; - } - return m_updatedProperties.size() > 0; + return QVariant(); } -bool ShaderData::updateWorldTransform(const QMatrix4x4 &worldMatrix) +// Called by FramePreparationJob or by RenderView when dealing with lights +void ShaderData::updateWorldTransform(const QMatrix4x4 &worldMatrix) { - // TODO: Factor this out into a job that populates data in the corresponding - // renderview or other intermediate data structure. See QTBUG-54818 QMutexLocker lock(&m_mutex); if (m_worldMatrix != worldMatrix) { m_worldMatrix = worldMatrix; - - const QHash<QString, TransformType>::const_iterator transformedEnd = m_transformedProperties.end(); - QHash<QString, TransformType>::const_iterator transformedIt = m_transformedProperties.begin(); - - while (transformedIt != transformedEnd) { - if (transformedIt.value() == ModelToEye) { - m_updatedProperties.insert(transformedIt.key(), m_viewMatrix * m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); - m_properties.insert(transformedIt.key(), m_viewMatrix * m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); - } else if (transformedIt.value() == ModelToWorldDirection) { - auto localDirection = QVector4D(m_originalProperties.value(transformedIt.key()).value<QVector3D>(), 0.0f); - auto worldDirection = (m_worldMatrix * localDirection).toVector3D(); - m_updatedProperties.insert(transformedIt.key(), worldDirection); - m_properties.insert(transformedIt.key(), worldDirection); - } else { - m_updatedProperties.insert(transformedIt.key(), m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); - m_properties.insert(transformedIt.key(), m_worldMatrix * m_originalProperties.value(transformedIt.key()).value<QVector3D>()); - } - ++transformedIt; - } } - return m_updatedProperties.size() > 0; } // This will add the ShaderData to be cleared from updates at the end of the frame @@ -279,6 +211,21 @@ void ShaderData::markDirty() ShaderData::m_updatedShaderData.append(peerId()); } +/*! + \internal + Lookup if the current ShaderData or a nested ShaderData has updated properties. + UpdateProperties contains either the value of the propertie of a QNodeId if it's another ShaderData. + Transformed properties are updated for all of ShaderData that have ones at the point. + + \note This needs to be performed for every top level ShaderData every time it is used. + As we don't know if the transformed properties use the same viewMatrix for all RenderViews. + */ + +ShaderData::TransformType ShaderData::propertyTransformType(const QString &name) const +{ + return m_transformedProperties.value(name, TransformType::NoTransform); +} + void ShaderData::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) { if (!m_propertyReader.isNull() && e->type() == PropertyUpdated) { @@ -297,19 +244,7 @@ void ShaderData::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) // Note we aren't notified about nested QShaderData in this call // only scalar / vec properties - if (m_properties.contains(propertyName)) { - // If this is a Transformed property, we need to multiply against the correct - // matrices - m_originalProperties.insert(propertyName, propertyValue); - if (m_transformedProperties.contains(propertyName)) { - if (m_transformedProperties[propertyName] == ModelToEye) - propertyValue = m_viewMatrix * m_worldMatrix * propertyValue.value<QVector3D>(); - else - propertyValue = m_worldMatrix * propertyValue.value<QVector3D>(); - } - m_properties.insert(propertyName, propertyValue); - m_updatedProperties.insert(propertyName, propertyValue); - } + m_originalProperties.insert(propertyName, propertyValue); BackendNode::markDirty(AbstractRenderer::AllDirty); } diff --git a/src/render/materialsystem/shaderdata_p.h b/src/render/materialsystem/shaderdata_p.h index 46dd26faf..6ce0c734c 100644 --- a/src/render/materialsystem/shaderdata_p.h +++ b/src/render/materialsystem/shaderdata_p.h @@ -71,6 +71,7 @@ class Q_AUTOTEST_EXPORT ShaderData : public BackendNode { public: enum TransformType { + NoTransform = -1, ModelToEye = 0, ModelToWorld, ModelToWorldDirection @@ -79,15 +80,16 @@ public: ShaderData(); ~ShaderData(); - QHash<QString, QVariant> properties() const { return m_properties; } - QHash<QString, QVariant> updatedProperties() const { return m_updatedProperties; } + QHash<QString, QVariant> properties() const { return m_originalProperties; } // Called by FramePreparationJob - bool updateWorldTransform(const QMatrix4x4 &worldMatrix); + void updateWorldTransform(const QMatrix4x4 &worldMatrix); // Call by RenderViewJob void markDirty(); - bool updateViewTransform(const QMatrix4x4 &viewMatrix); + + TransformType propertyTransformType(const QString &name) const; + QVariant getTransformedProperty(const QString &name, const QMatrix4x4 &viewMatrix); // Called by FrameCleanupJob static void cleanup(NodeManagers *managers); @@ -98,17 +100,18 @@ protected: void initializeFromPeer(const Qt3DCore::QNodeCreatedChangeBasePtr &change) Q_DECL_OVERRIDE; void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &e) Q_DECL_OVERRIDE; + PropertyReaderInterfacePtr m_propertyReader; + // 1 to 1 match with frontend properties, modified only by sceneChangeEvent QHash<QString, QVariant> m_originalProperties; - // 1 to 1 match with frontend properties apart from Transformed - // properties which contain the matrices product - QHash<QString, QVariant> m_properties; - // only updated properties, Transformed properties have the same - // value as in m_properties - QHash<QString, QVariant> m_updatedProperties; - PropertyReaderInterfacePtr m_propertyReader; + + // Contains properties thar are of type ShaderData QHash<QString, QVariant> m_nestedShaderDataProperties; + + // Contains property that are defined like: postionTransformed: ModelToEye QHash<QString, TransformType> m_transformedProperties; + + QMutex m_mutex; static QVector<Qt3DCore::QNodeId> m_updatedShaderData; QMatrix4x4 m_worldMatrix; diff --git a/src/render/renderstates/qblendequation.cpp b/src/render/renderstates/qblendequation.cpp index de999a19f..e48e83883 100644 --- a/src/render/renderstates/qblendequation.cpp +++ b/src/render/renderstates/qblendequation.cpp @@ -39,9 +39,10 @@ ****************************************************************************/ /*! - * \class QBlendEquation + * \class Qt3DRender::QBlendEquation * \brief The QBlendEquation class specifies the equation used for both the RGB * blend equation and the Alpha blend equation + * \inmodule Qt3DRender * \since 5.7 * \ingroup renderstates * @@ -49,6 +50,19 @@ * already in the framebuffer. */ +/*! + \qmltype BlendEquation + \instantiates Qt3DRender::QBlendEquation + \inherits RenderState + \inqmlmodule Qt3D.Render + \since 5.5 + \brief The BlendEquation class specifies the equation used for both the RGB + blend equation and the Alpha blend equation + + The blend equation is used to determine how a new pixel is combined with a pixel + already in the framebuffer. +*/ + #include "qblendequation.h" #include "qblendequation_p.h" #include <Qt3DRender/private/qrenderstatecreatedchange_p.h> @@ -70,17 +84,34 @@ QBlendEquation::~QBlendEquation() { } +/*! + \enum Qt3DRender::QBlendEquation::BlendFunction + + \value Add GL_FUNC_ADD + \value Subtract GL_FUNC_SUBTRACT + \value ReverseSubtract GL_FUNC_REVERSE_SUBTRACT + \value Min GL_MIN + \value Max GL_MAX +*/ + +/*! + \qmlproperty enumeration BlendEquation::blendFunction + + Holds the blend function, which determines how source and destination colors are combined. + */ + +/*! + \property QBlendEquation::blendFunction + + Holds the blend function, which determines how source and destination colors are combined. + */ + QBlendEquation::BlendFunction QBlendEquation::blendFunction() const { Q_D(const QBlendEquation); return d->m_blendFunction; } -/*! - * Sets the function used to decide how the source and destination colors are combined, - * to \a blendFunction. - * \param blendFunction - */ void QBlendEquation::setBlendFunction(QBlendEquation::BlendFunction blendFunction) { Q_D(QBlendEquation); diff --git a/src/render/renderstates/qblendequationarguments.cpp b/src/render/renderstates/qblendequationarguments.cpp index cbb3ff886..58c048138 100644 --- a/src/render/renderstates/qblendequationarguments.cpp +++ b/src/render/renderstates/qblendequationarguments.cpp @@ -125,12 +125,12 @@ QBlendEquationArguments::QBlendEquationArguments(QBlendEquationArgumentsPrivate */ /*! - \qmlproperty enumeration Qt3D.Render::BlendEquationArguments::sourceRgb + \qmlproperty enumeration BlendEquationArguments::sourceRgb */ /*! - \property Qt3DRender::QBlendEquationArguments::sourceRgb + \property QBlendEquationArguments::sourceRgb */ QBlendEquationArguments::Blending QBlendEquationArguments::sourceRgb() const @@ -152,12 +152,12 @@ void QBlendEquationArguments::setSourceRgb(QBlendEquationArguments::Blending sou } /*! - \qmlproperty enumeration Qt3D.Render::BlendEquationArguments::destinationRgb + \qmlproperty enumeration BlendEquationArguments::destinationRgb */ /*! - \property Qt3DRender::QBlendEquationArguments::destinationRgb + \property QBlendEquationArguments::destinationRgb */ QBlendEquationArguments::Blending QBlendEquationArguments::destinationRgb() const @@ -179,12 +179,12 @@ void QBlendEquationArguments::setDestinationRgb(QBlendEquationArguments::Blendin } /*! - \qmlproperty enumeration Qt3D.Render::BlendEquationArguments::sourceAlpha + \qmlproperty enumeration BlendEquationArguments::sourceAlpha */ /*! - \property Qt3DRender::QBlendEquationArguments::sourceAlpha + \property QBlendEquationArguments::sourceAlpha */ QBlendEquationArguments::Blending QBlendEquationArguments::sourceAlpha() const @@ -206,12 +206,12 @@ void QBlendEquationArguments::setSourceAlpha(QBlendEquationArguments::Blending s } /*! - \qmlproperty enumeration Qt3D.Render::BlendEquationArguments::DestinationAlpha + \qmlproperty enumeration BlendEquationArguments::DestinationAlpha */ /*! - \property Qt3DRender::QBlendEquationArguments::destinationAlpha + \property QBlendEquationArguments::destinationAlpha */ QBlendEquationArguments::Blending QBlendEquationArguments::destinationAlpha() const @@ -232,12 +232,30 @@ void QBlendEquationArguments::setDestinationAlpha(QBlendEquationArguments::Blend } } +/*! + \fn QBlendEquationArguments::sourceRgbaChanged(Blending sourceRgba) + + Notify that both sourceRgb and sourceAlpha properties have changed to \a sourceRgba. +*/ +/*! + \fn QBlendEquationArguments::destinationRgbaChanged(Blending destinationRgba) + + Notify that both destinationRgb and destinationAlpha properties have changed to + \a destinationRgba. +*/ + +/*! + Change both sourceRgb and sourceAlpha properties to \a sourceRgba. +*/ void QBlendEquationArguments::setSourceRgba(Blending sourceRgba) { setSourceRgb(sourceRgba); setSourceAlpha(sourceRgba); } +/*! + Change both destinationRgb and destinationAlpha properties to \a destinationRgba. +*/ void QBlendEquationArguments::setDestinationRgba(Blending destinationRgba) { setDestinationRgb(destinationRgba); @@ -245,14 +263,14 @@ void QBlendEquationArguments::setDestinationRgba(Blending destinationRgba) } /*! - \qmlproperty int Qt3D.Render::BlendEquationArguments::bufferIndex + \qmlproperty int BlendEquationArguments::bufferIndex Specifies the index of the Draw Buffer that this BlendEquationArguments applies to. If negative, this will apply to all Draw Buffers. */ /*! - \property Qt3DRender::QBlendEquationArguments::bufferIndex + \property QBlendEquationArguments::bufferIndex Specifies the index of the Draw Buffer that this BlendEquationArguments applies to. If negative, this will apply to all Draw Buffers. diff --git a/src/render/renderstates/qblendequationarguments.h b/src/render/renderstates/qblendequationarguments.h index 8e2f86f6c..2f844b8cf 100644 --- a/src/render/renderstates/qblendequationarguments.h +++ b/src/render/renderstates/qblendequationarguments.h @@ -92,7 +92,6 @@ public: Blending sourceAlpha() const; Blending destinationAlpha() const; int bufferIndex() const; - bool specifiesAllDrawBuffers() const; public Q_SLOTS: void setSourceRgb(Blending sourceRgb); diff --git a/src/render/renderstates/qpointsize.cpp b/src/render/renderstates/qpointsize.cpp index 8aa2d7e0c..03c37bc4b 100644 --- a/src/render/renderstates/qpointsize.cpp +++ b/src/render/renderstates/qpointsize.cpp @@ -51,11 +51,36 @@ namespace Qt3DRender { \brief Specifies the size of rasterized points. May either be set statically or by shader programs. - When using StaticValue, the value is set using glPointSize(), if available. - When using Programmable, gl_PointSize must be set within shader programs, - the value provided to this RenderState is ignored in that case. + When the sizeMode property is set to SizeMode::Fixed, the value is set + using glPointSize(), if available. When using SizeMode::Programmable, + gl_PointSize must be set within shader programs, the value provided to this + RenderState is ignored in that case. */ +/*! + \qmltype PointSize + \instantiates Qt3DRender::QPointSize + \inqmlmodule Qt3D.Render + + \brief Specifies the size of rasterized points. May either be set statically + or by shader programs. + + When the sizeMode property is set to SizeMode::Fixed, the value is set + using glPointSize(), if available. When using SizeMode::Programmable, + gl_PointSize must be set within shader programs, the value provided to this + RenderState is ignored in that case. + */ + +/*! + \qmlproperty float Qt3D.Render::QPointSize::value + Specifies the point size value to be used. +*/ + +/*! + \qmlproperty QPointSize::SizeMode Qt3D.Render::QPointSize::sizeMode + Specifies the sizeMode to be used. +*/ + QPointSize::QPointSize(Qt3DCore::QNode *parent) : QRenderState(*new QPointSizePrivate(SizeMode::Programmable, 0.f), parent) { diff --git a/src/render/texture/qabstracttextureimage.cpp b/src/render/texture/qabstracttextureimage.cpp index d3694efc9..42e78ced6 100644 --- a/src/render/texture/qabstracttextureimage.cpp +++ b/src/render/texture/qabstracttextureimage.cpp @@ -48,6 +48,40 @@ using namespace Qt3DCore; namespace Qt3DRender { +/*! + \class Qt3DRender::QTextureImageDataGenerator + \inmodule Qt3DRender + \since 5.7 + \brief Provides texture image data for QAbstractTextureImage + + QTextureImageDataGenerator is a data provider for QAbstractTexture. + QTextureImageDataGenerator can be used to expand Qt3D with more ways to load + texture image data as well as support user-defined formats and formats Qt3D + does not natively support. The data is returned by the QTextureImageDataPtr + which contains the data that will be loaded to the texture. + QTextureImageDataGenerator is executed by Aspect jobs in the backend. + */ +/*! + \typedef Qt3DRender::QTextureImageDataPtr + \relates Qt3DRender::QTextureImageDataGenerator + + Shared pointer to \l QTextureImageData. +*/ + +/*! + \fn QTextureImageDataPtr QTextureImageDataGenerator::operator()() + + Implement the method to return the texture image data. +*/ + +/*! + \fn bool QTextureImageDataGenerator::operator ==(const QTextureImageDataGenerator &other) const + + Implement the method to compare this texture data generator to \a other. + The operator is used to check if the \l QAbstractTextureImage needs to reload + the \l QTextureImageData. +*/ + QAbstractTextureImagePrivate::QAbstractTextureImagePrivate() : QNodePrivate(), m_mipLevel(0), @@ -90,6 +124,13 @@ QAbstractTextureImagePrivate::~QAbstractTextureImagePrivate() */ /*! + \fn QTextureImageDataGeneratorPtr QAbstractTextureImage::dataGenerator() const + + Implement this method to return the \l QTextureImageDataGeneratorPtr, which will + provide the data for the texture image. +*/ + +/*! Constructs a new QAbstractTextureImage instance with \a parent as parent. */ QAbstractTextureImage::QAbstractTextureImage(QNode *parent) diff --git a/src/render/texture/qtextureimage.cpp b/src/render/texture/qtextureimage.cpp index dab92082a..dbe0ff05c 100644 --- a/src/render/texture/qtextureimage.cpp +++ b/src/render/texture/qtextureimage.cpp @@ -71,6 +71,59 @@ namespace Qt3DRender { */ /*! + \enum QTextureImage::Status + + This enumeration specifies the status values for texture image loading. + + \value None The texture image loading has not been started yet. + \value Loading The texture image loading has started, but not finised. + \value Ready The texture image loading has finished. + \value Error The texture image loading confronted an error. +*/ + +/*! + \qmlproperty url TextureImage::source + + This property holds the source url from which data for the texture + image will be loaded. +*/ + +/*! + \qmlproperty enumeration TextureImage::status + + This property holds the status of the texture image loading. + + \list + \li TextureImage.None + \li TextureImage.Loading + \li TextureImage.Ready + \li TextureImage.Error + \endlist + \readonly +*/ + +/*! + \property QTextureImage::source + + This property holds the source url from which data for the texture + image will be loaded. +*/ + +/*! + \property QTextureImage::status + + This property holds the status of the texture image loading. + + \list + \li TextureImage.None + \li TextureImage.Loading + \li TextureImage.Ready + \li TextureImage.Error + \endlist + \readonly +*/ + +/*! Constructs a new Qt3DRender::QTextureImage instance with \a parent as parent. */ QTextureImage::QTextureImage(QNode *parent) @@ -93,7 +146,7 @@ QUrl QTextureImage::source() const } /*! - * \return the current status. + \return the current status. */ QTextureImage::Status QTextureImage::status() const { @@ -102,20 +155,6 @@ QTextureImage::Status QTextureImage::status() const } /*! - \property Qt3DRender::QTextureImage::source - - This property holds the source url from which data for the texture - image will be loaded. -*/ - -/*! - \qmlproperty url Qt3D.Render::TextureImage::source - - This property holds the source url from which data for the texture - image will be loaded. -*/ - -/*! Sets the source url of the texture image to \a source. \note This triggers a call to update() */ @@ -130,8 +169,8 @@ void QTextureImage::setSource(const QUrl &source) } /*! - * Sets the status to \a status. - * \param status + Sets the status to \a status. + \param status */ void QTextureImage::setStatus(Status status) { @@ -152,8 +191,8 @@ QTextureImageDataGeneratorPtr QTextureImage::dataGenerator() const } /*! - * Sets the scene change event to \a change. - * \param change + Sets the scene change event to \a change. + \param change */ void QTextureImage::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) { @@ -164,8 +203,8 @@ void QTextureImage::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) } /*! - * The constructor creats a new QImageTextureDataFunctor::QImageTextureDataFunctor - * instance with the specified \a url. + The constructor creates a new QImageTextureDataFunctor::QImageTextureDataFunctor + instance with the specified \a url. */ QImageTextureDataFunctor::QImageTextureDataFunctor(const QUrl &url) : QTextureImageDataGenerator() |