<table><tr><td style="">fredrik added a comment.<br />Restricted Application edited projects, added Plasma; removed KWin.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D9848" rel="noreferrer">View Revision</a></tr></table><br /><div><div><p>Don't forget to add your name to the license headers.</p></div></div><br /><div><strong>INLINE COMMENTS</strong><div><div style="margin: 6px 0 12px 0;"><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-45215" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.cpp:46</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; "> <span class="n">m_simpleShader</span> <span style="color: #aa2211">=</span> <span class="n">ShaderManager</span><span style="color: #aa2211">::</span><span class="n">instance</span><span class="p">()</span><span style="color: #aa2211">-></span><span class="n">generateShaderFromResources</span><span class="p">(</span><span class="n">ShaderTrait</span><span style="color: #aa2211">::</span><span class="n">MapTexture</span><span class="p">,</span> <span class="n">QString</span><span class="p">(),</span> <span class="n">QStringLiteral</span><span class="p">(</span><span style="color: #766510">"logout-blur.frag"</span><span class="p">));</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">m_simpleTarget</span> <span style="color: #aa2211">=</span> <span style="color: #aa4000">new</span> <span class="n">GLRenderTarget</span><span class="p">(</span><span class="n">GLTexture</span><span class="p">(</span><span class="n">GL_RGBA8</span><span class="p">,</span> <span style="color: #601200">1</span><span class="p">,</span> <span style="color: #601200">1</span><span class="p">));</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">You should add a GLRenderTarget constructor that takes no arguments.<br />
This is working around deficiencies in the API.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-45229" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.cpp:116</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="bright"></span><span class="n"><span class="bright">tex</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">=</span></span><span class="bright"> </span><span class="n"><span class="bright">GLTexture</span></span><span class="bright"></span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span class="n"><span class="bright">GL_RGBA8</span></span><span class="bright"></span><span class="p"><span class="bright">,</span></span><span class="bright"> </span><span class="n"><span class="bright">effects</span></span><span class="bright"></span><span style="color: #aa2211"><span class="bright">-></span></span><span class="bright"></span><span class="n"><span class="bright">virtualScreenSize</span></span><span class="bright"></span><span class="p"><span class="bright">()</span>);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="bright"></span><span class="n"><span class="bright">tex</span></span><span class="bright"></span><span class="p"><span class="bright">.</span></span><span class="bright"></span><span class="n"><span class="bright">setFilter</span></span><span class="bright"></span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span class="n"><span class="bright">GL_LINEAR</span></span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"><span class="bright"> </span><span class="n"><span class="bright">tex</span></span><span class="bright"></span><span class="p"><span class="bright">.</span></span><span class="bright"></span><span class="n"><span class="bright">setWrapMode</span></span><span class="bright"></span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span class="n"><span class="bright">GL_CLAMP_TO_EDGE</span></span><span class="bright"></span><span class="p"><span class="bright">);</span></span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="bright"> </span><span style="color: #aa4000"><span class="bright">return</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">!</span></span><span class="bright"></span><span class="n"><span class="bright">target</span></span><span class="bright"></span><span style="color: #aa2211"><span class="bright">-></span></span><span class="bright"></span><span class="n"><span class="bright">valid</span></span><span class="bright"></span><span class="p"><span class="bright">(</span>);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="bright"> </span><span class="p"><span class="bright">})</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">==</span></span><span class="bright"> </span><span class="n"><span class="bright">m_renderTargets</span></span><span class="bright"></span><span class="p"><span class="bright">.</span></span><span class="bright"></span><span class="n"><span class="bright">cend</span></span><span class="bright"></span><span class="p"><span class="bright">(</span>);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span class="bright"></span><span class="p"><span class="bright">}</span></span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">I suggest doing this check after creating the render targets, and caching the result.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-45224" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.cpp:135</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">deleteFBOs</span><span class="p">();</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);">
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">for</span> <span class="p">(</span><span style="color: #aa4000">int</span> <span class="n">i</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span> <span class="n">i</span> <span style="color: #aa2211"><=</span> <span class="n">m_downSampleIterations</span><span class="p">;</span> <span class="n">i</span><span style="color: #aa2211">++</span><span class="p">)</span> <span class="p">{</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Call reserve() on m_renderTextures and m_renderTargets here.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-45213" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.cpp:137</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">for</span> <span class="p">(</span><span style="color: #aa4000">int</span> <span class="n">i</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span> <span class="n">i</span> <span style="color: #aa2211"><=</span> <span class="n">m_downSampleIterations</span><span class="p">;</span> <span class="n">i</span><span style="color: #aa2211">++</span><span class="p">)</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">m_renderTextures</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">GLTexture</span><span class="p">(</span><span class="n">GL_RGBA8</span><span class="p">,</span> <span class="n">effects</span><span style="color: #aa2211">-></span><span class="n">virtualScreenSize</span><span class="p">()</span> <span style="color: #aa2211">/</span> <span class="n">qPow</span><span class="p">(</span><span style="color: #601200">2</span><span class="p">,</span> <span class="n">i</span><span class="p">)));</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">m_renderTextures</span><span class="p">.</span><span class="n">last</span><span class="p">().</span><span class="n">setFilter</span><span class="p">(</span><span class="n">GL_LINEAR</span><span class="p">);</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">1 << i</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-45214" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.cpp:145</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #74777d">// This last set is used as a temporary helper texture</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">m_renderTextures</span><span class="p">.</span><span class="n">append</span><span class="p">(</span><span class="n">GLTexture</span><span class="p">(</span><span class="n">GL_RGBA8</span><span class="p">,</span> <span class="n">effects</span><span style="color: #aa2211">-></span><span class="n">virtualScreenSize</span><span class="p">()));</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">m_renderTextures</span><span class="p">.</span><span class="n">last</span><span class="p">().</span><span class="n">setFilter</span><span class="p">(</span><span class="n">GL_LINEAR</span><span class="p">);</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Why is this needed?</p>
<p style="padding: 0; margin: 8px;">I'm probably missing something here, but it looks to me as if the effect copies the contents of the framebuffer to the helper texture, then copies the contents of that texture to m_renderTextures[0], after which the contents of helper texture is not used again. Can't copyScreenSampleTexture() copy directly from the framebuffer to m_renderTextures[0]?</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-45216" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.cpp:694</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="bright"></span><span class="n"><span class="bright">t</span>arget</span><span style="color: #aa2211">-></span><span class="n">attachTexture</span><span class="p">(</span><span class="n">blurTexture</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="bright"></span><span class="n"><span class="bright">t</span>arget</span><span style="color: #aa2211">-></span><span class="n">blitFromFramebuffer</span><span class="p">(</span><span class="n">w</span><span style="color: #aa2211">-></span><span class="n">geometry</span><span class="p">(),</span> <span class="n">QRect</span><span class="p">(</span><span class="n">QPoint</span><span class="p">(</span><span style="color: #601200">0</span><span class="p">,</span> <span style="color: #601200">0</span><span class="p">),</span> <span class="n">w</span><span style="color: #aa2211">-></span><span class="n">size</span><span class="p">()));</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="bright"></span><span class="n"><span class="bright">m_simpleT</span>arget</span><span style="color: #aa2211">-></span><span class="n">attachTexture</span><span class="p">(</span><span class="n">blurTexture</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="bright"></span><span class="n"><span class="bright">m_simpleT</span>arget</span><span style="color: #aa2211">-></span><span class="n">blitFromFramebuffer</span><span class="p">(</span><span class="n">w</span><span style="color: #aa2211">-></span><span class="n">geometry</span><span class="p">(),</span> <span class="n">QRect</span><span class="p">(</span><span class="n">QPoint</span><span class="p">(</span><span style="color: #601200">0</span><span class="p">,</span> <span style="color: #601200">0</span><span class="p">),</span> <span class="n">w</span><span style="color: #aa2211">-></span><span class="n">size</span><span class="p">()));</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Detach the texture from the render target before you return from this method - otherwise the FBO continues to hold a reference to the texture, preventing it from being deleted.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-44894" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.cpp:123</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">for</span> <span class="p">(</span><span style="color: #aa4000">int</span> <span class="n">i</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span> <span class="n">i</span> <span style="color: #aa2211"><</span> <span class="n">m_renderTargets</span><span class="p">.</span><span class="n">size</span><span class="p">();</span> <span class="n">i</span><span style="color: #aa2211">++</span><span class="p">)</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">delete</span> <span class="n">m_renderTargets</span><span class="p">[</span><span class="n">i</span><span class="p">];</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">You can use qDeleteAll() here.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-44893" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.cpp:127</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="bright"></span><span class="n"><span class="bright">target</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">=</span></span><span class="bright"> </span><span style="color: #aa4000"><span class="bright">new</span></span><span class="bright"> </span><span class="n"><span class="bright">GLR</span>enderT<span class="bright">arget</span></span><span class="bright"></span><span class="p"><span class="bright">(</span></span><span class="bright"></span><span class="n"><span class="bright">tex</span></span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="bright"> </span><span class="n"><span class="bright">m_r</span>enderT<span class="bright">extures</span></span><span class="bright"></span><span class="p"><span class="bright">[</span></span><span class="bright"></span><span class="n"><span class="bright">i</span></span><span class="bright"></span><span class="p"><span class="bright">].</span></span><span class="bright"></span><span class="n"><span class="bright">discard</span></span><span class="bright"></span><span class="p"><span class="bright">(</span>);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="p">}</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">There is no need to call discard on the textures - just clear the vector.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-44891" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.cpp:374</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">for</span> <span class="p">(</span><span style="color: #aa4000">int</span> <span class="n">i</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span> <span class="n">i</span> <span style="color: #aa2211"><=</span> <span class="n">downSampleIterations</span><span class="p">;</span> <span class="n">i</span><span style="color: #aa2211">++</span><span class="p">)</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">const</span> <span style="color: #aa4000">int</span> <span class="n">divisionRatio</span> <span style="color: #aa2211">=</span> <span class="n">qPow</span><span class="p">(</span><span style="color: #601200">2</span><span class="p">,</span> <span class="n">i</span><span class="p">);</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">1 << i</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-45234" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.cpp:717</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">vbo</span><span style="color: #aa2211">-></span><span class="n">draw</span><span class="p">(</span><span class="n">GL_TRIANGLES</span><span class="p">,</span> <span class="n">blurRectCount</span> <span style="color: #aa2211">*</span> <span class="n">i</span><span class="p">,</span> <span class="n">blurRectCount</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">GLRenderTarget</span><span style="color: #aa2211">::</span><span class="n">popRenderTarget</span><span class="p">();</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="p">}</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">These three lines of code will expand to an unfortunate sequence of GL calls:</p>
<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">// Iteration N
glGetIntegerv(GL_VIEWPORT, ...);
glBindFramebuffer(GL_FRAMEBUFFER, ...);
glViewport(...);
glDrawArrays(...);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(...);
// Iteration N+1
glGetIntegerv(GL_VIEWPORT, ..);
glBindFramebuffer(GL_FRAMEBUFFER, ...);
glViewport(...);
glDrawArrays(...);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(...);</pre></div>
<p style="padding: 0; margin: 8px;">Note the redundant calls to glViewport() and glBindFramebuffer(). The worst offender here is glGetIntegerv() however, because it forces serialization of the internal driver threads.</p>
<p style="padding: 0; margin: 8px;">Ideally the call sequence should look like this:</p>
<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">// Iteration N
glBindFramebuffer(GL_FRAMEBUFFER, ...);
glViewport(...);
glDrawArrays(...);
// Iteration N+1
glBindFramebuffer(GL_FRAMEBUFFER, ...);
glViewport(...);
glDrawArrays(...);</pre></div>
<p style="padding: 0; margin: 8px;">This can be fixed in a followup patch though.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-45212" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blur.h:41</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span style="color: #aa4000">static</span> <span style="color: #aa4000">const</span> <span style="color: #aa4000">int</span> <span class="n">borderSize</span> <span style="color: #aa2211">=</span> <span style="color: #601200">5</span><span class="p">;</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">This number could use an explanation.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-45218" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blurshader.cpp:241</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="bright"></span><span class="n"><span class="bright">stream</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright"><<</span></span> <span style="color: #766510">"uniform <span class="bright">mat4 textureMatrix</span>;</span><span style="color: #bb6622">\n</span><span style="color: #766510">"<span class="bright"></span></span><span class="bright"></span><span class="p"><span class="bright">;</span></span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="bright"></span><span class="n"><span class="bright">stream</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright"><<</span></span> <span style="color: #766510">"uniform vec2 <span class="bright">pixel</span>Size;<span class="bright"></span></span><span class="bright"></span><span style="color: #bb6622"><span class="bright">\n</span>\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span class="n">attribute</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">" vec4 vertex;</span><span style="color: #bb6622">\n\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span class="n">varying_out</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">" vec4 samplePos["</span> <span style="color: #aa2211"><<</span> <span class="n">std</span><span style="color: #aa2211">::</span><span class="n">ceil</span><span class="p">(</span><span class="n">size</span> <span style="color: #aa2211">/</span> <span style="color: #601200">2.0</span><span class="p">)</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">"];</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">"</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">"void main(void)</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">"{</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">" vec4 center = vec4(textureMatrix * vertex).stst;</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">" vec4 ps = pixelSize.stst;</span><span style="color: #bb6622">\n\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span style="color: #aa4000">for</span> <span class="p">(</span><span style="color: #aa4000">int</span> <span class="n">i</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span> <span class="n">i</span> <span style="color: #aa2211"><</span> <span class="n">offsets</span><span class="p">.</span><span class="n">size</span><span class="p">();</span> <span class="n">i</span><span style="color: #aa2211">++</span><span class="p">)</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">" samplePos["</span> <span style="color: #aa2211"><<</span> <span class="n">i</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">"] = center + ps * vec4("</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span style="color: #aa2211"><<</span> <span class="n">offsets</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">x</span><span class="p">()</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">", "</span> <span style="color: #aa2211"><<</span> <span class="n">offsets</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">y</span><span class="p">()</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">", "</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span style="color: #aa2211"><<</span> <span class="n">offsets</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">z</span><span class="p">()</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">", "</span> <span style="color: #aa2211"><<</span> <span class="n">offsets</span><span class="p">[</span><span class="n">i</span><span class="p">].</span><span class="n">w</span><span class="p">()</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">");</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="p">}</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">"</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">" gl_Position = modelViewProjectionMatrix * vertex;</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span> <span style="color: #aa2211"><<</span> <span style="color: #766510">"}</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">stream</span><span class="p">.</span><span class="n">flush</span><span class="p">();</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="bright"> </span> <span style="color: #766510">"uniform <span class="bright">float offset</span>;</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="bright"> </span> <span style="color: #766510">"uniform vec2 <span class="bright">texture</span>Size;</span><span style="color: #bb6622">\n</span><span style="color: #766510">"</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; ">
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span style="color: #74777d">// Fragment shader</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span style="color: #74777d">// ===================================================================</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">QTextStream</span> <span style="color: #004012">stream2</span><span class="p">(</span><span style="color: #aa2211">&</span><span class="n">fragmentSource</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);">
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span style="color: #aa4000">if</span> <span class="p">(</span><span class="n">gles</span><span class="p">)</span> <span class="p">{</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">textureSize is also the name of a built-in function in GLSL, so I suggest changing the name to targetSize, renderTargetSize, framebufferSize or something similar. That also makes it clear that it is not the size of the texture being sampled.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-45219" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blurshader.h:95</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="bright"></span><span style="color: #aa4000"><span class="bright">int</span></span><span class="bright"> </span><span class="n"><span class="bright">mvpMatrixLocation</span></span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="bright"></span><span style="color: #aa4000"><span class="bright">int</span></span><span class="bright"> </span><span class="n"><span class="bright">textureMatrixLocation</span></span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"><span class="bright"> </span><span style="color: #aa4000"><span class="bright">int</span></span><span class="bright"> </span><span class="n"><span class="bright">pixelSizeLocation</span></span><span class="bright"></span><span class="p"><span class="bright">;</span></span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="bright"></span><span class="n"><span class="bright">GLShader</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">*</span></span><span class="bright"></span><span class="n"><span class="bright">m_shaderUpsample</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">=</span></span><span class="bright"> </span><span class="n"><span class="bright">nullptr</span></span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="bright"></span><span class="n"><span class="bright">GLShader</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">*</span></span><span class="bright"></span><span class="n"><span class="bright">m_shaderCopysample</span></span><span class="bright"> </span><span style="color: #aa2211"><span class="bright">=</span></span><span class="bright"> </span><span class="n"><span class="bright">nullptr</span></span><span class="p">;</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">I think you could simplify the code quite a bit by having an array of</p>
<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="text" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);">struct {
GLShader *shader;
int mvpMatrixLocation;
...
};</pre></div>
<p style="padding: 0; margin: 8px;">and use m_activeSampleType as an index into that array.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-44897" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blurshader.h:47</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">virtual</span> <span style="color: #aa4000">void</span> <span style="color: #004012">setOffset</span><span class="p">(</span><span style="color: #aa4000">float</span> <span class="n">offset</span><span class="p">)</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">virtual</span> <span style="color: #aa4000">void</span> <span style="color: #004012">setTextureSize</span><span class="p">(</span><span class="n">QSize</span> <span class="n">textureSize</span><span class="p">)</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">virtual</span> <span style="color: #aa4000">void</span> <span style="color: #004012">setBlurRect</span><span class="p">(</span><span class="n">QRect</span> <span class="n">blurRect</span><span class="p">,</span> <span class="n">QSize</span> <span class="n">screenSize</span><span class="p">)</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">I suggest changing the name to setTargetSize() to make it clear that the size is the size of the render target, and not the size of the texture being sampled.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-44896" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blurshader.h:50</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(251, 175, 175, .7);"> <span class="n">virtual</span> <span style="color: #aa4000">void</span> <span style="color: #004012">bind</span><span class="p">()</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">virtual</span> <span style="color: #aa4000">void</span> <span style="color: #004012">bind</span><span class="p">(<span class="bright"></span></span><span class="bright"></span><span style="color: #aa4000"><span class="bright">int</span></span><span class="bright"> </span><span class="n"><span class="bright">sampleType</span></span><span class="p">)</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span>
</div><div style="padding: 0 8px; margin: 0 4px; "> <span class="n">virtual</span> <span style="color: #aa4000">void</span> <span style="color: #004012">unbind</span><span class="p">()</span> <span style="color: #aa2211">=</span> <span style="color: #601200">0</span><span class="p">;</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">sampleTypeEnum sampleType</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-44895" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blurshader.h:53</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">enum</span> <span class="n">sampleTypeEnum</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">downSampleType</span><span class="p">,</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">The first letter in enums should be capitalized. I think SampleType would also be a better name.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D9848#inline-44898" rel="noreferrer">View Inline</a><span style="color: #4b4d51; font-weight: bold;">blurshader.h:84</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; "> <span style="color: #aa4000">void</span> <span style="color: #004012">setModelViewProjectionMatrix</span><span class="p">(</span><span style="color: #aa4000">const</span> <span class="n">QMatrix4x4</span> <span style="color: #aa2211">&</span><span class="n">matrix</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">void</span> <span style="color: #004012">setOffset</span><span class="p">(</span><span style="color: #aa4000">float</span> <span class="n">offset</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">void</span> <span style="color: #004012">setTextureSize</span><span class="p">(</span><span class="n">QSize</span> <span class="n">textureSize</span><span class="p">);</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">override final</p>
<p style="padding: 0; margin: 8px;">This goes for all reimplemented virtual functions.</p></div></div></div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R108 KWin</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D9848" rel="noreferrer">https://phabricator.kde.org/D9848</a></div></div><br /><div><strong>To: </strong>anemeth, Plasma, KWin<br /><strong>Cc: </strong>luebking, broulik, romangg, zzag, anthonyfieroni, mart, davidedmundson, fredrik, ngraham, plasma-devel, kwin, KWin, ZrenBot, progwolff, lesliezhai, ali-mohamed, jensreuterberg, abetts, sebas, apol<br /></div>