diff options
Diffstat (limited to 'src/quick')
95 files changed, 646 insertions, 3831 deletions
diff --git a/src/quick/CMakeLists.txt b/src/quick/CMakeLists.txt index a8c8aa378c..5450be04ad 100644 --- a/src/quick/CMakeLists.txt +++ b/src/quick/CMakeLists.txt @@ -110,7 +110,6 @@ qt_add_module(Quick scenegraph/coreapi/qsgabstractrenderer_p_p.h scenegraph/coreapi/qsggeometry.cpp scenegraph/coreapi/qsggeometry.h scenegraph/coreapi/qsggeometry_p.h scenegraph/coreapi/qsgmaterial.cpp scenegraph/coreapi/qsgmaterial.h - scenegraph/coreapi/qsgmaterialrhishader.cpp scenegraph/coreapi/qsgmaterialrhishader.h scenegraph/coreapi/qsgmaterialrhishader_p.h scenegraph/coreapi/qsgmaterialshader.cpp scenegraph/coreapi/qsgmaterialshader.h scenegraph/coreapi/qsgmaterialshader_p.h scenegraph/coreapi/qsgmaterialtype.h scenegraph/coreapi/qsgnode.cpp scenegraph/coreapi/qsgnode.h scenegraph/coreapi/qsgnode_p.h @@ -199,76 +198,10 @@ qt_add_module(Quick # Resources: set(scenegraph_resource_files - "shaders/24bittextmask.frag" - "shaders/24bittextmask_core.frag" - "shaders/32bitcolortext.frag" - "shaders/32bitcolortext_core.frag" - "shaders/8bittextmask.frag" - "shaders/8bittextmask_core.frag" - "shaders/distancefieldoutlinetext.frag" - "shaders/distancefieldoutlinetext_core.frag" - "shaders/distancefieldshiftedtext.frag" - "shaders/distancefieldshiftedtext.vert" - "shaders/distancefieldshiftedtext_core.frag" - "shaders/distancefieldshiftedtext_core.vert" - "shaders/distancefieldtext.frag" - "shaders/distancefieldtext.vert" - "shaders/distancefieldtext_core.frag" - "shaders/distancefieldtext_core.vert" - "shaders/flatcolor.frag" - "shaders/flatcolor.vert" - "shaders/flatcolor_core.frag" - "shaders/flatcolor_core.vert" - "shaders/hiqsubpixeldistancefieldtext.frag" - "shaders/hiqsubpixeldistancefieldtext.vert" - "shaders/hiqsubpixeldistancefieldtext_core.frag" - "shaders/hiqsubpixeldistancefieldtext_core.vert" - "shaders/loqsubpixeldistancefieldtext.frag" - "shaders/loqsubpixeldistancefieldtext.vert" - "shaders/loqsubpixeldistancefieldtext_core.frag" - "shaders/loqsubpixeldistancefieldtext_core.vert" - "shaders/opaquetexture.frag" - "shaders/opaquetexture.vert" - "shaders/opaquetexture_core.frag" - "shaders/opaquetexture_core.vert" - "shaders/outlinedtext.frag" - "shaders/outlinedtext.vert" - "shaders/outlinedtext_core.frag" - "shaders/outlinedtext_core.vert" - "shaders/rendernode.frag" - "shaders/rendernode.vert" - "shaders/rendernode_core.frag" - "shaders/rendernode_core.vert" - "shaders/smoothcolor.frag" - "shaders/smoothcolor.vert" - "shaders/smoothcolor_core.frag" - "shaders/smoothcolor_core.vert" - "shaders/smoothtexture.frag" - "shaders/smoothtexture.vert" - "shaders/smoothtexture_core.frag" - "shaders/smoothtexture_core.vert" - "shaders/sprite.frag" - "shaders/sprite.vert" - "shaders/sprite_core.frag" - "shaders/sprite_core.vert" "shaders/stencilclip.frag" "shaders/stencilclip.vert" "shaders/stencilclip_core.frag" "shaders/stencilclip_core.vert" - "shaders/styledtext.frag" - "shaders/styledtext.vert" - "shaders/styledtext_core.frag" - "shaders/styledtext_core.vert" - "shaders/textmask.frag" - "shaders/textmask.vert" - "shaders/textmask_core.frag" - "shaders/textmask_core.vert" - "shaders/texture.frag" - "shaders/texture_core.frag" - "shaders/vertexcolor.frag" - "shaders/vertexcolor.vert" - "shaders/vertexcolor_core.frag" - "shaders/vertexcolor_core.vert" "shaders/visualization.frag" "shaders/visualization.vert" "shaders_ng/24bittextmask.frag.qsb" diff --git a/src/quick/items/qquickopenglshadereffectnode.cpp b/src/quick/items/qquickopenglshadereffectnode.cpp index 919b92780a..019450935f 100644 --- a/src/quick/items/qquickopenglshadereffectnode.cpp +++ b/src/quick/items/qquickopenglshadereffectnode.cpp @@ -107,7 +107,7 @@ void QQuickCustomMaterialShader::deactivate() QOpenGLContext::currentContext()->functions()->glDisable(GL_CULL_FACE); } -void QQuickCustomMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) +void QQuickCustomMaterialShader::updateState(const RenderState &, QSGMaterial *newEffect, QSGMaterial *) { typedef QQuickOpenGLShaderEffectMaterial::UniformData UniformData; @@ -142,6 +142,7 @@ void QQuickCustomMaterialShader::updateState(const RenderState &state, QSGMateri textureProviderIndex = 0; } +#if 0 QOpenGLFunctions *functions = state.context()->functions(); for (int shaderType = 0; shaderType < QQuickOpenGLShaderEffectMaterialKey::ShaderTypeCount; ++shaderType) { for (int i = 0; i < material->uniforms[shaderType].size(); ++i) { @@ -254,6 +255,7 @@ void QQuickCustomMaterialShader::updateState(const RenderState &state, QSGMateri break; } } +#endif } char const *const *QQuickCustomMaterialShader::attributeNames() const diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp index bf26b44498..a3305bf93e 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer.cpp @@ -58,7 +58,7 @@ #include <private/qnumeric_p.h> #include <private/qquickprofiler_p.h> -#include "qsgmaterialrhishader_p.h" +#include "qsgmaterialshader_p.h" #include "qsgopenglvisualizer_p.h" #include "qsgrhivisualizer_p.h" @@ -181,12 +181,12 @@ QRhiVertexInputAttribute::Format qsg_vertexInputFormat(const QSGGeometry::Attrib return QRhiVertexInputAttribute::Float; } -static QRhiVertexInputLayout calculateVertexInputLayout(const QSGMaterialRhiShader *s, const QSGGeometry *geometry, bool batchable) +static QRhiVertexInputLayout calculateVertexInputLayout(const QSGMaterialShader *s, const QSGGeometry *geometry, bool batchable) { Q_ASSERT(geometry); - const QSGMaterialRhiShaderPrivate *sd = QSGMaterialRhiShaderPrivate::get(s); + const QSGMaterialShaderPrivate *sd = QSGMaterialShaderPrivate::get(s); if (!sd->vertexShader) { - qWarning("No vertex shader in QSGMaterialRhiShader %p", s); + qWarning("No vertex shader in QSGMaterialShader %p", s); return QRhiVertexInputLayout(); } @@ -269,11 +269,6 @@ ShaderManager::Shader *ShaderManager::prepareMaterial(QSGMaterial *material, boo if (shader) return shader; - if (enableRhiShaders && !material->flags().testFlag(QSGMaterial::SupportsRhiShader)) { - qWarning("The material failed to provide a working QShader pack"); - return nullptr; - } - Q_TRACE_SCOPE(QSG_prepareMaterial); if (QSG_LOG_TIME_COMPILATION().isDebugEnabled()) qsg_renderer_timer.start(); @@ -281,13 +276,11 @@ ShaderManager::Shader *ShaderManager::prepareMaterial(QSGMaterial *material, boo shader = new Shader; if (enableRhiShaders) { - material->setFlag(QSGMaterial::RhiShaderWanted, true); - QSGMaterialRhiShader *s = static_cast<QSGMaterialRhiShader *>(material->createShader()); - material->setFlag(QSGMaterial::RhiShaderWanted, false); + QSGMaterialShader *s = static_cast<QSGMaterialShader *>(material->createShader()); context->initializeRhiShader(s, QShader::BatchableVertexShader); shader->programRhi.program = s; shader->programRhi.inputLayout = calculateVertexInputLayout(s, geometry, true); - QSGMaterialRhiShaderPrivate *sD = QSGMaterialRhiShaderPrivate::get(s); + QSGMaterialShaderPrivate *sD = QSGMaterialShaderPrivate::get(s); shader->programRhi.shaderStages = { { QRhiGraphicsShaderStage::Vertex, sD->shader(QShader::VertexStage), QShader::BatchableVertexShader }, { QRhiGraphicsShaderStage::Fragment, sD->shader(QShader::FragmentStage) } @@ -332,11 +325,6 @@ ShaderManager::Shader *ShaderManager::prepareMaterialNoRewrite(QSGMaterial *mate if (shader) return shader; - if (enableRhiShaders && !material->flags().testFlag(QSGMaterial::SupportsRhiShader)) { - qWarning("The material failed to provide a working QShader pack"); - return nullptr; - } - Q_TRACE_SCOPE(QSG_prepareMaterial); if (QSG_LOG_TIME_COMPILATION().isDebugEnabled()) qsg_renderer_timer.start(); @@ -344,13 +332,11 @@ ShaderManager::Shader *ShaderManager::prepareMaterialNoRewrite(QSGMaterial *mate shader = new Shader; if (enableRhiShaders) { - material->setFlag(QSGMaterial::RhiShaderWanted, true); - QSGMaterialRhiShader *s = static_cast<QSGMaterialRhiShader *>(material->createShader()); - material->setFlag(QSGMaterial::RhiShaderWanted, false); + QSGMaterialShader *s = static_cast<QSGMaterialShader *>(material->createShader()); context->initializeRhiShader(s, QShader::StandardShader); shader->programRhi.program = s; shader->programRhi.inputLayout = calculateVertexInputLayout(s, geometry, false); - QSGMaterialRhiShaderPrivate *sD = QSGMaterialRhiShaderPrivate::get(s); + QSGMaterialShaderPrivate *sD = QSGMaterialShaderPrivate::get(s); shader->programRhi.shaderStages = { { QRhiGraphicsShaderStage::Vertex, sD->shader(QShader::VertexStage) }, { QRhiGraphicsShaderStage::Fragment, sD->shader(QShader::FragmentStage) } @@ -393,16 +379,16 @@ void ShaderManager::invalidated() void ShaderManager::clearCachedRendererData() { for (ShaderManager::Shader *sms : stockShaders) { - QSGMaterialRhiShader *s = sms->programRhi.program; + QSGMaterialShader *s = sms->programRhi.program; if (s) { - QSGMaterialRhiShaderPrivate *sd = QSGMaterialRhiShaderPrivate::get(s); + QSGMaterialShaderPrivate *sd = QSGMaterialShaderPrivate::get(s); sd->clearCachedRendererData(); } } for (ShaderManager::Shader *sms : rewrittenShaders) { - QSGMaterialRhiShader *s = sms->programRhi.program; + QSGMaterialShader *s = sms->programRhi.program; if (s) { - QSGMaterialRhiShaderPrivate *sd = QSGMaterialRhiShaderPrivate::get(s); + QSGMaterialShaderPrivate *sd = QSGMaterialShaderPrivate::get(s); sd->clearCachedRendererData(); } } @@ -2892,10 +2878,10 @@ void Renderer::updateClipState(const QSGClipNode *clipList, Batch *batch) // RHI } if (!m_stencilClipCommon.vs.isValid()) - m_stencilClipCommon.vs = QSGMaterialRhiShaderPrivate::loadShader(QLatin1String(":/qt-project.org/scenegraph/shaders_ng/stencilclip.vert.qsb")); + m_stencilClipCommon.vs = QSGMaterialShaderPrivate::loadShader(QLatin1String(":/qt-project.org/scenegraph/shaders_ng/stencilclip.vert.qsb")); if (!m_stencilClipCommon.fs.isValid()) - m_stencilClipCommon.fs = QSGMaterialRhiShaderPrivate::loadShader(QLatin1String(":/qt-project.org/scenegraph/shaders_ng/stencilclip.frag.qsb")); + m_stencilClipCommon.fs = QSGMaterialShaderPrivate::loadShader(QLatin1String(":/qt-project.org/scenegraph/shaders_ng/stencilclip.frag.qsb")); if (!m_stencilClipCommon.replacePs) m_stencilClipCommon.replacePs = buildStencilPipeline(batch, true); @@ -2952,10 +2938,10 @@ void Renderer::enqueueStencilDraw(const Batch *batch) // RHI only } } -void Renderer::setActiveRhiShader(QSGMaterialRhiShader *program, ShaderManager::Shader *shader) // RHI only +void Renderer::setActiveRhiShader(QSGMaterialShader *program, ShaderManager::Shader *shader) // RHI only { Q_ASSERT(m_rhi); - m_currentRhiProgram = program; + m_currentProgram = program; m_currentShader = shader; m_currentMaterial = nullptr; } @@ -3400,26 +3386,26 @@ QRhiTexture *Renderer::dummyTexture() return m_dummyTexture; } -static void rendererToMaterialGraphicsState(QSGMaterialRhiShader::GraphicsPipelineState *dst, +static void rendererToMaterialGraphicsState(QSGMaterialShader::GraphicsPipelineState *dst, GraphicsState *src) { dst->blendEnable = src->blending; // the enum values should match, sanity check it - Q_ASSERT(int(QSGMaterialRhiShader::GraphicsPipelineState::OneMinusSrc1Alpha) == int(QRhiGraphicsPipeline::OneMinusSrc1Alpha)); - Q_ASSERT(int(QSGMaterialRhiShader::GraphicsPipelineState::A) == int(QRhiGraphicsPipeline::A)); - Q_ASSERT(int(QSGMaterialRhiShader::GraphicsPipelineState::CullBack) == int(QRhiGraphicsPipeline::Back)); + Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::OneMinusSrc1Alpha) == int(QRhiGraphicsPipeline::OneMinusSrc1Alpha)); + Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::A) == int(QRhiGraphicsPipeline::A)); + Q_ASSERT(int(QSGMaterialShader::GraphicsPipelineState::CullBack) == int(QRhiGraphicsPipeline::Back)); - dst->srcColor = QSGMaterialRhiShader::GraphicsPipelineState::BlendFactor(src->srcColor); - dst->dstColor = QSGMaterialRhiShader::GraphicsPipelineState::BlendFactor(src->dstColor); + dst->srcColor = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->srcColor); + dst->dstColor = QSGMaterialShader::GraphicsPipelineState::BlendFactor(src->dstColor); - dst->colorWrite = QSGMaterialRhiShader::GraphicsPipelineState::ColorMask(int(src->colorWrite)); + dst->colorWrite = QSGMaterialShader::GraphicsPipelineState::ColorMask(int(src->colorWrite)); - dst->cullMode = QSGMaterialRhiShader::GraphicsPipelineState::CullMode(src->cullMode); + dst->cullMode = QSGMaterialShader::GraphicsPipelineState::CullMode(src->cullMode); } static void materialToRendererGraphicsState(GraphicsState *dst, - QSGMaterialRhiShader::GraphicsPipelineState *src) + QSGMaterialShader::GraphicsPipelineState *src) { dst->blending = src->blendEnable; dst->srcColor = QRhiGraphicsPipeline::BlendFactor(src->srcColor); @@ -3429,7 +3415,7 @@ static void materialToRendererGraphicsState(GraphicsState *dst, } void Renderer::updateMaterialDynamicData(ShaderManager::Shader *sms, - QSGMaterialRhiShader::RenderState &renderState, + QSGMaterialShader::RenderState &renderState, QSGMaterial *material, ShaderManager::ShaderResourceBindingList *bindings, const Batch *batch, @@ -3438,8 +3424,8 @@ void Renderer::updateMaterialDynamicData(ShaderManager::Shader *sms, { m_current_resource_update_batch = m_resourceUpdates; - QSGMaterialRhiShader *shader = sms->programRhi.program; - QSGMaterialRhiShaderPrivate *pd = QSGMaterialRhiShaderPrivate::get(shader); + QSGMaterialShader *shader = sms->programRhi.program; + QSGMaterialShaderPrivate *pd = QSGMaterialShaderPrivate::get(shader); if (pd->ubufBinding >= 0) { m_current_uniform_data = &pd->masterUniformData; const bool changed = shader->updateUniformData(renderState, material, m_currentMaterial); @@ -3455,7 +3441,7 @@ void Renderer::updateMaterialDynamicData(ShaderManager::Shader *sms, ubufRegionSize)); } - for (int binding = 0; binding < QSGMaterialRhiShaderPrivate::MAX_SHADER_RESOURCE_BINDINGS; ++binding) { + for (int binding = 0; binding < QSGMaterialShaderPrivate::MAX_SHADER_RESOURCE_BINDINGS; ++binding) { const QRhiShaderResourceBinding::StageFlags stages = pd->combinedImageSamplerBindings[binding]; if (!stages) continue; @@ -3520,18 +3506,18 @@ void Renderer::updateMaterialDynamicData(ShaderManager::Shader *sms, } void Renderer::updateMaterialStaticData(ShaderManager::Shader *sms, - QSGMaterialRhiShader::RenderState &renderState, + QSGMaterialShader::RenderState &renderState, QSGMaterial *material, Batch *batch, bool *gstateChanged) // RHI only, [prepare step] { - QSGMaterialRhiShader *shader = sms->programRhi.program; + QSGMaterialShader *shader = sms->programRhi.program; *gstateChanged = false; - if (shader->flags().testFlag(QSGMaterialRhiShader::UpdatesGraphicsPipelineState)) { + if (shader->flags().testFlag(QSGMaterialShader::UpdatesGraphicsPipelineState)) { // generate the public mini-state from m_gstate, invoke the material, // write the changes, if any, back to m_gstate, together with a way to // roll those back. - QSGMaterialRhiShader::GraphicsPipelineState shaderPs; + QSGMaterialShader::GraphicsPipelineState shaderPs; rendererToMaterialGraphicsState(&shaderPs, &m_gstate); const bool changed = shader->updateGraphicsPipelineState(renderState, &shaderPs, material, m_currentMaterial); if (changed) { @@ -3604,7 +3590,7 @@ bool Renderer::prepareRenderMergedBatch(Batch *batch, PreparedRenderBatch *rende sms->lastOpacity = m_current_opacity; } - QSGMaterialRhiShaderPrivate *pd = QSGMaterialRhiShaderPrivate::get(sms->programRhi.program); + QSGMaterialShaderPrivate *pd = QSGMaterialShaderPrivate::get(sms->programRhi.program); const int ubufSize = pd->masterUniformData.size(); if (pd->ubufBinding >= 0) { bool ubufRebuild = false; @@ -3628,7 +3614,7 @@ bool Renderer::prepareRenderMergedBatch(Batch *batch, PreparedRenderBatch *rende } } - QSGMaterialRhiShader::RenderState renderState = rhiState(QSGMaterialRhiShader::RenderState::DirtyStates(int(dirty))); + QSGMaterialShader::RenderState renderState = state(QSGMaterialShader::RenderState::DirtyStates(int(dirty))); bool pendingGStatePop = false; updateMaterialStaticData(sms, renderState, material, batch, &pendingGStatePop); @@ -3776,7 +3762,7 @@ bool Renderer::prepareRenderUnmergedBatch(Batch *batch, PreparedRenderBatch *ren QMatrix4x4 rootMatrix = batch->root ? qsg_matrixForRoot(batch->root) : QMatrix4x4(); - QSGMaterialRhiShaderPrivate *pd = QSGMaterialRhiShaderPrivate::get(sms->programRhi.program); + QSGMaterialShaderPrivate *pd = QSGMaterialShaderPrivate::get(sms->programRhi.program); const int ubufSize = pd->masterUniformData.size(); if (pd->ubufBinding >= 0) { int totalUBufSize = 0; @@ -3805,7 +3791,7 @@ bool Renderer::prepareRenderUnmergedBatch(Batch *batch, PreparedRenderBatch *ren } } - QSGMaterialRhiShader::RenderState renderState = rhiState(QSGMaterialRhiShader::RenderState::DirtyStates(int(dirty))); + QSGMaterialShader::RenderState renderState = state(QSGMaterialShader::RenderState::DirtyStates(int(dirty))); bool pendingGStatePop = false; updateMaterialStaticData(sms, renderState, material, batch, &pendingGStatePop); @@ -3826,7 +3812,7 @@ bool Renderer::prepareRenderUnmergedBatch(Batch *batch, PreparedRenderBatch *ren m_current_projection_matrix(2, 3) = 1.0f - e->order * m_zRange; } - QSGMaterialRhiShader::RenderState renderState = rhiState(QSGMaterialRhiShader::RenderState::DirtyStates(int(dirty))); + QSGMaterialShader::RenderState renderState = state(QSGMaterialShader::RenderState::DirtyStates(int(dirty))); ShaderManager::ShaderResourceBindingList bindings; updateMaterialDynamicData(sms, renderState, material, &bindings, batch, ubufOffset, ubufSize); @@ -3970,7 +3956,6 @@ void Renderer::renderBatches() m_currentMaterial = nullptr; m_currentShader = nullptr; m_currentProgram = nullptr; - m_currentRhiProgram = nullptr; m_currentClip = nullptr; m_currentClipState.reset(); diff --git a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h index 3db93bee41..7ac6435fc0 100644 --- a/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgbatchrenderer_p.h @@ -672,7 +672,7 @@ struct ShaderManagerShader int pos_order; } programGL; struct { - QSGMaterialRhiShader *program = nullptr; + QSGMaterialShader *program = nullptr; QRhiVertexInputLayout inputLayout; QVarLengthArray<QRhiGraphicsShaderStage, 2> shaderStages; } programRhi; @@ -804,10 +804,10 @@ private: void renderBatches(); bool ensurePipelineState(Element *e, const ShaderManager::Shader *sms); QRhiTexture *dummyTexture(); - void updateMaterialDynamicData(ShaderManager::Shader *sms, QSGMaterialRhiShader::RenderState &renderState, + void updateMaterialDynamicData(ShaderManager::Shader *sms, QSGMaterialShader::RenderState &renderState, QSGMaterial *material, ShaderManager::ShaderResourceBindingList *bindings, const Batch *batch, int ubufOffset, int ubufRegionSize); - void updateMaterialStaticData(ShaderManager::Shader *sms, QSGMaterialRhiShader::RenderState &renderState, + void updateMaterialStaticData(ShaderManager::Shader *sms, QSGMaterialShader::RenderState &renderState, QSGMaterial *material, Batch *batch, bool *gstateChanged); void checkLineWidth(QSGGeometry *g); bool prepareRenderMergedBatch(Batch *batch, PreparedRenderBatch *renderBatch); @@ -828,7 +828,7 @@ private: bool prepareRhiRenderNode(Batch *batch, PreparedRenderBatch *renderBatch); void renderRhiRenderNode(const Batch *batch); void setActiveShader(QSGMaterialShader *program, ShaderManager::Shader *shader); - void setActiveRhiShader(QSGMaterialRhiShader *program, ShaderManager::Shader *shader); + void setActiveRhiShader(QSGMaterialShader *program, ShaderManager::Shader *shader); bool changeBatchRoot(Node *node, Node *newRoot); void registerBatchRoot(Node *childRoot, Node *parentRoot); @@ -884,7 +884,6 @@ private: ShaderManager *m_shaderManager; // per rendercontext, shared QSGMaterial *m_currentMaterial; QSGMaterialShader *m_currentProgram; - QSGMaterialRhiShader *m_currentRhiProgram; ShaderManager::Shader *m_currentShader; ClipState m_currentClipState; diff --git a/src/quick/scenegraph/coreapi/qsgmaterial.cpp b/src/quick/scenegraph/coreapi/qsgmaterial.cpp index 7984547ef1..0094fc2015 100644 --- a/src/quick/scenegraph/coreapi/qsgmaterial.cpp +++ b/src/quick/scenegraph/coreapi/qsgmaterial.cpp @@ -98,9 +98,9 @@ static void qt_print_material_count() \inmodule QtQuick \ingroup qtquick-scenegraph-materials - The QSGMaterial, QSGMaterialShader and QSGMaterialRhiShader subclasses + The QSGMaterial, QSGMaterialShader and QSGMaterialShader subclasses form a tight relationship. For one scene graph (including nested graphs), - there is one unique QSGMaterialShader or QSGMaterialRhiShader instance + there is one unique QSGMaterialShader or QSGMaterialShader instance which encapsulates the shaders the scene graph uses to render that material, such as a shader to flat coloring of geometry. Each QSGGeometryNode can have a unique QSGMaterial containing the how the shader @@ -110,7 +110,7 @@ static void qt_print_material_count() QSGMaterial has two virtual functions that both need to be implemented. The function type() should return a unique instance for all instances of a specific subclass. The createShader() function should return a new instance - of QSGMaterialShader or QSGMaterialRhiShader, specific to that subclass of + of QSGMaterialShader or QSGMaterialShader, specific to that subclass of QSGMaterial. A minimal QSGMaterial implementation could look like this: @@ -123,27 +123,6 @@ static void qt_print_material_count() }; \endcode - This is suitable only for the OpenGL-based, traditional renderer of the - scene graph. When using the new, graphics API abstracted renderer, - materials must create QSGMaterialRhiShader instances instead, or in - addition: - \code - class Material : public QSGMaterial - { - public: - Material() { setFlag(SupportsRhiShader, true); } - QSGMaterialType *type() const { static QSGMaterialType type; return &type; } - QSGMaterialShader *createShader() { - if (flags().testFlag(RhiShaderWanted)) { - return new RhiShader; - } else { - // this is optional, relevant for materials that intend to be usable with the legacy OpenGL renderer as well - return new Shader; - } - } - }; - \endcode - \note All classes with QSG prefix should be used solely on the scene graph's rendering thread. See \l {Scene Graph and Rendering} for more information. */ @@ -203,17 +182,6 @@ QSGMaterial::~QSGMaterial() \value CustomCompileStep Starting with Qt 5.2, the scene graph will not always call QSGMaterialShader::compile() when its shader program is compiled and linked. Set this flag to enforce that the function is called. - - \value SupportsRhiShader Starting with Qt 5.14, the scene graph supports - QSGMaterialRhiShader as an alternative to the OpenGL-specific - QSGMaterialShader. Set this flag to indicate createShader() is capable of - returning QSGMaterialRhiShader instances when the RhiShaderWanted flag is - set. - - \value RhiShaderWanted This flag is set by the scene graph, not by the - QSGMaterial. When set, and that can only happen when SupportsRhiShader was - set by the material, it indicates that createShader() must return a - QSGMaterialRhiShader instance instead of QSGMaterialShader. */ /*! @@ -279,11 +247,6 @@ int QSGMaterial::compare(const QSGMaterial *other) const The function will be called only once for each material type that exists in the scene graph and will be cached internally. - - When the QSGMaterial reports SupportsRhiShader in flags(), the scene graph - may request a QSGMaterialRhiShader instead of QSGMaterialShader. This is - indicated by having the RhiShaderWanted flag set. In this case the return - value must be a QSGRhiMaterialShader subclass. */ QT_END_NAMESPACE diff --git a/src/quick/scenegraph/coreapi/qsgmaterial.h b/src/quick/scenegraph/coreapi/qsgmaterial.h index cb6e9a456a..fd98c64cca 100644 --- a/src/quick/scenegraph/coreapi/qsgmaterial.h +++ b/src/quick/scenegraph/coreapi/qsgmaterial.h @@ -42,7 +42,6 @@ #include <QtQuick/qtquickglobal.h> #include <QtQuick/qsgmaterialshader.h> -#include <QtQuick/qsgmaterialrhishader.h> #include <QtQuick/qsgmaterialtype.h> QT_BEGIN_NAMESPACE @@ -56,11 +55,7 @@ public: RequiresFullMatrixExceptTranslate = 0x0004 | RequiresDeterminant, // Allow precalculated translation RequiresFullMatrix = 0x0008 | RequiresFullMatrixExceptTranslate, - CustomCompileStep = 0x0010, - - SupportsRhiShader = 0x0020, - - RhiShaderWanted = 0x1000 // // ### Qt 6: remove + CustomCompileStep = 0x0010 }; Q_DECLARE_FLAGS(Flags, Flag) diff --git a/src/quick/scenegraph/coreapi/qsgmaterialrhishader.cpp b/src/quick/scenegraph/coreapi/qsgmaterialrhishader.cpp deleted file mode 100644 index c5cbd0c979..0000000000 --- a/src/quick/scenegraph/coreapi/qsgmaterialrhishader.cpp +++ /dev/null @@ -1,630 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQuick 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 "qsgmaterial.h" -#include "qsgrenderer_p.h" -#include "qsgmaterialrhishader_p.h" -#include <QtCore/QFile> - -QT_BEGIN_NAMESPACE - -/*! - \class QSGMaterialRhiShader - \brief The QSGMaterialRhiShader class represents a graphics API independent shader program. - \inmodule QtQuick - \ingroup qtquick-scenegraph-materials - \since 5.14 - - QSGMaterialRhiShader is a modern, cross-platform alternative to - QSGMaterialShader. The latter is tied to OpenGL and GLSL by design, whereas - QSGMaterialRhiShader is based on QShader, a container for multiple - versions of a graphics shader together with reflection information. - - \note All classes with QSG prefix should be used solely on the scene graph's - rendering thread. See \l {Scene Graph and Rendering} for more information. - */ - -/*! - \enum QSGMaterialRhiShader::Flag - Flag values to indicate special material properties. - - \value UpdatesGraphicsPipelineState Setting this flag enables calling - updateGraphicsPipelineState(). - */ - -QShader QSGMaterialRhiShaderPrivate::loadShader(const QString &filename) -{ - QFile f(filename); - if (!f.open(QIODevice::ReadOnly)) { - qWarning() << "Failed to find shader" << filename; - return QShader(); - } - return QShader::fromSerialized(f.readAll()); -} - -void QSGMaterialRhiShaderPrivate::clearCachedRendererData() -{ - for (int i = 0; i < MAX_SHADER_RESOURCE_BINDINGS; ++i) - textureBindingTable[i] = nullptr; - for (int i = 0; i < MAX_SHADER_RESOURCE_BINDINGS; ++i) - samplerBindingTable[i] = nullptr; -} - -static inline QRhiShaderResourceBinding::StageFlags toSrbStage(QShader::Stage stage) -{ - switch (stage) { - case QShader::VertexStage: - return QRhiShaderResourceBinding::VertexStage; - case QShader::FragmentStage: - return QRhiShaderResourceBinding::FragmentStage; - default: - Q_UNREACHABLE(); - break; - } - return { }; -} - -void QSGMaterialRhiShaderPrivate::prepare(QShader::Variant vertexShaderVariant) -{ - ubufBinding = -1; - ubufSize = 0; - ubufStages = { }; - memset(combinedImageSamplerBindings, 0, sizeof(combinedImageSamplerBindings)); - vertexShader = fragmentShader = nullptr; - masterUniformData.clear(); - - clearCachedRendererData(); - - for (QShader::Stage stage : { QShader::VertexStage, QShader::FragmentStage }) { - auto it = shaderFileNames.find(stage); - if (it != shaderFileNames.end()) { - QString fn = *it; - const QShader s = loadShader(*it); - if (!s.isValid()) - continue; - shaders[stage] = ShaderStageData(s); - // load only once, subsequent prepare() calls will have it all in shaders already - shaderFileNames.erase(it); - } - } - - auto vsIt = shaders.find(QShader::VertexStage); - if (vsIt != shaders.end()) { - vsIt->shaderVariant = vertexShaderVariant; - vsIt->vertexInputLocations.clear(); - vsIt->qt_order_attrib_location = -1; - - const QShaderDescription desc = vsIt->shader.description(); - const QVector<QShaderDescription::InOutVariable> vertexInputs = desc.inputVariables(); - for (const QShaderDescription::InOutVariable &v : vertexInputs) { - const QByteArray name = v.name.toUtf8(); - if (vertexShaderVariant == QShader::BatchableVertexShader - && name == QByteArrayLiteral("_qt_order")) - { - vsIt->qt_order_attrib_location = v.location; - } else { - vsIt->vertexInputLocations.append(v.location); - } - } - - if (vsIt->vertexInputLocations.contains(vsIt->qt_order_attrib_location)) { - qWarning("Vertex input clash in rewritten (batchable) vertex shader at input location %d. " - "Vertex shaders must avoid using this location.", vsIt->qt_order_attrib_location); - } - } - - for (auto it = shaders.begin(); it != shaders.end(); ++it) { - const QShaderDescription desc = it->shader.description(); - - const QVector<QShaderDescription::UniformBlock> ubufs = desc.uniformBlocks(); - const int ubufCount = ubufs.count(); - if (ubufCount > 1) { - qWarning("Multiple uniform blocks found in shader. " - "This should be avoided as Qt Quick supports only one."); - } - for (int i = 0; i < ubufCount; ++i) { - const QShaderDescription::UniformBlock &ubuf(ubufs[i]); - if (ubufBinding == -1 && ubuf.binding >= 0) { - ubufBinding = ubuf.binding; - ubufSize = ubuf.size; - ubufStages |= toSrbStage(it->shader.stage()); - masterUniformData.fill('\0', ubufSize); - } else if (ubufBinding == ubuf.binding && ubuf.binding >= 0) { - if (ubuf.size > ubufSize) { - ubufSize = ubuf.size; - masterUniformData.fill('\0', ubufSize); - } - ubufStages |= toSrbStage(it->shader.stage()); - } else { - qWarning("Uniform block %s (binding %d) ignored", qPrintable(ubuf.blockName), ubuf.binding); - } - } - - const QVector<QShaderDescription::InOutVariable> imageSamplers = desc.combinedImageSamplers(); - const int imageSamplersCount = imageSamplers.count(); - for (int i = 0; i < imageSamplersCount; ++i) { - const QShaderDescription::InOutVariable &var(imageSamplers[i]); - if (var.binding >= 0 && var.binding < MAX_SHADER_RESOURCE_BINDINGS) - combinedImageSamplerBindings[var.binding] |= toSrbStage(it->shader.stage()); - else - qWarning("Encountered invalid combined image sampler (%s) binding %d", - qPrintable(var.name), var.binding); - } - - if (it.key() == QShader::VertexStage) - vertexShader = &it.value(); - else if (it.key() == QShader::FragmentStage) - fragmentShader = &it.value(); - } - - if (vertexShader && vertexShaderVariant == QShader::BatchableVertexShader && vertexShader->qt_order_attrib_location == -1) - qWarning("No rewriter-inserted attribute found, this should not happen."); -} - -/*! - Constructs a new QSGMaterialRhiShader. - */ -QSGMaterialRhiShader::QSGMaterialRhiShader() - : d_ptr(new QSGMaterialRhiShaderPrivate(this)) -{ -} - -/*! - \internal - */ -QSGMaterialRhiShader::QSGMaterialRhiShader(QSGMaterialRhiShaderPrivate &dd) - : d_ptr(&dd) -{ -} - -/*! - \internal - */ -QSGMaterialRhiShader::~QSGMaterialRhiShader() -{ -} - -// We have our own enum as QShader is not initially public. Internally -// everything works with QShader::Stage however. So convert. -static inline QShader::Stage toShaderStage(QSGMaterialRhiShader::Stage stage) -{ - switch (stage) { - case QSGMaterialRhiShader::VertexStage: - return QShader::VertexStage; - case QSGMaterialRhiShader::FragmentStage: - return QShader::FragmentStage; - default: - Q_UNREACHABLE(); - return QShader::VertexStage; - } -} - -/*! - Sets the \a shader for the specified \a stage. - */ -void QSGMaterialRhiShader::setShader(Stage stage, const QShader &shader) -{ - Q_D(QSGMaterialRhiShader); - d->shaders[toShaderStage(stage)] = QSGMaterialRhiShaderPrivate::ShaderStageData(shader); -} - -/*! - Sets the \a filename for the shader for the specified \a stage. - - The file is expected to contain a serialized QRhiShader. - */ -void QSGMaterialRhiShader::setShaderFileName(Stage stage, const QString &filename) -{ - Q_D(QSGMaterialRhiShader); - d->shaderFileNames[toShaderStage(stage)] = filename; -} - -/*! - \return the currently set flags for this material shader. - */ -QSGMaterialRhiShader::Flags QSGMaterialRhiShader::flags() const -{ - Q_D(const QSGMaterialRhiShader); - return d->flags; -} - -/*! - Sets the \a flags on this material shader if \a on is true; - otherwise clears the specified flags. -*/ -void QSGMaterialRhiShader::setFlag(Flags flags, bool on) -{ - Q_D(QSGMaterialRhiShader); - if (on) - d->flags |= flags; - else - d->flags &= ~flags; -} - -/*! - This function is called by the scene graph to get the contents of the - shader program's uniform buffer updated. The implementation is not expected - to perform any real graphics operations, it is merely responsible for - copying data to the QByteArray returned from RenderState::uniformData(). - The scene graph takes care of making that buffer visible in the shaders. - - The current rendering \a state is passed from the scene graph. If the state - indicates that any relevant state is dirty, the implementation must update - the appropriate region in the buffer data that is accessible via - RenderState::uniformData(). When a state, such as, matrix or opacity, is - not dirty, there is no need to touch the corresponding region since the - data is persistent. - - The return value must be \c true whenever any change was made to the uniform data. - - The subclass specific state, such as the color of a flat color material, - should be extracted from \a newMaterial to update the relevant regions in - the buffer accordingly. - - \a oldMaterial can be used to minimize buffer changes (which are typically - memcpy calls) when updating material states. When \a oldMaterial is null, - this shader was just activated. - */ -bool QSGMaterialRhiShader::updateUniformData(RenderState &state, - QSGMaterial *newMaterial, - QSGMaterial *oldMaterial) -{ - Q_UNUSED(state); - Q_UNUSED(newMaterial); - Q_UNUSED(oldMaterial); - return false; -} - -/*! - This function is called by the scene graph to prepare using a sampled image - in the shader, typically in form of a combined image sampler. - - \a binding is the binding number of the sampler. The function is called for - each variable in the material's shaders' - \l{QShaderDescription::combinedImageSamplers()}. - - When *\a{texture} is null, it must be set to a QSGTexture pointer before - returning. When non-null, it is up to the material to decide if a new - \c{QSGTexture *} is stored to it, or if it updates some parameters on the - already known QSGTexture. The ownership of the QSGTexture is not - transferred. - - The current rendering \a state is passed from the scene graph. It is up to - the material to enqueue the texture data uploads to the - QRhiResourceUpdateBatch retriveable via RenderState::resourceUpdateBatch(). - - The subclass specific state can be extracted from \a newMaterial. - - \a oldMaterial can be used to minimize changes. When \a oldMaterial is null, - this shader was just activated. - */ -void QSGMaterialRhiShader::updateSampledImage(RenderState &state, - int binding, - QSGTexture **texture, - QSGMaterial *newMaterial, - QSGMaterial *oldMaterial) -{ - Q_UNUSED(state); - Q_UNUSED(binding); - Q_UNUSED(texture); - Q_UNUSED(newMaterial); - Q_UNUSED(oldMaterial); -} - -/*! - This function is called by the scene graph to enable the material to - provide a custom set of graphics state. The set of states that are - customizable by material is limited to blending and related settings. - - \note This function is only called when the UpdatesGraphicsPipelineState - flag was enabled via setFlags(). By default it is not set, and so this - function is never called. - - The return value must be \c true whenever a change was made to any of the - members in \a ps. - - \note The contents of \a ps is not persistent between invocations of this - function. - - The current rendering \a state is passed from the scene graph. - - The subclass specific state can be extracted from \a newMaterial. When \a - oldMaterial is null, this shader was just activated. - */ -bool QSGMaterialRhiShader::updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps, - QSGMaterial *newMaterial, QSGMaterial *oldMaterial) -{ - Q_UNUSED(state); - Q_UNUSED(ps); - Q_UNUSED(newMaterial); - Q_UNUSED(oldMaterial); - return false; -} - -/*! - \class QSGMaterialRhiShader::RenderState - - \brief Encapsulates the current rendering state during a call to - QSGMaterialRhiShader::updateUniformData() and the other \c update type of - functions. - - \inmodule QtQuick - \since 5.14 - - The render state contains a number of accessors that the shader needs to - respect in order to conform to the current state of the scene graph. - */ - -/*! - \enum QSGMaterialRhiShader::RenderState::DirtyState - - \value DirtyMatrix Used to indicate that the matrix has changed and must be - updated. - - \value DirtyOpacity Used to indicate that the opacity has changed and must - be updated. - - \value DirtyAll Used to indicate that everything needs to be updated. - */ - -/*! - \fn bool QSGMaterialRhiShader::RenderState::isMatrixDirty() const - - Returns \c true if the dirtyStates() contain the dirty matrix state, - otherwise returns \c false. - */ - -/*! - \fn bool QSGMaterialRhiShader::RenderState::isOpacityDirty() const - - Returns \c true if the dirtyStates() contains the dirty opacity state, - otherwise returns \c false. - */ - -/*! - \fn QSGMaterialRhiShader::RenderState::DirtyStates QSGMaterialRhiShader::RenderState::dirtyStates() const - - Returns which rendering states that have changed and needs to be updated - for geometry rendered with this material to conform to the current - rendering state. - */ - -/*! - \class QSGMaterialRhiShader::GraphicsPipelineState - - \brief Describes state changes that the material wants to apply to the - currently active graphics pipeline state. - - \inmodule QtQuick - \since 5.14 - - Unlike QSGMaterialShader, directly issuing state change commands with the - underlying graphics API is not possible with QSGMaterialRhiShader. This is - mainly because the concept of individually changeable states is considered - deprecated and not supported with modern graphics APIs. - - Therefore, it is up to QSGMaterialRhiShader to expose a data structure with - the set of supported states, which the material can change in its - updatePipelineState() implementation, if there is one. The scenegraph will - then internally apply these changes to the active graphics pipeline state, - then rolling them back as appropriate. - */ - -/*! - \enum QSGMaterialRhiShader::GraphicsPipelineState::BlendFactor - \since 5.14 - - \value Zero - \value One - \value SrcColor - \value OneMinusSrcColor - \value DstColor - \value OneMinusDstColor - \value SrcAlpha - \value OneMinusSrcAlpha - \value DstAlpha - \value OneMinusDstAlpha - \value ConstantColor - \value OneMinusConstantColor - \value ConstantAlpha - \value OneMinusConstantAlpha - \value SrcAlphaSaturate - \value Src1Color - \value OneMinusSrc1Color - \value Src1Alpha - \value OneMinusSrc1Alpha - */ - -/*! - \enum QSGMaterialRhiShader::GraphicsPipelineState::ColorMaskComponent - \since 5.14 - - \value R - \value G - \value B - \value A - */ - -/*! - \enum QSGMaterialRhiShader::GraphicsPipelineState::CullMode - \since 5.14 - - \value CullNone - \value CullFront - \value CullBack - */ - -/*! - Returns the accumulated opacity to be used for rendering. - */ -float QSGMaterialRhiShader::RenderState::opacity() const -{ - Q_ASSERT(m_data); - return float(static_cast<const QSGRenderer *>(m_data)->currentOpacity()); -} - -/*! - Returns the modelview determinant to be used for rendering. - */ -float QSGMaterialRhiShader::RenderState::determinant() const -{ - Q_ASSERT(m_data); - return float(static_cast<const QSGRenderer *>(m_data)->determinant()); -} - -/*! - Returns the matrix combined of modelview matrix and project matrix. - */ -QMatrix4x4 QSGMaterialRhiShader::RenderState::combinedMatrix() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentCombinedMatrix(); -} - -/*! - Returns the ratio between physical pixels and device-independent pixels - to be used for rendering. -*/ -float QSGMaterialRhiShader::RenderState::devicePixelRatio() const -{ - Q_ASSERT(m_data); - return float(static_cast<const QSGRenderer *>(m_data)->devicePixelRatio()); -} - -/*! - Returns the model view matrix. - - If the material has the RequiresFullMatrix flag set, this is guaranteed to - be the complete transform matrix calculated from the scenegraph. - - However, if this flag is not set, the renderer may choose to alter this - matrix. For example, it may pre-transform vertices on the CPU and set this - matrix to identity. - - In a situation such as the above, it is still possible to retrieve the - actual matrix determinant by setting the RequiresDeterminant flag in the - material and calling the determinant() accessor. - */ -QMatrix4x4 QSGMaterialRhiShader::RenderState::modelViewMatrix() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentModelViewMatrix(); -} - -/*! - Returns the projection matrix. - */ -QMatrix4x4 QSGMaterialRhiShader::RenderState::projectionMatrix() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentProjectionMatrix(); -} - -/*! - Returns the viewport rect of the surface being rendered to. - */ -QRect QSGMaterialRhiShader::RenderState::viewportRect() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->viewportRect(); -} - -/*! - Returns the device rect of the surface being rendered to - */ -QRect QSGMaterialRhiShader::RenderState::deviceRect() const -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->deviceRect(); -} - -/*! - Returns a pointer to the data for the uniform (constant) buffer in the - shader. Uniform data must only be updated from - QSGMaterialRhiShader::updateUniformData(). The return value is null in the - other reimplementable functions, such as, - QSGMaterialRhiShader::updateSampledImage(). - - \note It is strongly recommended to declare the uniform block with \c - std140 in the shader, and to carefully study the standard uniform block - layout as described in section 7.6.2.2 of the OpenGL specification. It is - up to the QSGMaterialRhiShader implementation to ensure data gets placed - at the right location in this QByteArray, taking alignment requirements - into account. Shader code translated to other shading languages is expected - to use the same offsets for block members, even when the target language - uses different packing rules by default. - - \note Avoid copying from C++ POD types, such as, structs, in order to - update multiple members at once, unless it has been verified that the - layouts of the C++ struct and the GLSL uniform block match. - */ -QByteArray *QSGMaterialRhiShader::RenderState::uniformData() -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentUniformData(); -} - -/*! - Returns a resource update batch to which upload and copy operatoins can be - queued. This is typically used by - QSGMaterialRhiShader::updateSampledImage() to enqueue texture image - content updates. - */ -QRhiResourceUpdateBatch *QSGMaterialRhiShader::RenderState::resourceUpdateBatch() -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentResourceUpdateBatch(); -} - -/*! - Returns the current QRhi. - */ -QRhi *QSGMaterialRhiShader::RenderState::rhi() -{ - Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentRhi(); -} - -char const *const *QSGMaterialRhiShader::attributeNames() const -{ - Q_ASSERT_X(false, "QSGMaterialRhiShader::attributeNames()", "Not implemented for RHI"); - return nullptr; -} - -QT_END_NAMESPACE diff --git a/src/quick/scenegraph/coreapi/qsgmaterialrhishader.h b/src/quick/scenegraph/coreapi/qsgmaterialrhishader.h deleted file mode 100644 index 86208516cd..0000000000 --- a/src/quick/scenegraph/coreapi/qsgmaterialrhishader.h +++ /dev/null @@ -1,182 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQuick 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 QSGMATERIALRHISHADER_H -#define QSGMATERIALRHISHADER_H - -#include <QtQuick/qtquickglobal.h> -#include <QtCore/QRect> -#include <QtGui/QMatrix4x4> -#include <QtGui/QColor> -#include <QtQuick/qsgmaterialshader.h> - -QT_BEGIN_NAMESPACE - -class QSGMaterial; -class QSGMaterialRhiShaderPrivate; -class QSGTexture; -class QRhiResourceUpdateBatch; -class QRhi; -class QShader; - -class Q_QUICK_EXPORT QSGMaterialRhiShader : public QSGMaterialShader // ### Qt 6: remove inheritance -{ -public: - class Q_QUICK_EXPORT RenderState { - public: - using DirtyStates = QSGMaterialShader::RenderState::DirtyStates; - - inline DirtyStates dirtyStates() const { return m_dirty; } - - inline bool isMatrixDirty() const { return m_dirty & QSGMaterialShader::RenderState::DirtyMatrix; } - inline bool isOpacityDirty() const { return m_dirty & QSGMaterialShader::RenderState::DirtyOpacity; } - - float opacity() const; - QMatrix4x4 combinedMatrix() const; - QMatrix4x4 modelViewMatrix() const; - QMatrix4x4 projectionMatrix() const; - QRect viewportRect() const; - QRect deviceRect() const; - float determinant() const; - float devicePixelRatio() const; - - QByteArray *uniformData(); - QRhiResourceUpdateBatch *resourceUpdateBatch(); - QRhi *rhi(); - - private: - friend class QSGRenderer; - DirtyStates m_dirty; - const void *m_data; - }; - - struct Q_QUICK_EXPORT GraphicsPipelineState { - enum BlendFactor { - Zero, - One, - SrcColor, - OneMinusSrcColor, - DstColor, - OneMinusDstColor, - SrcAlpha, - OneMinusSrcAlpha, - DstAlpha, - OneMinusDstAlpha, - ConstantColor, - OneMinusConstantColor, - ConstantAlpha, - OneMinusConstantAlpha, - SrcAlphaSaturate, - Src1Color, - OneMinusSrc1Color, - Src1Alpha, - OneMinusSrc1Alpha - }; - - enum ColorMaskComponent { - R = 1 << 0, - G = 1 << 1, - B = 1 << 2, - A = 1 << 3 - }; - Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent) - - enum CullMode { - CullNone, - CullFront, - CullBack - }; - - bool blendEnable; - BlendFactor srcColor; - BlendFactor dstColor; - ColorMask colorWrite; - QColor blendConstant; - CullMode cullMode; - // This struct is extensible while keeping BC since apps only ever get - // a ptr to the struct, it is not created by them. - }; - - enum Flag { - UpdatesGraphicsPipelineState = 0x0001 - }; - Q_DECLARE_FLAGS(Flags, Flag) - - enum Stage { - VertexStage, - FragmentStage, - }; - - QSGMaterialRhiShader(); - virtual ~QSGMaterialRhiShader(); - - virtual bool updateUniformData(RenderState &state, - QSGMaterial *newMaterial, QSGMaterial *oldMaterial); - - virtual void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, - QSGMaterial *newMaterial, QSGMaterial *oldMaterial); - - virtual bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps, - QSGMaterial *newMaterial, QSGMaterial *oldMaterial); - - Flags flags() const; - void setFlag(Flags flags, bool on = true); - - // dummy impl for base class pure virtual, never called - char const *const *attributeNames() const override; - -protected: - Q_DECLARE_PRIVATE(QSGMaterialRhiShader) - QSGMaterialRhiShader(QSGMaterialRhiShaderPrivate &dd); - - // filename is for a file containing a serialized QShader. - void setShaderFileName(Stage stage, const QString &filename); - - void setShader(Stage stage, const QShader &shader); - -private: - QScopedPointer<QSGMaterialRhiShaderPrivate> d_ptr; -}; - -Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialRhiShader::GraphicsPipelineState::ColorMask) -Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialRhiShader::Flags) - -QT_END_NAMESPACE - -#endif diff --git a/src/quick/scenegraph/coreapi/qsgmaterialrhishader_p.h b/src/quick/scenegraph/coreapi/qsgmaterialrhishader_p.h deleted file mode 100644 index 153b4b120a..0000000000 --- a/src/quick/scenegraph/coreapi/qsgmaterialrhishader_p.h +++ /dev/null @@ -1,114 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQuick 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 QSGMATERIALRHISHADER_P_H -#define QSGMATERIALRHISHADER_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <private/qtquickglobal_p.h> -#include "qsgmaterialrhishader.h" -#include "qsgmaterial.h" -#include <QtGui/private/qrhi_p.h> -#include <QtGui/private/qshader_p.h> - -QT_BEGIN_NAMESPACE - -class QRhiSampler; - -class Q_QUICK_PRIVATE_EXPORT QSGMaterialRhiShaderPrivate -{ -public: - Q_DECLARE_PUBLIC(QSGMaterialRhiShader) - - QSGMaterialRhiShaderPrivate(QSGMaterialRhiShader *q) : q_ptr(q) { } - static QSGMaterialRhiShaderPrivate *get(QSGMaterialRhiShader *s) { return s->d_func(); } - static const QSGMaterialRhiShaderPrivate *get(const QSGMaterialRhiShader *s) { return s->d_func(); } - - void clearCachedRendererData(); - void prepare(QShader::Variant vertexShaderVariant); - - QShader shader(QShader::Stage stage) const { return shaders[stage].shader; } - - static QShader loadShader(const QString &filename); - - QSGMaterialRhiShader *q_ptr; - QHash<QShader::Stage, QString> shaderFileNames; - QSGMaterialRhiShader::Flags flags; - - struct ShaderStageData { - ShaderStageData() { } // so shader.isValid() == false - ShaderStageData(const QShader &shader) : shader(shader) { } - QShader shader; - QShader::Variant shaderVariant = QShader::StandardShader; - QVector<int> vertexInputLocations; // excluding rewriter-inserted ones - int qt_order_attrib_location = -1; // rewriter-inserted - }; - QHash<QShader::Stage, ShaderStageData> shaders; - - static const int MAX_SHADER_RESOURCE_BINDINGS = 32; - - int ubufBinding = -1; - int ubufSize = 0; - QRhiShaderResourceBinding::StageFlags ubufStages; - QRhiShaderResourceBinding::StageFlags combinedImageSamplerBindings[MAX_SHADER_RESOURCE_BINDINGS]; - - ShaderStageData *vertexShader = nullptr; - ShaderStageData *fragmentShader = nullptr; - - QByteArray masterUniformData; - - QSGTexture *textureBindingTable[MAX_SHADER_RESOURCE_BINDINGS]; - QRhiSampler *samplerBindingTable[MAX_SHADER_RESOURCE_BINDINGS]; -}; - -Q_DECLARE_TYPEINFO(QSGMaterialRhiShaderPrivate::ShaderStageData, Q_MOVABLE_TYPE); - -QT_END_NAMESPACE - -#endif // QSGMATERIALRHISHADER_P_H diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp b/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp index 64956e2ca4..57c6007e47 100644 --- a/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp +++ b/src/quick/scenegraph/coreapi/qsgmaterialshader.cpp @@ -40,37 +40,26 @@ #include "qsgmaterial.h" #include "qsgrenderer_p.h" #include "qsgmaterialshader_p.h" -#if QT_CONFIG(opengl) -# include <private/qsgshadersourcebuilder_p.h> -# include <private/qsgdefaultcontext_p.h> -# include <private/qsgdefaultrendercontext_p.h> -# include <QOpenGLFunctions> -# include <QOpenGLContext> -#endif +#include <QtCore/QFile> QT_BEGIN_NAMESPACE -#if QT_CONFIG(opengl) -const char *QSGMaterialShaderPrivate::loadShaderSource(QOpenGLShader::ShaderType type) const -{ - const QStringList files = m_sourceFiles[type]; - QSGShaderSourceBuilder builder; - for (const QString &file : files) - builder.appendSourceFile(file); - m_sources[type] = builder.source(); - return m_sources[type].constData(); -} -#endif - /*! \class QSGMaterialShader - \brief The QSGMaterialShader class represents an OpenGL shader program - in the renderer. + \brief The QSGMaterialShader class represents a graphics API independent shader program. \inmodule QtQuick \ingroup qtquick-scenegraph-materials + \since 5.14 + + // ### glpurge Rewrite to not talk about OpenGL and GLSL directly anymore + + QSGMaterialShader is a modern, cross-platform alternative to + QSGMaterialShader. The latter is tied to OpenGL and GLSL by design, whereas + QSGMaterialShader is based on QShader, a container for multiple + versions of a graphics shader together with reflection information. - \warning This class is only functional when running with the legacy OpenGL - renderer of the Qt Quick scenegraph. + \note All classes with QSG prefix should be used solely on the scene graph's + rendering thread. See \l {Scene Graph and Rendering} for more information. The QSGMaterial and QSGMaterialShader form a tight relationship. For one scene graph (including nested graphs), there is one unique QSGMaterialShader @@ -160,16 +149,150 @@ const char *QSGMaterialShaderPrivate::loadShaderSource(QOpenGLShader::ShaderType \note All classes with QSG prefix should be used solely on the scene graph's rendering thread. See \l {Scene Graph and Rendering} for more information. + */ + +/*! + \enum QSGMaterialShader::Flag + Flag values to indicate special material properties. + \value UpdatesGraphicsPipelineState Setting this flag enables calling + updateGraphicsPipelineState(). */ +QShader QSGMaterialShaderPrivate::loadShader(const QString &filename) +{ + QFile f(filename); + if (!f.open(QIODevice::ReadOnly)) { + qWarning() << "Failed to find shader" << filename; + return QShader(); + } + return QShader::fromSerialized(f.readAll()); +} + +void QSGMaterialShaderPrivate::clearCachedRendererData() +{ + for (int i = 0; i < MAX_SHADER_RESOURCE_BINDINGS; ++i) + textureBindingTable[i] = nullptr; + for (int i = 0; i < MAX_SHADER_RESOURCE_BINDINGS; ++i) + samplerBindingTable[i] = nullptr; +} + +static inline QRhiShaderResourceBinding::StageFlags toSrbStage(QShader::Stage stage) +{ + switch (stage) { + case QShader::VertexStage: + return QRhiShaderResourceBinding::VertexStage; + case QShader::FragmentStage: + return QRhiShaderResourceBinding::FragmentStage; + default: + Q_UNREACHABLE(); + break; + } + return { }; +} + +void QSGMaterialShaderPrivate::prepare(QShader::Variant vertexShaderVariant) +{ + ubufBinding = -1; + ubufSize = 0; + ubufStages = { }; + memset(combinedImageSamplerBindings, 0, sizeof(combinedImageSamplerBindings)); + vertexShader = fragmentShader = nullptr; + masterUniformData.clear(); + + clearCachedRendererData(); + + for (QShader::Stage stage : { QShader::VertexStage, QShader::FragmentStage }) { + auto it = shaderFileNames.find(stage); + if (it != shaderFileNames.end()) { + QString fn = *it; + const QShader s = loadShader(*it); + if (!s.isValid()) + continue; + shaders[stage] = ShaderStageData(s); + // load only once, subsequent prepare() calls will have it all in shaders already + shaderFileNames.erase(it); + } + } + + auto vsIt = shaders.find(QShader::VertexStage); + if (vsIt != shaders.end()) { + vsIt->shaderVariant = vertexShaderVariant; + vsIt->vertexInputLocations.clear(); + vsIt->qt_order_attrib_location = -1; + + const QShaderDescription desc = vsIt->shader.description(); + const QVector<QShaderDescription::InOutVariable> vertexInputs = desc.inputVariables(); + for (const QShaderDescription::InOutVariable &v : vertexInputs) { + const QByteArray name = v.name.toUtf8(); + if (vertexShaderVariant == QShader::BatchableVertexShader + && name == QByteArrayLiteral("_qt_order")) + { + vsIt->qt_order_attrib_location = v.location; + } else { + vsIt->vertexInputLocations.append(v.location); + } + } + + if (vsIt->vertexInputLocations.contains(vsIt->qt_order_attrib_location)) { + qWarning("Vertex input clash in rewritten (batchable) vertex shader at input location %d. " + "Vertex shaders must avoid using this location.", vsIt->qt_order_attrib_location); + } + } + + for (auto it = shaders.begin(); it != shaders.end(); ++it) { + const QShaderDescription desc = it->shader.description(); + + const QVector<QShaderDescription::UniformBlock> ubufs = desc.uniformBlocks(); + const int ubufCount = ubufs.count(); + if (ubufCount > 1) { + qWarning("Multiple uniform blocks found in shader. " + "This should be avoided as Qt Quick supports only one."); + } + for (int i = 0; i < ubufCount; ++i) { + const QShaderDescription::UniformBlock &ubuf(ubufs[i]); + if (ubufBinding == -1 && ubuf.binding >= 0) { + ubufBinding = ubuf.binding; + ubufSize = ubuf.size; + ubufStages |= toSrbStage(it->shader.stage()); + masterUniformData.fill('\0', ubufSize); + } else if (ubufBinding == ubuf.binding && ubuf.binding >= 0) { + if (ubuf.size > ubufSize) { + ubufSize = ubuf.size; + masterUniformData.fill('\0', ubufSize); + } + ubufStages |= toSrbStage(it->shader.stage()); + } else { + qWarning("Uniform block %s (binding %d) ignored", qPrintable(ubuf.blockName), ubuf.binding); + } + } + + const QVector<QShaderDescription::InOutVariable> imageSamplers = desc.combinedImageSamplers(); + const int imageSamplersCount = imageSamplers.count(); + for (int i = 0; i < imageSamplersCount; ++i) { + const QShaderDescription::InOutVariable &var(imageSamplers[i]); + if (var.binding >= 0 && var.binding < MAX_SHADER_RESOURCE_BINDINGS) + combinedImageSamplerBindings[var.binding] |= toSrbStage(it->shader.stage()); + else + qWarning("Encountered invalid combined image sampler (%s) binding %d", + qPrintable(var.name), var.binding); + } + + if (it.key() == QShader::VertexStage) + vertexShader = &it.value(); + else if (it.key() == QShader::FragmentStage) + fragmentShader = &it.value(); + } + if (vertexShader && vertexShaderVariant == QShader::BatchableVertexShader && vertexShader->qt_order_attrib_location == -1) + qWarning("No rewriter-inserted attribute found, this should not happen."); +} /*! - Creates a new QSGMaterialShader. + Constructs a new QSGMaterialShader. */ QSGMaterialShader::QSGMaterialShader() - : d_ptr(new QSGMaterialShaderPrivate) + : d_ptr(new QSGMaterialShaderPrivate(this)) { } @@ -188,217 +311,189 @@ QSGMaterialShader::~QSGMaterialShader() { } -/*! - \fn char const *const *QSGMaterialShader::attributeNames() const - - Returns a zero-terminated array describing the names of the - attributes used in the vertex shader. - - This function is called when the shader is compiled to specify - which attributes exist. The order of the attribute names - defines the attribute register position in the vertex shader. - */ - -#if QT_CONFIG(opengl) -/*! - \fn const char *QSGMaterialShader::vertexShader() const - - Called when the shader is being initialized to get the vertex - shader source code. - - The contents returned from this function should never change. -*/ -const char *QSGMaterialShader::vertexShader() const +// We have our own enum as QShader is not initially public. Internally +// everything works with QShader::Stage however. So convert. +static inline QShader::Stage toShaderStage(QSGMaterialShader::Stage stage) { - Q_D(const QSGMaterialShader); - return d->loadShaderSource(QOpenGLShader::Vertex); + switch (stage) { + case QSGMaterialShader::VertexStage: + return QShader::VertexStage; + case QSGMaterialShader::FragmentStage: + return QShader::FragmentStage; + default: + Q_UNREACHABLE(); + return QShader::VertexStage; + } } - /*! - \fn const char *QSGMaterialShader::fragmentShader() const - - Called when the shader is being initialized to get the fragment - shader source code. - - The contents returned from this function should never change. -*/ -const char *QSGMaterialShader::fragmentShader() const + Sets the \a shader for the specified \a stage. + */ +void QSGMaterialShader::setShader(Stage stage, const QShader &shader) { - Q_D(const QSGMaterialShader); - return d->loadShaderSource(QOpenGLShader::Fragment); + Q_D(QSGMaterialShader); + d->shaders[toShaderStage(stage)] = QSGMaterialShaderPrivate::ShaderStageData(shader); } - -/*! - \fn QOpenGLShaderProgram *QSGMaterialShader::program() - - Returns the shader program used by this QSGMaterialShader. - */ -#endif - /*! - \fn void QSGMaterialShader::initialize() + Sets the \a filename for the shader for the specified \a stage. - Reimplement this function to do one-time initialization when the - shader program is compiled. The OpenGL shader program is compiled - and linked, but not bound, when this function is called. + The file is expected to contain a serialized QShader. */ - +void QSGMaterialShader::setShaderFileName(Stage stage, const QString &filename) +{ + Q_D(QSGMaterialShader); + d->shaderFileNames[toShaderStage(stage)] = filename; +} /*! - This function is called by the scene graph to indicate that geometry is - about to be rendered using this shader. - - State that is global for all uses of the shader, independent of the geometry - that is being drawn, can be setup in this function. + \return the currently set flags for this material shader. */ - -void QSGMaterialShader::activate() +QSGMaterialShader::Flags QSGMaterialShader::flags() const { + Q_D(const QSGMaterialShader); + return d->flags; } - - /*! - This function is called by the scene graph to indicate that geometry will - no longer to be rendered using this shader. - */ - -void QSGMaterialShader::deactivate() + Sets the \a flags on this material shader if \a on is true; + otherwise clears the specified flags. +*/ +void QSGMaterialShader::setFlag(Flags flags, bool on) { + Q_D(QSGMaterialShader); + if (on) + d->flags |= flags; + else + d->flags &= ~flags; } - - /*! - This function is called by the scene graph before geometry is rendered - to make sure the shader is in the right state. + This function is called by the scene graph to get the contents of the + shader program's uniform buffer updated. The implementation is not expected + to perform any real graphics operations, it is merely responsible for + copying data to the QByteArray returned from RenderState::uniformData(). + The scene graph takes care of making that buffer visible in the shaders. The current rendering \a state is passed from the scene graph. If the state - indicates that any state is dirty, the updateState implementation must - update accordingly for the geometry to render correctly. + indicates that any relevant state is dirty, the implementation must update + the appropriate region in the buffer data that is accessible via + RenderState::uniformData(). When a state, such as, matrix or opacity, is + not dirty, there is no need to touch the corresponding region since the + data is persistent. - The subclass specific state, such as the color of a flat color material, should - be extracted from \a newMaterial to update the color uniforms accordingly. + The return value must be \c true whenever any change was made to the uniform data. - The \a oldMaterial can be used to minimze state changes when updating - material states. The \a oldMaterial is 0 if this shader was just activated. + The subclass specific state, such as the color of a flat color material, + should be extracted from \a newMaterial to update the relevant regions in + the buffer accordingly. - \sa activate(), deactivate() + \a oldMaterial can be used to minimize buffer changes (which are typically + memcpy calls) when updating material states. When \a oldMaterial is null, + this shader was just activated. */ - -void QSGMaterialShader::updateState(const RenderState & /* state */, QSGMaterial * /* newMaterial */, QSGMaterial * /* oldMaterial */) +bool QSGMaterialShader::updateUniformData(RenderState &state, + QSGMaterial *newMaterial, + QSGMaterial *oldMaterial) { + Q_UNUSED(state); + Q_UNUSED(newMaterial); + Q_UNUSED(oldMaterial); + return false; } -#if QT_CONFIG(opengl) /*! - Sets the GLSL source file for the shader stage \a type to \a sourceFile. The - default implementation of the vertexShader() and fragmentShader() functions - will load the source files set by this function. + This function is called by the scene graph to prepare using a sampled image + in the shader, typically in form of a combined image sampler. - This function is useful when you have a single source file for a given shader - stage. If your shader consists of multiple source files then use - setShaderSourceFiles() + \a binding is the binding number of the sampler. The function is called for + each variable in the material's shaders' + \l{QShaderDescription::combinedImageSamplers()}. - \sa setShaderSourceFiles(), vertexShader(), fragmentShader() - */ -void QSGMaterialShader::setShaderSourceFile(QOpenGLShader::ShaderType type, const QString &sourceFile) -{ - Q_D(QSGMaterialShader); - d->m_sourceFiles[type] = (QStringList() << sourceFile); -} + When *\a{texture} is null, it must be set to a QSGTexture pointer before + returning. When non-null, it is up to the material to decide if a new + \c{QSGTexture *} is stored to it, or if it updates some parameters on the + already known QSGTexture. The ownership of the QSGTexture is not + transferred. -/*! - Sets the GLSL source files for the shader stage \a type to \a sourceFiles. The - default implementation of the vertexShader() and fragmentShader() functions - will load the source files set by this function in the order given. + The current rendering \a state is passed from the scene graph. It is up to + the material to enqueue the texture data uploads to the + QRhiResourceUpdateBatch retriveable via RenderState::resourceUpdateBatch(). - \sa setShaderSourceFile(), vertexShader(), fragmentShader() + The subclass specific state can be extracted from \a newMaterial. + + \a oldMaterial can be used to minimize changes. When \a oldMaterial is null, + this shader was just activated. */ -void QSGMaterialShader::setShaderSourceFiles(QOpenGLShader::ShaderType type, const QStringList &sourceFiles) +void QSGMaterialShader::updateSampledImage(RenderState &state, + int binding, + QSGTexture **texture, + QSGMaterial *newMaterial, + QSGMaterial *oldMaterial) { - Q_D(QSGMaterialShader); - d->m_sourceFiles[type] = sourceFiles; + Q_UNUSED(state); + Q_UNUSED(binding); + Q_UNUSED(texture); + Q_UNUSED(newMaterial); + Q_UNUSED(oldMaterial); } /*! - This function is called when the shader is initialized to compile the - actual QOpenGLShaderProgram. Do not call it explicitly. + This function is called by the scene graph to enable the material to + provide a custom set of graphics state. The set of states that are + customizable by material is limited to blending and related settings. - The default implementation will extract the vertexShader() and - fragmentShader() and bind the names returned from attributeNames() - to consecutive vertex attribute registers starting at 0. - */ + \note This function is only called when the UpdatesGraphicsPipelineState + flag was enabled via setFlags(). By default it is not set, and so this + function is never called. -void QSGMaterialShader::compile() -{ - Q_ASSERT_X(!m_program.isLinked(), "QSGSMaterialShader::compile()", "Compile called multiple times!"); - - program()->addCacheableShaderFromSourceCode(QOpenGLShader::Vertex, vertexShader()); - program()->addCacheableShaderFromSourceCode(QOpenGLShader::Fragment, fragmentShader()); - - char const *const *attr = attributeNames(); -#ifndef QT_NO_DEBUG - int maxVertexAttribs = 0; - QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); - funcs->glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &maxVertexAttribs); - for (int i = 0; attr[i]; ++i) { - if (i >= maxVertexAttribs) { - qFatal("List of attribute names is either too long or not null-terminated.\n" - "Maximum number of attributes on this hardware is %i.\n" - "Vertex shader:\n%s\n" - "Fragment shader:\n%s\n", - maxVertexAttribs, vertexShader(), fragmentShader()); - } - if (*attr[i]) - program()->bindAttributeLocation(attr[i], i); - } -#else - for (int i = 0; attr[i]; ++i) { - if (*attr[i]) - program()->bindAttributeLocation(attr[i], i); - } -#endif + The return value must be \c true whenever a change was made to any of the + members in \a ps. - if (!program()->link()) { - qWarning("QSGMaterialShader: Shader compilation failed:"); - qWarning() << program()->log(); - } -} + \note The contents of \a ps is not persistent between invocations of this + function. -#endif + The current rendering \a state is passed from the scene graph. + + The subclass specific state can be extracted from \a newMaterial. When \a + oldMaterial is null, this shader was just activated. + */ +bool QSGMaterialShader::updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps, + QSGMaterial *newMaterial, QSGMaterial *oldMaterial) +{ + Q_UNUSED(state); + Q_UNUSED(ps); + Q_UNUSED(newMaterial); + Q_UNUSED(oldMaterial); + return false; +} /*! \class QSGMaterialShader::RenderState - \brief The QSGMaterialShader::RenderState encapsulates the current rendering state - during a call to QSGMaterialShader::updateState(). - \inmodule QtQuick - The render state contains a number of accessors that the shader needs to respect - in order to conform to the current state of the scene graph. - - The instance is only valid inside a call to QSGMaterialShader::updateState() and - should not be used outisde this function. - */ + \brief Encapsulates the current rendering state during a call to + QSGMaterialShader::updateUniformData() and the other \c update type of + functions. + \inmodule QtQuick + \since 5.14 + The render state contains a number of accessors that the shader needs to + respect in order to conform to the current state of the scene graph. + */ /*! \enum QSGMaterialShader::RenderState::DirtyState - \value DirtyMatrix Used to indicate that the matrix has changed and must be updated. - - \value DirtyOpacity Used to indicate that the opacity has changed and must be updated. + \value DirtyMatrix Used to indicate that the matrix has changed and must be + updated. - \value DirtyCachedMaterialData Used to indicate that the cached material data have changed and must be updated. + \value DirtyOpacity Used to indicate that the opacity has changed and must + be updated. \value DirtyAll Used to indicate that everything needs to be updated. */ - - /*! \fn bool QSGMaterialShader::RenderState::isMatrixDirty() const @@ -406,8 +501,6 @@ void QSGMaterialShader::compile() otherwise returns \c false. */ - - /*! \fn bool QSGMaterialShader::RenderState::isOpacityDirty() const @@ -416,13 +509,6 @@ void QSGMaterialShader::compile() */ /*! - \fn bool QSGMaterialShader::RenderState::isCachedMaterialDataDirty() const - - Returns \c true if the dirtyStates() contains the dirty cached material state, - otherwise returns \c false. - */ - -/*! \fn QSGMaterialShader::RenderState::DirtyStates QSGMaterialShader::RenderState::dirtyStates() const Returns which rendering states that have changed and needs to be updated @@ -430,37 +516,98 @@ void QSGMaterialShader::compile() rendering state. */ +/*! + \class QSGMaterialShader::GraphicsPipelineState + + \brief Describes state changes that the material wants to apply to the + currently active graphics pipeline state. + \inmodule QtQuick + \since 5.14 + + Unlike QSGMaterialShader, directly issuing state change commands with the + underlying graphics API is not possible with QSGMaterialShader. This is + mainly because the concept of individually changeable states is considered + deprecated and not supported with modern graphics APIs. + + Therefore, it is up to QSGMaterialShader to expose a data structure with + the set of supported states, which the material can change in its + updatePipelineState() implementation, if there is one. The scenegraph will + then internally apply these changes to the active graphics pipeline state, + then rolling them back as appropriate. + */ /*! - Returns the accumulated opacity to be used for rendering. + \enum QSGMaterialShader::GraphicsPipelineState::BlendFactor + \since 5.14 + + \value Zero + \value One + \value SrcColor + \value OneMinusSrcColor + \value DstColor + \value OneMinusDstColor + \value SrcAlpha + \value OneMinusSrcAlpha + \value DstAlpha + \value OneMinusDstAlpha + \value ConstantColor + \value OneMinusConstantColor + \value ConstantAlpha + \value OneMinusConstantAlpha + \value SrcAlphaSaturate + \value Src1Color + \value OneMinusSrc1Color + \value Src1Alpha + \value OneMinusSrc1Alpha + */ + +/*! + \enum QSGMaterialShader::GraphicsPipelineState::ColorMaskComponent + \since 5.14 + + \value R + \value G + \value B + \value A */ +/*! + \enum QSGMaterialShader::GraphicsPipelineState::CullMode + \since 5.14 + + \value CullNone + \value CullFront + \value CullBack + */ + +/*! + Returns the accumulated opacity to be used for rendering. + */ float QSGMaterialShader::RenderState::opacity() const { Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->currentOpacity(); + return float(static_cast<const QSGRenderer *>(m_data)->currentOpacity()); } /*! Returns the modelview determinant to be used for rendering. */ - float QSGMaterialShader::RenderState::determinant() const { Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->determinant(); + return float(static_cast<const QSGRenderer *>(m_data)->determinant()); } /*! Returns the matrix combined of modelview matrix and project matrix. */ - QMatrix4x4 QSGMaterialShader::RenderState::combinedMatrix() const { Q_ASSERT(m_data); return static_cast<const QSGRenderer *>(m_data)->currentCombinedMatrix(); } + /*! Returns the ratio between physical pixels and device-independent pixels to be used for rendering. @@ -468,29 +615,23 @@ QMatrix4x4 QSGMaterialShader::RenderState::combinedMatrix() const float QSGMaterialShader::RenderState::devicePixelRatio() const { Q_ASSERT(m_data); - return static_cast<const QSGRenderer *>(m_data)->devicePixelRatio(); + return float(static_cast<const QSGRenderer *>(m_data)->devicePixelRatio()); } - - /*! Returns the model view matrix. - If the material has the RequiresFullMatrix flag - set, this is guaranteed to be the complete transform - matrix calculated from the scenegraph. + If the material has the RequiresFullMatrix flag set, this is guaranteed to + be the complete transform matrix calculated from the scenegraph. - However, if this flag is not set, the renderer may - choose to alter this matrix. For example, it may - pre-transform vertices on the CPU and set this matrix - to identity. + However, if this flag is not set, the renderer may choose to alter this + matrix. For example, it may pre-transform vertices on the CPU and set this + matrix to identity. - In a situation such as the above, it is still possible - to retrieve the actual matrix determinant by setting - the RequiresDeterminant flag in the material and - calling the determinant() accessor. + In a situation such as the above, it is still possible to retrieve the + actual matrix determinant by setting the RequiresDeterminant flag in the + material and calling the determinant() accessor. */ - QMatrix4x4 QSGMaterialShader::RenderState::modelViewMatrix() const { Q_ASSERT(m_data); @@ -500,53 +641,75 @@ QMatrix4x4 QSGMaterialShader::RenderState::modelViewMatrix() const /*! Returns the projection matrix. */ - QMatrix4x4 QSGMaterialShader::RenderState::projectionMatrix() const { Q_ASSERT(m_data); return static_cast<const QSGRenderer *>(m_data)->currentProjectionMatrix(); } - - /*! Returns the viewport rect of the surface being rendered to. */ - QRect QSGMaterialShader::RenderState::viewportRect() const { Q_ASSERT(m_data); return static_cast<const QSGRenderer *>(m_data)->viewportRect(); } - - /*! Returns the device rect of the surface being rendered to */ - QRect QSGMaterialShader::RenderState::deviceRect() const { Q_ASSERT(m_data); return static_cast<const QSGRenderer *>(m_data)->deviceRect(); } -#if QT_CONFIG(opengl) - /*! - Returns the QOpenGLContext that is being used for rendering + Returns a pointer to the data for the uniform (constant) buffer in the + shader. Uniform data must only be updated from + QSGMaterialShader::updateUniformData(). The return value is null in the + other reimplementable functions, such as, + QSGMaterialShader::updateSampledImage(). + + \note It is strongly recommended to declare the uniform block with \c + std140 in the shader, and to carefully study the standard uniform block + layout as described in section 7.6.2.2 of the OpenGL specification. It is + up to the QSGMaterialShader implementation to ensure data gets placed + at the right location in this QByteArray, taking alignment requirements + into account. Shader code translated to other shading languages is expected + to use the same offsets for block members, even when the target language + uses different packing rules by default. + + \note Avoid copying from C++ POD types, such as, structs, in order to + update multiple members at once, unless it has been verified that the + layouts of the C++ struct and the GLSL uniform block match. */ +QByteArray *QSGMaterialShader::RenderState::uniformData() +{ + Q_ASSERT(m_data); + return static_cast<const QSGRenderer *>(m_data)->currentUniformData(); +} -QOpenGLContext *QSGMaterialShader::RenderState::context() const +/*! + Returns a resource update batch to which upload and copy operatoins can be + queued. This is typically used by + QSGMaterialShader::updateSampledImage() to enqueue texture image + content updates. + */ +QRhiResourceUpdateBatch *QSGMaterialShader::RenderState::resourceUpdateBatch() { - // Only the QSGDefaultRenderContext will have an OpenGL Context to query - auto openGLRenderContext = static_cast<const QSGDefaultRenderContext *>(static_cast<const QSGRenderer *>(m_data)->context()); - if (openGLRenderContext != nullptr) - return openGLRenderContext->openglContext(); - else - return nullptr; + Q_ASSERT(m_data); + return static_cast<const QSGRenderer *>(m_data)->currentResourceUpdateBatch(); } -#endif +/*! + Returns the current QRhi. + */ +QRhi *QSGMaterialShader::RenderState::rhi() +{ + Q_ASSERT(m_data); + return static_cast<const QSGRenderer *>(m_data)->currentRhi(); +} QT_END_NAMESPACE diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader.h b/src/quick/scenegraph/coreapi/qsgmaterialshader.h index 6783b3f890..765a8ee513 100644 --- a/src/quick/scenegraph/coreapi/qsgmaterialshader.h +++ b/src/quick/scenegraph/coreapi/qsgmaterialshader.h @@ -41,21 +41,24 @@ #define QSGMATERIALSHADER_H #include <QtQuick/qtquickglobal.h> +#include <QtCore/QRect> +#include <QtGui/QMatrix4x4> +#include <QtGui/QColor> +#include <QtQuick/qsgmaterialtype.h> + +// ### glpurge Remove when purging direct OpenGL usage #if QT_CONFIG(opengl) # include <qopenglshaderprogram.h> #endif -#include <QtGui/QMatrix4x4> -#include <QtCore/QRect> -#include <QtQuick/qsgmaterialtype.h> // for source compat QT_BEGIN_NAMESPACE class QSGMaterial; class QSGMaterialShaderPrivate; - -namespace QSGBatchRenderer { - class ShaderManager; -} +class QSGTexture; +class QRhiResourceUpdateBatch; +class QRhi; +class QShader; class Q_QUICK_EXPORT QSGMaterialShader { @@ -73,9 +76,8 @@ public: inline DirtyStates dirtyStates() const { return m_dirty; } - inline bool isMatrixDirty() const { return m_dirty & DirtyMatrix; } - inline bool isOpacityDirty() const { return m_dirty & DirtyOpacity; } - bool isCachedMaterialDataDirty() const { return m_dirty & DirtyCachedMaterialData; } + inline bool isMatrixDirty() const { return m_dirty & QSGMaterialShader::RenderState::DirtyMatrix; } + inline bool isOpacityDirty() const { return m_dirty & QSGMaterialShader::RenderState::DirtyOpacity; } float opacity() const; QMatrix4x4 combinedMatrix() const; @@ -85,51 +87,124 @@ public: QRect deviceRect() const; float determinant() const; float devicePixelRatio() const; -#if QT_CONFIG(opengl) - QOpenGLContext *context() const; -#endif + + QByteArray *uniformData(); + QRhiResourceUpdateBatch *resourceUpdateBatch(); + QRhi *rhi(); + private: friend class QSGRenderer; DirtyStates m_dirty; const void *m_data; }; + struct Q_QUICK_EXPORT GraphicsPipelineState { + enum BlendFactor { + Zero, + One, + SrcColor, + OneMinusSrcColor, + DstColor, + OneMinusDstColor, + SrcAlpha, + OneMinusSrcAlpha, + DstAlpha, + OneMinusDstAlpha, + ConstantColor, + OneMinusConstantColor, + ConstantAlpha, + OneMinusConstantAlpha, + SrcAlphaSaturate, + Src1Color, + OneMinusSrc1Color, + Src1Alpha, + OneMinusSrc1Alpha + }; + + enum ColorMaskComponent { + R = 1 << 0, + G = 1 << 1, + B = 1 << 2, + A = 1 << 3 + }; + Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent) + + enum CullMode { + CullNone, + CullFront, + CullBack + }; + + bool blendEnable; + BlendFactor srcColor; + BlendFactor dstColor; + ColorMask colorWrite; + QColor blendConstant; + CullMode cullMode; + // This struct is extensible while keeping BC since apps only ever get + // a ptr to the struct, it is not created by them. + }; + + enum Flag { + UpdatesGraphicsPipelineState = 0x0001 + }; + Q_DECLARE_FLAGS(Flags, Flag) + + enum Stage { + VertexStage, + FragmentStage, + }; + QSGMaterialShader(); virtual ~QSGMaterialShader(); - virtual void activate(); - virtual void deactivate(); - // First time a material is used, oldMaterial is null. - virtual void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial); - virtual char const *const *attributeNames() const = 0; // Array must end with null. + virtual bool updateUniformData(RenderState &state, + QSGMaterial *newMaterial, QSGMaterial *oldMaterial); + + virtual void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, + QSGMaterial *newMaterial, QSGMaterial *oldMaterial); + + virtual bool updateGraphicsPipelineState(RenderState &state, GraphicsPipelineState *ps, + QSGMaterial *newMaterial, QSGMaterial *oldMaterial); + + Flags flags() const; + void setFlag(Flags flags, bool on = true); + + // ### glpurge Remove when purging direct OpenGL usage + virtual char const *const *attributeNames() const { return nullptr; } + virtual void activate() { } + virtual void deactivate() { } + virtual void updateState(const RenderState &, QSGMaterial *, QSGMaterial *) { } #if QT_CONFIG(opengl) - inline QOpenGLShaderProgram *program() { return &m_program; } + inline QOpenGLShaderProgram *program() { return nullptr; } #endif -protected: - Q_DECLARE_PRIVATE(QSGMaterialShader) - QSGMaterialShader(QSGMaterialShaderPrivate &dd); - - friend class QSGDefaultRenderContext; - friend class QSGBatchRenderer::ShaderManager; #if QT_CONFIG(opengl) - void setShaderSourceFile(QOpenGLShader::ShaderType type, const QString &sourceFile); - void setShaderSourceFiles(QOpenGLShader::ShaderType type, const QStringList &sourceFiles); - - virtual void compile(); + void setShaderSourceFile(QOpenGLShader::ShaderType, const QString &) { } + void setShaderSourceFiles(QOpenGLShader::ShaderType, const QStringList &) { } + virtual void compile() { } #endif virtual void initialize() { } #if QT_CONFIG(opengl) - virtual const char *vertexShader() const; - virtual const char *fragmentShader() const; + virtual const char *vertexShader() const { return nullptr; } + virtual const char *fragmentShader() const { return nullptr; } #endif + +protected: + Q_DECLARE_PRIVATE(QSGMaterialShader) + QSGMaterialShader(QSGMaterialShaderPrivate &dd); + + // filename is for a file containing a serialized QShader. + void setShaderFileName(Stage stage, const QString &filename); + + void setShader(Stage stage, const QShader &shader); + private: -#if QT_CONFIG(opengl) - QOpenGLShaderProgram m_program; -#endif QScopedPointer<QSGMaterialShaderPrivate> d_ptr; }; Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::RenderState::DirtyStates) +Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::GraphicsPipelineState::ColorMask) +Q_DECLARE_OPERATORS_FOR_FLAGS(QSGMaterialShader::Flags) QT_END_NAMESPACE diff --git a/src/quick/scenegraph/coreapi/qsgmaterialshader_p.h b/src/quick/scenegraph/coreapi/qsgmaterialshader_p.h index ae23b4a8ce..4104e32dbc 100644 --- a/src/quick/scenegraph/coreapi/qsgmaterialshader_p.h +++ b/src/quick/scenegraph/coreapi/qsgmaterialshader_p.h @@ -1,7 +1,6 @@ /**************************************************************************** ** ** Copyright (C) 2019 The Qt Company Ltd. -** Copyright (C) 2016 Klaralvdalens Datakonsult AB (KDAB). ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtQuick module of the Qt Toolkit. @@ -53,21 +52,63 @@ // #include <private/qtquickglobal_p.h> +#include "qsgmaterialshader.h" #include "qsgmaterial.h" +#include <QtGui/private/qrhi_p.h> +#include <QtGui/private/qshader_p.h> QT_BEGIN_NAMESPACE +class QRhiSampler; + class Q_QUICK_PRIVATE_EXPORT QSGMaterialShaderPrivate { public: -#if QT_CONFIG(opengl) - const char *loadShaderSource(QOpenGLShader::ShaderType type) const; + Q_DECLARE_PUBLIC(QSGMaterialShader) - QHash<QOpenGLShader::ShaderType, QStringList> m_sourceFiles; - mutable QHash<QOpenGLShader::ShaderType, QByteArray> m_sources; -#endif + QSGMaterialShaderPrivate(QSGMaterialShader *q) : q_ptr(q) { } + static QSGMaterialShaderPrivate *get(QSGMaterialShader *s) { return s->d_func(); } + static const QSGMaterialShaderPrivate *get(const QSGMaterialShader *s) { return s->d_func(); } + + void clearCachedRendererData(); + void prepare(QShader::Variant vertexShaderVariant); + + QShader shader(QShader::Stage stage) const { return shaders[stage].shader; } + + static QShader loadShader(const QString &filename); + + QSGMaterialShader *q_ptr; + QHash<QShader::Stage, QString> shaderFileNames; + QSGMaterialShader::Flags flags; + + struct ShaderStageData { + ShaderStageData() { } // so shader.isValid() == false + ShaderStageData(const QShader &shader) : shader(shader) { } + QShader shader; + QShader::Variant shaderVariant = QShader::StandardShader; + QVector<int> vertexInputLocations; // excluding rewriter-inserted ones + int qt_order_attrib_location = -1; // rewriter-inserted + }; + QHash<QShader::Stage, ShaderStageData> shaders; + + static const int MAX_SHADER_RESOURCE_BINDINGS = 32; + + int ubufBinding = -1; + int ubufSize = 0; + QRhiShaderResourceBinding::StageFlags ubufStages; + QRhiShaderResourceBinding::StageFlags combinedImageSamplerBindings[MAX_SHADER_RESOURCE_BINDINGS]; + + ShaderStageData *vertexShader = nullptr; + ShaderStageData *fragmentShader = nullptr; + + QByteArray masterUniformData; + + QSGTexture *textureBindingTable[MAX_SHADER_RESOURCE_BINDINGS]; + QRhiSampler *samplerBindingTable[MAX_SHADER_RESOURCE_BINDINGS]; }; +Q_DECLARE_TYPEINFO(QSGMaterialShaderPrivate::ShaderStageData, Q_MOVABLE_TYPE); + QT_END_NAMESPACE -#endif // QSGMATERIALSHADER_P_H +#endif diff --git a/src/quick/scenegraph/coreapi/qsgrenderer_p.h b/src/quick/scenegraph/coreapi/qsgrenderer_p.h index 3f2154e3c1..f9d7d3a65a 100644 --- a/src/quick/scenegraph/coreapi/qsgrenderer_p.h +++ b/src/quick/scenegraph/coreapi/qsgrenderer_p.h @@ -94,7 +94,6 @@ public: QSGNodeUpdater *nodeUpdater() const; void setNodeUpdater(QSGNodeUpdater *updater); inline QSGMaterialShader::RenderState state(QSGMaterialShader::RenderState::DirtyStates dirty) const; - inline QSGMaterialRhiShader::RenderState rhiState(QSGMaterialRhiShader::RenderState::DirtyStates dirty) const; virtual void setCustomRenderMode(const QByteArray &) { } virtual bool hasCustomRenderModeWithContinuousUpdate() const { return false; } virtual void releaseCachedResources() { } @@ -102,7 +101,7 @@ public: void clearChangedFlag() { m_changed_emitted = false; } - // Accessed by QSGMaterialRhiShader::RenderState. + // Accessed by QSGMaterialShader::RenderState. QByteArray *currentUniformData() const { return m_current_uniform_data; } QRhiResourceUpdateBatch *currentResourceUpdateBatch() const { return m_current_resource_update_batch; } QRhi *currentRhi() const { return m_rhi; } @@ -197,14 +196,6 @@ QSGMaterialShader::RenderState QSGRenderer::state(QSGMaterialShader::RenderState return s; } -QSGMaterialRhiShader::RenderState QSGRenderer::rhiState(QSGMaterialRhiShader::RenderState::DirtyStates dirty) const -{ - QSGMaterialRhiShader::RenderState s; - s.m_dirty = dirty; - s.m_data = this; - return s; -} - class Q_QUICK_PRIVATE_EXPORT QSGNodeDumper : public QSGNodeVisitor { diff --git a/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp b/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp index 3468cc270d..b26cba3ac3 100644 --- a/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp +++ b/src/quick/scenegraph/coreapi/qsgrhivisualizer.cpp @@ -42,7 +42,7 @@ #include "qsgrhivisualizer_p.h" #include <qmath.h> #include <QQuickWindow> -#include <private/qsgmaterialrhishader_p.h> +#include <private/qsgmaterialshader_p.h> #include <private/qsgshadersourcebuilder_p.h> QT_BEGIN_NAMESPACE @@ -94,9 +94,9 @@ void RhiVisualizer::prepareVisualize() return; if (!m_vs.isValid()) { - m_vs = QSGMaterialRhiShaderPrivate::loadShader( + m_vs = QSGMaterialShaderPrivate::loadShader( QLatin1String(":/qt-project.org/scenegraph/shaders_ng/visualization.vert.qsb")); - m_fs = QSGMaterialRhiShaderPrivate::loadShader( + m_fs = QSGMaterialShaderPrivate::loadShader( QLatin1String(":/qt-project.org/scenegraph/shaders_ng/visualization.frag.qsb")); } diff --git a/src/quick/scenegraph/coreapi/qsgtexture.cpp b/src/quick/scenegraph/coreapi/qsgtexture.cpp index 65a43785aa..b90dff910d 100644 --- a/src/quick/scenegraph/coreapi/qsgtexture.cpp +++ b/src/quick/scenegraph/coreapi/qsgtexture.cpp @@ -451,7 +451,7 @@ QSGTexture::~QSGTexture() \a resourceUpdates is an optional resource update batch, on which texture operations, if any, are enqueued. Materials can retrieve an instance from - QSGMaterialRhiShader::RenderState. When null, the removedFromAtlas() + QSGMaterialShader::RenderState. When null, the removedFromAtlas() implementation creates its own batch and submit it right away. However, when a valid instance is specified, this function will not submit the update batch. diff --git a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp index 44fef4ddef..e13b16c95b 100644 --- a/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdefaultglyphnode_p.cpp @@ -90,9 +90,6 @@ static inline qreal fontSmoothingGamma() return fontSmoothingGamma; } - -// ***** legacy (GL) material shader implementations - static inline qreal qsg_device_pixel_ratio(QOpenGLContext *ctx) { qreal devicePixelRatio = 1; @@ -108,304 +105,7 @@ static inline qreal qsg_device_pixel_ratio(QOpenGLContext *ctx) return devicePixelRatio; } -class QSGTextMaskShader : public QSGMaterialShader -{ -public: - QSGTextMaskShader(QFontEngine::GlyphFormat glyphFormat); - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - char const *const *attributeNames() const override; - -protected: - void initialize() override; - - int m_matrix_id; - int m_color_id; - int m_textureScale_id; - float m_devicePixelRatio; - - QFontEngine::GlyphFormat m_glyphFormat; -}; - -char const *const *QSGTextMaskShader::attributeNames() const -{ - static char const *const attr[] = { "vCoord", "tCoord", nullptr }; - return attr; -} - -QSGTextMaskShader::QSGTextMaskShader(QFontEngine::GlyphFormat glyphFormat) - : QSGMaterialShader(*new QSGMaterialShaderPrivate) - , m_matrix_id(-1) - , m_color_id(-1) - , m_textureScale_id(-1) - , m_glyphFormat(glyphFormat) -{ - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/textmask.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/textmask.frag")); -} - -void QSGTextMaskShader::initialize() -{ - m_matrix_id = program()->uniformLocation("matrix"); - m_color_id = program()->uniformLocation("color"); - m_textureScale_id = program()->uniformLocation("textureScale"); - m_devicePixelRatio = (float) qsg_device_pixel_ratio(QOpenGLContext::currentContext()); - program()->setUniformValue("dpr", m_devicePixelRatio); -} - -void QSGTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect); - QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect); - Q_ASSERT(oldEffect == nullptr || newEffect->type() == oldEffect->type()); - bool updated = material->ensureUpToDate(); - Q_ASSERT(material->texture()); - - Q_ASSERT(oldMaterial == nullptr || oldMaterial->texture()); - if (updated - || oldMaterial == nullptr - || oldMaterial->texture()->textureId() != material->texture()->textureId()) { - program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->openglGlyphCache()->width(), - 1.0 / material->openglGlyphCache()->height())); - QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); - funcs->glBindTexture(GL_TEXTURE_2D, material->texture()->textureId()); - - // Set the mag/min filters to be nearest. We only need to do this when the texture - // has been recreated. - if (updated) { - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - } - } - - float devicePixelRatio = (float) qsg_device_pixel_ratio(QOpenGLContext::currentContext()); - if (m_devicePixelRatio != devicePixelRatio) { - m_devicePixelRatio = devicePixelRatio; - program()->setUniformValue("dpr", m_devicePixelRatio); - } - - if (state.isMatrixDirty()) - program()->setUniformValue(m_matrix_id, state.combinedMatrix()); -} - -class QSG8BitTextMaskShader : public QSGTextMaskShader -{ -public: - QSG8BitTextMaskShader(QFontEngine::GlyphFormat glyphFormat) - : QSGTextMaskShader(glyphFormat) - { - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/8bittextmask.frag")); - } - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; -}; - -void QSG8BitTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - QSGTextMaskShader::updateState(state, newEffect, oldEffect); - QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect); - QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect); - - if (oldMaterial == nullptr || material->color() != oldMaterial->color() || state.isOpacityDirty()) { - QVector4D color = qsg_premultiply(material->color(), state.opacity()); - program()->setUniformValue(m_color_id, color); - } -} - -class QSG24BitTextMaskShader : public QSGTextMaskShader -{ -public: - QSG24BitTextMaskShader(QFontEngine::GlyphFormat glyphFormat) - : QSGTextMaskShader(glyphFormat) - , m_useSRGB(false) - { - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/24bittextmask.frag")); - } - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - void initialize() override; - void activate() override; - void deactivate() override; - - bool useSRGB() const; - uint m_useSRGB : 1; -}; - -void QSG24BitTextMaskShader::initialize() -{ - QSGTextMaskShader::initialize(); - // 0.25 was found to be acceptable error margin by experimentation. On Mac, the gamma is 2.0, - // but using sRGB looks okay. - if (QOpenGLContext::currentContext()->hasExtension(QByteArrayLiteral("GL_ARB_framebuffer_sRGB")) - && m_glyphFormat == QFontEngine::Format_A32 - && qAbs(fontSmoothingGamma() - 2.2) < 0.25) { - QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); - GLint srgbCapable = 0; - funcs->glGetIntegerv(GL_FRAMEBUFFER_SRGB_CAPABLE, &srgbCapable); - if (srgbCapable) - m_useSRGB = true; - } -} - -bool QSG24BitTextMaskShader::useSRGB() const -{ -#ifdef Q_OS_MACOS - if (!m_useSRGB) - return false; - - // m_useSRGB is true, but if some QOGLFBO was bound check it's texture format: - QOpenGLContext *ctx = QOpenGLContext::currentContext(); - QOpenGLFramebufferObject *qfbo = QOpenGLContextPrivate::get(ctx)->qgl_current_fbo; - bool fboInvalid = QOpenGLContextPrivate::get(ctx)->qgl_current_fbo_invalid; - return !qfbo || fboInvalid || qfbo->format().internalTextureFormat() == GL_SRGB8_ALPHA8_EXT; -#else - return m_useSRGB; -#endif -} - -void QSG24BitTextMaskShader::activate() -{ - QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); - funcs->glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); - if (useSRGB()) - funcs->glEnable(GL_FRAMEBUFFER_SRGB); -} - -void QSG24BitTextMaskShader::deactivate() -{ - QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); - funcs->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - if (useSRGB()) - funcs->glDisable(GL_FRAMEBUFFER_SRGB); -} - -void QSG24BitTextMaskShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - QSGTextMaskShader::updateState(state, newEffect, oldEffect); - QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect); - QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect); - - if (oldMaterial == nullptr || material->color() != oldMaterial->color() || state.isOpacityDirty()) { - QVector4D color = material->color(); - if (useSRGB()) - color = qt_sRGB_to_linear_RGB(color); - QOpenGLContext::currentContext()->functions()->glBlendColor(color.x(), color.y(), color.z(), color.w()); - color = qsg_premultiply(color, state.opacity()); - program()->setUniformValue(m_color_id, color.w()); - } -} - -class QSG32BitColorTextShader : public QSGTextMaskShader -{ -public: - QSG32BitColorTextShader(QFontEngine::GlyphFormat glyphFormat) - : QSGTextMaskShader(glyphFormat) - { - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/32bitcolortext.frag")); - } - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; -}; - -void QSG32BitColorTextShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - QSGTextMaskShader::updateState(state, newEffect, oldEffect); - QSGTextMaskMaterial *material = static_cast<QSGTextMaskMaterial *>(newEffect); - QSGTextMaskMaterial *oldMaterial = static_cast<QSGTextMaskMaterial *>(oldEffect); - - if (oldMaterial == nullptr || material->color() != oldMaterial->color() || state.isOpacityDirty()) { - float opacity = material->color().w() * state.opacity(); - program()->setUniformValue(m_color_id, opacity); - } -} - -class QSGStyledTextShader : public QSG8BitTextMaskShader -{ -public: - QSGStyledTextShader(QFontEngine::GlyphFormat glyphFormat) - : QSG8BitTextMaskShader(glyphFormat) - { - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/styledtext.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/styledtext.frag")); - } - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - -private: - void initialize() override; - - int m_shift_id; - int m_styleColor_id; -}; - -void QSGStyledTextShader::initialize() -{ - QSG8BitTextMaskShader::initialize(); - m_shift_id = program()->uniformLocation("shift"); - m_styleColor_id = program()->uniformLocation("styleColor"); -} - -void QSGStyledTextShader::updateState(const RenderState &state, - QSGMaterial *newEffect, - QSGMaterial *oldEffect) -{ - Q_ASSERT(oldEffect == nullptr || newEffect->type() == oldEffect->type()); - - QSGStyledTextMaterial *material = static_cast<QSGStyledTextMaterial *>(newEffect); - QSGStyledTextMaterial *oldMaterial = static_cast<QSGStyledTextMaterial *>(oldEffect); - - if (oldMaterial == nullptr || oldMaterial->styleShift() != material->styleShift()) - program()->setUniformValue(m_shift_id, material->styleShift()); - - if (oldMaterial == nullptr || material->color() != oldMaterial->color() || state.isOpacityDirty()) { - QVector4D color = qsg_premultiply(material->color(), state.opacity()); - program()->setUniformValue(m_color_id, color); - } - - if (oldMaterial == nullptr || material->styleColor() != oldMaterial->styleColor() || state.isOpacityDirty()) { - QVector4D styleColor = qsg_premultiply(material->styleColor(), state.opacity()); - program()->setUniformValue(m_styleColor_id, styleColor); - } - - bool updated = material->ensureUpToDate(); - Q_ASSERT(material->texture()); - - Q_ASSERT(oldMaterial == nullptr || oldMaterial->texture()); - if (updated - || oldMaterial == nullptr - || oldMaterial->texture()->textureId() != material->texture()->textureId()) { - program()->setUniformValue(m_textureScale_id, QVector2D(1.0 / material->openglGlyphCache()->width(), - 1.0 / material->openglGlyphCache()->height())); - QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); - funcs->glBindTexture(GL_TEXTURE_2D, material->texture()->textureId()); - - // Set the mag/min filters to be nearest. We only need to do this when the texture - // has been recreated. - if (updated) { - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - } - } - - if (state.isMatrixDirty()) - program()->setUniformValue(m_matrix_id, state.combinedMatrix()); -} - -class QSGOutlinedTextShader : public QSGStyledTextShader -{ -public: - QSGOutlinedTextShader(QFontEngine::GlyphFormat glyphFormat) - : QSGStyledTextShader(glyphFormat) - { - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/outlinedtext.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/outlinedtext.frag")); - } -}; - - -// ***** RHI shader implementations - -class QSGTextMaskRhiShader : public QSGMaterialRhiShader +class QSGTextMaskRhiShader : public QSGMaterialShader { public: QSGTextMaskRhiShader(QFontEngine::GlyphFormat glyphFormat); @@ -721,7 +421,6 @@ void QSGTextMaskMaterial::init(QFontEngine::GlyphFormat glyphFormat) { Q_ASSERT(m_font.isValid()); - setFlag(SupportsRhiShader, true); setFlag(Blending, true); Q_ASSERT(m_rc); @@ -902,28 +601,16 @@ QSGRhiTextureGlyphCache *QSGTextMaskMaterial::rhiGlyphCache() const QSGMaterialShader *QSGTextMaskMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) { - QSGRhiTextureGlyphCache *gc = rhiGlyphCache(); - const QFontEngine::GlyphFormat glyphFormat = gc->glyphFormat(); - switch (glyphFormat) { - case QFontEngine::Format_ARGB: - return new QSG32BitColorTextRhiShader(glyphFormat); - case QFontEngine::Format_A32: - return new QSG24BitTextMaskRhiShader(glyphFormat); - case QFontEngine::Format_A8: - default: - return new QSG8BitTextMaskRhiShader(glyphFormat, gc->eightBitFormatIsAlphaSwizzled()); - } - } else { - switch (QFontEngine::GlyphFormat glyphFormat = glyphCache()->glyphFormat()) { - case QFontEngine::Format_ARGB: - return new QSG32BitColorTextShader(glyphFormat); - case QFontEngine::Format_A32: - return new QSG24BitTextMaskShader(glyphFormat); - case QFontEngine::Format_A8: - default: - return new QSG8BitTextMaskShader(glyphFormat); - } + QSGRhiTextureGlyphCache *gc = rhiGlyphCache(); + const QFontEngine::GlyphFormat glyphFormat = gc->glyphFormat(); + switch (glyphFormat) { + case QFontEngine::Format_ARGB: + return new QSG32BitColorTextRhiShader(glyphFormat); + case QFontEngine::Format_A32: + return new QSG24BitTextMaskRhiShader(glyphFormat); + case QFontEngine::Format_A8: + default: + return new QSG8BitTextMaskRhiShader(glyphFormat, gc->eightBitFormatIsAlphaSwizzled()); } } @@ -996,12 +683,8 @@ QSGMaterialType *QSGStyledTextMaterial::type() const QSGMaterialShader *QSGStyledTextMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) { - QSGRhiTextureGlyphCache *gc = rhiGlyphCache(); - return new QSGStyledTextRhiShader(gc->glyphFormat(), gc->eightBitFormatIsAlphaSwizzled()); - } else { - return new QSGStyledTextShader(glyphCache()->glyphFormat()); - } + QSGRhiTextureGlyphCache *gc = rhiGlyphCache(); + return new QSGStyledTextRhiShader(gc->glyphFormat(), gc->eightBitFormatIsAlphaSwizzled()); } int QSGStyledTextMaterial::compare(const QSGMaterial *o) const @@ -1031,12 +714,8 @@ QSGMaterialType *QSGOutlinedTextMaterial::type() const QSGMaterialShader *QSGOutlinedTextMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) { - QSGRhiTextureGlyphCache *gc = rhiGlyphCache(); - return new QSGOutlinedTextRhiShader(gc->glyphFormat(), gc->eightBitFormatIsAlphaSwizzled()); - } else { - return new QSGOutlinedTextShader(glyphCache()->glyphFormat()); - } + QSGRhiTextureGlyphCache *gc = rhiGlyphCache(); + return new QSGOutlinedTextRhiShader(gc->glyphFormat(), gc->eightBitFormatIsAlphaSwizzled()); } QT_END_NAMESPACE diff --git a/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp b/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp index e609bea439..6cd4dcec78 100644 --- a/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp +++ b/src/quick/scenegraph/qsgdefaultinternalimagenode.cpp @@ -47,20 +47,6 @@ QT_BEGIN_NAMESPACE -class SmoothTextureMaterialShader : public QSGTextureMaterialShader -{ -public: - SmoothTextureMaterialShader(); - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - char const *const *attributeNames() const override; - -protected: - void initialize() override; - - int m_pixelSizeLoc; -}; - class SmoothTextureMaterialRhiShader : public QSGTextureMaterialRhiShader { public: @@ -72,7 +58,6 @@ public: QSGSmoothTextureMaterial::QSGSmoothTextureMaterial() { - setFlag(SupportsRhiShader, true); setFlag(RequiresFullMatrixExceptTranslate, true); setFlag(Blending, true); } @@ -90,44 +75,7 @@ QSGMaterialType *QSGSmoothTextureMaterial::type() const QSGMaterialShader *QSGSmoothTextureMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new SmoothTextureMaterialRhiShader; - else - return new SmoothTextureMaterialShader; -} - -SmoothTextureMaterialShader::SmoothTextureMaterialShader() -{ - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/smoothtexture.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/smoothtexture.frag")); -} - -void SmoothTextureMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - if (oldEffect == nullptr) { - // The viewport is constant, so set the pixel size uniform only once. - QRect r = state.viewportRect(); - program()->setUniformValue(m_pixelSizeLoc, 2.0f / r.width(), 2.0f / r.height()); - } - QSGTextureMaterialShader::updateState(state, newEffect, oldEffect); -} - -char const *const *SmoothTextureMaterialShader::attributeNames() const -{ - static char const *const attributes[] = { - "vertex", - "multiTexCoord", - "vertexOffset", - "texCoordOffset", - nullptr - }; - return attributes; -} - -void SmoothTextureMaterialShader::initialize() -{ - m_pixelSizeLoc = program()->uniformLocation("pixelSize"); - QSGTextureMaterialShader::initialize(); + return new SmoothTextureMaterialRhiShader; } SmoothTextureMaterialRhiShader::SmoothTextureMaterialRhiShader() diff --git a/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp b/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp index 5e4affbf90..5f0932af82 100644 --- a/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp +++ b/src/quick/scenegraph/qsgdefaultinternalrectanglenode.cpp @@ -50,63 +50,7 @@ QT_BEGIN_NAMESPACE -class SmoothColorMaterialShader : public QSGMaterialShader -{ -public: - SmoothColorMaterialShader(); - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - char const *const *attributeNames() const override; - -private: - void initialize() override; - - int m_matrixLoc; - int m_opacityLoc; - int m_pixelSizeLoc; -}; - -SmoothColorMaterialShader::SmoothColorMaterialShader() -{ - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/smoothcolor.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/smoothcolor.frag")); -} - -void SmoothColorMaterialShader::updateState(const RenderState &state, QSGMaterial *, QSGMaterial *oldEffect) -{ - if (state.isOpacityDirty()) - program()->setUniformValue(m_opacityLoc, state.opacity()); - - if (state.isMatrixDirty()) - program()->setUniformValue(m_matrixLoc, state.combinedMatrix()); - - if (oldEffect == nullptr) { - // The viewport is constant, so set the pixel size uniform only once. - QRect r = state.viewportRect(); - program()->setUniformValue(m_pixelSizeLoc, 2.0f / r.width(), 2.0f / r.height()); - } -} - -char const *const *SmoothColorMaterialShader::attributeNames() const -{ - static char const *const attributes[] = { - "vertex", - "vertexColor", - "vertexOffset", - nullptr - }; - return attributes; -} - -void SmoothColorMaterialShader::initialize() -{ - m_matrixLoc = program()->uniformLocation("matrix"); - m_opacityLoc = program()->uniformLocation("opacity"); - m_pixelSizeLoc = program()->uniformLocation("pixelSize"); -} - - -class SmoothColorMaterialRhiShader : public QSGMaterialRhiShader +class SmoothColorMaterialRhiShader : public QSGMaterialShader { public: SmoothColorMaterialRhiShader(); @@ -154,7 +98,6 @@ QSGSmoothColorMaterial::QSGSmoothColorMaterial() { setFlag(RequiresFullMatrixExceptTranslate, true); setFlag(Blending, true); - setFlag(SupportsRhiShader, true); } int QSGSmoothColorMaterial::compare(const QSGMaterial *) const @@ -171,10 +114,7 @@ QSGMaterialType *QSGSmoothColorMaterial::type() const QSGMaterialShader *QSGSmoothColorMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new SmoothColorMaterialRhiShader; - else - return new SmoothColorMaterialShader; + return new SmoothColorMaterialRhiShader; } QSGDefaultInternalRectangleNode::QSGDefaultInternalRectangleNode() diff --git a/src/quick/scenegraph/qsgdefaultrendercontext.cpp b/src/quick/scenegraph/qsgdefaultrendercontext.cpp index d51d9e7bbe..a4ce8be967 100644 --- a/src/quick/scenegraph/qsgdefaultrendercontext.cpp +++ b/src/quick/scenegraph/qsgdefaultrendercontext.cpp @@ -46,7 +46,7 @@ #include <QtQuick/private/qsgrenderer_p.h> #include <QtQuick/private/qsgrhiatlastexture_p.h> #include <QtQuick/private/qsgrhidistancefieldglyphcache_p.h> -#include <QtQuick/private/qsgmaterialrhishader_p.h> +#include <QtQuick/private/qsgmaterialshader_p.h> #include <QtQuick/private/qsgopenglatlastexture_p.h> #include <QtQuick/private/qsgcompressedtexture_p.h> @@ -411,9 +411,9 @@ void QSGDefaultRenderContext::initializeShader(QSGMaterialShader *shader) shader->initialize(); } -void QSGDefaultRenderContext::initializeRhiShader(QSGMaterialRhiShader *shader, QShader::Variant shaderVariant) +void QSGDefaultRenderContext::initializeRhiShader(QSGMaterialShader *shader, QShader::Variant shaderVariant) { - QSGMaterialRhiShaderPrivate::get(shader)->prepare(shaderVariant); + QSGMaterialShaderPrivate::get(shader)->prepare(shaderVariant); } void QSGDefaultRenderContext::setAttachToGraphicsContext(bool attach) diff --git a/src/quick/scenegraph/qsgdefaultrendercontext_p.h b/src/quick/scenegraph/qsgdefaultrendercontext_p.h index be83f5a9f5..b6ed57ba6a 100644 --- a/src/quick/scenegraph/qsgdefaultrendercontext_p.h +++ b/src/quick/scenegraph/qsgdefaultrendercontext_p.h @@ -65,7 +65,6 @@ class QRhiCommandBuffer; class QRhiRenderPassDescriptor; class QOpenGLContext; class QSGMaterialShader; -class QSGMaterialRhiShader; class QOpenGLFramebufferObject; class QSGDepthStencilBufferManager; class QSGDepthStencilBuffer; @@ -130,9 +129,9 @@ public: QSGRenderer *createRenderer() override; QSGTexture *compressedTextureForFactory(const QSGCompressedTextureFactory *factory) const override; - virtual void compileShader(QSGMaterialShader *shader, QSGMaterial *material, const char *vertexCode = nullptr, const char *fragmentCode = nullptr); - virtual void initializeShader(QSGMaterialShader *shader); - virtual void initializeRhiShader(QSGMaterialRhiShader *shader, QShader::Variant shaderVariant); + virtual void compileShader(QSGMaterialShader *shader, QSGMaterial *material, const char *vertexCode = nullptr, const char *fragmentCode = nullptr); // legacy GL only + virtual void initializeShader(QSGMaterialShader *shader); // legacy GL only + virtual void initializeRhiShader(QSGMaterialShader *shader, QShader::Variant shaderVariant); void setAttachToGraphicsContext(bool attach) override; diff --git a/src/quick/scenegraph/qsgdefaultspritenode.cpp b/src/quick/scenegraph/qsgdefaultspritenode.cpp index 573c6e7a5d..2f3a384891 100644 --- a/src/quick/scenegraph/qsgdefaultspritenode.cpp +++ b/src/quick/scenegraph/qsgdefaultspritenode.cpp @@ -80,7 +80,6 @@ public: QQuickSpriteMaterial::QQuickSpriteMaterial() { setFlag(Blending, true); - setFlag(SupportsRhiShader, true); } QQuickSpriteMaterial::~QQuickSpriteMaterial() @@ -88,51 +87,7 @@ QQuickSpriteMaterial::~QQuickSpriteMaterial() delete texture; } -class SpriteMaterialShader : public QSGMaterialShader -{ -public: - SpriteMaterialShader() - { - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/sprite.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/sprite.frag")); - } - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *) override - { - QQuickSpriteMaterial *m = static_cast<QQuickSpriteMaterial *>(newEffect); - m->texture->bind(); - - program()->setUniformValue(m_opacity_id, state.opacity()); - program()->setUniformValue(m_animData_id, m->animW, m->animH, m->animT); - program()->setUniformValue(m_animPos_id, m->animX1, m->animY1, m->animX2, m->animY2); - - if (state.isMatrixDirty()) - program()->setUniformValue(m_matrix_id, state.combinedMatrix()); - } - - void initialize() override { - m_matrix_id = program()->uniformLocation("qt_Matrix"); - m_opacity_id = program()->uniformLocation("qt_Opacity"); - m_animData_id = program()->uniformLocation("animData"); - m_animPos_id = program()->uniformLocation("animPos"); - } - - char const *const *attributeNames() const override { - static const char *attr[] = { - "vPos", - "vTex", - nullptr - }; - return attr; - } - - int m_matrix_id; - int m_opacity_id; - int m_animData_id; - int m_animPos_id; -}; - -class SpriteMaterialRhiShader : public QSGMaterialRhiShader +class SpriteMaterialRhiShader : public QSGMaterialShader { public: SpriteMaterialRhiShader(); @@ -201,10 +156,7 @@ void SpriteMaterialRhiShader::updateSampledImage(RenderState &state, int binding QSGMaterialShader *QQuickSpriteMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new SpriteMaterialRhiShader; - else - return new SpriteMaterialShader; + return new SpriteMaterialRhiShader; } static QSGGeometry::Attribute Sprite_Attributes[] = { diff --git a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp index 30e17bbe04..8a4e0d0e9f 100644 --- a/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp +++ b/src/quick/scenegraph/qsgdistancefieldglyphnode_p.cpp @@ -70,144 +70,7 @@ static float spreadFunc(float glyphScale) return range / glyphScale; } -class QSGDistanceFieldTextMaterialShader : public QSGMaterialShader -{ -public: - QSGDistanceFieldTextMaterialShader(); - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - char const *const *attributeNames() const override; - -protected: - void initialize() override; - - void updateAlphaRange(); - void updateColor(const QVector4D &c); - void updateTextureScale(const QVector2D &ts); - - float m_fontScale = 1.0; - float m_matrixScale = 1.0; - - int m_matrix_id = -1; - int m_textureScale_id = -1; - int m_alphaMin_id = -1; - int m_alphaMax_id = -1; - int m_color_id = -1; - - QVector2D m_lastTextureScale; - QVector4D m_lastColor; - float m_lastAlphaMin = -1; - float m_lastAlphaMax = -1; -}; - -char const *const *QSGDistanceFieldTextMaterialShader::attributeNames() const { - static char const *const attr[] = { "vCoord", "tCoord", nullptr }; - return attr; -} - -QSGDistanceFieldTextMaterialShader::QSGDistanceFieldTextMaterialShader() -{ - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/distancefieldtext.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/distancefieldtext.frag")); -} - -void QSGDistanceFieldTextMaterialShader::updateAlphaRange() -{ - float combinedScale = m_fontScale * m_matrixScale; - float base = thresholdFunc(combinedScale); - float range = spreadFunc(combinedScale); - float alphaMin = qMax(0.0f, base - range); - float alphaMax = qMin(base + range, 1.0f); - if (alphaMin != m_lastAlphaMin) { - program()->setUniformValue(m_alphaMin_id, GLfloat(alphaMin)); - m_lastAlphaMin = alphaMin; - } - if (alphaMax != m_lastAlphaMax) { - program()->setUniformValue(m_alphaMax_id, GLfloat(alphaMax)); - m_lastAlphaMax = alphaMax; - } -} - -void QSGDistanceFieldTextMaterialShader::updateColor(const QVector4D &c) -{ - if (m_lastColor != c) { - program()->setUniformValue(m_color_id, c); - m_lastColor = c; - } -} - -void QSGDistanceFieldTextMaterialShader::updateTextureScale(const QVector2D &ts) -{ - if (m_lastTextureScale != ts) { - program()->setUniformValue(m_textureScale_id, ts); - m_lastTextureScale = ts; - } -} - -void QSGDistanceFieldTextMaterialShader::initialize() -{ - QSGMaterialShader::initialize(); - m_matrix_id = program()->uniformLocation("matrix"); - m_textureScale_id = program()->uniformLocation("textureScale"); - m_color_id = program()->uniformLocation("color"); - m_alphaMin_id = program()->uniformLocation("alphaMin"); - m_alphaMax_id = program()->uniformLocation("alphaMax"); -} - -void QSGDistanceFieldTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - Q_ASSERT(oldEffect == nullptr || newEffect->type() == oldEffect->type()); - QSGDistanceFieldTextMaterial *material = static_cast<QSGDistanceFieldTextMaterial *>(newEffect); - QSGDistanceFieldTextMaterial *oldMaterial = static_cast<QSGDistanceFieldTextMaterial *>(oldEffect); - - bool updated = material->updateTextureSize(); - - if (oldMaterial == nullptr - || material->color() != oldMaterial->color() - || state.isOpacityDirty()) { - QVector4D color = material->color(); - color *= state.opacity(); - updateColor(color); - } - - bool updateRange = false; - if (oldMaterial == nullptr - || material->fontScale() != oldMaterial->fontScale()) { - m_fontScale = material->fontScale(); - updateRange = true; - } - if (state.isMatrixDirty()) { - program()->setUniformValue(m_matrix_id, state.combinedMatrix()); - m_matrixScale = qSqrt(qAbs(state.determinant())) * state.devicePixelRatio(); - updateRange = true; - } - if (updateRange) { - updateAlphaRange(); - } - - Q_ASSERT(material->glyphCache()); - - if (updated - || oldMaterial == nullptr - || oldMaterial->texture()->textureId != material->texture()->textureId) { - updateTextureScale(QVector2D(1.0 / material->textureSize().width(), - 1.0 / material->textureSize().height())); - - QOpenGLFunctions *funcs = state.context()->functions(); - funcs->glBindTexture(GL_TEXTURE_2D, material->texture()->textureId); - - if (updated) { - // Set the mag/min filters to be linear. We only need to do this when the texture - // has been recreated. - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); - funcs->glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); - } - } -} - -class QSGDistanceFieldTextMaterialRhiShader : public QSGMaterialRhiShader +class QSGDistanceFieldTextMaterialRhiShader : public QSGMaterialShader { public: QSGDistanceFieldTextMaterialRhiShader(bool alphaTexture); @@ -310,7 +173,7 @@ QSGDistanceFieldTextMaterial::QSGDistanceFieldTextMaterial() , m_fontScale(1.0) , m_sgTexture(nullptr) { - setFlag(Blending | RequiresDeterminant | SupportsRhiShader, true); + setFlag(Blending | RequiresDeterminant, true); } QSGDistanceFieldTextMaterial::~QSGDistanceFieldTextMaterial() @@ -334,10 +197,7 @@ void QSGDistanceFieldTextMaterial::setColor(const QColor &color) QSGMaterialShader *QSGDistanceFieldTextMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new QSGDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled()); - else - return new QSGDistanceFieldTextMaterialShader; + return new QSGDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled()); } bool QSGDistanceFieldTextMaterial::updateTextureSize() @@ -387,47 +247,6 @@ int QSGDistanceFieldTextMaterial::compare(const QSGMaterial *o) const return diff < 0 ? -1 : (diff > 0 ? 1 : 0); } - -class DistanceFieldStyledTextMaterialShader : public QSGDistanceFieldTextMaterialShader -{ -public: - DistanceFieldStyledTextMaterialShader(); - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - -protected: - void initialize() override; - - int m_styleColor_id = -1; -}; - -DistanceFieldStyledTextMaterialShader::DistanceFieldStyledTextMaterialShader() - : QSGDistanceFieldTextMaterialShader() -{ -} - -void DistanceFieldStyledTextMaterialShader::initialize() -{ - QSGDistanceFieldTextMaterialShader::initialize(); - m_styleColor_id = program()->uniformLocation("styleColor"); -} - -void DistanceFieldStyledTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - QSGDistanceFieldTextMaterialShader::updateState(state, newEffect, oldEffect); - - QSGDistanceFieldStyledTextMaterial *material = static_cast<QSGDistanceFieldStyledTextMaterial *>(newEffect); - QSGDistanceFieldStyledTextMaterial *oldMaterial = static_cast<QSGDistanceFieldStyledTextMaterial *>(oldEffect); - - if (oldMaterial == nullptr - || material->styleColor() != oldMaterial->styleColor() - || (state.isOpacityDirty())) { - QVector4D color = material->styleColor(); - color *= state.opacity(); - program()->setUniformValue(m_styleColor_id, color); - } -} - class DistanceFieldStyledTextMaterialRhiShader : public QSGDistanceFieldTextMaterialRhiShader { public: @@ -487,63 +306,6 @@ int QSGDistanceFieldStyledTextMaterial::compare(const QSGMaterial *o) const return QSGDistanceFieldTextMaterial::compare(o); } - -class DistanceFieldOutlineTextMaterialShader : public DistanceFieldStyledTextMaterialShader -{ -public: - DistanceFieldOutlineTextMaterialShader(); - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - -protected: - void initialize() override; - - void updateOutlineAlphaRange(int dfRadius); - - int m_outlineAlphaMax0_id = -1; - int m_outlineAlphaMax1_id = -1; -}; - -DistanceFieldOutlineTextMaterialShader::DistanceFieldOutlineTextMaterialShader() - : DistanceFieldStyledTextMaterialShader() -{ - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/distancefieldoutlinetext.frag")); -} - -void DistanceFieldOutlineTextMaterialShader::initialize() -{ - DistanceFieldStyledTextMaterialShader::initialize(); - m_outlineAlphaMax0_id = program()->uniformLocation("outlineAlphaMax0"); - m_outlineAlphaMax1_id = program()->uniformLocation("outlineAlphaMax1"); -} - -void DistanceFieldOutlineTextMaterialShader::updateOutlineAlphaRange(int dfRadius) -{ - float combinedScale = m_fontScale * m_matrixScale; - float base = thresholdFunc(combinedScale); - float range = spreadFunc(combinedScale); - float outlineLimit = qMax(0.2f, base - 0.5f / dfRadius / m_fontScale); - - float alphaMin = qMax(0.0f, base - range); - float styleAlphaMin0 = qMax(0.0f, outlineLimit - range); - float styleAlphaMin1 = qMin(outlineLimit + range, alphaMin); - program()->setUniformValue(m_outlineAlphaMax0_id, GLfloat(styleAlphaMin0)); - program()->setUniformValue(m_outlineAlphaMax1_id, GLfloat(styleAlphaMin1)); -} - -void DistanceFieldOutlineTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - DistanceFieldStyledTextMaterialShader::updateState(state, newEffect, oldEffect); - - QSGDistanceFieldOutlineTextMaterial *material = static_cast<QSGDistanceFieldOutlineTextMaterial *>(newEffect); - QSGDistanceFieldOutlineTextMaterial *oldMaterial = static_cast<QSGDistanceFieldOutlineTextMaterial *>(oldEffect); - - if (oldMaterial == nullptr - || material->fontScale() != oldMaterial->fontScale() - || state.isMatrixDirty()) - updateOutlineAlphaRange(material->glyphCache()->distanceFieldRadius()); -} - class DistanceFieldOutlineTextMaterialRhiShader : public DistanceFieldStyledTextMaterialRhiShader { public: @@ -609,61 +371,7 @@ QSGMaterialType *QSGDistanceFieldOutlineTextMaterial::type() const QSGMaterialShader *QSGDistanceFieldOutlineTextMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new DistanceFieldOutlineTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled()); - else - return new DistanceFieldOutlineTextMaterialShader; -} - - -class DistanceFieldShiftedStyleTextMaterialShader : public DistanceFieldStyledTextMaterialShader -{ -public: - DistanceFieldShiftedStyleTextMaterialShader(); - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - -protected: - void initialize() override; - - void updateShift(qreal fontScale, const QPointF& shift); - - int m_shift_id = -1; -}; - -DistanceFieldShiftedStyleTextMaterialShader::DistanceFieldShiftedStyleTextMaterialShader() - : DistanceFieldStyledTextMaterialShader() -{ - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/distancefieldshiftedtext.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/distancefieldshiftedtext.frag")); -} - -void DistanceFieldShiftedStyleTextMaterialShader::initialize() -{ - DistanceFieldStyledTextMaterialShader::initialize(); - m_shift_id = program()->uniformLocation("shift"); -} - -void DistanceFieldShiftedStyleTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - DistanceFieldStyledTextMaterialShader::updateState(state, newEffect, oldEffect); - - QSGDistanceFieldShiftedStyleTextMaterial *material = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(newEffect); - QSGDistanceFieldShiftedStyleTextMaterial *oldMaterial = static_cast<QSGDistanceFieldShiftedStyleTextMaterial *>(oldEffect); - - if (oldMaterial == nullptr - || oldMaterial->fontScale() != material->fontScale() - || oldMaterial->shift() != material->shift() - || oldMaterial->textureSize() != material->textureSize()) { - updateShift(material->fontScale(), material->shift()); - } -} - -void DistanceFieldShiftedStyleTextMaterialShader::updateShift(qreal fontScale, const QPointF &shift) -{ - QPointF texel(1.0 / fontScale * shift.x(), - 1.0 / fontScale * shift.y()); - program()->setUniformValue(m_shift_id, texel); + return new DistanceFieldOutlineTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled()); } class DistanceFieldShiftedStyleTextMaterialRhiShader : public DistanceFieldStyledTextMaterialRhiShader @@ -726,10 +434,7 @@ QSGMaterialType *QSGDistanceFieldShiftedStyleTextMaterial::type() const QSGMaterialShader *QSGDistanceFieldShiftedStyleTextMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new DistanceFieldShiftedStyleTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled()); - else - return new DistanceFieldShiftedStyleTextMaterialShader; + return new DistanceFieldShiftedStyleTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled()); } int QSGDistanceFieldShiftedStyleTextMaterial::compare(const QSGMaterial *o) const @@ -740,71 +445,6 @@ int QSGDistanceFieldShiftedStyleTextMaterial::compare(const QSGMaterial *o) cons return QSGDistanceFieldStyledTextMaterial::compare(o); } - -class QSGHiQSubPixelDistanceFieldTextMaterialShader : public QSGDistanceFieldTextMaterialShader -{ -public: - QSGHiQSubPixelDistanceFieldTextMaterialShader(); - - void initialize() override; - void activate() override; - void deactivate() override; - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - -private: - int m_fontScale_id = -1; - int m_vecDelta_id = -1; -}; - -QSGHiQSubPixelDistanceFieldTextMaterialShader::QSGHiQSubPixelDistanceFieldTextMaterialShader() - : QSGDistanceFieldTextMaterialShader() -{ - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/hiqsubpixeldistancefieldtext.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/hiqsubpixeldistancefieldtext.frag")); -} - -void QSGHiQSubPixelDistanceFieldTextMaterialShader::initialize() -{ - QSGDistanceFieldTextMaterialShader::initialize(); - m_fontScale_id = program()->uniformLocation("fontScale"); - m_vecDelta_id = program()->uniformLocation("vecDelta"); -} - -void QSGHiQSubPixelDistanceFieldTextMaterialShader::activate() -{ - QSGDistanceFieldTextMaterialShader::activate(); - QOpenGLContext::currentContext()->functions()->glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_SRC_COLOR); -} - -void QSGHiQSubPixelDistanceFieldTextMaterialShader::deactivate() -{ - QSGDistanceFieldTextMaterialShader::deactivate(); - QOpenGLContext::currentContext()->functions()->glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); -} - -void QSGHiQSubPixelDistanceFieldTextMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - Q_ASSERT(oldEffect == nullptr || newEffect->type() == oldEffect->type()); - QSGDistanceFieldTextMaterial *material = static_cast<QSGDistanceFieldTextMaterial *>(newEffect); - QSGDistanceFieldTextMaterial *oldMaterial = static_cast<QSGDistanceFieldTextMaterial *>(oldEffect); - - if (oldMaterial == nullptr || material->color() != oldMaterial->color()) { - QVector4D c = material->color(); - state.context()->functions()->glBlendColor(c.x(), c.y(), c.z(), 1.0f); - } - - if (oldMaterial == nullptr || material->fontScale() != oldMaterial->fontScale()) - program()->setUniformValue(m_fontScale_id, GLfloat(material->fontScale())); - - if (oldMaterial == nullptr || state.isMatrixDirty()) { - int viewportWidth = state.viewportRect().width(); - QMatrix4x4 mat = state.combinedMatrix().inverted(); - program()->setUniformValue(m_vecDelta_id, mat.column(0) * (qreal(2) / viewportWidth)); - } - - QSGDistanceFieldTextMaterialShader::updateState(state, newEffect, oldEffect); -} - class QSGHiQSubPixelDistanceFieldTextMaterialRhiShader : public QSGDistanceFieldTextMaterialRhiShader { public: @@ -882,24 +522,7 @@ QSGMaterialType *QSGHiQSubPixelDistanceFieldTextMaterial::type() const QSGMaterialShader *QSGHiQSubPixelDistanceFieldTextMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new QSGHiQSubPixelDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled()); - else - return new QSGHiQSubPixelDistanceFieldTextMaterialShader; -} - - -class QSGLoQSubPixelDistanceFieldTextMaterialShader : public QSGHiQSubPixelDistanceFieldTextMaterialShader -{ -public: - QSGLoQSubPixelDistanceFieldTextMaterialShader(); -}; - -QSGLoQSubPixelDistanceFieldTextMaterialShader::QSGLoQSubPixelDistanceFieldTextMaterialShader() - : QSGHiQSubPixelDistanceFieldTextMaterialShader() -{ - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/loqsubpixeldistancefieldtext.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/loqsubpixeldistancefieldtext.frag")); + return new QSGHiQSubPixelDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled()); } class QSGLoQSubPixelDistanceFieldTextMaterialRhiShader : public QSGHiQSubPixelDistanceFieldTextMaterialRhiShader @@ -929,10 +552,7 @@ QSGMaterialType *QSGLoQSubPixelDistanceFieldTextMaterial::type() const QSGMaterialShader *QSGLoQSubPixelDistanceFieldTextMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new QSGLoQSubPixelDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled()); - else - return new QSGLoQSubPixelDistanceFieldTextMaterialShader; + return new QSGLoQSubPixelDistanceFieldTextMaterialRhiShader(m_glyph_cache->eightBitFormatIsAlphaSwizzled()); } QT_END_NAMESPACE diff --git a/src/quick/scenegraph/qsgrhishadereffectnode.cpp b/src/quick/scenegraph/qsgrhishadereffectnode.cpp index f4477918c0..cc2a887a9c 100644 --- a/src/quick/scenegraph/qsgrhishadereffectnode.cpp +++ b/src/quick/scenegraph/qsgrhishadereffectnode.cpp @@ -40,7 +40,7 @@ #include "qsgrhishadereffectnode_p.h" #include "qsgdefaultrendercontext_p.h" #include "qsgrhisupport_p.h" -#include <qsgmaterialrhishader.h> +#include <qsgmaterialshader.h> #include <qsgtextureprovider.h> #include <private/qsgplaintexture_p.h> #include <QtGui/private/qshaderdescription_p.h> @@ -209,7 +209,7 @@ QSGMaterialType *QSGRhiShaderMaterialTypeCache::get(const QShader &vs, const QSh static QSGRhiShaderMaterialTypeCache shaderMaterialTypeCache; -class QSGRhiShaderEffectMaterialShader : public QSGMaterialRhiShader +class QSGRhiShaderEffectMaterialShader : public QSGMaterialShader { public: QSGRhiShaderEffectMaterialShader(const QSGRhiShaderEffectMaterial *material); @@ -450,7 +450,7 @@ bool QSGRhiShaderEffectMaterialShader::updateGraphicsPipelineState(RenderState & QSGRhiShaderEffectMaterial::QSGRhiShaderEffectMaterial(QSGRhiShaderEffectNode *node) : m_node(node) { - setFlag(SupportsRhiShader | Blending | RequiresFullMatrix, true); // may be changed in syncMaterial() + setFlag(Blending | RequiresFullMatrix, true); // may be changed in syncMaterial() } QSGRhiShaderEffectMaterial::~QSGRhiShaderEffectMaterial() @@ -521,7 +521,6 @@ QSGMaterialType *QSGRhiShaderEffectMaterial::type() const QSGMaterialShader *QSGRhiShaderEffectMaterial::createShader() const { - Q_ASSERT(flags().testFlag(RhiShaderWanted)); return new QSGRhiShaderEffectMaterialShader(this); } diff --git a/src/quick/scenegraph/scenegraph.pri b/src/quick/scenegraph/scenegraph.pri index 87146dcac8..d03e79a272 100644 --- a/src/quick/scenegraph/scenegraph.pri +++ b/src/quick/scenegraph/scenegraph.pri @@ -7,8 +7,6 @@ HEADERS += \ $$PWD/coreapi/qsgmaterialtype.h \ $$PWD/coreapi/qsgmaterialshader.h \ $$PWD/coreapi/qsgmaterialshader_p.h \ - $$PWD/coreapi/qsgmaterialrhishader.h \ - $$PWD/coreapi/qsgmaterialrhishader_p.h \ $$PWD/coreapi/qsgnode.h \ $$PWD/coreapi/qsgnode_p.h \ $$PWD/coreapi/qsgnodeupdater_p.h \ @@ -27,7 +25,6 @@ SOURCES += \ $$PWD/coreapi/qsggeometry.cpp \ $$PWD/coreapi/qsgmaterial.cpp \ $$PWD/coreapi/qsgmaterialshader.cpp \ - $$PWD/coreapi/qsgmaterialrhishader.cpp \ $$PWD/coreapi/qsgtexture.cpp \ $$PWD/coreapi/qsgnode.cpp \ $$PWD/coreapi/qsgnodeupdater.cpp \ diff --git a/src/quick/scenegraph/scenegraph.qrc b/src/quick/scenegraph/scenegraph.qrc index e409f07610..ba93c2476c 100644 --- a/src/quick/scenegraph/scenegraph.qrc +++ b/src/quick/scenegraph/scenegraph.qrc @@ -1,77 +1,11 @@ <RCC> <qresource prefix="/qt-project.org/scenegraph"> - <file>shaders/flatcolor.frag</file> - <file>shaders/flatcolor.vert</file> - <file>shaders/8bittextmask.frag</file> - <file>shaders/24bittextmask.frag</file> - <file>shaders/32bitcolortext.frag</file> - <file>shaders/opaquetexture.frag</file> - <file>shaders/opaquetexture.vert</file> - <file>shaders/outlinedtext.frag</file> - <file>shaders/outlinedtext.vert</file> - <file>shaders/smoothcolor.frag</file> - <file>shaders/smoothcolor.vert</file> - <file>shaders/smoothtexture.frag</file> - <file>shaders/smoothtexture.vert</file> - <file>shaders/styledtext.frag</file> - <file>shaders/styledtext.vert</file> - <file>shaders/textmask.frag</file> - <file>shaders/textmask.vert</file> - <file>shaders/texture.frag</file> - <file>shaders/distancefieldoutlinetext.frag</file> - <file>shaders/distancefieldshiftedtext.frag</file> - <file>shaders/distancefieldshiftedtext.vert</file> - <file>shaders/distancefieldtext.frag</file> - <file>shaders/distancefieldtext.vert</file> - <file>shaders/hiqsubpixeldistancefieldtext.frag</file> - <file>shaders/hiqsubpixeldistancefieldtext.vert</file> - <file>shaders/loqsubpixeldistancefieldtext.frag</file> - <file>shaders/loqsubpixeldistancefieldtext.vert</file> - <file>shaders/vertexcolor.frag</file> - <file>shaders/vertexcolor.vert</file> - <file>shaders/rendernode.vert</file> - <file>shaders/rendernode.frag</file> <file>shaders/stencilclip.frag</file> <file>shaders/stencilclip.vert</file> - <file>shaders/8bittextmask_core.frag</file> - <file>shaders/24bittextmask_core.frag</file> - <file>shaders/32bitcolortext_core.frag</file> - <file>shaders/distancefieldoutlinetext_core.frag</file> - <file>shaders/distancefieldshiftedtext_core.frag</file> - <file>shaders/distancefieldshiftedtext_core.vert</file> - <file>shaders/distancefieldtext_core.frag</file> - <file>shaders/distancefieldtext_core.vert</file> - <file>shaders/flatcolor_core.frag</file> - <file>shaders/flatcolor_core.vert</file> - <file>shaders/hiqsubpixeldistancefieldtext_core.frag</file> - <file>shaders/hiqsubpixeldistancefieldtext_core.vert</file> - <file>shaders/loqsubpixeldistancefieldtext_core.frag</file> - <file>shaders/loqsubpixeldistancefieldtext_core.vert</file> - <file>shaders/opaquetexture_core.frag</file> - <file>shaders/opaquetexture_core.vert</file> - <file>shaders/outlinedtext_core.frag</file> - <file>shaders/outlinedtext_core.vert</file> - <file>shaders/rendernode_core.frag</file> - <file>shaders/rendernode_core.vert</file> - <file>shaders/smoothcolor_core.frag</file> - <file>shaders/smoothcolor_core.vert</file> - <file>shaders/smoothtexture_core.frag</file> - <file>shaders/smoothtexture_core.vert</file> <file>shaders/stencilclip_core.frag</file> <file>shaders/stencilclip_core.vert</file> - <file>shaders/styledtext_core.frag</file> - <file>shaders/styledtext_core.vert</file> - <file>shaders/textmask_core.frag</file> - <file>shaders/textmask_core.vert</file> - <file>shaders/texture_core.frag</file> - <file>shaders/vertexcolor_core.frag</file> - <file>shaders/vertexcolor_core.vert</file> <file>shaders/visualization.vert</file> <file>shaders/visualization.frag</file> - <file>shaders/sprite.frag</file> - <file>shaders/sprite.vert</file> - <file>shaders/sprite_core.frag</file> - <file>shaders/sprite_core.vert</file> <file>shaders_ng/vertexcolor.vert.qsb</file> <file>shaders_ng/vertexcolor.frag.qsb</file> diff --git a/src/quick/scenegraph/shaders/24bittextmask.frag b/src/quick/scenegraph/shaders/24bittextmask.frag deleted file mode 100644 index 5c21e202f9..0000000000 --- a/src/quick/scenegraph/shaders/24bittextmask.frag +++ /dev/null @@ -1,10 +0,0 @@ -varying highp vec2 sampleCoord; - -uniform lowp sampler2D _qt_texture; -uniform lowp float color; // just the alpha, really... - -void main() -{ - lowp vec4 glyph = texture2D(_qt_texture, sampleCoord); - gl_FragColor = vec4(glyph.rgb * color, glyph.a); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/24bittextmask_core.frag b/src/quick/scenegraph/shaders/24bittextmask_core.frag deleted file mode 100644 index 29d1f23017..0000000000 --- a/src/quick/scenegraph/shaders/24bittextmask_core.frag +++ /dev/null @@ -1,14 +0,0 @@ -#version 150 core - -in vec2 sampleCoord; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform float color; // just the alpha, really... - -void main() -{ - vec4 glyph = texture(_qt_texture, sampleCoord); - fragColor = vec4(glyph.rgb * color, glyph.a); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/32bitcolortext.frag b/src/quick/scenegraph/shaders/32bitcolortext.frag deleted file mode 100644 index 6fdb6e6aeb..0000000000 --- a/src/quick/scenegraph/shaders/32bitcolortext.frag +++ /dev/null @@ -1,9 +0,0 @@ -varying highp vec2 sampleCoord; - -uniform sampler2D _qt_texture; -uniform lowp float color; // just the alpha, really... - -void main() -{ - gl_FragColor = texture2D(_qt_texture, sampleCoord) * color; -} diff --git a/src/quick/scenegraph/shaders/32bitcolortext_core.frag b/src/quick/scenegraph/shaders/32bitcolortext_core.frag deleted file mode 100644 index 010aca97b4..0000000000 --- a/src/quick/scenegraph/shaders/32bitcolortext_core.frag +++ /dev/null @@ -1,13 +0,0 @@ -#version 150 core - -in vec2 sampleCoord; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform float color; // just the alpha, really... - -void main() -{ - fragColor = texture(_qt_texture, sampleCoord) * color; -} diff --git a/src/quick/scenegraph/shaders/8bittextmask.frag b/src/quick/scenegraph/shaders/8bittextmask.frag deleted file mode 100644 index 44ffb279cb..0000000000 --- a/src/quick/scenegraph/shaders/8bittextmask.frag +++ /dev/null @@ -1,9 +0,0 @@ -varying highp vec2 sampleCoord; - -uniform lowp sampler2D _qt_texture; -uniform lowp vec4 color; - -void main() -{ - gl_FragColor = color * texture2D(_qt_texture, sampleCoord).a; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/8bittextmask_core.frag b/src/quick/scenegraph/shaders/8bittextmask_core.frag deleted file mode 100644 index 2d67a4676a..0000000000 --- a/src/quick/scenegraph/shaders/8bittextmask_core.frag +++ /dev/null @@ -1,13 +0,0 @@ -#version 150 core - -in vec2 sampleCoord; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform vec4 color; - -void main() -{ - fragColor = color * texture(_qt_texture, sampleCoord).r; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldoutlinetext.frag b/src/quick/scenegraph/shaders/distancefieldoutlinetext.frag deleted file mode 100644 index 250ed322a1..0000000000 --- a/src/quick/scenegraph/shaders/distancefieldoutlinetext.frag +++ /dev/null @@ -1,16 +0,0 @@ -varying highp vec2 sampleCoord; - -uniform sampler2D _qt_texture; -uniform lowp vec4 color; -uniform lowp vec4 styleColor; -uniform mediump float alphaMin; -uniform mediump float alphaMax; -uniform mediump float outlineAlphaMax0; -uniform mediump float outlineAlphaMax1; - -void main() -{ - mediump float d = texture2D(_qt_texture, sampleCoord).a; - gl_FragColor = mix(styleColor, color, smoothstep(alphaMin, alphaMax, d)) - * smoothstep(outlineAlphaMax0, outlineAlphaMax1, d); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldoutlinetext_core.frag b/src/quick/scenegraph/shaders/distancefieldoutlinetext_core.frag deleted file mode 100644 index 80fa05ca3c..0000000000 --- a/src/quick/scenegraph/shaders/distancefieldoutlinetext_core.frag +++ /dev/null @@ -1,20 +0,0 @@ -#version 150 core - -in vec2 sampleCoord; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform vec4 color; -uniform vec4 styleColor; -uniform float alphaMin; -uniform float alphaMax; -uniform float outlineAlphaMax0; -uniform float outlineAlphaMax1; - -void main() -{ - float d = texture(_qt_texture, sampleCoord).r; - fragColor = mix(styleColor, color, smoothstep(alphaMin, alphaMax, d)) - * smoothstep(outlineAlphaMax0, outlineAlphaMax1, d); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldshiftedtext.frag b/src/quick/scenegraph/shaders/distancefieldshiftedtext.frag deleted file mode 100644 index 42fead8713..0000000000 --- a/src/quick/scenegraph/shaders/distancefieldshiftedtext.frag +++ /dev/null @@ -1,17 +0,0 @@ -varying highp vec2 sampleCoord; -varying highp vec2 shiftedSampleCoord; - -uniform mediump sampler2D _qt_texture; -uniform lowp vec4 color; -uniform lowp vec4 styleColor; -uniform mediump float alphaMin; -uniform mediump float alphaMax; - -void main() -{ - highp float a = smoothstep(alphaMin, alphaMax, texture2D(_qt_texture, sampleCoord).a); - highp vec4 shifted = styleColor * smoothstep(alphaMin, - alphaMax, - texture2D(_qt_texture, shiftedSampleCoord).a); - gl_FragColor = mix(shifted, color, a); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldshiftedtext.vert b/src/quick/scenegraph/shaders/distancefieldshiftedtext.vert deleted file mode 100644 index 800eadc4f1..0000000000 --- a/src/quick/scenegraph/shaders/distancefieldshiftedtext.vert +++ /dev/null @@ -1,17 +0,0 @@ -uniform highp mat4 matrix; -uniform highp vec2 textureScale; - -attribute highp vec4 vCoord; -attribute highp vec2 tCoord; - -uniform highp vec2 shift; - -varying highp vec2 sampleCoord; -varying highp vec2 shiftedSampleCoord; - -void main() -{ - sampleCoord = tCoord * textureScale; - shiftedSampleCoord = (tCoord - shift) * textureScale; - gl_Position = matrix * vCoord; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.frag b/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.frag deleted file mode 100644 index 3f66965e78..0000000000 --- a/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.frag +++ /dev/null @@ -1,20 +0,0 @@ -#version 150 core - -in vec2 sampleCoord; -in vec2 shiftedSampleCoord; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform vec4 color; -uniform vec4 styleColor; -uniform float alphaMin; -uniform float alphaMax; - -void main() -{ - float a = smoothstep(alphaMin, alphaMax, texture(_qt_texture, sampleCoord).r); - vec4 shifted = styleColor * smoothstep(alphaMin, alphaMax, - texture(_qt_texture, shiftedSampleCoord).r); - fragColor = mix(shifted, color, a); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.vert b/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.vert deleted file mode 100644 index b7a3ecc667..0000000000 --- a/src/quick/scenegraph/shaders/distancefieldshiftedtext_core.vert +++ /dev/null @@ -1,18 +0,0 @@ -#version 150 core - -in vec4 vCoord; -in vec2 tCoord; - -out vec2 sampleCoord; -out vec2 shiftedSampleCoord; - -uniform mat4 matrix; -uniform vec2 textureScale; -uniform vec2 shift; - -void main() -{ - sampleCoord = tCoord * textureScale; - shiftedSampleCoord = (tCoord - shift) * textureScale; - gl_Position = matrix * vCoord; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldtext.frag b/src/quick/scenegraph/shaders/distancefieldtext.frag deleted file mode 100644 index 951fb2a825..0000000000 --- a/src/quick/scenegraph/shaders/distancefieldtext.frag +++ /dev/null @@ -1,13 +0,0 @@ -varying highp vec2 sampleCoord; - -uniform mediump sampler2D _qt_texture; -uniform lowp vec4 color; -uniform mediump float alphaMin; -uniform mediump float alphaMax; - -void main() -{ - gl_FragColor = color * smoothstep(alphaMin, - alphaMax, - texture2D(_qt_texture, sampleCoord).a); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldtext.vert b/src/quick/scenegraph/shaders/distancefieldtext.vert deleted file mode 100644 index c4963977a5..0000000000 --- a/src/quick/scenegraph/shaders/distancefieldtext.vert +++ /dev/null @@ -1,13 +0,0 @@ -uniform highp mat4 matrix; -uniform highp vec2 textureScale; - -attribute highp vec4 vCoord; -attribute highp vec2 tCoord; - -varying highp vec2 sampleCoord; - -void main() -{ - sampleCoord = tCoord * textureScale; - gl_Position = matrix * vCoord; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldtext_core.frag b/src/quick/scenegraph/shaders/distancefieldtext_core.frag deleted file mode 100644 index 9c64a60d3d..0000000000 --- a/src/quick/scenegraph/shaders/distancefieldtext_core.frag +++ /dev/null @@ -1,16 +0,0 @@ -#version 150 core - -in vec2 sampleCoord; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform vec4 color; -uniform float alphaMin; -uniform float alphaMax; - -void main() -{ - fragColor = color * smoothstep(alphaMin, alphaMax, - texture(_qt_texture, sampleCoord).r); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/distancefieldtext_core.vert b/src/quick/scenegraph/shaders/distancefieldtext_core.vert deleted file mode 100644 index 7fc693d139..0000000000 --- a/src/quick/scenegraph/shaders/distancefieldtext_core.vert +++ /dev/null @@ -1,15 +0,0 @@ -#version 150 core - -in vec4 vCoord; -in vec2 tCoord; - -out vec2 sampleCoord; - -uniform mat4 matrix; -uniform vec2 textureScale; - -void main() -{ - sampleCoord = tCoord * textureScale; - gl_Position = matrix * vCoord; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/flatcolor.frag b/src/quick/scenegraph/shaders/flatcolor.frag deleted file mode 100644 index 8c225bf5a4..0000000000 --- a/src/quick/scenegraph/shaders/flatcolor.frag +++ /dev/null @@ -1,6 +0,0 @@ -uniform lowp vec4 color; - -void main() -{ - gl_FragColor = color; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/flatcolor.vert b/src/quick/scenegraph/shaders/flatcolor.vert deleted file mode 100644 index a61de97f85..0000000000 --- a/src/quick/scenegraph/shaders/flatcolor.vert +++ /dev/null @@ -1,7 +0,0 @@ -attribute highp vec4 vCoord; -uniform highp mat4 matrix; - -void main() -{ - gl_Position = matrix * vCoord; -} diff --git a/src/quick/scenegraph/shaders/flatcolor_core.frag b/src/quick/scenegraph/shaders/flatcolor_core.frag deleted file mode 100644 index 23a957ad7b..0000000000 --- a/src/quick/scenegraph/shaders/flatcolor_core.frag +++ /dev/null @@ -1,10 +0,0 @@ -#version 150 core - -out vec4 fragColor; - -uniform vec4 color; - -void main() -{ - fragColor = color; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/flatcolor_core.vert b/src/quick/scenegraph/shaders/flatcolor_core.vert deleted file mode 100644 index e33c591b95..0000000000 --- a/src/quick/scenegraph/shaders/flatcolor_core.vert +++ /dev/null @@ -1,10 +0,0 @@ -#version 150 core - -in vec4 vCoord; - -uniform mat4 matrix; - -void main() -{ - gl_Position = matrix * vCoord; -} diff --git a/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext.frag b/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext.frag deleted file mode 100644 index 9b65e5f79b..0000000000 --- a/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext.frag +++ /dev/null @@ -1,58 +0,0 @@ -varying highp vec2 sampleCoord; -varying highp vec3 sampleFarLeft; -varying highp vec3 sampleNearLeft; -varying highp vec3 sampleNearRight; -varying highp vec3 sampleFarRight; - -uniform sampler2D _qt_texture; -uniform lowp vec4 color; -uniform mediump float alphaMin; -uniform mediump float alphaMax; - -void main() -{ - highp vec4 n; - n.x = texture2DProj(_qt_texture, sampleFarLeft).a; - n.y = texture2DProj(_qt_texture, sampleNearLeft).a; - highp float c = texture2D(_qt_texture, sampleCoord).a; - n.z = texture2DProj(_qt_texture, sampleNearRight).a; - n.w = texture2DProj(_qt_texture, sampleFarRight).a; -#if 0 - // Blurrier, faster. - n = smoothstep(alphaMin, alphaMax, n); - c = smoothstep(alphaMin, alphaMax, c); -#else - // Sharper, slower. - highp vec2 d = min(abs(n.yw - n.xz) * 2., 0.67); - highp vec2 lo = mix(vec2(alphaMin), vec2(0.5), d); - highp vec2 hi = mix(vec2(alphaMax), vec2(0.5), d); - n = smoothstep(lo.xxyy, hi.xxyy, n); - c = smoothstep(lo.x + lo.y, hi.x + hi.y, 2. * c); -#endif - gl_FragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * color.w; -} - -/* -#extension GL_OES_standard_derivatives: enable - -varying highp vec2 sampleCoord; - -uniform sampler2D _qt_texture; -uniform lowp vec4 color; -uniform highp float alphaMin; -uniform highp float alphaMax; - -void main() -{ - highp vec2 delta = dFdx(sampleCoord); - highp vec4 n; - n.x = texture2D(_qt_texture, sampleCoord - 0.667 * delta).a; - n.y = texture2D(_qt_texture, sampleCoord - 0.333 * delta).a; - highp float c = texture2D(_qt_texture, sampleCoord).a; - n.z = texture2D(_qt_texture, sampleCoord + 0.333 * delta).a; - n.w = texture2D(_qt_texture, sampleCoord + 0.667 * delta).a; - n = smoothstep(alphaMin, alphaMax, n); - c = smoothstep(alphaMin, alphaMax, c); - gl_FragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * color.w; -}; -*/
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext.vert b/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext.vert deleted file mode 100644 index 62768e88e1..0000000000 --- a/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext.vert +++ /dev/null @@ -1,34 +0,0 @@ -uniform highp mat4 matrix; -uniform highp vec2 textureScale; -uniform highp float fontScale; -uniform highp vec4 vecDelta; - -attribute highp vec4 vCoord; -attribute highp vec2 tCoord; - -varying highp vec2 sampleCoord; -varying highp vec3 sampleFarLeft; -varying highp vec3 sampleNearLeft; -varying highp vec3 sampleNearRight; -varying highp vec3 sampleFarRight; - -void main() -{ - sampleCoord = tCoord * textureScale; - gl_Position = matrix * vCoord; - - // Calculate neighbor pixel position in item space. - highp vec3 wDelta = gl_Position.w * vecDelta.xyw; - highp vec3 farLeft = vCoord.xyw - 0.667 * wDelta; - highp vec3 nearLeft = vCoord.xyw - 0.333 * wDelta; - highp vec3 nearRight = vCoord.xyw + 0.333 * wDelta; - highp vec3 farRight = vCoord.xyw + 0.667 * wDelta; - - // Calculate neighbor texture coordinate. - highp vec2 scale = textureScale / fontScale; - highp vec2 base = sampleCoord - scale * vCoord.xy; - sampleFarLeft = vec3(base * farLeft.z + scale * farLeft.xy, farLeft.z); - sampleNearLeft = vec3(base * nearLeft.z + scale * nearLeft.xy, nearLeft.z); - sampleNearRight = vec3(base * nearRight.z + scale * nearRight.xy, nearRight.z); - sampleFarRight = vec3(base * farRight.z + scale * farRight.xy, farRight.z); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.frag b/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.frag deleted file mode 100644 index cf6ba2b8d9..0000000000 --- a/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.frag +++ /dev/null @@ -1,32 +0,0 @@ -#version 150 core - -in vec2 sampleCoord; -in vec3 sampleFarLeft; -in vec3 sampleNearLeft; -in vec3 sampleNearRight; -in vec3 sampleFarRight; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform vec4 color; -uniform float alphaMin; -uniform float alphaMax; - -void main() -{ - vec4 n; - n.x = textureProj(_qt_texture, sampleFarLeft).r; - n.y = textureProj(_qt_texture, sampleNearLeft).r; - float c = texture(_qt_texture, sampleCoord).r; - n.z = textureProj(_qt_texture, sampleNearRight).r; - n.w = textureProj(_qt_texture, sampleFarRight).r; - - vec2 d = min(abs(n.yw - n.xz) * 2., 0.67); - vec2 lo = mix(vec2(alphaMin), vec2(0.5), d); - vec2 hi = mix(vec2(alphaMax), vec2(0.5), d); - n = smoothstep(lo.xxyy, hi.xxyy, n); - c = smoothstep(lo.x + lo.y, hi.x + hi.y, 2. * c); - - fragColor = vec4(0.333 * (n.xyz + n.yzw + c), c) * color.w; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.vert b/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.vert deleted file mode 100644 index 936f74725b..0000000000 --- a/src/quick/scenegraph/shaders/hiqsubpixeldistancefieldtext_core.vert +++ /dev/null @@ -1,36 +0,0 @@ -#version 150 core - -in vec4 vCoord; -in vec2 tCoord; - -out vec2 sampleCoord; -out vec3 sampleFarLeft; -out vec3 sampleNearLeft; -out vec3 sampleNearRight; -out vec3 sampleFarRight; - -uniform mat4 matrix; -uniform vec2 textureScale; -uniform float fontScale; -uniform vec4 vecDelta; - -void main() -{ - sampleCoord = tCoord * textureScale; - gl_Position = matrix * vCoord; - - // Calculate neighbor pixel position in item space. - vec3 wDelta = gl_Position.w * vecDelta.xyw; - vec3 farLeft = vCoord.xyw - 0.667 * wDelta; - vec3 nearLeft = vCoord.xyw - 0.333 * wDelta; - vec3 nearRight = vCoord.xyw + 0.333 * wDelta; - vec3 farRight = vCoord.xyw + 0.667 * wDelta; - - // Calculate neighbor texture coordinate. - vec2 scale = textureScale / fontScale; - vec2 base = sampleCoord - scale * vCoord.xy; - sampleFarLeft = vec3(base * farLeft.z + scale * farLeft.xy, farLeft.z); - sampleNearLeft = vec3(base * nearLeft.z + scale * nearLeft.xy, nearLeft.z); - sampleNearRight = vec3(base * nearRight.z + scale * nearRight.xy, nearRight.z); - sampleFarRight = vec3(base * farRight.z + scale * farRight.xy, farRight.z); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext.frag b/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext.frag deleted file mode 100644 index 61b6c8dd9a..0000000000 --- a/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext.frag +++ /dev/null @@ -1,17 +0,0 @@ -varying highp vec3 sampleNearLeft; -varying highp vec3 sampleNearRight; - -uniform sampler2D _qt_texture; -uniform lowp vec4 color; -uniform mediump float alphaMin; -uniform mediump float alphaMax; - -void main() -{ - highp vec2 n; - n.x = texture2DProj(_qt_texture, sampleNearLeft).a; - n.y = texture2DProj(_qt_texture, sampleNearRight).a; - n = smoothstep(alphaMin, alphaMax, n); - highp float c = 0.5 * (n.x + n.y); - gl_FragColor = vec4(n.x, c, n.y, c) * color.w; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext.vert b/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext.vert deleted file mode 100644 index 33cb7efb19..0000000000 --- a/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext.vert +++ /dev/null @@ -1,27 +0,0 @@ -uniform highp mat4 matrix; -uniform highp vec2 textureScale; -uniform highp float fontScale; -uniform highp vec4 vecDelta; - -attribute highp vec4 vCoord; -attribute highp vec2 tCoord; - -varying highp vec3 sampleNearLeft; -varying highp vec3 sampleNearRight; - -void main() -{ - highp vec2 sampleCoord = tCoord * textureScale; - gl_Position = matrix * vCoord; - - // Calculate neighbor pixel position in item space. - highp vec3 wDelta = gl_Position.w * vecDelta.xyw; - highp vec3 nearLeft = vCoord.xyw - 0.25 * wDelta; - highp vec3 nearRight = vCoord.xyw + 0.25 * wDelta; - - // Calculate neighbor texture coordinate. - highp vec2 scale = textureScale / fontScale; - highp vec2 base = sampleCoord - scale * vCoord.xy; - sampleNearLeft = vec3(base * nearLeft.z + scale * nearLeft.xy, nearLeft.z); - sampleNearRight = vec3(base * nearRight.z + scale * nearRight.xy, nearRight.z); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.frag b/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.frag deleted file mode 100644 index 2dd588d307..0000000000 --- a/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.frag +++ /dev/null @@ -1,21 +0,0 @@ -#version 150 core - -in vec3 sampleNearLeft; -in vec3 sampleNearRight; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform vec4 color; -uniform float alphaMin; -uniform float alphaMax; - -void main() -{ - vec2 n; - n.x = textureProj(_qt_texture, sampleNearLeft).r; - n.y = textureProj(_qt_texture, sampleNearRight).r; - n = smoothstep(alphaMin, alphaMax, n); - float c = 0.5 * (n.x + n.y); - fragColor = vec4(n.x, c, n.y, c) * color.w; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.vert b/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.vert deleted file mode 100644 index b887a70001..0000000000 --- a/src/quick/scenegraph/shaders/loqsubpixeldistancefieldtext_core.vert +++ /dev/null @@ -1,29 +0,0 @@ -#version 150 core - -in vec4 vCoord; -in vec2 tCoord; - -out vec3 sampleNearLeft; -out vec3 sampleNearRight; - -uniform mat4 matrix; -uniform vec2 textureScale; -uniform float fontScale; -uniform vec4 vecDelta; - -void main() -{ - vec2 sampleCoord = tCoord * textureScale; - gl_Position = matrix * vCoord; - - // Calculate neighbor pixel position in item space. - vec3 wDelta = gl_Position.w * vecDelta.xyw; - vec3 nearLeft = vCoord.xyw - 0.25 * wDelta; - vec3 nearRight = vCoord.xyw + 0.25 * wDelta; - - // Calculate neighbor texture coordinate. - vec2 scale = textureScale / fontScale; - vec2 base = sampleCoord - scale * vCoord.xy; - sampleNearLeft = vec3(base * nearLeft.z + scale * nearLeft.xy, nearLeft.z); - sampleNearRight = vec3(base * nearRight.z + scale * nearRight.xy, nearRight.z); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/opaquetexture.frag b/src/quick/scenegraph/shaders/opaquetexture.frag deleted file mode 100644 index b7e07de385..0000000000 --- a/src/quick/scenegraph/shaders/opaquetexture.frag +++ /dev/null @@ -1,8 +0,0 @@ -varying highp vec2 qt_TexCoord; - -uniform sampler2D qt_Texture; - -void main() -{ - gl_FragColor = texture2D(qt_Texture, qt_TexCoord); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/opaquetexture.vert b/src/quick/scenegraph/shaders/opaquetexture.vert deleted file mode 100644 index 32cf02df25..0000000000 --- a/src/quick/scenegraph/shaders/opaquetexture.vert +++ /dev/null @@ -1,12 +0,0 @@ -uniform highp mat4 qt_Matrix; - -attribute highp vec4 qt_VertexPosition; -attribute highp vec2 qt_VertexTexCoord; - -varying highp vec2 qt_TexCoord; - -void main() -{ - qt_TexCoord = qt_VertexTexCoord; - gl_Position = qt_Matrix * qt_VertexPosition; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/opaquetexture_core.frag b/src/quick/scenegraph/shaders/opaquetexture_core.frag deleted file mode 100644 index 5f30e68677..0000000000 --- a/src/quick/scenegraph/shaders/opaquetexture_core.frag +++ /dev/null @@ -1,12 +0,0 @@ -#version 150 core - -in vec2 qt_TexCoord; - -out vec4 fragColor; - -uniform sampler2D qt_Texture; - -void main() -{ - fragColor = texture(qt_Texture, qt_TexCoord); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/opaquetexture_core.vert b/src/quick/scenegraph/shaders/opaquetexture_core.vert deleted file mode 100644 index 419b1a825c..0000000000 --- a/src/quick/scenegraph/shaders/opaquetexture_core.vert +++ /dev/null @@ -1,14 +0,0 @@ -#version 150 core - -uniform mat4 qt_Matrix; - -in vec4 qt_VertexPosition; -in vec2 qt_VertexTexCoord; - -out vec2 qt_TexCoord; - -void main() -{ - qt_TexCoord = qt_VertexTexCoord; - gl_Position = qt_Matrix * qt_VertexPosition; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/outlinedtext.frag b/src/quick/scenegraph/shaders/outlinedtext.frag deleted file mode 100644 index b3e5475d5d..0000000000 --- a/src/quick/scenegraph/shaders/outlinedtext.frag +++ /dev/null @@ -1,21 +0,0 @@ -varying highp vec2 sampleCoord; -varying highp vec2 sCoordUp; -varying highp vec2 sCoordDown; -varying highp vec2 sCoordLeft; -varying highp vec2 sCoordRight; - -uniform sampler2D _qt_texture; -uniform lowp vec4 color; -uniform lowp vec4 styleColor; - -void main() -{ - lowp float glyph = texture2D(_qt_texture, sampleCoord).a; - lowp float outline = clamp(clamp(texture2D(_qt_texture, sCoordUp).a + - texture2D(_qt_texture, sCoordDown).a + - texture2D(_qt_texture, sCoordLeft).a + - texture2D(_qt_texture, sCoordRight).a, - 0.0, 1.0) - glyph, - 0.0, 1.0); - gl_FragColor = outline * styleColor + glyph * color; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/outlinedtext.vert b/src/quick/scenegraph/shaders/outlinedtext.vert deleted file mode 100644 index 9df832de3c..0000000000 --- a/src/quick/scenegraph/shaders/outlinedtext.vert +++ /dev/null @@ -1,24 +0,0 @@ -uniform highp mat4 matrix; -uniform highp vec2 textureScale; -uniform highp vec2 shift; -uniform highp float dpr; - -attribute highp vec4 vCoord; -attribute highp vec2 tCoord; - -varying highp vec2 sampleCoord; -varying highp vec2 sCoordUp; -varying highp vec2 sCoordDown; -varying highp vec2 sCoordLeft; -varying highp vec2 sCoordRight; - -void main() -{ - sampleCoord = tCoord * textureScale; - sCoordUp = (tCoord - vec2(0.0, -1.0)) * textureScale; - sCoordDown = (tCoord - vec2(0.0, 1.0)) * textureScale; - sCoordLeft = (tCoord - vec2(-1.0, 0.0)) * textureScale; - sCoordRight = (tCoord - vec2(1.0, 0.0)) * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/outlinedtext_core.frag b/src/quick/scenegraph/shaders/outlinedtext_core.frag deleted file mode 100644 index e19c8937f9..0000000000 --- a/src/quick/scenegraph/shaders/outlinedtext_core.frag +++ /dev/null @@ -1,25 +0,0 @@ -#version 150 core - -in vec2 sampleCoord; -in vec2 sCoordUp; -in vec2 sCoordDown; -in vec2 sCoordLeft; -in vec2 sCoordRight; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform vec4 color; -uniform vec4 styleColor; - -void main() -{ - float glyph = texture(_qt_texture, sampleCoord).r; - float outline = clamp(clamp(texture(_qt_texture, sCoordUp).r + - texture(_qt_texture, sCoordDown).r + - texture(_qt_texture, sCoordLeft).r + - texture(_qt_texture, sCoordRight).r, - 0.0, 1.0) - glyph, - 0.0, 1.0); - fragColor = outline * styleColor + glyph * color; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/outlinedtext_core.vert b/src/quick/scenegraph/shaders/outlinedtext_core.vert deleted file mode 100644 index a854355460..0000000000 --- a/src/quick/scenegraph/shaders/outlinedtext_core.vert +++ /dev/null @@ -1,26 +0,0 @@ -#version 150 core - -in vec4 vCoord; -in vec2 tCoord; - -out vec2 sampleCoord; -out vec2 sCoordUp; -out vec2 sCoordDown; -out vec2 sCoordLeft; -out vec2 sCoordRight; - -uniform mat4 matrix; -uniform vec2 textureScale; -uniform vec2 shift; -uniform float dpr; - -void main() -{ - sampleCoord = tCoord * textureScale; - sCoordUp = (tCoord - vec2(0.0, -1.0)) * textureScale; - sCoordDown = (tCoord - vec2(0.0, 1.0)) * textureScale; - sCoordLeft = (tCoord - vec2(-1.0, 0.0)) * textureScale; - sCoordRight = (tCoord - vec2(1.0, 0.0)) * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/rendernode.frag b/src/quick/scenegraph/shaders/rendernode.frag deleted file mode 100644 index b4e9b0209c..0000000000 --- a/src/quick/scenegraph/shaders/rendernode.frag +++ /dev/null @@ -1,8 +0,0 @@ -uniform lowp sampler2D tex; - -varying highp vec2 t; - -void main() -{ - gl_FragColor = texture2D(tex, t); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/rendernode.vert b/src/quick/scenegraph/shaders/rendernode.vert deleted file mode 100644 index fbfe9ef8ae..0000000000 --- a/src/quick/scenegraph/shaders/rendernode.vert +++ /dev/null @@ -1,10 +0,0 @@ -attribute highp vec4 av; -attribute highp vec2 at; - -varying highp vec2 t; - -void main() -{ - gl_Position = av; - t = at; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/rendernode_core.frag b/src/quick/scenegraph/shaders/rendernode_core.frag deleted file mode 100644 index b29301b058..0000000000 --- a/src/quick/scenegraph/shaders/rendernode_core.frag +++ /dev/null @@ -1,12 +0,0 @@ -#version 150 core - -uniform sampler2D tex; - -in vec2 t; - -out vec4 fragColor; - -void main() -{ - fragColor = texture(tex, t); -} diff --git a/src/quick/scenegraph/shaders/rendernode_core.vert b/src/quick/scenegraph/shaders/rendernode_core.vert deleted file mode 100644 index a76d519a5a..0000000000 --- a/src/quick/scenegraph/shaders/rendernode_core.vert +++ /dev/null @@ -1,12 +0,0 @@ -#version 150 core - -in vec4 av; -in vec2 at; - -out vec2 t; - -void main() -{ - gl_Position = av; - t = at; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothcolor.frag b/src/quick/scenegraph/shaders/smoothcolor.frag deleted file mode 100644 index 71de9dbfc2..0000000000 --- a/src/quick/scenegraph/shaders/smoothcolor.frag +++ /dev/null @@ -1,6 +0,0 @@ -varying lowp vec4 color; - -void main() -{ - gl_FragColor = color; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothcolor.vert b/src/quick/scenegraph/shaders/smoothcolor.vert deleted file mode 100644 index df70fea92a..0000000000 --- a/src/quick/scenegraph/shaders/smoothcolor.vert +++ /dev/null @@ -1,45 +0,0 @@ -uniform highp vec2 pixelSize; -uniform highp mat4 matrix; -uniform lowp float opacity; - -attribute highp vec4 vertex; -attribute lowp vec4 vertexColor; -attribute highp vec2 vertexOffset; - -varying lowp vec4 color; - -void main() -{ - highp vec4 pos = matrix * vertex; - gl_Position = pos; - - if (vertexOffset.x != 0.) { - highp vec4 delta = matrix[0] * vertexOffset.x; - highp vec2 dir = delta.xy * pos.w - pos.xy * delta.w; - highp vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); - dir -= ndir * delta.w * pos.w; - highp float numerator = dot(dir, ndir * pos.w * pos.w); - highp float scale = 0.0; - if (numerator < 0.0) - scale = 1.0; - else - scale = min(1.0, numerator / dot(dir, dir)); - gl_Position += scale * delta; - } - - if (vertexOffset.y != 0.) { - highp vec4 delta = matrix[1] * vertexOffset.y; - highp vec2 dir = delta.xy * pos.w - pos.xy * delta.w; - highp vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); - dir -= ndir * delta.w * pos.w; - highp float numerator = dot(dir, ndir * pos.w * pos.w); - highp float scale = 0.0; - if (numerator < 0.0) - scale = 1.0; - else - scale = min(1.0, numerator / dot(dir, dir)); - gl_Position += scale * delta; - } - - color = vertexColor * opacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothcolor_core.frag b/src/quick/scenegraph/shaders/smoothcolor_core.frag deleted file mode 100644 index 84533c2b40..0000000000 --- a/src/quick/scenegraph/shaders/smoothcolor_core.frag +++ /dev/null @@ -1,10 +0,0 @@ -#version 150 core - -in vec4 color; - -out vec4 fragColor; - -void main() -{ - fragColor = color; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothcolor_core.vert b/src/quick/scenegraph/shaders/smoothcolor_core.vert deleted file mode 100644 index 1eed751ccd..0000000000 --- a/src/quick/scenegraph/shaders/smoothcolor_core.vert +++ /dev/null @@ -1,47 +0,0 @@ -#version 150 core - -in vec4 vertex; -in vec4 vertexColor; -in vec2 vertexOffset; - -out vec4 color; - -uniform vec2 pixelSize; -uniform mat4 matrix; -uniform float opacity; - -void main() -{ - vec4 pos = matrix * vertex; - gl_Position = pos; - - if (vertexOffset.x != 0.) { - vec4 delta = matrix[0] * vertexOffset.x; - vec2 dir = delta.xy * pos.w - pos.xy * delta.w; - vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); - dir -= ndir * delta.w * pos.w; - float numerator = dot(dir, ndir * pos.w * pos.w); - float scale = 0.0; - if (numerator < 0.0) - scale = 1.0; - else - scale = min(1.0, numerator / dot(dir, dir)); - gl_Position += scale * delta; - } - - if (vertexOffset.y != 0.) { - vec4 delta = matrix[1] * vertexOffset.y; - vec2 dir = delta.xy * pos.w - pos.xy * delta.w; - vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); - dir -= ndir * delta.w * pos.w; - float numerator = dot(dir, ndir * pos.w * pos.w); - float scale = 0.0; - if (numerator < 0.0) - scale = 1.0; - else - scale = min(1.0, numerator / dot(dir, dir)); - gl_Position += scale * delta; - } - - color = vertexColor * opacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothtexture.frag b/src/quick/scenegraph/shaders/smoothtexture.frag deleted file mode 100644 index e4f6359f3d..0000000000 --- a/src/quick/scenegraph/shaders/smoothtexture.frag +++ /dev/null @@ -1,9 +0,0 @@ -uniform sampler2D qt_Texture; - -varying highp vec2 texCoord; -varying lowp float vertexOpacity; - -void main() -{ - gl_FragColor = texture2D(qt_Texture, texCoord) * vertexOpacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothtexture.vert b/src/quick/scenegraph/shaders/smoothtexture.vert deleted file mode 100644 index 900fbc6a72..0000000000 --- a/src/quick/scenegraph/shaders/smoothtexture.vert +++ /dev/null @@ -1,55 +0,0 @@ -uniform highp vec2 pixelSize; -uniform highp mat4 qt_Matrix; -uniform lowp float opacity; - -attribute highp vec4 vertex; -attribute highp vec2 multiTexCoord; -attribute highp vec2 vertexOffset; -attribute highp vec2 texCoordOffset; - -varying highp vec2 texCoord; -varying lowp float vertexOpacity; - -void main() -{ - highp vec4 pos = qt_Matrix * vertex; - gl_Position = pos; - texCoord = multiTexCoord; - - if (vertexOffset.x != 0.) { - highp vec4 delta = qt_Matrix[0] * vertexOffset.x; - highp vec2 dir = delta.xy * pos.w - pos.xy * delta.w; - highp vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); - dir -= ndir * delta.w * pos.w; - highp float numerator = dot(dir, ndir * pos.w * pos.w); - highp float scale = 0.0; - if (numerator < 0.0) - scale = 1.0; - else - scale = min(1.0, numerator / dot(dir, dir)); - gl_Position += scale * delta; - texCoord.x += scale * texCoordOffset.x; - } - - if (vertexOffset.y != 0.) { - highp vec4 delta = qt_Matrix[1] * vertexOffset.y; - highp vec2 dir = delta.xy * pos.w - pos.xy * delta.w; - highp vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); - dir -= ndir * delta.w * pos.w; - highp float numerator = dot(dir, ndir * pos.w * pos.w); - highp float scale = 0.0; - if (numerator < 0.0) - scale = 1.0; - else - scale = min(1.0, numerator / dot(dir, dir)); - gl_Position += scale * delta; - texCoord.y += scale * texCoordOffset.y; - } - - bool onEdge = any(notEqual(vertexOffset, vec2(0.))); - bool outerEdge = all(equal(texCoordOffset, vec2(0.))); - if (onEdge && outerEdge) - vertexOpacity = 0.; - else - vertexOpacity = opacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothtexture_core.frag b/src/quick/scenegraph/shaders/smoothtexture_core.frag deleted file mode 100644 index 8a9aefd4c8..0000000000 --- a/src/quick/scenegraph/shaders/smoothtexture_core.frag +++ /dev/null @@ -1,13 +0,0 @@ -#version 150 core - -in vec2 texCoord; -in float vertexOpacity; - -out vec4 fragColor; - -uniform sampler2D qt_Texture; - -void main() -{ - fragColor = texture(qt_Texture, texCoord) * vertexOpacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/smoothtexture_core.vert b/src/quick/scenegraph/shaders/smoothtexture_core.vert deleted file mode 100644 index 6821398e57..0000000000 --- a/src/quick/scenegraph/shaders/smoothtexture_core.vert +++ /dev/null @@ -1,57 +0,0 @@ -#version 150 core - -in vec4 vertex; -in vec2 multiTexCoord; -in vec2 vertexOffset; -in vec2 texCoordOffset; - -out vec2 texCoord; -out float vertexOpacity; - -uniform vec2 pixelSize; -uniform mat4 qt_Matrix; -uniform float opacity; - -void main() -{ - vec4 pos = qt_Matrix * vertex; - gl_Position = pos; - texCoord = multiTexCoord; - - if (vertexOffset.x != 0.) { - vec4 delta = qt_Matrix[0] * vertexOffset.x; - vec2 dir = delta.xy * pos.w - pos.xy * delta.w; - vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); - dir -= ndir * delta.w * pos.w; - float numerator = dot(dir, ndir * pos.w * pos.w); - float scale = 0.0; - if (numerator < 0.0) - scale = 1.0; - else - scale = min(1.0, numerator / dot(dir, dir)); - gl_Position += scale * delta; - texCoord.x += scale * texCoordOffset.x; - } - - if (vertexOffset.y != 0.) { - vec4 delta = qt_Matrix[1] * vertexOffset.y; - vec2 dir = delta.xy * pos.w - pos.xy * delta.w; - vec2 ndir = .5 * pixelSize * normalize(dir / pixelSize); - dir -= ndir * delta.w * pos.w; - float numerator = dot(dir, ndir * pos.w * pos.w); - float scale = 0.0; - if (numerator < 0.0) - scale = 1.0; - else - scale = min(1.0, numerator / dot(dir, dir)); - gl_Position += scale * delta; - texCoord.y += scale * texCoordOffset.y; - } - - bool onEdge = any(notEqual(vertexOffset, vec2(0.))); - bool outerEdge = all(equal(texCoordOffset, vec2(0.))); - if (onEdge && outerEdge) - vertexOpacity = 0.; - else - vertexOpacity = opacity; -} diff --git a/src/quick/scenegraph/shaders/sprite.frag b/src/quick/scenegraph/shaders/sprite.frag deleted file mode 100644 index e1fcb0f006..0000000000 --- a/src/quick/scenegraph/shaders/sprite.frag +++ /dev/null @@ -1,12 +0,0 @@ -uniform sampler2D _qt_texture; -uniform lowp float qt_Opacity; - -varying highp vec4 fTexS; -varying lowp float progress; - -void main() -{ - gl_FragColor = mix(texture2D(_qt_texture, fTexS.xy), - texture2D(_qt_texture, fTexS.zw), - progress) * qt_Opacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/sprite.vert b/src/quick/scenegraph/shaders/sprite.vert deleted file mode 100644 index fc826f60b4..0000000000 --- a/src/quick/scenegraph/shaders/sprite.vert +++ /dev/null @@ -1,23 +0,0 @@ -attribute highp vec2 vPos; -attribute highp vec2 vTex; - -uniform highp vec3 animData;// w,h(premultiplied of anim), interpolation progress -uniform highp vec4 animPos;//x,y, x,y (two frames for interpolation) - -uniform highp mat4 qt_Matrix; - -varying highp vec4 fTexS; -varying lowp float progress; - -void main() -{ - progress = animData.z; - - // Calculate frame location in texture - fTexS.xy = animPos.xy + vTex.xy * animData.xy; - - // Next frame is also passed, for interpolation - fTexS.zw = animPos.zw + vTex.xy * animData.xy; - - gl_Position = qt_Matrix * vec4(vPos.x, vPos.y, 0, 1); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/sprite_core.frag b/src/quick/scenegraph/shaders/sprite_core.frag deleted file mode 100644 index c1087a8754..0000000000 --- a/src/quick/scenegraph/shaders/sprite_core.frag +++ /dev/null @@ -1,16 +0,0 @@ -#version 150 core - -in vec4 fTexS; -in float progress; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform float qt_Opacity; - -void main() -{ - fragColor = mix(texture(_qt_texture, fTexS.xy), - texture(_qt_texture, fTexS.zw), - progress) * qt_Opacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/sprite_core.vert b/src/quick/scenegraph/shaders/sprite_core.vert deleted file mode 100644 index 5027bf03fc..0000000000 --- a/src/quick/scenegraph/shaders/sprite_core.vert +++ /dev/null @@ -1,24 +0,0 @@ -#version 150 core - -in vec2 vPos; -in vec2 vTex; - -out vec4 fTexS; -out float progress; - -uniform vec3 animData; // w,h(premultiplied of anim), interpolation progress -uniform vec4 animPos; // x,y, x,y (two frames for interpolation) -uniform mat4 qt_Matrix; - -void main() -{ - progress = animData.z; - - // Calculate frame location in texture - fTexS.xy = animPos.xy + vTex.xy * animData.xy; - - // Next frame is also passed, for interpolation - fTexS.zw = animPos.zw + vTex.xy * animData.xy; - - gl_Position = qt_Matrix * vec4(vPos.x, vPos.y, 0, 1); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/styledtext.frag b/src/quick/scenegraph/shaders/styledtext.frag deleted file mode 100644 index 662dbef2fc..0000000000 --- a/src/quick/scenegraph/shaders/styledtext.frag +++ /dev/null @@ -1,14 +0,0 @@ -varying highp vec2 sampleCoord; -varying highp vec2 shiftedSampleCoord; - -uniform sampler2D _qt_texture; -uniform lowp vec4 color; -uniform lowp vec4 styleColor; - -void main() -{ - lowp float glyph = texture2D(_qt_texture, sampleCoord).a; - lowp float style = clamp(texture2D(_qt_texture, shiftedSampleCoord).a - glyph, - 0.0, 1.0); - gl_FragColor = style * styleColor + glyph * color; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/styledtext.vert b/src/quick/scenegraph/shaders/styledtext.vert deleted file mode 100644 index 29c9902609..0000000000 --- a/src/quick/scenegraph/shaders/styledtext.vert +++ /dev/null @@ -1,18 +0,0 @@ -uniform highp mat4 matrix; -uniform highp vec2 textureScale; -uniform highp vec2 shift; -uniform highp float dpr; - -attribute highp vec4 vCoord; -attribute highp vec2 tCoord; - -varying highp vec2 sampleCoord; -varying highp vec2 shiftedSampleCoord; - -void main() -{ - sampleCoord = tCoord * textureScale; - shiftedSampleCoord = (tCoord - shift) * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); -} diff --git a/src/quick/scenegraph/shaders/styledtext_core.frag b/src/quick/scenegraph/shaders/styledtext_core.frag deleted file mode 100644 index 5480e95a42..0000000000 --- a/src/quick/scenegraph/shaders/styledtext_core.frag +++ /dev/null @@ -1,18 +0,0 @@ -#version 150 core - -in vec2 sampleCoord; -in vec2 shiftedSampleCoord; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform vec4 color; -uniform vec4 styleColor; - -void main() -{ - float glyph = texture(_qt_texture, sampleCoord).r; - float style = clamp(texture(_qt_texture, shiftedSampleCoord).r - glyph, - 0.0, 1.0); - fragColor = style * styleColor + glyph * color; -} diff --git a/src/quick/scenegraph/shaders/styledtext_core.vert b/src/quick/scenegraph/shaders/styledtext_core.vert deleted file mode 100644 index 04a0e88da8..0000000000 --- a/src/quick/scenegraph/shaders/styledtext_core.vert +++ /dev/null @@ -1,20 +0,0 @@ -#version 150 core - -in vec4 vCoord; -in vec2 tCoord; - -out vec2 sampleCoord; -out vec2 shiftedSampleCoord; - -uniform mat4 matrix; -uniform vec2 textureScale; -uniform vec2 shift; -uniform float dpr; - -void main() -{ - sampleCoord = tCoord * textureScale; - shiftedSampleCoord = (tCoord - shift) * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); -} diff --git a/src/quick/scenegraph/shaders/textmask.frag b/src/quick/scenegraph/shaders/textmask.frag deleted file mode 100644 index 7715688ecc..0000000000 --- a/src/quick/scenegraph/shaders/textmask.frag +++ /dev/null @@ -1,10 +0,0 @@ -varying highp vec2 sampleCoord; - -uniform sampler2D _qt_texture; -uniform lowp vec4 color; - -void main() -{ - lowp vec4 glyph = texture2D(_qt_texture, sampleCoord); - gl_FragColor = vec4(glyph.rgb * color.a, glyph.a); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/textmask.vert b/src/quick/scenegraph/shaders/textmask.vert deleted file mode 100644 index 1692159d2c..0000000000 --- a/src/quick/scenegraph/shaders/textmask.vert +++ /dev/null @@ -1,15 +0,0 @@ -uniform highp mat4 matrix; -uniform highp vec2 textureScale; -uniform highp float dpr; - -attribute highp vec4 vCoord; -attribute highp vec2 tCoord; - -varying highp vec2 sampleCoord; - -void main() -{ - sampleCoord = tCoord * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); -} diff --git a/src/quick/scenegraph/shaders/textmask_core.frag b/src/quick/scenegraph/shaders/textmask_core.frag deleted file mode 100644 index 17dda53c97..0000000000 --- a/src/quick/scenegraph/shaders/textmask_core.frag +++ /dev/null @@ -1,14 +0,0 @@ -#version 150 core - -in vec2 sampleCoord; - -out vec4 fragColor; - -uniform sampler2D _qt_texture; -uniform vec4 color; - -void main() -{ - vec4 glyph = texture(_qt_texture, sampleCoord); - fragColor = vec4(glyph.rgb * color.a, glyph.a); -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/textmask_core.vert b/src/quick/scenegraph/shaders/textmask_core.vert deleted file mode 100644 index b0efc1e731..0000000000 --- a/src/quick/scenegraph/shaders/textmask_core.vert +++ /dev/null @@ -1,17 +0,0 @@ -#version 150 core - -in vec4 vCoord; -in vec2 tCoord; - -out vec2 sampleCoord; - -uniform mat4 matrix; -uniform vec2 textureScale; -uniform float dpr; - -void main() -{ - sampleCoord = tCoord * textureScale; - vec3 dprSnapPos = floor(vCoord.xyz * dpr + 0.5) / dpr; - gl_Position = matrix * vec4(dprSnapPos, vCoord.w); -} diff --git a/src/quick/scenegraph/shaders/texture.frag b/src/quick/scenegraph/shaders/texture.frag deleted file mode 100644 index 2d97f2e66a..0000000000 --- a/src/quick/scenegraph/shaders/texture.frag +++ /dev/null @@ -1,9 +0,0 @@ -varying highp vec2 qt_TexCoord; - -uniform sampler2D qt_Texture; -uniform lowp float opacity; - -void main() -{ - gl_FragColor = texture2D(qt_Texture, qt_TexCoord) * opacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/texture_core.frag b/src/quick/scenegraph/shaders/texture_core.frag deleted file mode 100644 index d9bdf6a238..0000000000 --- a/src/quick/scenegraph/shaders/texture_core.frag +++ /dev/null @@ -1,13 +0,0 @@ -#version 150 core - -in vec2 qt_TexCoord; - -out vec4 fragColor; - -uniform sampler2D qt_Texture; -uniform float opacity; - -void main() -{ - fragColor = texture(qt_Texture, qt_TexCoord) * opacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/vertexcolor.frag b/src/quick/scenegraph/shaders/vertexcolor.frag deleted file mode 100644 index 71de9dbfc2..0000000000 --- a/src/quick/scenegraph/shaders/vertexcolor.frag +++ /dev/null @@ -1,6 +0,0 @@ -varying lowp vec4 color; - -void main() -{ - gl_FragColor = color; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/vertexcolor.vert b/src/quick/scenegraph/shaders/vertexcolor.vert deleted file mode 100644 index 750d520114..0000000000 --- a/src/quick/scenegraph/shaders/vertexcolor.vert +++ /dev/null @@ -1,13 +0,0 @@ -attribute highp vec4 vertexCoord; -attribute highp vec4 vertexColor; - -uniform highp mat4 matrix; -uniform highp float opacity; - -varying lowp vec4 color; - -void main() -{ - gl_Position = matrix * vertexCoord; - color = vertexColor * opacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/vertexcolor_core.frag b/src/quick/scenegraph/shaders/vertexcolor_core.frag deleted file mode 100644 index 84533c2b40..0000000000 --- a/src/quick/scenegraph/shaders/vertexcolor_core.frag +++ /dev/null @@ -1,10 +0,0 @@ -#version 150 core - -in vec4 color; - -out vec4 fragColor; - -void main() -{ - fragColor = color; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/shaders/vertexcolor_core.vert b/src/quick/scenegraph/shaders/vertexcolor_core.vert deleted file mode 100644 index 219b840913..0000000000 --- a/src/quick/scenegraph/shaders/vertexcolor_core.vert +++ /dev/null @@ -1,15 +0,0 @@ -#version 150 core - -in vec4 vertexCoord; -in vec4 vertexColor; - -out vec4 color; - -uniform mat4 matrix; -uniform float opacity; - -void main() -{ - gl_Position = matrix * vertexCoord; - color = vertexColor * opacity; -}
\ No newline at end of file diff --git a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp index 87941bf31a..ab37a05ce6 100644 --- a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp +++ b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp @@ -39,90 +39,20 @@ #include "qsgflatcolormaterial.h" #include <private/qsgmaterialshader_p.h> -#if QT_CONFIG(opengl) -# include <qopenglshaderprogram.h> -#endif QT_BEGIN_NAMESPACE -class FlatColorMaterialShader : public QSGMaterialShader +class FlatColorMaterialRhiShader : public QSGMaterialShader { public: - FlatColorMaterialShader(); + FlatColorMaterialRhiShader(); - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - char const *const *attributeNames() const override; + bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; static QSGMaterialType type; - -private: - void initialize() override; -#if QT_CONFIG(opengl) - int m_matrix_id; - int m_color_id; -#endif }; -QSGMaterialType FlatColorMaterialShader::type; - -FlatColorMaterialShader::FlatColorMaterialShader() - : QSGMaterialShader(*new QSGMaterialShaderPrivate) -{ -#if QT_CONFIG(opengl) - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/flatcolor.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/flatcolor.frag")); -#endif -} - -void FlatColorMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ -#if QT_CONFIG(opengl) - Q_ASSERT(oldEffect == nullptr || newEffect->type() == oldEffect->type()); - QSGFlatColorMaterial *oldMaterial = static_cast<QSGFlatColorMaterial *>(oldEffect); - QSGFlatColorMaterial *newMaterial = static_cast<QSGFlatColorMaterial *>(newEffect); - - const QColor &c = newMaterial->color(); - - if (oldMaterial == nullptr || c != oldMaterial->color() || state.isOpacityDirty()) { - float opacity = state.opacity() * c.alphaF(); - QVector4D v(c.redF() * opacity, - c.greenF() * opacity, - c.blueF() * opacity, - opacity); - program()->setUniformValue(m_color_id, v); - } - - if (state.isMatrixDirty()) - program()->setUniformValue(m_matrix_id, state.combinedMatrix()); -#else - Q_UNUSED(state) - Q_UNUSED(newEffect) - Q_UNUSED(oldEffect) -#endif -} - -char const *const *FlatColorMaterialShader::attributeNames() const -{ - static char const *const attr[] = { "vCoord", nullptr }; - return attr; -} - -void FlatColorMaterialShader::initialize() -{ -#if QT_CONFIG(opengl) - m_matrix_id = program()->uniformLocation("matrix"); - m_color_id = program()->uniformLocation("color"); -#endif -} - - -class FlatColorMaterialRhiShader : public QSGMaterialRhiShader -{ -public: - FlatColorMaterialRhiShader(); - - bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; -}; +QSGMaterialType FlatColorMaterialRhiShader::type; FlatColorMaterialRhiShader::FlatColorMaterialRhiShader() { @@ -195,7 +125,6 @@ bool FlatColorMaterialRhiShader::updateUniformData(RenderState &state, QSGFlatColorMaterial::QSGFlatColorMaterial() : m_color(QColor(255, 255, 255)) { - setFlag(SupportsRhiShader, true); } /*! @@ -226,7 +155,7 @@ void QSGFlatColorMaterial::setColor(const QColor &color) QSGMaterialType *QSGFlatColorMaterial::type() const { - return &FlatColorMaterialShader::type; + return &FlatColorMaterialRhiShader::type; } @@ -237,10 +166,7 @@ QSGMaterialType *QSGFlatColorMaterial::type() const QSGMaterialShader *QSGFlatColorMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new FlatColorMaterialRhiShader; - else - return new FlatColorMaterialShader; + return new FlatColorMaterialRhiShader; } diff --git a/src/quick/scenegraph/util/qsgtexturematerial.cpp b/src/quick/scenegraph/util/qsgtexturematerial.cpp index 0e70d0638b..38776dbaa6 100644 --- a/src/quick/scenegraph/util/qsgtexturematerial.cpp +++ b/src/quick/scenegraph/util/qsgtexturematerial.cpp @@ -39,10 +39,6 @@ #include "qsgtexturematerial_p.h" #include <private/qsgtexture_p.h> -#if QT_CONFIG(opengl) -# include <qopenglshaderprogram.h> -# include <qopenglfunctions.h> -#endif #include <QtGui/private/qrhi_p.h> QT_BEGIN_NAMESPACE @@ -53,72 +49,6 @@ inline static bool isPowerOfTwo(int x) return x == (x & -x); } -QSGOpaqueTextureMaterialShader::QSGOpaqueTextureMaterialShader() -{ -#if QT_CONFIG(opengl) - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/opaquetexture.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/opaquetexture.frag")); -#endif -} - -char const *const *QSGOpaqueTextureMaterialShader::attributeNames() const -{ - static char const *const attr[] = { "qt_VertexPosition", "qt_VertexTexCoord", nullptr }; - return attr; -} - -void QSGOpaqueTextureMaterialShader::initialize() -{ -#if QT_CONFIG(opengl) - m_matrix_id = program()->uniformLocation("qt_Matrix"); -#endif -} - -void QSGOpaqueTextureMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - Q_ASSERT(oldEffect == nullptr || newEffect->type() == oldEffect->type()); - QSGOpaqueTextureMaterial *tx = static_cast<QSGOpaqueTextureMaterial *>(newEffect); - QSGOpaqueTextureMaterial *oldTx = static_cast<QSGOpaqueTextureMaterial *>(oldEffect); - - QSGTexture *t = tx->texture(); - -#ifndef QT_NO_DEBUG - if (!qsg_safeguard_texture(t)) - return; -#endif - - t->setFiltering(tx->filtering()); - - t->setHorizontalWrapMode(tx->horizontalWrapMode()); - t->setVerticalWrapMode(tx->verticalWrapMode()); -#if QT_CONFIG(opengl) - bool npotSupported = const_cast<QOpenGLContext *>(state.context()) - ->functions()->hasOpenGLFeature(QOpenGLFunctions::NPOTTextureRepeat); - if (!npotSupported) { - QSize size = t->textureSize(); - const bool isNpot = !isPowerOfTwo(size.width()) || !isPowerOfTwo(size.height()); - if (isNpot) { - t->setHorizontalWrapMode(QSGTexture::ClampToEdge); - t->setVerticalWrapMode(QSGTexture::ClampToEdge); - } - } -#else - Q_UNUSED(state) -#endif - t->setMipmapFiltering(tx->mipmapFiltering()); - t->setAnisotropyLevel(tx->anisotropyLevel()); - - if (oldTx == nullptr || oldTx->texture()->textureId() != t->textureId()) - t->bind(); - else - t->updateBindOptions(); -#if QT_CONFIG(opengl) - if (state.isMatrixDirty()) - program()->setUniformValue(m_matrix_id, state.combinedMatrix()); -#endif -} - - QSGOpaqueTextureMaterialRhiShader::QSGOpaqueTextureMaterialRhiShader() { setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/opaquetexture.vert.qsb")); @@ -226,7 +156,6 @@ QSGOpaqueTextureMaterial::QSGOpaqueTextureMaterial() , m_vertical_wrap(QSGTexture::ClampToEdge) , m_anisotropy_level(QSGTexture::AnisotropyNone) { - setFlag(SupportsRhiShader, true); } @@ -244,10 +173,7 @@ QSGMaterialType *QSGOpaqueTextureMaterial::type() const */ QSGMaterialShader *QSGOpaqueTextureMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new QSGOpaqueTextureMaterialRhiShader; - else - return new QSGOpaqueTextureMaterialShader; + return new QSGOpaqueTextureMaterialRhiShader; } @@ -435,36 +361,7 @@ QSGMaterialType *QSGTextureMaterial::type() const QSGMaterialShader *QSGTextureMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new QSGTextureMaterialRhiShader; - else - return new QSGTextureMaterialShader; -} - - -QSGTextureMaterialShader::QSGTextureMaterialShader() -{ -#if QT_CONFIG(opengl) - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/texture.frag")); -#endif -} - -void QSGTextureMaterialShader::updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) -{ - Q_ASSERT(oldEffect == nullptr || newEffect->type() == oldEffect->type()); -#if QT_CONFIG(opengl) - if (state.isOpacityDirty()) - program()->setUniformValue(m_opacity_id, state.opacity()); -#endif - QSGOpaqueTextureMaterialShader::updateState(state, newEffect, oldEffect); -} - -void QSGTextureMaterialShader::initialize() -{ - QSGOpaqueTextureMaterialShader::initialize(); -#if QT_CONFIG(opengl) - m_opacity_id = program()->uniformLocation("opacity"); -#endif + return new QSGTextureMaterialRhiShader; } diff --git a/src/quick/scenegraph/util/qsgtexturematerial_p.h b/src/quick/scenegraph/util/qsgtexturematerial_p.h index d1ef7d1d7f..cdd3e416a6 100644 --- a/src/quick/scenegraph/util/qsgtexturematerial_p.h +++ b/src/quick/scenegraph/util/qsgtexturematerial_p.h @@ -56,21 +56,7 @@ QT_BEGIN_NAMESPACE -class Q_QUICK_PRIVATE_EXPORT QSGOpaqueTextureMaterialShader : public QSGMaterialShader -{ -public: - QSGOpaqueTextureMaterialShader(); - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - char const *const *attributeNames() const override; - -protected: - void initialize() override; - - int m_matrix_id; -}; - -class Q_QUICK_PRIVATE_EXPORT QSGOpaqueTextureMaterialRhiShader : public QSGMaterialRhiShader +class Q_QUICK_PRIVATE_EXPORT QSGOpaqueTextureMaterialRhiShader : public QSGMaterialShader { public: QSGOpaqueTextureMaterialRhiShader(); @@ -79,18 +65,6 @@ public: void updateSampledImage(RenderState &state, int binding, QSGTexture **texture, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; }; -class QSGTextureMaterialShader : public QSGOpaqueTextureMaterialShader -{ -public: - QSGTextureMaterialShader(); - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - void initialize() override; - -protected: - int m_opacity_id; -}; - class QSGTextureMaterialRhiShader : public QSGOpaqueTextureMaterialRhiShader { public: diff --git a/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp b/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp index c27dd7d1f0..9f2836d6aa 100644 --- a/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp +++ b/src/quick/scenegraph/util/qsgvertexcolormaterial.cpp @@ -38,64 +38,10 @@ ****************************************************************************/ #include "qsgvertexcolormaterial.h" -#if QT_CONFIG(opengl) -# include <qopenglshaderprogram.h> -#endif -QT_BEGIN_NAMESPACE - -class QSGVertexColorMaterialShader : public QSGMaterialShader -{ -public: - QSGVertexColorMaterialShader(); - - void updateState(const RenderState &state, QSGMaterial *newEffect, QSGMaterial *oldEffect) override; - char const *const *attributeNames() const override; - -private: - void initialize() override; -#if QT_CONFIG(opengl) - int m_matrix_id; - int m_opacity_id; -#endif -}; - -QSGVertexColorMaterialShader::QSGVertexColorMaterialShader() -{ -#if QT_CONFIG(opengl) - setShaderSourceFile(QOpenGLShader::Vertex, QStringLiteral(":/qt-project.org/scenegraph/shaders/vertexcolor.vert")); - setShaderSourceFile(QOpenGLShader::Fragment, QStringLiteral(":/qt-project.org/scenegraph/shaders/vertexcolor.frag")); -#endif -} - -void QSGVertexColorMaterialShader::updateState(const RenderState &state, QSGMaterial * /*newEffect*/, QSGMaterial *) -{ -#if QT_CONFIG(opengl) - if (state.isOpacityDirty()) - program()->setUniformValue(m_opacity_id, state.opacity()); - - if (state.isMatrixDirty()) - program()->setUniformValue(m_matrix_id, state.combinedMatrix()); -#else - Q_UNUSED(state) -#endif -} - -char const *const *QSGVertexColorMaterialShader::attributeNames() const -{ - static const char *const attr[] = { "vertexCoord", "vertexColor", nullptr }; - return attr; -} - -void QSGVertexColorMaterialShader::initialize() -{ -#if QT_CONFIG(opengl) - m_matrix_id = program()->uniformLocation("matrix"); - m_opacity_id = program()->uniformLocation("opacity"); -#endif -} +QT_BEGIN_NAMESPACE -class QSGVertexColorMaterialRhiShader : public QSGMaterialRhiShader +class QSGVertexColorMaterialRhiShader : public QSGMaterialShader { public: QSGVertexColorMaterialRhiShader(); @@ -168,7 +114,6 @@ bool QSGVertexColorMaterialRhiShader::updateUniformData(RenderState &state, QSGVertexColorMaterial::QSGVertexColorMaterial() { setFlag(Blending, true); - setFlag(SupportsRhiShader, true); } @@ -204,10 +149,7 @@ QSGMaterialType *QSGVertexColorMaterial::type() const QSGMaterialShader *QSGVertexColorMaterial::createShader() const { - if (flags().testFlag(RhiShaderWanted)) - return new QSGVertexColorMaterialRhiShader; - else - return new QSGVertexColorMaterialShader; + return new QSGVertexColorMaterialRhiShader; } QT_END_NAMESPACE |