Qt6 supported
This commit is contained in:
parent
a90f1c4439
commit
0392f8ea36
|
@ -6,10 +6,7 @@ add_subdirectory(invoker)
|
|||
add_subdirectory(shadows)
|
||||
add_subdirectory(shapes)
|
||||
add_subdirectory(charts)
|
||||
|
||||
if (QT_VERSION_MAJOR VERSION_LESS 6)
|
||||
add_subdirectory(parrots)
|
||||
endif()
|
||||
add_subdirectory(parrots)
|
||||
|
||||
if (BUILD_INPUTCONTEXT)
|
||||
add_subdirectory(inputpanel)
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
############################################################################
|
||||
|
||||
set(SOURCES main.cpp)
|
||||
qt_add_resources(SOURCES images.qrc)
|
||||
qt_add_resources(SOURCES images.qrc shaders.qrc)
|
||||
|
||||
qsk_add_example(parrots ${SOURCES})
|
||||
|
|
|
@ -23,31 +23,13 @@
|
|||
#include <private/qquickshadereffect_p.h>
|
||||
#include <private/qquickshadereffectsource_p.h>
|
||||
|
||||
static const char* vertexShader = R"(
|
||||
uniform highp mat4 qt_Matrix;
|
||||
attribute highp vec4 qt_Vertex;
|
||||
attribute highp vec2 qt_MultiTexCoord0;
|
||||
varying highp vec2 coord;
|
||||
void main() {
|
||||
coord = qt_MultiTexCoord0;
|
||||
gl_Position = qt_Matrix * qt_Vertex;
|
||||
})";
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
||||
#include <QFile>
|
||||
#else
|
||||
#include <QUrl>
|
||||
#endif
|
||||
|
||||
static const char* fragmentShader = R"(
|
||||
varying highp vec2 coord;
|
||||
uniform sampler2D source;
|
||||
uniform lowp float qt_Opacity;
|
||||
|
||||
void main() {
|
||||
vec2 delta = vec2(0.01, 0.01);
|
||||
gl_FragColor =(0.0538 * texture2D(source, coord - 3.182 * delta)
|
||||
+ 0.3229 * texture2D(source, coord - 1.364 * delta)
|
||||
+ 0.2466 * texture2D(source, coord)
|
||||
+ 0.3229 * texture2D(source, coord + 1.364 * delta)
|
||||
+ 0.0538 * texture2D(source, coord + 3.182 * delta)) * qt_Opacity;
|
||||
})";
|
||||
|
||||
class ButtonBox: public QskLinearBox
|
||||
class ButtonBox : public QskLinearBox
|
||||
{
|
||||
public:
|
||||
ButtonBox( QQuickItem* parent = nullptr )
|
||||
|
@ -67,8 +49,13 @@ class ShaderEffect : public QQuickShaderEffect
|
|||
ShaderEffect( QQuickItem* parent = nullptr )
|
||||
: QQuickShaderEffect( parent )
|
||||
{
|
||||
setVertexShader( ::vertexShader );
|
||||
setFragmentShader( ::fragmentShader );
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
||||
setVertexShader( loadShader( ":/shaders/blur.vert" ) );
|
||||
setFragmentShader( loadShader( ":/shaders/blur.frag" ) );
|
||||
#else
|
||||
setVertexShader( QUrl( "qrc:/shaders/blur.vert.qsb" ) );
|
||||
setFragmentShader( QUrl( "qrc:/shaders/blur.frag.qsb" ) );
|
||||
#endif
|
||||
|
||||
m_source = new QQuickShaderEffectSource( this );
|
||||
m_source->setLive( true );
|
||||
|
@ -80,17 +67,37 @@ class ShaderEffect : public QQuickShaderEffect
|
|||
QQuickItem* sourceItem() const { return m_source->sourceItem(); }
|
||||
|
||||
protected:
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
||||
void geometryChanged( const QRectF& newRect, const QRectF& oldRect ) override
|
||||
{
|
||||
Inherited::geometryChanged( newRect, oldRect );
|
||||
updateSourceRect( newRect );
|
||||
}
|
||||
#else
|
||||
void geometryChange( const QRectF& newRect, const QRectF& oldRect ) override
|
||||
{
|
||||
Inherited::geometryChange( newRect, oldRect );
|
||||
updateSourceRect( newRect );
|
||||
}
|
||||
#endif
|
||||
|
||||
auto sourceRect = newRect;
|
||||
sourceRect = m_source->sourceItem()->mapRectFromItem( this, sourceRect );
|
||||
|
||||
private:
|
||||
void updateSourceRect( const QRectF& rect )
|
||||
{
|
||||
const auto sourceRect = m_source->sourceItem()->mapRectFromItem( this, rect );
|
||||
m_source->setSourceRect( sourceRect );
|
||||
}
|
||||
|
||||
private:
|
||||
#if QT_VERSION < QT_VERSION_CHECK( 6, 0, 0 )
|
||||
QByteArray loadShader( const char* path ) const
|
||||
{
|
||||
QFile f( path );
|
||||
f.open( QFile::ReadOnly );
|
||||
|
||||
return f.readAll();
|
||||
}
|
||||
#endif
|
||||
|
||||
void setSource( QQuickShaderEffectSource* source )
|
||||
{
|
||||
setProperty( "source", QVariant::fromValue( source ) );
|
||||
|
@ -138,10 +145,10 @@ class BackgroundItem : public QskControl
|
|||
}
|
||||
|
||||
void timerEvent( QTimerEvent* ) override
|
||||
{
|
||||
{
|
||||
static int counter = 0;
|
||||
|
||||
const auto angle = counter++ / 50.0 * M_PI * 2.0 ;
|
||||
const auto angle = counter++ / 50.0 * M_PI * 2.0;
|
||||
|
||||
const auto x = std::cos( angle );
|
||||
const auto y = std::sin( angle );
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE RCC>
|
||||
<RCC version="1.0">
|
||||
<qresource>
|
||||
<file>shaders/blur.vert</file>
|
||||
<file>shaders/blur.frag</file>
|
||||
|
||||
<file>shaders/blur.vert.qsb</file>
|
||||
<file>shaders/blur.frag.qsb</file>
|
||||
</qresource>
|
||||
</RCC>
|
|
@ -0,0 +1,24 @@
|
|||
#version 440
|
||||
|
||||
layout(location = 0) in vec2 qt_TexCoord0;
|
||||
layout(location = 0) out vec4 fragColor;
|
||||
|
||||
layout(binding = 1) uniform sampler2D source;
|
||||
|
||||
layout(std140, binding = 0) uniform buf
|
||||
{
|
||||
mat4 qt_Matrix;
|
||||
float qt_Opacity;
|
||||
|
||||
} ubuf;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 delta = vec2(0.01, 0.01);
|
||||
|
||||
fragColor =(0.0538 * texture(source, qt_TexCoord0 - 3.182 * delta)
|
||||
+ 0.3229 * texture(source, qt_TexCoord0 - 1.364 * delta)
|
||||
+ 0.2466 * texture(source, qt_TexCoord0)
|
||||
+ 0.3229 * texture(source, qt_TexCoord0 + 1.364 * delta)
|
||||
+ 0.0538 * texture(source, qt_TexCoord0 + 3.182 * delta)) * ubuf.qt_Opacity;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#version 440
|
||||
|
||||
layout(location = 0) in vec4 qt_Vertex;
|
||||
layout(location = 1) in vec2 qt_MultiTexCoord0;
|
||||
|
||||
layout(location = 0) out vec2 qt_TexCoord0;
|
||||
|
||||
layout(std140, binding = 0) uniform buf
|
||||
{
|
||||
mat4 qt_Matrix;
|
||||
float qt_Opacity;
|
||||
} ubuf;
|
||||
|
||||
out gl_PerVertex { vec4 gl_Position; };
|
||||
|
||||
void main()
|
||||
{
|
||||
qt_TexCoord0 = qt_MultiTexCoord0;
|
||||
gl_Position = ubuf.qt_Matrix * qt_Vertex;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
varying highp vec2 qt_TexCoord0;
|
||||
|
||||
uniform sampler2D source;
|
||||
uniform lowp float qt_Opacity;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 delta = vec2(0.01, 0.01);
|
||||
|
||||
gl_FragColor =(0.0538 * texture2D(source, qt_TexCoord0 - 3.182 * delta)
|
||||
+ 0.3229 * texture2D(source, qt_TexCoord0 - 1.364 * delta)
|
||||
+ 0.2466 * texture2D(source, qt_TexCoord0)
|
||||
+ 0.3229 * texture2D(source, qt_TexCoord0 + 1.364 * delta)
|
||||
+ 0.0538 * texture2D(source, qt_TexCoord0 + 3.182 * delta)) * qt_Opacity;
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,12 @@
|
|||
uniform highp mat4 qt_Matrix;
|
||||
|
||||
attribute highp vec4 qt_Vertex;
|
||||
attribute highp vec2 qt_MultiTexCoord0;
|
||||
|
||||
varying highp vec2 qt_TexCoord0;
|
||||
|
||||
void main()
|
||||
{
|
||||
qt_TexCoord0 = qt_MultiTexCoord0;
|
||||
gl_Position = qt_Matrix * qt_Vertex;
|
||||
}
|
Binary file not shown.
|
@ -0,0 +1,9 @@
|
|||
#! /bin/sh
|
||||
|
||||
function qsbcompile {
|
||||
qsbfile=`echo $1 | sed 's/-vulkan//'`
|
||||
qsb --glsl 100es,120,150 --hlsl 50 --msl 12 -b -o ${qsbfile}.qsb $1
|
||||
}
|
||||
|
||||
qsbcompile blur-vulkan.vert
|
||||
qsbcompile blur-vulkan.frag
|
Loading…
Reference in New Issue