From 280fcf7acef20eb56df94a25aff6c4d54da5ad13 Mon Sep 17 00:00:00 2001 From: m0dB Date: Fri, 23 Aug 2024 20:46:13 +0200 Subject: [PATCH 01/64] using rendergraph for allshader waveforms, with rendergraph::GeometryNode for end of track --- CMakeLists.txt | 5 + res/mixxx.qrc | 4 + res/shaders/rendergraph/CMakeLists.txt | 25 ++++ res/shaders/rendergraph/README | 9 ++ res/shaders/rendergraph/endoftrack.frag | 17 +++ res/shaders/rendergraph/endoftrack.frag.gl | 19 +++ res/shaders/rendergraph/endoftrack.vert | 14 +++ res/shaders/rendergraph/endoftrack.vert.gl | 12 ++ .../rendergraph/generate_shaders_gl.pl | 68 +++++++++++ .../rendergraph/generated_shaders_gl.cmake | 6 + res/shaders/rendergraph/texture.frag | 9 ++ res/shaders/rendergraph/texture.frag.gl | 11 ++ res/shaders/rendergraph/texture.vert | 15 +++ res/shaders/rendergraph/texture.vert.gl | 19 +++ res/shaders/rendergraph/texture.vert.qsb | Bin 0 -> 607 bytes src/rendergraph/CMakeLists.txt | 2 + src/rendergraph/README | 29 +++++ src/rendergraph/attribute.h | 31 +++++ src/rendergraph/attributeset.cpp | 36 ++++++ src/rendergraph/attributeset.h | 36 ++++++ src/rendergraph/context.cpp | 15 +++ src/rendergraph/context.h | 18 +++ src/rendergraph/examples/CMakeLists.txt | 12 ++ src/rendergraph/examples/README | 6 + .../examples/common/CMakeLists.txt | 16 +++ .../examples/common/endoftrackmaterial.cpp | 38 ++++++ .../examples/common/endoftrackmaterial.h | 21 ++++ .../examples/common/examplenodes.cpp | 60 ++++++++++ .../examples/common/examplenodes.h | 36 ++++++ .../examples/common/texturematerial.cpp | 38 ++++++ .../examples/common/texturematerial.h | 34 ++++++ .../examples/gl_example/CMakeLists.txt | 39 ++++++ .../examples/gl_example/images/test.png | Bin 0 -> 12849 bytes src/rendergraph/examples/gl_example/main.cpp | 12 ++ .../examples/gl_example/window.cpp | 43 +++++++ src/rendergraph/examples/gl_example/window.h | 21 ++++ .../examples/sg_example/CMakeLists.txt | 35 ++++++ .../examples/sg_example/customitem.cpp | 59 ++++++++++ .../examples/sg_example/customitem.h | 26 ++++ .../examples/sg_example/images/test.png | Bin 0 -> 12849 bytes src/rendergraph/examples/sg_example/main.cpp | 16 +++ .../examples/sg_example/qml/main.qml | 13 ++ .../examples/shaders/CMakeLists.txt | 25 ++++ src/rendergraph/examples/shaders/README | 9 ++ .../examples/shaders/endoftrack.frag | 17 +++ .../examples/shaders/endoftrack.frag.gl | 19 +++ .../examples/shaders/endoftrack.vert | 14 +++ .../examples/shaders/endoftrack.vert.gl | 12 ++ .../examples/shaders/generate_shaders_gl.pl | 68 +++++++++++ .../shaders/generated_shaders_gl.cmake | 6 + src/rendergraph/examples/shaders/texture.frag | 9 ++ .../examples/shaders/texture.frag.gl | 11 ++ src/rendergraph/examples/shaders/texture.vert | 15 +++ .../examples/shaders/texture.vert.gl | 19 +++ .../examples/shaders/texture.vert.qsb | Bin 0 -> 607 bytes src/rendergraph/geometry.cpp | 30 +++++ src/rendergraph/geometry.h | 30 +++++ src/rendergraph/geometrynode.cpp | 34 ++++++ src/rendergraph/geometrynode.h | 26 ++++ src/rendergraph/material.cpp | 20 ++++ src/rendergraph/material.h | 52 ++++++++ src/rendergraph/materialshader.cpp | 25 ++++ src/rendergraph/materialshader.h | 26 ++++ src/rendergraph/materialtype.cpp | 18 +++ src/rendergraph/materialtype.h | 21 ++++ src/rendergraph/node.cpp | 35 ++++++ src/rendergraph/node.h | 38 ++++++ src/rendergraph/opacitynode.cpp | 19 +++ src/rendergraph/opacitynode.h | 19 +++ src/rendergraph/opengl/CMakeLists.txt | 54 +++++++++ src/rendergraph/opengl/geometrynode_impl.cpp | 83 +++++++++++++ src/rendergraph/opengl/graph.cpp | 35 ++++++ src/rendergraph/opengl/graph.h | 25 ++++ .../opengl/materialshader_impl.cpp | 25 ++++ src/rendergraph/opengl/openglnode.cpp | 15 +++ src/rendergraph/opengl/openglnode.h | 27 +++++ .../opengl/private/attributeset_impl.h | 17 +++ src/rendergraph/opengl/private/context_impl.h | 6 + .../opengl/private/geometry_impl.h | 53 +++++++++ .../opengl/private/geometrynode_impl.h | 34 ++++++ .../opengl/private/material_impl.h | 36 ++++++ .../opengl/private/materialshader_impl.h | 33 ++++++ .../opengl/private/materialtype_impl.h | 9 ++ src/rendergraph/opengl/private/node_impl.h | 78 ++++++++++++ .../opengl/private/opacitynode_impl.h | 28 +++++ .../opengl/private/openglnode_impl.h | 35 ++++++ src/rendergraph/opengl/private/texture_impl.h | 20 ++++ .../opengl/private/visiblenode_impl.h | 33 ++++++ src/rendergraph/scenegraph/CMakeLists.txt | 53 +++++++++ .../scenegraph/materialshader_impl.cpp | 22 ++++ .../scenegraph/private/attributeset_impl.h | 37 ++++++ .../scenegraph/private/context_impl.h | 18 +++ .../scenegraph/private/geometry_impl.h | 69 +++++++++++ .../scenegraph/private/geometrynode_impl.h | 28 +++++ .../scenegraph/private/material_impl.h | 48 ++++++++ .../scenegraph/private/materialshader_impl.h | 41 +++++++ .../scenegraph/private/materialtype_impl.h | 12 ++ .../scenegraph/private/node_impl.h | 56 +++++++++ .../scenegraph/private/opacitynode_impl.h | 23 ++++ .../scenegraph/private/texture_impl.h | 19 +++ src/rendergraph/scenegraph/scenegraph.cpp | 16 +++ src/rendergraph/scenegraph/scenegraph.h | 13 ++ src/rendergraph/scenegraph/texture_impl.cpp | 9 ++ src/rendergraph/texture.cpp | 19 +++ src/rendergraph/texture.h | 22 ++++ src/rendergraph/trash | 25 ++++ src/rendergraph/types.cpp | 111 ++++++++++++++++++ src/rendergraph/types.h | 31 +++++ src/rendergraph/uniform.h | 28 +++++ src/rendergraph/uniformscache.cpp | 28 +++++ src/rendergraph/uniformscache.h | 53 +++++++++ src/rendergraph/uniformset.cpp | 20 ++++ src/rendergraph/uniformset.h | 29 +++++ .../allshader/endoftrackmaterial.cpp | 38 ++++++ .../renderers/allshader/endoftrackmaterial.h | 21 ++++ .../allshader/waveformrenderbeat.cpp | 1 - .../renderers/allshader/waveformrenderer.h | 18 +-- .../allshader/waveformrendererabstract.h | 26 ---- .../allshader/waveformrendererendoftrack.cpp | 74 +++++------- .../allshader/waveformrendererendoftrack.h | 22 ++-- .../allshader/waveformrendererfiltered.cpp | 1 - .../allshader/waveformrendererhsv.cpp | 1 - .../allshader/waveformrendererpreroll.cpp | 1 - .../allshader/waveformrendererrgb.cpp | 1 - .../allshader/waveformrenderersignalbase.h | 8 +- .../allshader/waveformrenderersimple.cpp | 1 - .../allshader/waveformrendererslipmode.cpp | 1 - .../allshader/waveformrendererstem.cpp | 1 - .../allshader/waveformrenderertextured.cpp | 2 - .../allshader/waveformrendermark.cpp | 1 - .../renderers/allshader/waveformrendermark.h | 8 +- .../allshader/waveformrendermarkrange.cpp | 1 - .../renderers/waveformrendererabstract.h | 11 +- .../widgets/allshader/waveformwidget.cpp | 82 ++++++++----- .../widgets/allshader/waveformwidget.h | 4 + 135 files changed, 3186 insertions(+), 156 deletions(-) create mode 100644 res/shaders/rendergraph/CMakeLists.txt create mode 100644 res/shaders/rendergraph/README create mode 100644 res/shaders/rendergraph/endoftrack.frag create mode 100644 res/shaders/rendergraph/endoftrack.frag.gl create mode 100644 res/shaders/rendergraph/endoftrack.vert create mode 100644 res/shaders/rendergraph/endoftrack.vert.gl create mode 100755 res/shaders/rendergraph/generate_shaders_gl.pl create mode 100644 res/shaders/rendergraph/generated_shaders_gl.cmake create mode 100644 res/shaders/rendergraph/texture.frag create mode 100644 res/shaders/rendergraph/texture.frag.gl create mode 100644 res/shaders/rendergraph/texture.vert create mode 100644 res/shaders/rendergraph/texture.vert.gl create mode 100644 res/shaders/rendergraph/texture.vert.qsb create mode 100644 src/rendergraph/CMakeLists.txt create mode 100644 src/rendergraph/README create mode 100644 src/rendergraph/attribute.h create mode 100644 src/rendergraph/attributeset.cpp create mode 100644 src/rendergraph/attributeset.h create mode 100644 src/rendergraph/context.cpp create mode 100644 src/rendergraph/context.h create mode 100644 src/rendergraph/examples/CMakeLists.txt create mode 100644 src/rendergraph/examples/README create mode 100644 src/rendergraph/examples/common/CMakeLists.txt create mode 100644 src/rendergraph/examples/common/endoftrackmaterial.cpp create mode 100644 src/rendergraph/examples/common/endoftrackmaterial.h create mode 100644 src/rendergraph/examples/common/examplenodes.cpp create mode 100644 src/rendergraph/examples/common/examplenodes.h create mode 100644 src/rendergraph/examples/common/texturematerial.cpp create mode 100644 src/rendergraph/examples/common/texturematerial.h create mode 100644 src/rendergraph/examples/gl_example/CMakeLists.txt create mode 100644 src/rendergraph/examples/gl_example/images/test.png create mode 100644 src/rendergraph/examples/gl_example/main.cpp create mode 100644 src/rendergraph/examples/gl_example/window.cpp create mode 100644 src/rendergraph/examples/gl_example/window.h create mode 100644 src/rendergraph/examples/sg_example/CMakeLists.txt create mode 100644 src/rendergraph/examples/sg_example/customitem.cpp create mode 100644 src/rendergraph/examples/sg_example/customitem.h create mode 100644 src/rendergraph/examples/sg_example/images/test.png create mode 100644 src/rendergraph/examples/sg_example/main.cpp create mode 100644 src/rendergraph/examples/sg_example/qml/main.qml create mode 100644 src/rendergraph/examples/shaders/CMakeLists.txt create mode 100644 src/rendergraph/examples/shaders/README create mode 100644 src/rendergraph/examples/shaders/endoftrack.frag create mode 100644 src/rendergraph/examples/shaders/endoftrack.frag.gl create mode 100644 src/rendergraph/examples/shaders/endoftrack.vert create mode 100644 src/rendergraph/examples/shaders/endoftrack.vert.gl create mode 100755 src/rendergraph/examples/shaders/generate_shaders_gl.pl create mode 100644 src/rendergraph/examples/shaders/generated_shaders_gl.cmake create mode 100644 src/rendergraph/examples/shaders/texture.frag create mode 100644 src/rendergraph/examples/shaders/texture.frag.gl create mode 100644 src/rendergraph/examples/shaders/texture.vert create mode 100644 src/rendergraph/examples/shaders/texture.vert.gl create mode 100644 src/rendergraph/examples/shaders/texture.vert.qsb create mode 100644 src/rendergraph/geometry.cpp create mode 100644 src/rendergraph/geometry.h create mode 100644 src/rendergraph/geometrynode.cpp create mode 100644 src/rendergraph/geometrynode.h create mode 100644 src/rendergraph/material.cpp create mode 100644 src/rendergraph/material.h create mode 100644 src/rendergraph/materialshader.cpp create mode 100644 src/rendergraph/materialshader.h create mode 100644 src/rendergraph/materialtype.cpp create mode 100644 src/rendergraph/materialtype.h create mode 100644 src/rendergraph/node.cpp create mode 100644 src/rendergraph/node.h create mode 100644 src/rendergraph/opacitynode.cpp create mode 100644 src/rendergraph/opacitynode.h create mode 100644 src/rendergraph/opengl/CMakeLists.txt create mode 100644 src/rendergraph/opengl/geometrynode_impl.cpp create mode 100644 src/rendergraph/opengl/graph.cpp create mode 100644 src/rendergraph/opengl/graph.h create mode 100644 src/rendergraph/opengl/materialshader_impl.cpp create mode 100644 src/rendergraph/opengl/openglnode.cpp create mode 100644 src/rendergraph/opengl/openglnode.h create mode 100644 src/rendergraph/opengl/private/attributeset_impl.h create mode 100644 src/rendergraph/opengl/private/context_impl.h create mode 100644 src/rendergraph/opengl/private/geometry_impl.h create mode 100644 src/rendergraph/opengl/private/geometrynode_impl.h create mode 100644 src/rendergraph/opengl/private/material_impl.h create mode 100644 src/rendergraph/opengl/private/materialshader_impl.h create mode 100644 src/rendergraph/opengl/private/materialtype_impl.h create mode 100644 src/rendergraph/opengl/private/node_impl.h create mode 100644 src/rendergraph/opengl/private/opacitynode_impl.h create mode 100644 src/rendergraph/opengl/private/openglnode_impl.h create mode 100644 src/rendergraph/opengl/private/texture_impl.h create mode 100644 src/rendergraph/opengl/private/visiblenode_impl.h create mode 100644 src/rendergraph/scenegraph/CMakeLists.txt create mode 100644 src/rendergraph/scenegraph/materialshader_impl.cpp create mode 100644 src/rendergraph/scenegraph/private/attributeset_impl.h create mode 100644 src/rendergraph/scenegraph/private/context_impl.h create mode 100644 src/rendergraph/scenegraph/private/geometry_impl.h create mode 100644 src/rendergraph/scenegraph/private/geometrynode_impl.h create mode 100644 src/rendergraph/scenegraph/private/material_impl.h create mode 100644 src/rendergraph/scenegraph/private/materialshader_impl.h create mode 100644 src/rendergraph/scenegraph/private/materialtype_impl.h create mode 100644 src/rendergraph/scenegraph/private/node_impl.h create mode 100644 src/rendergraph/scenegraph/private/opacitynode_impl.h create mode 100644 src/rendergraph/scenegraph/private/texture_impl.h create mode 100644 src/rendergraph/scenegraph/scenegraph.cpp create mode 100644 src/rendergraph/scenegraph/scenegraph.h create mode 100644 src/rendergraph/scenegraph/texture_impl.cpp create mode 100644 src/rendergraph/texture.cpp create mode 100644 src/rendergraph/texture.h create mode 100644 src/rendergraph/trash create mode 100644 src/rendergraph/types.cpp create mode 100644 src/rendergraph/types.h create mode 100644 src/rendergraph/uniform.h create mode 100644 src/rendergraph/uniformscache.cpp create mode 100644 src/rendergraph/uniformscache.h create mode 100644 src/rendergraph/uniformset.cpp create mode 100644 src/rendergraph/uniformset.h create mode 100644 src/waveform/renderers/allshader/endoftrackmaterial.cpp create mode 100644 src/waveform/renderers/allshader/endoftrackmaterial.h delete mode 100644 src/waveform/renderers/allshader/waveformrendererabstract.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 437d3c0a154..2a4236d2529 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1514,6 +1514,7 @@ if(QOPENGL) src/shaders/vinylqualityshader.cpp src/util/opengltexture2d.cpp src/waveform/renderers/allshader/digitsrenderer.cpp + src/waveform/renderers/allshader/endoftrackmaterial.cpp src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp src/waveform/renderers/allshader/waveformrenderbackground.cpp src/waveform/renderers/allshader/waveformrenderbeat.cpp @@ -3810,6 +3811,10 @@ if(VINYLCONTROL) target_link_libraries(mixxx-lib PRIVATE mixxx-xwax) endif() +# rendergraph +add_subdirectory(src/rendergraph) +target_link_libraries(mixxx-lib PUBLIC rendergraph_gl) + # WavPack audio file support find_package(wavpack) default_option(WAVPACK "WavPack audio file support" "wavpack_FOUND") diff --git a/res/mixxx.qrc b/res/mixxx.qrc index 8011fe39f94..c21ec6a8008 100644 --- a/res/mixxx.qrc +++ b/res/mixxx.qrc @@ -96,5 +96,9 @@ shaders/passthrough.vert shaders/rgbsignal.frag shaders/stackedsignal.frag + shaders/rendergraph/endoftrack.frag.gl + shaders/rendergraph/endoftrack.vert.gl + shaders/rendergraph/texture.frag.gl + shaders/rendergraph/texture.vert.gl diff --git a/res/shaders/rendergraph/CMakeLists.txt b/res/shaders/rendergraph/CMakeLists.txt new file mode 100644 index 00000000000..b0a4339699b --- /dev/null +++ b/res/shaders/rendergraph/CMakeLists.txt @@ -0,0 +1,25 @@ +set(shaders + endoftrack.vert + endoftrack.frag + texture.vert + texture.frag +) + +qt6_add_shaders(rendergraph_sg "shaders-sg" + BATCHABLE + PRECOMPILE + OPTIMIZED + PREFIX + /rendergraph_sg/shaders + FILES + ${shaders} +) + +include(generated_shaders_gl.cmake) + +qt_add_resources(rendergraph_gl "shaders-gl" + PREFIX + /rendergraph_gl/shaders + FILES + ${generated_shaders_gl} +) diff --git a/res/shaders/rendergraph/README b/res/shaders/rendergraph/README new file mode 100644 index 00000000000..04bb5086e24 --- /dev/null +++ b/res/shaders/rendergraph/README @@ -0,0 +1,9 @@ +Generate the GLSL shaders from the spirv shaders by running + +generate_shaders_gl.pl + +(Make sure qsb and spirv commands are in your path. E.g: +export PATH=$PATH:~/VulkanSDK/1.3.283.0/macOS/bin:~/Qt/6.7.2/macos/bin +) + +Since Qt 6.6 we should be able to access this programmatically with QShader, but for now I do it manually diff --git a/res/shaders/rendergraph/endoftrack.frag b/res/shaders/rendergraph/endoftrack.frag new file mode 100644 index 00000000000..65a99d13e4d --- /dev/null +++ b/res/shaders/rendergraph/endoftrack.frag @@ -0,0 +1,17 @@ +#version 440 + +layout(location = 0) in float vgradient; +layout(location = 0) out vec4 fragColor; + +layout(std140, binding = 0) uniform buf { + vec4 color; +} +ubuf; + +void main() { + float minAlpha = 0.5 * ubuf.color.w; + float maxAlpha = 0.83 * ubuf.color.w; + float alpha = mix(minAlpha, maxAlpha, max(0.0, vgradient)); + // premultiple alpha + fragColor = vec4(ubuf.color.xyz * alpha, alpha); +} diff --git a/res/shaders/rendergraph/endoftrack.frag.gl b/res/shaders/rendergraph/endoftrack.frag.gl new file mode 100644 index 00000000000..f65b1ea3dda --- /dev/null +++ b/res/shaders/rendergraph/endoftrack.frag.gl @@ -0,0 +1,19 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +struct buf +{ + vec4 color; +}; + +uniform buf ubuf; + +varying float vgradient; + +void main() +{ + float minAlpha = 0.5 * ubuf.color.w; + float maxAlpha = 0.829999983310699462890625 * ubuf.color.w; + float alpha = mix(minAlpha, maxAlpha, max(0.0, vgradient)); + gl_FragData[0] = vec4(ubuf.color.xyz * alpha, alpha); +} diff --git a/res/shaders/rendergraph/endoftrack.vert b/res/shaders/rendergraph/endoftrack.vert new file mode 100644 index 00000000000..b5741fc8f35 --- /dev/null +++ b/res/shaders/rendergraph/endoftrack.vert @@ -0,0 +1,14 @@ +#version 440 + +layout(location = 0) in vec4 position; +layout(location = 1) in float gradient; +layout(location = 0) out float vgradient; + +out gl_PerVertex { + vec4 gl_Position; +}; + +void main() { + vgradient = gradient; + gl_Position = position; +} diff --git a/res/shaders/rendergraph/endoftrack.vert.gl b/res/shaders/rendergraph/endoftrack.vert.gl new file mode 100644 index 00000000000..053f0d12e78 --- /dev/null +++ b/res/shaders/rendergraph/endoftrack.vert.gl @@ -0,0 +1,12 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +varying float vgradient; +attribute float gradient; +attribute vec4 position; + +void main() +{ + vgradient = gradient; + gl_Position = position; +} diff --git a/res/shaders/rendergraph/generate_shaders_gl.pl b/res/shaders/rendergraph/generate_shaders_gl.pl new file mode 100755 index 00000000000..c528eb94747 --- /dev/null +++ b/res/shaders/rendergraph/generate_shaders_gl.pl @@ -0,0 +1,68 @@ +#!/usr/bin/perl + +my @files = (glob("*.vert"),glob("*.frag")); + +open(GENERATED,">generated_shaders_gl.cmake"); +print(GENERATED "set(generated_shaders_gl\n"); +for $file (@files) +{ + system("qsb","--glsl","120",$file,"-o","/tmp/$$-$file.qsb"); + open(INFILE,"qsb --dump /tmp/$$-$file.qsb|"); + open(OUTFILE,">$file.gl"); + $ok = 0; + $comment_added = 0; + print "Generating $file.gl from $file\n"; + while () + { + if ($in_shader_block == 2) + { + if (m/^\*\*/) + { + $in_shader_block = 0; + $ok = 1; + } + else + { + if (!$comment_added) + { + if (!m/^#/) + { + print(OUTFILE "//// GENERATED - EDITS WILL BE OVERWRITTEN\n"); + $comment_added = 1; + } + } + print OUTFILE "$_"; + } + } + elsif ($in_shader_block == 1) + { + chomp($_); + if ($_ eq "Contents:") + { + $in_shader_block = 2; + } + } + else + { + chomp($_); + if ($_ eq "Shader 1: GLSL 120 [Standard]") + { + $in_shader_block = 1; + } + } + } + close INFILE; + close OUTFILE; + if($ok) + { + print(GENERATED " $file.gl\n"); + } + else + { + print STDERR "Failed to generated $file.gl"; + unlink("$file.gl") + } + unlink("/tmp/$$-$file.qsb"); +} +print(GENERATED ")\n"); +close GENERATED; diff --git a/res/shaders/rendergraph/generated_shaders_gl.cmake b/res/shaders/rendergraph/generated_shaders_gl.cmake new file mode 100644 index 00000000000..e3bd0c644f2 --- /dev/null +++ b/res/shaders/rendergraph/generated_shaders_gl.cmake @@ -0,0 +1,6 @@ +set(generated_shaders_gl + endoftrack.vert.gl + texture.vert.gl + endoftrack.frag.gl + texture.frag.gl +) diff --git a/res/shaders/rendergraph/texture.frag b/res/shaders/rendergraph/texture.frag new file mode 100644 index 00000000000..bbe37bccd69 --- /dev/null +++ b/res/shaders/rendergraph/texture.frag @@ -0,0 +1,9 @@ +#version 440 + +layout(binding = 1) uniform sampler2D texture1; +layout(location = 0) in vec2 vTexcoord; +layout(location = 0) out vec4 fragColor; + +void main() { + fragColor = texture(texture1, vTexcoord); +} diff --git a/res/shaders/rendergraph/texture.frag.gl b/res/shaders/rendergraph/texture.frag.gl new file mode 100644 index 00000000000..b2d03f1352c --- /dev/null +++ b/res/shaders/rendergraph/texture.frag.gl @@ -0,0 +1,11 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +uniform sampler2D texture1; + +varying vec2 vTexcoord; + +void main() +{ + gl_FragData[0] = texture2D(texture1, vTexcoord); +} diff --git a/res/shaders/rendergraph/texture.vert b/res/shaders/rendergraph/texture.vert new file mode 100644 index 00000000000..46e4c84d254 --- /dev/null +++ b/res/shaders/rendergraph/texture.vert @@ -0,0 +1,15 @@ +#version 440 + +layout(location = 0) in vec4 position; +layout(location = 1) in vec2 texcoord; +layout(location = 0) out vec2 vTexcoord; + +layout(std140, binding = 0) uniform buf { + mat4 matrix; +} +ubuf; + +void main() { + vTexcoord = texcoord; + gl_Position = ubuf.matrix * position; +} diff --git a/res/shaders/rendergraph/texture.vert.gl b/res/shaders/rendergraph/texture.vert.gl new file mode 100644 index 00000000000..a3d58014be3 --- /dev/null +++ b/res/shaders/rendergraph/texture.vert.gl @@ -0,0 +1,19 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +struct buf +{ + mat4 matrix; +}; + +uniform buf ubuf; + +varying vec2 vTexcoord; +attribute vec2 texcoord; +attribute vec4 position; + +void main() +{ + vTexcoord = texcoord; + gl_Position = ubuf.matrix * position; +} diff --git a/res/shaders/rendergraph/texture.vert.qsb b/res/shaders/rendergraph/texture.vert.qsb new file mode 100644 index 0000000000000000000000000000000000000000..84fa7e916fe48a406e5e2205a9c2988b4c4e84dd GIT binary patch literal 607 zcmV-l0-*f>00rZCoRw2eZ`wc*9ovM4B?JNqByB#HaOsDH(uh`-5LJ6>4mnh6?iFB2 zEfpLY8&OsH5&ez*6TMXJ%=+1^D%7fj*1Pj&=DpdmA)*qc=JKjhOcPqsm_q(V(4-E7qRXK9f}l+ct<+q`GzH-BX9(2R!MRm6R* z*e@ey=hZez{Es=<3)o%k{yN3`rB#68oGoSS?q@~(NcIA3&%h-vn> z(YxS%_$6QxSGaE$SJn)KuL3@q`2jz7p(XYVeiix0?AMTAHGQWu%s6V$tV4efnsvNC z4;uT>aG z$EEd0F8B{d~R-cRoORr*&f;Qt}ciq`hMvz$bWAe`&xmlsMc;wTx%dX!AnSEboz!?-7pC|LE? zeP5|$9!$e%CMi1M2SdwY^d*?z>g8m7sh2mC)i?|zzpsWdmyMEml1Adqfu6n#7eUM| t2vr#PT3UVl1mt{rU@=JK_VdU0sN|UR(oGxHPc6!OrL61c_8Su|ltEZLJ_G;& literal 0 HcmV?d00001 diff --git a/src/rendergraph/CMakeLists.txt b/src/rendergraph/CMakeLists.txt new file mode 100644 index 00000000000..d50852826c8 --- /dev/null +++ b/src/rendergraph/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(opengl) +add_subdirectory(scenegraph) diff --git a/src/rendergraph/README b/src/rendergraph/README new file mode 100644 index 00000000000..8110ef888f8 --- /dev/null +++ b/src/rendergraph/README @@ -0,0 +1,29 @@ +rendergraph is an abstraction layer that can be compiled to be used with QtQuick scene graph classes +or with QOpenGL classes. This abstraction layer follows the design of the QtQuick scene graph, with +classes such as Material, Geometry, Node and GeometryNode, but it only gives access to a subset of +its functionality. + +The rendergraph/scenegraph implementation calls the underlying scenegraph classes directly or almost +directly. The opengl/layer implementation class implements classes that mimic the behaviour of the +scenegraph classes. + +The objective is to be able to write code that can be used both within the context of a QWidgets +applications and of a QML application. This includes using the same Vulkan-style GLSL shader code for +both. (The QSGMaterialShader uses the qsb files, QOpenGLShader uses the OpenGL shader code generated +by qsb) + +The common code is in library rendergraph, src/rendergraph + +The scene graph implementation is in library rendergraph_sg, src/rendergraph/scenegraph + +The OpenGL implementation is in library rendergraph_gl, src/rendergraph/opengl + +Example shader and nodes are in library rendergraph_examples, in src/rendergraph/examples. +Note that this code is agnostic of the layer that it will be linked against. + +Example applications are in src/rendergraph/example/sg_example and src/rendergraph/examples/gl_example, +which each link with rendergraph_examples and respectively with rendergraph_gl and rendergraph_sg. + +This is still very much work in progress! + +m0dB diff --git a/src/rendergraph/attribute.h b/src/rendergraph/attribute.h new file mode 100644 index 00000000000..5fae9e3df54 --- /dev/null +++ b/src/rendergraph/attribute.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include "rendergraph/types.h" + +namespace rendergraph { +struct Attribute; +} + +struct rendergraph::Attribute { + const int m_tupleSize; + const PrimitiveType m_primitiveType; + const QString m_name; + + Attribute(int tupleSize, PrimitiveType primitiveType) + : m_tupleSize{tupleSize}, + m_primitiveType{primitiveType} { + } + + Attribute(int tupleSize, PrimitiveType primitiveType, QString name) + : m_tupleSize{tupleSize}, + m_primitiveType{primitiveType}, + m_name{std::move(name)} { + } + + template + static Attribute create() { + return Attribute(tupleSizeOf(), primitiveTypeOf()); + } +}; diff --git a/src/rendergraph/attributeset.cpp b/src/rendergraph/attributeset.cpp new file mode 100644 index 00000000000..cb8fd9cb189 --- /dev/null +++ b/src/rendergraph/attributeset.cpp @@ -0,0 +1,36 @@ +#include "rendergraph/attributeset.h" + +#include "attributeset_impl.h" + +using namespace rendergraph; + +AttributeSet::AttributeSet(AttributeSet::Impl* pImpl) + : m_pImpl(pImpl) { +} + +AttributeSet::AttributeSet() + : AttributeSet(new AttributeSet::Impl()) { +} + +AttributeSet::AttributeSet(std::initializer_list list, const std::vector& names) + : AttributeSet() { + int i = 0; + for (auto item : list) { + add(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); + } +} + +AttributeSet::~AttributeSet() = default; + +AttributeSet::Impl& AttributeSet::impl() const { + return *m_pImpl; +} + +void AttributeSet::add(const Attribute& attribute) { + m_attributes.push_back(attribute); + m_pImpl->add(attribute); +} + +const std::vector& AttributeSet::attributes() const { + return m_attributes; +} diff --git a/src/rendergraph/attributeset.h b/src/rendergraph/attributeset.h new file mode 100644 index 00000000000..c242f42cfb6 --- /dev/null +++ b/src/rendergraph/attributeset.h @@ -0,0 +1,36 @@ +#pragma once + +#include + +#include "rendergraph/attribute.h" + +namespace rendergraph { +class AttributeSet; +} + +class rendergraph::AttributeSet { + public: + class Impl; + + AttributeSet(); + AttributeSet(std::initializer_list list, const std::vector& names); + + ~AttributeSet(); + + const std::vector& attributes() const; + Impl& impl() const; + + private: + AttributeSet(Impl* pImpl); + void add(const Attribute& attribute); + + std::vector m_attributes; + const std::unique_ptr m_pImpl; +}; + +namespace rendergraph { +template +AttributeSet makeAttributeSet(const std::vector& names) { + return AttributeSet({(Attribute::create())...}, names); +} +} // namespace rendergraph diff --git a/src/rendergraph/context.cpp b/src/rendergraph/context.cpp new file mode 100644 index 00000000000..1c64ec6d851 --- /dev/null +++ b/src/rendergraph/context.cpp @@ -0,0 +1,15 @@ +#include "rendergraph/context.h" + +#include "context_impl.h" + +using namespace rendergraph; + +Context::Context() + : m_pImpl(new Context::Impl()) { +} + +Context::~Context() = default; + +Context::Impl& Context::impl() const { + return *m_pImpl; +} diff --git a/src/rendergraph/context.h b/src/rendergraph/context.h new file mode 100644 index 00000000000..2659910bfdd --- /dev/null +++ b/src/rendergraph/context.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +namespace rendergraph { +class Context; +} + +class rendergraph::Context { + public: + class Impl; + Context(); + ~Context(); + Impl& impl() const; + + private: + const std::unique_ptr m_pImpl; +}; diff --git a/src/rendergraph/examples/CMakeLists.txt b/src/rendergraph/examples/CMakeLists.txt new file mode 100644 index 00000000000..b950f152d6f --- /dev/null +++ b/src/rendergraph/examples/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.16) +project(rendergraph LANGUAGES CXX) + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick ShaderTools) + +qt_standard_project_setup() + +add_subdirectory(../ rendergraph) +add_subdirectory(shaders) +add_subdirectory(gl_example) +add_subdirectory(sg_example) +add_subdirectory(common) diff --git a/src/rendergraph/examples/README b/src/rendergraph/examples/README new file mode 100644 index 00000000000..6168efc09c4 --- /dev/null +++ b/src/rendergraph/examples/README @@ -0,0 +1,6 @@ +Build examples with + +$ cd ../../../ +$ mkdir build-rendergraph_examples +$ cd build-rendergraph_examples +$ cmake -DCMAKE_PREFIX_PATH=~/Qt/6.7.2/macos/ ../src/rendergraph/examples diff --git a/src/rendergraph/examples/common/CMakeLists.txt b/src/rendergraph/examples/common/CMakeLists.txt new file mode 100644 index 00000000000..e6cfcbf839f --- /dev/null +++ b/src/rendergraph/examples/common/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(rendergraph_examples + endoftrackmaterial.cpp + endoftrackmaterial.h + texturematerial.cpp + texturematerial.h + examplenodes.cpp + examplenodes.h +) + +target_link_libraries(rendergraph_examples PUBLIC + Qt6::Core + Qt6::Gui + Qt6::OpenGL +) + +target_include_directories(rendergraph_examples PUBLIC ../../../ .) diff --git a/src/rendergraph/examples/common/endoftrackmaterial.cpp b/src/rendergraph/examples/common/endoftrackmaterial.cpp new file mode 100644 index 00000000000..4f5c9dfee41 --- /dev/null +++ b/src/rendergraph/examples/common/endoftrackmaterial.cpp @@ -0,0 +1,38 @@ +#include "endoftrackmaterial.h" + +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +EndOfTrackMaterial::EndOfTrackMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& EndOfTrackMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "gradient"}); + return set; +} + +/* static */ const UniformSet& EndOfTrackMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.color"}); + return set; +} + +MaterialType* EndOfTrackMaterial::type() const { + static MaterialType type; + return &type; +} + +int EndOfTrackMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +MaterialShader* EndOfTrackMaterial::createShader() const { + return new MaterialShader("endoftrack.vert", "endoftrack.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/examples/common/endoftrackmaterial.h b/src/rendergraph/examples/common/endoftrackmaterial.h new file mode 100644 index 00000000000..bcaa02b0430 --- /dev/null +++ b/src/rendergraph/examples/common/endoftrackmaterial.h @@ -0,0 +1,21 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" + +namespace rendergraph { +class EndOfTrackMaterial; +} + +class rendergraph::EndOfTrackMaterial : public rendergraph::Material { + public: + EndOfTrackMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + MaterialShader* createShader() const override; +}; diff --git a/src/rendergraph/examples/common/examplenodes.cpp b/src/rendergraph/examples/common/examplenodes.cpp new file mode 100644 index 00000000000..a2eca46ecb4 --- /dev/null +++ b/src/rendergraph/examples/common/examplenodes.cpp @@ -0,0 +1,60 @@ +#include "examplenodes.h" + +#include +#include +#include + +#include "endoftrackmaterial.h" +#include "rendergraph/geometry.h" +#include "texturematerial.h" + +using namespace rendergraph; + +ExampleNode1::ExampleNode1() { + setMaterial(std::make_unique()); + setGeometry(std::make_unique(EndOfTrackMaterial::attributes(), 4)); + + geometry().setAttributeValues(0, positionArray, 4); + geometry().setAttributeValues(1, horizontalGradientArray, 4); + + QColor color("red"); + material().setUniform(0, + QVector4D{color.redF(), + color.greenF(), + color.blueF(), + color.alphaF()}); +} + +ExampleNode2::ExampleNode2() { + setMaterial(std::make_unique()); + setGeometry(std::make_unique(EndOfTrackMaterial::attributes(), 4)); + + geometry().setAttributeValues(0, positionArray, 4); + geometry().setAttributeValues(1, horizontalGradientArray, 4); + + QColor color("blue"); + material().setUniform(0, + QVector4D{color.redF(), + color.greenF(), + color.blueF(), + color.alphaF()}); +} + +ExampleNode3::ExampleNode3() { + auto* m = new TextureMaterial; + + setMaterial(std::make_unique()); + setGeometry(std::make_unique(TextureMaterial::attributes(), 4)); + + geometry().setAttributeValues(0, positionArray, 4); + geometry().setAttributeValues(1, texcoordArray, 4); + + QMatrix4x4 matrix; + + matrix.scale(0.3); + material().setUniform(0, matrix); +} + +void ExampleNode3::setTexture(std::unique_ptr texture) { + dynamic_cast(material()).setTexture(std::move(texture)); +} diff --git a/src/rendergraph/examples/common/examplenodes.h b/src/rendergraph/examples/common/examplenodes.h new file mode 100644 index 00000000000..1ff3d01fb44 --- /dev/null +++ b/src/rendergraph/examples/common/examplenodes.h @@ -0,0 +1,36 @@ +#include "rendergraph/geometrynode.h" +#include "rendergraph/texture.h" + +namespace rendergraph { +class ExampleNode1; +class ExampleNode2; +class ExampleNode3; +} // namespace rendergraph + +class rendergraph::ExampleNode1 : public rendergraph::GeometryNode { + public: + static constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; + static constexpr float verticalGradientArray[] = {1.f, 1.f, -1.f, -1.f}; + static constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; + + ExampleNode1(); +}; + +class rendergraph::ExampleNode2 : public rendergraph::GeometryNode { + public: + static constexpr float positionArray[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f}; + static constexpr float verticalGradientArray[] = {1.f, 1.f, 0.f, 0.f}; + static constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; + + ExampleNode2(); +}; + +class rendergraph::ExampleNode3 : public rendergraph::GeometryNode { + public: + static constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; + static constexpr float texcoordArray[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f}; + + ExampleNode3(); + + void setTexture(std::unique_ptr texture); +}; diff --git a/src/rendergraph/examples/common/texturematerial.cpp b/src/rendergraph/examples/common/texturematerial.cpp new file mode 100644 index 00000000000..b437afeba49 --- /dev/null +++ b/src/rendergraph/examples/common/texturematerial.cpp @@ -0,0 +1,38 @@ +#include "texturematerial.h" + +#include +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" + +using namespace rendergraph; + +TextureMaterial::TextureMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& TextureMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "texcoord"}); + return set; +} + +/* static */ const UniformSet& TextureMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.matrix"}); + return set; +} + +MaterialType* TextureMaterial::type() const { + static MaterialType type; + return &type; +} + +int TextureMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +MaterialShader* TextureMaterial::createShader() const { + return new MaterialShader("texture.vert", "texture.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/examples/common/texturematerial.h b/src/rendergraph/examples/common/texturematerial.h new file mode 100644 index 00000000000..6f5c8460ec0 --- /dev/null +++ b/src/rendergraph/examples/common/texturematerial.h @@ -0,0 +1,34 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" +#include "rendergraph/texture.h" +#include "rendergraph/uniformset.h" + +namespace rendergraph { +class TextureMaterial; +} + +class rendergraph::TextureMaterial : public rendergraph::Material { + public: + TextureMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + MaterialShader* createShader() const override; + + Texture* texture(int binding) const override { + return m_pTexture.get(); + } + + void setTexture(std::unique_ptr texture) { + m_pTexture = std::move(texture); + } + + private: + std::unique_ptr m_pTexture; +}; diff --git a/src/rendergraph/examples/gl_example/CMakeLists.txt b/src/rendergraph/examples/gl_example/CMakeLists.txt new file mode 100644 index 00000000000..30f6a547b88 --- /dev/null +++ b/src/rendergraph/examples/gl_example/CMakeLists.txt @@ -0,0 +1,39 @@ +find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL) + +qt_add_executable(gl_example + window.cpp window.h + main.cpp +) + +set_target_properties(gl_example PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +target_link_libraries(gl_example PRIVATE + rendergraph_gl + rendergraph_examples + Qt6::Core + Qt6::Gui + Qt6::OpenGL +) + +qt_add_resources(gl_example "gl_example" + PREFIX + /example + FILES + images/test.png +) + +install(TARGETS gl_example + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +qt_generate_deploy_app_script( + TARGET gl_example + OUTPUT_SCRIPT deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR +) +install(SCRIPT ${deploy_script}) diff --git a/src/rendergraph/examples/gl_example/images/test.png b/src/rendergraph/examples/gl_example/images/test.png new file mode 100644 index 0000000000000000000000000000000000000000..f9580346eb8b893f1d6acb3be80d2ee911bc20e5 GIT binary patch literal 12849 zcmeHuWmglph1GW+u#nt9VP^Km%(}Gd4I%R z_rv|rvU>IEbxxf+wRi2Rj{2%1hxv}|9RL8pRFIce2LRw$VD}@a$gs2e#<~{lg61Tz z=L!HI)c$wCF%Do?!5)&j$>_RiI9j-Qnz)z)JUu;GtsQJ#fhJDotd1_0S!cpz0Kf-; zg0zIDSN3U+w-RuYuKJG+gTtpKx`C8Oqc1${5M2QS!JeJ@ON(g8~ z5;(;{h%p~f=fs0$a6+v={NL;U1C|N#tEP0~xVsuZ$3%MvRy}|9_@k!%&98onZ^I7= z{cYq!!eJ`yWTtsy5p^vt^0a2RFq=dh@%{C*Wn-_|&v9ory+j5X*>N5Sz1Wl@6nnV= zrl%cuc%G-fCwgDY!9x$3Zep$|^*U=%U1a4nEu?pS@>F~-%6!TFTP26HO;Hfw-_R|| z-FX*UZ0&6;YA~mdn*T7{{r9K8b_9Lc1_?QSNn5AQg-q*f<0<8SXLDuc(IQ*70hG$< z(PO5a`H7#-J|34`NxTB#_4V4EiVB))Bzr;L3$J@VeNk&hOH^J_@fY4HB!Oa9+4$>4 zX5>hucHgv`u0Tk!HFzCdvalc%DkDvIP{)i#S?S&quvEQ)b$2jx&9AucFC{5?lYtCC zMEpi+a@_rBQ{zCZY!a*Y;cC!7(>XyDyN zAwz!QBvu4u8IO`sof!V3FvN z09m+&x4^F6?}LJ<-;j+DghMaZL!J0344}80xk$E8cc)GDmEZI7JjF>aMOavbO>Pbp z^EiAc-&RWW!)1)~2?Ggx=##^PI}u8&suoVk0n)NEoq4ILzl8`~s9UcJCVmtA9Q_)K zQKj_j-+`J`p0Bjoe4rk zFx|HM$0xudlN7fD$i&S{WUp}C=o)XaTT%aqA3|w-Fr8#gO3KvoutgDylV}d5ieo`x z2M>SMYJ%7|J3s`tI$&qP0(IdU`=4BOeXB;KU_OXP1*`WKO{yd|5_X*)0K>9eMx&8TU=B%?D^wypwnV zw7S`fm9$2s@xRK;voq7~904KzrnLytgQ5Opcw{yQI)B27trH0bPkpiEFqeFDeqfz3 zj?XRwhu?Lns!q+9=mNI3wrGaq!CT4z{LU3ee-97r)EGI+KGIiLKz0=J3>lNnrG*Jx zK_O5$+D9%@RsNfR(?9w=yVaXrQpY>=+HFFVqK`u)6vnr2+*VG3XyL2sLSLd|aPxju z7$E`@v$L~Bd?qs5jQsBO;`yF1Uw5t)`PsFgK{@m6aU1p4J;j0{9+U52^GMzj>V*%S zpTD^tjwQWbni73F$rI%|3YsY#Rytm-()Tr zh)Yc6SUQ-PmMLm^bHKduycN^*Bv}6viCvAEu31T7RRY;~A1rdwzkA$FUhhnFN#3hY z*CwS*BdAYil(gHDnQ?MTVNBx=xpG5`=2glyqwNYz5-O#!onc5Jufl8E4 zU;NFFSvP7_fqKcn6`~JtxGCFYa62XIVxZ=j@w7p*%+EiOsO6q)`+HpEMXd|?s-xpO z1B0k$kIAEgjxzGRL>!mD|Iil!Bx{QvYwebXJxF=-!aK8RJK@HZZ^6;fVcq#i- zFX&fM(`{2s9?Ut;**x$`y;#lDP6~+Xw(*YvZ+e5n>?eg<9CjVEU2&NV zE_=N8k)u`fXDuDWrh~!+(Z_|Q=9;d@BV3Vs-?*!$4N2652ZmHvhyaV$txD}HwEOLp z!vAnthnboAJTfwJ+Fc27F#CHv!?p$-(3i<`-l6Q`sPg3<1_s9WDrfol$B{95btV47 za^y{$S!oI#9}24X{DEiS8{!{B0|Ork2?_HG;^?4B?~$ORncNff^6@@K6v06p$W;oB zyQPj}g5@OfRKoG01Jb%x+K^ZGv)SFrikdE;+X$+F)=|ilRCg;kk%0rBq#bcJ#GbAJ4|s;Ql32MQqYv9l*AOU4ZL-F#=1 zx%__6b^knP{okUd*6j~79Q~Qm(?qYY7p$TX3wUO1Yip}YUN?aYis6oARhkE_Q1>8a zgPkyO(*Yb$%D-`cA`INk#A)Xu7waM1Z0Egl|T#(N2mnJT%2l_ew4oY)5F?G#e&?kYEtO5brKNK%Oz zC$jjhF_RZlze~sc7g?AB5)G{eD8aTwB?ri;ntL@=uEosAYbbUzH|~IvksphXpt3-E zuJ_!3k=3UbCFI*ZIb>R=JKdz;BESc6OIb5wa%_8L1C5@{H0*1}47zAPYiY#{qsDNc z@ELc2Ekhw!y(m-^Orq{KYTn*I^RJJ7=7`+yWjW@a)n_f0X^`M=@gTFaWf@*1(h=_*g z^|Hl6lu8yY`+La!^Xr%rd`1mGieBu!bCu;+_m7+w{c!8Lk~7l*LJzrOZ?#t1!d(0%F&yNNtN!?yS4Q0 z$1&zPOOHH(K#oH=1$Or0pkDXqp*LG)nzHbb^12!vCHA=Mc7=0rUdQVqlScFum0!^7 zd!3lESuUX}Qn3KP311Q4RW_0xT_o|hlp_G*#oo~PQqG**O6Q;>qM|xMUOG=>k!oHS zu~Ihw#@Xq;yeDVE|*CW28cQTIMU7feRR44G;Mxy9%CKG$)iO5 zACFXc85rox2I&Wlaz{pdBDp*o6pKQwM9nay3ct4DtyEe|eg}Ajf61>?*mem6Qe2!3 z=sP^=tv`9{+T(a~my=h-I_(1kH1DS}=w+|sPbU$3QYbyX=ll)2pH_K|NuPX!dXXF9li zF4;Wgy7K4G9|*7a)sBw(-0T@DCg$Andt@vUe%?2$&5=2#@LUC=;HWje?~i&>xU~E5 z-MB0Y$&)^zNB|LEi->F%!3X5PZm$kUQ`0dy!wz?JL39V6{!J$@KW-E!SzRB*@wIwn z&(4>DP`isZ8-pss( zgF`iN><7~lF%eNfT5fK2xAijL+T-=#xLP}{Om3tsRASrMS_4e!dB&aN!SZl)B|l$Z zhla~x?W%7)r)M4KZAYs8;fy3qLzK>DrH@H3_?H1osg>uX`#9s#dOvMf zUFAbDr=B>CVkP}%mt92%Tm5wo_s1I(Vob2p4b^7hw6IS5cs+(*k~^VdxoEVp;+N>D zwKiAZ!ybwKLozi&z*b7~#VsMwX|DS(%D>p6%;+E5Mvn9(zoLdr)gu}@H{EjfGPWEj za#NXg0ythALHb$AnJ%eGk0o78H^X;@`XACq{#AFf^SRgv)DSum`zceiZm z?6eyRLU_7^9{j8lLRqbH)uC8*M(nmYpK0*TrLR4L0}qQX-6t7eHfS$SCl3rr=jJ9Q zqkm{9d@?Kky+1TG^w<^NiwQ&CnPSZit}?mW*u7eVoxQz9l^j9$F<2ty$Vgvu(8XXV zhcQh2bO*fI`;3|NL$T-^FJ_jkAy$x31N2;MYxL}DKd<{SAN0IEUu)9uj(vzjNEx?$ zob2SY%Ou{Y(#n_6oC$8(ys1`C0DD$wR|)d_Ki0Ym=KKPS^x(Oec2y1XzLS{9oXOTZ<{ zzSZ=xJF4lo`4dgZ{MzKYKY5EW?H>;Z2Uq)-8xCo6^H!ihc4n)(TbUT3WUQS2;=6jv z%_QpW;ui2d*J6k3fU6dJIWLc-K`-tfWHsdFP|ZsI4z5jl#jT4-U)gg$Q9$3A$aL>j$urx@>-hfN?IP(3YQ< z$dhhP6es1w1!$RA*BQ1FMu`sZ;+Op&cGE%Nw^uzjOEa@|Qaj`9N9rZ)!N->kNx?Dd z^*aJyUVH&!uJkjnVyQxAO>Iq#zfHbNGXefjhh2vqZb!jl_U{90xIhjdV6TU6@TdKz z?tBo8n*IJ5eHL_hlMJay|EBx36{|-kw>c_7^}fh<$pLilZo}N?@-pTVWAh7dof1Y* z;`JIV;)FaZFB)!cFd)kPqWuxu-D{p(TW_y55{(A6#mbUFYbhS5pUz4lgE7R)Ak*I9 z3N})I>w=(O)Fhrdp)2B3qy`}>!dWu166LJm=kYQs``YqXjn)^D*htgy~J zb8XUPk?(ZJ!(to=fxFGu+U`-A{N#1{WwsYg<$G*otuPwqje@ldBgjusiD^RW$?$w9 z)@lorm-e~xlMI?wve*qw)z9A=&8~}$0z8{oZ+I~s<=e2d^|Qq81jOPW=It2+S1zb} zXCKgY^)*6_0$x`t)M&Hta7m+7^z@kZtMi0Bt5<*PFa7TA?QK8N*3pVG3Rr2>s4?Q) zfA1K;)=iA*ba>*oe!VB+bE_)$;x-l;cM*wt(s4?(FYZ;H8ds3Yh9uw4przaC<@_3d zDnyi;o=)zJO>8Je5kFZvW#H^Yy|CXz=ft3z*L}*AkOQz+)3xfpX!(GBZ=<(XV`Kz@ z+==;hZ{}oX9`SD9G#lHara5GtocON~t59^)ocF*<0hw<3-~67T<>LTuhJVz*6tFl1 ze4q}HXfDUUg{}e5&fB73No;=FwZAQQaFtGjT8W4#C`MeMCBK^CaL>y=bOAyk&$HI+ zduL$6bsQN#9{8P5i-F-Tj-C1$|9MQ&3n2_>66OXPTgZWcR{OaO3lH z?Fask2bHPj!W@o&RkJ{l&M~dz{PIsbK2(A}l%zoUEGLA!-zB`2+wh8o2`5jJrJzAZ zRV+vwFk&srOz2AqYYwi9vR8<)^99ZPrM0ZTe!bb~aaO?VuJ4kjnNK1e+LEO~*mU$z zyG8H7L>}wYGGEH-BU(U;+rH0mfdxi3m+gNC7D9L$BRpM#Om8~2U8@(s!3w)&`@%OtF5XlNm_p0OOmf5E=la}Bm+ zcFkl~ncI0Pi99sTi%|8V#zun>`vf`cT~v@|i_ zhc<>penS960$l0*Oc^=n{d<)qllX?4dpO5pxv z&hPW?H%Cn^E$>q!Q`0TIJT!WK{=1sys~3IrXq6!%q9X@fsZcqqmh{{<`iBwRJmsCA zDc2XXmU;dTvxBs9ce8H1*q@2eeKuyXg{U^J&O*rF>Lzu%cK7xKU0n7cKeDsyd3jk? zJn8&q0%K|&fdP=An+-=o_G#ohjc3_fUHv({mNqI|uj;cX#@vtJYmIwfoSoCfw#!(4 zeTGK}Vc*({@oixtO{7Pwr;$n`9I3~UQG+P}`fU7!rPa;(^#v64^z! zZRu1=;uHH*Pg*?$>*+Jc60?t-r+MsV`30VmyeZK+(NvP2i6&C4R`T;91a?O!iqv@m3}_Dm|Mg2 zbpP@q;t!iOY+J6kwq`A>!FQ|YOO<-AtHfPkh`F{AlAlKlxYtYWIWYOE`A>0Cae+pO zlC-QW%_mO0d=nE?bZj{{O#&Ya%M$R-tYVE)7H^eQSmkMNk1puRzNR`su-xt8)Dna8 zmk~BC4UO)8W#u~buP>X;daLu>2HiTG7#<6)>g%}6HQQFu%hOPixfz90WP%QWTR~JP zOd-j9*^Z~Qx>{08i|~$0FcLP?lfMn*Vz2l3DtQiXPrdrmPPj?9st(JwCi-*k(K4H# zTaG^_?=bbLe;8G-*!CPL_FEjHKm=ryW(s6F^U4I8WLBXH;hEO`F70>Et@_ByG>L(Z z?T_5^S=RrF``96-Z+?jfjwhc6(2wT>tg;986I`Bs{OH6xC4x)zK49VT_L#Wyc2VD3 z_T~6(udxG>7zhZ54%Unar-dUTq|{kJk0|e8qC)`U{dJMyUl@-Vyh-C>U;I)_#A={> zKPhxByw+hkMcPb89vvO+bbn!T0%;%?@;K>fwqN_IvoDZC>rDzqL_&Ja%*}i>8^4XF zb9S_EGk))bMu;@I(}~s58D~+fHYVqufcH-S4|mBiTqXiY!-k#fBkJzLOEMn;AiE|z_3t!L@{ ztjO6KZjKvu$mv_tb|JzB@XJI~J7|OyNW$+lZH`XNN+ITZcVa;M`hX8h&?sNvKh ziUTU)h;&(qm*7kPE{@z~m5vL9T z`kXJtkT4$_z24$(cLGDPM-0PJ8W$Q`HTf;_8Ld1JEQ5za0Tb&h-tO3ev5jbj;?mayW8W(Jd8{vsV#CBW=HYd^Ml-4}b) zE3gFdda|CUOzLp;2Ftt@io*8{O>ZA`-4Z{Sy&;{hUPwDRu?w2J>$z|Ek1w(s`qWGb zvQ5$lXhbY<_L;`^+BDH{(!eW3p&k543W~kqhAm40tRCTa-y4x30AvWqri#zwb#N2f zH-_nb{wDeP5pQwhz zNK>$G|8@$j<7(`GP4Ql9u-FLmgAt+-PsTY#K|37n?ZM&dFcF*TKN z8SFcv)9!I6^~}&09T{0GD<{)ygDDQnm?^MO;wgo~KkGLe&lM}*zdoHiU+pNgJoy}{ z`M%sP#niw;fnG$y{Oh=b=Y6LYCyTJ3oQ1_6F!ygd-O4_!ih&kP$J|cCvR7DI&!nYO z!XT-g8=@^X8(bj`78TVD?a5K6#|jPq)j0d4jzNqRhP0&Ae!D27(|xxZ^Y>)Gw2@_Z zx;~p&LmYMAvC(+aiuuV4^__bCg`z?PvYwNop0|vZwe?|io9ljV-uB?c=t|AR;kW=O zlmodpJH?PcBEhqZHHDky@l-@!5i8%Q`&C{=MN-`q4=*_xhZJ|l;#)rw5Ci;lM|m~D zHKo+OpX=)u)g`tG6J4DhHk$33c^y|{&%2%`tN6WbcwMj(_(n5%Y+Y(vx1x{H(G%jX zb6Nt+%bU=g>*kCC9?TOqBxTex{!$R_uS=!i#C4zjU7gpsH!cqyOI>D{D=n&i=u zLf;%KXBsr3Rj*xVICLNrJn`_T{B<#NICuW!_i*)_@{0>7N#Fr*^8VB~uyo2$00o3I zjp+G^8YD)@nE#;?k@3?FA0{@XpfEc-`vnJ}iUH^@x9IAr4-YSC6p^T@Cbkt~8;uz> z&x9VH@_+RTEM?uPAlEA=3V z?>V@bd>G6G+q}n1HE%B^d7!p|+tr^!=Li4*ZvB6~09mNPuD|~nHC0wt`r0*TqO0Z! z6n3xuMuO#EY~ZJ}jyGFda=nEO#Svjy-N|q4h5{@rEegiu;KW(m%GC`F<>hL1_tp~bfzlSX^r8Xu1bj|y4#5sB$v zXmI_7N$DTr%xQj?O#Q2<$!fVNC@7riHUhbwE+UmNl|?2bM1WuY)YUauV7T9fG_4Os zdxQ%}=})GkeRyB>hi$9gd_10>kx|4>O)GDws(^;plaZdT@kz0Ktp3#%?~InEM-RS$ zIbydT^?2g`2BUXCQXWt-r6XV|DkJqihR0iV3tnSTVIT~Vy!|c$o080Zn9{RZj6tBr zUoDvSr&Nfmb0E6h_S>dabJv_RVThCv`Bhaxr*Lh1rQO4No9mk2Y{AmiaD=!#*9SUF z{3cOQ7{deezR&)#U{pUZH}0aiZPu`up?dIJzzgAbKNErXe*fUsU7-*!|63csx9)SN z`+pKW~CH_LhM zyBS8jN=dArrd9ovy(-_{;e!Tl9u--;iEfK^O|1zJO(9ck1Nf~lmQZIob;jhnH*q z*byO26tQ=gJf3^Y?rFV?)+lXcP}8yvvRN(;05`1$B{gg6ekOu+IS+mP>g09=tLB_H z8#idNZB_gqlVCJU>$1j|=F zhP4(IJrT+*xWCU<#DVAcI=B!?5WbS{|8bhdS(7mq=Fv89p}EVDu;BMn#-cbzziEQ& z?c={~Ao=}o?<5>t5N49n(41<75Qz~QbzNGL1~7C%aLeZBwjd?Tl#0rifXPTlUVThv zem`!@*XIY)@UsZl|0YuTQ7M`Kh9y3{JTD%Xm|RGNn!0N_3s_`n(b?p7XDXATiV(#dO&^n| z^Iu(EJ52oKbA$(cbcY+yza-eC*4d3N{wAxVT*$6`ao$3S<<0Q<^KS2QMk!UCK?iKh zallGOdYi8)cSf+CO(3)B1LDwBxcyT5-uI-=KZjH3a}%+sbVzPW0ir~*nLjSkjhyZR7bh~8!h{E#Nbtt0~j8luAY2` zfr-h+jrSQwuUjI(+P-8s6?FWP!e~i5CjN7$=8>T9UFW+{z`uu*yzl9WiTBC48=pRX z+AY{-Ov`?|M{hyxWkBWgE?WeL#MS6a8xT5uOp#WJPfJMws($&>&NWS@YckL+;tP!% z`^k4M0fr8=^?(o+XGwYFDUx>#VFc-Vf6BK&A6orpJLMrSUz_$LgP)Oc_$gROOAA9< z_e=;+b3r`xH(wYJAJbQ$7dW8#EB4k-Y_qO@-{7U$2#Pl*&lea+Wr>Z7Z`Ic#%zqPv zdw4)8&ixWYvPh!UWOdi{t%j%C@kEBDw5kCzchlJ5>ybxENP5|kB)|8sHzW#tV$QtE zY~r-UV%Ltz?J?C{mO$zB&I!k4;(3F%um(xG17onw9#bRpUc1axESbx)h^ij{13_bSE?tY7)-@RmD|c^( z$J1`aUmNWsQCLVEyT9KN(&XtWUg8_#AM?s9{x*UkO0?8c--cFO8(a0G*qtFsNRy+Y|G z1%6TovQ4(#)9NQhbdBaIfnOMDKRvo9N)Q)PQ) zVinzEqV3Ys(x%y+HwlHeCyH!W9=|!XwONQ@!)Fkt zhZxevA4S!6KD81bB%-q@}cL?>cdrlKN-Ccd7>BX&T7V2J1`2HlDgrMg>L`mcz>xkM?@xKOx= z3tOZTON-)kzNVi!5a4MnDTr@AreLf*sC333i}|CxGg16e{V~M-U8$=uHd1 z^!Y21#?o;-a;b9cW+CnQ2F3IMTvEcz;3WC{9VMoKNtIxWR0z-0H*ORjr_E_Ieg@2q z+_gOo^!^C!mSMU9RW+^O>ye-m&zJCCxOj`UPpUIoFUKt&8zK#m+{6Do;&*LrEsw09 zkn@(blehKZm}B?LqGK+bM+7XY(lNEesF8odH@Tm%Dq`9hq@$aRfB<8X-tBbu)XUAS zar0qMQ;TC-@!&yE@(??+ww%bq027U`BO!ZQc-2MYbdoM`v~=Dq0Nq6)jPT0(2%UIjQNvn%%33x8 zHhSP*0?@Is@qhmOsj38PQGLUBcS|yA(sV1{QpweKbWj*dI7L6eUJYLN*a`J<#(n&#!zzYr|NI?=3lw>k9n4-9qX!s0vi2oXbUg6>4 zGkCsk?6Z!a4a%r#>Q)6!19h~1c(l}s>^6KsIcyLg)GaxrS(+f^SvM8xgMZprb(pU}8r zn9+4%(sKTjD*RU-(#S6qq4*3)oxf#9#H-HutsklT#NC&rz_gJs@N9^1to8~sy0NmTIf zzLBY^j?I4TC4ax$1)a{SrJ2_HdvxM)ayUndyLKnZ^f4GvlT11L8K*6rkyu&bNDzE5pO4P1thi`fNC)B@GQS({ zh_Igoq?xF__JizQ3D)9kt!4^tUEfc7H#axmeFyVS{zz5aB_xayeS5y1Vg=u*cav(b zI3kXlHho~9eka03rmwlcX4%rDi_ofN8T$Jh0XD8S4*Y*E)ly}vPnqMxhwrerwCzNz zQqX3#AZG~wahC1@tA_HrXFK7K?^#k?LL6=;NyU=vcQssf$2MeA)lNj}<%tQ}jl(?q z0yHiQC6Okl(PZn?R4v@?k%a$b*W?sdtgrM_s}{;Fn5br~;?A(TBD*<0Rm>mDoW!3nNkN!0Cy(%kVK<}{P>8;@-Aj*w=_UI4q>W{!! z*<#*^?YWsWmBc~3l-uSr$3&FCIhFXo2K@hhzb1sgA#DFLO}rx$--7+_0Z@=pk*=0B G4*q`+EtQY} literal 0 HcmV?d00001 diff --git a/src/rendergraph/examples/gl_example/main.cpp b/src/rendergraph/examples/gl_example/main.cpp new file mode 100644 index 00000000000..7b62238b429 --- /dev/null +++ b/src/rendergraph/examples/gl_example/main.cpp @@ -0,0 +1,12 @@ +#include + +#include "window.h" + +int main(int argc, char* argv[]) { + QGuiApplication app(argc, argv); + + Window window; + window.show(); + + return app.exec(); +} diff --git a/src/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/examples/gl_example/window.cpp new file mode 100644 index 00000000000..72b13753451 --- /dev/null +++ b/src/rendergraph/examples/gl_example/window.cpp @@ -0,0 +1,43 @@ +#include "window.h" + +#include "examplenodes.h" +#include "rendergraph/context.h" +#include "rendergraph/opengl/graph.h" + +Window::Window() { +} + +Window::~Window() { +} + +void Window::initializeGL() { + auto node = std::make_unique(); + node->appendChildNode(std::make_unique()); + node->appendChildNode(std::make_unique()); + node->appendChildNode(std::make_unique()); + + { + QImage img(":/example/images/test.png"); + rendergraph::Context context; + static_cast(node->lastChild()) + ->setTexture( + std::make_unique(context, img)); + } + + m_rendergraph = std::make_unique(std::move(node)); + m_rendergraph->initialize(); +} + +void Window::resizeGL(int, int) { +} + +void Window::paintGL() { + glClearColor(0.f, 0.f, 0.f, 1.f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_BLEND); + // qt scene graph uses premultiplied alpha color in the shader, + // so we need to do the same + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + + m_rendergraph->render(); +} diff --git a/src/rendergraph/examples/gl_example/window.h b/src/rendergraph/examples/gl_example/window.h new file mode 100644 index 00000000000..e1b898c0357 --- /dev/null +++ b/src/rendergraph/examples/gl_example/window.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +namespace rendergraph { +class Graph; +} + +class Window : public QOpenGLWindow { + public: + Window(); + ~Window(); + + void initializeGL() override; + void resizeGL(int w, int h) override; + void paintGL() override; + + private: + std::unique_ptr m_rendergraph; +}; diff --git a/src/rendergraph/examples/sg_example/CMakeLists.txt b/src/rendergraph/examples/sg_example/CMakeLists.txt new file mode 100644 index 00000000000..096e131e47e --- /dev/null +++ b/src/rendergraph/examples/sg_example/CMakeLists.txt @@ -0,0 +1,35 @@ +qt_add_executable(sg_example WIN32 MACOSX_BUNDLE + customitem.cpp + customitem.h + main.cpp +) + +target_link_libraries(sg_example PRIVATE + rendergraph_sg + rendergraph_examples +) + +qt_add_qml_module(sg_example + URI RenderGraph + QML_FILES + qml/main.qml + RESOURCES + images/test.png + RESOURCE_PREFIX /example + NO_RESOURCE_TARGET_PATH +) + +install(TARGETS sg_example + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +qt_generate_deploy_qml_app_script( + TARGET sg_example + OUTPUT_SCRIPT deploy_script + MACOS_BUNDLE_POST_BUILD + NO_UNSUPPORTED_PLATFORM_ERROR + DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM +) +install(SCRIPT ${deploy_script}) diff --git a/src/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/examples/sg_example/customitem.cpp new file mode 100644 index 00000000000..fcf1f0feb07 --- /dev/null +++ b/src/rendergraph/examples/sg_example/customitem.cpp @@ -0,0 +1,59 @@ +#include "customitem.h" + +#include +#include +#include +#include +#include + +#include "examplenodes.h" +#include "rendergraph/context.h" +#include "rendergraph/scenegraph/scenegraph.h" + +CustomItem::CustomItem(QQuickItem* parent) + : QQuickItem(parent) { + setFlag(ItemHasContents, true); +} + +CustomItem::~CustomItem() = default; + +void CustomItem::geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) { + m_geometryChanged = true; + update(); + QQuickItem::geometryChange(newGeometry, oldGeometry); +} + +QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { + QSGRectangleNode* bgNode; + if (!node) { + bgNode = window()->createRectangleNode(); + bgNode->setColor(QColor(0, 0, 0, 255)); + bgNode->setRect(boundingRect()); + + m_node = std::make_unique(); + m_node->appendChildNode(std::make_unique()); + m_node->appendChildNode(std::make_unique()); + m_node->appendChildNode(std::make_unique()); + + { + QImage img(":/example/images/test.png"); + auto context = rendergraph::createSgContext(window()); + static_cast(m_node->lastChild()) + ->setTexture(std::make_unique( + *context, img)); + } + + bgNode->appendChildNode(rendergraph::sgNode(m_node.get())); + + node = bgNode; + } else { + bgNode = static_cast(node); + } + + if (m_geometryChanged) { + bgNode->setRect(boundingRect()); + m_geometryChanged = false; + } + + return node; +} diff --git a/src/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/examples/sg_example/customitem.h new file mode 100644 index 00000000000..304fb5c8f5e --- /dev/null +++ b/src/rendergraph/examples/sg_example/customitem.h @@ -0,0 +1,26 @@ +#ifndef CUSTOMITEM_H +#define CUSTOMITEM_H + +#include + +namespace rendergraph { +class Node; +} + +class CustomItem : public QQuickItem { + Q_OBJECT + QML_ELEMENT + + public: + explicit CustomItem(QQuickItem* parent = nullptr); + ~CustomItem(); + + protected: + QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*) override; + void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override; + + bool m_geometryChanged{}; + std::unique_ptr m_node; +}; + +#endif // CUSTOMITEM_H diff --git a/src/rendergraph/examples/sg_example/images/test.png b/src/rendergraph/examples/sg_example/images/test.png new file mode 100644 index 0000000000000000000000000000000000000000..f9580346eb8b893f1d6acb3be80d2ee911bc20e5 GIT binary patch literal 12849 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 G4*q`+EtQY} literal 0 HcmV?d00001 diff --git a/src/rendergraph/examples/sg_example/main.cpp b/src/rendergraph/examples/sg_example/main.cpp new file mode 100644 index 00000000000..ab2e5b34072 --- /dev/null +++ b/src/rendergraph/examples/sg_example/main.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +#include "customitem.h" + +int main(int argc, char** argv) { + QGuiApplication app(argc, argv); + + QQuickView view; + view.setResizeMode(QQuickView::SizeRootObjectToView); + view.setSource(QUrl("qrc:///example/qml/main.qml")); + view.show(); + + return app.exec(); +} diff --git a/src/rendergraph/examples/sg_example/qml/main.qml b/src/rendergraph/examples/sg_example/qml/main.qml new file mode 100644 index 00000000000..2410ad1a560 --- /dev/null +++ b/src/rendergraph/examples/sg_example/qml/main.qml @@ -0,0 +1,13 @@ +import QtQuick +import RenderGraph + +Item { + id: root + + width: 640 + height: 480 + + CustomItem { + anchors.fill: parent + } +} diff --git a/src/rendergraph/examples/shaders/CMakeLists.txt b/src/rendergraph/examples/shaders/CMakeLists.txt new file mode 100644 index 00000000000..c16c1e33ab1 --- /dev/null +++ b/src/rendergraph/examples/shaders/CMakeLists.txt @@ -0,0 +1,25 @@ +set(shaders + endoftrack.vert + endoftrack.frag + texture.vert + texture.frag +) + +qt6_add_shaders(rendergraph_sg "shaders-sg" + BATCHABLE + PRECOMPILE + OPTIMIZED + PREFIX + /shaders/rendergraph + FILES + ${shaders} +) + +include(generated_shaders_gl.cmake) + +qt_add_resources(rendergraph_gl "shaders-gl" + PREFIX + /shaders/rendergraph + FILES + ${generated_shaders_gl} +) diff --git a/src/rendergraph/examples/shaders/README b/src/rendergraph/examples/shaders/README new file mode 100644 index 00000000000..04bb5086e24 --- /dev/null +++ b/src/rendergraph/examples/shaders/README @@ -0,0 +1,9 @@ +Generate the GLSL shaders from the spirv shaders by running + +generate_shaders_gl.pl + +(Make sure qsb and spirv commands are in your path. E.g: +export PATH=$PATH:~/VulkanSDK/1.3.283.0/macOS/bin:~/Qt/6.7.2/macos/bin +) + +Since Qt 6.6 we should be able to access this programmatically with QShader, but for now I do it manually diff --git a/src/rendergraph/examples/shaders/endoftrack.frag b/src/rendergraph/examples/shaders/endoftrack.frag new file mode 100644 index 00000000000..65a99d13e4d --- /dev/null +++ b/src/rendergraph/examples/shaders/endoftrack.frag @@ -0,0 +1,17 @@ +#version 440 + +layout(location = 0) in float vgradient; +layout(location = 0) out vec4 fragColor; + +layout(std140, binding = 0) uniform buf { + vec4 color; +} +ubuf; + +void main() { + float minAlpha = 0.5 * ubuf.color.w; + float maxAlpha = 0.83 * ubuf.color.w; + float alpha = mix(minAlpha, maxAlpha, max(0.0, vgradient)); + // premultiple alpha + fragColor = vec4(ubuf.color.xyz * alpha, alpha); +} diff --git a/src/rendergraph/examples/shaders/endoftrack.frag.gl b/src/rendergraph/examples/shaders/endoftrack.frag.gl new file mode 100644 index 00000000000..f65b1ea3dda --- /dev/null +++ b/src/rendergraph/examples/shaders/endoftrack.frag.gl @@ -0,0 +1,19 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +struct buf +{ + vec4 color; +}; + +uniform buf ubuf; + +varying float vgradient; + +void main() +{ + float minAlpha = 0.5 * ubuf.color.w; + float maxAlpha = 0.829999983310699462890625 * ubuf.color.w; + float alpha = mix(minAlpha, maxAlpha, max(0.0, vgradient)); + gl_FragData[0] = vec4(ubuf.color.xyz * alpha, alpha); +} diff --git a/src/rendergraph/examples/shaders/endoftrack.vert b/src/rendergraph/examples/shaders/endoftrack.vert new file mode 100644 index 00000000000..b5741fc8f35 --- /dev/null +++ b/src/rendergraph/examples/shaders/endoftrack.vert @@ -0,0 +1,14 @@ +#version 440 + +layout(location = 0) in vec4 position; +layout(location = 1) in float gradient; +layout(location = 0) out float vgradient; + +out gl_PerVertex { + vec4 gl_Position; +}; + +void main() { + vgradient = gradient; + gl_Position = position; +} diff --git a/src/rendergraph/examples/shaders/endoftrack.vert.gl b/src/rendergraph/examples/shaders/endoftrack.vert.gl new file mode 100644 index 00000000000..053f0d12e78 --- /dev/null +++ b/src/rendergraph/examples/shaders/endoftrack.vert.gl @@ -0,0 +1,12 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +varying float vgradient; +attribute float gradient; +attribute vec4 position; + +void main() +{ + vgradient = gradient; + gl_Position = position; +} diff --git a/src/rendergraph/examples/shaders/generate_shaders_gl.pl b/src/rendergraph/examples/shaders/generate_shaders_gl.pl new file mode 100755 index 00000000000..c528eb94747 --- /dev/null +++ b/src/rendergraph/examples/shaders/generate_shaders_gl.pl @@ -0,0 +1,68 @@ +#!/usr/bin/perl + +my @files = (glob("*.vert"),glob("*.frag")); + +open(GENERATED,">generated_shaders_gl.cmake"); +print(GENERATED "set(generated_shaders_gl\n"); +for $file (@files) +{ + system("qsb","--glsl","120",$file,"-o","/tmp/$$-$file.qsb"); + open(INFILE,"qsb --dump /tmp/$$-$file.qsb|"); + open(OUTFILE,">$file.gl"); + $ok = 0; + $comment_added = 0; + print "Generating $file.gl from $file\n"; + while () + { + if ($in_shader_block == 2) + { + if (m/^\*\*/) + { + $in_shader_block = 0; + $ok = 1; + } + else + { + if (!$comment_added) + { + if (!m/^#/) + { + print(OUTFILE "//// GENERATED - EDITS WILL BE OVERWRITTEN\n"); + $comment_added = 1; + } + } + print OUTFILE "$_"; + } + } + elsif ($in_shader_block == 1) + { + chomp($_); + if ($_ eq "Contents:") + { + $in_shader_block = 2; + } + } + else + { + chomp($_); + if ($_ eq "Shader 1: GLSL 120 [Standard]") + { + $in_shader_block = 1; + } + } + } + close INFILE; + close OUTFILE; + if($ok) + { + print(GENERATED " $file.gl\n"); + } + else + { + print STDERR "Failed to generated $file.gl"; + unlink("$file.gl") + } + unlink("/tmp/$$-$file.qsb"); +} +print(GENERATED ")\n"); +close GENERATED; diff --git a/src/rendergraph/examples/shaders/generated_shaders_gl.cmake b/src/rendergraph/examples/shaders/generated_shaders_gl.cmake new file mode 100644 index 00000000000..e3bd0c644f2 --- /dev/null +++ b/src/rendergraph/examples/shaders/generated_shaders_gl.cmake @@ -0,0 +1,6 @@ +set(generated_shaders_gl + endoftrack.vert.gl + texture.vert.gl + endoftrack.frag.gl + texture.frag.gl +) diff --git a/src/rendergraph/examples/shaders/texture.frag b/src/rendergraph/examples/shaders/texture.frag new file mode 100644 index 00000000000..bbe37bccd69 --- /dev/null +++ b/src/rendergraph/examples/shaders/texture.frag @@ -0,0 +1,9 @@ +#version 440 + +layout(binding = 1) uniform sampler2D texture1; +layout(location = 0) in vec2 vTexcoord; +layout(location = 0) out vec4 fragColor; + +void main() { + fragColor = texture(texture1, vTexcoord); +} diff --git a/src/rendergraph/examples/shaders/texture.frag.gl b/src/rendergraph/examples/shaders/texture.frag.gl new file mode 100644 index 00000000000..b2d03f1352c --- /dev/null +++ b/src/rendergraph/examples/shaders/texture.frag.gl @@ -0,0 +1,11 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +uniform sampler2D texture1; + +varying vec2 vTexcoord; + +void main() +{ + gl_FragData[0] = texture2D(texture1, vTexcoord); +} diff --git a/src/rendergraph/examples/shaders/texture.vert b/src/rendergraph/examples/shaders/texture.vert new file mode 100644 index 00000000000..46e4c84d254 --- /dev/null +++ b/src/rendergraph/examples/shaders/texture.vert @@ -0,0 +1,15 @@ +#version 440 + +layout(location = 0) in vec4 position; +layout(location = 1) in vec2 texcoord; +layout(location = 0) out vec2 vTexcoord; + +layout(std140, binding = 0) uniform buf { + mat4 matrix; +} +ubuf; + +void main() { + vTexcoord = texcoord; + gl_Position = ubuf.matrix * position; +} diff --git a/src/rendergraph/examples/shaders/texture.vert.gl b/src/rendergraph/examples/shaders/texture.vert.gl new file mode 100644 index 00000000000..a3d58014be3 --- /dev/null +++ b/src/rendergraph/examples/shaders/texture.vert.gl @@ -0,0 +1,19 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +struct buf +{ + mat4 matrix; +}; + +uniform buf ubuf; + +varying vec2 vTexcoord; +attribute vec2 texcoord; +attribute vec4 position; + +void main() +{ + vTexcoord = texcoord; + gl_Position = ubuf.matrix * position; +} diff --git a/src/rendergraph/examples/shaders/texture.vert.qsb b/src/rendergraph/examples/shaders/texture.vert.qsb new file mode 100644 index 0000000000000000000000000000000000000000..84fa7e916fe48a406e5e2205a9c2988b4c4e84dd GIT binary patch literal 607 zcmV-l0-*f>00rZCoRw2eZ`wc*9ovM4B?JNqByB#HaOsDH(uh`-5LJ6>4mnh6?iFB2 zEfpLY8&OsH5&ez*6TMXJ%=+1^D%7fj*1Pj&=DpdmA)*qc=JKjhOcPqsm_q(V(4-E7qRXK9f}l+ct<+q`GzH-BX9(2R!MRm6R* z*e@ey=hZez{Es=<3)o%k{yN3`rB#68oGoSS?q@~(NcIA3&%h-vn> z(YxS%_$6QxSGaE$SJn)KuL3@q`2jz7p(XYVeiix0?AMTAHGQWu%s6V$tV4efnsvNC z4;uT>aG z$EEd0F8B{d~R-cRoORr*&f;Qt}ciq`hMvz$bWAe`&xmlsMc;wTx%dX!AnSEboz!?-7pC|LE? zeP5|$9!$e%CMi1M2SdwY^d*?z>g8m7sh2mC)i?|zzpsWdmyMEml1Adqfu6n#7eUM| t2vr#PT3UVl1mt{rU@=JK_VdU0sN|UR(oGxHPc6!OrL61c_8Su|ltEZLJ_G;& literal 0 HcmV?d00001 diff --git a/src/rendergraph/geometry.cpp b/src/rendergraph/geometry.cpp new file mode 100644 index 00000000000..cc06ce59077 --- /dev/null +++ b/src/rendergraph/geometry.cpp @@ -0,0 +1,30 @@ +#include "rendergraph/geometry.h" + +#include "geometry_impl.h" + +using namespace rendergraph; + +Geometry::Geometry(Impl* pImpl) + : m_pImpl(pImpl) { +} + +Geometry::Geometry(const AttributeSet& attributeSet, int vertexCount) + : Geometry(new Geometry::Impl(attributeSet, vertexCount)){}; + +Geometry::~Geometry() = default; + +Geometry::Impl& Geometry::impl() const { + return *m_pImpl; +} + +void Geometry::setAttributeValues(int attributePosition, const float* data, int numTuples) { + m_pImpl->setAttributeValues(attributePosition, data, numTuples); +} + +void Geometry::setDrawingMode(Geometry::DrawingMode mode) { + m_pImpl->setDrawingMode(mode); +} + +Geometry::DrawingMode Geometry::drawingMode() const { + return m_pImpl->Impl::drawingMode(); +} diff --git a/src/rendergraph/geometry.h b/src/rendergraph/geometry.h new file mode 100644 index 00000000000..7f6829f29cf --- /dev/null +++ b/src/rendergraph/geometry.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +namespace rendergraph { +class Geometry; +class AttributeSet; +} // namespace rendergraph + +class rendergraph::Geometry { + public: + enum class DrawingMode { + Triangles, + TriangleStrip + }; + class Impl; + + Geometry(const AttributeSet& attributeSet, int vertexCount); + ~Geometry(); + void setAttributeValues(int attributePosition, const float* data, int numTuples); + Impl& impl() const; + + DrawingMode drawingMode() const; + void setDrawingMode(DrawingMode mode); + + private: + Geometry(Impl* pImpl); + + const std::unique_ptr m_pImpl; +}; diff --git a/src/rendergraph/geometrynode.cpp b/src/rendergraph/geometrynode.cpp new file mode 100644 index 00000000000..e083d56f718 --- /dev/null +++ b/src/rendergraph/geometrynode.cpp @@ -0,0 +1,34 @@ +#include "rendergraph/geometrynode.h" + +#include "geometrynode_impl.h" +#include "rendergraph/geometry.h" + +using namespace rendergraph; + +GeometryNode::GeometryNode(NodeImplBase* pImpl) + : Node(pImpl) { +} + +GeometryNode::GeometryNode() + : GeometryNode(new GeometryNode::Impl(this)) { +} + +GeometryNode::~GeometryNode() = default; + +void GeometryNode::setGeometry(std::unique_ptr geometry) { + m_geometry = std::move(geometry); + static_cast(impl()).setGeometry(m_geometry.get()); +} + +void GeometryNode::setMaterial(std::unique_ptr material) { + m_material = std::move(material); + static_cast(impl()).setMaterial(m_material.get()); +} + +Geometry& GeometryNode::geometry() const { + return *m_geometry; +} + +Material& GeometryNode::material() const { + return *m_material; +} diff --git a/src/rendergraph/geometrynode.h b/src/rendergraph/geometrynode.h new file mode 100644 index 00000000000..f8884a110cd --- /dev/null +++ b/src/rendergraph/geometrynode.h @@ -0,0 +1,26 @@ +#pragma once + +#include "rendergraph/node.h" + +namespace rendergraph { +class GeometryNode; +class Geometry; +class Material; +} // namespace rendergraph + +class rendergraph::GeometryNode : public rendergraph::Node { + public: + class Impl; + + GeometryNode(); + ~GeometryNode(); + void setMaterial(std::unique_ptr material); + void setGeometry(std::unique_ptr geometry); + Geometry& geometry() const; + Material& material() const; + + private: + GeometryNode(NodeImplBase* pImpl); + std::unique_ptr m_material; + std::unique_ptr m_geometry; +}; diff --git a/src/rendergraph/material.cpp b/src/rendergraph/material.cpp new file mode 100644 index 00000000000..7f45a2ead86 --- /dev/null +++ b/src/rendergraph/material.cpp @@ -0,0 +1,20 @@ +#include "rendergraph/material.h" + +#include "material_impl.h" + +using namespace rendergraph; + +Material::Material(Impl* pImpl, const UniformSet& uniformSet) + : m_pImpl(pImpl), + m_uniformsCache(uniformSet) { +} + +Material::Material(const UniformSet& uniformSet) + : Material(new Material::Impl(this), uniformSet) { +} + +Material::~Material() = default; + +Material::Impl& Material::impl() const { + return *m_pImpl; +} diff --git a/src/rendergraph/material.h b/src/rendergraph/material.h new file mode 100644 index 00000000000..e1644d5bb00 --- /dev/null +++ b/src/rendergraph/material.h @@ -0,0 +1,52 @@ +#pragma once + +#include "rendergraph/uniformscache.h" + +namespace rendergraph { +class UniformSet; +class Material; +class MaterialShader; +class MaterialType; +class Texture; +} // namespace rendergraph + +class rendergraph::Material { + public: + class Impl; + + Material(const UniformSet& uniformSet); + virtual ~Material(); + virtual int compare(const Material* other) const = 0; + virtual MaterialShader* createShader() const = 0; + virtual MaterialType* type() const = 0; + + template + void setUniform(int uniformIndex, const T& value) { + m_uniformsCache.set(uniformIndex, value); + m_uniformsCacheDirty = true; + } + + Impl& impl() const; + const UniformsCache& uniformsCache() const { + return m_uniformsCache; + } + + bool clearUniformsCacheDirty() { + if (m_uniformsCacheDirty) { + m_uniformsCacheDirty = false; + return true; + } + return false; + } + + virtual Texture* texture(int /*binding*/) const { + return nullptr; + } + + private: + Material(Impl* pImpl, const UniformSet& uniformSet); + + const std::unique_ptr m_pImpl; + UniformsCache m_uniformsCache; + bool m_uniformsCacheDirty{}; +}; diff --git a/src/rendergraph/materialshader.cpp b/src/rendergraph/materialshader.cpp new file mode 100644 index 00000000000..6d27917b4be --- /dev/null +++ b/src/rendergraph/materialshader.cpp @@ -0,0 +1,25 @@ +#include "rendergraph/materialshader.h" + +#include "materialshader_impl.h" + +using namespace rendergraph; + +MaterialShader::MaterialShader(Impl* pImpl) + : m_pImpl(pImpl) { +} + +MaterialShader::MaterialShader(const char* vertexShaderFile, + const char* fragmentShaderFile, + const UniformSet& uniformSet, + const AttributeSet& attributeSet) + : MaterialShader(new MaterialShader::Impl(this, + vertexShaderFile, + fragmentShaderFile, + uniformSet, + attributeSet)){}; + +MaterialShader::~MaterialShader() = default; + +MaterialShader::Impl& MaterialShader::impl() const { + return *m_pImpl; +} diff --git a/src/rendergraph/materialshader.h b/src/rendergraph/materialshader.h new file mode 100644 index 00000000000..e696a520b6b --- /dev/null +++ b/src/rendergraph/materialshader.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace rendergraph { +class AttributeSet; +class UniformSet; +class MaterialShader; +} // namespace rendergraph + +class rendergraph::MaterialShader { + public: + class Impl; + + MaterialShader(const char* vertexShaderFile, + const char* fragmentShaderFile, + const UniformSet& uniforms, + const AttributeSet& attributeSet); + ~MaterialShader(); + Impl& impl() const; + + private: + MaterialShader(Impl* pImpl); + + const std::unique_ptr m_pImpl; +}; diff --git a/src/rendergraph/materialtype.cpp b/src/rendergraph/materialtype.cpp new file mode 100644 index 00000000000..8249ee89f03 --- /dev/null +++ b/src/rendergraph/materialtype.cpp @@ -0,0 +1,18 @@ +#include "rendergraph/materialtype.h" + +#include "materialtype_impl.h" + +using namespace rendergraph; + +MaterialType::MaterialType(Impl* pImpl) + : m_pImpl(pImpl) { +} + +MaterialType::MaterialType() + : MaterialType(new MaterialType::Impl()){}; + +MaterialType::~MaterialType() = default; + +MaterialType::Impl& MaterialType::impl() const { + return *m_pImpl; +} diff --git a/src/rendergraph/materialtype.h b/src/rendergraph/materialtype.h new file mode 100644 index 00000000000..06d85f131cf --- /dev/null +++ b/src/rendergraph/materialtype.h @@ -0,0 +1,21 @@ +#pragma once + +#include + +namespace rendergraph { +class MaterialType; +} + +class rendergraph::MaterialType { + public: + class Impl; + + MaterialType(); + ~MaterialType(); + Impl& impl() const; + + private: + MaterialType(Impl* pImpl); + + const std::unique_ptr m_pImpl; +}; diff --git a/src/rendergraph/node.cpp b/src/rendergraph/node.cpp new file mode 100644 index 00000000000..4334fd7abbc --- /dev/null +++ b/src/rendergraph/node.cpp @@ -0,0 +1,35 @@ +#include "rendergraph/node.h" + +#include "node_impl.h" + +using namespace rendergraph; + +Node::Node(NodeImplBase* pImpl) + : m_pImpl(pImpl) { +} + +Node::Node() + : Node(new Node::Impl(this)) { +} + +Node::~Node() = default; + +NodeImplBase& Node::impl() const { + return *m_pImpl; +} + +void Node::appendChildNode(std::unique_ptr pChild) { + impl().appendChildNode(std::move(pChild)); +} + +void Node::removeAllChildNodes() { + impl().removeAllChildNodes(); +} + +void Node::setUsePreprocess(bool value) { + impl().setUsePreprocess(value); +} + +Node* Node::lastChild() const { + return impl().lastChild(); +} diff --git a/src/rendergraph/node.h b/src/rendergraph/node.h new file mode 100644 index 00000000000..c9865402dcd --- /dev/null +++ b/src/rendergraph/node.h @@ -0,0 +1,38 @@ +#pragma once + +#include + +namespace rendergraph { +class Node; +class NodeImplBase; +} // namespace rendergraph + +class rendergraph::Node { + public: + class Impl; + + Node(); + + virtual ~Node(); + + void appendChildNode(std::unique_ptr pChild); + void removeAllChildNodes(); + Node* lastChild() const; + + NodeImplBase& impl() const; + + virtual bool isSubtreeBlocked() const { + return false; + } + + virtual void preprocess() { + } + + void setUsePreprocess(bool value); + + protected: + Node(NodeImplBase* impl); + + private: + const std::unique_ptr m_pImpl; +}; diff --git a/src/rendergraph/opacitynode.cpp b/src/rendergraph/opacitynode.cpp new file mode 100644 index 00000000000..9be655c4ee4 --- /dev/null +++ b/src/rendergraph/opacitynode.cpp @@ -0,0 +1,19 @@ +#include "rendergraph/opacitynode.h" + +#include "opacitynode_impl.h" + +using namespace rendergraph; + +OpacityNode::OpacityNode(NodeImplBase* pImpl) + : Node(pImpl) { +} + +OpacityNode::OpacityNode() + : OpacityNode(new OpacityNode::Impl(this)) { +} + +OpacityNode::~OpacityNode() = default; + +void OpacityNode::setOpacity(float opacity) { + static_cast(impl()).setOpacity(opacity); +} diff --git a/src/rendergraph/opacitynode.h b/src/rendergraph/opacitynode.h new file mode 100644 index 00000000000..a95bc3a58f4 --- /dev/null +++ b/src/rendergraph/opacitynode.h @@ -0,0 +1,19 @@ +#pragma once + +#include "rendergraph/node.h" + +namespace rendergraph { +class OpacityNode; +} // namespace rendergraph + +class rendergraph::OpacityNode : public rendergraph::Node { + public: + class Impl; + + OpacityNode(); + ~OpacityNode(); + void setOpacity(float opacity); + + private: + OpacityNode(NodeImplBase* pImpl); +}; diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt new file mode 100644 index 00000000000..08e85b9784b --- /dev/null +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -0,0 +1,54 @@ +add_library(rendergraph_gl + ../attribute.h + ../attributeset.cpp + ../attributeset.h + ../context.cpp + ../context.h + ../geometry.cpp + ../geometry.h + ../geometrynode.cpp + ../geometrynode.h + ../material.cpp + ../material.h + ../materialshader.cpp + ../materialshader.h + ../materialtype.cpp + ../materialtype.h + ../node.cpp + ../node.h + ../opacitynode.cpp + ../opacitynode.h + ../texture.cpp + ../texture.h + ../types.cpp + ../types.h + ../uniform.h + ../uniformscache.cpp + ../uniformscache.h + ../uniformset.cpp + ../uniformset.h + geometrynode_impl.cpp + graph.cpp + graph.h + materialshader_impl.cpp + openglnode.cpp + openglnode.h + private/attributeset_impl.h + private/context_impl.h + private/geometry_impl.h + private/geometrynode_impl.h + private/material_impl.h + private/materialshader_impl.h + private/materialtype_impl.h + private/node_impl.h + private/opacitynode_impl.h + private/texture_impl.h +) + +target_link_libraries(rendergraph_gl PUBLIC + Qt6::Core + Qt6::Gui + Qt6::OpenGL +) + +target_include_directories(rendergraph_gl PUBLIC ../.. PRIVATE private) diff --git a/src/rendergraph/opengl/geometrynode_impl.cpp b/src/rendergraph/opengl/geometrynode_impl.cpp new file mode 100644 index 00000000000..66ab05c50fd --- /dev/null +++ b/src/rendergraph/opengl/geometrynode_impl.cpp @@ -0,0 +1,83 @@ +#include "geometrynode_impl.h" + +#include "geometry_impl.h" + +using namespace rendergraph; + +namespace { +GLenum toGlDrawingMode(Geometry::DrawingMode mode) { + switch (mode) { + case Geometry::DrawingMode::Triangles: + return GL_TRIANGLES; + case Geometry::DrawingMode::TriangleStrip: + return GL_TRIANGLE_STRIP; + } +} +} // namespace + +void GeometryNode::Impl::render() { + glEnable(GL_BLEND); + // qt scene graph uses premultiplied alpha color in the shader, + // so we need to do the same + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + + Material::Impl& material = m_pMaterial->impl(); + Geometry::Impl& geometry = m_pGeometry->impl(); + + QOpenGLShaderProgram& shader = material.glShader(); + shader.bind(); + + if (m_pMaterial->clearUniformsCacheDirty()) { + const UniformsCache& cache = m_pMaterial->uniformsCache(); + for (int i = 0; i < cache.count(); i++) { + int location = material.uniformLocation(i); + switch (cache.type(i)) { + case Type::UInt: + shader.setUniformValue(location, cache.get(i)); + break; + case Type::Float: + shader.setUniformValue(location, cache.get(i)); + break; + case Type::Vector2D: + shader.setUniformValue(location, cache.get(i)); + break; + case Type::Vector3D: + shader.setUniformValue(location, cache.get(i)); + break; + case Type::Vector4D: + shader.setUniformValue(location, cache.get(i)); + break; + case Type::Matrix4x4: + shader.setUniformValue(location, cache.get(i)); + break; + } + } + } + + for (int i = 0; i < geometry.attributeCount(); i++) { + int location = material.attributeLocation(i); + shader.enableAttributeArray(location); + shader.setAttributeArray(location, geometry.vertexData(i), geometry.tupleSize(i)); + } + + // TODO multiple textures + auto pTexture = m_pMaterial->texture(1); + if (pTexture) { + pTexture->impl().glTexture()->bind(); + } + + glDrawArrays(toGlDrawingMode(geometry.drawingMode()), 0, geometry.vertexCount()); + + if (pTexture) { + pTexture->impl().glTexture()->release(); + } + + for (int i = 0; i < geometry.attributeCount(); i++) { + int location = material.attributeLocation(i); + shader.disableAttributeArray(location); + } + + shader.release(); + + Node::Impl::render(); +} diff --git a/src/rendergraph/opengl/graph.cpp b/src/rendergraph/opengl/graph.cpp new file mode 100644 index 00000000000..d0be84bed25 --- /dev/null +++ b/src/rendergraph/opengl/graph.cpp @@ -0,0 +1,35 @@ +#include "rendergraph/opengl/graph.h" + +#include "rendergraph/node.h" +#include "rendergraph/opengl/private/node_impl.h" + +using namespace rendergraph; + +Graph::Graph(std::unique_ptr node) + : m_pTopNode(std::move(node)) { + m_pTopNode->impl().addToPreprocessNodes(&m_pPreprocessNodes); +} + +Graph::~Graph() = default; + +void Graph::initialize() { + m_pTopNode->impl().initialize(); +} + +void Graph::render() { + if (!m_pTopNode->impl().isSubtreeBlocked()) { + m_pTopNode->impl().render(); + } +} + +void Graph::resize(int w, int h) { + m_pTopNode->impl().resize(w, h); +} + +void Graph::preprocess() { + for (auto pNode : m_pPreprocessNodes) { + if (!pNode->impl().isSubtreeBlocked()) { + pNode->preprocess(); + } + } +} diff --git a/src/rendergraph/opengl/graph.h b/src/rendergraph/opengl/graph.h new file mode 100644 index 00000000000..538035aef81 --- /dev/null +++ b/src/rendergraph/opengl/graph.h @@ -0,0 +1,25 @@ +#pragma once + +#include +#include + +namespace rendergraph { +class Graph; +class Node; +} // namespace rendergraph + +class rendergraph::Graph { + public: + class Impl; + Graph(std::unique_ptr node); + ~Graph(); + Impl& impl() const; + void initialize(); + void render(); + void resize(int w, int h); + void preprocess(); + + private: + const std::unique_ptr m_pTopNode; + std::vector m_pPreprocessNodes; +}; diff --git a/src/rendergraph/opengl/materialshader_impl.cpp b/src/rendergraph/opengl/materialshader_impl.cpp new file mode 100644 index 00000000000..188bac4006d --- /dev/null +++ b/src/rendergraph/opengl/materialshader_impl.cpp @@ -0,0 +1,25 @@ +#include "materialshader_impl.h" + +#include "rendergraph/attributeset.h" +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +MaterialShader::Impl::Impl(MaterialShader* pOwner, + const char* vertexShaderFile, + const char* fragmentShaderFile, + const UniformSet& uniformSet, + const AttributeSet& attributeSet) + : m_pOwner(pOwner) { + addShaderFromSourceFile(QOpenGLShader::Vertex, resource(vertexShaderFile)); + addShaderFromSourceFile(QOpenGLShader::Fragment, resource(fragmentShaderFile)); + link(); + for (const auto& attribute : attributeSet.attributes()) { + int location = QOpenGLShaderProgram::attributeLocation(attribute.m_name); + m_attributeLocations.push_back(location); + } + for (const auto& uniform : uniformSet.uniforms()) { + int location = QOpenGLShaderProgram::uniformLocation(uniform.m_name); + m_uniformLocations.push_back(location); + } +} diff --git a/src/rendergraph/opengl/openglnode.cpp b/src/rendergraph/opengl/openglnode.cpp new file mode 100644 index 00000000000..5455ce79ab5 --- /dev/null +++ b/src/rendergraph/opengl/openglnode.cpp @@ -0,0 +1,15 @@ +#include "rendergraph/opengl/openglnode.h" + +#include "openglnode_impl.h" + +using namespace rendergraph; + +OpenGLNode::OpenGLNode(NodeImplBase* pImpl) + : Node(pImpl) { +} + +OpenGLNode::OpenGLNode() + : OpenGLNode(new OpenGLNode::Impl(this)) { +} + +OpenGLNode::~OpenGLNode() = default; diff --git a/src/rendergraph/opengl/openglnode.h b/src/rendergraph/opengl/openglnode.h new file mode 100644 index 00000000000..a618631bab0 --- /dev/null +++ b/src/rendergraph/opengl/openglnode.h @@ -0,0 +1,27 @@ +#pragma once + +#include + +#include "rendergraph/node.h" + +namespace rendergraph { +class OpenGLNode; +} // namespace rendergraph + +class rendergraph::OpenGLNode : public rendergraph::Node, public QOpenGLFunctions { + public: + class Impl; + + OpenGLNode(); + ~OpenGLNode(); + + virtual void initializeGL() { + } + virtual void paintGL() { + } + virtual void resizeGL(int, int) { + } + + private: + OpenGLNode(NodeImplBase* pImpl); +}; diff --git a/src/rendergraph/opengl/private/attributeset_impl.h b/src/rendergraph/opengl/private/attributeset_impl.h new file mode 100644 index 00000000000..af6187da11a --- /dev/null +++ b/src/rendergraph/opengl/private/attributeset_impl.h @@ -0,0 +1,17 @@ +#pragma once + +#include "rendergraph/attributeset.h" + +class rendergraph::AttributeSet::Impl { + public: + void add(const Attribute& attribute) { + m_attributes.push_back(attribute); + } + + const std::vector& attributes() const { + return m_attributes; + } + + private: + std::vector m_attributes; +}; diff --git a/src/rendergraph/opengl/private/context_impl.h b/src/rendergraph/opengl/private/context_impl.h new file mode 100644 index 00000000000..e5afe9f870a --- /dev/null +++ b/src/rendergraph/opengl/private/context_impl.h @@ -0,0 +1,6 @@ +#pragma once + +#include "rendergraph/context.h" + +class rendergraph::Context::Impl { +}; diff --git a/src/rendergraph/opengl/private/geometry_impl.h b/src/rendergraph/opengl/private/geometry_impl.h new file mode 100644 index 00000000000..3f59a286f06 --- /dev/null +++ b/src/rendergraph/opengl/private/geometry_impl.h @@ -0,0 +1,53 @@ +#pragma once + +#include "attributeset_impl.h" +#include "rendergraph/geometry.h" + +class rendergraph::Geometry::Impl { + public: + Impl(const AttributeSet& attributeSet, int vertexCount) + : m_drawingMode(Geometry::DrawingMode::TriangleStrip) // to mimic sg default + , + m_vertexCount(vertexCount) { + for (const auto& attribute : attributeSet.impl().attributes()) { + m_data.emplace_back(std::vector(m_vertexCount * attribute.m_tupleSize)); + m_tupleSizes.push_back(attribute.m_tupleSize); + } + } + + int attributeCount() const { + return m_tupleSizes.size(); + } + + int vertexCount() const { + return m_vertexCount; + } + + float const* vertexData(int attributeIndex) const { + return m_data[attributeIndex].data(); + } + + int tupleSize(int attributeIndex) const { + return m_tupleSizes[attributeIndex]; + } + + void setAttributeValues(int attributePosition, const float* from, int numTuples) { + memcpy(m_data[attributePosition].data(), + from, + numTuples * m_tupleSizes[attributePosition] * sizeof(float)); + } + + void setDrawingMode(Geometry::DrawingMode mode) { + m_drawingMode = mode; + } + + Geometry::DrawingMode drawingMode() const { + return m_drawingMode; + } + + private: + Geometry::DrawingMode m_drawingMode; + int m_vertexCount; + std::vector m_tupleSizes; + std::vector> m_data; +}; diff --git a/src/rendergraph/opengl/private/geometrynode_impl.h b/src/rendergraph/opengl/private/geometrynode_impl.h new file mode 100644 index 00000000000..0d12ae7474f --- /dev/null +++ b/src/rendergraph/opengl/private/geometrynode_impl.h @@ -0,0 +1,34 @@ +#pragma once + +#include + +#include "material_impl.h" +#include "node_impl.h" +#include "rendergraph/geometrynode.h" + +class rendergraph::GeometryNode::Impl : public rendergraph::Node::Impl, public QOpenGLFunctions { + public: + Impl(GeometryNode* pOwner) + : Node::Impl(pOwner) { + } + + void setGeometry(Geometry* geometry) { + m_pGeometry = geometry; + } + + void setMaterial(Material* material) { + m_pMaterial = material; + } + + void initialize() override { + initializeOpenGLFunctions(); + m_pMaterial->impl().setShader(m_pMaterial->createShader()); + Node::Impl::initialize(); + } + + void render() override; + + private: + Geometry* m_pGeometry{}; + Material* m_pMaterial{}; +}; diff --git a/src/rendergraph/opengl/private/material_impl.h b/src/rendergraph/opengl/private/material_impl.h new file mode 100644 index 00000000000..918f20ded42 --- /dev/null +++ b/src/rendergraph/opengl/private/material_impl.h @@ -0,0 +1,36 @@ +#pragma once + +#include "materialshader_impl.h" +#include "rendergraph/material.h" +#include "texture_impl.h" + +class rendergraph::Material::Impl { + public: + Impl(Material* pOwner) + : m_pOwner(pOwner) { + } + + void setShader(MaterialShader* pShader) { + m_pShader = pShader; + } + + int attributeLocation(int attributeIndex) const { + return m_pShader->impl().attributeLocation(attributeIndex); + } + + QOpenGLTexture* texture(int binding) { + return m_pOwner->texture(binding)->impl().glTexture(); + } + + int uniformLocation(int uniformIndex) const { + return m_pShader->impl().uniformLocation(uniformIndex); + } + + QOpenGLShaderProgram& glShader() const { + return m_pShader->impl().glShader(); + } + + private: + MaterialShader* m_pShader{}; + Material* const m_pOwner; +}; diff --git a/src/rendergraph/opengl/private/materialshader_impl.h b/src/rendergraph/opengl/private/materialshader_impl.h new file mode 100644 index 00000000000..d89797302eb --- /dev/null +++ b/src/rendergraph/opengl/private/materialshader_impl.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +#include "rendergraph/materialshader.h" + +class rendergraph::MaterialShader::Impl : private QOpenGLShaderProgram { + public: + Impl(MaterialShader* pOwner, + const char* vertexShaderFile, + const char* fragmentShaderFile, + const UniformSet& uniformSet, + const AttributeSet& attributeSet); + QOpenGLShaderProgram& glShader() { + return *this; + } + + int attributeLocation(int attributeIndex) const { + return m_attributeLocations[attributeIndex]; + } + + int uniformLocation(int uniformIndex) const { + return m_uniformLocations[uniformIndex]; + } + + private: + static QString resource(const char* filename) { + return QString(":/shaders/rendergraph/") + QString(filename) + QString(".gl"); + } + std::vector m_attributeLocations; + std::vector m_uniformLocations; + MaterialShader* const m_pOwner; +}; diff --git a/src/rendergraph/opengl/private/materialtype_impl.h b/src/rendergraph/opengl/private/materialtype_impl.h new file mode 100644 index 00000000000..51dc3601df2 --- /dev/null +++ b/src/rendergraph/opengl/private/materialtype_impl.h @@ -0,0 +1,9 @@ +#pragma once + +#include "rendergraph/materialtype.h" + +class rendergraph::MaterialType::Impl { + public: + Impl() { + } +}; diff --git a/src/rendergraph/opengl/private/node_impl.h b/src/rendergraph/opengl/private/node_impl.h new file mode 100644 index 00000000000..f3df4b2c801 --- /dev/null +++ b/src/rendergraph/opengl/private/node_impl.h @@ -0,0 +1,78 @@ +#pragma once + +#include + +#include "rendergraph/node.h" + +class rendergraph::NodeImplBase { + public: + NodeImplBase(Node* pOwner) + : m_pOwner(pOwner) { + } + virtual ~NodeImplBase() = default; + + void appendChildNode(std::unique_ptr pChild) { + m_pChildren.emplace_back(std::move(pChild)); + } + + void removeAllChildNodes() { + m_pChildren.clear(); + } + + Node* lastChild() const { + return m_pChildren.back().get(); + } + + virtual void initialize() { + for (auto& pChild : m_pChildren) { + pChild->impl().initialize(); + } + } + + virtual void render() { + for (auto& pChild : m_pChildren) { + if (!pChild->impl().isSubtreeBlocked()) { + pChild->impl().render(); + } + } + } + + virtual void resize(int w, int h) { + for (auto& pChild : m_pChildren) { + pChild->impl().resize(w, h); + } + } + + virtual bool isSubtreeBlocked() const { + return m_pOwner->isSubtreeBlocked(); + } + + Node* owner() const { + return m_pOwner; + } + + void addToPreprocessNodes(std::vector* preprocessNodes) { + if (m_usePreprocess) { + preprocessNodes->push_back(m_pOwner); + } + for (auto& pChild : m_pChildren) { + pChild->impl().addToPreprocessNodes(preprocessNodes); + } + } + + void setUsePreprocess(bool value) { + m_usePreprocess = value; + } + + private: + Node* const m_pOwner; + std::vector> m_pChildren; + bool m_usePreprocess{}; +}; + +class rendergraph::Node::Impl : public rendergraph::NodeImplBase { + public: + Impl(Node* pOwner) + : NodeImplBase(pOwner) { + } +}; diff --git a/src/rendergraph/opengl/private/opacitynode_impl.h b/src/rendergraph/opengl/private/opacitynode_impl.h new file mode 100644 index 00000000000..6b4f36ec75d --- /dev/null +++ b/src/rendergraph/opengl/private/opacitynode_impl.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include "material_impl.h" +#include "node_impl.h" +#include "rendergraph/opacitynode.h" + +// TODO implement opacity of subnodes. +// For now we only use this for visibility, +// mimicking QSGOpacityNode isSubtreeBlocked() + +class rendergraph::OpacityNode::Impl : public rendergraph::NodeImplBase { + public: + Impl(OpacityNode* pOwner) + : NodeImplBase(pOwner) { + } + void setOpacity(float opacity) { + m_opacity = opacity; + } + + bool isSubtreeBlocked() const override { + return m_opacity == 0.f || NodeImplBase::isSubtreeBlocked(); + } + + private: + float m_opacity{1.f}; +}; diff --git a/src/rendergraph/opengl/private/openglnode_impl.h b/src/rendergraph/opengl/private/openglnode_impl.h new file mode 100644 index 00000000000..a6ea8f8a206 --- /dev/null +++ b/src/rendergraph/opengl/private/openglnode_impl.h @@ -0,0 +1,35 @@ +#pragma once + +#include "node_impl.h" +#include "rendergraph/opengl/openglnode.h" + +class rendergraph::OpenGLNode::Impl : public rendergraph::NodeImplBase { + public: + Impl(OpenGLNode* pOwner) + : NodeImplBase(pOwner) { + } + + ~Impl() { + } + + void initialize() override { + owner()->initializeOpenGLFunctions(); + owner()->initializeGL(); + NodeImplBase::initialize(); + } + + void render() override { + owner()->paintGL(); + NodeImplBase::render(); + } + + void resize(int w, int h) override { + owner()->resizeGL(w, h); + NodeImplBase::resize(w, h); + } + + private: + OpenGLNode* owner() const { + return static_cast(NodeImplBase::owner()); + } +}; diff --git a/src/rendergraph/opengl/private/texture_impl.h b/src/rendergraph/opengl/private/texture_impl.h new file mode 100644 index 00000000000..73ecd89dfdf --- /dev/null +++ b/src/rendergraph/opengl/private/texture_impl.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include "rendergraph/texture.h" + +class rendergraph::Texture::Impl { + public: + Impl(Context& context, const QImage& image) + : m_pTexture(new QOpenGLTexture(image.convertToFormat( + QImage::Format_ARGB32_Premultiplied))) { + } + + QOpenGLTexture* glTexture() const { + return m_pTexture.get(); + } + + private: + const std::unique_ptr m_pTexture{}; +}; diff --git a/src/rendergraph/opengl/private/visiblenode_impl.h b/src/rendergraph/opengl/private/visiblenode_impl.h new file mode 100644 index 00000000000..2730a0037db --- /dev/null +++ b/src/rendergraph/opengl/private/visiblenode_impl.h @@ -0,0 +1,33 @@ +#pragma once + +#include + +#include "material_impl.h" +#include "node_impl.h" +#include "rendergraph/geometrynode.h" + +class rendergraph::GeometryNode::Impl : public rendergraph::Node::Impl, public QOpenGLFunctions { + public: + Impl() { + } + + void setGeometry(Geometry* geometry) { + m_pGeometry = geometry; + } + + void setMaterial(Material* material) { + m_pMaterial = material; + } + + void initialize() override { + initializeOpenGLFunctions(); + m_pMaterial->impl().setShader(m_pMaterial->createShader()); + Node::Impl::initialize(); + } + + void render() override; + + private: + Geometry* m_pGeometry{}; + Material* m_pMaterial{}; +}; diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt new file mode 100644 index 00000000000..fe6260420e1 --- /dev/null +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -0,0 +1,53 @@ +add_library(rendergraph_sg + ../attribute.h + ../attributeset.cpp + ../attributeset.h + ../context.cpp + ../context.h + ../geometry.cpp + ../geometry.h + ../geometrynode.cpp + ../geometrynode.h + ../material.cpp + ../material.h + ../materialshader.cpp + ../materialshader.h + ../materialtype.cpp + ../materialtype.h + ../node.cpp + ../node.h + ../opacitynode.cpp + ../opacitynode.h + ../texture.cpp + ../texture.h + ../types.cpp + ../types.h + ../uniform.h + ../uniformscache.cpp + ../uniformscache.h + ../uniformset.cpp + ../uniformset.h + materialshader_impl.cpp + private/attributeset_impl.h + private/context_impl.h + private/geometry_impl.h + private/geometrynode_impl.h + private/material_impl.h + private/materialshader_impl.h + private/materialtype_impl.h + private/node_impl.h + private/opacitynode_impl.h + private/texture_impl.h + scenegraph.cpp + scenegraph.h + texture_impl.cpp +) + +target_link_libraries(rendergraph_sg PUBLIC + Qt6::Core + Qt6::Gui + Qt6::Qml + Qt6::Quick +) + +target_include_directories(rendergraph_sg PUBLIC ../.. PRIVATE private) diff --git a/src/rendergraph/scenegraph/materialshader_impl.cpp b/src/rendergraph/scenegraph/materialshader_impl.cpp new file mode 100644 index 00000000000..5b95250e6c8 --- /dev/null +++ b/src/rendergraph/scenegraph/materialshader_impl.cpp @@ -0,0 +1,22 @@ +#include "materialshader_impl.h" + +#include "material_impl.h" + +using namespace rendergraph; + +bool rendergraph::MaterialShader::Impl::updateUniformData(RenderState& state, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) { + Material::Impl* pMaterialImpl = static_cast(newMaterial); + return pMaterialImpl->updateUniformsByteArray(state.uniformData()); +} + +void MaterialShader::Impl::updateSampledImage(RenderState& state, + int binding, + QSGTexture** texture, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) { + Material::Impl* pMaterialImpl = static_cast(newMaterial); + *texture = pMaterialImpl->texture(binding); + (*texture)->commitTextureOperations(state.rhi(), state.resourceUpdateBatch()); +} diff --git a/src/rendergraph/scenegraph/private/attributeset_impl.h b/src/rendergraph/scenegraph/private/attributeset_impl.h new file mode 100644 index 00000000000..45cc8714cfc --- /dev/null +++ b/src/rendergraph/scenegraph/private/attributeset_impl.h @@ -0,0 +1,37 @@ +#pragma once + +#include + +#include "rendergraph/attributeset.h" + +class rendergraph::AttributeSet::Impl { + public: + void add(const Attribute& attribute) { + const int count = static_cast(m_sgAttributes.size()); + const bool isPosition = count == 0; + m_sgAttributes.push_back(QSGGeometry::Attribute::create(count, + attribute.m_tupleSize, + toQSGGeometryType(attribute.m_primitiveType), + isPosition)); + const int stride = m_sgAttributeSet.stride + + attribute.m_tupleSize * sizeOf(attribute.m_primitiveType); + m_sgAttributeSet = QSGGeometry::AttributeSet{count + 1, stride, m_sgAttributes.data()}; + } + + const QSGGeometry::AttributeSet& sgAttributeSet() const { + return m_sgAttributeSet; + } + + private: + QSGGeometry::AttributeSet m_sgAttributeSet{}; + std::vector m_sgAttributes; + + int toQSGGeometryType(const rendergraph::PrimitiveType& t) { + switch (t) { + case rendergraph::PrimitiveType::Float: + return QSGGeometry::FloatType; + case rendergraph::PrimitiveType::UInt: + return QSGGeometry::UnsignedIntType; + } + } +}; diff --git a/src/rendergraph/scenegraph/private/context_impl.h b/src/rendergraph/scenegraph/private/context_impl.h new file mode 100644 index 00000000000..bce2fb3ac76 --- /dev/null +++ b/src/rendergraph/scenegraph/private/context_impl.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +#include "rendergraph/context.h" + +class rendergraph::Context::Impl { + public: + void setWindow(QQuickWindow* pWindow) { + m_pWindow = pWindow; + } + QQuickWindow* window() const { + return m_pWindow; + } + + private: + QQuickWindow* m_pWindow; +}; diff --git a/src/rendergraph/scenegraph/private/geometry_impl.h b/src/rendergraph/scenegraph/private/geometry_impl.h new file mode 100644 index 00000000000..fa6ea95e5e5 --- /dev/null +++ b/src/rendergraph/scenegraph/private/geometry_impl.h @@ -0,0 +1,69 @@ +#pragma once + +#include + +#include "attributeset_impl.h" +#include "rendergraph/geometry.h" + +class rendergraph::Geometry::Impl : public QSGGeometry { + public: + Impl(const rendergraph::AttributeSet& rgAttributeSet, int vertexCount) + : QSGGeometry(rgAttributeSet.impl().sgAttributeSet(), vertexCount), + m_stride(rgAttributeSet.impl().sgAttributeSet().stride) { + QSGGeometry::setDrawingMode(QSGGeometry::DrawTriangleStrip); + } + + QSGGeometry* sgGeometry() { + return this; + } + + void setAttributeValues(int attributePosition, const float* from, int numTuples) { + const auto attributeArray = QSGGeometry::attributes(); + int offset = 0; + for (int i = 0; i < attributePosition; i++) { + offset += attributeArray[i].tupleSize; + } + const int tupleSize = attributeArray[attributePosition].tupleSize; + const int skip = m_stride / sizeof(float) - tupleSize; + + float* to = static_cast(QSGGeometry::vertexData()); + to += offset; + while (numTuples--) { + int k = tupleSize; + while (k--) { + *to++ = *from++; + } + to += skip; + } + } + + void setDrawingMode(Geometry::DrawingMode mode) { + QSGGeometry::setDrawingMode(toSgDrawingMode(mode)); + } + + Geometry::DrawingMode drawingMode() const { + return fromSgDrawingMode(QSGGeometry::drawingMode()); + } + + private: + const int m_stride; + + static QSGGeometry::DrawingMode toSgDrawingMode(Geometry::DrawingMode mode) { + switch (mode) { + case Geometry::DrawingMode::Triangles: + return QSGGeometry::DrawTriangles; + case Geometry::DrawingMode::TriangleStrip: + return QSGGeometry::DrawTriangleStrip; + } + } + static Geometry::DrawingMode fromSgDrawingMode(unsigned int mode) { + switch (mode) { + case QSGGeometry::DrawTriangles: + return Geometry::DrawingMode::Triangles; + case QSGGeometry::DrawTriangleStrip: + return Geometry::DrawingMode::TriangleStrip; + default: + throw "not implemented"; + } + } +}; diff --git a/src/rendergraph/scenegraph/private/geometrynode_impl.h b/src/rendergraph/scenegraph/private/geometrynode_impl.h new file mode 100644 index 00000000000..1717df1b063 --- /dev/null +++ b/src/rendergraph/scenegraph/private/geometrynode_impl.h @@ -0,0 +1,28 @@ +#pragma once + +#include "geometry_impl.h" +#include "material_impl.h" +#include "node_impl.h" +#include "rendergraph/geometrynode.h" + +class rendergraph::GeometryNode::Impl : public QSGGeometryNode, public rendergraph::NodeImplBase { + public: + Impl(GeometryNode* pOwner) + : NodeImplBase(pOwner) { + } + QSGNode* sgNode() override { + return this; + } + void setGeometry(Geometry* geometry) { + QSGGeometryNode::setGeometry(geometry->impl().sgGeometry()); + } + void setMaterial(Material* material) { + QSGGeometryNode::setMaterial(material->impl().sgMaterial()); + } + void preprocess() override { + owner()->preprocess(); + } + bool isSubtreeBlocked() const override { + return owner()->isSubtreeBlocked(); + } +}; diff --git a/src/rendergraph/scenegraph/private/material_impl.h b/src/rendergraph/scenegraph/private/material_impl.h new file mode 100644 index 00000000000..d4779eb1517 --- /dev/null +++ b/src/rendergraph/scenegraph/private/material_impl.h @@ -0,0 +1,48 @@ +#pragma once + +#include + +#include "materialshader_impl.h" +#include "materialtype_impl.h" +#include "rendergraph/material.h" +#include "texture_impl.h" + +class rendergraph::Material::Impl : public QSGMaterial { + public: + Impl(Material* pOwner) + : m_pOwner(pOwner) { + setFlag(QSGMaterial::Blending); + } + + QSGMaterial* sgMaterial() { + return this; + } + + bool updateUniformsByteArray(QByteArray* buf) { + if (m_pOwner->clearUniformsCacheDirty()) { + memcpy(buf->data(), m_pOwner->uniformsCache().data(), m_pOwner->uniformsCache().size()); + return true; + } + return false; + } + + QSGTexture* texture(int binding) { + return m_pOwner->texture(binding)->impl().sgTexture(); + } + + private: + QSGMaterialType* type() const override { + return m_pOwner->type()->impl().sgMaterialType(); + } + + int compare(const QSGMaterial* other) const override { + const Impl* otherCasted = static_cast(other); + return otherCasted && m_pOwner->compare(otherCasted->m_pOwner); + } + + QSGMaterialShader* createShader(QSGRendererInterface::RenderMode) const override { + return m_pOwner->createShader()->impl().sgMaterialShader(); + } + + Material* m_pOwner; +}; diff --git a/src/rendergraph/scenegraph/private/materialshader_impl.h b/src/rendergraph/scenegraph/private/materialshader_impl.h new file mode 100644 index 00000000000..3067e605c0e --- /dev/null +++ b/src/rendergraph/scenegraph/private/materialshader_impl.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +#include "rendergraph/materialshader.h" + +class rendergraph::MaterialShader::Impl : public QSGMaterialShader { + public: + Impl(MaterialShader* pOwner, + const char* vertexShaderFile, + const char* fragmentShaderFile, + const UniformSet& uniformSet, + const AttributeSet& attributeSet) + : m_pOwner(pOwner) { + (void)uniformSet; + (void)attributeSet; + setShaderFileName(VertexStage, resource(vertexShaderFile)); + setShaderFileName(FragmentStage, resource(fragmentShaderFile)); + } + + QSGMaterialShader* sgMaterialShader() { + return this; + } + + private: + bool updateUniformData(RenderState& state, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) override; + + void updateSampledImage(RenderState& state, + int binding, + QSGTexture** texture, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) override; + + static QString resource(const char* filename) { + return QString(":/shaders/rendergraph/") + QString(filename) + QString(".qsb"); + } + + MaterialShader* m_pOwner; +}; diff --git a/src/rendergraph/scenegraph/private/materialtype_impl.h b/src/rendergraph/scenegraph/private/materialtype_impl.h new file mode 100644 index 00000000000..c48df486446 --- /dev/null +++ b/src/rendergraph/scenegraph/private/materialtype_impl.h @@ -0,0 +1,12 @@ +#pragma once + +#include + +#include "rendergraph/materialtype.h" + +class rendergraph::MaterialType::Impl : public QSGMaterialType { + public: + QSGMaterialType* sgMaterialType() { + return this; + } +}; diff --git a/src/rendergraph/scenegraph/private/node_impl.h b/src/rendergraph/scenegraph/private/node_impl.h new file mode 100644 index 00000000000..e72c6bda0a4 --- /dev/null +++ b/src/rendergraph/scenegraph/private/node_impl.h @@ -0,0 +1,56 @@ +#pragma once + +#include + +#include "rendergraph/node.h" + +class rendergraph::NodeImplBase { + public: + NodeImplBase(Node* pOwner) + : m_pOwner(pOwner) { + } + virtual ~NodeImplBase() = default; + + void appendChildNode(std::unique_ptr pChild) { + sgNode()->appendChildNode(pChild->impl().sgNode()); + m_pChildren.emplace_back(std::move(pChild)); + } + void removeAllChildNodes() { + sgNode()->removeAllChildNodes(); + m_pChildren.clear(); + } + + Node* lastChild() const { + return m_pChildren.back().get(); + } + + virtual QSGNode* sgNode() = 0; + + Node* owner() const { + return m_pOwner; + } + + void setUsePreprocess(bool value) { + sgNode()->setFlag(QSGNode::UsePreprocess, value); + } + + private: + Node* m_pOwner; + std::vector> m_pChildren; +}; + +class rendergraph::Node::Impl : public QSGNode, public rendergraph::NodeImplBase { + public: + Impl(Node* pOwner) + : NodeImplBase(pOwner) { + } + QSGNode* sgNode() override { + return this; + } + bool isSubtreeBlocked() const override { + return owner()->isSubtreeBlocked(); + } + void preprocess() override { + owner()->preprocess(); + } +}; diff --git a/src/rendergraph/scenegraph/private/opacitynode_impl.h b/src/rendergraph/scenegraph/private/opacitynode_impl.h new file mode 100644 index 00000000000..aa19bc8f6e7 --- /dev/null +++ b/src/rendergraph/scenegraph/private/opacitynode_impl.h @@ -0,0 +1,23 @@ +#pragma once + +#include "node_impl.h" +#include "rendergraph/opacitynode.h" + +class rendergraph::OpacityNode::Impl : public QSGOpacityNode, public rendergraph::NodeImplBase { + public: + Impl(OpacityNode* pOwner) + : NodeImplBase(pOwner) { + } + + QSGNode* sgNode() override { + return this; + } + + void preprocess() override { + owner()->preprocess(); + } + + bool isSubtreeBlocked() const override { + return QSGOpacityNode::isSubtreeBlocked() || owner()->isSubtreeBlocked(); + } +}; diff --git a/src/rendergraph/scenegraph/private/texture_impl.h b/src/rendergraph/scenegraph/private/texture_impl.h new file mode 100644 index 00000000000..eea6d6d6a29 --- /dev/null +++ b/src/rendergraph/scenegraph/private/texture_impl.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include "rendergraph/texture.h" + +// We can't use inheritance because QSGTexture has pure virtuals that we can't +// implement, so we encapsulate instead. +class rendergraph::Texture::Impl { + public: + Impl(Context& context, const QImage& image); + + QSGTexture* sgTexture() const { + return m_pTexture.get(); + } + + private: + std::unique_ptr m_pTexture{}; +}; diff --git a/src/rendergraph/scenegraph/scenegraph.cpp b/src/rendergraph/scenegraph/scenegraph.cpp new file mode 100644 index 00000000000..efb0f63a0f8 --- /dev/null +++ b/src/rendergraph/scenegraph/scenegraph.cpp @@ -0,0 +1,16 @@ +#include "scenegraph.h" + +#include "context_impl.h" +#include "node_impl.h" + +using namespace rendergraph; + +QSGNode* rendergraph::sgNode(Node* pNode) { + return pNode->impl().sgNode(); +} + +std::unique_ptr rendergraph::createSgContext(QQuickWindow* window) { + auto context = std::make_unique(); + context->impl().setWindow(window); + return context; +} diff --git a/src/rendergraph/scenegraph/scenegraph.h b/src/rendergraph/scenegraph/scenegraph.h new file mode 100644 index 00000000000..3924cf35119 --- /dev/null +++ b/src/rendergraph/scenegraph/scenegraph.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include +#include + +namespace rendergraph { +class Context; +class Node; + +std::unique_ptr createSgContext(QQuickWindow* window); +QSGNode* sgNode(Node* pNode); +} // namespace rendergraph diff --git a/src/rendergraph/scenegraph/texture_impl.cpp b/src/rendergraph/scenegraph/texture_impl.cpp new file mode 100644 index 00000000000..1416d4312e4 --- /dev/null +++ b/src/rendergraph/scenegraph/texture_impl.cpp @@ -0,0 +1,9 @@ +#include "texture_impl.h" + +#include "context_impl.h" + +using namespace rendergraph; + +Texture::Impl::Impl(Context& context, const QImage& image) + : m_pTexture(context.impl().window()->createTextureFromImage(image)) { +} diff --git a/src/rendergraph/texture.cpp b/src/rendergraph/texture.cpp new file mode 100644 index 00000000000..3d16c12189e --- /dev/null +++ b/src/rendergraph/texture.cpp @@ -0,0 +1,19 @@ +#include "rendergraph/texture.h" + +#include "texture_impl.h" + +using namespace rendergraph; + +Texture::Texture(Impl* pImpl) + : m_pImpl(pImpl) { +} + +Texture::Texture(Context& context, const QImage& image) + : Texture(new Texture::Impl(context, image)) { +} + +Texture::~Texture() = default; + +Texture::Impl& Texture::impl() const { + return *m_pImpl; +} diff --git a/src/rendergraph/texture.h b/src/rendergraph/texture.h new file mode 100644 index 00000000000..8069a8192bb --- /dev/null +++ b/src/rendergraph/texture.h @@ -0,0 +1,22 @@ +#pragma once + +#include + +namespace rendergraph { +class Context; +class Texture; +} // namespace rendergraph + +class rendergraph::Texture { + public: + class Impl; + + Texture(Context& context, const QImage& image); + ~Texture(); + Impl& impl() const; + + private: + Texture(Impl* pImpl); + + const std::unique_ptr m_pImpl; +}; diff --git a/src/rendergraph/trash b/src/rendergraph/trash new file mode 100644 index 00000000000..55a577b26d0 --- /dev/null +++ b/src/rendergraph/trash @@ -0,0 +1,25 @@ +#pragma once + +#pragma once + +#include +#include +#include +#include + +namespace rendergraph { +struct Attribute; +class AttributeSet; +struct Uniform; +class UniformSet; +class UniformsCache; +class MaterialType; +class MaterialShader; +class Texture; +class Material; +class Geometry; +class Node; +class GeometryNode; +class RenderGraph; +class Context; +} diff --git a/src/rendergraph/types.cpp b/src/rendergraph/types.cpp new file mode 100644 index 00000000000..2962b47e190 --- /dev/null +++ b/src/rendergraph/types.cpp @@ -0,0 +1,111 @@ +#include "rendergraph/types.h" + +#include +#include +#include +#include +#include + +using namespace rendergraph; + +int rendergraph::sizeOf(PrimitiveType type) { + switch (type) { + case PrimitiveType::UInt: + return sizeof(GLuint); + case PrimitiveType::Float: + return sizeof(GLfloat); + } + return 0; +} + +int rendergraph::sizeOf(Type type) { + switch (type) { + case Type::UInt: + return sizeof(GLuint); + case Type::Float: + return sizeof(GLfloat); + case Type::Vector2D: + return sizeof(QVector2D); + case Type::Vector3D: + return sizeof(QVector3D); + case Type::Vector4D: + return sizeof(QVector4D); + case Type::Matrix4x4: + return sizeof(QMatrix4x4); + } + return 0; +} + +template<> +Type rendergraph::typeOf() { + return Type::UInt; +} + +template<> +Type rendergraph::typeOf() { + return Type::Float; +} + +template<> +Type rendergraph::typeOf() { + return Type::Vector2D; +} + +template<> +Type rendergraph::typeOf() { + return Type::Vector3D; +} + +template<> +Type rendergraph::typeOf() { + return Type::Vector4D; +} + +template<> +Type rendergraph::typeOf() { + return Type::Matrix4x4; +} + +template<> +PrimitiveType rendergraph::primitiveTypeOf() { + return PrimitiveType::Float; +} + +template<> +PrimitiveType rendergraph::primitiveTypeOf() { + return PrimitiveType::UInt; +} + +template<> +PrimitiveType rendergraph::primitiveTypeOf() { + return PrimitiveType::Float; +} +template<> +PrimitiveType rendergraph::primitiveTypeOf() { + return PrimitiveType::Float; +} +template<> +PrimitiveType rendergraph::primitiveTypeOf() { + return PrimitiveType::Float; +} + +template<> +int rendergraph::tupleSizeOf() { + return 1; +} +template<> +int rendergraph::tupleSizeOf() { + return 1; +} +template<> +int rendergraph::tupleSizeOf() { + return 2; +} +template<> +int rendergraph::tupleSizeOf() { + return 3; +} +template<> +int rendergraph::tupleSizeOf() { + return 4; +} diff --git a/src/rendergraph/types.h b/src/rendergraph/types.h new file mode 100644 index 00000000000..768738964fd --- /dev/null +++ b/src/rendergraph/types.h @@ -0,0 +1,31 @@ +#pragma once + +namespace rendergraph { + +enum class PrimitiveType { + UInt, + Float, +}; + +enum class Type { + UInt, + Float, + Vector2D, + Vector3D, + Vector4D, + Matrix4x4 +}; + +int sizeOf(Type type); +int sizeOf(PrimitiveType primitiveType); + +template +Type typeOf(); + +template +PrimitiveType primitiveTypeOf(); + +template +int tupleSizeOf(); + +} // namespace rendergraph diff --git a/src/rendergraph/uniform.h b/src/rendergraph/uniform.h new file mode 100644 index 00000000000..19a6a9c74a3 --- /dev/null +++ b/src/rendergraph/uniform.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include "rendergraph/types.h" + +namespace rendergraph { +struct Uniform; +} + +struct rendergraph::Uniform { + const Type m_type; + const QString m_name; + + Uniform(Type type) + : m_type{type} { + } + + Uniform(Type type, QString name) + : m_type{type}, + m_name{std::move(name)} { + } + + template + static Uniform create() { + return Uniform(typeOf()); + } +}; diff --git a/src/rendergraph/uniformscache.cpp b/src/rendergraph/uniformscache.cpp new file mode 100644 index 00000000000..3e43b60aab6 --- /dev/null +++ b/src/rendergraph/uniformscache.cpp @@ -0,0 +1,28 @@ +#include "rendergraph/uniformscache.h" + +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +UniformsCache::UniformsCache(const UniformSet& uniformSet) { + int offset = 0; + for (const auto& uniform : uniformSet.uniforms()) { + const int size = sizeOf(uniform.m_type); + m_infos.push_back({uniform.m_type, offset}); + offset += size; + } + m_byteArray.resize(offset); + m_byteArray.fill('\0'); +} + +UniformsCache::~UniformsCache() = default; + +void UniformsCache::set(int uniformIndex, Type type, const void* ptr, int size) { + assert(type == m_infos[uniformIndex].m_type); + memcpy(m_byteArray.data() + m_infos[uniformIndex].m_offset, ptr, size); +} + +void UniformsCache::get(int uniformIndex, Type type, void* ptr, int size) const { + assert(type == m_infos[uniformIndex].m_type); + memcpy(ptr, m_byteArray.data() + m_infos[uniformIndex].m_offset, size); +} diff --git a/src/rendergraph/uniformscache.h b/src/rendergraph/uniformscache.h new file mode 100644 index 00000000000..4d93f1b2018 --- /dev/null +++ b/src/rendergraph/uniformscache.h @@ -0,0 +1,53 @@ +#pragma once + +#include + +#include "rendergraph/types.h" + +namespace rendergraph { +class UniformSet; +class UniformsCache; +} // namespace rendergraph + +class rendergraph::UniformsCache { + public: + UniformsCache(const UniformSet& uniformSet); + ~UniformsCache(); + + template + void set(int uniformIndex, const T& value) { + set(uniformIndex, typeOf(), static_cast(&value), sizeof(T)); + } + + template + T get(int uniformIndex) const { + T value; + get(uniformIndex, typeOf(), static_cast(&value), sizeof(T)); + return value; + } + Type type(int uniformIndex) const { + return m_infos[uniformIndex].m_type; + } + + const char* data() const { + return m_byteArray.data(); + } + qsizetype size() const { + return m_byteArray.size(); + } + int count() const { + return m_infos.size(); + } + + private: + void set(int uniformIndex, Type type, const void* ptr, int size); + void get(int uniformIndex, Type type, void* ptr, int size) const; + + struct Info { + const Type m_type; + const int m_offset; + }; + + std::vector m_infos; + QByteArray m_byteArray; +}; diff --git a/src/rendergraph/uniformset.cpp b/src/rendergraph/uniformset.cpp new file mode 100644 index 00000000000..68e077613bd --- /dev/null +++ b/src/rendergraph/uniformset.cpp @@ -0,0 +1,20 @@ +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +UniformSet::UniformSet(std::initializer_list list, const std::vector& names) { + int i = 0; + for (auto item : list) { + add(Uniform{item.m_type, names[i++]}); + } +} + +UniformSet::~UniformSet() = default; + +void UniformSet::add(const Uniform& uniform) { + m_uniforms.push_back(uniform); +} + +const std::vector& UniformSet::uniforms() const { + return m_uniforms; +} diff --git a/src/rendergraph/uniformset.h b/src/rendergraph/uniformset.h new file mode 100644 index 00000000000..11f8a597637 --- /dev/null +++ b/src/rendergraph/uniformset.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include "rendergraph/uniform.h" + +namespace rendergraph { +class UniformSet; +} + +class rendergraph::UniformSet { + public: + UniformSet(std::initializer_list list, const std::vector& names); + + ~UniformSet(); + + const std::vector& uniforms() const; + + private: + void add(const Uniform& uniform); + std::vector m_uniforms; +}; + +namespace rendergraph { +template +UniformSet makeUniformSet(const std::vector& names) { + return UniformSet({(Uniform::create())...}, names); +} +} // namespace rendergraph diff --git a/src/waveform/renderers/allshader/endoftrackmaterial.cpp b/src/waveform/renderers/allshader/endoftrackmaterial.cpp new file mode 100644 index 00000000000..4f5c9dfee41 --- /dev/null +++ b/src/waveform/renderers/allshader/endoftrackmaterial.cpp @@ -0,0 +1,38 @@ +#include "endoftrackmaterial.h" + +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +EndOfTrackMaterial::EndOfTrackMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& EndOfTrackMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "gradient"}); + return set; +} + +/* static */ const UniformSet& EndOfTrackMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.color"}); + return set; +} + +MaterialType* EndOfTrackMaterial::type() const { + static MaterialType type; + return &type; +} + +int EndOfTrackMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +MaterialShader* EndOfTrackMaterial::createShader() const { + return new MaterialShader("endoftrack.vert", "endoftrack.frag", uniforms(), attributes()); +} diff --git a/src/waveform/renderers/allshader/endoftrackmaterial.h b/src/waveform/renderers/allshader/endoftrackmaterial.h new file mode 100644 index 00000000000..bcaa02b0430 --- /dev/null +++ b/src/waveform/renderers/allshader/endoftrackmaterial.h @@ -0,0 +1,21 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" + +namespace rendergraph { +class EndOfTrackMaterial; +} + +class rendergraph::EndOfTrackMaterial : public rendergraph::Material { + public: + EndOfTrackMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + MaterialShader* createShader() const override; +}; diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.cpp b/src/waveform/renderers/allshader/waveformrenderbeat.cpp index 3f793efd706..39da6e21401 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.cpp +++ b/src/waveform/renderers/allshader/waveformrenderbeat.cpp @@ -17,7 +17,6 @@ WaveformRenderBeat::WaveformRenderBeat(WaveformWidgetRenderer* waveformWidget, } void WaveformRenderBeat::initializeGL() { - WaveformRenderer::initializeGL(); m_shader.init(); } diff --git a/src/waveform/renderers/allshader/waveformrenderer.h b/src/waveform/renderers/allshader/waveformrenderer.h index 04b4b427935..52b2c222047 100644 --- a/src/waveform/renderers/allshader/waveformrenderer.h +++ b/src/waveform/renderers/allshader/waveformrenderer.h @@ -1,6 +1,6 @@ #pragma once -#include "waveform/renderers/allshader/waveformrendererabstract.h" +#include "rendergraph/opengl/openglnode.h" #include "waveform/renderers/waveformrendererabstract.h" class WaveformWidgetRenderer; @@ -10,27 +10,15 @@ class WaveformRenderer; } class allshader::WaveformRenderer : public ::WaveformRendererAbstract, - public allshader::WaveformRendererAbstract { + public rendergraph::OpenGLNode { public: explicit WaveformRenderer(WaveformWidgetRenderer* widget); - // Pure virtual from allshader::WaveformRendererAbstract. + // Pure virtual from WaveformRendererAbstract // Renderers that use QPainter functionality implement this. // But as all classes derived from allshader::WaveformRenderer // will only use openGL functions (combining QPainter and // QOpenGLWindow has bad performance), we leave this empty. // Should never be called. void draw(QPainter* painter, QPaintEvent* event) override final; - - allshader::WaveformRendererAbstract* allshaderWaveformRenderer() override final { - // This class is indirectly derived from - // WaveformWidgetRenderer, which has a member - // QList m_rendererStack; - // In the case of allshader::WaveformRenderer widgets, - // all the items on this stack are derived from - // allshader::WaveformRendererAbstract and we use this method to - // access them as such. (We could also have used a - // dynamic cast (or even static cast instead) - return this; - } }; diff --git a/src/waveform/renderers/allshader/waveformrendererabstract.h b/src/waveform/renderers/allshader/waveformrendererabstract.h deleted file mode 100644 index 5c530a00e22..00000000000 --- a/src/waveform/renderers/allshader/waveformrendererabstract.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include - -namespace allshader { -class WaveformRendererAbstract; -} - -class allshader::WaveformRendererAbstract : public QOpenGLFunctions { - public: - /// This interface class is called by class allshader::WaveformWidget. - /// Class allshader::WaveformWidget is derived from the allshader-based - /// class WGLWidget and, in its implementation of the WGLWidget virtual - /// methods, calls a stack of allshader::WaveformRendererAbstract instances, for - /// the different layers of the waveform graphics (background, beat - /// markers, the actual waveform, etc). In other word, this interface - /// mimics the WGLWidget virtuals, but to be called as layers of an - /// actual WGLWidget. - virtual ~WaveformRendererAbstract() = default; - virtual void initializeGL() { - initializeOpenGLFunctions(); - } - virtual void resizeGL(int /* w */, int /* h */) { - } - virtual void paintGL() = 0; -}; diff --git a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp index 10df7121020..1896446b328 100644 --- a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp +++ b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp @@ -1,9 +1,12 @@ #include "waveform/renderers/allshader/waveformrendererendoftrack.h" #include +#include #include #include "control/controlproxy.h" +#include "endoftrackmaterial.h" +#include "rendergraph/geometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveformwidgetfactory.h" #include "widget/wskincolor.h" @@ -11,19 +14,31 @@ namespace { constexpr int kBlinkingPeriodMillis = 1000; -constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; -constexpr float verticalGradientArray[] = {1.f, 1.f, -1.f, -1.f}; -constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; } // anonymous namespace +using namespace rendergraph; + namespace allshader { WaveformRendererEndOfTrack::WaveformRendererEndOfTrack( WaveformWidgetRenderer* waveformWidget) - : WaveformRenderer(waveformWidget), + : ::WaveformRendererAbstract(waveformWidget), m_pEndOfTrackControl(nullptr), m_pTimeRemainingControl(nullptr) { + setGeometry(std::make_unique(EndOfTrackMaterial::attributes(), 4)); + setMaterial(std::make_unique()); + setUsePreprocess(true); + + geometry().setAttributeValues(0, positionArray, 4); + geometry().setAttributeValues(1, horizontalGradientArray, 4); + material().setUniform(0, QVector4D{1.f, 0.f, 0.f, 1.f}); +} + +void WaveformRendererEndOfTrack::draw(QPainter* painter, QPaintEvent* event) { + Q_UNUSED(painter); + Q_UNUSED(event); + DEBUG_ASSERT(false); } bool WaveformRendererEndOfTrack::init() { @@ -46,43 +61,7 @@ void WaveformRendererEndOfTrack::setup(const QDomNode& node, const SkinContext& } } -void WaveformRendererEndOfTrack::initializeGL() { - WaveformRenderer::initializeGL(); - m_shader.init(); -} - -void WaveformRendererEndOfTrack::fillWithGradient(QColor color) { - const int colorLocation = m_shader.colorLocation(); - const int positionLocation = m_shader.positionLocation(); - const int gradientLocation = m_shader.gradientLocation(); - - m_shader.bind(); - m_shader.enableAttributeArray(positionLocation); - m_shader.enableAttributeArray(gradientLocation); - - m_shader.setUniformValue(colorLocation, color); - - m_shader.setAttributeArray( - positionLocation, GL_FLOAT, positionArray, 2); - m_shader.setAttributeArray(gradientLocation, - GL_FLOAT, - m_waveformRenderer->getOrientation() == Qt::Vertical - ? verticalGradientArray - : horizontalGradientArray, - 1); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - m_shader.disableAttributeArray(positionLocation); - m_shader.disableAttributeArray(gradientLocation); - m_shader.release(); -} - -void WaveformRendererEndOfTrack::paintGL() { - if (!m_pEndOfTrackControl->toBool()) { - return; - } - +void WaveformRendererEndOfTrack::preprocess() { const int elapsed = m_timer.elapsed().toIntegerMillis() % kBlinkingPeriodMillis; const double blinkIntensity = (double)(2 * abs(elapsed - kBlinkingPeriodMillis / 2)) / @@ -100,11 +79,16 @@ void WaveformRendererEndOfTrack::paintGL() { QColor color = m_color; color.setAlphaF(static_cast(alpha)); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - - fillWithGradient(color); + material().setUniform(0, + QVector4D{color.redF(), + color.greenF(), + color.blueF(), + color.alphaF()}); } } +bool WaveformRendererEndOfTrack::isSubtreeBlocked() const { + return !m_pEndOfTrackControl->toBool(); +} + } // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrendererendoftrack.h b/src/waveform/renderers/allshader/waveformrendererendoftrack.h index 664a2cac16e..9b7ec182de5 100644 --- a/src/waveform/renderers/allshader/waveformrendererendoftrack.h +++ b/src/waveform/renderers/allshader/waveformrendererendoftrack.h @@ -3,10 +3,11 @@ #include #include -#include "shaders/endoftrackshader.h" +#include "rendergraph/geometrynode.h" +#include "rendergraph/opacitynode.h" #include "util/class.h" #include "util/performancetimer.h" -#include "waveform/renderers/allshader/waveformrenderer.h" +#include "waveform/renderers/waveformrendererabstract.h" class ControlProxy; class QDomNode; @@ -16,22 +17,29 @@ namespace allshader { class WaveformRendererEndOfTrack; } -class allshader::WaveformRendererEndOfTrack final : public allshader::WaveformRenderer { +class allshader::WaveformRendererEndOfTrack final + : public ::WaveformRendererAbstract, + public rendergraph::GeometryNode { public: explicit WaveformRendererEndOfTrack( WaveformWidgetRenderer* waveformWidget); + // Pure virtual from WaveformRendererAbstract, not used + void draw(QPainter* painter, QPaintEvent* event) override final; + void setup(const QDomNode& node, const SkinContext& context) override; bool init() override; - void initializeGL() override; - void paintGL() override; + // Virtual for rendergraph::Node + void preprocess() override; + bool isSubtreeBlocked() const override; private: - void fillWithGradient(QColor color); + static constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; + static constexpr float verticalGradientArray[] = {1.f, 1.f, -1.f, -1.f}; + static constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; - mixxx::EndOfTrackShader m_shader; std::unique_ptr m_pEndOfTrackControl; std::unique_ptr m_pTimeRemainingControl; diff --git a/src/waveform/renderers/allshader/waveformrendererfiltered.cpp b/src/waveform/renderers/allshader/waveformrendererfiltered.cpp index 0ddf164cc3e..f48b1136f59 100644 --- a/src/waveform/renderers/allshader/waveformrendererfiltered.cpp +++ b/src/waveform/renderers/allshader/waveformrendererfiltered.cpp @@ -19,7 +19,6 @@ void WaveformRendererFiltered::onSetup(const QDomNode& node) { } void WaveformRendererFiltered::initializeGL() { - WaveformRendererSignalBase::initializeGL(); m_shader.init(); } diff --git a/src/waveform/renderers/allshader/waveformrendererhsv.cpp b/src/waveform/renderers/allshader/waveformrendererhsv.cpp index 31b9785acdf..75b34dbae00 100644 --- a/src/waveform/renderers/allshader/waveformrendererhsv.cpp +++ b/src/waveform/renderers/allshader/waveformrendererhsv.cpp @@ -19,7 +19,6 @@ void WaveformRendererHSV::onSetup(const QDomNode& node) { } void WaveformRendererHSV::initializeGL() { - WaveformRendererSignalBase::initializeGL(); m_shader.init(); } diff --git a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp index eea01c5bdad..89948347d87 100644 --- a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp +++ b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp @@ -75,7 +75,6 @@ void WaveformRendererPreroll::setup( } void WaveformRendererPreroll::initializeGL() { - WaveformRenderer::initializeGL(); m_shader.init(); } diff --git a/src/waveform/renderers/allshader/waveformrendererrgb.cpp b/src/waveform/renderers/allshader/waveformrendererrgb.cpp index 54cea537640..31cd94f1a5d 100644 --- a/src/waveform/renderers/allshader/waveformrendererrgb.cpp +++ b/src/waveform/renderers/allshader/waveformrendererrgb.cpp @@ -27,7 +27,6 @@ void WaveformRendererRGB::onSetup(const QDomNode& node) { } void WaveformRendererRGB::initializeGL() { - WaveformRendererSignalBase::initializeGL(); m_shader.init(); } diff --git a/src/waveform/renderers/allshader/waveformrenderersignalbase.h b/src/waveform/renderers/allshader/waveformrenderersignalbase.h index 0e72d9364c7..7b1fe8002d9 100644 --- a/src/waveform/renderers/allshader/waveformrenderersignalbase.h +++ b/src/waveform/renderers/allshader/waveformrenderersignalbase.h @@ -3,8 +3,8 @@ #include #include +#include "rendergraph/opengl/openglnode.h" #include "util/class.h" -#include "waveform/renderers/allshader/waveformrendererabstract.h" #include "waveform/renderers/waveformrenderersignalbase.h" class WaveformWidgetRenderer; @@ -14,7 +14,7 @@ class WaveformRendererSignalBase; } class allshader::WaveformRendererSignalBase : public ::WaveformRendererSignalBase, - public allshader::WaveformRendererAbstract { + public rendergraph::OpenGLNode { public: enum class Option { None = 0b0, @@ -37,9 +37,5 @@ class allshader::WaveformRendererSignalBase : public ::WaveformRendererSignalBas Q_UNUSED(event); } - allshader::WaveformRendererAbstract* allshaderWaveformRenderer() override { - return this; - } - DISALLOW_COPY_AND_ASSIGN(WaveformRendererSignalBase); }; diff --git a/src/waveform/renderers/allshader/waveformrenderersimple.cpp b/src/waveform/renderers/allshader/waveformrenderersimple.cpp index 02e9453afdf..90a707d2373 100644 --- a/src/waveform/renderers/allshader/waveformrenderersimple.cpp +++ b/src/waveform/renderers/allshader/waveformrenderersimple.cpp @@ -18,7 +18,6 @@ void WaveformRendererSimple::onSetup(const QDomNode& node) { } void WaveformRendererSimple::initializeGL() { - WaveformRendererSignalBase::initializeGL(); m_shader.init(); } diff --git a/src/waveform/renderers/allshader/waveformrendererslipmode.cpp b/src/waveform/renderers/allshader/waveformrendererslipmode.cpp index 4311f00a4ce..8ddf0be80e5 100644 --- a/src/waveform/renderers/allshader/waveformrendererslipmode.cpp +++ b/src/waveform/renderers/allshader/waveformrendererslipmode.cpp @@ -63,7 +63,6 @@ void WaveformRendererSlipMode::setup(const QDomNode& node, const SkinContext& co } void WaveformRendererSlipMode::initializeGL() { - WaveformRenderer::initializeGL(); m_shader.init(); } diff --git a/src/waveform/renderers/allshader/waveformrendererstem.cpp b/src/waveform/renderers/allshader/waveformrendererstem.cpp index bacb18d32ca..c8dbe5a949c 100644 --- a/src/waveform/renderers/allshader/waveformrendererstem.cpp +++ b/src/waveform/renderers/allshader/waveformrendererstem.cpp @@ -29,7 +29,6 @@ void WaveformRendererStem::onSetup(const QDomNode& node) { } void WaveformRendererStem::initializeGL() { - WaveformRendererSignalBase::initializeGL(); m_shader.init(); m_textureShader.init(); auto group = m_pEQEnabled->getKey().group; diff --git a/src/waveform/renderers/allshader/waveformrenderertextured.cpp b/src/waveform/renderers/allshader/waveformrenderertextured.cpp index dc137b73208..de21a013259 100644 --- a/src/waveform/renderers/allshader/waveformrenderertextured.cpp +++ b/src/waveform/renderers/allshader/waveformrenderertextured.cpp @@ -219,8 +219,6 @@ void WaveformRendererTextured::createFrameBuffers() { } void WaveformRendererTextured::initializeGL() { - WaveformRendererSignalBase::initializeGL(); - m_textureRenderedWaveformCompletion = 0; if (!m_frameShaderProgram) { diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 1a66df4deb4..bca7ecb24cc 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -75,7 +75,6 @@ bool allshader::WaveformRenderMark::init() { } void allshader::WaveformRenderMark::initializeGL() { - allshader::WaveformRendererAbstract::initializeGL(); m_digitsRenderer.init(); m_rgbaShader.init(); m_textureShader.init(); diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index 317f132e26d..ab9caaa5f4c 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -2,11 +2,11 @@ #include +#include "rendergraph/opengl/openglnode.h" #include "shaders/rgbashader.h" #include "shaders/textureshader.h" #include "util/opengltexture2d.h" #include "waveform/renderers/allshader/digitsrenderer.h" -#include "waveform/renderers/allshader/waveformrendererabstract.h" #include "waveform/renderers/waveformrendermarkbase.h" class QDomNode; @@ -18,7 +18,7 @@ class WaveformRenderMark; } class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, - public allshader::WaveformRendererAbstract { + public rendergraph::OpenGLNode { public: explicit WaveformRenderMark(WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type = @@ -29,10 +29,6 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, Q_UNUSED(event); } - allshader::WaveformRendererAbstract* allshaderWaveformRenderer() override { - return this; - } - bool init() override; void initializeGL() override; diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index 6b3a33d4936..eaacffdbdba 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -9,7 +9,6 @@ allshader::WaveformRenderMarkRange::WaveformRenderMarkRange(WaveformWidgetRender } void allshader::WaveformRenderMarkRange::initializeGL() { - WaveformRenderer::initializeGL(); m_shader.init(); } diff --git a/src/waveform/renderers/waveformrendererabstract.h b/src/waveform/renderers/waveformrendererabstract.h index 6c15dd523d5..9d4f84a629e 100644 --- a/src/waveform/renderers/waveformrendererabstract.h +++ b/src/waveform/renderers/waveformrendererabstract.h @@ -6,13 +6,13 @@ QT_FORWARD_DECLARE_CLASS(QDomNode) QT_FORWARD_DECLARE_CLASS(QPaintEvent) QT_FORWARD_DECLARE_CLASS(QPainter) +namespace rendergraph { +class Node; +} + class SkinContext; class WaveformWidgetRenderer; -namespace allshader { -class WaveformRendererAbstract; -} - class WaveformRendererAbstract { public: /// The type of cursor for which the waveform is rendered @@ -32,9 +32,6 @@ class WaveformRendererAbstract { virtual void onResize() {} virtual void onSetTrack() {} - virtual allshader::WaveformRendererAbstract* allshaderWaveformRenderer() { - return nullptr; - } protected: bool isDirty() const { diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index 2b507ff7afc..65b23e95b15 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -3,10 +3,10 @@ #include #include +#include #include "waveform/renderers/allshader/waveformrenderbackground.h" #include "waveform/renderers/allshader/waveformrenderbeat.h" -#include "waveform/renderers/allshader/waveformrendererabstract.h" #include "waveform/renderers/allshader/waveformrendererendoftrack.h" #include "waveform/renderers/allshader/waveformrendererfiltered.h" #include "waveform/renderers/allshader/waveformrendererhsv.h" @@ -20,6 +20,15 @@ #include "waveform/renderers/allshader/waveformrendermarkrange.h" #include "waveform/widgets/allshader/moc_waveformwidget.cpp" +namespace { +void appendChildTo(std::unique_ptr& pNode, rendergraph::Node* pChild) { + pNode->appendChildNode(std::unique_ptr(pChild)); +} +void appendChildTo(std::unique_ptr& pNode, rendergraph::Node* pChild) { + pNode->appendChildNode(std::unique_ptr(pChild)); +} +} // namespace + namespace allshader { WaveformWidget::WaveformWidget(QWidget* parent, @@ -27,47 +36,64 @@ WaveformWidget::WaveformWidget(QWidget* parent, const QString& group, WaveformRendererSignalBase::Options options) : WGLWidget(parent), WaveformWidgetAbstract(group) { - addRenderer(); - addRenderer(); - addRenderer(); - addRenderer(); + auto pTopNode = std::make_unique(); + auto pOpacityNode = std::make_unique(); + + appendChildTo(pTopNode, addRenderer()); + appendChildTo(pOpacityNode, addRenderer()); + appendChildTo(pOpacityNode, addRenderer()); + appendChildTo(pOpacityNode, addRenderer()); #ifdef __STEM__ // The following two renderers work in tandem: if the rendered waveform is // for a stem track, WaveformRendererSignalBase will skip rendering and let // WaveformRendererStem do the rendering, and vice-versa. - addRenderer(); + appendChildTo(pOpacityNode, addRenderer()); #endif allshader::WaveformRendererSignalBase* waveformSignalRenderer = addWaveformSignalRenderer( type, options, ::WaveformRendererAbstract::Play); + appendChildTo(pOpacityNode, waveformSignalRenderer); - addRenderer(); - addRenderer(); + appendChildTo(pOpacityNode, addRenderer()); + appendChildTo(pOpacityNode, addRenderer()); // if the signal renderer supports slip, we add it again, now for slip, together with the // other slip renderers if (waveformSignalRenderer && waveformSignalRenderer->supportsSlip()) { // The following renderer will add an overlay waveform if a slip is in progress - addRenderer(); - addRenderer(::WaveformRendererAbstract::Slip); + appendChildTo(pOpacityNode, addRenderer()); + appendChildTo(pOpacityNode, + addRenderer( + ::WaveformRendererAbstract::Slip)); #ifdef __STEM__ - addRenderer(::WaveformRendererAbstract::Slip); + appendChildTo(pOpacityNode, + addRenderer( + ::WaveformRendererAbstract::Slip)); #endif - addWaveformSignalRenderer(type, options, ::WaveformRendererAbstract::Slip); - addRenderer(::WaveformRendererAbstract::Slip); - addRenderer(::WaveformRendererAbstract::Slip); + appendChildTo(pOpacityNode, + addWaveformSignalRenderer( + type, options, ::WaveformRendererAbstract::Slip)); + appendChildTo(pOpacityNode, + addRenderer( + ::WaveformRendererAbstract::Slip)); + appendChildTo(pOpacityNode, + addRenderer( + ::WaveformRendererAbstract::Slip)); } m_initSuccess = init(); + + m_pOpacityNode = pOpacityNode.get(); + pTopNode->appendChildNode(std::move(pOpacityNode)); + + m_pGraph = std::make_unique(std::move(pTopNode)); } WaveformWidget::~WaveformWidget() { makeCurrentIfNeeded(); - for (auto* pRenderer : std::as_const(m_rendererStack)) { - delete pRenderer; - } m_rendererStack.clear(); + m_pGraph.reset(); doneCurrent(); } @@ -117,15 +143,11 @@ mixxx::Duration WaveformWidget::render() { } void WaveformWidget::paintGL() { - if (shouldOnlyDrawBackground()) { - if (!m_rendererStack.empty()) { - m_rendererStack[0]->allshaderWaveformRenderer()->paintGL(); - } - } else { - for (auto* pRenderer : std::as_const(m_rendererStack)) { - pRenderer->allshaderWaveformRenderer()->paintGL(); - } - } + // opacity of 0.f effectively skips the subtree rendering + m_pOpacityNode->setOpacity(shouldOnlyDrawBackground() ? 0.f : 1.f); + + m_pGraph->preprocess(); + m_pGraph->render(); } void WaveformWidget::castToQWidget() { @@ -133,15 +155,11 @@ void WaveformWidget::castToQWidget() { } void WaveformWidget::initializeGL() { - for (auto* pRenderer : std::as_const(m_rendererStack)) { - pRenderer->allshaderWaveformRenderer()->initializeGL(); - } + m_pGraph->initialize(); } void WaveformWidget::resizeGL(int w, int h) { - for (auto* pRenderer : std::as_const(m_rendererStack)) { - pRenderer->allshaderWaveformRenderer()->resizeGL(w, h); - } + m_pGraph->resize(w, h); } void WaveformWidget::paintEvent(QPaintEvent* event) { diff --git a/src/waveform/widgets/allshader/waveformwidget.h b/src/waveform/widgets/allshader/waveformwidget.h index f6c0877975e..c40ff4b932b 100644 --- a/src/waveform/widgets/allshader/waveformwidget.h +++ b/src/waveform/widgets/allshader/waveformwidget.h @@ -1,5 +1,7 @@ #pragma once +#include "rendergraph/opacitynode.h" +#include "rendergraph/opengl/graph.h" #include "waveform/renderers/allshader/waveformrenderersignalbase.h" #include "waveform/widgets/waveformwidgetabstract.h" #include "waveform/widgets/waveformwidgetvars.h" @@ -48,6 +50,8 @@ class allshader::WaveformWidget final : public ::WGLWidget, ::WaveformRendererAbstract::PositionSource positionSource); WaveformWidgetType::Type m_type; + std::unique_ptr m_pGraph; + rendergraph::OpacityNode* m_pOpacityNode; DISALLOW_COPY_AND_ASSIGN(WaveformWidget); }; From d3a69bb4c3398ba144d98b67005b8c52e3d5d7fe Mon Sep 17 00:00:00 2001 From: m0dB Date: Tue, 27 Aug 2024 11:31:01 +0200 Subject: [PATCH 02/64] waveformrenderbeat with rendergraph, various fixes, use same shaders and material for mixxx and rendergraph examples --- CMakeLists.txt | 1 - res/shaders/rendergraph/CMakeLists.txt | 6 +- .../rendergraph/generated_shaders_gl.cmake | 2 + res/shaders/rendergraph/unicolor.frag | 13 ++++ res/shaders/rendergraph/unicolor.frag.gl | 15 ++++ .../shaders/rendergraph/unicolor.vert | 4 +- .../shaders/rendergraph/unicolor.vert.gl | 4 +- src/rendergraph/CMakeLists.txt | 1 + src/rendergraph/examples/CMakeLists.txt | 1 - .../examples/common/CMakeLists.txt | 4 -- .../examples/common/examplenodes.cpp | 3 +- .../examples/shaders/CMakeLists.txt | 25 ------- src/rendergraph/examples/shaders/README | 9 --- .../examples/shaders/endoftrack.frag | 17 ----- .../examples/shaders/endoftrack.frag.gl | 19 ----- .../examples/shaders/endoftrack.vert | 14 ---- .../examples/shaders/endoftrack.vert.gl | 12 ---- .../examples/shaders/generate_shaders_gl.pl | 68 ------------------ .../shaders/generated_shaders_gl.cmake | 6 -- src/rendergraph/examples/shaders/texture.frag | 9 --- .../examples/shaders/texture.frag.gl | 11 --- .../examples/shaders/texture.vert.qsb | Bin 607 -> 0 bytes src/rendergraph/geometry.cpp | 15 ++++ src/rendergraph/geometry.h | 7 ++ .../material}/endoftrackmaterial.cpp | 0 .../material}/endoftrackmaterial.h | 0 .../common => material}/texturematerial.cpp | 2 +- .../common => material}/texturematerial.h | 0 src/rendergraph/material/unicolormaterial.cpp | 38 ++++++++++ src/rendergraph/material/unicolormaterial.h | 21 ++++++ src/rendergraph/opengl/CMakeLists.txt | 6 ++ src/rendergraph/opengl/geometrynode_impl.cpp | 5 +- .../opengl/private/geometry_impl.h | 48 +++++++++++-- src/rendergraph/scenegraph/CMakeLists.txt | 6 ++ .../scenegraph/private/geometry_impl.h | 9 +++ src/rendergraph/types.cpp | 8 +-- src/rendergraph/uniformscache.h | 15 +++- .../renderers/allshader/vertexupdater.h | 34 +++++++++ .../allshader/waveformrenderbeat.cpp | 59 ++++++++------- .../renderers/allshader/waveformrenderbeat.h | 22 +++--- .../allshader/waveformrendererendoftrack.cpp | 10 +-- 41 files changed, 283 insertions(+), 266 deletions(-) create mode 100644 res/shaders/rendergraph/unicolor.frag create mode 100644 res/shaders/rendergraph/unicolor.frag.gl rename src/rendergraph/examples/shaders/texture.vert => res/shaders/rendergraph/unicolor.vert (62%) rename src/rendergraph/examples/shaders/texture.vert.gl => res/shaders/rendergraph/unicolor.vert.gl (72%) delete mode 100644 src/rendergraph/examples/shaders/CMakeLists.txt delete mode 100644 src/rendergraph/examples/shaders/README delete mode 100644 src/rendergraph/examples/shaders/endoftrack.frag delete mode 100644 src/rendergraph/examples/shaders/endoftrack.frag.gl delete mode 100644 src/rendergraph/examples/shaders/endoftrack.vert delete mode 100644 src/rendergraph/examples/shaders/endoftrack.vert.gl delete mode 100755 src/rendergraph/examples/shaders/generate_shaders_gl.pl delete mode 100644 src/rendergraph/examples/shaders/generated_shaders_gl.cmake delete mode 100644 src/rendergraph/examples/shaders/texture.frag delete mode 100644 src/rendergraph/examples/shaders/texture.frag.gl delete mode 100644 src/rendergraph/examples/shaders/texture.vert.qsb rename src/{waveform/renderers/allshader => rendergraph/material}/endoftrackmaterial.cpp (100%) rename src/{waveform/renderers/allshader => rendergraph/material}/endoftrackmaterial.h (100%) rename src/rendergraph/{examples/common => material}/texturematerial.cpp (90%) rename src/rendergraph/{examples/common => material}/texturematerial.h (100%) create mode 100644 src/rendergraph/material/unicolormaterial.cpp create mode 100644 src/rendergraph/material/unicolormaterial.h create mode 100644 src/waveform/renderers/allshader/vertexupdater.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a4236d2529..72c8345cf3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1514,7 +1514,6 @@ if(QOPENGL) src/shaders/vinylqualityshader.cpp src/util/opengltexture2d.cpp src/waveform/renderers/allshader/digitsrenderer.cpp - src/waveform/renderers/allshader/endoftrackmaterial.cpp src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp src/waveform/renderers/allshader/waveformrenderbackground.cpp src/waveform/renderers/allshader/waveformrenderbeat.cpp diff --git a/res/shaders/rendergraph/CMakeLists.txt b/res/shaders/rendergraph/CMakeLists.txt index b0a4339699b..2c908fdd8b3 100644 --- a/res/shaders/rendergraph/CMakeLists.txt +++ b/res/shaders/rendergraph/CMakeLists.txt @@ -3,6 +3,8 @@ set(shaders endoftrack.frag texture.vert texture.frag + unicolor.vert + unicolor.frag ) qt6_add_shaders(rendergraph_sg "shaders-sg" @@ -10,7 +12,7 @@ qt6_add_shaders(rendergraph_sg "shaders-sg" PRECOMPILE OPTIMIZED PREFIX - /rendergraph_sg/shaders + /shaders/rendergraph FILES ${shaders} ) @@ -19,7 +21,7 @@ include(generated_shaders_gl.cmake) qt_add_resources(rendergraph_gl "shaders-gl" PREFIX - /rendergraph_gl/shaders + /shaders/rendergraph FILES ${generated_shaders_gl} ) diff --git a/res/shaders/rendergraph/generated_shaders_gl.cmake b/res/shaders/rendergraph/generated_shaders_gl.cmake index e3bd0c644f2..9c72d8dd115 100644 --- a/res/shaders/rendergraph/generated_shaders_gl.cmake +++ b/res/shaders/rendergraph/generated_shaders_gl.cmake @@ -1,6 +1,8 @@ set(generated_shaders_gl endoftrack.vert.gl texture.vert.gl + unicolor.vert.gl endoftrack.frag.gl texture.frag.gl + unicolor.frag.gl ) diff --git a/res/shaders/rendergraph/unicolor.frag b/res/shaders/rendergraph/unicolor.frag new file mode 100644 index 00000000000..4c2afaaefb0 --- /dev/null +++ b/res/shaders/rendergraph/unicolor.frag @@ -0,0 +1,13 @@ +#version 440 + +layout(location = 0) out vec4 fragColor; + +layout(std140, binding = 0) uniform buf { + mat4 matrix; + vec4 color; +} +ubuf; + +void main() { + fragColor = vec4(ubuf.color.xyz * ubuf.color.w, ubuf.color.w); // premultiple alpha +} diff --git a/res/shaders/rendergraph/unicolor.frag.gl b/res/shaders/rendergraph/unicolor.frag.gl new file mode 100644 index 00000000000..bfef503120b --- /dev/null +++ b/res/shaders/rendergraph/unicolor.frag.gl @@ -0,0 +1,15 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +struct buf +{ + mat4 matrix; + vec4 color; +}; + +uniform buf ubuf; + +void main() +{ + gl_FragData[0] = vec4(ubuf.color.xyz * ubuf.color.w, ubuf.color.w); +} diff --git a/src/rendergraph/examples/shaders/texture.vert b/res/shaders/rendergraph/unicolor.vert similarity index 62% rename from src/rendergraph/examples/shaders/texture.vert rename to res/shaders/rendergraph/unicolor.vert index 46e4c84d254..05862534df7 100644 --- a/src/rendergraph/examples/shaders/texture.vert +++ b/res/shaders/rendergraph/unicolor.vert @@ -1,15 +1,13 @@ #version 440 layout(location = 0) in vec4 position; -layout(location = 1) in vec2 texcoord; -layout(location = 0) out vec2 vTexcoord; layout(std140, binding = 0) uniform buf { mat4 matrix; + vec4 color; } ubuf; void main() { - vTexcoord = texcoord; gl_Position = ubuf.matrix * position; } diff --git a/src/rendergraph/examples/shaders/texture.vert.gl b/res/shaders/rendergraph/unicolor.vert.gl similarity index 72% rename from src/rendergraph/examples/shaders/texture.vert.gl rename to res/shaders/rendergraph/unicolor.vert.gl index a3d58014be3..d126f3dab58 100644 --- a/src/rendergraph/examples/shaders/texture.vert.gl +++ b/res/shaders/rendergraph/unicolor.vert.gl @@ -4,16 +4,14 @@ struct buf { mat4 matrix; + vec4 color; }; uniform buf ubuf; -varying vec2 vTexcoord; -attribute vec2 texcoord; attribute vec4 position; void main() { - vTexcoord = texcoord; gl_Position = ubuf.matrix * position; } diff --git a/src/rendergraph/CMakeLists.txt b/src/rendergraph/CMakeLists.txt index d50852826c8..91bcb99beb5 100644 --- a/src/rendergraph/CMakeLists.txt +++ b/src/rendergraph/CMakeLists.txt @@ -1,2 +1,3 @@ add_subdirectory(opengl) add_subdirectory(scenegraph) +add_subdirectory(../../res/shaders/rendergraph shaders) diff --git a/src/rendergraph/examples/CMakeLists.txt b/src/rendergraph/examples/CMakeLists.txt index b950f152d6f..bd918d2f9ad 100644 --- a/src/rendergraph/examples/CMakeLists.txt +++ b/src/rendergraph/examples/CMakeLists.txt @@ -6,7 +6,6 @@ find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick ShaderTools) qt_standard_project_setup() add_subdirectory(../ rendergraph) -add_subdirectory(shaders) add_subdirectory(gl_example) add_subdirectory(sg_example) add_subdirectory(common) diff --git a/src/rendergraph/examples/common/CMakeLists.txt b/src/rendergraph/examples/common/CMakeLists.txt index e6cfcbf839f..e7ee6c0160e 100644 --- a/src/rendergraph/examples/common/CMakeLists.txt +++ b/src/rendergraph/examples/common/CMakeLists.txt @@ -1,8 +1,4 @@ add_library(rendergraph_examples - endoftrackmaterial.cpp - endoftrackmaterial.h - texturematerial.cpp - texturematerial.h examplenodes.cpp examplenodes.h ) diff --git a/src/rendergraph/examples/common/examplenodes.cpp b/src/rendergraph/examples/common/examplenodes.cpp index a2eca46ecb4..dbac0ea2bdd 100644 --- a/src/rendergraph/examples/common/examplenodes.cpp +++ b/src/rendergraph/examples/common/examplenodes.cpp @@ -6,7 +6,7 @@ #include "endoftrackmaterial.h" #include "rendergraph/geometry.h" -#include "texturematerial.h" +#include "rendergraph/material/texturematerial.h" using namespace rendergraph; @@ -53,6 +53,7 @@ ExampleNode3::ExampleNode3() { matrix.scale(0.3); material().setUniform(0, matrix); + material().setUniform(1, QVector4D{1.f, 0.5f, 0.2f, 0.7f}); } void ExampleNode3::setTexture(std::unique_ptr texture) { diff --git a/src/rendergraph/examples/shaders/CMakeLists.txt b/src/rendergraph/examples/shaders/CMakeLists.txt deleted file mode 100644 index c16c1e33ab1..00000000000 --- a/src/rendergraph/examples/shaders/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -set(shaders - endoftrack.vert - endoftrack.frag - texture.vert - texture.frag -) - -qt6_add_shaders(rendergraph_sg "shaders-sg" - BATCHABLE - PRECOMPILE - OPTIMIZED - PREFIX - /shaders/rendergraph - FILES - ${shaders} -) - -include(generated_shaders_gl.cmake) - -qt_add_resources(rendergraph_gl "shaders-gl" - PREFIX - /shaders/rendergraph - FILES - ${generated_shaders_gl} -) diff --git a/src/rendergraph/examples/shaders/README b/src/rendergraph/examples/shaders/README deleted file mode 100644 index 04bb5086e24..00000000000 --- a/src/rendergraph/examples/shaders/README +++ /dev/null @@ -1,9 +0,0 @@ -Generate the GLSL shaders from the spirv shaders by running - -generate_shaders_gl.pl - -(Make sure qsb and spirv commands are in your path. E.g: -export PATH=$PATH:~/VulkanSDK/1.3.283.0/macOS/bin:~/Qt/6.7.2/macos/bin -) - -Since Qt 6.6 we should be able to access this programmatically with QShader, but for now I do it manually diff --git a/src/rendergraph/examples/shaders/endoftrack.frag b/src/rendergraph/examples/shaders/endoftrack.frag deleted file mode 100644 index 65a99d13e4d..00000000000 --- a/src/rendergraph/examples/shaders/endoftrack.frag +++ /dev/null @@ -1,17 +0,0 @@ -#version 440 - -layout(location = 0) in float vgradient; -layout(location = 0) out vec4 fragColor; - -layout(std140, binding = 0) uniform buf { - vec4 color; -} -ubuf; - -void main() { - float minAlpha = 0.5 * ubuf.color.w; - float maxAlpha = 0.83 * ubuf.color.w; - float alpha = mix(minAlpha, maxAlpha, max(0.0, vgradient)); - // premultiple alpha - fragColor = vec4(ubuf.color.xyz * alpha, alpha); -} diff --git a/src/rendergraph/examples/shaders/endoftrack.frag.gl b/src/rendergraph/examples/shaders/endoftrack.frag.gl deleted file mode 100644 index f65b1ea3dda..00000000000 --- a/src/rendergraph/examples/shaders/endoftrack.frag.gl +++ /dev/null @@ -1,19 +0,0 @@ -#version 120 -//// GENERATED - EDITS WILL BE OVERWRITTEN - -struct buf -{ - vec4 color; -}; - -uniform buf ubuf; - -varying float vgradient; - -void main() -{ - float minAlpha = 0.5 * ubuf.color.w; - float maxAlpha = 0.829999983310699462890625 * ubuf.color.w; - float alpha = mix(minAlpha, maxAlpha, max(0.0, vgradient)); - gl_FragData[0] = vec4(ubuf.color.xyz * alpha, alpha); -} diff --git a/src/rendergraph/examples/shaders/endoftrack.vert b/src/rendergraph/examples/shaders/endoftrack.vert deleted file mode 100644 index b5741fc8f35..00000000000 --- a/src/rendergraph/examples/shaders/endoftrack.vert +++ /dev/null @@ -1,14 +0,0 @@ -#version 440 - -layout(location = 0) in vec4 position; -layout(location = 1) in float gradient; -layout(location = 0) out float vgradient; - -out gl_PerVertex { - vec4 gl_Position; -}; - -void main() { - vgradient = gradient; - gl_Position = position; -} diff --git a/src/rendergraph/examples/shaders/endoftrack.vert.gl b/src/rendergraph/examples/shaders/endoftrack.vert.gl deleted file mode 100644 index 053f0d12e78..00000000000 --- a/src/rendergraph/examples/shaders/endoftrack.vert.gl +++ /dev/null @@ -1,12 +0,0 @@ -#version 120 -//// GENERATED - EDITS WILL BE OVERWRITTEN - -varying float vgradient; -attribute float gradient; -attribute vec4 position; - -void main() -{ - vgradient = gradient; - gl_Position = position; -} diff --git a/src/rendergraph/examples/shaders/generate_shaders_gl.pl b/src/rendergraph/examples/shaders/generate_shaders_gl.pl deleted file mode 100755 index c528eb94747..00000000000 --- a/src/rendergraph/examples/shaders/generate_shaders_gl.pl +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/perl - -my @files = (glob("*.vert"),glob("*.frag")); - -open(GENERATED,">generated_shaders_gl.cmake"); -print(GENERATED "set(generated_shaders_gl\n"); -for $file (@files) -{ - system("qsb","--glsl","120",$file,"-o","/tmp/$$-$file.qsb"); - open(INFILE,"qsb --dump /tmp/$$-$file.qsb|"); - open(OUTFILE,">$file.gl"); - $ok = 0; - $comment_added = 0; - print "Generating $file.gl from $file\n"; - while () - { - if ($in_shader_block == 2) - { - if (m/^\*\*/) - { - $in_shader_block = 0; - $ok = 1; - } - else - { - if (!$comment_added) - { - if (!m/^#/) - { - print(OUTFILE "//// GENERATED - EDITS WILL BE OVERWRITTEN\n"); - $comment_added = 1; - } - } - print OUTFILE "$_"; - } - } - elsif ($in_shader_block == 1) - { - chomp($_); - if ($_ eq "Contents:") - { - $in_shader_block = 2; - } - } - else - { - chomp($_); - if ($_ eq "Shader 1: GLSL 120 [Standard]") - { - $in_shader_block = 1; - } - } - } - close INFILE; - close OUTFILE; - if($ok) - { - print(GENERATED " $file.gl\n"); - } - else - { - print STDERR "Failed to generated $file.gl"; - unlink("$file.gl") - } - unlink("/tmp/$$-$file.qsb"); -} -print(GENERATED ")\n"); -close GENERATED; diff --git a/src/rendergraph/examples/shaders/generated_shaders_gl.cmake b/src/rendergraph/examples/shaders/generated_shaders_gl.cmake deleted file mode 100644 index e3bd0c644f2..00000000000 --- a/src/rendergraph/examples/shaders/generated_shaders_gl.cmake +++ /dev/null @@ -1,6 +0,0 @@ -set(generated_shaders_gl - endoftrack.vert.gl - texture.vert.gl - endoftrack.frag.gl - texture.frag.gl -) diff --git a/src/rendergraph/examples/shaders/texture.frag b/src/rendergraph/examples/shaders/texture.frag deleted file mode 100644 index bbe37bccd69..00000000000 --- a/src/rendergraph/examples/shaders/texture.frag +++ /dev/null @@ -1,9 +0,0 @@ -#version 440 - -layout(binding = 1) uniform sampler2D texture1; -layout(location = 0) in vec2 vTexcoord; -layout(location = 0) out vec4 fragColor; - -void main() { - fragColor = texture(texture1, vTexcoord); -} diff --git a/src/rendergraph/examples/shaders/texture.frag.gl b/src/rendergraph/examples/shaders/texture.frag.gl deleted file mode 100644 index b2d03f1352c..00000000000 --- a/src/rendergraph/examples/shaders/texture.frag.gl +++ /dev/null @@ -1,11 +0,0 @@ -#version 120 -//// GENERATED - EDITS WILL BE OVERWRITTEN - -uniform sampler2D texture1; - -varying vec2 vTexcoord; - -void main() -{ - gl_FragData[0] = texture2D(texture1, vTexcoord); -} diff --git a/src/rendergraph/examples/shaders/texture.vert.qsb b/src/rendergraph/examples/shaders/texture.vert.qsb deleted file mode 100644 index 84fa7e916fe48a406e5e2205a9c2988b4c4e84dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 607 zcmV-l0-*f>00rZCoRw2eZ`wc*9ovM4B?JNqByB#HaOsDH(uh`-5LJ6>4mnh6?iFB2 zEfpLY8&OsH5&ez*6TMXJ%=+1^D%7fj*1Pj&=DpdmA)*qc=JKjhOcPqsm_q(V(4-E7qRXK9f}l+ct<+q`GzH-BX9(2R!MRm6R* z*e@ey=hZez{Es=<3)o%k{yN3`rB#68oGoSS?q@~(NcIA3&%h-vn> z(YxS%_$6QxSGaE$SJn)KuL3@q`2jz7p(XYVeiix0?AMTAHGQWu%s6V$tV4efnsvNC z4;uT>aG z$EEd0F8B{d~R-cRoORr*&f;Qt}ciq`hMvz$bWAe`&xmlsMc;wTx%dX!AnSEboz!?-7pC|LE? zeP5|$9!$e%CMi1M2SdwY^d*?z>g8m7sh2mC)i?|zzpsWdmyMEml1Adqfu6n#7eUM| t2vr#PT3UVl1mt{rU@=JK_VdU0sN|UR(oGxHPc6!OrL61c_8Su|ltEZLJ_G;& diff --git a/src/rendergraph/geometry.cpp b/src/rendergraph/geometry.cpp index cc06ce59077..61ce4f4e45e 100644 --- a/src/rendergraph/geometry.cpp +++ b/src/rendergraph/geometry.cpp @@ -1,5 +1,7 @@ #include "rendergraph/geometry.h" +#include + #include "geometry_impl.h" using namespace rendergraph; @@ -21,6 +23,19 @@ void Geometry::setAttributeValues(int attributePosition, const float* data, int m_pImpl->setAttributeValues(attributePosition, data, numTuples); } +float* Geometry::vertexData() { + return m_pImpl->vertexData(); +} + +template<> +QVector2D* Geometry::vertexDataAs() { + return m_pImpl->vertexDataAs(); +} + +void Geometry::allocate(int vertexCount) { + m_pImpl->allocate(vertexCount); +} + void Geometry::setDrawingMode(Geometry::DrawingMode mode) { m_pImpl->setDrawingMode(mode); } diff --git a/src/rendergraph/geometry.h b/src/rendergraph/geometry.h index 7f6829f29cf..7a5119ec6e7 100644 --- a/src/rendergraph/geometry.h +++ b/src/rendergraph/geometry.h @@ -20,6 +20,13 @@ class rendergraph::Geometry { void setAttributeValues(int attributePosition, const float* data, int numTuples); Impl& impl() const; + float* vertexData(); + + template + T* vertexDataAs(); + + void allocate(int vertexCount); + DrawingMode drawingMode() const; void setDrawingMode(DrawingMode mode); diff --git a/src/waveform/renderers/allshader/endoftrackmaterial.cpp b/src/rendergraph/material/endoftrackmaterial.cpp similarity index 100% rename from src/waveform/renderers/allshader/endoftrackmaterial.cpp rename to src/rendergraph/material/endoftrackmaterial.cpp diff --git a/src/waveform/renderers/allshader/endoftrackmaterial.h b/src/rendergraph/material/endoftrackmaterial.h similarity index 100% rename from src/waveform/renderers/allshader/endoftrackmaterial.h rename to src/rendergraph/material/endoftrackmaterial.h diff --git a/src/rendergraph/examples/common/texturematerial.cpp b/src/rendergraph/material/texturematerial.cpp similarity index 90% rename from src/rendergraph/examples/common/texturematerial.cpp rename to src/rendergraph/material/texturematerial.cpp index b437afeba49..bbf8de9998a 100644 --- a/src/rendergraph/examples/common/texturematerial.cpp +++ b/src/rendergraph/material/texturematerial.cpp @@ -18,7 +18,7 @@ TextureMaterial::TextureMaterial() } /* static */ const UniformSet& TextureMaterial::uniforms() { - static UniformSet set = makeUniformSet({"ubuf.matrix"}); + static UniformSet set = makeUniformSet({"ubuf.matrix", "ubuf.color"}); return set; } diff --git a/src/rendergraph/examples/common/texturematerial.h b/src/rendergraph/material/texturematerial.h similarity index 100% rename from src/rendergraph/examples/common/texturematerial.h rename to src/rendergraph/material/texturematerial.h diff --git a/src/rendergraph/material/unicolormaterial.cpp b/src/rendergraph/material/unicolormaterial.cpp new file mode 100644 index 00000000000..b6aa7dfb1c6 --- /dev/null +++ b/src/rendergraph/material/unicolormaterial.cpp @@ -0,0 +1,38 @@ +#include "unicolormaterial.h" + +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +UniColorMaterial::UniColorMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& UniColorMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position"}); + return set; +} + +/* static */ const UniformSet& UniColorMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.matrix", "ubuf.color"}); + return set; +} + +MaterialType* UniColorMaterial::type() const { + static MaterialType type; + return &type; +} + +int UniColorMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +MaterialShader* UniColorMaterial::createShader() const { + return new MaterialShader("unicolor.vert", "unicolor.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/material/unicolormaterial.h b/src/rendergraph/material/unicolormaterial.h new file mode 100644 index 00000000000..1d3ee5fe304 --- /dev/null +++ b/src/rendergraph/material/unicolormaterial.h @@ -0,0 +1,21 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" + +namespace rendergraph { +class UniColorMaterial; +} + +class rendergraph::UniColorMaterial : public rendergraph::Material { + public: + UniColorMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + MaterialShader* createShader() const override; +}; diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 08e85b9784b..666e5064c95 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -27,6 +27,12 @@ add_library(rendergraph_gl ../uniformscache.h ../uniformset.cpp ../uniformset.h + ../material/endoftrackmaterial.cpp + ../material/endoftrackmaterial.h + ../material/texturematerial.cpp + ../material/texturematerial.h + ../material/unicolormaterial.cpp + ../material/unicolormaterial.h geometrynode_impl.cpp graph.cpp graph.h diff --git a/src/rendergraph/opengl/geometrynode_impl.cpp b/src/rendergraph/opengl/geometrynode_impl.cpp index 66ab05c50fd..30c6e6cf944 100644 --- a/src/rendergraph/opengl/geometrynode_impl.cpp +++ b/src/rendergraph/opengl/geometrynode_impl.cpp @@ -57,7 +57,10 @@ void GeometryNode::Impl::render() { for (int i = 0; i < geometry.attributeCount(); i++) { int location = material.attributeLocation(i); shader.enableAttributeArray(location); - shader.setAttributeArray(location, geometry.vertexData(i), geometry.tupleSize(i)); + shader.setAttributeArray(location, + geometry.vertexData() + geometry.offset(i), + geometry.tupleSize(i), + geometry.stride()); } // TODO multiple textures diff --git a/src/rendergraph/opengl/private/geometry_impl.h b/src/rendergraph/opengl/private/geometry_impl.h index 3f59a286f06..75eff3b5a49 100644 --- a/src/rendergraph/opengl/private/geometry_impl.h +++ b/src/rendergraph/opengl/private/geometry_impl.h @@ -9,10 +9,19 @@ class rendergraph::Geometry::Impl { : m_drawingMode(Geometry::DrawingMode::TriangleStrip) // to mimic sg default , m_vertexCount(vertexCount) { + int offset = 0; for (const auto& attribute : attributeSet.impl().attributes()) { - m_data.emplace_back(std::vector(m_vertexCount * attribute.m_tupleSize)); + m_offsets.push_back(offset); + offset += attribute.m_tupleSize; m_tupleSizes.push_back(attribute.m_tupleSize); } + m_stride = offset * sizeof(float); + m_data.resize(offset * vertexCount); + } + + void allocate(int vertexCount) { + m_vertexCount = vertexCount; + m_data.resize((m_stride / sizeof(float)) * m_vertexCount); } int attributeCount() const { @@ -23,18 +32,41 @@ class rendergraph::Geometry::Impl { return m_vertexCount; } - float const* vertexData(int attributeIndex) const { - return m_data[attributeIndex].data(); + float* vertexData() { + return m_data.data(); + } + + template + T* vertexDataAs() { + return reinterpret_cast(vertexData()); + } + + int offset(int attributeIndex) const { + return m_offsets[attributeIndex]; } int tupleSize(int attributeIndex) const { return m_tupleSizes[attributeIndex]; } + int stride() const { + return m_stride; + } + void setAttributeValues(int attributePosition, const float* from, int numTuples) { - memcpy(m_data[attributePosition].data(), - from, - numTuples * m_tupleSizes[attributePosition] * sizeof(float)); + const int offset = m_offsets[attributePosition]; + const int tupleSize = m_tupleSizes[attributePosition]; + const int skip = m_stride / sizeof(float) - tupleSize; + + float* to = m_data.data(); + to += offset; + while (numTuples--) { + int k = tupleSize; + while (k--) { + *to++ = *from++; + } + to += skip; + } } void setDrawingMode(Geometry::DrawingMode mode) { @@ -49,5 +81,7 @@ class rendergraph::Geometry::Impl { Geometry::DrawingMode m_drawingMode; int m_vertexCount; std::vector m_tupleSizes; - std::vector> m_data; + std::vector m_offsets; + int m_stride; + std::vector m_data; }; diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index fe6260420e1..dc0cf95d758 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -27,6 +27,12 @@ add_library(rendergraph_sg ../uniformscache.h ../uniformset.cpp ../uniformset.h + ../material/endoftrackmaterial.cpp + ../material/endoftrackmaterial.h + ../material/texturematerial.cpp + ../material/texturematerial.h + ../material/unicolormaterial.cpp + ../material/unicolormaterial.h materialshader_impl.cpp private/attributeset_impl.h private/context_impl.h diff --git a/src/rendergraph/scenegraph/private/geometry_impl.h b/src/rendergraph/scenegraph/private/geometry_impl.h index fa6ea95e5e5..b3e1cd80389 100644 --- a/src/rendergraph/scenegraph/private/geometry_impl.h +++ b/src/rendergraph/scenegraph/private/geometry_impl.h @@ -45,6 +45,15 @@ class rendergraph::Geometry::Impl : public QSGGeometry { return fromSgDrawingMode(QSGGeometry::drawingMode()); } + float* vertexData() { + return static_cast(QSGGeometry::vertexData()); + } + + template + T* vertexDataAs() { + return static_cast(QSGGeometry::vertexData()); + } + private: const int m_stride; diff --git a/src/rendergraph/types.cpp b/src/rendergraph/types.cpp index 2962b47e190..654fa6567e1 100644 --- a/src/rendergraph/types.cpp +++ b/src/rendergraph/types.cpp @@ -25,13 +25,13 @@ int rendergraph::sizeOf(Type type) { case Type::Float: return sizeof(GLfloat); case Type::Vector2D: - return sizeof(QVector2D); + return sizeof(GLfloat) * 2; case Type::Vector3D: - return sizeof(QVector3D); + return sizeof(GLfloat) * 3; case Type::Vector4D: - return sizeof(QVector4D); + return sizeof(GLfloat) * 4; case Type::Matrix4x4: - return sizeof(QMatrix4x4); + return sizeof(GLfloat) * 4 * 4; } return 0; } diff --git a/src/rendergraph/uniformscache.h b/src/rendergraph/uniformscache.h index 4d93f1b2018..bd303e936d6 100644 --- a/src/rendergraph/uniformscache.h +++ b/src/rendergraph/uniformscache.h @@ -1,6 +1,9 @@ #pragma once #include +#include +#include +#include #include "rendergraph/types.h" @@ -16,7 +19,17 @@ class rendergraph::UniformsCache { template void set(int uniformIndex, const T& value) { - set(uniformIndex, typeOf(), static_cast(&value), sizeof(T)); + set(uniformIndex, typeOf(), static_cast(&value), sizeOf(typeOf())); + } + + template<> + void set(int uniformIndex, const QColor& color) { + set(uniformIndex, QVector4D{color.redF(), color.greenF(), color.blueF(), color.alphaF()}); + } + + template<> + void set(int uniformIndex, const QMatrix4x4& matrix) { + set(uniformIndex, typeOf(), matrix.constData(), sizeOf(typeOf())); } template diff --git a/src/waveform/renderers/allshader/vertexupdater.h b/src/waveform/renderers/allshader/vertexupdater.h new file mode 100644 index 00000000000..820fca61985 --- /dev/null +++ b/src/waveform/renderers/allshader/vertexupdater.h @@ -0,0 +1,34 @@ +#pragma once + +namespace allshader { +class VertexUpdater; +} + +class allshader::VertexUpdater { + public: + VertexUpdater(QVector2D* pData) + : m_pData(pData), + m_pWrite(pData) { + } + + void addRectangle( + float x1, + float y1, + float x2, + float y2) { + addTriangle(x1, y1, x2, y1, x1, y2); + addTriangle(x1, y2, x2, y2, x2, y1); + } + void addTriangle(float x1, float y1, float x2, float y2, float x3, float y3) { + *m_pWrite++ = QVector2D{x1, y1}; + *m_pWrite++ = QVector2D{x2, y2}; + *m_pWrite++ = QVector2D{x3, y3}; + } + int index() const { + return static_cast(m_pWrite - m_pData); + } + + private: + QVector2D* const m_pData; + QVector2D* m_pWrite; +}; diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.cpp b/src/waveform/renderers/allshader/waveformrenderbeat.cpp index 39da6e21401..9be404132ca 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.cpp +++ b/src/waveform/renderers/allshader/waveformrenderbeat.cpp @@ -2,22 +2,27 @@ #include +#include "rendergraph/geometry.h" +#include "rendergraph/material/unicolormaterial.h" #include "skin/legacy/skincontext.h" #include "track/track.h" +#include "vertexupdater.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "widget/wskincolor.h" +using namespace rendergraph; + namespace allshader { WaveformRenderBeat::WaveformRenderBeat(WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type) - : WaveformRenderer(waveformWidget), + : ::WaveformRendererAbstract(waveformWidget), m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) { -} - -void WaveformRenderBeat::initializeGL() { - m_shader.init(); + setGeometry(std::make_unique(UniColorMaterial::attributes(), 0)); + setMaterial(std::make_unique()); + setUsePreprocess(true); + geometry().setDrawingMode(Geometry::DrawingMode::Triangles); } void WaveformRenderBeat::setup(const QDomNode& node, const SkinContext& context) { @@ -25,7 +30,13 @@ void WaveformRenderBeat::setup(const QDomNode& node, const SkinContext& context) m_color = WSkinColor::getCorrectColor(m_color).toRgb(); } -void WaveformRenderBeat::paintGL() { +void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* event) { + Q_UNUSED(painter); + Q_UNUSED(event); + DEBUG_ASSERT(false); +} + +void WaveformRenderBeat::preprocess() { TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); if (!trackInfo || (m_isSlipRenderer && !m_waveformRenderer->isSlipActive())) { @@ -47,13 +58,12 @@ void WaveformRenderBeat::paintGL() { const float devicePixelRatio = m_waveformRenderer->getDevicePixelRatio(); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - m_color.setAlphaF(alpha / 100.0f); const double trackSamples = m_waveformRenderer->getTrackSamples(); - if (trackSamples <= 0) { + if (trackSamples <= 0.0) { + geometry().allocate(0); + // TODO set dirty for scenegraph return; } @@ -87,8 +97,10 @@ void WaveformRenderBeat::paintGL() { } const int reserved = numBeatsInRange * numVerticesPerLine; - m_vertices.clear(); - m_vertices.reserve(reserved); + geometry().allocate(reserved); + // TODO set dirty for scenegraph + + VertexUpdater vertexUpdater{geometry().vertexDataAs()}; for (auto it = trackBeats->iteratorFrom(startPosition); it != trackBeats->cend() && *it <= endPosition; @@ -103,33 +115,18 @@ void WaveformRenderBeat::paintGL() { const float x1 = static_cast(xBeatPoint); const float x2 = x1 + 1.f; - m_vertices.addRectangle(x1, + vertexUpdater.addRectangle(x1, 0.f, x2, m_isSlipRenderer ? rendererBreadth / 2 : rendererBreadth); } - DEBUG_ASSERT(reserved == m_vertices.size()); - - const int positionLocation = m_shader.positionLocation(); - const int matrixLocation = m_shader.matrixLocation(); - const int colorLocation = m_shader.colorLocation(); - - m_shader.bind(); - m_shader.enableAttributeArray(positionLocation); + DEBUG_ASSERT(reserved == vertexUpdater.index()); const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - m_shader.setAttributeArray( - positionLocation, GL_FLOAT, m_vertices.constData(), 2); - - m_shader.setUniformValue(matrixLocation, matrix); - m_shader.setUniformValue(colorLocation, m_color); - - glDrawArrays(GL_TRIANGLES, 0, m_vertices.size()); - - m_shader.disableAttributeArray(positionLocation); - m_shader.release(); + material().setUniform(0, matrix); + material().setUniform(1, m_color); } } // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.h b/src/waveform/renderers/allshader/waveformrenderbeat.h index d3b2b79d1bc..2b9d99ccd9f 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.h +++ b/src/waveform/renderers/allshader/waveformrenderbeat.h @@ -1,11 +1,12 @@ #pragma once #include +#include -#include "shaders/unicolorshader.h" +#include "rendergraph/geometrynode.h" +#include "rendergraph/opacitynode.h" #include "util/class.h" -#include "waveform/renderers/allshader/vertexdata.h" -#include "waveform/renderers/allshader/waveformrenderer.h" +#include "waveform/renderers/waveformrendererabstract.h" class QDomNode; class SkinContext; @@ -14,21 +15,24 @@ namespace allshader { class WaveformRenderBeat; } -class allshader::WaveformRenderBeat final : public allshader::WaveformRenderer { +class allshader::WaveformRenderBeat final + : public ::WaveformRendererAbstract, + public rendergraph::GeometryNode { public: explicit WaveformRenderBeat(WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type = ::WaveformRendererAbstract::Play); + // Pure virtual from WaveformRendererAbstract, not used + void draw(QPainter* painter, QPaintEvent* event) override final; + void setup(const QDomNode& node, const SkinContext& context) override; - void paintGL() override; - void initializeGL() override; + + // Virtual for rendergraph::Node + void preprocess() override; private: - mixxx::UnicolorShader m_shader; QColor m_color; - VertexData m_vertices; - bool m_isSlipRenderer; DISALLOW_COPY_AND_ASSIGN(WaveformRenderBeat); diff --git a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp index 1896446b328..6b5b5f12f1c 100644 --- a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp +++ b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp @@ -5,8 +5,8 @@ #include #include "control/controlproxy.h" -#include "endoftrackmaterial.h" #include "rendergraph/geometry.h" +#include "rendergraph/material/endoftrackmaterial.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveformwidgetfactory.h" #include "widget/wskincolor.h" @@ -32,7 +32,7 @@ WaveformRendererEndOfTrack::WaveformRendererEndOfTrack( geometry().setAttributeValues(0, positionArray, 4); geometry().setAttributeValues(1, horizontalGradientArray, 4); - material().setUniform(0, QVector4D{1.f, 0.f, 0.f, 1.f}); + material().setUniform(0, QVector4D{0.f, 0.f, 0.f, 0.f}); } void WaveformRendererEndOfTrack::draw(QPainter* painter, QPaintEvent* event) { @@ -79,11 +79,7 @@ void WaveformRendererEndOfTrack::preprocess() { QColor color = m_color; color.setAlphaF(static_cast(alpha)); - material().setUniform(0, - QVector4D{color.redF(), - color.greenF(), - color.blueF(), - color.alphaF()}); + material().setUniform(0, color); } } From c2fffea8ea6cce862f037db0b21dd6ac8ca4ecab Mon Sep 17 00:00:00 2001 From: m0dB Date: Fri, 30 Aug 2024 23:28:11 +0200 Subject: [PATCH 03/64] preroll/postroll using rendergraph --- res/shaders/rendergraph/CMakeLists.txt | 2 + .../rendergraph/generated_shaders_gl.cmake | 2 + res/shaders/rendergraph/pattern.frag | 9 ++ res/shaders/rendergraph/pattern.frag.gl | 11 ++ res/shaders/rendergraph/pattern.vert | 15 ++ res/shaders/rendergraph/pattern.vert.gl | 19 +++ res/shaders/rendergraph/unicolor.frag | 4 +- res/shaders/rendergraph/unicolor.vert | 4 +- src/rendergraph/geometry.cpp | 10 ++ src/rendergraph/geometry.h | 17 +++ src/rendergraph/material/patternmaterial.cpp | 38 +++++ src/rendergraph/material/patternmaterial.h | 34 +++++ src/rendergraph/material/texturematerial.cpp | 2 +- src/rendergraph/material/texturematerial.h | 2 +- src/rendergraph/opengl/CMakeLists.txt | 2 + src/rendergraph/opengl/private/texture_impl.h | 17 ++- src/rendergraph/scenegraph/CMakeLists.txt | 2 + .../allshader/texturedvertexupdater.h | 51 +++++++ .../renderers/allshader/vertexupdater.h | 16 +- .../allshader/waveformrenderbeat.cpp | 24 +-- .../renderers/allshader/waveformrenderbeat.h | 3 +- .../allshader/waveformrendererpreroll.cpp | 139 +++++++++--------- .../allshader/waveformrendererpreroll.h | 30 ++-- 23 files changed, 341 insertions(+), 112 deletions(-) create mode 100644 res/shaders/rendergraph/pattern.frag create mode 100644 res/shaders/rendergraph/pattern.frag.gl create mode 100644 res/shaders/rendergraph/pattern.vert create mode 100644 res/shaders/rendergraph/pattern.vert.gl create mode 100644 src/rendergraph/material/patternmaterial.cpp create mode 100644 src/rendergraph/material/patternmaterial.h create mode 100644 src/waveform/renderers/allshader/texturedvertexupdater.h diff --git a/res/shaders/rendergraph/CMakeLists.txt b/res/shaders/rendergraph/CMakeLists.txt index 2c908fdd8b3..fa03d006e94 100644 --- a/res/shaders/rendergraph/CMakeLists.txt +++ b/res/shaders/rendergraph/CMakeLists.txt @@ -5,6 +5,8 @@ set(shaders texture.frag unicolor.vert unicolor.frag + pattern.vert + pattern.frag ) qt6_add_shaders(rendergraph_sg "shaders-sg" diff --git a/res/shaders/rendergraph/generated_shaders_gl.cmake b/res/shaders/rendergraph/generated_shaders_gl.cmake index 9c72d8dd115..e2b3318bc3e 100644 --- a/res/shaders/rendergraph/generated_shaders_gl.cmake +++ b/res/shaders/rendergraph/generated_shaders_gl.cmake @@ -1,8 +1,10 @@ set(generated_shaders_gl endoftrack.vert.gl + pattern.vert.gl texture.vert.gl unicolor.vert.gl endoftrack.frag.gl + pattern.frag.gl texture.frag.gl unicolor.frag.gl ) diff --git a/res/shaders/rendergraph/pattern.frag b/res/shaders/rendergraph/pattern.frag new file mode 100644 index 00000000000..5aa3d1556b1 --- /dev/null +++ b/res/shaders/rendergraph/pattern.frag @@ -0,0 +1,9 @@ +#version 440 + +layout(binding = 1) uniform sampler2D texture1; +layout(location = 0) in vec2 vTexcoord; +layout(location = 0) out vec4 fragColor; + +void main() { + fragColor = texture(texture1, fract(vTexcoord)); +} diff --git a/res/shaders/rendergraph/pattern.frag.gl b/res/shaders/rendergraph/pattern.frag.gl new file mode 100644 index 00000000000..376c71668ba --- /dev/null +++ b/res/shaders/rendergraph/pattern.frag.gl @@ -0,0 +1,11 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +uniform sampler2D texture1; + +varying vec2 vTexcoord; + +void main() +{ + gl_FragData[0] = texture2D(texture1, fract(vTexcoord)); +} diff --git a/res/shaders/rendergraph/pattern.vert b/res/shaders/rendergraph/pattern.vert new file mode 100644 index 00000000000..46e4c84d254 --- /dev/null +++ b/res/shaders/rendergraph/pattern.vert @@ -0,0 +1,15 @@ +#version 440 + +layout(location = 0) in vec4 position; +layout(location = 1) in vec2 texcoord; +layout(location = 0) out vec2 vTexcoord; + +layout(std140, binding = 0) uniform buf { + mat4 matrix; +} +ubuf; + +void main() { + vTexcoord = texcoord; + gl_Position = ubuf.matrix * position; +} diff --git a/res/shaders/rendergraph/pattern.vert.gl b/res/shaders/rendergraph/pattern.vert.gl new file mode 100644 index 00000000000..a3d58014be3 --- /dev/null +++ b/res/shaders/rendergraph/pattern.vert.gl @@ -0,0 +1,19 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +struct buf +{ + mat4 matrix; +}; + +uniform buf ubuf; + +varying vec2 vTexcoord; +attribute vec2 texcoord; +attribute vec4 position; + +void main() +{ + vTexcoord = texcoord; + gl_Position = ubuf.matrix * position; +} diff --git a/res/shaders/rendergraph/unicolor.frag b/res/shaders/rendergraph/unicolor.frag index 4c2afaaefb0..e4a8535e349 100644 --- a/res/shaders/rendergraph/unicolor.frag +++ b/res/shaders/rendergraph/unicolor.frag @@ -1,13 +1,13 @@ #version 440 -layout(location = 0) out vec4 fragColor; - layout(std140, binding = 0) uniform buf { mat4 matrix; vec4 color; } ubuf; +layout(location = 0) out vec4 fragColor; + void main() { fragColor = vec4(ubuf.color.xyz * ubuf.color.w, ubuf.color.w); // premultiple alpha } diff --git a/res/shaders/rendergraph/unicolor.vert b/res/shaders/rendergraph/unicolor.vert index 05862534df7..9e268c18fba 100644 --- a/res/shaders/rendergraph/unicolor.vert +++ b/res/shaders/rendergraph/unicolor.vert @@ -1,13 +1,13 @@ #version 440 -layout(location = 0) in vec4 position; - layout(std140, binding = 0) uniform buf { mat4 matrix; vec4 color; } ubuf; +layout(location = 0) in vec4 position; + void main() { gl_Position = ubuf.matrix * position; } diff --git a/src/rendergraph/geometry.cpp b/src/rendergraph/geometry.cpp index 61ce4f4e45e..6ac75b07860 100644 --- a/src/rendergraph/geometry.cpp +++ b/src/rendergraph/geometry.cpp @@ -32,6 +32,16 @@ QVector2D* Geometry::vertexDataAs() { return m_pImpl->vertexDataAs(); } +template<> +Geometry::Point2D* Geometry::vertexDataAs() { + return m_pImpl->vertexDataAs(); +} + +template<> +Geometry::TexturedPoint2D* Geometry::vertexDataAs() { + return m_pImpl->vertexDataAs(); +} + void Geometry::allocate(int vertexCount) { m_pImpl->allocate(vertexCount); } diff --git a/src/rendergraph/geometry.h b/src/rendergraph/geometry.h index 7a5119ec6e7..09de345772f 100644 --- a/src/rendergraph/geometry.h +++ b/src/rendergraph/geometry.h @@ -1,5 +1,6 @@ #pragma once +#include #include namespace rendergraph { @@ -9,6 +10,22 @@ class AttributeSet; class rendergraph::Geometry { public: + struct Point2D { + QVector2D position2D; + Point2D(float x, float y) + : position2D{x, y} { + } + }; + + struct TexturedPoint2D { + QVector2D position2D; + QVector2D texcoord2D; + TexturedPoint2D(float x, float y, float tx, float ty) + : position2D{x, y}, + texcoord2D{tx, ty} { + } + }; + enum class DrawingMode { Triangles, TriangleStrip diff --git a/src/rendergraph/material/patternmaterial.cpp b/src/rendergraph/material/patternmaterial.cpp new file mode 100644 index 00000000000..55f4b0430bd --- /dev/null +++ b/src/rendergraph/material/patternmaterial.cpp @@ -0,0 +1,38 @@ +#include "patternmaterial.h" + +#include +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" + +using namespace rendergraph; + +PatternMaterial::PatternMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& PatternMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "texcoord"}); + return set; +} + +/* static */ const UniformSet& PatternMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.matrix"}); + return set; +} + +MaterialType* PatternMaterial::type() const { + static MaterialType type; + return &type; +} + +int PatternMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +MaterialShader* PatternMaterial::createShader() const { + return new MaterialShader("pattern.vert", "pattern.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/material/patternmaterial.h b/src/rendergraph/material/patternmaterial.h new file mode 100644 index 00000000000..475381e6a49 --- /dev/null +++ b/src/rendergraph/material/patternmaterial.h @@ -0,0 +1,34 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" +#include "rendergraph/texture.h" +#include "rendergraph/uniformset.h" + +namespace rendergraph { +class PatternMaterial; +} + +class rendergraph::PatternMaterial : public rendergraph::Material { + public: + PatternMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + MaterialShader* createShader() const override; + + Texture* texture(int /*binding*/) const override { + return m_pTexture.get(); + } + + void setTexture(std::unique_ptr texture) { + m_pTexture = std::move(texture); + } + + private: + std::unique_ptr m_pTexture; +}; diff --git a/src/rendergraph/material/texturematerial.cpp b/src/rendergraph/material/texturematerial.cpp index bbf8de9998a..b437afeba49 100644 --- a/src/rendergraph/material/texturematerial.cpp +++ b/src/rendergraph/material/texturematerial.cpp @@ -18,7 +18,7 @@ TextureMaterial::TextureMaterial() } /* static */ const UniformSet& TextureMaterial::uniforms() { - static UniformSet set = makeUniformSet({"ubuf.matrix", "ubuf.color"}); + static UniformSet set = makeUniformSet({"ubuf.matrix"}); return set; } diff --git a/src/rendergraph/material/texturematerial.h b/src/rendergraph/material/texturematerial.h index 6f5c8460ec0..d892989d08d 100644 --- a/src/rendergraph/material/texturematerial.h +++ b/src/rendergraph/material/texturematerial.h @@ -21,7 +21,7 @@ class rendergraph::TextureMaterial : public rendergraph::Material { MaterialShader* createShader() const override; - Texture* texture(int binding) const override { + Texture* texture(int /*binding*/) const override { return m_pTexture.get(); } diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 666e5064c95..6a106948c45 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -29,6 +29,8 @@ add_library(rendergraph_gl ../uniformset.h ../material/endoftrackmaterial.cpp ../material/endoftrackmaterial.h + ../material/patternmaterial.cpp + ../material/patternmaterial.h ../material/texturematerial.cpp ../material/texturematerial.h ../material/unicolormaterial.cpp diff --git a/src/rendergraph/opengl/private/texture_impl.h b/src/rendergraph/opengl/private/texture_impl.h index 73ecd89dfdf..bb884585176 100644 --- a/src/rendergraph/opengl/private/texture_impl.h +++ b/src/rendergraph/opengl/private/texture_impl.h @@ -7,8 +7,9 @@ class rendergraph::Texture::Impl { public: Impl(Context& context, const QImage& image) - : m_pTexture(new QOpenGLTexture(image.convertToFormat( - QImage::Format_ARGB32_Premultiplied))) { + : m_pTexture(new QOpenGLTexture(premultiplyAlpha(image))) { + m_pTexture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); + m_pTexture->setWrapMode(QOpenGLTexture::ClampToEdge); } QOpenGLTexture* glTexture() const { @@ -17,4 +18,16 @@ class rendergraph::Texture::Impl { private: const std::unique_ptr m_pTexture{}; + + static QImage premultiplyAlpha(const QImage& image) { + if (image.format() == QImage::Format_RGBA8888_Premultiplied) { + return QImage(image.bits(), image.width(), image.height(), QImage::Format_RGBA8888); + } + return QImage( + image.convertToFormat(QImage::Format_RGBA8888_Premultiplied) + .bits(), + image.width(), + image.height(), + QImage::Format_RGBA8888); + } }; diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index dc0cf95d758..3c0ae4e2557 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -29,6 +29,8 @@ add_library(rendergraph_sg ../uniformset.h ../material/endoftrackmaterial.cpp ../material/endoftrackmaterial.h + ../material/patternmaterial.cpp + ../material/patternmaterial.h ../material/texturematerial.cpp ../material/texturematerial.h ../material/unicolormaterial.cpp diff --git a/src/waveform/renderers/allshader/texturedvertexupdater.h b/src/waveform/renderers/allshader/texturedvertexupdater.h new file mode 100644 index 00000000000..a61f6877ae4 --- /dev/null +++ b/src/waveform/renderers/allshader/texturedvertexupdater.h @@ -0,0 +1,51 @@ +#pragma once + +#include "rendergraph/geometry.h" + +namespace rendergraph { +class TexturedVertexUpdater; +} + +class rendergraph::TexturedVertexUpdater { + public: + TexturedVertexUpdater(Geometry::TexturedPoint2D* pData) + : m_pData(pData), + m_pWrite(pData) { + } + + void addRectangle( + float x1, + float y1, + float x2, + float y2, + float tx1, + float ty1, + float tx2, + float ty2) { + addTriangle(x1, y1, x2, y1, x1, y2, tx1, ty1, tx2, ty1, tx1, ty2); + addTriangle(x1, y2, x2, y2, x2, y1, tx1, ty2, tx2, ty2, tx2, ty1); + } + void addTriangle(float x1, + float y1, + float x2, + float y2, + float x3, + float y3, + float tx1, + float ty1, + float tx2, + float ty2, + float tx3, + float ty3) { + *m_pWrite++ = Geometry::TexturedPoint2D{x1, y1, tx1, ty1}; + *m_pWrite++ = Geometry::TexturedPoint2D{x2, y2, tx2, ty2}; + *m_pWrite++ = Geometry::TexturedPoint2D{x3, y3, tx3, ty3}; + } + int index() const { + return static_cast(m_pWrite - m_pData); + } + + private: + Geometry::TexturedPoint2D* const m_pData; + Geometry::TexturedPoint2D* m_pWrite; +}; diff --git a/src/waveform/renderers/allshader/vertexupdater.h b/src/waveform/renderers/allshader/vertexupdater.h index 820fca61985..50032ee0aa2 100644 --- a/src/waveform/renderers/allshader/vertexupdater.h +++ b/src/waveform/renderers/allshader/vertexupdater.h @@ -1,12 +1,12 @@ #pragma once -namespace allshader { +namespace rendergraph { class VertexUpdater; } -class allshader::VertexUpdater { +class rendergraph::VertexUpdater { public: - VertexUpdater(QVector2D* pData) + VertexUpdater(Geometry::Point2D* pData) : m_pData(pData), m_pWrite(pData) { } @@ -20,15 +20,15 @@ class allshader::VertexUpdater { addTriangle(x1, y2, x2, y2, x2, y1); } void addTriangle(float x1, float y1, float x2, float y2, float x3, float y3) { - *m_pWrite++ = QVector2D{x1, y1}; - *m_pWrite++ = QVector2D{x2, y2}; - *m_pWrite++ = QVector2D{x3, y3}; + *m_pWrite++ = Geometry::Point2D{x1, y1}; + *m_pWrite++ = Geometry::Point2D{x2, y2}; + *m_pWrite++ = Geometry::Point2D{x3, y3}; } int index() const { return static_cast(m_pWrite - m_pData); } private: - QVector2D* const m_pData; - QVector2D* m_pWrite; + Geometry::Point2D* const m_pData; + Geometry::Point2D* m_pWrite; }; diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.cpp b/src/waveform/renderers/allshader/waveformrenderbeat.cpp index 9be404132ca..113b8ece90a 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.cpp +++ b/src/waveform/renderers/allshader/waveformrenderbeat.cpp @@ -37,10 +37,16 @@ void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* event) { } void WaveformRenderBeat::preprocess() { - TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); + if (!preprocessSelf()) { + geometry().allocate(0); + } +} + +bool WaveformRenderBeat::preprocessSelf() { + const TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); if (!trackInfo || (m_isSlipRenderer && !m_waveformRenderer->isSlipActive())) { - return; + return false; } auto positionType = m_isSlipRenderer ? ::WaveformRendererAbstract::Slip @@ -48,12 +54,12 @@ void WaveformRenderBeat::preprocess() { mixxx::BeatsPointer trackBeats = trackInfo->getBeats(); if (!trackBeats) { - return; + return false; } int alpha = m_waveformRenderer->getBeatGridAlpha(); if (alpha == 0) { - return; + return false; } const float devicePixelRatio = m_waveformRenderer->getDevicePixelRatio(); @@ -62,9 +68,7 @@ void WaveformRenderBeat::preprocess() { const double trackSamples = m_waveformRenderer->getTrackSamples(); if (trackSamples <= 0.0) { - geometry().allocate(0); - // TODO set dirty for scenegraph - return; + return false; } const double firstDisplayedPosition = @@ -78,7 +82,7 @@ void WaveformRenderBeat::preprocess() { lastDisplayedPosition * trackSamples); if (!startPosition.isValid() || !endPosition.isValid()) { - return; + return false; } const float rendererBreadth = m_waveformRenderer->getBreadth(); @@ -100,7 +104,7 @@ void WaveformRenderBeat::preprocess() { geometry().allocate(reserved); // TODO set dirty for scenegraph - VertexUpdater vertexUpdater{geometry().vertexDataAs()}; + VertexUpdater vertexUpdater{geometry().vertexDataAs()}; for (auto it = trackBeats->iteratorFrom(startPosition); it != trackBeats->cend() && *it <= endPosition; @@ -127,6 +131,8 @@ void WaveformRenderBeat::preprocess() { material().setUniform(0, matrix); material().setUniform(1, m_color); + + return true; } } // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.h b/src/waveform/renderers/allshader/waveformrenderbeat.h index 2b9d99ccd9f..5a9d6e7535f 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.h +++ b/src/waveform/renderers/allshader/waveformrenderbeat.h @@ -4,7 +4,6 @@ #include #include "rendergraph/geometrynode.h" -#include "rendergraph/opacitynode.h" #include "util/class.h" #include "waveform/renderers/waveformrendererabstract.h" @@ -35,5 +34,7 @@ class allshader::WaveformRenderBeat final QColor m_color; bool m_isSlipRenderer; + bool preprocessSelf(); + DISALLOW_COPY_AND_ASSIGN(WaveformRenderBeat); }; diff --git a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp index 89948347d87..01258dac89d 100644 --- a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp +++ b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp @@ -1,11 +1,14 @@ #include "waveform/renderers/allshader/waveformrendererpreroll.h" #include -#include #include #include +#include "rendergraph/context.h" +#include "rendergraph/geometry.h" +#include "rendergraph/material/patternmaterial.h" #include "skin/legacy/skincontext.h" +#include "texturedvertexupdater.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "widget/wskincolor.h" @@ -20,7 +23,7 @@ QImage drawPrerollImage(float markerLength, const float imageW = static_cast(imagePixelW) / devicePixelRatio; const float imageH = static_cast(imagePixelH) / devicePixelRatio; - QImage image(imagePixelW, imagePixelH, QImage::Format_ARGB32_Premultiplied); + QImage image(imagePixelW, imagePixelH, QImage::Format_RGBA8888_Premultiplied); image.setDevicePixelRatio(devicePixelRatio); const float penWidth = 1.5f; @@ -47,7 +50,7 @@ QImage drawPrerollImage(float markerLength, path.lineTo(p0); path.closeSubpath(); QColor fillColor = color; - fillColor.setAlphaF(0.5f); + fillColor.setAlphaF(0.25f); painter.fillPath(path, QBrush(fillColor)); painter.drawPath(path); @@ -57,13 +60,19 @@ QImage drawPrerollImage(float markerLength, } } // anonymous namespace +using namespace rendergraph; + namespace allshader { WaveformRendererPreroll::WaveformRendererPreroll( WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type) - : WaveformRenderer(waveformWidget), + : ::WaveformRendererAbstract(waveformWidget), m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) { + setGeometry(std::make_unique(PatternMaterial::attributes(), 0)); + setMaterial(std::make_unique()); + setUsePreprocess(true); + geometry().setDrawingMode(Geometry::DrawingMode::Triangles); } WaveformRendererPreroll::~WaveformRendererPreroll() = default; @@ -74,14 +83,23 @@ void WaveformRendererPreroll::setup( m_color = WSkinColor::getCorrectColor(m_color); } -void WaveformRendererPreroll::initializeGL() { - m_shader.init(); +void WaveformRendererPreroll::draw(QPainter* painter, QPaintEvent* event) { + Q_UNUSED(painter); + Q_UNUSED(event); + DEBUG_ASSERT(false); +} + +void WaveformRendererPreroll::preprocess() { + if (!preprocessSelf()) { + geometry().allocate(0); + } } -void WaveformRendererPreroll::paintGL() { - const TrackPointer track = m_waveformRenderer->getTrackInfo(); - if (!track || (m_isSlipRenderer && !m_waveformRenderer->isSlipActive())) { - return; +bool WaveformRendererPreroll::preprocessSelf() { + const TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); + + if (!trackInfo || (m_isSlipRenderer && !m_waveformRenderer->isSlipActive())) { + return false; } auto positionType = m_isSlipRenderer ? ::WaveformRendererAbstract::Slip @@ -95,11 +113,15 @@ void WaveformRendererPreroll::paintGL() { // to indicate the respective zones. const bool preRollVisible = firstDisplayedPosition < 0; const bool postRollVisible = lastDisplayedPosition > 1; + const int numVerticesPerRectangle = 6; - if (!(preRollVisible || postRollVisible)) { - return; + if (!preRollVisible && !postRollVisible) { + return false; } + const int reserved = (preRollVisible ? numVerticesPerRectangle : 0) + + (postRollVisible ? numVerticesPerRectangle : 0); + const double playMarkerPosition = m_waveformRenderer->getPlayMarkerPosition(); const double vSamplesPerPixel = m_waveformRenderer->getVisualSamplePerPixel(); const double numberOfVSamples = m_waveformRenderer->getLength() * vSamplesPerPixel; @@ -125,36 +147,25 @@ void WaveformRendererPreroll::paintGL() { // has changed size last time. m_markerLength = markerLength; m_markerBreadth = markerBreadth; - m_texture.setData(drawPrerollImage(m_markerLength, - m_markerBreadth, - m_waveformRenderer->getDevicePixelRatio(), - m_color)); + Context context; + dynamic_cast(material()) + .setTexture(std::make_unique(context, + drawPrerollImage(m_markerLength, + m_markerBreadth, + m_waveformRenderer->getDevicePixelRatio(), + m_color))); } - if (!m_texture.isStorageAllocated()) { - return; + if (!dynamic_cast(material()).texture(0)) { + return false; } - const int matrixLocation = m_shader.matrixLocation(); - const int textureLocation = m_shader.textureLocation(); - const int positionLocation = m_shader.positionLocation(); - const int texcoordLocation = m_shader.texcoordLocation(); - - // Set up the shader - m_shader.bind(); - - m_shader.enableAttributeArray(positionLocation); - m_shader.enableAttributeArray(texcoordLocation); - - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - - m_shader.setUniformValue(matrixLocation, matrix); - m_shader.setUniformValue(textureLocation, 0); - - m_texture.bind(); + geometry().allocate(reserved); const float end = m_waveformRenderer->getLength(); + TexturedVertexUpdater vertexUpdater{geometry().vertexDataAs()}; + if (preRollVisible) { // VSample position of the right-most triangle's tip const double triangleTipVSamplePosition = @@ -168,11 +179,17 @@ void WaveformRendererPreroll::paintGL() { x -= std::ceil((x - limit) / markerLength) * markerLength; } - drawPattern(x, + const float repetitions = x / markerLength; + + vertexUpdater.addRectangle(x, halfBreadth - halfMarkerBreadth, + 0, + m_isSlipRenderer ? halfBreadth + : halfBreadth + halfMarkerBreadth, 0.f, - m_isSlipRenderer ? halfBreadth : halfBreadth + halfMarkerBreadth, - x / markerLength); + 0.f, + repetitions, + m_isSlipRenderer ? 0.5 : 1.f); } if (postRollVisible) { @@ -189,44 +206,26 @@ void WaveformRendererPreroll::paintGL() { x += std::ceil((limit - x) / markerLength) * markerLength; } - drawPattern(x, + const float repetitions = (end - x) / markerLength; + + vertexUpdater.addRectangle(x, halfBreadth - halfMarkerBreadth, end, - m_isSlipRenderer ? halfBreadth : halfBreadth + halfMarkerBreadth, - (end - x) / markerLength); + m_isSlipRenderer ? halfBreadth + : halfBreadth + halfMarkerBreadth, + 0.f, + 0.f, + repetitions, + m_isSlipRenderer ? 0.5 : 1.f); } - m_texture.release(); + DEBUG_ASSERT(reserved == vertexUpdater.index()); - m_shader.disableAttributeArray(positionLocation); - m_shader.disableAttributeArray(texcoordLocation); - m_shader.release(); -} + const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); + + material().setUniform(0, matrix); -void WaveformRendererPreroll::drawPattern( - float x1, float y1, float x2, float y2, float repetitions) { - // Draw a large rectangle with a repeating pattern of the texture - const int repetitionsLocation = m_shader.repetitionsLocation(); - const int positionLocation = m_shader.positionLocation(); - const int texcoordLocation = m_shader.texcoordLocation(); - - const std::array positionArray = {x1, y1, x2, y1, x1, y2, x2, y2}; - const std::array texcoordArray = {0.f, - 0.f, - 1.f, - 0.f, - 0.f, - m_isSlipRenderer ? 0.5f : 1.f, - 1.f, - m_isSlipRenderer ? 0.5f : 1.f}; - m_shader.setUniformValue(repetitionsLocation, QVector2D(repetitions, 1.0)); - - m_shader.setAttributeArray( - positionLocation, GL_FLOAT, positionArray.data(), 2); - m_shader.setAttributeArray( - texcoordLocation, GL_FLOAT, texcoordArray.data(), 2); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + return true; } } // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrendererpreroll.h b/src/waveform/renderers/allshader/waveformrendererpreroll.h index 742320424c5..b4844914acd 100644 --- a/src/waveform/renderers/allshader/waveformrendererpreroll.h +++ b/src/waveform/renderers/allshader/waveformrendererpreroll.h @@ -1,46 +1,44 @@ #pragma once #include -#include #include -#include "shaders/patternshader.h" +#include "rendergraph/geometrynode.h" #include "util/class.h" -#include "util/opengltexture2d.h" -#include "waveform/renderers/allshader/vertexdata.h" -#include "waveform/renderers/allshader/waveformrenderer.h" +#include "waveform/renderers/waveformrendererabstract.h" class QDomNode; class SkinContext; -class QOpenGLTexture; namespace allshader { class WaveformRendererPreroll; -class WaveformRendererSlipPreroll; } -class allshader::WaveformRendererPreroll : public allshader::WaveformRenderer { +class allshader::WaveformRendererPreroll final + : public ::WaveformRendererAbstract, + public rendergraph::GeometryNode { public: explicit WaveformRendererPreroll( - WaveformWidgetRenderer* waveformWidgetRenderer, + WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type = ::WaveformRendererAbstract::Play); ~WaveformRendererPreroll() override; + // Pure virtual from WaveformRendererAbstract, not used + void draw(QPainter* painter, QPaintEvent* event) override final; + void setup(const QDomNode& node, const SkinContext& context) override; - void paintGL() override; - void initializeGL() override; - private: - void drawPattern(float x1, float y1, float x2, float y2, float repetitions); + // Virtual for rendergraph::Node + void preprocess() override; - mixxx::PatternShader m_shader; + private: QColor m_color; float m_markerBreadth{}; float m_markerLength{}; - OpenGLTexture2D m_texture; - bool m_isSlipRenderer; + bool preprocessSelf(); + DISALLOW_COPY_AND_ASSIGN(WaveformRendererPreroll); }; From 4ad583ce15050497dacc222f0b3db3653f479969 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 31 Aug 2024 01:25:58 +0200 Subject: [PATCH 04/64] node iterator, fixed examples --- .../examples/common/endoftrackmaterial.cpp | 38 ------------- .../examples/common/endoftrackmaterial.h | 21 ------- .../examples/common/examplenodes.cpp | 3 +- src/rendergraph/node.cpp | 16 +++--- src/rendergraph/node.h | 57 ++++++++++++++++++- src/rendergraph/opengl/private/node_impl.h | 30 ++++------ .../scenegraph/private/node_impl.h | 24 ++++---- 7 files changed, 85 insertions(+), 104 deletions(-) delete mode 100644 src/rendergraph/examples/common/endoftrackmaterial.cpp delete mode 100644 src/rendergraph/examples/common/endoftrackmaterial.h diff --git a/src/rendergraph/examples/common/endoftrackmaterial.cpp b/src/rendergraph/examples/common/endoftrackmaterial.cpp deleted file mode 100644 index 4f5c9dfee41..00000000000 --- a/src/rendergraph/examples/common/endoftrackmaterial.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "endoftrackmaterial.h" - -#include - -#include "rendergraph/materialshader.h" -#include "rendergraph/materialtype.h" -#include "rendergraph/uniformset.h" - -using namespace rendergraph; - -EndOfTrackMaterial::EndOfTrackMaterial() - : Material(uniforms()) { -} - -/* static */ const AttributeSet& EndOfTrackMaterial::attributes() { - static AttributeSet set = makeAttributeSet({"position", "gradient"}); - return set; -} - -/* static */ const UniformSet& EndOfTrackMaterial::uniforms() { - static UniformSet set = makeUniformSet({"ubuf.color"}); - return set; -} - -MaterialType* EndOfTrackMaterial::type() const { - static MaterialType type; - return &type; -} - -int EndOfTrackMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - -MaterialShader* EndOfTrackMaterial::createShader() const { - return new MaterialShader("endoftrack.vert", "endoftrack.frag", uniforms(), attributes()); -} diff --git a/src/rendergraph/examples/common/endoftrackmaterial.h b/src/rendergraph/examples/common/endoftrackmaterial.h deleted file mode 100644 index bcaa02b0430..00000000000 --- a/src/rendergraph/examples/common/endoftrackmaterial.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "rendergraph/attributeset.h" -#include "rendergraph/material.h" - -namespace rendergraph { -class EndOfTrackMaterial; -} - -class rendergraph::EndOfTrackMaterial : public rendergraph::Material { - public: - EndOfTrackMaterial(); - - static const AttributeSet& attributes(); - - static const UniformSet& uniforms(); - - MaterialType* type() const override; - - int compare(const Material* other) const override; - - MaterialShader* createShader() const override; -}; diff --git a/src/rendergraph/examples/common/examplenodes.cpp b/src/rendergraph/examples/common/examplenodes.cpp index dbac0ea2bdd..420bbae40ca 100644 --- a/src/rendergraph/examples/common/examplenodes.cpp +++ b/src/rendergraph/examples/common/examplenodes.cpp @@ -4,8 +4,8 @@ #include #include -#include "endoftrackmaterial.h" #include "rendergraph/geometry.h" +#include "rendergraph/material/endoftrackmaterial.h" #include "rendergraph/material/texturematerial.h" using namespace rendergraph; @@ -53,7 +53,6 @@ ExampleNode3::ExampleNode3() { matrix.scale(0.3); material().setUniform(0, matrix); - material().setUniform(1, QVector4D{1.f, 0.5f, 0.2f, 0.7f}); } void ExampleNode3::setTexture(std::unique_ptr texture) { diff --git a/src/rendergraph/node.cpp b/src/rendergraph/node.cpp index 4334fd7abbc..bd2ec2eed3e 100644 --- a/src/rendergraph/node.cpp +++ b/src/rendergraph/node.cpp @@ -18,18 +18,18 @@ NodeImplBase& Node::impl() const { return *m_pImpl; } -void Node::appendChildNode(std::unique_ptr pChild) { - impl().appendChildNode(std::move(pChild)); +void Node::setUsePreprocess(bool value) { + impl().setUsePreprocess(value); } -void Node::removeAllChildNodes() { - impl().removeAllChildNodes(); +void Node::onAppendChildNode(Node* pChild) { + impl().onAppendChildNode(pChild); } -void Node::setUsePreprocess(bool value) { - impl().setUsePreprocess(value); +void Node::onRemoveChildNode(Node* pChild) { + impl().onRemoveChildNode(pChild); } -Node* Node::lastChild() const { - return impl().lastChild(); +void Node::onRemoveAllChildNodes() { + impl().onRemoveAllChildNodes(); } diff --git a/src/rendergraph/node.h b/src/rendergraph/node.h index c9865402dcd..0fa638c254e 100644 --- a/src/rendergraph/node.h +++ b/src/rendergraph/node.h @@ -1,5 +1,6 @@ #pragma once +#include #include namespace rendergraph { @@ -11,14 +12,59 @@ class rendergraph::Node { public: class Impl; + class Iterator { + public: + Iterator(Node* pOwner, std::list>::iterator iter) + : m_pOwner(pOwner), + m_iterator(iter) { + } + void operator++() { + m_iterator++; + } + const std::unique_ptr& operator*() const { + return *m_iterator; + } + bool operator==(const Iterator& other) const { + return m_iterator == other.m_iterator; + } + bool operator!=(const Iterator& other) const { + return m_iterator != other.m_iterator; + } + std::unique_ptr nextAfterRemove() { + std::unique_ptr result = std::move(*m_iterator); + m_pOwner->onRemoveChildNode(result.get()); + m_iterator = m_pOwner->m_pChildren.erase(m_iterator); + return result; + } + + private: + Node* m_pOwner; + std::list>::iterator m_iterator; + }; + Node(); virtual ~Node(); - void appendChildNode(std::unique_ptr pChild); - void removeAllChildNodes(); - Node* lastChild() const; + Iterator begin() { + return Iterator(this, m_pChildren.begin()); + } + + Iterator end() { + return Iterator(this, m_pChildren.end()); + } + void appendChildNode(std::unique_ptr pChild) { + onAppendChildNode(pChild.get()); + m_pChildren.push_back(std::move(pChild)); + } + void removeAllChildNodes() { + m_pChildren.clear(); + onRemoveAllChildNodes(); + } + Node* lastChild() const { + return m_pChildren.back().get(); + } NodeImplBase& impl() const; virtual bool isSubtreeBlocked() const { @@ -34,5 +80,10 @@ class rendergraph::Node { Node(NodeImplBase* impl); private: + std::list> m_pChildren; const std::unique_ptr m_pImpl; + + void onAppendChildNode(Node* pChild); + void onRemoveChildNode(Node* pChild); + void onRemoveAllChildNodes(); }; diff --git a/src/rendergraph/opengl/private/node_impl.h b/src/rendergraph/opengl/private/node_impl.h index f3df4b2c801..50df8b6a493 100644 --- a/src/rendergraph/opengl/private/node_impl.h +++ b/src/rendergraph/opengl/private/node_impl.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "rendergraph/node.h" @@ -11,26 +11,14 @@ class rendergraph::NodeImplBase { } virtual ~NodeImplBase() = default; - void appendChildNode(std::unique_ptr pChild) { - m_pChildren.emplace_back(std::move(pChild)); - } - - void removeAllChildNodes() { - m_pChildren.clear(); - } - - Node* lastChild() const { - return m_pChildren.back().get(); - } - virtual void initialize() { - for (auto& pChild : m_pChildren) { + for (auto& pChild : *m_pOwner) { pChild->impl().initialize(); } } virtual void render() { - for (auto& pChild : m_pChildren) { + for (auto& pChild : *m_pOwner) { if (!pChild->impl().isSubtreeBlocked()) { pChild->impl().render(); } @@ -38,7 +26,7 @@ class rendergraph::NodeImplBase { } virtual void resize(int w, int h) { - for (auto& pChild : m_pChildren) { + for (auto& pChild : *m_pOwner) { pChild->impl().resize(w, h); } } @@ -55,7 +43,7 @@ class rendergraph::NodeImplBase { if (m_usePreprocess) { preprocessNodes->push_back(m_pOwner); } - for (auto& pChild : m_pChildren) { + for (auto& pChild : *m_pOwner) { pChild->impl().addToPreprocessNodes(preprocessNodes); } } @@ -64,9 +52,15 @@ class rendergraph::NodeImplBase { m_usePreprocess = value; } + void onAppendChildNode(Node*) { + } + void onRemoveChildNode(Node*) { + } + void onRemoveAllChildNodes() { + } + private: Node* const m_pOwner; - std::vector> m_pChildren; bool m_usePreprocess{}; }; diff --git a/src/rendergraph/scenegraph/private/node_impl.h b/src/rendergraph/scenegraph/private/node_impl.h index e72c6bda0a4..1f3b4f34b7f 100644 --- a/src/rendergraph/scenegraph/private/node_impl.h +++ b/src/rendergraph/scenegraph/private/node_impl.h @@ -11,19 +11,6 @@ class rendergraph::NodeImplBase { } virtual ~NodeImplBase() = default; - void appendChildNode(std::unique_ptr pChild) { - sgNode()->appendChildNode(pChild->impl().sgNode()); - m_pChildren.emplace_back(std::move(pChild)); - } - void removeAllChildNodes() { - sgNode()->removeAllChildNodes(); - m_pChildren.clear(); - } - - Node* lastChild() const { - return m_pChildren.back().get(); - } - virtual QSGNode* sgNode() = 0; Node* owner() const { @@ -34,9 +21,18 @@ class rendergraph::NodeImplBase { sgNode()->setFlag(QSGNode::UsePreprocess, value); } + void onAppendChildNode(Node* pChild) { + sgNode()->appendChildNode(pChild->impl().sgNode()); + } + void onRemoveAllChildNodes() { + sgNode()->removeAllChildNodes(); + } + void onRemoveChildNode(Node* pChild) { + sgNode()->removeChildNode(pChild->impl().sgNode()); + } + private: Node* m_pOwner; - std::vector> m_pChildren; }; class rendergraph::Node::Impl : public QSGNode, public rendergraph::NodeImplBase { From 1dc16a52a764f77452df3499b4a6f318cab81e3a Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 31 Aug 2024 01:48:10 +0200 Subject: [PATCH 05/64] fix teardown order --- src/rendergraph/examples/gl_example/window.cpp | 7 ++++++- src/rendergraph/examples/gl_example/window.h | 2 ++ src/rendergraph/node.h | 2 +- src/rendergraph/scenegraph/private/geometrynode_impl.h | 1 + src/rendergraph/scenegraph/private/node_impl.h | 3 +++ 5 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/examples/gl_example/window.cpp index 72b13753451..81bc0db439b 100644 --- a/src/rendergraph/examples/gl_example/window.cpp +++ b/src/rendergraph/examples/gl_example/window.cpp @@ -7,7 +7,12 @@ Window::Window() { } -Window::~Window() { +Window::~Window() = default; + +void Window::closeEvent(QCloseEvent*) { + // since this is the only and last window, we need to cleanup before destruction, + // because at destruction the context can't be used anymore + m_rendergraph.reset(); } void Window::initializeGL() { diff --git a/src/rendergraph/examples/gl_example/window.h b/src/rendergraph/examples/gl_example/window.h index e1b898c0357..6d7d5f69749 100644 --- a/src/rendergraph/examples/gl_example/window.h +++ b/src/rendergraph/examples/gl_example/window.h @@ -16,6 +16,8 @@ class Window : public QOpenGLWindow { void resizeGL(int w, int h) override; void paintGL() override; + void closeEvent(QCloseEvent* ev) override; + private: std::unique_ptr m_rendergraph; }; diff --git a/src/rendergraph/node.h b/src/rendergraph/node.h index 0fa638c254e..e8ad2c14d8e 100644 --- a/src/rendergraph/node.h +++ b/src/rendergraph/node.h @@ -80,8 +80,8 @@ class rendergraph::Node { Node(NodeImplBase* impl); private: - std::list> m_pChildren; const std::unique_ptr m_pImpl; + std::list> m_pChildren; void onAppendChildNode(Node* pChild); void onRemoveChildNode(Node* pChild); diff --git a/src/rendergraph/scenegraph/private/geometrynode_impl.h b/src/rendergraph/scenegraph/private/geometrynode_impl.h index 1717df1b063..7270d5e357d 100644 --- a/src/rendergraph/scenegraph/private/geometrynode_impl.h +++ b/src/rendergraph/scenegraph/private/geometrynode_impl.h @@ -10,6 +10,7 @@ class rendergraph::GeometryNode::Impl : public QSGGeometryNode, public rendergra Impl(GeometryNode* pOwner) : NodeImplBase(pOwner) { } + QSGNode* sgNode() override { return this; } diff --git a/src/rendergraph/scenegraph/private/node_impl.h b/src/rendergraph/scenegraph/private/node_impl.h index 1f3b4f34b7f..7767ef33344 100644 --- a/src/rendergraph/scenegraph/private/node_impl.h +++ b/src/rendergraph/scenegraph/private/node_impl.h @@ -9,6 +9,7 @@ class rendergraph::NodeImplBase { NodeImplBase(Node* pOwner) : m_pOwner(pOwner) { } + virtual ~NodeImplBase() = default; virtual QSGNode* sgNode() = 0; @@ -40,6 +41,8 @@ class rendergraph::Node::Impl : public QSGNode, public rendergraph::NodeImplBase Impl(Node* pOwner) : NodeImplBase(pOwner) { } + virtual ~Impl() = default; + QSGNode* sgNode() override { return this; } From 801416381d9ea66788612e3260b0663880801f64 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 31 Aug 2024 03:58:14 +0200 Subject: [PATCH 06/64] mark range with dynamic nodes --- src/rendergraph/node.h | 16 ++-- src/rendergraph/opengl/graph.cpp | 1 + src/rendergraph/opengl/private/node_impl.h | 9 ++ .../allshader/waveformrendermarkrange.cpp | 87 ++++++++++--------- .../allshader/waveformrendermarkrange.h | 18 ++-- .../widgets/allshader/waveformwidget.cpp | 5 +- .../widgets/allshader/waveformwidget.h | 2 + 7 files changed, 81 insertions(+), 57 deletions(-) diff --git a/src/rendergraph/node.h b/src/rendergraph/node.h index e8ad2c14d8e..cad77864dbd 100644 --- a/src/rendergraph/node.h +++ b/src/rendergraph/node.h @@ -18,9 +18,6 @@ class rendergraph::Node { : m_pOwner(pOwner), m_iterator(iter) { } - void operator++() { - m_iterator++; - } const std::unique_ptr& operator*() const { return *m_iterator; } @@ -30,7 +27,16 @@ class rendergraph::Node { bool operator!=(const Iterator& other) const { return m_iterator != other.m_iterator; } - std::unique_ptr nextAfterRemove() { + Iterator& operator++() { + ++m_iterator; + return *this; + } + Iterator operator++(int) { + Iterator result = *this; + ++(*this); + return result; + } + std::unique_ptr incrementAfterRemove() { std::unique_ptr result = std::move(*m_iterator); m_pOwner->onRemoveChildNode(result.get()); m_iterator = m_pOwner->m_pChildren.erase(m_iterator); @@ -62,7 +68,7 @@ class rendergraph::Node { m_pChildren.clear(); onRemoveAllChildNodes(); } - Node* lastChild() const { + Node* lastChildNode() const { return m_pChildren.back().get(); } NodeImplBase& impl() const; diff --git a/src/rendergraph/opengl/graph.cpp b/src/rendergraph/opengl/graph.cpp index d0be84bed25..252f0ad7d87 100644 --- a/src/rendergraph/opengl/graph.cpp +++ b/src/rendergraph/opengl/graph.cpp @@ -18,6 +18,7 @@ void Graph::initialize() { void Graph::render() { if (!m_pTopNode->impl().isSubtreeBlocked()) { + m_pTopNode->impl().initializeIfNeeded(); m_pTopNode->impl().render(); } } diff --git a/src/rendergraph/opengl/private/node_impl.h b/src/rendergraph/opengl/private/node_impl.h index 50df8b6a493..2d16ad5d811 100644 --- a/src/rendergraph/opengl/private/node_impl.h +++ b/src/rendergraph/opengl/private/node_impl.h @@ -15,16 +15,24 @@ class rendergraph::NodeImplBase { for (auto& pChild : *m_pOwner) { pChild->impl().initialize(); } + m_initialized = true; } virtual void render() { for (auto& pChild : *m_pOwner) { if (!pChild->impl().isSubtreeBlocked()) { + pChild->impl().initializeIfNeeded(); pChild->impl().render(); } } } + void initializeIfNeeded() { + if (!m_initialized) { + initialize(); + } + } + virtual void resize(int w, int h) { for (auto& pChild : *m_pOwner) { pChild->impl().resize(w, h); @@ -62,6 +70,7 @@ class rendergraph::NodeImplBase { private: Node* const m_pOwner; bool m_usePreprocess{}; + bool m_initialized{}; }; class rendergraph::Node::Impl : public rendergraph::NodeImplBase { diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index eaacffdbdba..4adafcd4512 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -1,40 +1,23 @@ #include "waveform/renderers/allshader/waveformrendermarkrange.h" +#include "rendergraph/geometry.h" +#include "rendergraph/geometrynode.h" +#include "rendergraph/material/unicolormaterial.h" #include "skin/legacy/skincontext.h" +#include "vertexupdater.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" -allshader::WaveformRenderMarkRange::WaveformRenderMarkRange(WaveformWidgetRenderer* waveformWidget) - : WaveformRenderer(waveformWidget) { -} - -void allshader::WaveformRenderMarkRange::initializeGL() { - m_shader.init(); -} - -void allshader::WaveformRenderMarkRange::fillRect( - const QRectF& rect, QColor color) { - const float posx1 = static_cast(rect.x()); - const float posx2 = static_cast(rect.x() + rect.width()); - const float posy1 = static_cast(rect.y()); - const float posy2 = static_cast(rect.y() + rect.height()); +using namespace rendergraph; - const float posarray[] = {posx1, posy1, posx2, posy1, posx1, posy2, posx2, posy2}; +namespace allshader { - const int colorLocation = m_shader.colorLocation(); - const int positionLocation = m_shader.positionLocation(); - - m_shader.setUniformValue(colorLocation, color); - - m_shader.setAttributeArray( - positionLocation, GL_FLOAT, posarray, 2); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); +WaveformRenderMarkRange::WaveformRenderMarkRange(WaveformWidgetRenderer* waveformWidget) + : ::WaveformRendererAbstract(waveformWidget) { } -void allshader::WaveformRenderMarkRange::setup(const QDomNode& node, const SkinContext& context) { +void WaveformRenderMarkRange::setup(const QDomNode& node, const SkinContext& context) { m_markRanges.clear(); - m_markRanges.reserve(1); QDomNode child = node.firstChild(); while (!child.isNull()) { @@ -50,21 +33,18 @@ void allshader::WaveformRenderMarkRange::setup(const QDomNode& node, const SkinC } } -void allshader::WaveformRenderMarkRange::paintGL() { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +void WaveformRenderMarkRange::draw(QPainter* painter, QPaintEvent* event) { + Q_UNUSED(painter); + Q_UNUSED(event); + DEBUG_ASSERT(false); +} +void WaveformRenderMarkRange::updateNode() { const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - const int positionLocation = m_shader.positionLocation(); - const int matrixLocation = m_shader.matrixLocation(); + Iterator iter = begin(); - m_shader.bind(); - m_shader.enableAttributeArray(positionLocation); - - m_shader.setUniformValue(matrixLocation, matrix); - - for (auto&& markRange : m_markRanges) { + for (const auto& markRange : m_markRanges) { // If the mark range is not active we should not draw it. if (!markRange.active()) { continue; @@ -88,8 +68,6 @@ void allshader::WaveformRenderMarkRange::paintGL() { startPosition = std::floor(startPosition); endPosition = std::floor(endPosition); - const double span = std::max(endPosition - startPosition, 1.0); - // range not in the current display if (startPosition > m_waveformRenderer->getLength() || endPosition < 0) { continue; @@ -98,8 +76,33 @@ void allshader::WaveformRenderMarkRange::paintGL() { QColor color = markRange.enabled() ? markRange.m_activeColor : markRange.m_disabledColor; color.setAlphaF(0.3f); - fillRect(QRectF(startPosition, 0, span, m_waveformRenderer->getBreadth()), color); + GeometryNode* pNode; + if (iter == end()) { + qDebug() << "Appended new node for mark range"; + appendChildNode(std::make_unique()); + pNode = static_cast(lastChildNode()); + pNode->setGeometry(std::make_unique(UniColorMaterial::attributes(), 0)); + pNode->setMaterial(std::make_unique()); + pNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + pNode->geometry().allocate(6); + + iter = end(); + } else { + pNode = static_cast((*iter++).get()); + } + + VertexUpdater vertexUpdater{pNode->geometry().vertexDataAs()}; + vertexUpdater.addRectangle(static_cast(startPosition), + 0.f, + static_cast(endPosition) + 1.f, + m_waveformRenderer->getBreadth()); + pNode->material().setUniform(0, matrix); + pNode->material().setUniform(1, color); + } + while (iter != end()) { + qDebug() << "Remove unused node for mark range"; + iter.incrementAfterRemove(); } - m_shader.disableAttributeArray(positionLocation); - m_shader.release(); } + +} // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.h b/src/waveform/renderers/allshader/waveformrendermarkrange.h index 0c46a8dd5b8..3b2c64a7dd7 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.h +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.h @@ -1,12 +1,12 @@ #pragma once #include -#include +#include -#include "shaders/unicolorshader.h" +#include "rendergraph/node.h" #include "util/class.h" -#include "waveform/renderers/allshader/waveformrenderer.h" #include "waveform/renderers/waveformmarkrange.h" +#include "waveform/renderers/waveformrendererabstract.h" class QDomNode; class SkinContext; @@ -15,19 +15,19 @@ namespace allshader { class WaveformRenderMarkRange; } -class allshader::WaveformRenderMarkRange final : public allshader::WaveformRenderer { +class allshader::WaveformRenderMarkRange final : public ::WaveformRendererAbstract, + public rendergraph::Node { public: explicit WaveformRenderMarkRange(WaveformWidgetRenderer* waveformWidget); + // Pure virtual from WaveformRendererAbstract, not used + void draw(QPainter* painter, QPaintEvent* event) override final; + void setup(const QDomNode& node, const SkinContext& context) override; - void initializeGL() override; - void paintGL() override; + void updateNode(); private: - void fillRect(const QRectF& rect, QColor color); - - mixxx::UnicolorShader m_shader; std::vector m_markRanges; DISALLOW_COPY_AND_ASSIGN(WaveformRenderMarkRange); diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index 65b23e95b15..ddd4498d8c0 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -42,7 +42,8 @@ WaveformWidget::WaveformWidget(QWidget* parent, appendChildTo(pTopNode, addRenderer()); appendChildTo(pOpacityNode, addRenderer()); appendChildTo(pOpacityNode, addRenderer()); - appendChildTo(pOpacityNode, addRenderer()); + m_pWaveformRenderMarkRange = addRenderer(); + appendChildTo(pOpacityNode, m_pWaveformRenderMarkRange); #ifdef __STEM__ // The following two renderers work in tandem: if the rendered waveform is @@ -146,6 +147,8 @@ void WaveformWidget::paintGL() { // opacity of 0.f effectively skips the subtree rendering m_pOpacityNode->setOpacity(shouldOnlyDrawBackground() ? 0.f : 1.f); + m_pWaveformRenderMarkRange->updateNode(); + m_pGraph->preprocess(); m_pGraph->render(); } diff --git a/src/waveform/widgets/allshader/waveformwidget.h b/src/waveform/widgets/allshader/waveformwidget.h index c40ff4b932b..4aa82a0aa16 100644 --- a/src/waveform/widgets/allshader/waveformwidget.h +++ b/src/waveform/widgets/allshader/waveformwidget.h @@ -9,6 +9,7 @@ namespace allshader { class WaveformWidget; +class WaveformRenderMarkRange; } class allshader::WaveformWidget final : public ::WGLWidget, @@ -52,6 +53,7 @@ class allshader::WaveformWidget final : public ::WGLWidget, WaveformWidgetType::Type m_type; std::unique_ptr m_pGraph; rendergraph::OpacityNode* m_pOpacityNode; + WaveformRenderMarkRange* m_pWaveformRenderMarkRange; DISALLOW_COPY_AND_ASSIGN(WaveformWidget); }; From 9a01213eb41a2e2be7f83d7dfa59500dee1f6f95 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 31 Aug 2024 12:18:42 +0200 Subject: [PATCH 07/64] make linked list handling part of rendergraph::Node --- src/rendergraph/node.h | 104 +++++++++--------- src/rendergraph/opengl/private/node_impl.h | 16 ++- .../allshader/waveformrendermarkrange.cpp | 33 +++--- 3 files changed, 81 insertions(+), 72 deletions(-) diff --git a/src/rendergraph/node.h b/src/rendergraph/node.h index cad77864dbd..cd8b8646767 100644 --- a/src/rendergraph/node.h +++ b/src/rendergraph/node.h @@ -12,64 +12,62 @@ class rendergraph::Node { public: class Impl; - class Iterator { - public: - Iterator(Node* pOwner, std::list>::iterator iter) - : m_pOwner(pOwner), - m_iterator(iter) { - } - const std::unique_ptr& operator*() const { - return *m_iterator; - } - bool operator==(const Iterator& other) const { - return m_iterator == other.m_iterator; - } - bool operator!=(const Iterator& other) const { - return m_iterator != other.m_iterator; - } - Iterator& operator++() { - ++m_iterator; - return *this; - } - Iterator operator++(int) { - Iterator result = *this; - ++(*this); - return result; - } - std::unique_ptr incrementAfterRemove() { - std::unique_ptr result = std::move(*m_iterator); - m_pOwner->onRemoveChildNode(result.get()); - m_iterator = m_pOwner->m_pChildren.erase(m_iterator); - return result; - } - - private: - Node* m_pOwner; - std::list>::iterator m_iterator; - }; - Node(); virtual ~Node(); - Iterator begin() { - return Iterator(this, m_pChildren.begin()); + void appendChildNode(std::unique_ptr&& pChild) { + auto pChildRawPtr = pChild.get(); + if (m_pLastChild) { + pChild->m_pPreviousSibling = m_pLastChild; + m_pLastChild->m_pNextSibling = std::move(pChild); + } else { + m_pFirstChild = std::move(pChild); + } + m_pLastChild = pChildRawPtr; + m_pLastChild->m_pParent = this; + onAppendChildNode(m_pLastChild); } - - Iterator end() { - return Iterator(this, m_pChildren.end()); + std::unique_ptr removeAllChildNodes() { + onRemoveAllChildNodes(); + m_pLastChild = nullptr; + Node* pChild = m_pFirstChild.get(); + while (pChild) { + pChild->m_pParent = nullptr; + pChild = pChild->m_pNextSibling.get(); + } + return std::move(m_pFirstChild); } - - void appendChildNode(std::unique_ptr pChild) { - onAppendChildNode(pChild.get()); - m_pChildren.push_back(std::move(pChild)); + std::unique_ptr removeChildNode(Node* pChild) { + std::unique_ptr pRemoved; + if (pChild == m_pFirstChild.get()) { + pRemoved = std::move(m_pFirstChild); + m_pFirstChild = std::move(pChild->m_pNextSibling); + } else { + pRemoved = std::move(pChild->m_pPreviousSibling->m_pNextSibling); + pChild->m_pPreviousSibling->m_pNextSibling = std::move(pChild->m_pNextSibling); + pChild->m_pPreviousSibling = nullptr; + } + if (pChild == m_pLastChild) { + m_pLastChild = nullptr; + } + pChild->m_pParent = nullptr; + return pRemoved; } - void removeAllChildNodes() { - m_pChildren.clear(); - onRemoveAllChildNodes(); + Node* parent() const { + return m_pParent; + } + Node* firstChild() const { + return m_pFirstChild.get(); + } + Node* lastChild() const { + return m_pLastChild; + } + Node* nextSibling() const { + return m_pNextSibling.get(); } - Node* lastChildNode() const { - return m_pChildren.back().get(); + Node* previousSibling() const { + return m_pPreviousSibling; } NodeImplBase& impl() const; @@ -87,7 +85,11 @@ class rendergraph::Node { private: const std::unique_ptr m_pImpl; - std::list> m_pChildren; + Node* m_pParent{}; + std::unique_ptr m_pFirstChild; + Node* m_pLastChild{}; + std::unique_ptr m_pNextSibling; + Node* m_pPreviousSibling{}; void onAppendChildNode(Node* pChild); void onRemoveChildNode(Node* pChild); diff --git a/src/rendergraph/opengl/private/node_impl.h b/src/rendergraph/opengl/private/node_impl.h index 2d16ad5d811..9a4c9c3efad 100644 --- a/src/rendergraph/opengl/private/node_impl.h +++ b/src/rendergraph/opengl/private/node_impl.h @@ -12,18 +12,22 @@ class rendergraph::NodeImplBase { virtual ~NodeImplBase() = default; virtual void initialize() { - for (auto& pChild : *m_pOwner) { + Node* pChild = m_pOwner->firstChild(); + while (pChild) { pChild->impl().initialize(); + pChild = pChild->nextSibling(); } m_initialized = true; } virtual void render() { - for (auto& pChild : *m_pOwner) { + Node* pChild = m_pOwner->firstChild(); + while (pChild) { if (!pChild->impl().isSubtreeBlocked()) { pChild->impl().initializeIfNeeded(); pChild->impl().render(); } + pChild = pChild->nextSibling(); } } @@ -34,8 +38,10 @@ class rendergraph::NodeImplBase { } virtual void resize(int w, int h) { - for (auto& pChild : *m_pOwner) { + Node* pChild = m_pOwner->firstChild(); + while (pChild) { pChild->impl().resize(w, h); + pChild = pChild->nextSibling(); } } @@ -51,8 +57,10 @@ class rendergraph::NodeImplBase { if (m_usePreprocess) { preprocessNodes->push_back(m_pOwner); } - for (auto& pChild : *m_pOwner) { + Node* pChild = m_pOwner->firstChild(); + while (pChild) { pChild->impl().addToPreprocessNodes(preprocessNodes); + pChild = pChild->nextSibling(); } } diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index 4adafcd4512..f85a3a63e9d 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -42,7 +42,7 @@ void WaveformRenderMarkRange::draw(QPainter* painter, QPaintEvent* event) { void WaveformRenderMarkRange::updateNode() { const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - Iterator iter = begin(); + GeometryNode* pChild = static_cast(firstChild()); for (const auto& markRange : m_markRanges) { // If the mark range is not active we should not draw it. @@ -76,32 +76,31 @@ void WaveformRenderMarkRange::updateNode() { QColor color = markRange.enabled() ? markRange.m_activeColor : markRange.m_disabledColor; color.setAlphaF(0.3f); - GeometryNode* pNode; - if (iter == end()) { + if (!pChild) { qDebug() << "Appended new node for mark range"; appendChildNode(std::make_unique()); - pNode = static_cast(lastChildNode()); - pNode->setGeometry(std::make_unique(UniColorMaterial::attributes(), 0)); - pNode->setMaterial(std::make_unique()); - pNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); - pNode->geometry().allocate(6); - - iter = end(); - } else { - pNode = static_cast((*iter++).get()); + pChild = static_cast(lastChild()); + pChild->setGeometry(std::make_unique(UniColorMaterial::attributes(), 0)); + pChild->setMaterial(std::make_unique()); + pChild->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + pChild->geometry().allocate(6); } - VertexUpdater vertexUpdater{pNode->geometry().vertexDataAs()}; + VertexUpdater vertexUpdater{pChild->geometry().vertexDataAs()}; vertexUpdater.addRectangle(static_cast(startPosition), 0.f, static_cast(endPosition) + 1.f, m_waveformRenderer->getBreadth()); - pNode->material().setUniform(0, matrix); - pNode->material().setUniform(1, color); + pChild->material().setUniform(0, matrix); + pChild->material().setUniform(1, color); + + pChild = static_cast(pChild->nextSibling()); } - while (iter != end()) { + while (pChild) { qDebug() << "Remove unused node for mark range"; - iter.incrementAfterRemove(); + auto pNext = static_cast(pChild->nextSibling()); + removeChildNode(pChild); + pChild = pNext; } } From 9eb2938d1d84e9c83ddbd394a1889e0c086ed83c Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 31 Aug 2024 12:41:29 +0200 Subject: [PATCH 08/64] towards digits renderer as node --- .../renderers/allshader/digitsrenderer.cpp | 26 +++++++++++++++++++ .../renderers/allshader/digitsrenderer.h | 12 +++++++-- .../allshader/waveformrendermark.cpp | 24 +++++------------ 3 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/waveform/renderers/allshader/digitsrenderer.cpp b/src/waveform/renderers/allshader/digitsrenderer.cpp index 2c6d2f7d147..73be7621986 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.cpp +++ b/src/waveform/renderers/allshader/digitsrenderer.cpp @@ -205,6 +205,32 @@ void allshader::DigitsRenderer::updateTexture( m_texture.setData(image); } +void allshader::DigitsRenderer::draw(const QMatrix4x4& matrix, + float x, + float y, + bool multiLine, + const QString& s1, + const QString& s2) { + const float ch = height(); + if (!s1.isEmpty()) { + const auto w = draw(matrix, + x, + y, + s1); + if (multiLine) { + y += ch; + } else { + x += w + ch * 0.75f; + } + } + if (!s2.isEmpty()) { + draw(matrix, + x, + y, + s2); + } +} + float allshader::DigitsRenderer::draw(const QMatrix4x4& matrix, float x, float y, diff --git a/src/waveform/renderers/allshader/digitsrenderer.h b/src/waveform/renderers/allshader/digitsrenderer.h index 4d280bbdaad..124ba778b53 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.h +++ b/src/waveform/renderers/allshader/digitsrenderer.h @@ -16,13 +16,21 @@ class allshader::DigitsRenderer : public QOpenGLFunctions { void init(); void updateTexture(float fontPointSize, float maxHeight, float devicePixelRatio); - float draw(const QMatrix4x4& matrix, + + void draw(const QMatrix4x4& matrix, float x, float y, - const QString& s); + bool multiLine, + const QString& s1, + const QString& s2); float height() const; private: + float draw(const QMatrix4x4& matrix, + float x, + float y, + const QString& s); + mixxx::TextureShader m_shader; OpenGLTexture2D m_texture; int m_penWidth; diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index bca7ecb24cc..aa48de0ca5b 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -349,24 +349,12 @@ void allshader::WaveformRenderMark::drawUntilMark(const QMatrix4x4& matrix, floa } } - if (untilMarkShowBeats) { - const auto w = m_digitsRenderer.draw(matrix, - x, - y, - QString::number(m_beatsUntilMark)); - if (multiLine) { - y += ch; - } else { - x += w + ch * 0.75f; - } - } - - if (untilMarkShowTime) { - m_digitsRenderer.draw(matrix, - x, - y, - timeSecToString(m_timeUntilMark)); - } + m_digitsRenderer.draw(matrix, + x, + y, + multiLine, + untilMarkShowBeats ? QString::number(m_beatsUntilMark) : QString{}, + untilMarkShowTime ? timeSecToString(m_timeUntilMark) : QString{}); } // Generate the texture used to draw the play position marker. From 1e4d04b0482b5900e21d33d473d7109b8004d54a Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 31 Aug 2024 13:49:14 +0200 Subject: [PATCH 09/64] draw playpos with rendergraph --- src/rendergraph/attributeset.h | 1 + src/rendergraph/opengl/private/node_impl.h | 1 + .../opengl/private/visiblenode_impl.h | 33 ----------------- src/rendergraph/uniformscache.h | 21 +++++------ .../allshader/waveformrendermark.cpp | 35 ++++++++++++++++--- .../renderers/allshader/waveformrendermark.h | 8 +++-- 6 files changed, 50 insertions(+), 49 deletions(-) delete mode 100644 src/rendergraph/opengl/private/visiblenode_impl.h diff --git a/src/rendergraph/attributeset.h b/src/rendergraph/attributeset.h index c242f42cfb6..a402973cb0d 100644 --- a/src/rendergraph/attributeset.h +++ b/src/rendergraph/attributeset.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "rendergraph/attribute.h" diff --git a/src/rendergraph/opengl/private/node_impl.h b/src/rendergraph/opengl/private/node_impl.h index 9a4c9c3efad..6aae041848f 100644 --- a/src/rendergraph/opengl/private/node_impl.h +++ b/src/rendergraph/opengl/private/node_impl.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "rendergraph/node.h" diff --git a/src/rendergraph/opengl/private/visiblenode_impl.h b/src/rendergraph/opengl/private/visiblenode_impl.h deleted file mode 100644 index 2730a0037db..00000000000 --- a/src/rendergraph/opengl/private/visiblenode_impl.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include - -#include "material_impl.h" -#include "node_impl.h" -#include "rendergraph/geometrynode.h" - -class rendergraph::GeometryNode::Impl : public rendergraph::Node::Impl, public QOpenGLFunctions { - public: - Impl() { - } - - void setGeometry(Geometry* geometry) { - m_pGeometry = geometry; - } - - void setMaterial(Material* material) { - m_pMaterial = material; - } - - void initialize() override { - initializeOpenGLFunctions(); - m_pMaterial->impl().setShader(m_pMaterial->createShader()); - Node::Impl::initialize(); - } - - void render() override; - - private: - Geometry* m_pGeometry{}; - Material* m_pMaterial{}; -}; diff --git a/src/rendergraph/uniformscache.h b/src/rendergraph/uniformscache.h index bd303e936d6..a88254ded40 100644 --- a/src/rendergraph/uniformscache.h +++ b/src/rendergraph/uniformscache.h @@ -22,16 +22,6 @@ class rendergraph::UniformsCache { set(uniformIndex, typeOf(), static_cast(&value), sizeOf(typeOf())); } - template<> - void set(int uniformIndex, const QColor& color) { - set(uniformIndex, QVector4D{color.redF(), color.greenF(), color.blueF(), color.alphaF()}); - } - - template<> - void set(int uniformIndex, const QMatrix4x4& matrix) { - set(uniformIndex, typeOf(), matrix.constData(), sizeOf(typeOf())); - } - template T get(int uniformIndex) const { T value; @@ -64,3 +54,14 @@ class rendergraph::UniformsCache { std::vector m_infos; QByteArray m_byteArray; }; + +template<> +inline void rendergraph::UniformsCache::set(int uniformIndex, const QColor& color) { + set(uniformIndex, QVector4D{color.redF(), color.greenF(), color.blueF(), color.alphaF()}); +} + +template<> +inline void rendergraph::UniformsCache::set( + int uniformIndex, const QMatrix4x4& matrix) { + set(uniformIndex, typeOf(), matrix.constData(), sizeOf(typeOf())); +} diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index aa48de0ca5b..8d089dbf46a 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -3,6 +3,12 @@ #include #include +#include "rendergraph/context.h" +#include "rendergraph/geometry.h" +#include "rendergraph/geometrynode.h" +#include "rendergraph/material/texturematerial.h" +#include "rendergraph/texture.h" +#include "texturedvertexupdater.h" #include "track/track.h" #include "util/colorcomponents.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" @@ -11,6 +17,8 @@ #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveformwidgetfactory.h" +using namespace rendergraph; + // On the use of QPainter: // // The renderers in this folder are optimized to use GLSL shaders and refrain @@ -66,6 +74,11 @@ allshader::WaveformRenderMark::WaveformRenderMark( m_timeUntilMark(0.0), m_pTimeRemainingControl(nullptr), m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) { + appendChildNode(std::make_unique()); + m_pPlayPosNode = static_cast(lastChild()); + m_pPlayPosNode->setGeometry(std::make_unique(TextureMaterial::attributes(), 6)); + m_pPlayPosNode->setMaterial(std::make_unique()); + m_pPlayPosNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); } bool allshader::WaveformRenderMark::init() { @@ -301,11 +314,23 @@ void allshader::WaveformRenderMark::paintGL() { devicePixelRatio) / devicePixelRatio; - if (m_playPosMarkTexture.isStorageAllocated()) { - const float markHalfWidth = m_playPosMarkTexture.width() / devicePixelRatio / 2.f; + { + const float markHalfWidth = 11.f / 2.f; const float drawOffset = currentMarkPoint - markHalfWidth; - drawTexture(matrix, drawOffset, 0.f, &m_playPosMarkTexture); + m_pPlayPosNode->material().setUniform(0, matrix); + + TexturedVertexUpdater vertexUpdater{ + m_pPlayPosNode->geometry() + .vertexDataAs()}; + vertexUpdater.addRectangle(drawOffset, + 0.f, + drawOffset + 11.f, + m_waveformRenderer->getBreadth(), + 0.f, + 0.f, + 1.f, + 1.f); } if (WaveformWidgetFactory::instance()->getUntilMarkShowBeats() || @@ -421,7 +446,9 @@ void allshader::WaveformRenderMark::updatePlayPosMarkTexture() { } painter.end(); - m_playPosMarkTexture.setData(image); + Context context; + dynamic_cast(m_pPlayPosNode->material()) + .setTexture(std::make_unique(context, image)); } void allshader::WaveformRenderMark::drawTriangle(QPainter* painter, diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index ab9caaa5f4c..584bf4d57d5 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -11,7 +11,10 @@ class QDomNode; class SkinContext; -class QOpenGLTexture; + +namespace rendergraph { +class GeometryNode; +} namespace allshader { class WaveformRenderMark; @@ -54,7 +57,6 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, mixxx::RGBAShader m_rgbaShader; mixxx::TextureShader m_textureShader; - OpenGLTexture2D m_playPosMarkTexture; DigitsRenderer m_digitsRenderer; int m_beatsUntilMark; double m_timeUntilMark; @@ -64,5 +66,7 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, bool m_isSlipRenderer; + rendergraph::GeometryNode* m_pPlayPosNode; + DISALLOW_COPY_AND_ASSIGN(WaveformRenderMark); }; From 058f5ecea8fbb942132ec91f55702decd242849d Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 31 Aug 2024 15:23:32 +0200 Subject: [PATCH 10/64] reuse materialshaders --- src/rendergraph/material.h | 4 +- .../material/endoftrackmaterial.cpp | 5 ++- src/rendergraph/material/endoftrackmaterial.h | 2 +- src/rendergraph/material/patternmaterial.cpp | 5 ++- src/rendergraph/material/patternmaterial.h | 2 +- src/rendergraph/material/texturematerial.cpp | 5 ++- src/rendergraph/material/texturematerial.h | 2 +- src/rendergraph/material/unicolormaterial.cpp | 5 ++- src/rendergraph/material/unicolormaterial.h | 2 +- .../opengl/private/geometrynode_impl.h | 3 +- .../opengl/private/material_impl.h | 9 ++++- .../opengl/private/materialshader_impl.h | 3 +- src/rendergraph/opengl/shadercache.h | 39 +++++++++++++++++++ src/rendergraph/uniformset.h | 1 + .../widgets/allshader/waveformwidget.cpp | 2 + 15 files changed, 72 insertions(+), 17 deletions(-) create mode 100644 src/rendergraph/opengl/shadercache.h diff --git a/src/rendergraph/material.h b/src/rendergraph/material.h index e1644d5bb00..51784b97eae 100644 --- a/src/rendergraph/material.h +++ b/src/rendergraph/material.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "rendergraph/uniformscache.h" namespace rendergraph { @@ -17,7 +19,7 @@ class rendergraph::Material { Material(const UniformSet& uniformSet); virtual ~Material(); virtual int compare(const Material* other) const = 0; - virtual MaterialShader* createShader() const = 0; + virtual std::shared_ptr createShader() const = 0; virtual MaterialType* type() const = 0; template diff --git a/src/rendergraph/material/endoftrackmaterial.cpp b/src/rendergraph/material/endoftrackmaterial.cpp index 4f5c9dfee41..044dc4e2c22 100644 --- a/src/rendergraph/material/endoftrackmaterial.cpp +++ b/src/rendergraph/material/endoftrackmaterial.cpp @@ -33,6 +33,7 @@ int EndOfTrackMaterial::compare(const Material* other) const { return otherCasted == this ? 0 : 1; } -MaterialShader* EndOfTrackMaterial::createShader() const { - return new MaterialShader("endoftrack.vert", "endoftrack.frag", uniforms(), attributes()); +std::shared_ptr EndOfTrackMaterial::createShader() const { + return std::make_shared( + "endoftrack.vert", "endoftrack.frag", uniforms(), attributes()); } diff --git a/src/rendergraph/material/endoftrackmaterial.h b/src/rendergraph/material/endoftrackmaterial.h index bcaa02b0430..983ba3112dd 100644 --- a/src/rendergraph/material/endoftrackmaterial.h +++ b/src/rendergraph/material/endoftrackmaterial.h @@ -17,5 +17,5 @@ class rendergraph::EndOfTrackMaterial : public rendergraph::Material { int compare(const Material* other) const override; - MaterialShader* createShader() const override; + std::shared_ptr createShader() const override; }; diff --git a/src/rendergraph/material/patternmaterial.cpp b/src/rendergraph/material/patternmaterial.cpp index 55f4b0430bd..5e1a4cbf15f 100644 --- a/src/rendergraph/material/patternmaterial.cpp +++ b/src/rendergraph/material/patternmaterial.cpp @@ -33,6 +33,7 @@ int PatternMaterial::compare(const Material* other) const { return otherCasted == this ? 0 : 1; } -MaterialShader* PatternMaterial::createShader() const { - return new MaterialShader("pattern.vert", "pattern.frag", uniforms(), attributes()); +std::shared_ptr PatternMaterial::createShader() const { + return std::make_shared( + "pattern.vert", "pattern.frag", uniforms(), attributes()); } diff --git a/src/rendergraph/material/patternmaterial.h b/src/rendergraph/material/patternmaterial.h index 475381e6a49..a89d993ccef 100644 --- a/src/rendergraph/material/patternmaterial.h +++ b/src/rendergraph/material/patternmaterial.h @@ -19,7 +19,7 @@ class rendergraph::PatternMaterial : public rendergraph::Material { int compare(const Material* other) const override; - MaterialShader* createShader() const override; + std::shared_ptr createShader() const override; Texture* texture(int /*binding*/) const override { return m_pTexture.get(); diff --git a/src/rendergraph/material/texturematerial.cpp b/src/rendergraph/material/texturematerial.cpp index b437afeba49..5a31f793c59 100644 --- a/src/rendergraph/material/texturematerial.cpp +++ b/src/rendergraph/material/texturematerial.cpp @@ -33,6 +33,7 @@ int TextureMaterial::compare(const Material* other) const { return otherCasted == this ? 0 : 1; } -MaterialShader* TextureMaterial::createShader() const { - return new MaterialShader("texture.vert", "texture.frag", uniforms(), attributes()); +std::shared_ptr TextureMaterial::createShader() const { + return std::make_shared( + "texture.vert", "texture.frag", uniforms(), attributes()); } diff --git a/src/rendergraph/material/texturematerial.h b/src/rendergraph/material/texturematerial.h index d892989d08d..ad68d2c1555 100644 --- a/src/rendergraph/material/texturematerial.h +++ b/src/rendergraph/material/texturematerial.h @@ -19,7 +19,7 @@ class rendergraph::TextureMaterial : public rendergraph::Material { int compare(const Material* other) const override; - MaterialShader* createShader() const override; + std::shared_ptr createShader() const override; Texture* texture(int /*binding*/) const override { return m_pTexture.get(); diff --git a/src/rendergraph/material/unicolormaterial.cpp b/src/rendergraph/material/unicolormaterial.cpp index b6aa7dfb1c6..6039d414be0 100644 --- a/src/rendergraph/material/unicolormaterial.cpp +++ b/src/rendergraph/material/unicolormaterial.cpp @@ -33,6 +33,7 @@ int UniColorMaterial::compare(const Material* other) const { return otherCasted == this ? 0 : 1; } -MaterialShader* UniColorMaterial::createShader() const { - return new MaterialShader("unicolor.vert", "unicolor.frag", uniforms(), attributes()); +std::shared_ptr UniColorMaterial::createShader() const { + return std::make_shared( + "unicolor.vert", "unicolor.frag", uniforms(), attributes()); } diff --git a/src/rendergraph/material/unicolormaterial.h b/src/rendergraph/material/unicolormaterial.h index 1d3ee5fe304..0b3cf0623e3 100644 --- a/src/rendergraph/material/unicolormaterial.h +++ b/src/rendergraph/material/unicolormaterial.h @@ -17,5 +17,5 @@ class rendergraph::UniColorMaterial : public rendergraph::Material { int compare(const Material* other) const override; - MaterialShader* createShader() const override; + std::shared_ptr createShader() const override; }; diff --git a/src/rendergraph/opengl/private/geometrynode_impl.h b/src/rendergraph/opengl/private/geometrynode_impl.h index 0d12ae7474f..2a3d1e74b5b 100644 --- a/src/rendergraph/opengl/private/geometrynode_impl.h +++ b/src/rendergraph/opengl/private/geometrynode_impl.h @@ -5,6 +5,7 @@ #include "material_impl.h" #include "node_impl.h" #include "rendergraph/geometrynode.h" +#include "rendergraph/opengl/shadercache.h" class rendergraph::GeometryNode::Impl : public rendergraph::Node::Impl, public QOpenGLFunctions { public: @@ -22,7 +23,7 @@ class rendergraph::GeometryNode::Impl : public rendergraph::Node::Impl, public Q void initialize() override { initializeOpenGLFunctions(); - m_pMaterial->impl().setShader(m_pMaterial->createShader()); + m_pMaterial->impl().setShader(ShaderCache::getShaderForMaterial(m_pMaterial)); Node::Impl::initialize(); } diff --git a/src/rendergraph/opengl/private/material_impl.h b/src/rendergraph/opengl/private/material_impl.h index 918f20ded42..1105ecb507a 100644 --- a/src/rendergraph/opengl/private/material_impl.h +++ b/src/rendergraph/opengl/private/material_impl.h @@ -2,6 +2,7 @@ #include "materialshader_impl.h" #include "rendergraph/material.h" +#include "rendergraph/opengl/shadercache.h" #include "texture_impl.h" class rendergraph::Material::Impl { @@ -10,7 +11,11 @@ class rendergraph::Material::Impl { : m_pOwner(pOwner) { } - void setShader(MaterialShader* pShader) { + ~Impl() { + m_pShader.reset(); + } + + void setShader(std::shared_ptr pShader) { m_pShader = pShader; } @@ -31,6 +36,6 @@ class rendergraph::Material::Impl { } private: - MaterialShader* m_pShader{}; + std::shared_ptr m_pShader; Material* const m_pOwner; }; diff --git a/src/rendergraph/opengl/private/materialshader_impl.h b/src/rendergraph/opengl/private/materialshader_impl.h index d89797302eb..07ccd3858a2 100644 --- a/src/rendergraph/opengl/private/materialshader_impl.h +++ b/src/rendergraph/opengl/private/materialshader_impl.h @@ -11,6 +11,7 @@ class rendergraph::MaterialShader::Impl : private QOpenGLShaderProgram { const char* fragmentShaderFile, const UniformSet& uniformSet, const AttributeSet& attributeSet); + QOpenGLShaderProgram& glShader() { return *this; } @@ -27,7 +28,7 @@ class rendergraph::MaterialShader::Impl : private QOpenGLShaderProgram { static QString resource(const char* filename) { return QString(":/shaders/rendergraph/") + QString(filename) + QString(".gl"); } + MaterialShader* const m_pOwner; std::vector m_attributeLocations; std::vector m_uniformLocations; - MaterialShader* const m_pOwner; }; diff --git a/src/rendergraph/opengl/shadercache.h b/src/rendergraph/opengl/shadercache.h new file mode 100644 index 00000000000..27e1958b835 --- /dev/null +++ b/src/rendergraph/opengl/shadercache.h @@ -0,0 +1,39 @@ +#pragma once + +#include + +#include "rendergraph/material.h" + +namespace rendergraph { +class ShaderCache; +} + +class rendergraph::ShaderCache { + private: + static std::map>& map() { + static std::map> s_map; + return s_map; + } + + public: + static std::shared_ptr getShaderForMaterial(Material* pMaterial) { + auto iter = map().find(pMaterial->type()); + if (iter != map().end()) { + return iter->second; + } + auto pResult = pMaterial->createShader(); + map().insert(std::pair>{ + pMaterial->type(), pResult}); + return pResult; + } + static void purge() { + auto iter = map().begin(); + while (iter != map().end()) { + if (iter->second.use_count() == 1) { + iter = map().erase(iter); + } else { + ++iter; + } + } + } +}; diff --git a/src/rendergraph/uniformset.h b/src/rendergraph/uniformset.h index 11f8a597637..afa1cfc2426 100644 --- a/src/rendergraph/uniformset.h +++ b/src/rendergraph/uniformset.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include "rendergraph/uniform.h" diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index ddd4498d8c0..3d68a6e34c9 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -5,6 +5,7 @@ #include #include +#include "rendergraph/opengl/shadercache.h" #include "waveform/renderers/allshader/waveformrenderbackground.h" #include "waveform/renderers/allshader/waveformrenderbeat.h" #include "waveform/renderers/allshader/waveformrendererendoftrack.h" @@ -95,6 +96,7 @@ WaveformWidget::~WaveformWidget() { makeCurrentIfNeeded(); m_rendererStack.clear(); m_pGraph.reset(); + rendergraph::ShaderCache::purge(); doneCurrent(); } From 8032b38a2f34ad8d18f9d282382b6b1b3f693010 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 31 Aug 2024 16:24:15 +0200 Subject: [PATCH 11/64] keep track of material that modified the shader uniforms, fix scenegraph --- src/rendergraph/material.h | 2 +- src/rendergraph/material/endoftrackmaterial.cpp | 4 ++-- src/rendergraph/material/endoftrackmaterial.h | 2 +- src/rendergraph/material/patternmaterial.cpp | 4 ++-- src/rendergraph/material/patternmaterial.h | 2 +- src/rendergraph/material/texturematerial.cpp | 4 ++-- src/rendergraph/material/texturematerial.h | 2 +- src/rendergraph/material/unicolormaterial.cpp | 4 ++-- src/rendergraph/material/unicolormaterial.h | 2 +- src/rendergraph/opengl/geometrynode_impl.cpp | 3 ++- src/rendergraph/opengl/private/material_impl.h | 8 ++++++++ src/rendergraph/opengl/private/materialshader_impl.h | 12 ++++++++++++ src/rendergraph/opengl/shadercache.h | 3 ++- src/rendergraph/scenegraph/private/material_impl.h | 3 ++- 14 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/rendergraph/material.h b/src/rendergraph/material.h index 51784b97eae..39ca86a6871 100644 --- a/src/rendergraph/material.h +++ b/src/rendergraph/material.h @@ -19,7 +19,7 @@ class rendergraph::Material { Material(const UniformSet& uniformSet); virtual ~Material(); virtual int compare(const Material* other) const = 0; - virtual std::shared_ptr createShader() const = 0; + virtual std::unique_ptr createShader() const = 0; virtual MaterialType* type() const = 0; template diff --git a/src/rendergraph/material/endoftrackmaterial.cpp b/src/rendergraph/material/endoftrackmaterial.cpp index 044dc4e2c22..fd9e5f73ec7 100644 --- a/src/rendergraph/material/endoftrackmaterial.cpp +++ b/src/rendergraph/material/endoftrackmaterial.cpp @@ -33,7 +33,7 @@ int EndOfTrackMaterial::compare(const Material* other) const { return otherCasted == this ? 0 : 1; } -std::shared_ptr EndOfTrackMaterial::createShader() const { - return std::make_shared( +std::unique_ptr EndOfTrackMaterial::createShader() const { + return std::make_unique( "endoftrack.vert", "endoftrack.frag", uniforms(), attributes()); } diff --git a/src/rendergraph/material/endoftrackmaterial.h b/src/rendergraph/material/endoftrackmaterial.h index 983ba3112dd..e66a825c164 100644 --- a/src/rendergraph/material/endoftrackmaterial.h +++ b/src/rendergraph/material/endoftrackmaterial.h @@ -17,5 +17,5 @@ class rendergraph::EndOfTrackMaterial : public rendergraph::Material { int compare(const Material* other) const override; - std::shared_ptr createShader() const override; + std::unique_ptr createShader() const override; }; diff --git a/src/rendergraph/material/patternmaterial.cpp b/src/rendergraph/material/patternmaterial.cpp index 5e1a4cbf15f..e16ca4213d7 100644 --- a/src/rendergraph/material/patternmaterial.cpp +++ b/src/rendergraph/material/patternmaterial.cpp @@ -33,7 +33,7 @@ int PatternMaterial::compare(const Material* other) const { return otherCasted == this ? 0 : 1; } -std::shared_ptr PatternMaterial::createShader() const { - return std::make_shared( +std::unique_ptr PatternMaterial::createShader() const { + return std::make_unique( "pattern.vert", "pattern.frag", uniforms(), attributes()); } diff --git a/src/rendergraph/material/patternmaterial.h b/src/rendergraph/material/patternmaterial.h index a89d993ccef..0df75c07371 100644 --- a/src/rendergraph/material/patternmaterial.h +++ b/src/rendergraph/material/patternmaterial.h @@ -19,7 +19,7 @@ class rendergraph::PatternMaterial : public rendergraph::Material { int compare(const Material* other) const override; - std::shared_ptr createShader() const override; + std::unique_ptr createShader() const override; Texture* texture(int /*binding*/) const override { return m_pTexture.get(); diff --git a/src/rendergraph/material/texturematerial.cpp b/src/rendergraph/material/texturematerial.cpp index 5a31f793c59..090e6070d98 100644 --- a/src/rendergraph/material/texturematerial.cpp +++ b/src/rendergraph/material/texturematerial.cpp @@ -33,7 +33,7 @@ int TextureMaterial::compare(const Material* other) const { return otherCasted == this ? 0 : 1; } -std::shared_ptr TextureMaterial::createShader() const { - return std::make_shared( +std::unique_ptr TextureMaterial::createShader() const { + return std::make_unique( "texture.vert", "texture.frag", uniforms(), attributes()); } diff --git a/src/rendergraph/material/texturematerial.h b/src/rendergraph/material/texturematerial.h index ad68d2c1555..4e0ac39b989 100644 --- a/src/rendergraph/material/texturematerial.h +++ b/src/rendergraph/material/texturematerial.h @@ -19,7 +19,7 @@ class rendergraph::TextureMaterial : public rendergraph::Material { int compare(const Material* other) const override; - std::shared_ptr createShader() const override; + std::unique_ptr createShader() const override; Texture* texture(int /*binding*/) const override { return m_pTexture.get(); diff --git a/src/rendergraph/material/unicolormaterial.cpp b/src/rendergraph/material/unicolormaterial.cpp index 6039d414be0..8e4bf12ed9c 100644 --- a/src/rendergraph/material/unicolormaterial.cpp +++ b/src/rendergraph/material/unicolormaterial.cpp @@ -33,7 +33,7 @@ int UniColorMaterial::compare(const Material* other) const { return otherCasted == this ? 0 : 1; } -std::shared_ptr UniColorMaterial::createShader() const { - return std::make_shared( +std::unique_ptr UniColorMaterial::createShader() const { + return std::make_unique( "unicolor.vert", "unicolor.frag", uniforms(), attributes()); } diff --git a/src/rendergraph/material/unicolormaterial.h b/src/rendergraph/material/unicolormaterial.h index 0b3cf0623e3..9516bb8c731 100644 --- a/src/rendergraph/material/unicolormaterial.h +++ b/src/rendergraph/material/unicolormaterial.h @@ -17,5 +17,5 @@ class rendergraph::UniColorMaterial : public rendergraph::Material { int compare(const Material* other) const override; - std::shared_ptr createShader() const override; + std::unique_ptr createShader() const override; }; diff --git a/src/rendergraph/opengl/geometrynode_impl.cpp b/src/rendergraph/opengl/geometrynode_impl.cpp index 30c6e6cf944..e4b64278538 100644 --- a/src/rendergraph/opengl/geometrynode_impl.cpp +++ b/src/rendergraph/opengl/geometrynode_impl.cpp @@ -27,7 +27,8 @@ void GeometryNode::Impl::render() { QOpenGLShaderProgram& shader = material.glShader(); shader.bind(); - if (m_pMaterial->clearUniformsCacheDirty()) { + if (m_pMaterial->clearUniformsCacheDirty() || !material.isLastModifierOfShader()) { + material.modifyShader(); const UniformsCache& cache = m_pMaterial->uniformsCache(); for (int i = 0; i < cache.count(); i++) { int location = material.uniformLocation(i); diff --git a/src/rendergraph/opengl/private/material_impl.h b/src/rendergraph/opengl/private/material_impl.h index 1105ecb507a..06aec895b55 100644 --- a/src/rendergraph/opengl/private/material_impl.h +++ b/src/rendergraph/opengl/private/material_impl.h @@ -27,6 +27,14 @@ class rendergraph::Material::Impl { return m_pOwner->texture(binding)->impl().glTexture(); } + void modifyShader() { + m_pShader->impl().setLastModifiedByMaterial(m_pOwner); + } + + bool isLastModifierOfShader() const { + return m_pOwner == m_pShader->impl().lastModifiedByMaterial(); + } + int uniformLocation(int uniformIndex) const { return m_pShader->impl().uniformLocation(uniformIndex); } diff --git a/src/rendergraph/opengl/private/materialshader_impl.h b/src/rendergraph/opengl/private/materialshader_impl.h index 07ccd3858a2..67e27a705e5 100644 --- a/src/rendergraph/opengl/private/materialshader_impl.h +++ b/src/rendergraph/opengl/private/materialshader_impl.h @@ -4,6 +4,10 @@ #include "rendergraph/materialshader.h" +namespace rendergraph { +class Material; +} + class rendergraph::MaterialShader::Impl : private QOpenGLShaderProgram { public: Impl(MaterialShader* pOwner, @@ -24,6 +28,13 @@ class rendergraph::MaterialShader::Impl : private QOpenGLShaderProgram { return m_uniformLocations[uniformIndex]; } + Material* lastModifiedByMaterial() const { + return m_pLastModifiedByMaterial; + } + void setLastModifiedByMaterial(Material* pMaterial) { + m_pLastModifiedByMaterial = pMaterial; + } + private: static QString resource(const char* filename) { return QString(":/shaders/rendergraph/") + QString(filename) + QString(".gl"); @@ -31,4 +42,5 @@ class rendergraph::MaterialShader::Impl : private QOpenGLShaderProgram { MaterialShader* const m_pOwner; std::vector m_attributeLocations; std::vector m_uniformLocations; + Material* m_pLastModifiedByMaterial{}; }; diff --git a/src/rendergraph/opengl/shadercache.h b/src/rendergraph/opengl/shadercache.h index 27e1958b835..15a4aee6799 100644 --- a/src/rendergraph/opengl/shadercache.h +++ b/src/rendergraph/opengl/shadercache.h @@ -3,6 +3,7 @@ #include #include "rendergraph/material.h" +#include "rendergraph/materialshader.h" namespace rendergraph { class ShaderCache; @@ -21,7 +22,7 @@ class rendergraph::ShaderCache { if (iter != map().end()) { return iter->second; } - auto pResult = pMaterial->createShader(); + auto pResult = std::shared_ptr(pMaterial->createShader().release()); map().insert(std::pair>{ pMaterial->type(), pResult}); return pResult; diff --git a/src/rendergraph/scenegraph/private/material_impl.h b/src/rendergraph/scenegraph/private/material_impl.h index d4779eb1517..4b36371f0c8 100644 --- a/src/rendergraph/scenegraph/private/material_impl.h +++ b/src/rendergraph/scenegraph/private/material_impl.h @@ -41,7 +41,8 @@ class rendergraph::Material::Impl : public QSGMaterial { } QSGMaterialShader* createShader(QSGRendererInterface::RenderMode) const override { - return m_pOwner->createShader()->impl().sgMaterialShader(); + auto pShader = m_pOwner->createShader().release(); // This leaks + return pShader->impl().sgMaterialShader(); } Material* m_pOwner; From 3dcf907fed0a072086c9265d9f3a1dd5ee9aaef4 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 31 Aug 2024 17:04:21 +0200 Subject: [PATCH 12/64] digitsrenderer with rendergraph --- CMakeLists.txt | 3 +- .../renderers/allshader/digitsrenderer.cpp | 88 ++++++++----------- .../renderers/allshader/digitsrenderer.h | 27 +++--- .../allshader/waveformrendererpreroll.cpp | 4 - .../allshader/waveformrendermark.cpp | 14 +-- .../renderers/allshader/waveformrendermark.h | 4 +- 6 files changed, 63 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72c8345cf3c..70a9ecf5997 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3811,7 +3811,8 @@ if(VINYLCONTROL) endif() # rendergraph -add_subdirectory(src/rendergraph) +add_subdirectory(src/rendergraph/opengl) +add_subdirectory(res/shaders/rendergraph) target_link_libraries(mixxx-lib PUBLIC rendergraph_gl) # WavPack audio file support diff --git a/src/waveform/renderers/allshader/digitsrenderer.cpp b/src/waveform/renderers/allshader/digitsrenderer.cpp index 73be7621986..03c72e92b34 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.cpp +++ b/src/waveform/renderers/allshader/digitsrenderer.cpp @@ -5,17 +5,21 @@ #include #include #include -#include #include #include #include #include "./util/assert.h" +#include "rendergraph/context.h" +#include "rendergraph/geometry.h" +#include "rendergraph/material/texturematerial.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" -#include "waveform/renderers/allshader/vertexdata.h" +#include "waveform/renderers/allshader/texturedvertexupdater.h" // Render digits using a texture (generated) with digits with blurred dark outline +using namespace rendergraph; + namespace { // The texture will contain 12 characters: 10 digits, colon and dot @@ -56,18 +60,19 @@ static_assert(checkCharToIndex()); } // namespace -allshader::DigitsRenderer::~DigitsRenderer() = default; - -void allshader::DigitsRenderer::init() { - initializeOpenGLFunctions(); - m_shader.init(); +allshader::DigitsRenderNode::DigitsRenderNode() { + setGeometry(std::make_unique(TextureMaterial::attributes(), 0)); + setMaterial(std::make_unique()); + geometry().setDrawingMode(Geometry::DrawingMode::Triangles); } -float allshader::DigitsRenderer::height() const { +allshader::DigitsRenderNode::~DigitsRenderNode() = default; + +float allshader::DigitsRenderNode::height() const { return m_height; } -void allshader::DigitsRenderer::updateTexture( +void allshader::DigitsRenderNode::updateTexture( float fontPointSize, float maxHeight, float devicePixelRatio) { if (fontPointSize == m_fontPointSize && maxHeight == m_maxHeight) { return; @@ -202,18 +207,25 @@ void allshader::DigitsRenderer::updateTexture( m_offset[NUM_CHARS] = 1.f; } - m_texture.setData(image); + Context context; + dynamic_cast(material()) + .setTexture(std::make_unique(context, image)); } -void allshader::DigitsRenderer::draw(const QMatrix4x4& matrix, +void allshader::DigitsRenderNode::update(const QMatrix4x4& matrix, float x, float y, bool multiLine, const QString& s1, const QString& s2) { + const int numVerticesPerRectangle = 6; + const int reserved = (s1.length() + s2.length()) * numVerticesPerRectangle; + geometry().allocate(reserved); + TexturedVertexUpdater vertexUpdater{geometry().vertexDataAs()}; + const float ch = height(); if (!s1.isEmpty()) { - const auto w = draw(matrix, + const auto w = addVertices(vertexUpdater, x, y, s1); @@ -224,68 +236,40 @@ void allshader::DigitsRenderer::draw(const QMatrix4x4& matrix, } } if (!s2.isEmpty()) { - draw(matrix, + addVertices(vertexUpdater, x, y, s2); } + + DEBUG_ASSERT(reserved == vertexUpdater.index()); + + material().setUniform(0, matrix); } -float allshader::DigitsRenderer::draw(const QMatrix4x4& matrix, +float allshader::DigitsRenderNode::addVertices(TexturedVertexUpdater& vertexUpdater, float x, float y, const QString& s) { - const int n = s.length(); const float x0 = x; const float space = static_cast(m_penWidth) / 2; - VertexData posVertices; - VertexData texVertices; - - posVertices.reserve(n * 6); // two triangles per character - texVertices.reserve(n * 6); - for (QChar c : s) { if (x != x0) { x -= space; } int index = charToIndex(c); - texVertices.addRectangle(m_offset[index], 0.f, m_offset[index + 1], 1.f); - posVertices.addRectangle(x, + vertexUpdater.addRectangle(x, y, x + m_width[index], - y + height()); + y + height(), + m_offset[index], + 0.f, + m_offset[index + 1], + 1.f); x += m_width[index]; } - m_shader.bind(); - - const int matrixLocation = m_shader.uniformLocation("matrix"); - const int textureLocation = m_shader.uniformLocation("texture"); - const int positionLocation = m_shader.attributeLocation("position"); - const int texcoordLocation = m_shader.attributeLocation("texcoord"); - - m_shader.setUniformValue(matrixLocation, matrix); - - m_shader.enableAttributeArray(positionLocation); - m_shader.setAttributeArray( - positionLocation, GL_FLOAT, posVertices.constData(), 2); - m_shader.enableAttributeArray(texcoordLocation); - m_shader.setAttributeArray( - texcoordLocation, GL_FLOAT, texVertices.constData(), 2); - - m_shader.setUniformValue(textureLocation, 0); - - m_texture.bind(); - - glDrawArrays(GL_TRIANGLES, 0, posVertices.size()); - - m_texture.release(); - - m_shader.disableAttributeArray(positionLocation); - m_shader.disableAttributeArray(texcoordLocation); - m_shader.release(); - return x - x0; } diff --git a/src/waveform/renderers/allshader/digitsrenderer.h b/src/waveform/renderers/allshader/digitsrenderer.h index 124ba778b53..277c89e7674 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.h +++ b/src/waveform/renderers/allshader/digitsrenderer.h @@ -1,23 +1,26 @@ #pragma once -#include +#include -#include "shaders/textureshader.h" -#include "util/opengltexture2d.h" +#include "rendergraph/geometrynode.h" +#include "util/class.h" + +namespace rendergraph { +class TexturedVertexUpdater; +} namespace allshader { -class DigitsRenderer; +class DigitsRenderNode; } -class allshader::DigitsRenderer : public QOpenGLFunctions { +class allshader::DigitsRenderNode : public rendergraph::GeometryNode { public: - DigitsRenderer() = default; - ~DigitsRenderer(); + DigitsRenderNode(); + ~DigitsRenderNode(); - void init(); void updateTexture(float fontPointSize, float maxHeight, float devicePixelRatio); - void draw(const QMatrix4x4& matrix, + void update(const QMatrix4x4& matrix, float x, float y, bool multiLine, @@ -26,13 +29,11 @@ class allshader::DigitsRenderer : public QOpenGLFunctions { float height() const; private: - float draw(const QMatrix4x4& matrix, + float addVertices(rendergraph::TexturedVertexUpdater& vertexUpdater, float x, float y, const QString& s); - mixxx::TextureShader m_shader; - OpenGLTexture2D m_texture; int m_penWidth; float m_offset[13]; float m_width[12]; @@ -40,5 +41,5 @@ class allshader::DigitsRenderer : public QOpenGLFunctions { float m_height{}; float m_maxHeight{}; float m_adjustedFontPointSize{}; - DISALLOW_COPY_AND_ASSIGN(DigitsRenderer); + DISALLOW_COPY_AND_ASSIGN(DigitsRenderNode); }; diff --git a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp index 01258dac89d..87675f2f78e 100644 --- a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp +++ b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp @@ -156,10 +156,6 @@ bool WaveformRendererPreroll::preprocessSelf() { m_color))); } - if (!dynamic_cast(material()).texture(0)) { - return false; - } - geometry().allocate(reserved); const float end = m_waveformRenderer->getLength(); diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 8d089dbf46a..3f71e748d07 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -11,6 +11,7 @@ #include "texturedvertexupdater.h" #include "track/track.h" #include "util/colorcomponents.h" +#include "waveform/renderers/allshader/digitsrenderer.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/allshader/rgbadata.h" #include "waveform/renderers/allshader/vertexdata.h" @@ -74,11 +75,15 @@ allshader::WaveformRenderMark::WaveformRenderMark( m_timeUntilMark(0.0), m_pTimeRemainingControl(nullptr), m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) { + // TODO move to PlayPosNode derived from GeometryNode appendChildNode(std::make_unique()); m_pPlayPosNode = static_cast(lastChild()); m_pPlayPosNode->setGeometry(std::make_unique(TextureMaterial::attributes(), 6)); m_pPlayPosNode->setMaterial(std::make_unique()); m_pPlayPosNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + + appendChildNode(std::make_unique()); + m_pDigitsRenderNode = static_cast(lastChild()); } bool allshader::WaveformRenderMark::init() { @@ -88,7 +93,6 @@ bool allshader::WaveformRenderMark::init() { } void allshader::WaveformRenderMark::initializeGL() { - m_digitsRenderer.init(); m_rgbaShader.init(); m_textureShader.init(); @@ -97,7 +101,7 @@ void allshader::WaveformRenderMark::initializeGL() { updatePlayPosMarkTexture(); const auto untilMarkTextPointSize = WaveformWidgetFactory::instance()->getUntilMarkTextPointSize(); - m_digitsRenderer.updateTexture(untilMarkTextPointSize, + m_pDigitsRenderNode->updateTexture(untilMarkTextPointSize, getMaxHeightForText(), m_waveformRenderer->getDevicePixelRatio()); } @@ -347,14 +351,14 @@ void allshader::WaveformRenderMark::drawUntilMark(const QMatrix4x4& matrix, floa const auto untilMarkTextPointSize = WaveformWidgetFactory::instance()->getUntilMarkTextPointSize(); - m_digitsRenderer.updateTexture(untilMarkTextPointSize, + m_pDigitsRenderNode->updateTexture(untilMarkTextPointSize, getMaxHeightForText(), m_waveformRenderer->getDevicePixelRatio()); if (m_timeUntilMark == 0.0) { return; } - const float ch = m_digitsRenderer.height(); + const float ch = m_pDigitsRenderNode->height(); float y = untilMarkAlign == Qt::AlignTop ? 0.f : untilMarkAlign == Qt::AlignBottom @@ -374,7 +378,7 @@ void allshader::WaveformRenderMark::drawUntilMark(const QMatrix4x4& matrix, floa } } - m_digitsRenderer.draw(matrix, + m_pDigitsRenderNode->update(matrix, x, y, multiLine, diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index 584bf4d57d5..c292dd31ee2 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -6,7 +6,6 @@ #include "shaders/rgbashader.h" #include "shaders/textureshader.h" #include "util/opengltexture2d.h" -#include "waveform/renderers/allshader/digitsrenderer.h" #include "waveform/renderers/waveformrendermarkbase.h" class QDomNode; @@ -17,6 +16,7 @@ class GeometryNode; } namespace allshader { +class DigitsRenderNode; class WaveformRenderMark; } @@ -57,7 +57,6 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, mixxx::RGBAShader m_rgbaShader; mixxx::TextureShader m_textureShader; - DigitsRenderer m_digitsRenderer; int m_beatsUntilMark; double m_timeUntilMark; double m_currentBeatPosition; @@ -66,6 +65,7 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, bool m_isSlipRenderer; + DigitsRenderNode* m_pDigitsRenderNode; rendergraph::GeometryNode* m_pPlayPosNode; DISALLOW_COPY_AND_ASSIGN(WaveformRenderMark); From 507a465ea91ce1148b4c5f12daa86f345ae77c48 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 31 Aug 2024 22:43:26 +0200 Subject: [PATCH 13/64] draw marks with rendergraph --- res/shaders/rendergraph/CMakeLists.txt | 14 +- res/shaders/rendergraph/endoftrack.frag | 4 +- res/shaders/rendergraph/endoftrack.frag.gl | 4 +- res/shaders/rendergraph/endoftrack.vert | 8 +- res/shaders/rendergraph/endoftrack.vert.gl | 4 +- .../rendergraph/generated_shaders_gl.cmake | 4 + res/shaders/rendergraph/pattern.vert | 8 +- res/shaders/rendergraph/rgb.frag | 8 + res/shaders/rendergraph/rgb.frag.gl | 9 + res/shaders/rendergraph/rgb.vert | 15 + res/shaders/rendergraph/rgb.vert.gl | 19 ++ res/shaders/rendergraph/rgba.frag | 8 + res/shaders/rendergraph/rgba.frag.gl | 9 + res/shaders/rendergraph/rgba.vert | 15 + res/shaders/rendergraph/rgba.vert.gl | 19 ++ res/shaders/rendergraph/texture.vert | 8 +- src/rendergraph/geometry.cpp | 15 +- src/rendergraph/geometry.h | 19 ++ src/rendergraph/geometrynode.h | 9 + src/rendergraph/material/rgbamaterial.cpp | 39 +++ src/rendergraph/material/rgbamaterial.h | 21 ++ src/rendergraph/material/rgbmaterial.cpp | 39 +++ src/rendergraph/material/rgbmaterial.h | 21 ++ src/rendergraph/opengl/CMakeLists.txt | 4 + src/rendergraph/opengl/geometrynode_impl.cpp | 11 +- src/rendergraph/scenegraph/CMakeLists.txt | 4 + src/rendergraph/uniformscache.h | 2 +- .../renderers/allshader/digitsrenderer.cpp | 16 +- .../renderers/allshader/digitsrenderer.h | 3 + .../renderers/allshader/rgbavertexupdater.h | 137 +++++++++ .../renderers/allshader/rgbvertexupdater.h | 129 ++++++++ .../allshader/texturedvertexupdater.h | 14 +- .../renderers/allshader/vertexupdater.h | 5 +- .../allshader/waveformrenderbeat.cpp | 14 +- .../renderers/allshader/waveformrenderbeat.h | 4 +- .../allshader/waveformrendererpreroll.cpp | 34 +- .../allshader/waveformrendererpreroll.h | 2 +- .../allshader/waveformrendermark.cpp | 291 ++++++++++-------- .../renderers/allshader/waveformrendermark.h | 33 +- .../allshader/waveformrendermarkrange.cpp | 39 ++- .../allshader/waveformrendermarkrange.h | 14 +- .../widgets/allshader/waveformwidget.cpp | 9 +- .../widgets/allshader/waveformwidget.h | 2 + 43 files changed, 843 insertions(+), 243 deletions(-) create mode 100644 res/shaders/rendergraph/rgb.frag create mode 100644 res/shaders/rendergraph/rgb.frag.gl create mode 100644 res/shaders/rendergraph/rgb.vert create mode 100644 res/shaders/rendergraph/rgb.vert.gl create mode 100644 res/shaders/rendergraph/rgba.frag create mode 100644 res/shaders/rendergraph/rgba.frag.gl create mode 100644 res/shaders/rendergraph/rgba.vert create mode 100644 res/shaders/rendergraph/rgba.vert.gl create mode 100644 src/rendergraph/material/rgbamaterial.cpp create mode 100644 src/rendergraph/material/rgbamaterial.h create mode 100644 src/rendergraph/material/rgbmaterial.cpp create mode 100644 src/rendergraph/material/rgbmaterial.h create mode 100644 src/waveform/renderers/allshader/rgbavertexupdater.h create mode 100644 src/waveform/renderers/allshader/rgbvertexupdater.h diff --git a/res/shaders/rendergraph/CMakeLists.txt b/res/shaders/rendergraph/CMakeLists.txt index fa03d006e94..3241c5a84c9 100644 --- a/res/shaders/rendergraph/CMakeLists.txt +++ b/res/shaders/rendergraph/CMakeLists.txt @@ -1,12 +1,16 @@ set(shaders - endoftrack.vert endoftrack.frag - texture.vert + endoftrack.vert + pattern.frag + pattern.vert + rgb.frag + rgb.vert + rgba.frag + rgba.vert texture.frag - unicolor.vert + texture.vert unicolor.frag - pattern.vert - pattern.frag + unicolor.vert ) qt6_add_shaders(rendergraph_sg "shaders-sg" diff --git a/res/shaders/rendergraph/endoftrack.frag b/res/shaders/rendergraph/endoftrack.frag index 65a99d13e4d..0f6712e87d5 100644 --- a/res/shaders/rendergraph/endoftrack.frag +++ b/res/shaders/rendergraph/endoftrack.frag @@ -1,6 +1,6 @@ #version 440 -layout(location = 0) in float vgradient; +layout(location = 0) in float vGradient; layout(location = 0) out vec4 fragColor; layout(std140, binding = 0) uniform buf { @@ -11,7 +11,7 @@ ubuf; void main() { float minAlpha = 0.5 * ubuf.color.w; float maxAlpha = 0.83 * ubuf.color.w; - float alpha = mix(minAlpha, maxAlpha, max(0.0, vgradient)); + float alpha = mix(minAlpha, maxAlpha, max(0.0, vGradient)); // premultiple alpha fragColor = vec4(ubuf.color.xyz * alpha, alpha); } diff --git a/res/shaders/rendergraph/endoftrack.frag.gl b/res/shaders/rendergraph/endoftrack.frag.gl index f65b1ea3dda..78de913751a 100644 --- a/res/shaders/rendergraph/endoftrack.frag.gl +++ b/res/shaders/rendergraph/endoftrack.frag.gl @@ -8,12 +8,12 @@ struct buf uniform buf ubuf; -varying float vgradient; +varying float vGradient; void main() { float minAlpha = 0.5 * ubuf.color.w; float maxAlpha = 0.829999983310699462890625 * ubuf.color.w; - float alpha = mix(minAlpha, maxAlpha, max(0.0, vgradient)); + float alpha = mix(minAlpha, maxAlpha, max(0.0, vGradient)); gl_FragData[0] = vec4(ubuf.color.xyz * alpha, alpha); } diff --git a/res/shaders/rendergraph/endoftrack.vert b/res/shaders/rendergraph/endoftrack.vert index b5741fc8f35..101cdb324e4 100644 --- a/res/shaders/rendergraph/endoftrack.vert +++ b/res/shaders/rendergraph/endoftrack.vert @@ -2,13 +2,9 @@ layout(location = 0) in vec4 position; layout(location = 1) in float gradient; -layout(location = 0) out float vgradient; - -out gl_PerVertex { - vec4 gl_Position; -}; +layout(location = 0) out float vGradient; void main() { - vgradient = gradient; + vGradient = gradient; gl_Position = position; } diff --git a/res/shaders/rendergraph/endoftrack.vert.gl b/res/shaders/rendergraph/endoftrack.vert.gl index 053f0d12e78..da4626bbf7c 100644 --- a/res/shaders/rendergraph/endoftrack.vert.gl +++ b/res/shaders/rendergraph/endoftrack.vert.gl @@ -1,12 +1,12 @@ #version 120 //// GENERATED - EDITS WILL BE OVERWRITTEN -varying float vgradient; +varying float vGradient; attribute float gradient; attribute vec4 position; void main() { - vgradient = gradient; + vGradient = gradient; gl_Position = position; } diff --git a/res/shaders/rendergraph/generated_shaders_gl.cmake b/res/shaders/rendergraph/generated_shaders_gl.cmake index e2b3318bc3e..951c85c3669 100644 --- a/res/shaders/rendergraph/generated_shaders_gl.cmake +++ b/res/shaders/rendergraph/generated_shaders_gl.cmake @@ -1,10 +1,14 @@ set(generated_shaders_gl endoftrack.vert.gl pattern.vert.gl + rgb.vert.gl + rgba.vert.gl texture.vert.gl unicolor.vert.gl endoftrack.frag.gl pattern.frag.gl + rgb.frag.gl + rgba.frag.gl texture.frag.gl unicolor.frag.gl ) diff --git a/res/shaders/rendergraph/pattern.vert b/res/shaders/rendergraph/pattern.vert index 46e4c84d254..07b3d7f1f3b 100644 --- a/res/shaders/rendergraph/pattern.vert +++ b/res/shaders/rendergraph/pattern.vert @@ -1,14 +1,14 @@ #version 440 -layout(location = 0) in vec4 position; -layout(location = 1) in vec2 texcoord; -layout(location = 0) out vec2 vTexcoord; - layout(std140, binding = 0) uniform buf { mat4 matrix; } ubuf; +layout(location = 0) in vec4 position; +layout(location = 1) in vec2 texcoord; +layout(location = 0) out vec2 vTexcoord; + void main() { vTexcoord = texcoord; gl_Position = ubuf.matrix * position; diff --git a/res/shaders/rendergraph/rgb.frag b/res/shaders/rendergraph/rgb.frag new file mode 100644 index 00000000000..0a808489f5b --- /dev/null +++ b/res/shaders/rendergraph/rgb.frag @@ -0,0 +1,8 @@ +#version 440 + +layout(location = 0) in vec3 vColor; +layout(location = 0) out vec4 fragColor; + +void main() { + fragColor = vec4(vColor, 1.0); +} diff --git a/res/shaders/rendergraph/rgb.frag.gl b/res/shaders/rendergraph/rgb.frag.gl new file mode 100644 index 00000000000..b8a61f8682f --- /dev/null +++ b/res/shaders/rendergraph/rgb.frag.gl @@ -0,0 +1,9 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +varying vec3 vColor; + +void main() +{ + gl_FragData[0] = vec4(vColor, 1.0); +} diff --git a/res/shaders/rendergraph/rgb.vert b/res/shaders/rendergraph/rgb.vert new file mode 100644 index 00000000000..6568d01f187 --- /dev/null +++ b/res/shaders/rendergraph/rgb.vert @@ -0,0 +1,15 @@ +#version 440 + +layout(std140, binding = 0) uniform buf { + mat4 matrix; +} +ubuf; + +layout(location = 0) in vec4 position; +layout(location = 1) in vec3 color; +layout(location = 0) out vec3 vColor; + +void main() { + vColor = color; + gl_Position = ubuf.matrix * position; +} diff --git a/res/shaders/rendergraph/rgb.vert.gl b/res/shaders/rendergraph/rgb.vert.gl new file mode 100644 index 00000000000..53e86e4501c --- /dev/null +++ b/res/shaders/rendergraph/rgb.vert.gl @@ -0,0 +1,19 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +struct buf +{ + mat4 matrix; +}; + +uniform buf ubuf; + +varying vec3 vColor; +attribute vec3 color; +attribute vec4 position; + +void main() +{ + vColor = color; + gl_Position = ubuf.matrix * position; +} diff --git a/res/shaders/rendergraph/rgba.frag b/res/shaders/rendergraph/rgba.frag new file mode 100644 index 00000000000..5cf90a770ea --- /dev/null +++ b/res/shaders/rendergraph/rgba.frag @@ -0,0 +1,8 @@ +#version 440 + +layout(location = 0) in vec4 vColor; +layout(location = 0) out vec4 fragColor; + +void main() { + fragColor = vec4(vColor.xyz * vColor.w, vColor.w); // premultiple alpha +} diff --git a/res/shaders/rendergraph/rgba.frag.gl b/res/shaders/rendergraph/rgba.frag.gl new file mode 100644 index 00000000000..a831457b968 --- /dev/null +++ b/res/shaders/rendergraph/rgba.frag.gl @@ -0,0 +1,9 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +varying vec4 vColor; + +void main() +{ + gl_FragData[0] = vec4(vColor.xyz * vColor.w, vColor.w); +} diff --git a/res/shaders/rendergraph/rgba.vert b/res/shaders/rendergraph/rgba.vert new file mode 100644 index 00000000000..d5ce8b2d9db --- /dev/null +++ b/res/shaders/rendergraph/rgba.vert @@ -0,0 +1,15 @@ +#version 440 + +layout(std140, binding = 0) uniform buf { + mat4 matrix; +} +ubuf; + +layout(location = 0) in vec4 position; +layout(location = 1) in vec4 color; +layout(location = 0) out vec4 vColor; + +void main() { + vColor = color; + gl_Position = ubuf.matrix * position; +} diff --git a/res/shaders/rendergraph/rgba.vert.gl b/res/shaders/rendergraph/rgba.vert.gl new file mode 100644 index 00000000000..df2bcf93236 --- /dev/null +++ b/res/shaders/rendergraph/rgba.vert.gl @@ -0,0 +1,19 @@ +#version 120 +//// GENERATED - EDITS WILL BE OVERWRITTEN + +struct buf +{ + mat4 matrix; +}; + +uniform buf ubuf; + +varying vec4 vColor; +attribute vec4 color; +attribute vec4 position; + +void main() +{ + vColor = color; + gl_Position = ubuf.matrix * position; +} diff --git a/res/shaders/rendergraph/texture.vert b/res/shaders/rendergraph/texture.vert index 46e4c84d254..07b3d7f1f3b 100644 --- a/res/shaders/rendergraph/texture.vert +++ b/res/shaders/rendergraph/texture.vert @@ -1,14 +1,14 @@ #version 440 -layout(location = 0) in vec4 position; -layout(location = 1) in vec2 texcoord; -layout(location = 0) out vec2 vTexcoord; - layout(std140, binding = 0) uniform buf { mat4 matrix; } ubuf; +layout(location = 0) in vec4 position; +layout(location = 1) in vec2 texcoord; +layout(location = 0) out vec2 vTexcoord; + void main() { vTexcoord = texcoord; gl_Position = ubuf.matrix * position; diff --git a/src/rendergraph/geometry.cpp b/src/rendergraph/geometry.cpp index 6ac75b07860..67eb8e86fe2 100644 --- a/src/rendergraph/geometry.cpp +++ b/src/rendergraph/geometry.cpp @@ -27,11 +27,6 @@ float* Geometry::vertexData() { return m_pImpl->vertexData(); } -template<> -QVector2D* Geometry::vertexDataAs() { - return m_pImpl->vertexDataAs(); -} - template<> Geometry::Point2D* Geometry::vertexDataAs() { return m_pImpl->vertexDataAs(); @@ -42,6 +37,16 @@ Geometry::TexturedPoint2D* Geometry::vertexDataAs() { return m_pImpl->vertexDataAs(); } +template<> +Geometry::RGBColoredPoint2D* Geometry::vertexDataAs() { + return m_pImpl->vertexDataAs(); +} + +template<> +Geometry::RGBAColoredPoint2D* Geometry::vertexDataAs() { + return m_pImpl->vertexDataAs(); +} + void Geometry::allocate(int vertexCount) { m_pImpl->allocate(vertexCount); } diff --git a/src/rendergraph/geometry.h b/src/rendergraph/geometry.h index 09de345772f..c83a8c6c5c5 100644 --- a/src/rendergraph/geometry.h +++ b/src/rendergraph/geometry.h @@ -26,6 +26,24 @@ class rendergraph::Geometry { } }; + struct RGBColoredPoint2D { + QVector2D position2D; + QVector3D color3D; + RGBColoredPoint2D(float x, float y, float r, float g, float b) + : position2D{x, y}, + color3D{r, g, b} { + } + }; + + struct RGBAColoredPoint2D { + QVector2D position2D; + QVector4D color4D; + RGBAColoredPoint2D(float x, float y, float r, float g, float b, float a) + : position2D{x, y}, + color4D{r, g, b, a} { + } + }; + enum class DrawingMode { Triangles, TriangleStrip @@ -34,6 +52,7 @@ class rendergraph::Geometry { Geometry(const AttributeSet& attributeSet, int vertexCount); ~Geometry(); + void setAttributeValues(int attributePosition, const float* data, int numTuples); Impl& impl() const; diff --git a/src/rendergraph/geometrynode.h b/src/rendergraph/geometrynode.h index f8884a110cd..1b0784a42cf 100644 --- a/src/rendergraph/geometrynode.h +++ b/src/rendergraph/geometrynode.h @@ -1,5 +1,6 @@ #pragma once +#include "rendergraph/geometry.h" #include "rendergraph/node.h" namespace rendergraph { @@ -14,6 +15,14 @@ class rendergraph::GeometryNode : public rendergraph::Node { GeometryNode(); ~GeometryNode(); + + template + void initForRectangles(int numRectangles) { + setGeometry(std::make_unique(T_Material::attributes(), numRectangles * 6)); + setMaterial(std::make_unique()); + geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + } + void setMaterial(std::unique_ptr material); void setGeometry(std::unique_ptr geometry); Geometry& geometry() const; diff --git a/src/rendergraph/material/rgbamaterial.cpp b/src/rendergraph/material/rgbamaterial.cpp new file mode 100644 index 00000000000..c1d53d3f8bc --- /dev/null +++ b/src/rendergraph/material/rgbamaterial.cpp @@ -0,0 +1,39 @@ +#include "rgbamaterial.h" + +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +RGBAMaterial::RGBAMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& RGBAMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "color"}); + return set; +} + +/* static */ const UniformSet& RGBAMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.matrix"}); + return set; +} + +MaterialType* RGBAMaterial::type() const { + static MaterialType type; + return &type; +} + +int RGBAMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +std::unique_ptr RGBAMaterial::createShader() const { + return std::make_unique( + "rgba.vert", "rgba.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/material/rgbamaterial.h b/src/rendergraph/material/rgbamaterial.h new file mode 100644 index 00000000000..b5b72a949c9 --- /dev/null +++ b/src/rendergraph/material/rgbamaterial.h @@ -0,0 +1,21 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" + +namespace rendergraph { +class RGBAMaterial; +} + +class rendergraph::RGBAMaterial : public rendergraph::Material { + public: + RGBAMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + std::unique_ptr createShader() const override; +}; diff --git a/src/rendergraph/material/rgbmaterial.cpp b/src/rendergraph/material/rgbmaterial.cpp new file mode 100644 index 00000000000..3a2f014d07e --- /dev/null +++ b/src/rendergraph/material/rgbmaterial.cpp @@ -0,0 +1,39 @@ +#include "rgbmaterial.h" + +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +RGBMaterial::RGBMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& RGBMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "color"}); + return set; +} + +/* static */ const UniformSet& RGBMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.matrix"}); + return set; +} + +MaterialType* RGBMaterial::type() const { + static MaterialType type; + return &type; +} + +int RGBMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +std::unique_ptr RGBMaterial::createShader() const { + return std::make_unique( + "rgb.vert", "rgb.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/material/rgbmaterial.h b/src/rendergraph/material/rgbmaterial.h new file mode 100644 index 00000000000..6d4d74b2514 --- /dev/null +++ b/src/rendergraph/material/rgbmaterial.h @@ -0,0 +1,21 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" + +namespace rendergraph { +class RGBMaterial; +} + +class rendergraph::RGBMaterial : public rendergraph::Material { + public: + RGBMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + std::unique_ptr createShader() const override; +}; diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 6a106948c45..f87cbc1797b 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -33,6 +33,10 @@ add_library(rendergraph_gl ../material/patternmaterial.h ../material/texturematerial.cpp ../material/texturematerial.h + ../material/rgbamaterial.cpp + ../material/rgbamaterial.h + ../material/rgbmaterial.cpp + ../material/rgbmaterial.h ../material/unicolormaterial.cpp ../material/unicolormaterial.h geometrynode_impl.cpp diff --git a/src/rendergraph/opengl/geometrynode_impl.cpp b/src/rendergraph/opengl/geometrynode_impl.cpp index e4b64278538..7c753c7a494 100644 --- a/src/rendergraph/opengl/geometrynode_impl.cpp +++ b/src/rendergraph/opengl/geometrynode_impl.cpp @@ -16,14 +16,19 @@ GLenum toGlDrawingMode(Geometry::DrawingMode mode) { } // namespace void GeometryNode::Impl::render() { + Geometry::Impl& geometry = m_pGeometry->impl(); + + if (geometry.vertexCount() == 0) { + return; + } + + Material::Impl& material = m_pMaterial->impl(); + glEnable(GL_BLEND); // qt scene graph uses premultiplied alpha color in the shader, // so we need to do the same glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - Material::Impl& material = m_pMaterial->impl(); - Geometry::Impl& geometry = m_pGeometry->impl(); - QOpenGLShaderProgram& shader = material.glShader(); shader.bind(); diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 3c0ae4e2557..825d6942377 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -31,6 +31,10 @@ add_library(rendergraph_sg ../material/endoftrackmaterial.h ../material/patternmaterial.cpp ../material/patternmaterial.h + ../material/rgbamaterial.cpp + ../material/rgbamaterial.h + ../material/rgbmaterial.cpp + ../material/rgbmaterial.h ../material/texturematerial.cpp ../material/texturematerial.h ../material/unicolormaterial.cpp diff --git a/src/rendergraph/uniformscache.h b/src/rendergraph/uniformscache.h index a88254ded40..5787570effd 100644 --- a/src/rendergraph/uniformscache.h +++ b/src/rendergraph/uniformscache.h @@ -39,7 +39,7 @@ class rendergraph::UniformsCache { return m_byteArray.size(); } int count() const { - return m_infos.size(); + return static_cast(m_infos.size()); } private: diff --git a/src/waveform/renderers/allshader/digitsrenderer.cpp b/src/waveform/renderers/allshader/digitsrenderer.cpp index 03c72e92b34..c4c2a77d349 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.cpp +++ b/src/waveform/renderers/allshader/digitsrenderer.cpp @@ -247,6 +247,10 @@ void allshader::DigitsRenderNode::update(const QMatrix4x4& matrix, material().setUniform(0, matrix); } +void allshader::DigitsRenderNode::clear() { + geometry().allocate(0); +} + float allshader::DigitsRenderNode::addVertices(TexturedVertexUpdater& vertexUpdater, float x, float y, @@ -260,14 +264,10 @@ float allshader::DigitsRenderNode::addVertices(TexturedVertexUpdater& vertexUpda } int index = charToIndex(c); - vertexUpdater.addRectangle(x, - y, - x + m_width[index], - y + height(), - m_offset[index], - 0.f, - m_offset[index + 1], - 1.f); + vertexUpdater.addRectangle({x, y}, + {x + m_width[index], y + height()}, + {m_offset[index], 0.f}, + {m_offset[index + 1], 1.f}); x += m_width[index]; } diff --git a/src/waveform/renderers/allshader/digitsrenderer.h b/src/waveform/renderers/allshader/digitsrenderer.h index 277c89e7674..b55c72b884b 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.h +++ b/src/waveform/renderers/allshader/digitsrenderer.h @@ -26,6 +26,9 @@ class allshader::DigitsRenderNode : public rendergraph::GeometryNode { bool multiLine, const QString& s1, const QString& s2); + + void clear(); + float height() const; private: diff --git a/src/waveform/renderers/allshader/rgbavertexupdater.h b/src/waveform/renderers/allshader/rgbavertexupdater.h new file mode 100644 index 00000000000..2f2a46dc2eb --- /dev/null +++ b/src/waveform/renderers/allshader/rgbavertexupdater.h @@ -0,0 +1,137 @@ +#pragma once + +#include "rendergraph/geometry.h" + +namespace rendergraph { +class RGBAVertexUpdater; +} + +class rendergraph::RGBAVertexUpdater { + public: + RGBAVertexUpdater(Geometry::RGBAColoredPoint2D* pData) + : m_pData(pData), + m_pWrite(pData) { + } + + void addRectangle( + QVector2D lt, + QVector2D rb, + QVector4D rgba) { + addRectangle(lt.x(), lt.y(), rb.x(), rb.y(), rgba.x(), rgba.y(), rgba.z(), rgba.w()); + } + void addRectangleVGradient( + QVector2D lt, + QVector2D rb, + QVector4D rgbat, + QVector4D rgbab) { + addRectangleVGradient(lt.x(), + lt.y(), + rb.x(), + rb.y(), + rgbat.x(), + rgbat.y(), + rgbat.z(), + rgbat.w(), + rgbab.x(), + rgbab.y(), + rgbab.z(), + rgbab.w()); + } + void addRectangleHGradient( + QVector2D lt, + QVector2D rb, + QVector4D rgbal, + QVector4D rgbar) { + addRectangleHGradient(lt.x(), + lt.y(), + rb.x(), + rb.y(), + rgbal.x(), + rgbal.y(), + rgbal.z(), + rgbal.w(), + rgbar.x(), + rgbar.y(), + rgbar.z(), + rgbar.w()); + } + void addRectangle(float x1, float y1, float x2, float y2, float r, float g, float b, float a) { + addTriangle(x1, y1, x2, y1, x1, y2, r, g, b, a); + addTriangle(x1, y2, x2, y2, x2, y1, r, g, b, a); + } + void addRectangleVGradient( + float x1, + float y1, + float x2, + float y2, + float r1, + float g1, + float b1, + float a1, + float r2, + float g2, + float b2, + float a2) { + addTriangle(x1, y1, x2, y1, x1, y2, r1, g1, b1, a1, r1, g1, b1, a1, r2, g2, b2, a2); + addTriangle(x1, y2, x2, y2, x2, y1, r2, g2, b2, a2, r2, g2, b2, a2, r1, g1, b1, a1); + } + void addRectangleHGradient( + float x1, + float y1, + float x2, + float y2, + float r1, + float g1, + float b1, + float a1, + float r2, + float g2, + float b2, + float a2) { + addTriangle(x1, y1, x2, y1, x1, y2, r1, g1, b1, a1, r2, g2, b2, a2, r1, g1, b1, a1); + addTriangle(x1, y2, x2, y2, x2, y1, r1, g1, b1, a1, r2, g2, b2, a2, r2, g2, b2, a2); + } + void addTriangle(float x1, + float y1, + float x2, + float y2, + float x3, + float y3, + float r, + float g, + float b, + float a) { + *m_pWrite++ = Geometry::RGBAColoredPoint2D{x1, y1, r, g, b, a}; + *m_pWrite++ = Geometry::RGBAColoredPoint2D{x2, y2, r, g, b, a}; + *m_pWrite++ = Geometry::RGBAColoredPoint2D{x3, y3, r, g, b, a}; + } + void addTriangle(float x1, + float y1, + float x2, + float y2, + float x3, + float y3, + float r1, + float g1, + float b1, + float a1, + float r2, + float g2, + float b2, + float a2, + float r3, + float g3, + float b3, + float a3) { + *m_pWrite++ = Geometry::RGBAColoredPoint2D{x1, y1, r1, g1, b1, a1}; + *m_pWrite++ = Geometry::RGBAColoredPoint2D{x2, y2, r2, g2, b2, a2}; + *m_pWrite++ = Geometry::RGBAColoredPoint2D{x3, y3, r3, g3, b3, a3}; + } + int index() const { + return static_cast(m_pWrite - m_pData); + } + + private: + Geometry::RGBAColoredPoint2D* const m_pData; + Geometry::RGBAColoredPoint2D* m_pWrite; +}; diff --git a/src/waveform/renderers/allshader/rgbvertexupdater.h b/src/waveform/renderers/allshader/rgbvertexupdater.h new file mode 100644 index 00000000000..580883cb6e1 --- /dev/null +++ b/src/waveform/renderers/allshader/rgbvertexupdater.h @@ -0,0 +1,129 @@ +#pragma once + +#include "rendergraph/geometry.h" + +namespace rendergraph { +class RGBVertexUpdater; +} + +class rendergraph::RGBVertexUpdater { + public: + RGBVertexUpdater(Geometry::RGBColoredPoint2D* pData) + : m_pData(pData), + m_pWrite(pData) { + } + + void addRectangle( + QVector2D lt, + QVector2D rb, + QVector4D rgb) { + addRectangle(lt.x(), lt.y(), rb.x(), rb.y(), rgb.x(), rgb.y(), rgb.z(), rgb.w()); + } + void addRectangleVGradient( + QVector2D lt, + QVector2D rb, + QVector4D rgbt, + QVector4D rgbb) { + addRectangleVGradient(lt.x(), + lt.y(), + rb.x(), + rb.y(), + rgbt.x(), + rgbt.y(), + rgbt.z(), + rgbb.x(), + rgbb.y(), + rgbb.z()); + } + void addRectangleHGradient( + QVector2D lt, + QVector2D rb, + QVector4D rgbl, + QVector4D rgbr) { + addRectangleHGradient(lt.x(), + lt.y(), + rb.x(), + rb.y(), + rgbl.x(), + rgbl.y(), + rgbl.z(), + rgbr.x(), + rgbr.y(), + rgbr.z()); + } + void addRectangle(float x1, float y1, float x2, float y2, float r, float g, float b) { + addTriangle(x1, y1, x2, y1, x1, y2, r, g, b, a); + addTriangle(x1, y2, x2, y2, x2, y1, r, g, b, a); + } + void addRectangleVGradient( + float x1, + float y1, + float x2, + float y2, + float r1, + float g1, + float b1, + float r2, + float g2, + float b2) { + addTriangle(x1, y1, x2, y1, x1, y2, r1, g1, b1, r2, g2, b2, r1, g1, b1); + addTriangle(x1, y2, x2, y2, x2, y1, r1, g1, b1, r2, g2, b2, r2, g2, b2); + } + void addRectangleHGradient( + float x1, + float y1, + float x2, + float y2, + float r1, + float g1, + float b1, + float r2, + float g2, + floar b2) { + addTriangle(x1, y1, x2, y1, x1, y2, r1, g1, b1, r2, g2, b2, r1, g1, b1); + addTriangle(x1, y2, x2, y2, x2, y1, r1, g1, b1, r2, g2, b2, r2, g2, b2); + } + void addTriangle(float x1, + float y1, + float x2, + float y2, + float x3, + float y3, + float r, + float g, + float b) { + *m_pWrite++ = Geometry::RGBColoredPoint2D{x1, y1, r, g, b}; + *m_pWrite++ = Geometry::RGBColoredPoint2D{x2, y2, r, g, b}; + *m_pWrite++ = Geometry::RGBColoredPoint2D{x3, y3, r, g, b}; + } + void addTriangle(float x1, + float y1, + float x2, + float y2, + float x3, + float y3, + float r1, + float g1, + float b1, + + float r2, + float g2, + float b2, + + float r3, + float g3, + float b3, + + ) { + *m_pWrite++ = Geometry::RGBColoredPoint2D{x1, y1, r1, g1, b1}; + *m_pWrite++ = Geometry::RGBColoredPoint2D{x2, y2, r2, g2, b2}; + *m_pWrite++ = Geometry::RGBColoredPoint2D{x3, y3, r3, g3, b3}; + } + int index() const { + return static_cast(m_pWrite - m_pData); + } + + private: + Geometry::RGBColoredPoint2D* const m_pData; + Geometry::RGBColoredPoint2D* m_pWrite; +}; diff --git a/src/waveform/renderers/allshader/texturedvertexupdater.h b/src/waveform/renderers/allshader/texturedvertexupdater.h index a61f6877ae4..e754fb509a0 100644 --- a/src/waveform/renderers/allshader/texturedvertexupdater.h +++ b/src/waveform/renderers/allshader/texturedvertexupdater.h @@ -12,16 +12,12 @@ class rendergraph::TexturedVertexUpdater { : m_pData(pData), m_pWrite(pData) { } - void addRectangle( - float x1, - float y1, - float x2, - float y2, - float tx1, - float ty1, - float tx2, - float ty2) { + QVector2D lt, QVector2D rb, QVector2D tlr, QVector2D trb) { + addRectangle(lt.x(), lt.y(), rb.x(), rb.y(), tlr.x(), tlr.y(), trb.x(), trb.y()); + } + void addRectangle( + float x1, float y1, float x2, float y2, float tx1, float ty1, float tx2, float ty2) { addTriangle(x1, y1, x2, y1, x1, y2, tx1, ty1, tx2, ty1, tx1, ty2); addTriangle(x1, y2, x2, y2, x2, y1, tx1, ty2, tx2, ty2, tx2, ty1); } diff --git a/src/waveform/renderers/allshader/vertexupdater.h b/src/waveform/renderers/allshader/vertexupdater.h index 50032ee0aa2..d98d40f8c19 100644 --- a/src/waveform/renderers/allshader/vertexupdater.h +++ b/src/waveform/renderers/allshader/vertexupdater.h @@ -10,7 +10,10 @@ class rendergraph::VertexUpdater { : m_pData(pData), m_pWrite(pData) { } - + void addRectangle( + QVector2D lt, QVector2D rb) { + addRectangle(lt.x(), lt.y(), rb.x(), rb.y()); + } void addRectangle( float x1, float y1, diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.cpp b/src/waveform/renderers/allshader/waveformrenderbeat.cpp index 113b8ece90a..0dc552e6cfb 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.cpp +++ b/src/waveform/renderers/allshader/waveformrenderbeat.cpp @@ -19,10 +19,8 @@ WaveformRenderBeat::WaveformRenderBeat(WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type) : ::WaveformRendererAbstract(waveformWidget), m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) { - setGeometry(std::make_unique(UniColorMaterial::attributes(), 0)); - setMaterial(std::make_unique()); + initForRectangles(0); setUsePreprocess(true); - geometry().setDrawingMode(Geometry::DrawingMode::Triangles); } void WaveformRenderBeat::setup(const QDomNode& node, const SkinContext& context) { @@ -37,12 +35,12 @@ void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* event) { } void WaveformRenderBeat::preprocess() { - if (!preprocessSelf()) { + if (!preprocessInner()) { geometry().allocate(0); } } -bool WaveformRenderBeat::preprocessSelf() { +bool WaveformRenderBeat::preprocessInner() { const TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); if (!trackInfo || (m_isSlipRenderer && !m_waveformRenderer->isSlipActive())) { @@ -119,10 +117,8 @@ bool WaveformRenderBeat::preprocessSelf() { const float x1 = static_cast(xBeatPoint); const float x2 = x1 + 1.f; - vertexUpdater.addRectangle(x1, - 0.f, - x2, - m_isSlipRenderer ? rendererBreadth / 2 : rendererBreadth); + vertexUpdater.addRectangle({x1, 0.f}, + {x2, m_isSlipRenderer ? rendererBreadth / 2 : rendererBreadth}); } DEBUG_ASSERT(reserved == vertexUpdater.index()); diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.h b/src/waveform/renderers/allshader/waveformrenderbeat.h index 5a9d6e7535f..c0c13126dc2 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.h +++ b/src/waveform/renderers/allshader/waveformrenderbeat.h @@ -27,14 +27,14 @@ class allshader::WaveformRenderBeat final void setup(const QDomNode& node, const SkinContext& context) override; - // Virtual for rendergraph::Node + // Virtuals for rendergraph::Node void preprocess() override; private: QColor m_color; bool m_isSlipRenderer; - bool preprocessSelf(); + bool preprocessInner(); DISALLOW_COPY_AND_ASSIGN(WaveformRenderBeat); }; diff --git a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp index 87675f2f78e..0dc044db41d 100644 --- a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp +++ b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp @@ -90,12 +90,12 @@ void WaveformRendererPreroll::draw(QPainter* painter, QPaintEvent* event) { } void WaveformRendererPreroll::preprocess() { - if (!preprocessSelf()) { + if (!preprocessInner()) { geometry().allocate(0); } } -bool WaveformRendererPreroll::preprocessSelf() { +bool WaveformRendererPreroll::preprocessInner() { const TrackPointer trackInfo = m_waveformRenderer->getTrackInfo(); if (!trackInfo || (m_isSlipRenderer && !m_waveformRenderer->isSlipActive())) { @@ -177,15 +177,12 @@ bool WaveformRendererPreroll::preprocessSelf() { const float repetitions = x / markerLength; - vertexUpdater.addRectangle(x, - halfBreadth - halfMarkerBreadth, - 0, - m_isSlipRenderer ? halfBreadth - : halfBreadth + halfMarkerBreadth, - 0.f, - 0.f, - repetitions, - m_isSlipRenderer ? 0.5 : 1.f); + vertexUpdater.addRectangle({x, halfBreadth - halfMarkerBreadth}, + {0, + m_isSlipRenderer ? halfBreadth + : halfBreadth + halfMarkerBreadth}, + {0.f, 0.f}, + {repetitions, m_isSlipRenderer ? 0.5f : 1.f}); } if (postRollVisible) { @@ -204,15 +201,12 @@ bool WaveformRendererPreroll::preprocessSelf() { const float repetitions = (end - x) / markerLength; - vertexUpdater.addRectangle(x, - halfBreadth - halfMarkerBreadth, - end, - m_isSlipRenderer ? halfBreadth - : halfBreadth + halfMarkerBreadth, - 0.f, - 0.f, - repetitions, - m_isSlipRenderer ? 0.5 : 1.f); + vertexUpdater.addRectangle({x, halfBreadth - halfMarkerBreadth}, + {end, + m_isSlipRenderer ? halfBreadth + : halfBreadth + halfMarkerBreadth}, + {0.f, 0.f}, + {repetitions, m_isSlipRenderer ? 0.5f : 1.f}); } DEBUG_ASSERT(reserved == vertexUpdater.index()); diff --git a/src/waveform/renderers/allshader/waveformrendererpreroll.h b/src/waveform/renderers/allshader/waveformrendererpreroll.h index b4844914acd..7e3f10ea628 100644 --- a/src/waveform/renderers/allshader/waveformrendererpreroll.h +++ b/src/waveform/renderers/allshader/waveformrendererpreroll.h @@ -38,7 +38,7 @@ class allshader::WaveformRendererPreroll final float m_markerLength{}; bool m_isSlipRenderer; - bool preprocessSelf(); + bool preprocessInner(); DISALLOW_COPY_AND_ASSIGN(WaveformRendererPreroll); }; diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 3f71e748d07..744ee7f4920 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -1,20 +1,19 @@ #include "waveform/renderers/allshader/waveformrendermark.h" -#include #include #include "rendergraph/context.h" #include "rendergraph/geometry.h" #include "rendergraph/geometrynode.h" +#include "rendergraph/material/rgbamaterial.h" #include "rendergraph/material/texturematerial.h" #include "rendergraph/texture.h" +#include "rgbavertexupdater.h" #include "texturedvertexupdater.h" #include "track/track.h" #include "util/colorcomponents.h" #include "waveform/renderers/allshader/digitsrenderer.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" -#include "waveform/renderers/allshader/rgbadata.h" -#include "waveform/renderers/allshader/vertexdata.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveformwidgetfactory.h" @@ -29,17 +28,75 @@ using namespace rendergraph; // only to draw on a QImage. This is only done once when needed and the images are // then used as textures to be drawn with a GLSL shader. -class TextureGraphics : public WaveformMark::Graphics { +class WaveformMarkNode : public rendergraph::GeometryNode { public: - TextureGraphics(const QImage& image) { - m_texture.setData(image); + WaveformMark* m_pOwner{}; + + WaveformMarkNode(WaveformMark* pOwner, const QImage& image) + : m_pOwner(pOwner) { + initForRectangles(1); + updateTexture(image); + } + void updateTexture(const QImage& image) { + Context context; + dynamic_cast(material()) + .setTexture(std::make_unique(context, image)); + m_textureWidth = image.width(); + m_textureHeight = image.height(); + } + void update(const QMatrix4x4& matrix, float x, float y, float devicePixelRatio) { + material().setUniform(0, matrix); + + TexturedVertexUpdater vertexUpdater{ + geometry().vertexDataAs()}; + vertexUpdater.addRectangle({x, y}, + {x + m_textureWidth / devicePixelRatio, + y + m_textureHeight / devicePixelRatio}, + {0.f, 0.f}, + {1.f, 1.f}); } - QOpenGLTexture* texture() { - return &m_texture; + float textureWidth() const { + return m_textureWidth; + } + float textureHeight() const { + return m_textureHeight; + } + + public: + float m_textureWidth{}; + float m_textureHeight{}; +}; + +class WaveformMarkNodeGraphics : public WaveformMark::Graphics { + public: + WaveformMarkNodeGraphics(WaveformMark* pOwner, const QImage& image) + : m_pNode(std::make_unique(pOwner, image)) { + } + void updateTexture(const QImage& image) { + waveformMarkNode()->updateTexture(image); + } + void update(const QMatrix4x4& matrix, float x, float y, float devicePixelRatio) { + waveformMarkNode()->update(matrix, x, y, devicePixelRatio); + } + float textureWidth() const { + return waveformMarkNode()->textureWidth(); + } + float textureHeight() const { + return waveformMarkNode()->textureHeight(); + } + void setNode(std::unique_ptr&& pNode) { + m_pNode = std::move(pNode); + } + void moveNodeToChildrenOf(Node* pParent) { + pParent->appendChildNode(std::move(m_pNode)); } private: - OpenGLTexture2D m_texture; + WaveformMarkNode* waveformMarkNode() const { + return static_cast(m_pNode.get()); + } + + std::unique_ptr m_pNode; }; // Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive @@ -75,15 +132,24 @@ allshader::WaveformRenderMark::WaveformRenderMark( m_timeUntilMark(0.0), m_pTimeRemainingControl(nullptr), m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) { - // TODO move to PlayPosNode derived from GeometryNode - appendChildNode(std::make_unique()); - m_pPlayPosNode = static_cast(lastChild()); - m_pPlayPosNode->setGeometry(std::make_unique(TextureMaterial::attributes(), 6)); - m_pPlayPosNode->setMaterial(std::make_unique()); - m_pPlayPosNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + appendChildNode(std::make_unique()); + m_pRangeNodesParent = lastChild(); + + appendChildNode(std::make_unique()); + m_pMarkNodesParent = lastChild(); appendChildNode(std::make_unique()); m_pDigitsRenderNode = static_cast(lastChild()); + + appendChildNode(std::make_unique()); + m_pPlayPosNode = static_cast(lastChild()); + m_pPlayPosNode->initForRectangles(1); +} + +void allshader::WaveformRenderMark::draw(QPainter* painter, QPaintEvent* event) { + Q_UNUSED(painter); + Q_UNUSED(event); + DEBUG_ASSERT(false); } bool allshader::WaveformRenderMark::init() { @@ -92,10 +158,7 @@ bool allshader::WaveformRenderMark::init() { return true; } -void allshader::WaveformRenderMark::initializeGL() { - m_rgbaShader.init(); - m_textureShader.init(); - +void allshader::WaveformRenderMark::initialize() { // Will create textures so requires OpenGL context updateMarkImages(); updatePlayPosMarkTexture(); @@ -106,53 +169,10 @@ void allshader::WaveformRenderMark::initializeGL() { m_waveformRenderer->getDevicePixelRatio()); } -void allshader::WaveformRenderMark::drawTexture( - const QMatrix4x4& matrix, float x, float y, QOpenGLTexture* texture) { - const float devicePixelRatio = m_waveformRenderer->getDevicePixelRatio(); - const float texx1 = 0.f; - const float texy1 = 0.f; - const float texx2 = 1.f; - const float texy2 = 1.f; - - const float posx1 = x; - const float posx2 = x + static_cast(texture->width() / devicePixelRatio); - const float posy1 = y; - const float posy2 = y + static_cast(texture->height() / devicePixelRatio); - - const float posarray[] = {posx1, posy1, posx2, posy1, posx1, posy2, posx2, posy2}; - const float texarray[] = {texx1, texy1, texx2, texy1, texx1, texy2, texx2, texy2}; - - m_textureShader.bind(); - - const int matrixLocation = m_textureShader.uniformLocation("matrix"); - const int textureLocation = m_textureShader.uniformLocation("texture"); - const int positionLocation = m_textureShader.attributeLocation("position"); - const int texcoordLocation = m_textureShader.attributeLocation("texcoord"); - - m_textureShader.setUniformValue(matrixLocation, matrix); - - m_textureShader.enableAttributeArray(positionLocation); - m_textureShader.setAttributeArray( - positionLocation, GL_FLOAT, posarray, 2); - m_textureShader.enableAttributeArray(texcoordLocation); - m_textureShader.setAttributeArray( - texcoordLocation, GL_FLOAT, texarray, 2); - - m_textureShader.setUniformValue(textureLocation, 0); - - texture->bind(); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - texture->release(); - - m_textureShader.disableAttributeArray(positionLocation); - m_textureShader.disableAttributeArray(texcoordLocation); - m_textureShader.release(); -} - -void allshader::WaveformRenderMark::drawMark( - const QMatrix4x4& matrix, const QRectF& rect, QColor color) { +void allshader::WaveformRenderMark::updateRangeNode(GeometryNode* pNode, + const QMatrix4x4& matrix, + const QRectF& rect, + QColor color) { // draw a gradient towards transparency at the upper and lower 25% of the waveform view const float qh = static_cast(std::floor(rect.height() * 0.25)); @@ -167,43 +187,44 @@ void allshader::WaveformRenderMark::drawMark( getRgbF(color, &r, &g, &b, &a); - VertexData vertices; - vertices.reserve(12); // 4 triangles - vertices.addRectangle(posx1, posy1, posx2, posy2); - vertices.addRectangle(posx1, posy4, posx2, posy3); - - RGBAData rgbaData; - rgbaData.reserve(12); // 4 triangles - rgbaData.addForRectangleGradient(r, g, b, a, r, g, b, 0.f); - rgbaData.addForRectangleGradient(r, g, b, a, r, g, b, 0.f); - - m_rgbaShader.bind(); - - const int matrixLocation = m_rgbaShader.matrixLocation(); - const int positionLocation = m_rgbaShader.positionLocation(); - const int colorLocation = m_rgbaShader.colorLocation(); + RGBAVertexUpdater vertexUpdater{pNode->geometry().vertexDataAs()}; + vertexUpdater.addRectangleVGradient( + {posx1, posy1}, {posx2, posy2}, {r, g, b, a}, {r, g, b, 0.f}); + vertexUpdater.addRectangleVGradient( + {posx1, posy4}, {posx2, posy3}, {r, g, b, a}, {r, g, b, 0.f}); - m_rgbaShader.setUniformValue(matrixLocation, matrix); - - m_rgbaShader.enableAttributeArray(positionLocation); - m_rgbaShader.setAttributeArray( - positionLocation, GL_FLOAT, vertices.constData(), 2); - m_rgbaShader.enableAttributeArray(colorLocation); - m_rgbaShader.setAttributeArray( - colorLocation, GL_FLOAT, rgbaData.constData(), 4); - - glDrawArrays(GL_TRIANGLES, 0, vertices.size()); + pNode->material().setUniform(0, matrix); +} - m_rgbaShader.disableAttributeArray(positionLocation); - m_rgbaShader.disableAttributeArray(colorLocation); - m_rgbaShader.release(); +bool allshader::WaveformRenderMark::isSubtreeBlocked() const { + return m_isSlipRenderer && !m_waveformRenderer->isSlipActive(); } -void allshader::WaveformRenderMark::paintGL() { - if (m_isSlipRenderer && !m_waveformRenderer->isSlipActive()) { +void allshader::WaveformRenderMark::update() { + if (isSubtreeBlocked()) { return; } + // For each WaveformMark we create a GeometryNode with Texture + // (in updateMarkImage). Of these GeometryNodes, we append the + // the ones that need to be shown on screen as children to + // m_pMarkNodesParent (transferring ownership). + // + // At the beginning of a new frame, we remove all the child nodes + // from m_pMarkNodesParent and store each with their mark + // (transferring ownership). Later in this function we move the + // visible nodes back to m_pMarkNodesParent children. + while (auto pChild = m_pMarkNodesParent->firstChild()) { + // Pop child from front of m_pMarkNodesParent + auto pRemoved = m_pMarkNodesParent->removeChildNode(pChild); + // Determine its WaveformMark + auto pMarkNode = static_cast(pRemoved.get()); + auto pMark = pMarkNode->m_pOwner; + auto pGraphics = static_cast(pMark->m_pGraphics.get()); + // Store the node with the WaveformMark + pGraphics->setNode(std::move(pRemoved)); + } + auto positionType = m_isSlipRenderer ? ::WaveformRendererAbstract::Slip : ::WaveformRendererAbstract::Play; bool slipActive = m_waveformRenderer->isSlipActive(); @@ -211,14 +232,14 @@ void allshader::WaveformRenderMark::paintGL() { const float devicePixelRatio = m_waveformRenderer->getDevicePixelRatio(); QList marksOnScreen; - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - for (const auto& pMark : std::as_const(m_marks)) { pMark->setBreadth(slipActive ? m_waveformRenderer->getBreadth() / 2 : m_waveformRenderer->getBreadth()); } - // Will create textures so requires OpenGL context + + // Generate initial node or update its texture if needed for each of + // the WaveformMarks (in which case updateMarkImage is called) + // (Will create textures so requires OpenGL context) updateMarkImages(); QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); @@ -226,6 +247,8 @@ void allshader::WaveformRenderMark::paintGL() { const double playPosition = m_waveformRenderer->getTruePosSample(positionType); double nextMarkPosition = std::numeric_limits::max(); + Node* pRangeChild = m_pRangeNodesParent->firstChild(); + for (const auto& pMark : std::as_const(m_marks)) { if (!pMark->isValid()) { continue; @@ -237,13 +260,10 @@ void allshader::WaveformRenderMark::paintGL() { continue; } - QOpenGLTexture* pTexture = - static_cast(pMark->m_pGraphics.get()) - ->texture(); - - if (!pTexture) { + auto pMarkGraphics = pMark->m_pGraphics.get(); + auto pMarkNodeGraphics = static_cast(pMarkGraphics); + if (!pMarkGraphics) // is this even possible? continue; - } const float currentMarkPoint = std::round( @@ -263,7 +283,7 @@ void allshader::WaveformRenderMark::paintGL() { // Pixmaps are expected to have the mark stroke at the center, // and preferably have an odd width in order to have the stroke // exactly at the sample position. - const float markHalfWidth = pTexture->width() / devicePixelRatio / 2.f; + const float markHalfWidth = pMarkNodeGraphics->textureWidth() / devicePixelRatio / 2.f; const float drawOffset = currentMarkPoint - markHalfWidth; bool visible = false; @@ -271,12 +291,16 @@ void allshader::WaveformRenderMark::paintGL() { if (drawOffset > -markHalfWidth && drawOffset < m_waveformRenderer->getLength() + markHalfWidth) { - drawTexture(matrix, + pMarkNodeGraphics->update(matrix, drawOffset, !m_isSlipRenderer && slipActive ? m_waveformRenderer->getBreadth() / 2 : 0, - pTexture); + devicePixelRatio); + + // transfer back to m_pMarkNodesParent children, for rendering + pMarkNodeGraphics->moveNodeToChildrenOf(m_pMarkNodesParent); + visible = true; } @@ -293,13 +317,22 @@ void allshader::WaveformRenderMark::paintGL() { QColor color = pMark->fillColor(); color.setAlphaF(0.4f); - drawMark(matrix, + // Reuse, or create new when needed + if (!pRangeChild) { + m_pRangeNodesParent->appendChildNode(std::make_unique()); + pRangeChild = m_pRangeNodesParent->lastChild(); + static_cast(pRangeChild)->initForRectangles(2); + } + + updateRangeNode(static_cast(pRangeChild), + matrix, QRectF(QPointF(currentMarkPoint, 0), QPointF(currentMarkEndPoint, - m_waveformRenderer - ->getBreadth())), + m_waveformRenderer->getBreadth())), color); + visible = true; + pRangeChild = pRangeChild->nextSibling(); } } @@ -309,6 +342,14 @@ void allshader::WaveformRenderMark::paintGL() { pMark, static_cast(drawOffset)}); } } + + // Remove unused nodes + while (pRangeChild) { + auto pNext = static_cast(pRangeChild->nextSibling()); + m_pRangeNodesParent->removeChildNode(pRangeChild); + pRangeChild = pNext; + } + m_waveformRenderer->setMarkPositions(marksOnScreen); const float currentMarkPoint = @@ -327,14 +368,10 @@ void allshader::WaveformRenderMark::paintGL() { TexturedVertexUpdater vertexUpdater{ m_pPlayPosNode->geometry() .vertexDataAs()}; - vertexUpdater.addRectangle(drawOffset, - 0.f, - drawOffset + 11.f, - m_waveformRenderer->getBreadth(), - 0.f, - 0.f, - 1.f, - 1.f); + vertexUpdater.addRectangle({drawOffset, 0.f}, + {drawOffset + 11.f, static_cast(m_waveformRenderer->getBreadth())}, + {0.f, 0.f}, + {1.f, 1.f}); } if (WaveformWidgetFactory::instance()->getUntilMarkShowBeats() || @@ -356,6 +393,7 @@ void allshader::WaveformRenderMark::drawUntilMark(const QMatrix4x4& matrix, floa m_waveformRenderer->getDevicePixelRatio()); if (m_timeUntilMark == 0.0) { + m_pDigitsRenderNode->clear(); return; } const float ch = m_pDigitsRenderNode->height(); @@ -469,15 +507,22 @@ void allshader::WaveformRenderMark::drawTriangle(QPainter* painter, painter->fillPath(triangle, fillColor); } -void allshader::WaveformRenderMark::resizeGL(int, int) { +void allshader::WaveformRenderMark::resize() { // Will create textures so requires OpenGL context updateMarkImages(); updatePlayPosMarkTexture(); } void allshader::WaveformRenderMark::updateMarkImage(WaveformMarkPointer pMark) { - pMark->m_pGraphics = std::make_unique( - pMark->generateImage(m_waveformRenderer->getDevicePixelRatio())); + if (!pMark->m_pGraphics) { + pMark->m_pGraphics = + std::make_unique(pMark.get(), + pMark->generateImage( + m_waveformRenderer->getDevicePixelRatio())); + } else { + auto pGraphics = static_cast(pMark->m_pGraphics.get()); + pGraphics->updateTexture(pMark->generateImage(m_waveformRenderer->getDevicePixelRatio())); + } } void allshader::WaveformRenderMark::updateUntilMark( diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index c292dd31ee2..a4cbd3b47ad 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -2,10 +2,7 @@ #include -#include "rendergraph/opengl/openglnode.h" -#include "shaders/rgbashader.h" -#include "shaders/textureshader.h" -#include "util/opengltexture2d.h" +#include "rendergraph/node.h" #include "waveform/renderers/waveformrendermarkbase.h" class QDomNode; @@ -21,22 +18,23 @@ class WaveformRenderMark; } class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, - public rendergraph::OpenGLNode { + public rendergraph::Node { public: explicit WaveformRenderMark(WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type = ::WaveformRendererAbstract::Play); - void draw(QPainter* painter, QPaintEvent* event) override { - Q_UNUSED(painter); - Q_UNUSED(event); - } + // Pure virtual from WaveformRendererAbstract, not used + void draw(QPainter* painter, QPaintEvent* event) override final; bool init() override; - void initializeGL() override; - void paintGL() override; - void resizeGL(int w, int h) override; + void initialize(); + void resize(); + void update(); + + // Virtual for rendergraph::Node + bool isSubtreeBlocked() const override; private: void updateMarkImage(WaveformMarkPointer pMark) override; @@ -50,13 +48,14 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, QPointF p3); void drawMark(const QMatrix4x4& matrix, const QRectF& rect, QColor color); - void drawTexture(const QMatrix4x4& matrix, float x, float y, QOpenGLTexture* texture); void updateUntilMark(double playPosition, double markerPosition); void drawUntilMark(const QMatrix4x4& matrix, float x); float getMaxHeightForText() const; + void updateRangeNode(rendergraph::GeometryNode* pNode, + const QMatrix4x4& matrix, + const QRectF& rect, + QColor color); - mixxx::RGBAShader m_rgbaShader; - mixxx::TextureShader m_textureShader; int m_beatsUntilMark; double m_timeUntilMark; double m_currentBeatPosition; @@ -65,8 +64,10 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, bool m_isSlipRenderer; - DigitsRenderNode* m_pDigitsRenderNode; + rendergraph::Node* m_pRangeNodesParent{}; + rendergraph::Node* m_pMarkNodesParent{}; rendergraph::GeometryNode* m_pPlayPosNode; + DigitsRenderNode* m_pDigitsRenderNode{}; DISALLOW_COPY_AND_ASSIGN(WaveformRenderMark); }; diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index f85a3a63e9d..6821658c024 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -39,10 +39,10 @@ void WaveformRenderMarkRange::draw(QPainter* painter, QPaintEvent* event) { DEBUG_ASSERT(false); } -void WaveformRenderMarkRange::updateNode() { +void WaveformRenderMarkRange::update() { const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - GeometryNode* pChild = static_cast(firstChild()); + Node* pChild = firstChild(); for (const auto& markRange : m_markRanges) { // If the mark range is not active we should not draw it. @@ -77,31 +77,36 @@ void WaveformRenderMarkRange::updateNode() { color.setAlphaF(0.3f); if (!pChild) { - qDebug() << "Appended new node for mark range"; appendChildNode(std::make_unique()); - pChild = static_cast(lastChild()); - pChild->setGeometry(std::make_unique(UniColorMaterial::attributes(), 0)); - pChild->setMaterial(std::make_unique()); - pChild->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); - pChild->geometry().allocate(6); + pChild = lastChild(); + static_cast(pChild)->initForRectangles(1); } - VertexUpdater vertexUpdater{pChild->geometry().vertexDataAs()}; - vertexUpdater.addRectangle(static_cast(startPosition), - 0.f, - static_cast(endPosition) + 1.f, - m_waveformRenderer->getBreadth()); - pChild->material().setUniform(0, matrix); - pChild->material().setUniform(1, color); + updateNode(static_cast(pChild), + matrix, + color, + {static_cast(startPosition), 0.f}, + {static_cast(endPosition) + 1.f, + static_cast(m_waveformRenderer->getBreadth())}); pChild = static_cast(pChild->nextSibling()); } while (pChild) { - qDebug() << "Remove unused node for mark range"; - auto pNext = static_cast(pChild->nextSibling()); + auto pNext = pChild->nextSibling(); removeChildNode(pChild); pChild = pNext; } } +void WaveformRenderMarkRange::updateNode(GeometryNode* pChild, + const QMatrix4x4& matrix, + QColor color, + QVector2D lt, + QVector2D rb) { + VertexUpdater vertexUpdater{pChild->geometry().vertexDataAs()}; + vertexUpdater.addRectangle(lt, rb); + pChild->material().setUniform(0, matrix); + pChild->material().setUniform(1, color); +} + } // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.h b/src/waveform/renderers/allshader/waveformrendermarkrange.h index 3b2c64a7dd7..416f9fce03d 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.h +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.h @@ -1,6 +1,8 @@ #pragma once #include +#include +#include #include #include "rendergraph/node.h" @@ -11,6 +13,10 @@ class QDomNode; class SkinContext; +namespace rendergraph { +class GeometryNode; +} + namespace allshader { class WaveformRenderMarkRange; } @@ -25,9 +31,15 @@ class allshader::WaveformRenderMarkRange final : public ::WaveformRendererAbstra void setup(const QDomNode& node, const SkinContext& context) override; - void updateNode(); + void update(); private: + void updateNode(rendergraph::GeometryNode* pChild, + const QMatrix4x4& matrix, + QColor color, + QVector2D lt, + QVector2D rb); + std::vector m_markRanges; DISALLOW_COPY_AND_ASSIGN(WaveformRenderMarkRange); diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index 3d68a6e34c9..2666e70afb0 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -58,7 +58,8 @@ WaveformWidget::WaveformWidget(QWidget* parent, appendChildTo(pOpacityNode, waveformSignalRenderer); appendChildTo(pOpacityNode, addRenderer()); - appendChildTo(pOpacityNode, addRenderer()); + m_pWaveformRenderMark = addRenderer(); + appendChildTo(pOpacityNode, m_pWaveformRenderMark); // if the signal renderer supports slip, we add it again, now for slip, together with the // other slip renderers @@ -149,7 +150,8 @@ void WaveformWidget::paintGL() { // opacity of 0.f effectively skips the subtree rendering m_pOpacityNode->setOpacity(shouldOnlyDrawBackground() ? 0.f : 1.f); - m_pWaveformRenderMarkRange->updateNode(); + m_pWaveformRenderMark->update(); + m_pWaveformRenderMarkRange->update(); m_pGraph->preprocess(); m_pGraph->render(); @@ -161,10 +163,13 @@ void WaveformWidget::castToQWidget() { void WaveformWidget::initializeGL() { m_pGraph->initialize(); + m_pWaveformRenderMark->initialize(); } void WaveformWidget::resizeGL(int w, int h) { m_pGraph->resize(w, h); + + m_pWaveformRenderMark->resize(); } void WaveformWidget::paintEvent(QPaintEvent* event) { diff --git a/src/waveform/widgets/allshader/waveformwidget.h b/src/waveform/widgets/allshader/waveformwidget.h index 4aa82a0aa16..0ecf97822a2 100644 --- a/src/waveform/widgets/allshader/waveformwidget.h +++ b/src/waveform/widgets/allshader/waveformwidget.h @@ -9,6 +9,7 @@ namespace allshader { class WaveformWidget; +class WaveformRenderMark; class WaveformRenderMarkRange; } @@ -53,6 +54,7 @@ class allshader::WaveformWidget final : public ::WGLWidget, WaveformWidgetType::Type m_type; std::unique_ptr m_pGraph; rendergraph::OpacityNode* m_pOpacityNode; + WaveformRenderMark* m_pWaveformRenderMark; WaveformRenderMarkRange* m_pWaveformRenderMarkRange; DISALLOW_COPY_AND_ASSIGN(WaveformWidget); From a0df59e93929b4b2aa127f4a49e0f48b5639b495 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 1 Sep 2024 20:51:08 +0200 Subject: [PATCH 14/64] removed pimpl from rendergraph opengl --- .../material/endoftrackmaterial.cpp | 0 .../material/endoftrackmaterial.h | 0 .../rendergraph}/material/patternmaterial.cpp | 0 .../rendergraph}/material/patternmaterial.h | 0 .../rendergraph}/material/rgbamaterial.cpp | 0 .../rendergraph}/material/rgbamaterial.h | 0 .../rendergraph}/material/rgbmaterial.cpp | 0 .../rendergraph}/material/rgbmaterial.h | 0 .../rendergraph}/material/texturematerial.cpp | 0 .../rendergraph}/material/texturematerial.h | 0 .../material/unicolormaterial.cpp | 0 .../rendergraph}/material/unicolormaterial.h | 0 src/rendergraph/examples/CMakeLists.txt | 1 - .../examples/gl_example/CMakeLists.txt | 3 +- .../examples/gl_example/window.cpp | 2 +- .../examples/sg_example/CMakeLists.txt | 3 +- .../examples/sg_example/customitem.cpp | 2 +- src/rendergraph/opengl/CMakeLists.txt | 102 ++++++++--------- src/rendergraph/opengl/graph.cpp | 36 ------ src/rendergraph/opengl/openglnode.cpp | 15 --- .../opengl/private/attributeset_impl.h | 17 --- src/rendergraph/opengl/private/context_impl.h | 6 - .../opengl/private/geometry_impl.h | 87 -------------- .../opengl/private/geometrynode_impl.h | 35 ------ .../opengl/private/material_impl.h | 49 -------- .../opengl/private/materialshader_impl.h | 46 -------- .../opengl/private/materialtype_impl.h | 9 -- src/rendergraph/opengl/private/node_impl.h | 90 --------------- .../opengl/private/opacitynode_impl.h | 28 ----- .../opengl/private/openglnode_impl.h | 35 ------ src/rendergraph/opengl/private/texture_impl.h | 33 ------ .../{ => opengl/rendergraph}/attribute.h | 0 .../opengl/rendergraph/attributeset.cpp | 23 ++++ .../opengl/rendergraph/attributeset.h | 32 ++++++ .../opengl/rendergraph/context.cpp | 6 + src/rendergraph/opengl/rendergraph/context.h | 11 ++ .../rendergraph/examples/CMakeLists.txt | 11 ++ .../opengl/rendergraph/examples/README | 6 + .../examples/common/CMakeLists.txt | 0 .../examples/common/examplenodes.cpp | 60 ++++++++++ .../examples/common/examplenodes.h | 36 ++++++ .../examples/gl_example/CMakeLists.txt | 39 +++++++ .../examples/gl_example/images/test.png | Bin 0 -> 12849 bytes .../rendergraph/examples/gl_example/main.cpp | 12 ++ .../examples/gl_example/window.cpp | 48 ++++++++ .../rendergraph/examples/gl_example/window.h | 23 ++++ .../examples/sg_example/CMakeLists.txt | 35 ++++++ .../examples/sg_example/customitem.cpp | 59 ++++++++++ .../examples/sg_example/customitem.h | 26 +++++ .../examples/sg_example/images/test.png | Bin 0 -> 12849 bytes .../rendergraph/examples/sg_example/main.cpp | 16 +++ .../examples/sg_example/qml/main.qml | 13 +++ .../opengl/rendergraph/geometry.cpp | 94 +++++++++++++++ src/rendergraph/opengl/rendergraph/geometry.h | 81 +++++++++++++ .../geometrynode.cpp} | 48 ++++++-- .../opengl/rendergraph/geometrynode.h | 39 +++++++ src/rendergraph/opengl/rendergraph/graph.cpp | 81 +++++++++++++ .../opengl/{ => rendergraph}/graph.h | 7 +- .../opengl/rendergraph/material.cpp | 36 ++++++ src/rendergraph/opengl/rendergraph/material.h | 63 +++++++++++ .../material/endoftrackmaterial.cpp | 39 +++++++ .../rendergraph/material/endoftrackmaterial.h | 21 ++++ .../rendergraph/material/patternmaterial.cpp | 39 +++++++ .../rendergraph/material/patternmaterial.h | 34 ++++++ .../rendergraph/material/rgbamaterial.cpp | 39 +++++++ .../rendergraph/material/rgbamaterial.h | 21 ++++ .../rendergraph/material/rgbmaterial.cpp | 39 +++++++ .../opengl/rendergraph/material/rgbmaterial.h | 21 ++++ .../rendergraph/material/texturematerial.cpp | 39 +++++++ .../rendergraph/material/texturematerial.h | 34 ++++++ .../rendergraph/material/unicolormaterial.cpp | 39 +++++++ .../rendergraph/material/unicolormaterial.h | 21 ++++ .../materialshader.cpp} | 32 +++++- .../opengl/rendergraph/materialshader.h | 37 ++++++ .../opengl/rendergraph/materialtype.cpp | 6 + .../opengl/rendergraph/materialtype.h | 11 ++ src/rendergraph/opengl/rendergraph/node.cpp | 49 ++++++++ src/rendergraph/opengl/rendergraph/node.h | 74 ++++++++++++ .../opengl/rendergraph/opacitynode.cpp | 15 +++ .../opengl/rendergraph/opacitynode.h | 18 +++ .../opengl/rendergraph/openglnode.cpp | 22 ++++ .../opengl/{ => rendergraph}/openglnode.h | 8 +- .../opengl/{ => rendergraph}/shadercache.h | 0 .../opengl/rendergraph/texture.cpp | 29 +++++ src/rendergraph/opengl/rendergraph/texture.h | 23 ++++ src/rendergraph/opengl/rendergraph/types.cpp | 107 ++++++++++++++++++ src/rendergraph/opengl/rendergraph/types.h | 36 ++++++ .../{ => opengl/rendergraph}/uniform.h | 0 .../rendergraph}/uniformscache.cpp | 0 .../{ => opengl/rendergraph}/uniformscache.h | 0 .../{ => opengl/rendergraph}/uniformset.cpp | 0 .../{ => opengl/rendergraph}/uniformset.h | 0 src/rendergraph/scenegraph/CMakeLists.txt | 86 +++++++------- .../scenegraph/rendergraph/attribute.h | 31 +++++ .../rendergraph}/attributeset.cpp | 0 .../rendergraph}/attributeset.h | 0 .../{ => scenegraph/rendergraph}/context.cpp | 0 .../{ => scenegraph/rendergraph}/context.h | 0 .../{ => scenegraph/rendergraph}/geometry.cpp | 0 .../{ => scenegraph/rendergraph}/geometry.h | 0 .../rendergraph}/geometrynode.cpp | 0 .../rendergraph}/geometrynode.h | 0 .../{ => scenegraph/rendergraph}/material.cpp | 0 .../{ => scenegraph/rendergraph}/material.h | 0 .../rendergraph}/materialshader.cpp | 0 .../rendergraph}/materialshader.h | 0 .../rendergraph}/materialtype.cpp | 0 .../rendergraph}/materialtype.h | 0 .../{ => scenegraph/rendergraph}/node.cpp | 0 .../{ => scenegraph/rendergraph}/node.h | 0 .../rendergraph}/opacitynode.cpp | 0 .../rendergraph}/opacitynode.h | 0 .../{ => rendergraph}/scenegraph.cpp | 0 .../scenegraph/{ => rendergraph}/scenegraph.h | 0 .../{ => scenegraph/rendergraph}/texture.cpp | 0 .../{ => scenegraph/rendergraph}/texture.h | 0 .../{ => scenegraph/rendergraph}/types.cpp | 0 .../{ => scenegraph/rendergraph}/types.h | 0 .../scenegraph/rendergraph/uniform.h | 28 +++++ .../scenegraph/rendergraph/uniformscache.cpp | 28 +++++ .../scenegraph/rendergraph/uniformscache.h | 67 +++++++++++ .../scenegraph/rendergraph/uniformset.cpp | 20 ++++ .../scenegraph/rendergraph/uniformset.h | 30 +++++ .../renderers/allshader/waveformrenderer.h | 2 +- .../allshader/waveformrenderersignalbase.h | 2 +- .../allshader/waveformrendermark.cpp | 3 +- .../renderers/allshader/waveformrendermark.h | 4 +- .../widgets/allshader/waveformwidget.cpp | 5 +- .../widgets/allshader/waveformwidget.h | 2 +- 129 files changed, 2041 insertions(+), 624 deletions(-) rename src/rendergraph/{ => common/rendergraph}/material/endoftrackmaterial.cpp (100%) rename src/rendergraph/{ => common/rendergraph}/material/endoftrackmaterial.h (100%) rename src/rendergraph/{ => common/rendergraph}/material/patternmaterial.cpp (100%) rename src/rendergraph/{ => common/rendergraph}/material/patternmaterial.h (100%) rename src/rendergraph/{ => common/rendergraph}/material/rgbamaterial.cpp (100%) rename src/rendergraph/{ => common/rendergraph}/material/rgbamaterial.h (100%) rename src/rendergraph/{ => common/rendergraph}/material/rgbmaterial.cpp (100%) rename src/rendergraph/{ => common/rendergraph}/material/rgbmaterial.h (100%) rename src/rendergraph/{ => common/rendergraph}/material/texturematerial.cpp (100%) rename src/rendergraph/{ => common/rendergraph}/material/texturematerial.h (100%) rename src/rendergraph/{ => common/rendergraph}/material/unicolormaterial.cpp (100%) rename src/rendergraph/{ => common/rendergraph}/material/unicolormaterial.h (100%) delete mode 100644 src/rendergraph/opengl/graph.cpp delete mode 100644 src/rendergraph/opengl/openglnode.cpp delete mode 100644 src/rendergraph/opengl/private/attributeset_impl.h delete mode 100644 src/rendergraph/opengl/private/context_impl.h delete mode 100644 src/rendergraph/opengl/private/geometry_impl.h delete mode 100644 src/rendergraph/opengl/private/geometrynode_impl.h delete mode 100644 src/rendergraph/opengl/private/material_impl.h delete mode 100644 src/rendergraph/opengl/private/materialshader_impl.h delete mode 100644 src/rendergraph/opengl/private/materialtype_impl.h delete mode 100644 src/rendergraph/opengl/private/node_impl.h delete mode 100644 src/rendergraph/opengl/private/opacitynode_impl.h delete mode 100644 src/rendergraph/opengl/private/openglnode_impl.h delete mode 100644 src/rendergraph/opengl/private/texture_impl.h rename src/rendergraph/{ => opengl/rendergraph}/attribute.h (100%) create mode 100644 src/rendergraph/opengl/rendergraph/attributeset.cpp create mode 100644 src/rendergraph/opengl/rendergraph/attributeset.h create mode 100644 src/rendergraph/opengl/rendergraph/context.cpp create mode 100644 src/rendergraph/opengl/rendergraph/context.h create mode 100644 src/rendergraph/opengl/rendergraph/examples/CMakeLists.txt create mode 100644 src/rendergraph/opengl/rendergraph/examples/README rename src/rendergraph/{ => opengl/rendergraph}/examples/common/CMakeLists.txt (100%) create mode 100644 src/rendergraph/opengl/rendergraph/examples/common/examplenodes.cpp create mode 100644 src/rendergraph/opengl/rendergraph/examples/common/examplenodes.h create mode 100644 src/rendergraph/opengl/rendergraph/examples/gl_example/CMakeLists.txt create mode 100644 src/rendergraph/opengl/rendergraph/examples/gl_example/images/test.png create mode 100644 src/rendergraph/opengl/rendergraph/examples/gl_example/main.cpp create mode 100644 src/rendergraph/opengl/rendergraph/examples/gl_example/window.cpp create mode 100644 src/rendergraph/opengl/rendergraph/examples/gl_example/window.h create mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/CMakeLists.txt create mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.cpp create mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.h create mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/images/test.png create mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/main.cpp create mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/qml/main.qml create mode 100644 src/rendergraph/opengl/rendergraph/geometry.cpp create mode 100644 src/rendergraph/opengl/rendergraph/geometry.h rename src/rendergraph/opengl/{geometrynode_impl.cpp => rendergraph/geometrynode.cpp} (70%) create mode 100644 src/rendergraph/opengl/rendergraph/geometrynode.h create mode 100644 src/rendergraph/opengl/rendergraph/graph.cpp rename src/rendergraph/opengl/{ => rendergraph}/graph.h (73%) create mode 100644 src/rendergraph/opengl/rendergraph/material.cpp create mode 100644 src/rendergraph/opengl/rendergraph/material.h create mode 100644 src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.cpp create mode 100644 src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.h create mode 100644 src/rendergraph/opengl/rendergraph/material/patternmaterial.cpp create mode 100644 src/rendergraph/opengl/rendergraph/material/patternmaterial.h create mode 100644 src/rendergraph/opengl/rendergraph/material/rgbamaterial.cpp create mode 100644 src/rendergraph/opengl/rendergraph/material/rgbamaterial.h create mode 100644 src/rendergraph/opengl/rendergraph/material/rgbmaterial.cpp create mode 100644 src/rendergraph/opengl/rendergraph/material/rgbmaterial.h create mode 100644 src/rendergraph/opengl/rendergraph/material/texturematerial.cpp create mode 100644 src/rendergraph/opengl/rendergraph/material/texturematerial.h create mode 100644 src/rendergraph/opengl/rendergraph/material/unicolormaterial.cpp create mode 100644 src/rendergraph/opengl/rendergraph/material/unicolormaterial.h rename src/rendergraph/opengl/{materialshader_impl.cpp => rendergraph/materialshader.cpp} (50%) create mode 100644 src/rendergraph/opengl/rendergraph/materialshader.h create mode 100644 src/rendergraph/opengl/rendergraph/materialtype.cpp create mode 100644 src/rendergraph/opengl/rendergraph/materialtype.h create mode 100644 src/rendergraph/opengl/rendergraph/node.cpp create mode 100644 src/rendergraph/opengl/rendergraph/node.h create mode 100644 src/rendergraph/opengl/rendergraph/opacitynode.cpp create mode 100644 src/rendergraph/opengl/rendergraph/opacitynode.h create mode 100644 src/rendergraph/opengl/rendergraph/openglnode.cpp rename src/rendergraph/opengl/{ => rendergraph}/openglnode.h (79%) rename src/rendergraph/opengl/{ => rendergraph}/shadercache.h (100%) create mode 100644 src/rendergraph/opengl/rendergraph/texture.cpp create mode 100644 src/rendergraph/opengl/rendergraph/texture.h create mode 100644 src/rendergraph/opengl/rendergraph/types.cpp create mode 100644 src/rendergraph/opengl/rendergraph/types.h rename src/rendergraph/{ => opengl/rendergraph}/uniform.h (100%) rename src/rendergraph/{ => opengl/rendergraph}/uniformscache.cpp (100%) rename src/rendergraph/{ => opengl/rendergraph}/uniformscache.h (100%) rename src/rendergraph/{ => opengl/rendergraph}/uniformset.cpp (100%) rename src/rendergraph/{ => opengl/rendergraph}/uniformset.h (100%) create mode 100644 src/rendergraph/scenegraph/rendergraph/attribute.h rename src/rendergraph/{ => scenegraph/rendergraph}/attributeset.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/attributeset.h (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/context.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/context.h (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/geometry.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/geometry.h (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/geometrynode.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/geometrynode.h (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/material.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/material.h (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/materialshader.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/materialshader.h (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/materialtype.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/materialtype.h (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/node.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/node.h (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/opacitynode.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/opacitynode.h (100%) rename src/rendergraph/scenegraph/{ => rendergraph}/scenegraph.cpp (100%) rename src/rendergraph/scenegraph/{ => rendergraph}/scenegraph.h (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/texture.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/texture.h (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/types.cpp (100%) rename src/rendergraph/{ => scenegraph/rendergraph}/types.h (100%) create mode 100644 src/rendergraph/scenegraph/rendergraph/uniform.h create mode 100644 src/rendergraph/scenegraph/rendergraph/uniformscache.cpp create mode 100644 src/rendergraph/scenegraph/rendergraph/uniformscache.h create mode 100644 src/rendergraph/scenegraph/rendergraph/uniformset.cpp create mode 100644 src/rendergraph/scenegraph/rendergraph/uniformset.h diff --git a/src/rendergraph/material/endoftrackmaterial.cpp b/src/rendergraph/common/rendergraph/material/endoftrackmaterial.cpp similarity index 100% rename from src/rendergraph/material/endoftrackmaterial.cpp rename to src/rendergraph/common/rendergraph/material/endoftrackmaterial.cpp diff --git a/src/rendergraph/material/endoftrackmaterial.h b/src/rendergraph/common/rendergraph/material/endoftrackmaterial.h similarity index 100% rename from src/rendergraph/material/endoftrackmaterial.h rename to src/rendergraph/common/rendergraph/material/endoftrackmaterial.h diff --git a/src/rendergraph/material/patternmaterial.cpp b/src/rendergraph/common/rendergraph/material/patternmaterial.cpp similarity index 100% rename from src/rendergraph/material/patternmaterial.cpp rename to src/rendergraph/common/rendergraph/material/patternmaterial.cpp diff --git a/src/rendergraph/material/patternmaterial.h b/src/rendergraph/common/rendergraph/material/patternmaterial.h similarity index 100% rename from src/rendergraph/material/patternmaterial.h rename to src/rendergraph/common/rendergraph/material/patternmaterial.h diff --git a/src/rendergraph/material/rgbamaterial.cpp b/src/rendergraph/common/rendergraph/material/rgbamaterial.cpp similarity index 100% rename from src/rendergraph/material/rgbamaterial.cpp rename to src/rendergraph/common/rendergraph/material/rgbamaterial.cpp diff --git a/src/rendergraph/material/rgbamaterial.h b/src/rendergraph/common/rendergraph/material/rgbamaterial.h similarity index 100% rename from src/rendergraph/material/rgbamaterial.h rename to src/rendergraph/common/rendergraph/material/rgbamaterial.h diff --git a/src/rendergraph/material/rgbmaterial.cpp b/src/rendergraph/common/rendergraph/material/rgbmaterial.cpp similarity index 100% rename from src/rendergraph/material/rgbmaterial.cpp rename to src/rendergraph/common/rendergraph/material/rgbmaterial.cpp diff --git a/src/rendergraph/material/rgbmaterial.h b/src/rendergraph/common/rendergraph/material/rgbmaterial.h similarity index 100% rename from src/rendergraph/material/rgbmaterial.h rename to src/rendergraph/common/rendergraph/material/rgbmaterial.h diff --git a/src/rendergraph/material/texturematerial.cpp b/src/rendergraph/common/rendergraph/material/texturematerial.cpp similarity index 100% rename from src/rendergraph/material/texturematerial.cpp rename to src/rendergraph/common/rendergraph/material/texturematerial.cpp diff --git a/src/rendergraph/material/texturematerial.h b/src/rendergraph/common/rendergraph/material/texturematerial.h similarity index 100% rename from src/rendergraph/material/texturematerial.h rename to src/rendergraph/common/rendergraph/material/texturematerial.h diff --git a/src/rendergraph/material/unicolormaterial.cpp b/src/rendergraph/common/rendergraph/material/unicolormaterial.cpp similarity index 100% rename from src/rendergraph/material/unicolormaterial.cpp rename to src/rendergraph/common/rendergraph/material/unicolormaterial.cpp diff --git a/src/rendergraph/material/unicolormaterial.h b/src/rendergraph/common/rendergraph/material/unicolormaterial.h similarity index 100% rename from src/rendergraph/material/unicolormaterial.h rename to src/rendergraph/common/rendergraph/material/unicolormaterial.h diff --git a/src/rendergraph/examples/CMakeLists.txt b/src/rendergraph/examples/CMakeLists.txt index bd918d2f9ad..61ba086297f 100644 --- a/src/rendergraph/examples/CMakeLists.txt +++ b/src/rendergraph/examples/CMakeLists.txt @@ -8,4 +8,3 @@ qt_standard_project_setup() add_subdirectory(../ rendergraph) add_subdirectory(gl_example) add_subdirectory(sg_example) -add_subdirectory(common) diff --git a/src/rendergraph/examples/gl_example/CMakeLists.txt b/src/rendergraph/examples/gl_example/CMakeLists.txt index 30f6a547b88..6a055ea5560 100644 --- a/src/rendergraph/examples/gl_example/CMakeLists.txt +++ b/src/rendergraph/examples/gl_example/CMakeLists.txt @@ -3,6 +3,7 @@ find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL) qt_add_executable(gl_example window.cpp window.h main.cpp + ../common/examplenodes.cpp ) set_target_properties(gl_example PROPERTIES @@ -12,11 +13,11 @@ set_target_properties(gl_example PROPERTIES target_link_libraries(gl_example PRIVATE rendergraph_gl - rendergraph_examples Qt6::Core Qt6::Gui Qt6::OpenGL ) +target_include_directories(gl_example PRIVATE ../common) qt_add_resources(gl_example "gl_example" PREFIX diff --git a/src/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/examples/gl_example/window.cpp index 81bc0db439b..a74fc3afab3 100644 --- a/src/rendergraph/examples/gl_example/window.cpp +++ b/src/rendergraph/examples/gl_example/window.cpp @@ -2,7 +2,7 @@ #include "examplenodes.h" #include "rendergraph/context.h" -#include "rendergraph/opengl/graph.h" +#include "rendergraph/graph.h" Window::Window() { } diff --git a/src/rendergraph/examples/sg_example/CMakeLists.txt b/src/rendergraph/examples/sg_example/CMakeLists.txt index 096e131e47e..378e062fcf2 100644 --- a/src/rendergraph/examples/sg_example/CMakeLists.txt +++ b/src/rendergraph/examples/sg_example/CMakeLists.txt @@ -2,12 +2,13 @@ qt_add_executable(sg_example WIN32 MACOSX_BUNDLE customitem.cpp customitem.h main.cpp + ../common/examplenodes.cpp ) target_link_libraries(sg_example PRIVATE rendergraph_sg - rendergraph_examples ) +target_include_directories(sg_example PRIVATE ../common) qt_add_qml_module(sg_example URI RenderGraph diff --git a/src/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/examples/sg_example/customitem.cpp index fcf1f0feb07..bf87f780f17 100644 --- a/src/rendergraph/examples/sg_example/customitem.cpp +++ b/src/rendergraph/examples/sg_example/customitem.cpp @@ -8,7 +8,7 @@ #include "examplenodes.h" #include "rendergraph/context.h" -#include "rendergraph/scenegraph/scenegraph.h" +#include "rendergraph/scenegraph.h" CustomItem::CustomItem(QQuickItem* parent) : QQuickItem(parent) { diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index f87cbc1797b..5b8c9f81969 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -1,60 +1,48 @@ add_library(rendergraph_gl - ../attribute.h - ../attributeset.cpp - ../attributeset.h - ../context.cpp - ../context.h - ../geometry.cpp - ../geometry.h - ../geometrynode.cpp - ../geometrynode.h - ../material.cpp - ../material.h - ../materialshader.cpp - ../materialshader.h - ../materialtype.cpp - ../materialtype.h - ../node.cpp - ../node.h - ../opacitynode.cpp - ../opacitynode.h - ../texture.cpp - ../texture.h - ../types.cpp - ../types.h - ../uniform.h - ../uniformscache.cpp - ../uniformscache.h - ../uniformset.cpp - ../uniformset.h - ../material/endoftrackmaterial.cpp - ../material/endoftrackmaterial.h - ../material/patternmaterial.cpp - ../material/patternmaterial.h - ../material/texturematerial.cpp - ../material/texturematerial.h - ../material/rgbamaterial.cpp - ../material/rgbamaterial.h - ../material/rgbmaterial.cpp - ../material/rgbmaterial.h - ../material/unicolormaterial.cpp - ../material/unicolormaterial.h - geometrynode_impl.cpp - graph.cpp - graph.h - materialshader_impl.cpp - openglnode.cpp - openglnode.h - private/attributeset_impl.h - private/context_impl.h - private/geometry_impl.h - private/geometrynode_impl.h - private/material_impl.h - private/materialshader_impl.h - private/materialtype_impl.h - private/node_impl.h - private/opacitynode_impl.h - private/texture_impl.h + rendergraph/attribute.h + rendergraph/attributeset.cpp + rendergraph/attributeset.h + rendergraph/context.cpp + rendergraph/context.h + rendergraph/geometry.cpp + rendergraph/geometry.h + rendergraph/geometrynode.cpp + rendergraph/geometrynode.h + rendergraph/material.cpp + rendergraph/material.h + rendergraph/materialshader.cpp + rendergraph/materialshader.h + rendergraph/materialtype.cpp + rendergraph/materialtype.h + rendergraph/node.cpp + rendergraph/node.h + rendergraph/opacitynode.cpp + rendergraph/opacitynode.h + rendergraph/texture.cpp + rendergraph/texture.h + rendergraph/types.cpp + rendergraph/types.h + rendergraph/uniform.h + rendergraph/uniformscache.cpp + rendergraph/uniformscache.h + rendergraph/uniformset.cpp + rendergraph/uniformset.h + ../common/rendergraph/material/endoftrackmaterial.cpp + ../common/rendergraph/material/endoftrackmaterial.h + ../common/rendergraph/material/patternmaterial.cpp + ../common/rendergraph/material/patternmaterial.h + ../common/rendergraph/material/texturematerial.cpp + ../common/rendergraph/material/texturematerial.h + ../common/rendergraph/material/rgbamaterial.cpp + ../common/rendergraph/material/rgbamaterial.h + ../common/rendergraph/material/rgbmaterial.cpp + ../common/rendergraph/material/rgbmaterial.h + ../common/rendergraph/material/unicolormaterial.cpp + ../common/rendergraph/material/unicolormaterial.h + rendergraph/graph.cpp + rendergraph/graph.h + rendergraph/openglnode.cpp + rendergraph/openglnode.h ) target_link_libraries(rendergraph_gl PUBLIC @@ -63,4 +51,4 @@ target_link_libraries(rendergraph_gl PUBLIC Qt6::OpenGL ) -target_include_directories(rendergraph_gl PUBLIC ../.. PRIVATE private) +target_include_directories(rendergraph_gl PUBLIC . ../common) diff --git a/src/rendergraph/opengl/graph.cpp b/src/rendergraph/opengl/graph.cpp deleted file mode 100644 index 252f0ad7d87..00000000000 --- a/src/rendergraph/opengl/graph.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "rendergraph/opengl/graph.h" - -#include "rendergraph/node.h" -#include "rendergraph/opengl/private/node_impl.h" - -using namespace rendergraph; - -Graph::Graph(std::unique_ptr node) - : m_pTopNode(std::move(node)) { - m_pTopNode->impl().addToPreprocessNodes(&m_pPreprocessNodes); -} - -Graph::~Graph() = default; - -void Graph::initialize() { - m_pTopNode->impl().initialize(); -} - -void Graph::render() { - if (!m_pTopNode->impl().isSubtreeBlocked()) { - m_pTopNode->impl().initializeIfNeeded(); - m_pTopNode->impl().render(); - } -} - -void Graph::resize(int w, int h) { - m_pTopNode->impl().resize(w, h); -} - -void Graph::preprocess() { - for (auto pNode : m_pPreprocessNodes) { - if (!pNode->impl().isSubtreeBlocked()) { - pNode->preprocess(); - } - } -} diff --git a/src/rendergraph/opengl/openglnode.cpp b/src/rendergraph/opengl/openglnode.cpp deleted file mode 100644 index 5455ce79ab5..00000000000 --- a/src/rendergraph/opengl/openglnode.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "rendergraph/opengl/openglnode.h" - -#include "openglnode_impl.h" - -using namespace rendergraph; - -OpenGLNode::OpenGLNode(NodeImplBase* pImpl) - : Node(pImpl) { -} - -OpenGLNode::OpenGLNode() - : OpenGLNode(new OpenGLNode::Impl(this)) { -} - -OpenGLNode::~OpenGLNode() = default; diff --git a/src/rendergraph/opengl/private/attributeset_impl.h b/src/rendergraph/opengl/private/attributeset_impl.h deleted file mode 100644 index af6187da11a..00000000000 --- a/src/rendergraph/opengl/private/attributeset_impl.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "rendergraph/attributeset.h" - -class rendergraph::AttributeSet::Impl { - public: - void add(const Attribute& attribute) { - m_attributes.push_back(attribute); - } - - const std::vector& attributes() const { - return m_attributes; - } - - private: - std::vector m_attributes; -}; diff --git a/src/rendergraph/opengl/private/context_impl.h b/src/rendergraph/opengl/private/context_impl.h deleted file mode 100644 index e5afe9f870a..00000000000 --- a/src/rendergraph/opengl/private/context_impl.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "rendergraph/context.h" - -class rendergraph::Context::Impl { -}; diff --git a/src/rendergraph/opengl/private/geometry_impl.h b/src/rendergraph/opengl/private/geometry_impl.h deleted file mode 100644 index 75eff3b5a49..00000000000 --- a/src/rendergraph/opengl/private/geometry_impl.h +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once - -#include "attributeset_impl.h" -#include "rendergraph/geometry.h" - -class rendergraph::Geometry::Impl { - public: - Impl(const AttributeSet& attributeSet, int vertexCount) - : m_drawingMode(Geometry::DrawingMode::TriangleStrip) // to mimic sg default - , - m_vertexCount(vertexCount) { - int offset = 0; - for (const auto& attribute : attributeSet.impl().attributes()) { - m_offsets.push_back(offset); - offset += attribute.m_tupleSize; - m_tupleSizes.push_back(attribute.m_tupleSize); - } - m_stride = offset * sizeof(float); - m_data.resize(offset * vertexCount); - } - - void allocate(int vertexCount) { - m_vertexCount = vertexCount; - m_data.resize((m_stride / sizeof(float)) * m_vertexCount); - } - - int attributeCount() const { - return m_tupleSizes.size(); - } - - int vertexCount() const { - return m_vertexCount; - } - - float* vertexData() { - return m_data.data(); - } - - template - T* vertexDataAs() { - return reinterpret_cast(vertexData()); - } - - int offset(int attributeIndex) const { - return m_offsets[attributeIndex]; - } - - int tupleSize(int attributeIndex) const { - return m_tupleSizes[attributeIndex]; - } - - int stride() const { - return m_stride; - } - - void setAttributeValues(int attributePosition, const float* from, int numTuples) { - const int offset = m_offsets[attributePosition]; - const int tupleSize = m_tupleSizes[attributePosition]; - const int skip = m_stride / sizeof(float) - tupleSize; - - float* to = m_data.data(); - to += offset; - while (numTuples--) { - int k = tupleSize; - while (k--) { - *to++ = *from++; - } - to += skip; - } - } - - void setDrawingMode(Geometry::DrawingMode mode) { - m_drawingMode = mode; - } - - Geometry::DrawingMode drawingMode() const { - return m_drawingMode; - } - - private: - Geometry::DrawingMode m_drawingMode; - int m_vertexCount; - std::vector m_tupleSizes; - std::vector m_offsets; - int m_stride; - std::vector m_data; -}; diff --git a/src/rendergraph/opengl/private/geometrynode_impl.h b/src/rendergraph/opengl/private/geometrynode_impl.h deleted file mode 100644 index 2a3d1e74b5b..00000000000 --- a/src/rendergraph/opengl/private/geometrynode_impl.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include - -#include "material_impl.h" -#include "node_impl.h" -#include "rendergraph/geometrynode.h" -#include "rendergraph/opengl/shadercache.h" - -class rendergraph::GeometryNode::Impl : public rendergraph::Node::Impl, public QOpenGLFunctions { - public: - Impl(GeometryNode* pOwner) - : Node::Impl(pOwner) { - } - - void setGeometry(Geometry* geometry) { - m_pGeometry = geometry; - } - - void setMaterial(Material* material) { - m_pMaterial = material; - } - - void initialize() override { - initializeOpenGLFunctions(); - m_pMaterial->impl().setShader(ShaderCache::getShaderForMaterial(m_pMaterial)); - Node::Impl::initialize(); - } - - void render() override; - - private: - Geometry* m_pGeometry{}; - Material* m_pMaterial{}; -}; diff --git a/src/rendergraph/opengl/private/material_impl.h b/src/rendergraph/opengl/private/material_impl.h deleted file mode 100644 index 06aec895b55..00000000000 --- a/src/rendergraph/opengl/private/material_impl.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "materialshader_impl.h" -#include "rendergraph/material.h" -#include "rendergraph/opengl/shadercache.h" -#include "texture_impl.h" - -class rendergraph::Material::Impl { - public: - Impl(Material* pOwner) - : m_pOwner(pOwner) { - } - - ~Impl() { - m_pShader.reset(); - } - - void setShader(std::shared_ptr pShader) { - m_pShader = pShader; - } - - int attributeLocation(int attributeIndex) const { - return m_pShader->impl().attributeLocation(attributeIndex); - } - - QOpenGLTexture* texture(int binding) { - return m_pOwner->texture(binding)->impl().glTexture(); - } - - void modifyShader() { - m_pShader->impl().setLastModifiedByMaterial(m_pOwner); - } - - bool isLastModifierOfShader() const { - return m_pOwner == m_pShader->impl().lastModifiedByMaterial(); - } - - int uniformLocation(int uniformIndex) const { - return m_pShader->impl().uniformLocation(uniformIndex); - } - - QOpenGLShaderProgram& glShader() const { - return m_pShader->impl().glShader(); - } - - private: - std::shared_ptr m_pShader; - Material* const m_pOwner; -}; diff --git a/src/rendergraph/opengl/private/materialshader_impl.h b/src/rendergraph/opengl/private/materialshader_impl.h deleted file mode 100644 index 67e27a705e5..00000000000 --- a/src/rendergraph/opengl/private/materialshader_impl.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/materialshader.h" - -namespace rendergraph { -class Material; -} - -class rendergraph::MaterialShader::Impl : private QOpenGLShaderProgram { - public: - Impl(MaterialShader* pOwner, - const char* vertexShaderFile, - const char* fragmentShaderFile, - const UniformSet& uniformSet, - const AttributeSet& attributeSet); - - QOpenGLShaderProgram& glShader() { - return *this; - } - - int attributeLocation(int attributeIndex) const { - return m_attributeLocations[attributeIndex]; - } - - int uniformLocation(int uniformIndex) const { - return m_uniformLocations[uniformIndex]; - } - - Material* lastModifiedByMaterial() const { - return m_pLastModifiedByMaterial; - } - void setLastModifiedByMaterial(Material* pMaterial) { - m_pLastModifiedByMaterial = pMaterial; - } - - private: - static QString resource(const char* filename) { - return QString(":/shaders/rendergraph/") + QString(filename) + QString(".gl"); - } - MaterialShader* const m_pOwner; - std::vector m_attributeLocations; - std::vector m_uniformLocations; - Material* m_pLastModifiedByMaterial{}; -}; diff --git a/src/rendergraph/opengl/private/materialtype_impl.h b/src/rendergraph/opengl/private/materialtype_impl.h deleted file mode 100644 index 51dc3601df2..00000000000 --- a/src/rendergraph/opengl/private/materialtype_impl.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "rendergraph/materialtype.h" - -class rendergraph::MaterialType::Impl { - public: - Impl() { - } -}; diff --git a/src/rendergraph/opengl/private/node_impl.h b/src/rendergraph/opengl/private/node_impl.h deleted file mode 100644 index 6aae041848f..00000000000 --- a/src/rendergraph/opengl/private/node_impl.h +++ /dev/null @@ -1,90 +0,0 @@ -#pragma once - -#include -#include - -#include "rendergraph/node.h" - -class rendergraph::NodeImplBase { - public: - NodeImplBase(Node* pOwner) - : m_pOwner(pOwner) { - } - virtual ~NodeImplBase() = default; - - virtual void initialize() { - Node* pChild = m_pOwner->firstChild(); - while (pChild) { - pChild->impl().initialize(); - pChild = pChild->nextSibling(); - } - m_initialized = true; - } - - virtual void render() { - Node* pChild = m_pOwner->firstChild(); - while (pChild) { - if (!pChild->impl().isSubtreeBlocked()) { - pChild->impl().initializeIfNeeded(); - pChild->impl().render(); - } - pChild = pChild->nextSibling(); - } - } - - void initializeIfNeeded() { - if (!m_initialized) { - initialize(); - } - } - - virtual void resize(int w, int h) { - Node* pChild = m_pOwner->firstChild(); - while (pChild) { - pChild->impl().resize(w, h); - pChild = pChild->nextSibling(); - } - } - - virtual bool isSubtreeBlocked() const { - return m_pOwner->isSubtreeBlocked(); - } - - Node* owner() const { - return m_pOwner; - } - - void addToPreprocessNodes(std::vector* preprocessNodes) { - if (m_usePreprocess) { - preprocessNodes->push_back(m_pOwner); - } - Node* pChild = m_pOwner->firstChild(); - while (pChild) { - pChild->impl().addToPreprocessNodes(preprocessNodes); - pChild = pChild->nextSibling(); - } - } - - void setUsePreprocess(bool value) { - m_usePreprocess = value; - } - - void onAppendChildNode(Node*) { - } - void onRemoveChildNode(Node*) { - } - void onRemoveAllChildNodes() { - } - - private: - Node* const m_pOwner; - bool m_usePreprocess{}; - bool m_initialized{}; -}; - -class rendergraph::Node::Impl : public rendergraph::NodeImplBase { - public: - Impl(Node* pOwner) - : NodeImplBase(pOwner) { - } -}; diff --git a/src/rendergraph/opengl/private/opacitynode_impl.h b/src/rendergraph/opengl/private/opacitynode_impl.h deleted file mode 100644 index 6b4f36ec75d..00000000000 --- a/src/rendergraph/opengl/private/opacitynode_impl.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -#include "material_impl.h" -#include "node_impl.h" -#include "rendergraph/opacitynode.h" - -// TODO implement opacity of subnodes. -// For now we only use this for visibility, -// mimicking QSGOpacityNode isSubtreeBlocked() - -class rendergraph::OpacityNode::Impl : public rendergraph::NodeImplBase { - public: - Impl(OpacityNode* pOwner) - : NodeImplBase(pOwner) { - } - void setOpacity(float opacity) { - m_opacity = opacity; - } - - bool isSubtreeBlocked() const override { - return m_opacity == 0.f || NodeImplBase::isSubtreeBlocked(); - } - - private: - float m_opacity{1.f}; -}; diff --git a/src/rendergraph/opengl/private/openglnode_impl.h b/src/rendergraph/opengl/private/openglnode_impl.h deleted file mode 100644 index a6ea8f8a206..00000000000 --- a/src/rendergraph/opengl/private/openglnode_impl.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include "node_impl.h" -#include "rendergraph/opengl/openglnode.h" - -class rendergraph::OpenGLNode::Impl : public rendergraph::NodeImplBase { - public: - Impl(OpenGLNode* pOwner) - : NodeImplBase(pOwner) { - } - - ~Impl() { - } - - void initialize() override { - owner()->initializeOpenGLFunctions(); - owner()->initializeGL(); - NodeImplBase::initialize(); - } - - void render() override { - owner()->paintGL(); - NodeImplBase::render(); - } - - void resize(int w, int h) override { - owner()->resizeGL(w, h); - NodeImplBase::resize(w, h); - } - - private: - OpenGLNode* owner() const { - return static_cast(NodeImplBase::owner()); - } -}; diff --git a/src/rendergraph/opengl/private/texture_impl.h b/src/rendergraph/opengl/private/texture_impl.h deleted file mode 100644 index bb884585176..00000000000 --- a/src/rendergraph/opengl/private/texture_impl.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/texture.h" - -class rendergraph::Texture::Impl { - public: - Impl(Context& context, const QImage& image) - : m_pTexture(new QOpenGLTexture(premultiplyAlpha(image))) { - m_pTexture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); - m_pTexture->setWrapMode(QOpenGLTexture::ClampToEdge); - } - - QOpenGLTexture* glTexture() const { - return m_pTexture.get(); - } - - private: - const std::unique_ptr m_pTexture{}; - - static QImage premultiplyAlpha(const QImage& image) { - if (image.format() == QImage::Format_RGBA8888_Premultiplied) { - return QImage(image.bits(), image.width(), image.height(), QImage::Format_RGBA8888); - } - return QImage( - image.convertToFormat(QImage::Format_RGBA8888_Premultiplied) - .bits(), - image.width(), - image.height(), - QImage::Format_RGBA8888); - } -}; diff --git a/src/rendergraph/attribute.h b/src/rendergraph/opengl/rendergraph/attribute.h similarity index 100% rename from src/rendergraph/attribute.h rename to src/rendergraph/opengl/rendergraph/attribute.h diff --git a/src/rendergraph/opengl/rendergraph/attributeset.cpp b/src/rendergraph/opengl/rendergraph/attributeset.cpp new file mode 100644 index 00000000000..6ca9d378983 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/attributeset.cpp @@ -0,0 +1,23 @@ +#include "rendergraph/attributeset.h" + +using namespace rendergraph; + +AttributeSet::AttributeSet() = default; + +AttributeSet::AttributeSet(std::initializer_list list, const std::vector& names) + : AttributeSet() { + int i = 0; + for (auto item : list) { + add(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); + } +} + +AttributeSet::~AttributeSet() = default; + +void AttributeSet::add(const Attribute& attribute) { + m_attributes.push_back(attribute); +} + +const std::vector& AttributeSet::attributes() const { + return m_attributes; +} diff --git a/src/rendergraph/opengl/rendergraph/attributeset.h b/src/rendergraph/opengl/rendergraph/attributeset.h new file mode 100644 index 00000000000..8d21921ee5e --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/attributeset.h @@ -0,0 +1,32 @@ +#pragma once + +#include +#include + +#include "rendergraph/attribute.h" + +namespace rendergraph { +class AttributeSet; +} + +class rendergraph::AttributeSet { + public: + AttributeSet(); + AttributeSet(std::initializer_list list, const std::vector& names); + + ~AttributeSet(); + + const std::vector& attributes() const; + + private: + void add(const Attribute& attribute); + + std::vector m_attributes; +}; + +namespace rendergraph { +template +AttributeSet makeAttributeSet(const std::vector& names) { + return AttributeSet({(Attribute::create())...}, names); +} +} // namespace rendergraph diff --git a/src/rendergraph/opengl/rendergraph/context.cpp b/src/rendergraph/opengl/rendergraph/context.cpp new file mode 100644 index 00000000000..c795cd2b00b --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/context.cpp @@ -0,0 +1,6 @@ +#include "rendergraph/context.h" + +using namespace rendergraph; + +Context::Context() = default; +Context::~Context() = default; diff --git a/src/rendergraph/opengl/rendergraph/context.h b/src/rendergraph/opengl/rendergraph/context.h new file mode 100644 index 00000000000..99e7f8e0ec7 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/context.h @@ -0,0 +1,11 @@ +#pragma once + +namespace rendergraph { +class Context; +} + +class rendergraph::Context { + public: + Context(); + ~Context(); +}; diff --git a/src/rendergraph/opengl/rendergraph/examples/CMakeLists.txt b/src/rendergraph/opengl/rendergraph/examples/CMakeLists.txt new file mode 100644 index 00000000000..bd918d2f9ad --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.16) +project(rendergraph LANGUAGES CXX) + +find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick ShaderTools) + +qt_standard_project_setup() + +add_subdirectory(../ rendergraph) +add_subdirectory(gl_example) +add_subdirectory(sg_example) +add_subdirectory(common) diff --git a/src/rendergraph/opengl/rendergraph/examples/README b/src/rendergraph/opengl/rendergraph/examples/README new file mode 100644 index 00000000000..6168efc09c4 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/README @@ -0,0 +1,6 @@ +Build examples with + +$ cd ../../../ +$ mkdir build-rendergraph_examples +$ cd build-rendergraph_examples +$ cmake -DCMAKE_PREFIX_PATH=~/Qt/6.7.2/macos/ ../src/rendergraph/examples diff --git a/src/rendergraph/examples/common/CMakeLists.txt b/src/rendergraph/opengl/rendergraph/examples/common/CMakeLists.txt similarity index 100% rename from src/rendergraph/examples/common/CMakeLists.txt rename to src/rendergraph/opengl/rendergraph/examples/common/CMakeLists.txt diff --git a/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.cpp b/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.cpp new file mode 100644 index 00000000000..420bbae40ca --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.cpp @@ -0,0 +1,60 @@ +#include "examplenodes.h" + +#include +#include +#include + +#include "rendergraph/geometry.h" +#include "rendergraph/material/endoftrackmaterial.h" +#include "rendergraph/material/texturematerial.h" + +using namespace rendergraph; + +ExampleNode1::ExampleNode1() { + setMaterial(std::make_unique()); + setGeometry(std::make_unique(EndOfTrackMaterial::attributes(), 4)); + + geometry().setAttributeValues(0, positionArray, 4); + geometry().setAttributeValues(1, horizontalGradientArray, 4); + + QColor color("red"); + material().setUniform(0, + QVector4D{color.redF(), + color.greenF(), + color.blueF(), + color.alphaF()}); +} + +ExampleNode2::ExampleNode2() { + setMaterial(std::make_unique()); + setGeometry(std::make_unique(EndOfTrackMaterial::attributes(), 4)); + + geometry().setAttributeValues(0, positionArray, 4); + geometry().setAttributeValues(1, horizontalGradientArray, 4); + + QColor color("blue"); + material().setUniform(0, + QVector4D{color.redF(), + color.greenF(), + color.blueF(), + color.alphaF()}); +} + +ExampleNode3::ExampleNode3() { + auto* m = new TextureMaterial; + + setMaterial(std::make_unique()); + setGeometry(std::make_unique(TextureMaterial::attributes(), 4)); + + geometry().setAttributeValues(0, positionArray, 4); + geometry().setAttributeValues(1, texcoordArray, 4); + + QMatrix4x4 matrix; + + matrix.scale(0.3); + material().setUniform(0, matrix); +} + +void ExampleNode3::setTexture(std::unique_ptr texture) { + dynamic_cast(material()).setTexture(std::move(texture)); +} diff --git a/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.h b/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.h new file mode 100644 index 00000000000..1ff3d01fb44 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.h @@ -0,0 +1,36 @@ +#include "rendergraph/geometrynode.h" +#include "rendergraph/texture.h" + +namespace rendergraph { +class ExampleNode1; +class ExampleNode2; +class ExampleNode3; +} // namespace rendergraph + +class rendergraph::ExampleNode1 : public rendergraph::GeometryNode { + public: + static constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; + static constexpr float verticalGradientArray[] = {1.f, 1.f, -1.f, -1.f}; + static constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; + + ExampleNode1(); +}; + +class rendergraph::ExampleNode2 : public rendergraph::GeometryNode { + public: + static constexpr float positionArray[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f}; + static constexpr float verticalGradientArray[] = {1.f, 1.f, 0.f, 0.f}; + static constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; + + ExampleNode2(); +}; + +class rendergraph::ExampleNode3 : public rendergraph::GeometryNode { + public: + static constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; + static constexpr float texcoordArray[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f}; + + ExampleNode3(); + + void setTexture(std::unique_ptr texture); +}; diff --git a/src/rendergraph/opengl/rendergraph/examples/gl_example/CMakeLists.txt b/src/rendergraph/opengl/rendergraph/examples/gl_example/CMakeLists.txt new file mode 100644 index 00000000000..30f6a547b88 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/gl_example/CMakeLists.txt @@ -0,0 +1,39 @@ +find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL) + +qt_add_executable(gl_example + window.cpp window.h + main.cpp +) + +set_target_properties(gl_example PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) + +target_link_libraries(gl_example PRIVATE + rendergraph_gl + rendergraph_examples + Qt6::Core + Qt6::Gui + Qt6::OpenGL +) + +qt_add_resources(gl_example "gl_example" + PREFIX + /example + FILES + images/test.png +) + +install(TARGETS gl_example + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +qt_generate_deploy_app_script( + TARGET gl_example + OUTPUT_SCRIPT deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR +) +install(SCRIPT ${deploy_script}) diff --git a/src/rendergraph/opengl/rendergraph/examples/gl_example/images/test.png b/src/rendergraph/opengl/rendergraph/examples/gl_example/images/test.png new file mode 100644 index 0000000000000000000000000000000000000000..f9580346eb8b893f1d6acb3be80d2ee911bc20e5 GIT binary patch literal 12849 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 G4*q`+EtQY} literal 0 HcmV?d00001 diff --git a/src/rendergraph/opengl/rendergraph/examples/gl_example/main.cpp b/src/rendergraph/opengl/rendergraph/examples/gl_example/main.cpp new file mode 100644 index 00000000000..7b62238b429 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/gl_example/main.cpp @@ -0,0 +1,12 @@ +#include + +#include "window.h" + +int main(int argc, char* argv[]) { + QGuiApplication app(argc, argv); + + Window window; + window.show(); + + return app.exec(); +} diff --git a/src/rendergraph/opengl/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/opengl/rendergraph/examples/gl_example/window.cpp new file mode 100644 index 00000000000..81bc0db439b --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/gl_example/window.cpp @@ -0,0 +1,48 @@ +#include "window.h" + +#include "examplenodes.h" +#include "rendergraph/context.h" +#include "rendergraph/opengl/graph.h" + +Window::Window() { +} + +Window::~Window() = default; + +void Window::closeEvent(QCloseEvent*) { + // since this is the only and last window, we need to cleanup before destruction, + // because at destruction the context can't be used anymore + m_rendergraph.reset(); +} + +void Window::initializeGL() { + auto node = std::make_unique(); + node->appendChildNode(std::make_unique()); + node->appendChildNode(std::make_unique()); + node->appendChildNode(std::make_unique()); + + { + QImage img(":/example/images/test.png"); + rendergraph::Context context; + static_cast(node->lastChild()) + ->setTexture( + std::make_unique(context, img)); + } + + m_rendergraph = std::make_unique(std::move(node)); + m_rendergraph->initialize(); +} + +void Window::resizeGL(int, int) { +} + +void Window::paintGL() { + glClearColor(0.f, 0.f, 0.f, 1.f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_BLEND); + // qt scene graph uses premultiplied alpha color in the shader, + // so we need to do the same + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + + m_rendergraph->render(); +} diff --git a/src/rendergraph/opengl/rendergraph/examples/gl_example/window.h b/src/rendergraph/opengl/rendergraph/examples/gl_example/window.h new file mode 100644 index 00000000000..6d7d5f69749 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/gl_example/window.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +namespace rendergraph { +class Graph; +} + +class Window : public QOpenGLWindow { + public: + Window(); + ~Window(); + + void initializeGL() override; + void resizeGL(int w, int h) override; + void paintGL() override; + + void closeEvent(QCloseEvent* ev) override; + + private: + std::unique_ptr m_rendergraph; +}; diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/CMakeLists.txt b/src/rendergraph/opengl/rendergraph/examples/sg_example/CMakeLists.txt new file mode 100644 index 00000000000..096e131e47e --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/sg_example/CMakeLists.txt @@ -0,0 +1,35 @@ +qt_add_executable(sg_example WIN32 MACOSX_BUNDLE + customitem.cpp + customitem.h + main.cpp +) + +target_link_libraries(sg_example PRIVATE + rendergraph_sg + rendergraph_examples +) + +qt_add_qml_module(sg_example + URI RenderGraph + QML_FILES + qml/main.qml + RESOURCES + images/test.png + RESOURCE_PREFIX /example + NO_RESOURCE_TARGET_PATH +) + +install(TARGETS sg_example + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +qt_generate_deploy_qml_app_script( + TARGET sg_example + OUTPUT_SCRIPT deploy_script + MACOS_BUNDLE_POST_BUILD + NO_UNSUPPORTED_PLATFORM_ERROR + DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM +) +install(SCRIPT ${deploy_script}) diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.cpp new file mode 100644 index 00000000000..fcf1f0feb07 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.cpp @@ -0,0 +1,59 @@ +#include "customitem.h" + +#include +#include +#include +#include +#include + +#include "examplenodes.h" +#include "rendergraph/context.h" +#include "rendergraph/scenegraph/scenegraph.h" + +CustomItem::CustomItem(QQuickItem* parent) + : QQuickItem(parent) { + setFlag(ItemHasContents, true); +} + +CustomItem::~CustomItem() = default; + +void CustomItem::geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) { + m_geometryChanged = true; + update(); + QQuickItem::geometryChange(newGeometry, oldGeometry); +} + +QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { + QSGRectangleNode* bgNode; + if (!node) { + bgNode = window()->createRectangleNode(); + bgNode->setColor(QColor(0, 0, 0, 255)); + bgNode->setRect(boundingRect()); + + m_node = std::make_unique(); + m_node->appendChildNode(std::make_unique()); + m_node->appendChildNode(std::make_unique()); + m_node->appendChildNode(std::make_unique()); + + { + QImage img(":/example/images/test.png"); + auto context = rendergraph::createSgContext(window()); + static_cast(m_node->lastChild()) + ->setTexture(std::make_unique( + *context, img)); + } + + bgNode->appendChildNode(rendergraph::sgNode(m_node.get())); + + node = bgNode; + } else { + bgNode = static_cast(node); + } + + if (m_geometryChanged) { + bgNode->setRect(boundingRect()); + m_geometryChanged = false; + } + + return node; +} diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.h new file mode 100644 index 00000000000..304fb5c8f5e --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.h @@ -0,0 +1,26 @@ +#ifndef CUSTOMITEM_H +#define CUSTOMITEM_H + +#include + +namespace rendergraph { +class Node; +} + +class CustomItem : public QQuickItem { + Q_OBJECT + QML_ELEMENT + + public: + explicit CustomItem(QQuickItem* parent = nullptr); + ~CustomItem(); + + protected: + QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*) override; + void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override; + + bool m_geometryChanged{}; + std::unique_ptr m_node; +}; + +#endif // CUSTOMITEM_H diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/images/test.png b/src/rendergraph/opengl/rendergraph/examples/sg_example/images/test.png new file mode 100644 index 0000000000000000000000000000000000000000..f9580346eb8b893f1d6acb3be80d2ee911bc20e5 GIT binary patch literal 12849 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 G4*q`+EtQY} literal 0 HcmV?d00001 diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/main.cpp b/src/rendergraph/opengl/rendergraph/examples/sg_example/main.cpp new file mode 100644 index 00000000000..ab2e5b34072 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/sg_example/main.cpp @@ -0,0 +1,16 @@ +#include +#include +#include + +#include "customitem.h" + +int main(int argc, char** argv) { + QGuiApplication app(argc, argv); + + QQuickView view; + view.setResizeMode(QQuickView::SizeRootObjectToView); + view.setSource(QUrl("qrc:///example/qml/main.qml")); + view.show(); + + return app.exec(); +} diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/qml/main.qml b/src/rendergraph/opengl/rendergraph/examples/sg_example/qml/main.qml new file mode 100644 index 00000000000..2410ad1a560 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/examples/sg_example/qml/main.qml @@ -0,0 +1,13 @@ +import QtQuick +import RenderGraph + +Item { + id: root + + width: 640 + height: 480 + + CustomItem { + anchors.fill: parent + } +} diff --git a/src/rendergraph/opengl/rendergraph/geometry.cpp b/src/rendergraph/opengl/rendergraph/geometry.cpp new file mode 100644 index 00000000000..c098f476e11 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/geometry.cpp @@ -0,0 +1,94 @@ +#include "rendergraph/geometry.h" + +#include "rendergraph/attributeset.h" + +using namespace rendergraph; + +Geometry::Geometry(const AttributeSet& attributeSet, int vertexCount) + : m_drawingMode(Geometry::DrawingMode::TriangleStrip) // to mimic sg default + , + m_vertexCount(vertexCount) { + int offset = 0; + for (const auto& attribute : attributeSet.attributes()) { + m_offsets.push_back(offset); + offset += attribute.m_tupleSize; + m_tupleSizes.push_back(attribute.m_tupleSize); + } + m_stride = offset * sizeof(float); + m_data.resize(offset * vertexCount); +} + +Geometry::~Geometry() = default; + +void Geometry::setAttributeValues(int attributePosition, const float* from, int numTuples) { + const int offset = m_offsets[attributePosition]; + const int tupleSize = m_tupleSizes[attributePosition]; + const int skip = m_stride / sizeof(float) - tupleSize; + + float* to = m_data.data(); + to += offset; + while (numTuples--) { + int k = tupleSize; + while (k--) { + *to++ = *from++; + } + to += skip; + } +} + +float* Geometry::vertexData() { + return m_data.data(); +} + +template +T* Geometry::vertexDataAs() { + return reinterpret_cast(vertexData()); +} + +template Geometry::Point2D* Geometry::vertexDataAs(); + +template Geometry::TexturedPoint2D* Geometry::vertexDataAs(); + +template Geometry::RGBColoredPoint2D* Geometry::vertexDataAs(); + +template Geometry::RGBAColoredPoint2D* Geometry::vertexDataAs(); + +void Geometry::allocate(int vertexCount) { + m_vertexCount = vertexCount; + m_data.resize((m_stride / sizeof(float)) * m_vertexCount); +} + +void Geometry::setDrawingMode(Geometry::DrawingMode mode) { + m_drawingMode = mode; +} + +Geometry::DrawingMode Geometry::drawingMode() const { + return m_drawingMode; +} + +int Geometry::attributeCount() const { + return m_tupleSizes.size(); +} + +int Geometry::vertexCount() const { + return m_vertexCount; +} + +int Geometry::offset(int attributeIndex) const { + return m_offsets[attributeIndex]; +} + +int Geometry::tupleSize(int attributeIndex) const { + return m_tupleSizes[attributeIndex]; +} + +int Geometry::stride() const { + return m_stride; +} + +Geometry::DrawingMode m_drawingMode; +int m_vertexCount; +std::vector m_tupleSizes; +std::vector m_offsets; +int m_stride; +std::vector m_data; diff --git a/src/rendergraph/opengl/rendergraph/geometry.h b/src/rendergraph/opengl/rendergraph/geometry.h new file mode 100644 index 00000000000..a4fdf2fa90c --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/geometry.h @@ -0,0 +1,81 @@ +#pragma once + +#include + +#include "rendergraph/types.h" + +namespace rendergraph { +class Geometry; +class AttributeSet; +} // namespace rendergraph + +class rendergraph::Geometry { + public: + struct Point2D { + QVector2D position2D; + Point2D(float x, float y) + : position2D{x, y} { + } + }; + + struct TexturedPoint2D { + QVector2D position2D; + QVector2D texcoord2D; + TexturedPoint2D(float x, float y, float tx, float ty) + : position2D{x, y}, + texcoord2D{tx, ty} { + } + }; + + struct RGBColoredPoint2D { + QVector2D position2D; + QVector3D color3D; + RGBColoredPoint2D(float x, float y, float r, float g, float b) + : position2D{x, y}, + color3D{r, g, b} { + } + }; + + struct RGBAColoredPoint2D { + QVector2D position2D; + QVector4D color4D; + RGBAColoredPoint2D(float x, float y, float r, float g, float b, float a) + : position2D{x, y}, + color4D{r, g, b, a} { + } + }; + + enum class DrawingMode { + Triangles, + TriangleStrip + }; + + Geometry(const AttributeSet& attributeSet, int vertexCount); + ~Geometry(); + + void allocate(int vertexCount); + + void setAttributeValues(int attributePosition, const float* data, int numTuples); + + float* vertexData(); + + template + T* vertexDataAs(); + + DrawingMode drawingMode() const; + void setDrawingMode(DrawingMode mode); + + int attributeCount() const; + int vertexCount() const; + int offset(int attributeIndex) const; + int tupleSize(int attributeIndex) const; + int stride() const; + + private: + DrawingMode m_drawingMode; + int m_vertexCount; + std::vector m_tupleSizes; + std::vector m_offsets; + int m_stride; + std::vector m_data; +}; diff --git a/src/rendergraph/opengl/geometrynode_impl.cpp b/src/rendergraph/opengl/rendergraph/geometrynode.cpp similarity index 70% rename from src/rendergraph/opengl/geometrynode_impl.cpp rename to src/rendergraph/opengl/rendergraph/geometrynode.cpp index 7c753c7a494..67df96e4d11 100644 --- a/src/rendergraph/opengl/geometrynode_impl.cpp +++ b/src/rendergraph/opengl/rendergraph/geometrynode.cpp @@ -1,9 +1,38 @@ -#include "geometrynode_impl.h" +#include "rendergraph/geometrynode.h" -#include "geometry_impl.h" +#include + +#include "rendergraph/shadercache.h" +#include "rendergraph/texture.h" using namespace rendergraph; +GeometryNode::GeometryNode() = default; + +GeometryNode::~GeometryNode() = default; + +void GeometryNode::setGeometry(std::unique_ptr pGeometry) { + m_pGeometry = std::move(pGeometry); +} + +void GeometryNode::setMaterial(std::unique_ptr pMaterial) { + m_pMaterial = std::move(pMaterial); +} + +Geometry& GeometryNode::geometry() const { + return *m_pGeometry; +} + +Material& GeometryNode::material() const { + return *m_pMaterial; +} + +void GeometryNode::initialize() { + initializeOpenGLFunctions(); + m_pMaterial->setShader(ShaderCache::getShaderForMaterial(m_pMaterial.get())); + Node::initialize(); +} + namespace { GLenum toGlDrawingMode(Geometry::DrawingMode mode) { switch (mode) { @@ -15,21 +44,20 @@ GLenum toGlDrawingMode(Geometry::DrawingMode mode) { } } // namespace -void GeometryNode::Impl::render() { - Geometry::Impl& geometry = m_pGeometry->impl(); +void GeometryNode::render() { + Geometry& geometry = *m_pGeometry; + Material& material = *m_pMaterial; if (geometry.vertexCount() == 0) { return; } - Material::Impl& material = m_pMaterial->impl(); - glEnable(GL_BLEND); // qt scene graph uses premultiplied alpha color in the shader, // so we need to do the same glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - QOpenGLShaderProgram& shader = material.glShader(); + QOpenGLShaderProgram& shader = material.shader(); shader.bind(); if (m_pMaterial->clearUniformsCacheDirty() || !material.isLastModifierOfShader()) { @@ -72,13 +100,13 @@ void GeometryNode::Impl::render() { // TODO multiple textures auto pTexture = m_pMaterial->texture(1); if (pTexture) { - pTexture->impl().glTexture()->bind(); + pTexture->glTexture()->bind(); } glDrawArrays(toGlDrawingMode(geometry.drawingMode()), 0, geometry.vertexCount()); if (pTexture) { - pTexture->impl().glTexture()->release(); + pTexture->glTexture()->release(); } for (int i = 0; i < geometry.attributeCount(); i++) { @@ -88,5 +116,5 @@ void GeometryNode::Impl::render() { shader.release(); - Node::Impl::render(); + Node::render(); } diff --git a/src/rendergraph/opengl/rendergraph/geometrynode.h b/src/rendergraph/opengl/rendergraph/geometrynode.h new file mode 100644 index 00000000000..4804f123d93 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/geometrynode.h @@ -0,0 +1,39 @@ +#pragma once + +#include + +#include "rendergraph/geometry.h" +#include "rendergraph/material.h" +#include "rendergraph/node.h" + +namespace rendergraph { +class GeometryNode; +class Material; +} // namespace rendergraph + +class rendergraph::GeometryNode : public rendergraph::Node, public QOpenGLFunctions { + public: + GeometryNode(); + ~GeometryNode(); + + template + void initForRectangles(int numRectangles) { + const int verticesPerRectangle = 6; // 2 rectangles + setGeometry(std::make_unique(T_Material::attributes(), + numRectangles * verticesPerRectangle)); + setMaterial(std::make_unique()); + geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + } + + void initialize() override; + void render() override; + + void setMaterial(std::unique_ptr material); + void setGeometry(std::unique_ptr geometry); + Geometry& geometry() const; + Material& material() const; + + private: + std::unique_ptr m_pMaterial; + std::unique_ptr m_pGeometry; +}; diff --git a/src/rendergraph/opengl/rendergraph/graph.cpp b/src/rendergraph/opengl/rendergraph/graph.cpp new file mode 100644 index 00000000000..cbb61e9e45a --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/graph.cpp @@ -0,0 +1,81 @@ +#include "rendergraph/graph.h" + +#include + +#include "rendergraph/node.h" + +using namespace rendergraph; + +Graph::Graph(std::unique_ptr node) + : m_pTopNode(std::move(node)) { + if (m_pTopNode->graph() != this) { + addToGraph(m_pTopNode.get()); + } +} + +Graph::~Graph() = default; + +void Graph::initialize() { + for (auto pNode : m_pInitializeNodes) { + pNode->initialize(); + } + m_pInitializeNodes.clear(); +} + +void Graph::render() { + if (!m_pInitializeNodes.empty()) { + initialize(); + } + if (!m_pTopNode->isSubtreeBlocked()) { + render(m_pTopNode.get()); + } +} + +void Graph::resize(int w, int h) { + resize(m_pTopNode.get(), w, h); +} + +void Graph::preprocess() { + for (auto pNode : m_pPreprocessNodes) { + if (!pNode->isSubtreeBlocked()) { + pNode->preprocess(); + } + } +} + +void Graph::render(Node* pNode) { + pNode->render(); + pNode = pNode->firstChild(); + while (pNode) { + if (!pNode->isSubtreeBlocked()) { + render(pNode); + } + pNode = pNode->nextSibling(); + } +} + +void Graph::resize(Node* pNode, int w, int h) { + pNode->resize(w, h); + pNode = pNode->firstChild(); + while (pNode) { + resize(pNode, w, h); + pNode = pNode->nextSibling(); + } +} + +void Graph::addToGraph(Node* pNode) { + assert(pNode->graph() == nullptr); + + pNode->setGraph(this); + m_pInitializeNodes.push_back(pNode); + if (pNode->usePreprocess()) { + m_pPreprocessNodes.push_back(pNode); + } + pNode = pNode->firstChild(); + while (pNode) { + if (pNode->graph() != this) { + addToGraph(pNode); + } + pNode = pNode->nextSibling(); + } +} diff --git a/src/rendergraph/opengl/graph.h b/src/rendergraph/opengl/rendergraph/graph.h similarity index 73% rename from src/rendergraph/opengl/graph.h rename to src/rendergraph/opengl/rendergraph/graph.h index 538035aef81..e5179fdde78 100644 --- a/src/rendergraph/opengl/graph.h +++ b/src/rendergraph/opengl/rendergraph/graph.h @@ -10,16 +10,19 @@ class Node; class rendergraph::Graph { public: - class Impl; Graph(std::unique_ptr node); ~Graph(); - Impl& impl() const; void initialize(); void render(); void resize(int w, int h); void preprocess(); + void addToGraph(Node* pNode); private: + void render(Node* pNode); + void resize(Node* pNode, int, int h); + const std::unique_ptr m_pTopNode; std::vector m_pPreprocessNodes; + std::vector m_pInitializeNodes; }; diff --git a/src/rendergraph/opengl/rendergraph/material.cpp b/src/rendergraph/opengl/rendergraph/material.cpp new file mode 100644 index 00000000000..6c525b1ebf5 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material.cpp @@ -0,0 +1,36 @@ +#include "rendergraph/material.h" + +#include "rendergraph/shadercache.h" +#include "rendergraph/texture.h" + +using namespace rendergraph; + +Material::Material(const UniformSet& uniformSet) + : m_uniformsCache(uniformSet) { +} + +Material::~Material() = default; + +void Material::setShader(std::shared_ptr pShader) { + m_pShader = pShader; +} + +MaterialShader& Material::shader() const { + return *m_pShader; +} + +int Material::uniformLocation(int uniformIndex) const { + return m_pShader->uniformLocation(uniformIndex); +} + +int Material::attributeLocation(int attributeIndex) const { + return m_pShader->attributeLocation(attributeIndex); +} + +void Material::modifyShader() { + m_pShader->setLastModifiedByMaterial(this); +} + +bool Material::isLastModifierOfShader() const { + return this == m_pShader->lastModifiedByMaterial(); +} diff --git a/src/rendergraph/opengl/rendergraph/material.h b/src/rendergraph/opengl/rendergraph/material.h new file mode 100644 index 00000000000..8c54be251e2 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material.h @@ -0,0 +1,63 @@ +#pragma once + +#include + +#include "rendergraph/uniformscache.h" + +namespace rendergraph { +class UniformSet; +class Material; +class MaterialShader; +class MaterialType; +class Texture; +class GeometryNode; +} // namespace rendergraph + +class rendergraph::Material { + public: + Material(const UniformSet& uniformSet); + virtual ~Material(); + virtual int compare(const Material* other) const = 0; + virtual std::unique_ptr createShader() const = 0; + virtual MaterialType* type() const = 0; + + template + void setUniform(int uniformIndex, const T& value) { + m_uniformsCache.set(uniformIndex, value); + m_uniformsCacheDirty = true; + } + + void setShader(std::shared_ptr pShader); + + MaterialShader& shader() const; + + int uniformLocation(int uniformIndex) const; + int attributeLocation(int attributeIndex) const; + + private: + friend MaterialShader; + friend GeometryNode; + + void modifyShader(); + bool isLastModifierOfShader() const; + + const UniformsCache& uniformsCache() const { + return m_uniformsCache; + } + + bool clearUniformsCacheDirty() { + if (m_uniformsCacheDirty) { + m_uniformsCacheDirty = false; + return true; + } + return false; + } + + virtual Texture* texture(int /*binding*/) const { + return nullptr; + } + + std::shared_ptr m_pShader; + UniformsCache m_uniformsCache; + bool m_uniformsCacheDirty{}; +}; diff --git a/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.cpp b/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.cpp new file mode 100644 index 00000000000..fd9e5f73ec7 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.cpp @@ -0,0 +1,39 @@ +#include "endoftrackmaterial.h" + +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +EndOfTrackMaterial::EndOfTrackMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& EndOfTrackMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "gradient"}); + return set; +} + +/* static */ const UniformSet& EndOfTrackMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.color"}); + return set; +} + +MaterialType* EndOfTrackMaterial::type() const { + static MaterialType type; + return &type; +} + +int EndOfTrackMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +std::unique_ptr EndOfTrackMaterial::createShader() const { + return std::make_unique( + "endoftrack.vert", "endoftrack.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.h b/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.h new file mode 100644 index 00000000000..e66a825c164 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.h @@ -0,0 +1,21 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" + +namespace rendergraph { +class EndOfTrackMaterial; +} + +class rendergraph::EndOfTrackMaterial : public rendergraph::Material { + public: + EndOfTrackMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + std::unique_ptr createShader() const override; +}; diff --git a/src/rendergraph/opengl/rendergraph/material/patternmaterial.cpp b/src/rendergraph/opengl/rendergraph/material/patternmaterial.cpp new file mode 100644 index 00000000000..e16ca4213d7 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/patternmaterial.cpp @@ -0,0 +1,39 @@ +#include "patternmaterial.h" + +#include +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" + +using namespace rendergraph; + +PatternMaterial::PatternMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& PatternMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "texcoord"}); + return set; +} + +/* static */ const UniformSet& PatternMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.matrix"}); + return set; +} + +MaterialType* PatternMaterial::type() const { + static MaterialType type; + return &type; +} + +int PatternMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +std::unique_ptr PatternMaterial::createShader() const { + return std::make_unique( + "pattern.vert", "pattern.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/opengl/rendergraph/material/patternmaterial.h b/src/rendergraph/opengl/rendergraph/material/patternmaterial.h new file mode 100644 index 00000000000..0df75c07371 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/patternmaterial.h @@ -0,0 +1,34 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" +#include "rendergraph/texture.h" +#include "rendergraph/uniformset.h" + +namespace rendergraph { +class PatternMaterial; +} + +class rendergraph::PatternMaterial : public rendergraph::Material { + public: + PatternMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + std::unique_ptr createShader() const override; + + Texture* texture(int /*binding*/) const override { + return m_pTexture.get(); + } + + void setTexture(std::unique_ptr texture) { + m_pTexture = std::move(texture); + } + + private: + std::unique_ptr m_pTexture; +}; diff --git a/src/rendergraph/opengl/rendergraph/material/rgbamaterial.cpp b/src/rendergraph/opengl/rendergraph/material/rgbamaterial.cpp new file mode 100644 index 00000000000..c1d53d3f8bc --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/rgbamaterial.cpp @@ -0,0 +1,39 @@ +#include "rgbamaterial.h" + +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +RGBAMaterial::RGBAMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& RGBAMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "color"}); + return set; +} + +/* static */ const UniformSet& RGBAMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.matrix"}); + return set; +} + +MaterialType* RGBAMaterial::type() const { + static MaterialType type; + return &type; +} + +int RGBAMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +std::unique_ptr RGBAMaterial::createShader() const { + return std::make_unique( + "rgba.vert", "rgba.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/opengl/rendergraph/material/rgbamaterial.h b/src/rendergraph/opengl/rendergraph/material/rgbamaterial.h new file mode 100644 index 00000000000..b5b72a949c9 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/rgbamaterial.h @@ -0,0 +1,21 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" + +namespace rendergraph { +class RGBAMaterial; +} + +class rendergraph::RGBAMaterial : public rendergraph::Material { + public: + RGBAMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + std::unique_ptr createShader() const override; +}; diff --git a/src/rendergraph/opengl/rendergraph/material/rgbmaterial.cpp b/src/rendergraph/opengl/rendergraph/material/rgbmaterial.cpp new file mode 100644 index 00000000000..3a2f014d07e --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/rgbmaterial.cpp @@ -0,0 +1,39 @@ +#include "rgbmaterial.h" + +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +RGBMaterial::RGBMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& RGBMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "color"}); + return set; +} + +/* static */ const UniformSet& RGBMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.matrix"}); + return set; +} + +MaterialType* RGBMaterial::type() const { + static MaterialType type; + return &type; +} + +int RGBMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +std::unique_ptr RGBMaterial::createShader() const { + return std::make_unique( + "rgb.vert", "rgb.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/opengl/rendergraph/material/rgbmaterial.h b/src/rendergraph/opengl/rendergraph/material/rgbmaterial.h new file mode 100644 index 00000000000..6d4d74b2514 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/rgbmaterial.h @@ -0,0 +1,21 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" + +namespace rendergraph { +class RGBMaterial; +} + +class rendergraph::RGBMaterial : public rendergraph::Material { + public: + RGBMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + std::unique_ptr createShader() const override; +}; diff --git a/src/rendergraph/opengl/rendergraph/material/texturematerial.cpp b/src/rendergraph/opengl/rendergraph/material/texturematerial.cpp new file mode 100644 index 00000000000..090e6070d98 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/texturematerial.cpp @@ -0,0 +1,39 @@ +#include "texturematerial.h" + +#include +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" + +using namespace rendergraph; + +TextureMaterial::TextureMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& TextureMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position", "texcoord"}); + return set; +} + +/* static */ const UniformSet& TextureMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.matrix"}); + return set; +} + +MaterialType* TextureMaterial::type() const { + static MaterialType type; + return &type; +} + +int TextureMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +std::unique_ptr TextureMaterial::createShader() const { + return std::make_unique( + "texture.vert", "texture.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/opengl/rendergraph/material/texturematerial.h b/src/rendergraph/opengl/rendergraph/material/texturematerial.h new file mode 100644 index 00000000000..4e0ac39b989 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/texturematerial.h @@ -0,0 +1,34 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" +#include "rendergraph/texture.h" +#include "rendergraph/uniformset.h" + +namespace rendergraph { +class TextureMaterial; +} + +class rendergraph::TextureMaterial : public rendergraph::Material { + public: + TextureMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + std::unique_ptr createShader() const override; + + Texture* texture(int /*binding*/) const override { + return m_pTexture.get(); + } + + void setTexture(std::unique_ptr texture) { + m_pTexture = std::move(texture); + } + + private: + std::unique_ptr m_pTexture; +}; diff --git a/src/rendergraph/opengl/rendergraph/material/unicolormaterial.cpp b/src/rendergraph/opengl/rendergraph/material/unicolormaterial.cpp new file mode 100644 index 00000000000..8e4bf12ed9c --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/unicolormaterial.cpp @@ -0,0 +1,39 @@ +#include "unicolormaterial.h" + +#include + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +UniColorMaterial::UniColorMaterial() + : Material(uniforms()) { +} + +/* static */ const AttributeSet& UniColorMaterial::attributes() { + static AttributeSet set = makeAttributeSet({"position"}); + return set; +} + +/* static */ const UniformSet& UniColorMaterial::uniforms() { + static UniformSet set = makeUniformSet({"ubuf.matrix", "ubuf.color"}); + return set; +} + +MaterialType* UniColorMaterial::type() const { + static MaterialType type; + return &type; +} + +int UniColorMaterial::compare(const Material* other) const { + Q_ASSERT(other && type() == other->type()); + const auto* otherCasted = static_cast(other); + return otherCasted == this ? 0 : 1; +} + +std::unique_ptr UniColorMaterial::createShader() const { + return std::make_unique( + "unicolor.vert", "unicolor.frag", uniforms(), attributes()); +} diff --git a/src/rendergraph/opengl/rendergraph/material/unicolormaterial.h b/src/rendergraph/opengl/rendergraph/material/unicolormaterial.h new file mode 100644 index 00000000000..9516bb8c731 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/material/unicolormaterial.h @@ -0,0 +1,21 @@ +#include "rendergraph/attributeset.h" +#include "rendergraph/material.h" + +namespace rendergraph { +class UniColorMaterial; +} + +class rendergraph::UniColorMaterial : public rendergraph::Material { + public: + UniColorMaterial(); + + static const AttributeSet& attributes(); + + static const UniformSet& uniforms(); + + MaterialType* type() const override; + + int compare(const Material* other) const override; + + std::unique_ptr createShader() const override; +}; diff --git a/src/rendergraph/opengl/materialshader_impl.cpp b/src/rendergraph/opengl/rendergraph/materialshader.cpp similarity index 50% rename from src/rendergraph/opengl/materialshader_impl.cpp rename to src/rendergraph/opengl/rendergraph/materialshader.cpp index 188bac4006d..aaea06fff17 100644 --- a/src/rendergraph/opengl/materialshader_impl.cpp +++ b/src/rendergraph/opengl/rendergraph/materialshader.cpp @@ -1,16 +1,15 @@ -#include "materialshader_impl.h" +#include "rendergraph/materialshader.h" + +#include #include "rendergraph/attributeset.h" #include "rendergraph/uniformset.h" - using namespace rendergraph; -MaterialShader::Impl::Impl(MaterialShader* pOwner, - const char* vertexShaderFile, +MaterialShader::MaterialShader(const char* vertexShaderFile, const char* fragmentShaderFile, const UniformSet& uniformSet, - const AttributeSet& attributeSet) - : m_pOwner(pOwner) { + const AttributeSet& attributeSet) { addShaderFromSourceFile(QOpenGLShader::Vertex, resource(vertexShaderFile)); addShaderFromSourceFile(QOpenGLShader::Fragment, resource(fragmentShaderFile)); link(); @@ -23,3 +22,24 @@ MaterialShader::Impl::Impl(MaterialShader* pOwner, m_uniformLocations.push_back(location); } } + +MaterialShader::~MaterialShader() = default; + +QOpenGLShaderProgram& MaterialShader::glShader() { + return *this; +} + +int MaterialShader::attributeLocation(int attributeIndex) const { + return m_attributeLocations[attributeIndex]; +} + +int MaterialShader::uniformLocation(int uniformIndex) const { + return m_uniformLocations[uniformIndex]; +} + +Material* MaterialShader::lastModifiedByMaterial() const { + return m_pLastModifiedByMaterial; +} +void MaterialShader::setLastModifiedByMaterial(Material* pMaterial) { + m_pLastModifiedByMaterial = pMaterial; +} diff --git a/src/rendergraph/opengl/rendergraph/materialshader.h b/src/rendergraph/opengl/rendergraph/materialshader.h new file mode 100644 index 00000000000..cc2ca699061 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/materialshader.h @@ -0,0 +1,37 @@ +#pragma once + +#include +#include + +namespace rendergraph { +class AttributeSet; +class UniformSet; +class MaterialShader; +class Material; +} // namespace rendergraph + +class rendergraph::MaterialShader : public QOpenGLShaderProgram { + public: + MaterialShader(const char* vertexShaderFile, + const char* fragmentShaderFile, + const UniformSet& uniforms, + const AttributeSet& attributeSet); + ~MaterialShader(); + + QOpenGLShaderProgram& glShader(); + int attributeLocation(int attributeIndex) const; + int uniformLocation(int uniformIndex) const; + + private: + friend Material; + + Material* lastModifiedByMaterial() const; + void setLastModifiedByMaterial(Material* pMaterial); + + static QString resource(const char* filename) { + return QString(":/shaders/rendergraph/") + QString(filename) + QString(".gl"); + } + std::vector m_attributeLocations; + std::vector m_uniformLocations; + Material* m_pLastModifiedByMaterial{}; +}; diff --git a/src/rendergraph/opengl/rendergraph/materialtype.cpp b/src/rendergraph/opengl/rendergraph/materialtype.cpp new file mode 100644 index 00000000000..3839d6f5b8e --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/materialtype.cpp @@ -0,0 +1,6 @@ +#include "rendergraph/materialtype.h" + +using namespace rendergraph; + +MaterialType::MaterialType() = default; +MaterialType::~MaterialType() = default; diff --git a/src/rendergraph/opengl/rendergraph/materialtype.h b/src/rendergraph/opengl/rendergraph/materialtype.h new file mode 100644 index 00000000000..d5b5c980fbd --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/materialtype.h @@ -0,0 +1,11 @@ +#pragma once + +namespace rendergraph { +class MaterialType; +} + +class rendergraph::MaterialType { + public: + MaterialType(); + ~MaterialType(); +}; diff --git a/src/rendergraph/opengl/rendergraph/node.cpp b/src/rendergraph/opengl/rendergraph/node.cpp new file mode 100644 index 00000000000..810aeef83e6 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/node.cpp @@ -0,0 +1,49 @@ +#include "rendergraph/node.h" + +#include "rendergraph/graph.h" + +using namespace rendergraph; + +Node::Node() = default; + +Node::~Node() = default; + +void Node::appendChildNode(std::unique_ptr&& pChild) { + auto pChildRawPtr = pChild.get(); + if (m_pLastChild) { + pChild->m_pPreviousSibling = m_pLastChild; + m_pLastChild->m_pNextSibling = std::move(pChild); + } else { + m_pFirstChild = std::move(pChild); + } + m_pLastChild = pChildRawPtr; + m_pLastChild->m_pParent = this; + if (graph() != nullptr && graph() != pChildRawPtr->graph()) { + graph()->addToGraph(pChildRawPtr); + } +} +std::unique_ptr Node::removeAllChildNodes() { + m_pLastChild = nullptr; + Node* pChild = m_pFirstChild.get(); + while (pChild) { + pChild->m_pParent = nullptr; + pChild = pChild->m_pNextSibling.get(); + } + return std::move(m_pFirstChild); +} +std::unique_ptr Node::removeChildNode(Node* pChild) { + std::unique_ptr pRemoved; + if (pChild == m_pFirstChild.get()) { + pRemoved = std::move(m_pFirstChild); + m_pFirstChild = std::move(pChild->m_pNextSibling); + } else { + pRemoved = std::move(pChild->m_pPreviousSibling->m_pNextSibling); + pChild->m_pPreviousSibling->m_pNextSibling = std::move(pChild->m_pNextSibling); + pChild->m_pPreviousSibling = nullptr; + } + if (pChild == m_pLastChild) { + m_pLastChild = nullptr; + } + pChild->m_pParent = nullptr; + return pRemoved; +} diff --git a/src/rendergraph/opengl/rendergraph/node.h b/src/rendergraph/opengl/rendergraph/node.h new file mode 100644 index 00000000000..f8f49a8bbeb --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/node.h @@ -0,0 +1,74 @@ +#pragma once + +#include +#include + +namespace rendergraph { +class Node; +class Graph; +} // namespace rendergraph + +class rendergraph::Node { + public: + Node(); + + virtual ~Node(); + + void appendChildNode(std::unique_ptr&& pChild); + std::unique_ptr removeAllChildNodes(); + std::unique_ptr removeChildNode(Node* pChild); + + Node* parent() const { + return m_pParent; + } + Node* firstChild() const { + return m_pFirstChild.get(); + } + Node* lastChild() const { + return m_pLastChild; + } + Node* nextSibling() const { + return m_pNextSibling.get(); + } + Node* previousSibling() const { + return m_pPreviousSibling; + } + + virtual bool isSubtreeBlocked() const { + return false; + } + + virtual void preprocess() { + } + + virtual void initialize() { + } + virtual void render() { + } + virtual void resize(int, int) { + } + + void setUsePreprocess(bool value) { + m_usePreprocess = value; + } + bool usePreprocess() const { + return m_usePreprocess; + } + + Graph* graph() const { + return m_pGraph; + } + void setGraph(Graph* pGraph) { + m_pGraph = pGraph; + } + + private: + Graph* m_pGraph{}; + Node* m_pParent{}; + std::unique_ptr m_pFirstChild; + Node* m_pLastChild{}; + std::unique_ptr m_pNextSibling; + Node* m_pPreviousSibling{}; + + bool m_usePreprocess{}; +}; diff --git a/src/rendergraph/opengl/rendergraph/opacitynode.cpp b/src/rendergraph/opengl/rendergraph/opacitynode.cpp new file mode 100644 index 00000000000..3059ae0886b --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/opacitynode.cpp @@ -0,0 +1,15 @@ +#include "rendergraph/opacitynode.h" + +using namespace rendergraph; + +OpacityNode::OpacityNode() = default; + +OpacityNode::~OpacityNode() = default; + +void OpacityNode::setOpacity(float opacity) { + m_opacity = opacity; +} + +bool OpacityNode::isSubtreeBlocked() const { + return m_opacity == 0.f; +} diff --git a/src/rendergraph/opengl/rendergraph/opacitynode.h b/src/rendergraph/opengl/rendergraph/opacitynode.h new file mode 100644 index 00000000000..a9a7b0216df --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/opacitynode.h @@ -0,0 +1,18 @@ +#pragma once + +#include "rendergraph/node.h" + +namespace rendergraph { +class OpacityNode; +} // namespace rendergraph + +class rendergraph::OpacityNode : public rendergraph::Node { + public: + OpacityNode(); + ~OpacityNode(); + void setOpacity(float opacity); + bool isSubtreeBlocked() const override; + + private: + float m_opacity{1.f}; +}; diff --git a/src/rendergraph/opengl/rendergraph/openglnode.cpp b/src/rendergraph/opengl/rendergraph/openglnode.cpp new file mode 100644 index 00000000000..f13844449e8 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/openglnode.cpp @@ -0,0 +1,22 @@ +#include "rendergraph/openglnode.h" + +using namespace rendergraph; + +OpenGLNode::OpenGLNode() = default; +OpenGLNode::~OpenGLNode() = default; + +void OpenGLNode::initialize() { + initializeOpenGLFunctions(); + initializeGL(); + Node::initialize(); +} + +void OpenGLNode::render() { + paintGL(); + Node::render(); +} + +void OpenGLNode::resize(int w, int h) { + resizeGL(w, h); + Node::resize(w, h); +} diff --git a/src/rendergraph/opengl/openglnode.h b/src/rendergraph/opengl/rendergraph/openglnode.h similarity index 79% rename from src/rendergraph/opengl/openglnode.h rename to src/rendergraph/opengl/rendergraph/openglnode.h index a618631bab0..8ff3dedc74d 100644 --- a/src/rendergraph/opengl/openglnode.h +++ b/src/rendergraph/opengl/rendergraph/openglnode.h @@ -10,8 +10,6 @@ class OpenGLNode; class rendergraph::OpenGLNode : public rendergraph::Node, public QOpenGLFunctions { public: - class Impl; - OpenGLNode(); ~OpenGLNode(); @@ -21,7 +19,7 @@ class rendergraph::OpenGLNode : public rendergraph::Node, public QOpenGLFunction } virtual void resizeGL(int, int) { } - - private: - OpenGLNode(NodeImplBase* pImpl); + void initialize() override; + void render() override; + void resize(int w, int h) override; }; diff --git a/src/rendergraph/opengl/shadercache.h b/src/rendergraph/opengl/rendergraph/shadercache.h similarity index 100% rename from src/rendergraph/opengl/shadercache.h rename to src/rendergraph/opengl/rendergraph/shadercache.h diff --git a/src/rendergraph/opengl/rendergraph/texture.cpp b/src/rendergraph/opengl/rendergraph/texture.cpp new file mode 100644 index 00000000000..fd3c9e16b19 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/texture.cpp @@ -0,0 +1,29 @@ +#include "rendergraph/texture.h" + +#include + +using namespace rendergraph; + +Texture::Texture(Context& context, const QImage& image) + : m_pTexture(new QOpenGLTexture(premultiplyAlpha(image))) { + m_pTexture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); + m_pTexture->setWrapMode(QOpenGLTexture::ClampToEdge); +} + +Texture::~Texture() = default; + +QOpenGLTexture* Texture::glTexture() const { + return m_pTexture.get(); +} + +QImage Texture::premultiplyAlpha(const QImage& image) { + if (image.format() == QImage::Format_RGBA8888_Premultiplied) { + return QImage(image.bits(), image.width(), image.height(), QImage::Format_RGBA8888); + } + return QImage( + image.convertToFormat(QImage::Format_RGBA8888_Premultiplied) + .bits(), + image.width(), + image.height(), + QImage::Format_RGBA8888); +} diff --git a/src/rendergraph/opengl/rendergraph/texture.h b/src/rendergraph/opengl/rendergraph/texture.h new file mode 100644 index 00000000000..a130e13d8b7 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/texture.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +class QImage; +class QOpenGLTexture; + +namespace rendergraph { +class Context; +class Texture; +} // namespace rendergraph + +class rendergraph::Texture { + public: + Texture(Context& context, const QImage& image); + ~Texture(); + + QOpenGLTexture* glTexture() const; + + private: + const std::unique_ptr m_pTexture{}; + static QImage premultiplyAlpha(const QImage& image); +}; diff --git a/src/rendergraph/opengl/rendergraph/types.cpp b/src/rendergraph/opengl/rendergraph/types.cpp new file mode 100644 index 00000000000..a44d113d7f8 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/types.cpp @@ -0,0 +1,107 @@ +#include "rendergraph/types.h" + +#include + +using namespace rendergraph; + +int rendergraph::sizeOf(PrimitiveType type) { + switch (type) { + case PrimitiveType::UInt: + return sizeof(GLuint); + case PrimitiveType::Float: + return sizeof(GLfloat); + } + return 0; +} + +int rendergraph::sizeOf(Type type) { + switch (type) { + case Type::UInt: + return sizeof(GLuint); + case Type::Float: + return sizeof(GLfloat); + case Type::Vector2D: + return sizeof(GLfloat) * 2; + case Type::Vector3D: + return sizeof(GLfloat) * 3; + case Type::Vector4D: + return sizeof(GLfloat) * 4; + case Type::Matrix4x4: + return sizeof(GLfloat) * 4 * 4; + } + return 0; +} + +template<> +Type rendergraph::typeOf() { + return Type::UInt; +} + +template<> +Type rendergraph::typeOf() { + return Type::Float; +} + +template<> +Type rendergraph::typeOf() { + return Type::Vector2D; +} + +template<> +Type rendergraph::typeOf() { + return Type::Vector3D; +} + +template<> +Type rendergraph::typeOf() { + return Type::Vector4D; +} + +template<> +Type rendergraph::typeOf() { + return Type::Matrix4x4; +} + +template<> +PrimitiveType rendergraph::primitiveTypeOf() { + return PrimitiveType::Float; +} + +template<> +PrimitiveType rendergraph::primitiveTypeOf() { + return PrimitiveType::UInt; +} + +template<> +PrimitiveType rendergraph::primitiveTypeOf() { + return PrimitiveType::Float; +} +template<> +PrimitiveType rendergraph::primitiveTypeOf() { + return PrimitiveType::Float; +} +template<> +PrimitiveType rendergraph::primitiveTypeOf() { + return PrimitiveType::Float; +} + +template<> +int rendergraph::tupleSizeOf() { + return 1; +} +template<> +int rendergraph::tupleSizeOf() { + return 1; +} +template<> +int rendergraph::tupleSizeOf() { + return 2; +} +template<> +int rendergraph::tupleSizeOf() { + return 3; +} +template<> +int rendergraph::tupleSizeOf() { + return 4; +} diff --git a/src/rendergraph/opengl/rendergraph/types.h b/src/rendergraph/opengl/rendergraph/types.h new file mode 100644 index 00000000000..c8aea683757 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/types.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include +#include +#include + +namespace rendergraph { + +enum class PrimitiveType { + UInt, + Float, +}; + +enum class Type { + UInt, + Float, + Vector2D, + Vector3D, + Vector4D, + Matrix4x4 +}; + +int sizeOf(Type type); +int sizeOf(PrimitiveType primitiveType); + +template +Type typeOf(); + +template +PrimitiveType primitiveTypeOf(); + +template +int tupleSizeOf(); + +} // namespace rendergraph diff --git a/src/rendergraph/uniform.h b/src/rendergraph/opengl/rendergraph/uniform.h similarity index 100% rename from src/rendergraph/uniform.h rename to src/rendergraph/opengl/rendergraph/uniform.h diff --git a/src/rendergraph/uniformscache.cpp b/src/rendergraph/opengl/rendergraph/uniformscache.cpp similarity index 100% rename from src/rendergraph/uniformscache.cpp rename to src/rendergraph/opengl/rendergraph/uniformscache.cpp diff --git a/src/rendergraph/uniformscache.h b/src/rendergraph/opengl/rendergraph/uniformscache.h similarity index 100% rename from src/rendergraph/uniformscache.h rename to src/rendergraph/opengl/rendergraph/uniformscache.h diff --git a/src/rendergraph/uniformset.cpp b/src/rendergraph/opengl/rendergraph/uniformset.cpp similarity index 100% rename from src/rendergraph/uniformset.cpp rename to src/rendergraph/opengl/rendergraph/uniformset.cpp diff --git a/src/rendergraph/uniformset.h b/src/rendergraph/opengl/rendergraph/uniformset.h similarity index 100% rename from src/rendergraph/uniformset.h rename to src/rendergraph/opengl/rendergraph/uniformset.h diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 825d6942377..46980ea4463 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -1,44 +1,44 @@ add_library(rendergraph_sg - ../attribute.h - ../attributeset.cpp - ../attributeset.h - ../context.cpp - ../context.h - ../geometry.cpp - ../geometry.h - ../geometrynode.cpp - ../geometrynode.h - ../material.cpp - ../material.h - ../materialshader.cpp - ../materialshader.h - ../materialtype.cpp - ../materialtype.h - ../node.cpp - ../node.h - ../opacitynode.cpp - ../opacitynode.h - ../texture.cpp - ../texture.h - ../types.cpp - ../types.h - ../uniform.h - ../uniformscache.cpp - ../uniformscache.h - ../uniformset.cpp - ../uniformset.h - ../material/endoftrackmaterial.cpp - ../material/endoftrackmaterial.h - ../material/patternmaterial.cpp - ../material/patternmaterial.h - ../material/rgbamaterial.cpp - ../material/rgbamaterial.h - ../material/rgbmaterial.cpp - ../material/rgbmaterial.h - ../material/texturematerial.cpp - ../material/texturematerial.h - ../material/unicolormaterial.cpp - ../material/unicolormaterial.h + rendergraph/attribute.h + rendergraph/attributeset.cpp + rendergraph/attributeset.h + rendergraph/context.cpp + rendergraph/context.h + rendergraph/geometry.cpp + rendergraph/geometry.h + rendergraph/geometrynode.cpp + rendergraph/geometrynode.h + rendergraph/material.cpp + rendergraph/material.h + rendergraph/materialshader.cpp + rendergraph/materialshader.h + rendergraph/materialtype.cpp + rendergraph/materialtype.h + rendergraph/node.cpp + rendergraph/node.h + rendergraph/opacitynode.cpp + rendergraph/opacitynode.h + rendergraph/texture.cpp + rendergraph/texture.h + rendergraph/types.cpp + rendergraph/types.h + rendergraph/uniform.h + rendergraph/uniformscache.cpp + rendergraph/uniformscache.h + rendergraph/uniformset.cpp + rendergraph/uniformset.h + ../common/rendergraph/material/endoftrackmaterial.cpp + ../common/rendergraph/material/endoftrackmaterial.h + ../common/rendergraph/material/patternmaterial.cpp + ../common/rendergraph/material/patternmaterial.h + ../common/rendergraph/material/rgbamaterial.cpp + ../common/rendergraph/material/rgbamaterial.h + ../common/rendergraph/material/rgbmaterial.cpp + ../common/rendergraph/material/rgbmaterial.h + ../common/rendergraph/material/texturematerial.cpp + ../common/rendergraph/material/texturematerial.h + ../common/rendergraph/material/unicolormaterial.cpp + ../common/rendergraph/material/unicolormaterial.h materialshader_impl.cpp private/attributeset_impl.h private/context_impl.h @@ -50,8 +50,8 @@ add_library(rendergraph_sg private/node_impl.h private/opacitynode_impl.h private/texture_impl.h - scenegraph.cpp - scenegraph.h + rendergraph/scenegraph.cpp + rendergraph/scenegraph.h texture_impl.cpp ) @@ -62,4 +62,4 @@ target_link_libraries(rendergraph_sg PUBLIC Qt6::Quick ) -target_include_directories(rendergraph_sg PUBLIC ../.. PRIVATE private) +target_include_directories(rendergraph_sg PUBLIC . ../common PRIVATE private) diff --git a/src/rendergraph/scenegraph/rendergraph/attribute.h b/src/rendergraph/scenegraph/rendergraph/attribute.h new file mode 100644 index 00000000000..5fae9e3df54 --- /dev/null +++ b/src/rendergraph/scenegraph/rendergraph/attribute.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include "rendergraph/types.h" + +namespace rendergraph { +struct Attribute; +} + +struct rendergraph::Attribute { + const int m_tupleSize; + const PrimitiveType m_primitiveType; + const QString m_name; + + Attribute(int tupleSize, PrimitiveType primitiveType) + : m_tupleSize{tupleSize}, + m_primitiveType{primitiveType} { + } + + Attribute(int tupleSize, PrimitiveType primitiveType, QString name) + : m_tupleSize{tupleSize}, + m_primitiveType{primitiveType}, + m_name{std::move(name)} { + } + + template + static Attribute create() { + return Attribute(tupleSizeOf(), primitiveTypeOf()); + } +}; diff --git a/src/rendergraph/attributeset.cpp b/src/rendergraph/scenegraph/rendergraph/attributeset.cpp similarity index 100% rename from src/rendergraph/attributeset.cpp rename to src/rendergraph/scenegraph/rendergraph/attributeset.cpp diff --git a/src/rendergraph/attributeset.h b/src/rendergraph/scenegraph/rendergraph/attributeset.h similarity index 100% rename from src/rendergraph/attributeset.h rename to src/rendergraph/scenegraph/rendergraph/attributeset.h diff --git a/src/rendergraph/context.cpp b/src/rendergraph/scenegraph/rendergraph/context.cpp similarity index 100% rename from src/rendergraph/context.cpp rename to src/rendergraph/scenegraph/rendergraph/context.cpp diff --git a/src/rendergraph/context.h b/src/rendergraph/scenegraph/rendergraph/context.h similarity index 100% rename from src/rendergraph/context.h rename to src/rendergraph/scenegraph/rendergraph/context.h diff --git a/src/rendergraph/geometry.cpp b/src/rendergraph/scenegraph/rendergraph/geometry.cpp similarity index 100% rename from src/rendergraph/geometry.cpp rename to src/rendergraph/scenegraph/rendergraph/geometry.cpp diff --git a/src/rendergraph/geometry.h b/src/rendergraph/scenegraph/rendergraph/geometry.h similarity index 100% rename from src/rendergraph/geometry.h rename to src/rendergraph/scenegraph/rendergraph/geometry.h diff --git a/src/rendergraph/geometrynode.cpp b/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp similarity index 100% rename from src/rendergraph/geometrynode.cpp rename to src/rendergraph/scenegraph/rendergraph/geometrynode.cpp diff --git a/src/rendergraph/geometrynode.h b/src/rendergraph/scenegraph/rendergraph/geometrynode.h similarity index 100% rename from src/rendergraph/geometrynode.h rename to src/rendergraph/scenegraph/rendergraph/geometrynode.h diff --git a/src/rendergraph/material.cpp b/src/rendergraph/scenegraph/rendergraph/material.cpp similarity index 100% rename from src/rendergraph/material.cpp rename to src/rendergraph/scenegraph/rendergraph/material.cpp diff --git a/src/rendergraph/material.h b/src/rendergraph/scenegraph/rendergraph/material.h similarity index 100% rename from src/rendergraph/material.h rename to src/rendergraph/scenegraph/rendergraph/material.h diff --git a/src/rendergraph/materialshader.cpp b/src/rendergraph/scenegraph/rendergraph/materialshader.cpp similarity index 100% rename from src/rendergraph/materialshader.cpp rename to src/rendergraph/scenegraph/rendergraph/materialshader.cpp diff --git a/src/rendergraph/materialshader.h b/src/rendergraph/scenegraph/rendergraph/materialshader.h similarity index 100% rename from src/rendergraph/materialshader.h rename to src/rendergraph/scenegraph/rendergraph/materialshader.h diff --git a/src/rendergraph/materialtype.cpp b/src/rendergraph/scenegraph/rendergraph/materialtype.cpp similarity index 100% rename from src/rendergraph/materialtype.cpp rename to src/rendergraph/scenegraph/rendergraph/materialtype.cpp diff --git a/src/rendergraph/materialtype.h b/src/rendergraph/scenegraph/rendergraph/materialtype.h similarity index 100% rename from src/rendergraph/materialtype.h rename to src/rendergraph/scenegraph/rendergraph/materialtype.h diff --git a/src/rendergraph/node.cpp b/src/rendergraph/scenegraph/rendergraph/node.cpp similarity index 100% rename from src/rendergraph/node.cpp rename to src/rendergraph/scenegraph/rendergraph/node.cpp diff --git a/src/rendergraph/node.h b/src/rendergraph/scenegraph/rendergraph/node.h similarity index 100% rename from src/rendergraph/node.h rename to src/rendergraph/scenegraph/rendergraph/node.h diff --git a/src/rendergraph/opacitynode.cpp b/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp similarity index 100% rename from src/rendergraph/opacitynode.cpp rename to src/rendergraph/scenegraph/rendergraph/opacitynode.cpp diff --git a/src/rendergraph/opacitynode.h b/src/rendergraph/scenegraph/rendergraph/opacitynode.h similarity index 100% rename from src/rendergraph/opacitynode.h rename to src/rendergraph/scenegraph/rendergraph/opacitynode.h diff --git a/src/rendergraph/scenegraph/scenegraph.cpp b/src/rendergraph/scenegraph/rendergraph/scenegraph.cpp similarity index 100% rename from src/rendergraph/scenegraph/scenegraph.cpp rename to src/rendergraph/scenegraph/rendergraph/scenegraph.cpp diff --git a/src/rendergraph/scenegraph/scenegraph.h b/src/rendergraph/scenegraph/rendergraph/scenegraph.h similarity index 100% rename from src/rendergraph/scenegraph/scenegraph.h rename to src/rendergraph/scenegraph/rendergraph/scenegraph.h diff --git a/src/rendergraph/texture.cpp b/src/rendergraph/scenegraph/rendergraph/texture.cpp similarity index 100% rename from src/rendergraph/texture.cpp rename to src/rendergraph/scenegraph/rendergraph/texture.cpp diff --git a/src/rendergraph/texture.h b/src/rendergraph/scenegraph/rendergraph/texture.h similarity index 100% rename from src/rendergraph/texture.h rename to src/rendergraph/scenegraph/rendergraph/texture.h diff --git a/src/rendergraph/types.cpp b/src/rendergraph/scenegraph/rendergraph/types.cpp similarity index 100% rename from src/rendergraph/types.cpp rename to src/rendergraph/scenegraph/rendergraph/types.cpp diff --git a/src/rendergraph/types.h b/src/rendergraph/scenegraph/rendergraph/types.h similarity index 100% rename from src/rendergraph/types.h rename to src/rendergraph/scenegraph/rendergraph/types.h diff --git a/src/rendergraph/scenegraph/rendergraph/uniform.h b/src/rendergraph/scenegraph/rendergraph/uniform.h new file mode 100644 index 00000000000..19a6a9c74a3 --- /dev/null +++ b/src/rendergraph/scenegraph/rendergraph/uniform.h @@ -0,0 +1,28 @@ +#pragma once + +#include + +#include "rendergraph/types.h" + +namespace rendergraph { +struct Uniform; +} + +struct rendergraph::Uniform { + const Type m_type; + const QString m_name; + + Uniform(Type type) + : m_type{type} { + } + + Uniform(Type type, QString name) + : m_type{type}, + m_name{std::move(name)} { + } + + template + static Uniform create() { + return Uniform(typeOf()); + } +}; diff --git a/src/rendergraph/scenegraph/rendergraph/uniformscache.cpp b/src/rendergraph/scenegraph/rendergraph/uniformscache.cpp new file mode 100644 index 00000000000..3e43b60aab6 --- /dev/null +++ b/src/rendergraph/scenegraph/rendergraph/uniformscache.cpp @@ -0,0 +1,28 @@ +#include "rendergraph/uniformscache.h" + +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +UniformsCache::UniformsCache(const UniformSet& uniformSet) { + int offset = 0; + for (const auto& uniform : uniformSet.uniforms()) { + const int size = sizeOf(uniform.m_type); + m_infos.push_back({uniform.m_type, offset}); + offset += size; + } + m_byteArray.resize(offset); + m_byteArray.fill('\0'); +} + +UniformsCache::~UniformsCache() = default; + +void UniformsCache::set(int uniformIndex, Type type, const void* ptr, int size) { + assert(type == m_infos[uniformIndex].m_type); + memcpy(m_byteArray.data() + m_infos[uniformIndex].m_offset, ptr, size); +} + +void UniformsCache::get(int uniformIndex, Type type, void* ptr, int size) const { + assert(type == m_infos[uniformIndex].m_type); + memcpy(ptr, m_byteArray.data() + m_infos[uniformIndex].m_offset, size); +} diff --git a/src/rendergraph/scenegraph/rendergraph/uniformscache.h b/src/rendergraph/scenegraph/rendergraph/uniformscache.h new file mode 100644 index 00000000000..5787570effd --- /dev/null +++ b/src/rendergraph/scenegraph/rendergraph/uniformscache.h @@ -0,0 +1,67 @@ +#pragma once + +#include +#include +#include +#include + +#include "rendergraph/types.h" + +namespace rendergraph { +class UniformSet; +class UniformsCache; +} // namespace rendergraph + +class rendergraph::UniformsCache { + public: + UniformsCache(const UniformSet& uniformSet); + ~UniformsCache(); + + template + void set(int uniformIndex, const T& value) { + set(uniformIndex, typeOf(), static_cast(&value), sizeOf(typeOf())); + } + + template + T get(int uniformIndex) const { + T value; + get(uniformIndex, typeOf(), static_cast(&value), sizeof(T)); + return value; + } + Type type(int uniformIndex) const { + return m_infos[uniformIndex].m_type; + } + + const char* data() const { + return m_byteArray.data(); + } + qsizetype size() const { + return m_byteArray.size(); + } + int count() const { + return static_cast(m_infos.size()); + } + + private: + void set(int uniformIndex, Type type, const void* ptr, int size); + void get(int uniformIndex, Type type, void* ptr, int size) const; + + struct Info { + const Type m_type; + const int m_offset; + }; + + std::vector m_infos; + QByteArray m_byteArray; +}; + +template<> +inline void rendergraph::UniformsCache::set(int uniformIndex, const QColor& color) { + set(uniformIndex, QVector4D{color.redF(), color.greenF(), color.blueF(), color.alphaF()}); +} + +template<> +inline void rendergraph::UniformsCache::set( + int uniformIndex, const QMatrix4x4& matrix) { + set(uniformIndex, typeOf(), matrix.constData(), sizeOf(typeOf())); +} diff --git a/src/rendergraph/scenegraph/rendergraph/uniformset.cpp b/src/rendergraph/scenegraph/rendergraph/uniformset.cpp new file mode 100644 index 00000000000..68e077613bd --- /dev/null +++ b/src/rendergraph/scenegraph/rendergraph/uniformset.cpp @@ -0,0 +1,20 @@ +#include "rendergraph/uniformset.h" + +using namespace rendergraph; + +UniformSet::UniformSet(std::initializer_list list, const std::vector& names) { + int i = 0; + for (auto item : list) { + add(Uniform{item.m_type, names[i++]}); + } +} + +UniformSet::~UniformSet() = default; + +void UniformSet::add(const Uniform& uniform) { + m_uniforms.push_back(uniform); +} + +const std::vector& UniformSet::uniforms() const { + return m_uniforms; +} diff --git a/src/rendergraph/scenegraph/rendergraph/uniformset.h b/src/rendergraph/scenegraph/rendergraph/uniformset.h new file mode 100644 index 00000000000..afa1cfc2426 --- /dev/null +++ b/src/rendergraph/scenegraph/rendergraph/uniformset.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +#include "rendergraph/uniform.h" + +namespace rendergraph { +class UniformSet; +} + +class rendergraph::UniformSet { + public: + UniformSet(std::initializer_list list, const std::vector& names); + + ~UniformSet(); + + const std::vector& uniforms() const; + + private: + void add(const Uniform& uniform); + std::vector m_uniforms; +}; + +namespace rendergraph { +template +UniformSet makeUniformSet(const std::vector& names) { + return UniformSet({(Uniform::create())...}, names); +} +} // namespace rendergraph diff --git a/src/waveform/renderers/allshader/waveformrenderer.h b/src/waveform/renderers/allshader/waveformrenderer.h index 52b2c222047..32dbc036b19 100644 --- a/src/waveform/renderers/allshader/waveformrenderer.h +++ b/src/waveform/renderers/allshader/waveformrenderer.h @@ -1,6 +1,6 @@ #pragma once -#include "rendergraph/opengl/openglnode.h" +#include "rendergraph/openglnode.h" #include "waveform/renderers/waveformrendererabstract.h" class WaveformWidgetRenderer; diff --git a/src/waveform/renderers/allshader/waveformrenderersignalbase.h b/src/waveform/renderers/allshader/waveformrenderersignalbase.h index 7b1fe8002d9..b09b528111a 100644 --- a/src/waveform/renderers/allshader/waveformrenderersignalbase.h +++ b/src/waveform/renderers/allshader/waveformrenderersignalbase.h @@ -3,7 +3,7 @@ #include #include -#include "rendergraph/opengl/openglnode.h" +#include "rendergraph/openglnode.h" #include "util/class.h" #include "waveform/renderers/waveformrenderersignalbase.h" diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 744ee7f4920..66948148246 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -167,6 +167,7 @@ void allshader::WaveformRenderMark::initialize() { m_pDigitsRenderNode->updateTexture(untilMarkTextPointSize, getMaxHeightForText(), m_waveformRenderer->getDevicePixelRatio()); + Node::initialize(); } void allshader::WaveformRenderMark::updateRangeNode(GeometryNode* pNode, @@ -507,7 +508,7 @@ void allshader::WaveformRenderMark::drawTriangle(QPainter* painter, painter->fillPath(triangle, fillColor); } -void allshader::WaveformRenderMark::resize() { +void allshader::WaveformRenderMark::resize(int, int) { // Will create textures so requires OpenGL context updateMarkImages(); updatePlayPosMarkTexture(); diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index a4cbd3b47ad..585c147be94 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -29,11 +29,11 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, bool init() override; - void initialize(); - void resize(); void update(); // Virtual for rendergraph::Node + void initialize() override; + void resize(int, int) override; bool isSubtreeBlocked() const override; private: diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index 2666e70afb0..ef86bc981ac 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -5,7 +5,7 @@ #include #include -#include "rendergraph/opengl/shadercache.h" +#include "rendergraph/shadercache.h" #include "waveform/renderers/allshader/waveformrenderbackground.h" #include "waveform/renderers/allshader/waveformrenderbeat.h" #include "waveform/renderers/allshader/waveformrendererendoftrack.h" @@ -163,13 +163,10 @@ void WaveformWidget::castToQWidget() { void WaveformWidget::initializeGL() { m_pGraph->initialize(); - m_pWaveformRenderMark->initialize(); } void WaveformWidget::resizeGL(int w, int h) { m_pGraph->resize(w, h); - - m_pWaveformRenderMark->resize(); } void WaveformWidget::paintEvent(QPaintEvent* event) { diff --git a/src/waveform/widgets/allshader/waveformwidget.h b/src/waveform/widgets/allshader/waveformwidget.h index 0ecf97822a2..2ee2a6f1dae 100644 --- a/src/waveform/widgets/allshader/waveformwidget.h +++ b/src/waveform/widgets/allshader/waveformwidget.h @@ -1,7 +1,7 @@ #pragma once +#include "rendergraph/graph.h" #include "rendergraph/opacitynode.h" -#include "rendergraph/opengl/graph.h" #include "waveform/renderers/allshader/waveformrenderersignalbase.h" #include "waveform/widgets/waveformwidgetabstract.h" #include "waveform/widgets/waveformwidgetvars.h" From 18fa2c4545bda1b1a6eceb552423b816908a66ce Mon Sep 17 00:00:00 2001 From: m0dB Date: Thu, 19 Sep 2024 00:42:46 +0200 Subject: [PATCH 15/64] removed pimpl from rendergraph scenegraph --- .../examples/sg_example/customitem.cpp | 3 +- .../examples/sg_example/customitem.h | 4 +- src/rendergraph/scenegraph/CMakeLists.txt | 20 +--- .../scenegraph/materialshader_impl.cpp | 22 ----- .../scenegraph/private/attributeset_impl.h | 37 -------- .../scenegraph/private/context_impl.h | 18 ---- .../scenegraph/private/geometry_impl.h | 78 ---------------- .../scenegraph/private/geometrynode_impl.h | 29 ------ .../scenegraph/private/material_impl.h | 49 ---------- .../scenegraph/private/materialshader_impl.h | 41 -------- .../scenegraph/private/materialtype_impl.h | 12 --- .../scenegraph/private/node_impl.h | 55 ----------- .../scenegraph/private/opacitynode_impl.h | 23 ----- .../scenegraph/private/texture_impl.h | 19 ---- .../scenegraph/rendergraph/attributeset.cpp | 46 +++++---- .../scenegraph/rendergraph/attributeset.h | 36 ++++--- .../scenegraph/rendergraph/context.cpp | 14 +-- .../scenegraph/rendergraph/context.h | 9 +- .../scenegraph/rendergraph/geometry.cpp | 83 +++++++++-------- .../scenegraph/rendergraph/geometry.h | 18 ++-- .../scenegraph/rendergraph/geometrynode.cpp | 16 +--- .../scenegraph/rendergraph/geometrynode.h | 10 +- .../scenegraph/rendergraph/material.cpp | 23 +++-- .../scenegraph/rendergraph/material.h | 16 ++-- .../scenegraph/rendergraph/materialshader.cpp | 35 ++++--- .../scenegraph/rendergraph/materialshader.h | 22 +++-- .../scenegraph/rendergraph/materialtype.cpp | 14 +-- .../scenegraph/rendergraph/materialtype.h | 12 +-- .../scenegraph/rendergraph/node.cpp | 31 +------ src/rendergraph/scenegraph/rendergraph/node.h | 93 ++----------------- .../scenegraph/rendergraph/nodebase.cpp | 61 ++++++++++++ .../scenegraph/rendergraph/nodebase.h | 46 +++++++++ .../scenegraph/rendergraph/opacitynode.cpp | 15 +-- .../scenegraph/rendergraph/opacitynode.h | 10 +- .../scenegraph/rendergraph/scenegraph.cpp | 10 +- .../scenegraph/rendergraph/scenegraph.h | 6 +- .../scenegraph/rendergraph/texture.cpp | 15 +-- .../scenegraph/rendergraph/texture.h | 18 ++-- .../scenegraph/rendergraph/types.cpp | 30 +++--- src/rendergraph/scenegraph/texture_impl.cpp | 9 -- 40 files changed, 351 insertions(+), 757 deletions(-) delete mode 100644 src/rendergraph/scenegraph/materialshader_impl.cpp delete mode 100644 src/rendergraph/scenegraph/private/attributeset_impl.h delete mode 100644 src/rendergraph/scenegraph/private/context_impl.h delete mode 100644 src/rendergraph/scenegraph/private/geometry_impl.h delete mode 100644 src/rendergraph/scenegraph/private/geometrynode_impl.h delete mode 100644 src/rendergraph/scenegraph/private/material_impl.h delete mode 100644 src/rendergraph/scenegraph/private/materialshader_impl.h delete mode 100644 src/rendergraph/scenegraph/private/materialtype_impl.h delete mode 100644 src/rendergraph/scenegraph/private/node_impl.h delete mode 100644 src/rendergraph/scenegraph/private/opacitynode_impl.h delete mode 100644 src/rendergraph/scenegraph/private/texture_impl.h create mode 100644 src/rendergraph/scenegraph/rendergraph/nodebase.cpp create mode 100644 src/rendergraph/scenegraph/rendergraph/nodebase.h delete mode 100644 src/rendergraph/scenegraph/texture_impl.cpp diff --git a/src/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/examples/sg_example/customitem.cpp index bf87f780f17..5e2b2f78403 100644 --- a/src/rendergraph/examples/sg_example/customitem.cpp +++ b/src/rendergraph/examples/sg_example/customitem.cpp @@ -8,6 +8,7 @@ #include "examplenodes.h" #include "rendergraph/context.h" +#include "rendergraph/node.h" #include "rendergraph/scenegraph.h" CustomItem::CustomItem(QQuickItem* parent) @@ -43,7 +44,7 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { *context, img)); } - bgNode->appendChildNode(rendergraph::sgNode(m_node.get())); + bgNode->appendChildNode(dynamic_cast(m_node.get())); node = bgNode; } else { diff --git a/src/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/examples/sg_example/customitem.h index 304fb5c8f5e..23d9a021fc1 100644 --- a/src/rendergraph/examples/sg_example/customitem.h +++ b/src/rendergraph/examples/sg_example/customitem.h @@ -4,7 +4,7 @@ #include namespace rendergraph { -class Node; +class NodeBase; } class CustomItem : public QQuickItem { @@ -20,7 +20,7 @@ class CustomItem : public QQuickItem { void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override; bool m_geometryChanged{}; - std::unique_ptr m_node; + std::unique_ptr m_node; }; #endif // CUSTOMITEM_H diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 46980ea4463..ebd4a16d791 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -16,6 +16,8 @@ add_library(rendergraph_sg rendergraph/materialtype.h rendergraph/node.cpp rendergraph/node.h + rendergraph/nodebase.cpp + rendergraph/nodebase.h rendergraph/opacitynode.cpp rendergraph/opacitynode.h rendergraph/texture.cpp @@ -27,6 +29,8 @@ add_library(rendergraph_sg rendergraph/uniformscache.h rendergraph/uniformset.cpp rendergraph/uniformset.h + rendergraph/scenegraph.cpp + rendergraph/scenegraph.h ../common/rendergraph/material/endoftrackmaterial.cpp ../common/rendergraph/material/endoftrackmaterial.h ../common/rendergraph/material/patternmaterial.cpp @@ -39,20 +43,6 @@ add_library(rendergraph_sg ../common/rendergraph/material/texturematerial.h ../common/rendergraph/material/unicolormaterial.cpp ../common/rendergraph/material/unicolormaterial.h - materialshader_impl.cpp - private/attributeset_impl.h - private/context_impl.h - private/geometry_impl.h - private/geometrynode_impl.h - private/material_impl.h - private/materialshader_impl.h - private/materialtype_impl.h - private/node_impl.h - private/opacitynode_impl.h - private/texture_impl.h - rendergraph/scenegraph.cpp - rendergraph/scenegraph.h - texture_impl.cpp ) target_link_libraries(rendergraph_sg PUBLIC @@ -62,4 +52,4 @@ target_link_libraries(rendergraph_sg PUBLIC Qt6::Quick ) -target_include_directories(rendergraph_sg PUBLIC . ../common PRIVATE private) +target_include_directories(rendergraph_sg PUBLIC . ../common) diff --git a/src/rendergraph/scenegraph/materialshader_impl.cpp b/src/rendergraph/scenegraph/materialshader_impl.cpp deleted file mode 100644 index 5b95250e6c8..00000000000 --- a/src/rendergraph/scenegraph/materialshader_impl.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "materialshader_impl.h" - -#include "material_impl.h" - -using namespace rendergraph; - -bool rendergraph::MaterialShader::Impl::updateUniformData(RenderState& state, - QSGMaterial* newMaterial, - QSGMaterial* oldMaterial) { - Material::Impl* pMaterialImpl = static_cast(newMaterial); - return pMaterialImpl->updateUniformsByteArray(state.uniformData()); -} - -void MaterialShader::Impl::updateSampledImage(RenderState& state, - int binding, - QSGTexture** texture, - QSGMaterial* newMaterial, - QSGMaterial* oldMaterial) { - Material::Impl* pMaterialImpl = static_cast(newMaterial); - *texture = pMaterialImpl->texture(binding); - (*texture)->commitTextureOperations(state.rhi(), state.resourceUpdateBatch()); -} diff --git a/src/rendergraph/scenegraph/private/attributeset_impl.h b/src/rendergraph/scenegraph/private/attributeset_impl.h deleted file mode 100644 index 45cc8714cfc..00000000000 --- a/src/rendergraph/scenegraph/private/attributeset_impl.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/attributeset.h" - -class rendergraph::AttributeSet::Impl { - public: - void add(const Attribute& attribute) { - const int count = static_cast(m_sgAttributes.size()); - const bool isPosition = count == 0; - m_sgAttributes.push_back(QSGGeometry::Attribute::create(count, - attribute.m_tupleSize, - toQSGGeometryType(attribute.m_primitiveType), - isPosition)); - const int stride = m_sgAttributeSet.stride + - attribute.m_tupleSize * sizeOf(attribute.m_primitiveType); - m_sgAttributeSet = QSGGeometry::AttributeSet{count + 1, stride, m_sgAttributes.data()}; - } - - const QSGGeometry::AttributeSet& sgAttributeSet() const { - return m_sgAttributeSet; - } - - private: - QSGGeometry::AttributeSet m_sgAttributeSet{}; - std::vector m_sgAttributes; - - int toQSGGeometryType(const rendergraph::PrimitiveType& t) { - switch (t) { - case rendergraph::PrimitiveType::Float: - return QSGGeometry::FloatType; - case rendergraph::PrimitiveType::UInt: - return QSGGeometry::UnsignedIntType; - } - } -}; diff --git a/src/rendergraph/scenegraph/private/context_impl.h b/src/rendergraph/scenegraph/private/context_impl.h deleted file mode 100644 index bce2fb3ac76..00000000000 --- a/src/rendergraph/scenegraph/private/context_impl.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/context.h" - -class rendergraph::Context::Impl { - public: - void setWindow(QQuickWindow* pWindow) { - m_pWindow = pWindow; - } - QQuickWindow* window() const { - return m_pWindow; - } - - private: - QQuickWindow* m_pWindow; -}; diff --git a/src/rendergraph/scenegraph/private/geometry_impl.h b/src/rendergraph/scenegraph/private/geometry_impl.h deleted file mode 100644 index b3e1cd80389..00000000000 --- a/src/rendergraph/scenegraph/private/geometry_impl.h +++ /dev/null @@ -1,78 +0,0 @@ -#pragma once - -#include - -#include "attributeset_impl.h" -#include "rendergraph/geometry.h" - -class rendergraph::Geometry::Impl : public QSGGeometry { - public: - Impl(const rendergraph::AttributeSet& rgAttributeSet, int vertexCount) - : QSGGeometry(rgAttributeSet.impl().sgAttributeSet(), vertexCount), - m_stride(rgAttributeSet.impl().sgAttributeSet().stride) { - QSGGeometry::setDrawingMode(QSGGeometry::DrawTriangleStrip); - } - - QSGGeometry* sgGeometry() { - return this; - } - - void setAttributeValues(int attributePosition, const float* from, int numTuples) { - const auto attributeArray = QSGGeometry::attributes(); - int offset = 0; - for (int i = 0; i < attributePosition; i++) { - offset += attributeArray[i].tupleSize; - } - const int tupleSize = attributeArray[attributePosition].tupleSize; - const int skip = m_stride / sizeof(float) - tupleSize; - - float* to = static_cast(QSGGeometry::vertexData()); - to += offset; - while (numTuples--) { - int k = tupleSize; - while (k--) { - *to++ = *from++; - } - to += skip; - } - } - - void setDrawingMode(Geometry::DrawingMode mode) { - QSGGeometry::setDrawingMode(toSgDrawingMode(mode)); - } - - Geometry::DrawingMode drawingMode() const { - return fromSgDrawingMode(QSGGeometry::drawingMode()); - } - - float* vertexData() { - return static_cast(QSGGeometry::vertexData()); - } - - template - T* vertexDataAs() { - return static_cast(QSGGeometry::vertexData()); - } - - private: - const int m_stride; - - static QSGGeometry::DrawingMode toSgDrawingMode(Geometry::DrawingMode mode) { - switch (mode) { - case Geometry::DrawingMode::Triangles: - return QSGGeometry::DrawTriangles; - case Geometry::DrawingMode::TriangleStrip: - return QSGGeometry::DrawTriangleStrip; - } - } - static Geometry::DrawingMode fromSgDrawingMode(unsigned int mode) { - switch (mode) { - case QSGGeometry::DrawTriangles: - return Geometry::DrawingMode::Triangles; - case QSGGeometry::DrawTriangleStrip: - return Geometry::DrawingMode::TriangleStrip; - default: - throw "not implemented"; - } - } -}; diff --git a/src/rendergraph/scenegraph/private/geometrynode_impl.h b/src/rendergraph/scenegraph/private/geometrynode_impl.h deleted file mode 100644 index 7270d5e357d..00000000000 --- a/src/rendergraph/scenegraph/private/geometrynode_impl.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include "geometry_impl.h" -#include "material_impl.h" -#include "node_impl.h" -#include "rendergraph/geometrynode.h" - -class rendergraph::GeometryNode::Impl : public QSGGeometryNode, public rendergraph::NodeImplBase { - public: - Impl(GeometryNode* pOwner) - : NodeImplBase(pOwner) { - } - - QSGNode* sgNode() override { - return this; - } - void setGeometry(Geometry* geometry) { - QSGGeometryNode::setGeometry(geometry->impl().sgGeometry()); - } - void setMaterial(Material* material) { - QSGGeometryNode::setMaterial(material->impl().sgMaterial()); - } - void preprocess() override { - owner()->preprocess(); - } - bool isSubtreeBlocked() const override { - return owner()->isSubtreeBlocked(); - } -}; diff --git a/src/rendergraph/scenegraph/private/material_impl.h b/src/rendergraph/scenegraph/private/material_impl.h deleted file mode 100644 index 4b36371f0c8..00000000000 --- a/src/rendergraph/scenegraph/private/material_impl.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include - -#include "materialshader_impl.h" -#include "materialtype_impl.h" -#include "rendergraph/material.h" -#include "texture_impl.h" - -class rendergraph::Material::Impl : public QSGMaterial { - public: - Impl(Material* pOwner) - : m_pOwner(pOwner) { - setFlag(QSGMaterial::Blending); - } - - QSGMaterial* sgMaterial() { - return this; - } - - bool updateUniformsByteArray(QByteArray* buf) { - if (m_pOwner->clearUniformsCacheDirty()) { - memcpy(buf->data(), m_pOwner->uniformsCache().data(), m_pOwner->uniformsCache().size()); - return true; - } - return false; - } - - QSGTexture* texture(int binding) { - return m_pOwner->texture(binding)->impl().sgTexture(); - } - - private: - QSGMaterialType* type() const override { - return m_pOwner->type()->impl().sgMaterialType(); - } - - int compare(const QSGMaterial* other) const override { - const Impl* otherCasted = static_cast(other); - return otherCasted && m_pOwner->compare(otherCasted->m_pOwner); - } - - QSGMaterialShader* createShader(QSGRendererInterface::RenderMode) const override { - auto pShader = m_pOwner->createShader().release(); // This leaks - return pShader->impl().sgMaterialShader(); - } - - Material* m_pOwner; -}; diff --git a/src/rendergraph/scenegraph/private/materialshader_impl.h b/src/rendergraph/scenegraph/private/materialshader_impl.h deleted file mode 100644 index 3067e605c0e..00000000000 --- a/src/rendergraph/scenegraph/private/materialshader_impl.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/materialshader.h" - -class rendergraph::MaterialShader::Impl : public QSGMaterialShader { - public: - Impl(MaterialShader* pOwner, - const char* vertexShaderFile, - const char* fragmentShaderFile, - const UniformSet& uniformSet, - const AttributeSet& attributeSet) - : m_pOwner(pOwner) { - (void)uniformSet; - (void)attributeSet; - setShaderFileName(VertexStage, resource(vertexShaderFile)); - setShaderFileName(FragmentStage, resource(fragmentShaderFile)); - } - - QSGMaterialShader* sgMaterialShader() { - return this; - } - - private: - bool updateUniformData(RenderState& state, - QSGMaterial* newMaterial, - QSGMaterial* oldMaterial) override; - - void updateSampledImage(RenderState& state, - int binding, - QSGTexture** texture, - QSGMaterial* newMaterial, - QSGMaterial* oldMaterial) override; - - static QString resource(const char* filename) { - return QString(":/shaders/rendergraph/") + QString(filename) + QString(".qsb"); - } - - MaterialShader* m_pOwner; -}; diff --git a/src/rendergraph/scenegraph/private/materialtype_impl.h b/src/rendergraph/scenegraph/private/materialtype_impl.h deleted file mode 100644 index c48df486446..00000000000 --- a/src/rendergraph/scenegraph/private/materialtype_impl.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/materialtype.h" - -class rendergraph::MaterialType::Impl : public QSGMaterialType { - public: - QSGMaterialType* sgMaterialType() { - return this; - } -}; diff --git a/src/rendergraph/scenegraph/private/node_impl.h b/src/rendergraph/scenegraph/private/node_impl.h deleted file mode 100644 index 7767ef33344..00000000000 --- a/src/rendergraph/scenegraph/private/node_impl.h +++ /dev/null @@ -1,55 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/node.h" - -class rendergraph::NodeImplBase { - public: - NodeImplBase(Node* pOwner) - : m_pOwner(pOwner) { - } - - virtual ~NodeImplBase() = default; - - virtual QSGNode* sgNode() = 0; - - Node* owner() const { - return m_pOwner; - } - - void setUsePreprocess(bool value) { - sgNode()->setFlag(QSGNode::UsePreprocess, value); - } - - void onAppendChildNode(Node* pChild) { - sgNode()->appendChildNode(pChild->impl().sgNode()); - } - void onRemoveAllChildNodes() { - sgNode()->removeAllChildNodes(); - } - void onRemoveChildNode(Node* pChild) { - sgNode()->removeChildNode(pChild->impl().sgNode()); - } - - private: - Node* m_pOwner; -}; - -class rendergraph::Node::Impl : public QSGNode, public rendergraph::NodeImplBase { - public: - Impl(Node* pOwner) - : NodeImplBase(pOwner) { - } - virtual ~Impl() = default; - - QSGNode* sgNode() override { - return this; - } - bool isSubtreeBlocked() const override { - return owner()->isSubtreeBlocked(); - } - void preprocess() override { - owner()->preprocess(); - } -}; diff --git a/src/rendergraph/scenegraph/private/opacitynode_impl.h b/src/rendergraph/scenegraph/private/opacitynode_impl.h deleted file mode 100644 index aa19bc8f6e7..00000000000 --- a/src/rendergraph/scenegraph/private/opacitynode_impl.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include "node_impl.h" -#include "rendergraph/opacitynode.h" - -class rendergraph::OpacityNode::Impl : public QSGOpacityNode, public rendergraph::NodeImplBase { - public: - Impl(OpacityNode* pOwner) - : NodeImplBase(pOwner) { - } - - QSGNode* sgNode() override { - return this; - } - - void preprocess() override { - owner()->preprocess(); - } - - bool isSubtreeBlocked() const override { - return QSGOpacityNode::isSubtreeBlocked() || owner()->isSubtreeBlocked(); - } -}; diff --git a/src/rendergraph/scenegraph/private/texture_impl.h b/src/rendergraph/scenegraph/private/texture_impl.h deleted file mode 100644 index eea6d6d6a29..00000000000 --- a/src/rendergraph/scenegraph/private/texture_impl.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/texture.h" - -// We can't use inheritance because QSGTexture has pure virtuals that we can't -// implement, so we encapsulate instead. -class rendergraph::Texture::Impl { - public: - Impl(Context& context, const QImage& image); - - QSGTexture* sgTexture() const { - return m_pTexture.get(); - } - - private: - std::unique_ptr m_pTexture{}; -}; diff --git a/src/rendergraph/scenegraph/rendergraph/attributeset.cpp b/src/rendergraph/scenegraph/rendergraph/attributeset.cpp index cb8fd9cb189..8938350eb8c 100644 --- a/src/rendergraph/scenegraph/rendergraph/attributeset.cpp +++ b/src/rendergraph/scenegraph/rendergraph/attributeset.cpp @@ -1,36 +1,42 @@ #include "rendergraph/attributeset.h" -#include "attributeset_impl.h" - using namespace rendergraph; -AttributeSet::AttributeSet(AttributeSet::Impl* pImpl) - : m_pImpl(pImpl) { -} - -AttributeSet::AttributeSet() - : AttributeSet(new AttributeSet::Impl()) { -} - -AttributeSet::AttributeSet(std::initializer_list list, const std::vector& names) - : AttributeSet() { +AttributeSetBase::AttributeSetBase(std::initializer_list list, + const std::vector& names) { int i = 0; for (auto item : list) { add(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); } } -AttributeSet::~AttributeSet() = default; +void AttributeSetBase::add(const Attribute& attribute) { + m_attributes.push_back(attribute); -AttributeSet::Impl& AttributeSet::impl() const { - return *m_pImpl; + const int count = static_cast(m_sgAttributes.size()); + const bool isPosition = count == 0; + m_sgAttributes.push_back(QSGGeometry::Attribute::create(count, + attribute.m_tupleSize, + toQSGGeometryType(attribute.m_primitiveType), + isPosition)); + m_stride += attribute.m_tupleSize * sizeOf(attribute.m_primitiveType); } -void AttributeSet::add(const Attribute& attribute) { - m_attributes.push_back(attribute); - m_pImpl->add(attribute); +int AttributeSetBase::toQSGGeometryType(const rendergraph::PrimitiveType& t) { + switch (t) { + case rendergraph::PrimitiveType::Float: + return QSGGeometry::FloatType; + case rendergraph::PrimitiveType::UInt: + return QSGGeometry::UnsignedIntType; + } } -const std::vector& AttributeSet::attributes() const { - return m_attributes; +AttributeSet::AttributeSet(std::initializer_list list, + const std::vector& names) + : AttributeSetBase(list, names), + QSGGeometry::AttributeSet{static_cast(m_sgAttributes.size()), + m_stride, + m_sgAttributes.data()} { } + +AttributeSet::~AttributeSet() = default; diff --git a/src/rendergraph/scenegraph/rendergraph/attributeset.h b/src/rendergraph/scenegraph/rendergraph/attributeset.h index a402973cb0d..2101dd46085 100644 --- a/src/rendergraph/scenegraph/rendergraph/attributeset.h +++ b/src/rendergraph/scenegraph/rendergraph/attributeset.h @@ -1,32 +1,44 @@ #pragma once +#include #include #include #include "rendergraph/attribute.h" namespace rendergraph { +class AttributeSetBase; class AttributeSet; } -class rendergraph::AttributeSet { - public: - class Impl; - - AttributeSet(); - AttributeSet(std::initializer_list list, const std::vector& names); +class rendergraph::AttributeSetBase { + protected: + int m_stride{}; - ~AttributeSet(); - - const std::vector& attributes() const; - Impl& impl() const; + AttributeSetBase(std::initializer_list list, const std::vector& names); private: - AttributeSet(Impl* pImpl); void add(const Attribute& attribute); + static int toQSGGeometryType(const rendergraph::PrimitiveType& t); + protected: std::vector m_attributes; - const std::unique_ptr m_pImpl; + QSGGeometry::AttributeSet m_sgAttributeSet{}; + std::vector m_sgAttributes; +}; + +class rendergraph::AttributeSet : private rendergraph::AttributeSetBase, + public QSGGeometry::AttributeSet { + public: + AttributeSet(std::initializer_list list, const std::vector& names); + ~AttributeSet(); + + const std::vector& attributes() const { + return m_attributes; + } + const QSGGeometry::AttributeSet& sgAttributeSet() const { + return *this; + } }; namespace rendergraph { diff --git a/src/rendergraph/scenegraph/rendergraph/context.cpp b/src/rendergraph/scenegraph/rendergraph/context.cpp index 1c64ec6d851..18ee9d28f3c 100644 --- a/src/rendergraph/scenegraph/rendergraph/context.cpp +++ b/src/rendergraph/scenegraph/rendergraph/context.cpp @@ -1,15 +1,15 @@ #include "rendergraph/context.h" -#include "context_impl.h" - using namespace rendergraph; -Context::Context() - : m_pImpl(new Context::Impl()) { -} +Context::Context() = default; Context::~Context() = default; -Context::Impl& Context::impl() const { - return *m_pImpl; +void Context::setWindow(QQuickWindow* pWindow) { + m_pWindow = pWindow; +} + +QQuickWindow* Context::window() const { + return m_pWindow; } diff --git a/src/rendergraph/scenegraph/rendergraph/context.h b/src/rendergraph/scenegraph/rendergraph/context.h index 2659910bfdd..b13b3c5b34e 100644 --- a/src/rendergraph/scenegraph/rendergraph/context.h +++ b/src/rendergraph/scenegraph/rendergraph/context.h @@ -1,6 +1,6 @@ #pragma once -#include +class QQuickWindow; namespace rendergraph { class Context; @@ -8,11 +8,12 @@ class Context; class rendergraph::Context { public: - class Impl; Context(); ~Context(); - Impl& impl() const; + + void setWindow(QQuickWindow* pWindow); + QQuickWindow* window() const; private: - const std::unique_ptr m_pImpl; + QQuickWindow* m_pWindow; }; diff --git a/src/rendergraph/scenegraph/rendergraph/geometry.cpp b/src/rendergraph/scenegraph/rendergraph/geometry.cpp index 67eb8e86fe2..caf16a5d4c3 100644 --- a/src/rendergraph/scenegraph/rendergraph/geometry.cpp +++ b/src/rendergraph/scenegraph/rendergraph/geometry.cpp @@ -1,60 +1,69 @@ #include "rendergraph/geometry.h" -#include - -#include "geometry_impl.h" +#include "rendergraph/attributeset.h" using namespace rendergraph; -Geometry::Geometry(Impl* pImpl) - : m_pImpl(pImpl) { +Geometry::Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount) + : QSGGeometry(attributeSet.sgAttributeSet(), vertexCount), + m_stride(attributeSet.sgAttributeSet().stride) { + QSGGeometry::setDrawingMode(QSGGeometry::DrawTriangleStrip); } -Geometry::Geometry(const AttributeSet& attributeSet, int vertexCount) - : Geometry(new Geometry::Impl(attributeSet, vertexCount)){}; - Geometry::~Geometry() = default; -Geometry::Impl& Geometry::impl() const { - return *m_pImpl; -} - -void Geometry::setAttributeValues(int attributePosition, const float* data, int numTuples) { - m_pImpl->setAttributeValues(attributePosition, data, numTuples); +void Geometry::setAttributeValues(int attributePosition, const float* from, int numTuples) { + const auto attributeArray = QSGGeometry::attributes(); + int offset = 0; + for (int i = 0; i < attributePosition; i++) { + offset += attributeArray[i].tupleSize; + } + const int tupleSize = attributeArray[attributePosition].tupleSize; + const int skip = m_stride / sizeof(float) - tupleSize; + + float* to = static_cast(QSGGeometry::vertexData()); + to += offset; + while (numTuples--) { + int k = tupleSize; + while (k--) { + *to++ = *from++; + } + to += skip; + } } float* Geometry::vertexData() { - return m_pImpl->vertexData(); -} - -template<> -Geometry::Point2D* Geometry::vertexDataAs() { - return m_pImpl->vertexDataAs(); -} - -template<> -Geometry::TexturedPoint2D* Geometry::vertexDataAs() { - return m_pImpl->vertexDataAs(); + return static_cast(QSGGeometry::vertexData()); } -template<> -Geometry::RGBColoredPoint2D* Geometry::vertexDataAs() { - return m_pImpl->vertexDataAs(); +void Geometry::allocate(int vertexCount) { + QSGGeometry::allocate(vertexCount); } -template<> -Geometry::RGBAColoredPoint2D* Geometry::vertexDataAs() { - return m_pImpl->vertexDataAs(); +void Geometry::setDrawingMode(Geometry::DrawingMode mode) { + QSGGeometry::setDrawingMode(toSgDrawingMode(mode)); } -void Geometry::allocate(int vertexCount) { - m_pImpl->allocate(vertexCount); +Geometry::DrawingMode Geometry::drawingMode() const { + return fromSgDrawingMode(QSGGeometry::drawingMode()); } -void Geometry::setDrawingMode(Geometry::DrawingMode mode) { - m_pImpl->setDrawingMode(mode); +QSGGeometry::DrawingMode Geometry::toSgDrawingMode(Geometry::DrawingMode mode) { + switch (mode) { + case Geometry::DrawingMode::Triangles: + return QSGGeometry::DrawTriangles; + case Geometry::DrawingMode::TriangleStrip: + return QSGGeometry::DrawTriangleStrip; + } } -Geometry::DrawingMode Geometry::drawingMode() const { - return m_pImpl->Impl::drawingMode(); +Geometry::DrawingMode Geometry::fromSgDrawingMode(unsigned int mode) { + switch (mode) { + case QSGGeometry::DrawTriangles: + return Geometry::DrawingMode::Triangles; + case QSGGeometry::DrawTriangleStrip: + return Geometry::DrawingMode::TriangleStrip; + default: + throw "not implemented"; + } } diff --git a/src/rendergraph/scenegraph/rendergraph/geometry.h b/src/rendergraph/scenegraph/rendergraph/geometry.h index c83a8c6c5c5..e527346d63a 100644 --- a/src/rendergraph/scenegraph/rendergraph/geometry.h +++ b/src/rendergraph/scenegraph/rendergraph/geometry.h @@ -1,14 +1,15 @@ #pragma once +#include #include -#include +#include namespace rendergraph { class Geometry; class AttributeSet; } // namespace rendergraph -class rendergraph::Geometry { +class rendergraph::Geometry : public QSGGeometry { public: struct Point2D { QVector2D position2D; @@ -48,18 +49,18 @@ class rendergraph::Geometry { Triangles, TriangleStrip }; - class Impl; - Geometry(const AttributeSet& attributeSet, int vertexCount); + Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount); ~Geometry(); void setAttributeValues(int attributePosition, const float* data, int numTuples); - Impl& impl() const; float* vertexData(); template - T* vertexDataAs(); + T* vertexDataAs() { + return static_cast(QSGGeometry::vertexData()); + } void allocate(int vertexCount); @@ -67,7 +68,8 @@ class rendergraph::Geometry { void setDrawingMode(DrawingMode mode); private: - Geometry(Impl* pImpl); + static QSGGeometry::DrawingMode toSgDrawingMode(Geometry::DrawingMode mode); + static Geometry::DrawingMode fromSgDrawingMode(unsigned int mode); - const std::unique_ptr m_pImpl; + const int m_stride; }; diff --git a/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp b/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp index e083d56f718..2a07129edd5 100644 --- a/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp +++ b/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp @@ -1,28 +1,20 @@ #include "rendergraph/geometrynode.h" -#include "geometrynode_impl.h" -#include "rendergraph/geometry.h" +#include "rendergraph/material.h" using namespace rendergraph; -GeometryNode::GeometryNode(NodeImplBase* pImpl) - : Node(pImpl) { -} - -GeometryNode::GeometryNode() - : GeometryNode(new GeometryNode::Impl(this)) { -} - +GeometryNode::GeometryNode() = default; GeometryNode::~GeometryNode() = default; void GeometryNode::setGeometry(std::unique_ptr geometry) { m_geometry = std::move(geometry); - static_cast(impl()).setGeometry(m_geometry.get()); + QSGGeometryNode::setGeometry(m_geometry.get()); } void GeometryNode::setMaterial(std::unique_ptr material) { m_material = std::move(material); - static_cast(impl()).setMaterial(m_material.get()); + QSGGeometryNode::setMaterial(m_material.get()); } Geometry& GeometryNode::geometry() const { diff --git a/src/rendergraph/scenegraph/rendergraph/geometrynode.h b/src/rendergraph/scenegraph/rendergraph/geometrynode.h index 1b0784a42cf..caeb0c58fd3 100644 --- a/src/rendergraph/scenegraph/rendergraph/geometrynode.h +++ b/src/rendergraph/scenegraph/rendergraph/geometrynode.h @@ -1,7 +1,9 @@ #pragma once +#include + #include "rendergraph/geometry.h" -#include "rendergraph/node.h" +#include "rendergraph/nodebase.h" namespace rendergraph { class GeometryNode; @@ -9,10 +11,8 @@ class Geometry; class Material; } // namespace rendergraph -class rendergraph::GeometryNode : public rendergraph::Node { +class rendergraph::GeometryNode : public QSGGeometryNode, public rendergraph::NodeBase { public: - class Impl; - GeometryNode(); ~GeometryNode(); @@ -25,11 +25,11 @@ class rendergraph::GeometryNode : public rendergraph::Node { void setMaterial(std::unique_ptr material); void setGeometry(std::unique_ptr geometry); + Geometry& geometry() const; Material& material() const; private: - GeometryNode(NodeImplBase* pImpl); std::unique_ptr m_material; std::unique_ptr m_geometry; }; diff --git a/src/rendergraph/scenegraph/rendergraph/material.cpp b/src/rendergraph/scenegraph/rendergraph/material.cpp index 7f45a2ead86..485349eda2b 100644 --- a/src/rendergraph/scenegraph/rendergraph/material.cpp +++ b/src/rendergraph/scenegraph/rendergraph/material.cpp @@ -1,20 +1,25 @@ #include "rendergraph/material.h" -#include "material_impl.h" +#include "rendergraph/materialshader.h" using namespace rendergraph; -Material::Material(Impl* pImpl, const UniformSet& uniformSet) - : m_pImpl(pImpl), - m_uniformsCache(uniformSet) { -} - Material::Material(const UniformSet& uniformSet) - : Material(new Material::Impl(this), uniformSet) { + : m_uniformsCache(uniformSet) { + setFlag(QSGMaterial::Blending); } Material::~Material() = default; -Material::Impl& Material::impl() const { - return *m_pImpl; +bool Material::updateUniformsByteArray(QByteArray* buf) { + if (clearUniformsCacheDirty()) { + memcpy(buf->data(), uniformsCache().data(), uniformsCache().size()); + return true; + } + return false; +} + +QSGMaterialShader* Material::createShader(QSGRendererInterface::RenderMode) const { + auto pShader = createShader().release(); // This leaks + return pShader; } diff --git a/src/rendergraph/scenegraph/rendergraph/material.h b/src/rendergraph/scenegraph/rendergraph/material.h index 39ca86a6871..259c9818838 100644 --- a/src/rendergraph/scenegraph/rendergraph/material.h +++ b/src/rendergraph/scenegraph/rendergraph/material.h @@ -1,7 +1,10 @@ #pragma once +#include #include +#include "rendergraph/materialtype.h" +#include "rendergraph/texture.h" #include "rendergraph/uniformscache.h" namespace rendergraph { @@ -12,15 +15,12 @@ class MaterialType; class Texture; } // namespace rendergraph -class rendergraph::Material { +class rendergraph::Material : public QSGMaterial { public: - class Impl; - Material(const UniformSet& uniformSet); virtual ~Material(); virtual int compare(const Material* other) const = 0; virtual std::unique_ptr createShader() const = 0; - virtual MaterialType* type() const = 0; template void setUniform(int uniformIndex, const T& value) { @@ -28,7 +28,6 @@ class rendergraph::Material { m_uniformsCacheDirty = true; } - Impl& impl() const; const UniformsCache& uniformsCache() const { return m_uniformsCache; } @@ -45,10 +44,11 @@ class rendergraph::Material { return nullptr; } - private: - Material(Impl* pImpl, const UniformSet& uniformSet); + QSGMaterialShader* createShader(QSGRendererInterface::RenderMode) const override; - const std::unique_ptr m_pImpl; + bool updateUniformsByteArray(QByteArray* buf); + + private: UniformsCache m_uniformsCache; bool m_uniformsCacheDirty{}; }; diff --git a/src/rendergraph/scenegraph/rendergraph/materialshader.cpp b/src/rendergraph/scenegraph/rendergraph/materialshader.cpp index 6d27917b4be..7bc69b85144 100644 --- a/src/rendergraph/scenegraph/rendergraph/materialshader.cpp +++ b/src/rendergraph/scenegraph/rendergraph/materialshader.cpp @@ -1,25 +1,34 @@ #include "rendergraph/materialshader.h" -#include "materialshader_impl.h" +#include -using namespace rendergraph; +#include "rendergraph/material.h" -MaterialShader::MaterialShader(Impl* pImpl) - : m_pImpl(pImpl) { -} +using namespace rendergraph; MaterialShader::MaterialShader(const char* vertexShaderFile, const char* fragmentShaderFile, const UniformSet& uniformSet, - const AttributeSet& attributeSet) - : MaterialShader(new MaterialShader::Impl(this, - vertexShaderFile, - fragmentShaderFile, - uniformSet, - attributeSet)){}; + const AttributeSet& attributeSet) { + (void)uniformSet; + (void)attributeSet; + setShaderFileName(VertexStage, resource(vertexShaderFile)); + setShaderFileName(FragmentStage, resource(fragmentShaderFile)); +} MaterialShader::~MaterialShader() = default; -MaterialShader::Impl& MaterialShader::impl() const { - return *m_pImpl; +bool rendergraph::MaterialShader::updateUniformData(RenderState& state, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) { + return static_cast(newMaterial)->updateUniformsByteArray(state.uniformData()); +} + +void MaterialShader::updateSampledImage(RenderState& state, + int binding, + QSGTexture** texture, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) { + *texture = static_cast(newMaterial)->texture(binding)->sgTexture(); + (*texture)->commitTextureOperations(state.rhi(), state.resourceUpdateBatch()); } diff --git a/src/rendergraph/scenegraph/rendergraph/materialshader.h b/src/rendergraph/scenegraph/rendergraph/materialshader.h index e696a520b6b..fd87d03f174 100644 --- a/src/rendergraph/scenegraph/rendergraph/materialshader.h +++ b/src/rendergraph/scenegraph/rendergraph/materialshader.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace rendergraph { class AttributeSet; @@ -8,19 +8,25 @@ class UniformSet; class MaterialShader; } // namespace rendergraph -class rendergraph::MaterialShader { +class rendergraph::MaterialShader : public QSGMaterialShader { public: - class Impl; - MaterialShader(const char* vertexShaderFile, const char* fragmentShaderFile, const UniformSet& uniforms, const AttributeSet& attributeSet); ~MaterialShader(); - Impl& impl() const; - private: - MaterialShader(Impl* pImpl); + bool updateUniformData(RenderState& state, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) override; + + void updateSampledImage(RenderState& state, + int binding, + QSGTexture** texture, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) override; - const std::unique_ptr m_pImpl; + static QString resource(const char* filename) { + return QString(":/shaders/rendergraph/") + QString(filename) + QString(".qsb"); + } }; diff --git a/src/rendergraph/scenegraph/rendergraph/materialtype.cpp b/src/rendergraph/scenegraph/rendergraph/materialtype.cpp index 8249ee89f03..3839d6f5b8e 100644 --- a/src/rendergraph/scenegraph/rendergraph/materialtype.cpp +++ b/src/rendergraph/scenegraph/rendergraph/materialtype.cpp @@ -1,18 +1,6 @@ #include "rendergraph/materialtype.h" -#include "materialtype_impl.h" - using namespace rendergraph; -MaterialType::MaterialType(Impl* pImpl) - : m_pImpl(pImpl) { -} - -MaterialType::MaterialType() - : MaterialType(new MaterialType::Impl()){}; - +MaterialType::MaterialType() = default; MaterialType::~MaterialType() = default; - -MaterialType::Impl& MaterialType::impl() const { - return *m_pImpl; -} diff --git a/src/rendergraph/scenegraph/rendergraph/materialtype.h b/src/rendergraph/scenegraph/rendergraph/materialtype.h index 06d85f131cf..61a3d039c21 100644 --- a/src/rendergraph/scenegraph/rendergraph/materialtype.h +++ b/src/rendergraph/scenegraph/rendergraph/materialtype.h @@ -1,21 +1,13 @@ #pragma once -#include +#include namespace rendergraph { class MaterialType; } -class rendergraph::MaterialType { +class rendergraph::MaterialType : public QSGMaterialType { public: - class Impl; - MaterialType(); ~MaterialType(); - Impl& impl() const; - - private: - MaterialType(Impl* pImpl); - - const std::unique_ptr m_pImpl; }; diff --git a/src/rendergraph/scenegraph/rendergraph/node.cpp b/src/rendergraph/scenegraph/rendergraph/node.cpp index bd2ec2eed3e..eeb5dac09fb 100644 --- a/src/rendergraph/scenegraph/rendergraph/node.cpp +++ b/src/rendergraph/scenegraph/rendergraph/node.cpp @@ -1,35 +1,6 @@ #include "rendergraph/node.h" -#include "node_impl.h" - using namespace rendergraph; -Node::Node(NodeImplBase* pImpl) - : m_pImpl(pImpl) { -} - -Node::Node() - : Node(new Node::Impl(this)) { -} - +Node::Node() = default; Node::~Node() = default; - -NodeImplBase& Node::impl() const { - return *m_pImpl; -} - -void Node::setUsePreprocess(bool value) { - impl().setUsePreprocess(value); -} - -void Node::onAppendChildNode(Node* pChild) { - impl().onAppendChildNode(pChild); -} - -void Node::onRemoveChildNode(Node* pChild) { - impl().onRemoveChildNode(pChild); -} - -void Node::onRemoveAllChildNodes() { - impl().onRemoveAllChildNodes(); -} diff --git a/src/rendergraph/scenegraph/rendergraph/node.h b/src/rendergraph/scenegraph/rendergraph/node.h index cd8b8646767..e21000b3825 100644 --- a/src/rendergraph/scenegraph/rendergraph/node.h +++ b/src/rendergraph/scenegraph/rendergraph/node.h @@ -1,97 +1,16 @@ #pragma once -#include -#include +#include + +#include "rendergraph/nodebase.h" namespace rendergraph { class Node; -class NodeImplBase; +class NodeBase; } // namespace rendergraph -class rendergraph::Node { +class rendergraph::Node : public QSGNode, public rendergraph::NodeBase { public: - class Impl; - Node(); - - virtual ~Node(); - - void appendChildNode(std::unique_ptr&& pChild) { - auto pChildRawPtr = pChild.get(); - if (m_pLastChild) { - pChild->m_pPreviousSibling = m_pLastChild; - m_pLastChild->m_pNextSibling = std::move(pChild); - } else { - m_pFirstChild = std::move(pChild); - } - m_pLastChild = pChildRawPtr; - m_pLastChild->m_pParent = this; - onAppendChildNode(m_pLastChild); - } - std::unique_ptr removeAllChildNodes() { - onRemoveAllChildNodes(); - m_pLastChild = nullptr; - Node* pChild = m_pFirstChild.get(); - while (pChild) { - pChild->m_pParent = nullptr; - pChild = pChild->m_pNextSibling.get(); - } - return std::move(m_pFirstChild); - } - std::unique_ptr removeChildNode(Node* pChild) { - std::unique_ptr pRemoved; - if (pChild == m_pFirstChild.get()) { - pRemoved = std::move(m_pFirstChild); - m_pFirstChild = std::move(pChild->m_pNextSibling); - } else { - pRemoved = std::move(pChild->m_pPreviousSibling->m_pNextSibling); - pChild->m_pPreviousSibling->m_pNextSibling = std::move(pChild->m_pNextSibling); - pChild->m_pPreviousSibling = nullptr; - } - if (pChild == m_pLastChild) { - m_pLastChild = nullptr; - } - pChild->m_pParent = nullptr; - return pRemoved; - } - Node* parent() const { - return m_pParent; - } - Node* firstChild() const { - return m_pFirstChild.get(); - } - Node* lastChild() const { - return m_pLastChild; - } - Node* nextSibling() const { - return m_pNextSibling.get(); - } - Node* previousSibling() const { - return m_pPreviousSibling; - } - NodeImplBase& impl() const; - - virtual bool isSubtreeBlocked() const { - return false; - } - - virtual void preprocess() { - } - - void setUsePreprocess(bool value); - - protected: - Node(NodeImplBase* impl); - - private: - const std::unique_ptr m_pImpl; - Node* m_pParent{}; - std::unique_ptr m_pFirstChild; - Node* m_pLastChild{}; - std::unique_ptr m_pNextSibling; - Node* m_pPreviousSibling{}; - - void onAppendChildNode(Node* pChild); - void onRemoveChildNode(Node* pChild); - void onRemoveAllChildNodes(); + ~Node(); }; diff --git a/src/rendergraph/scenegraph/rendergraph/nodebase.cpp b/src/rendergraph/scenegraph/rendergraph/nodebase.cpp new file mode 100644 index 00000000000..7f1d0b333fa --- /dev/null +++ b/src/rendergraph/scenegraph/rendergraph/nodebase.cpp @@ -0,0 +1,61 @@ +#include "rendergraph/nodebase.h" + +#include + +using namespace rendergraph; + +NodeBase::NodeBase() = default; +NodeBase::~NodeBase() = default; + +QSGNode* NodeBase::sgNode() { + return dynamic_cast(this); +} + +void NodeBase::setUsePreprocess(bool value) { + sgNode()->setFlag(QSGNode::UsePreprocess, value); +} + +void NodeBase::appendChildNode(std::unique_ptr&& pChild) { + sgNode()->appendChildNode(pChild->sgNode()); + + auto pChildRawPtr = pChild.get(); + if (m_pLastChild) { + pChild->m_pPreviousSibling = m_pLastChild; + m_pLastChild->m_pNextSibling = std::move(pChild); + } else { + m_pFirstChild = std::move(pChild); + } + m_pLastChild = pChildRawPtr; + m_pLastChild->m_pParent = this; +} + +std::unique_ptr NodeBase::removeAllChildNodes() { + sgNode()->removeAllChildNodes(); + + m_pLastChild = nullptr; + NodeBase* pChild = m_pFirstChild.get(); + while (pChild) { + pChild->m_pParent = nullptr; + pChild = pChild->m_pNextSibling.get(); + } + return std::move(m_pFirstChild); +} + +std::unique_ptr NodeBase::removeChildNode(NodeBase* pChild) { + sgNode()->removeChildNode(pChild->sgNode()); + + std::unique_ptr pRemoved; + if (pChild == m_pFirstChild.get()) { + pRemoved = std::move(m_pFirstChild); + m_pFirstChild = std::move(pChild->m_pNextSibling); + } else { + pRemoved = std::move(pChild->m_pPreviousSibling->m_pNextSibling); + pChild->m_pPreviousSibling->m_pNextSibling = std::move(pChild->m_pNextSibling); + pChild->m_pPreviousSibling = nullptr; + } + if (pChild == m_pLastChild) { + m_pLastChild = nullptr; + } + pChild->m_pParent = nullptr; + return pRemoved; +} diff --git a/src/rendergraph/scenegraph/rendergraph/nodebase.h b/src/rendergraph/scenegraph/rendergraph/nodebase.h new file mode 100644 index 00000000000..193bb6bfe7a --- /dev/null +++ b/src/rendergraph/scenegraph/rendergraph/nodebase.h @@ -0,0 +1,46 @@ +#pragma once + +#include + +class QSGNode; + +namespace rendergraph { +class NodeBase; +} // namespace rendergraph + +class rendergraph::NodeBase { + public: + NodeBase(); + virtual ~NodeBase(); + + void appendChildNode(std::unique_ptr&& pChild); + std::unique_ptr removeAllChildNodes(); + std::unique_ptr removeChildNode(NodeBase* pChild); + + NodeBase* parent() const { + return m_pParent; + } + NodeBase* firstChild() const { + return m_pFirstChild.get(); + } + NodeBase* lastChild() const { + return m_pLastChild; + } + NodeBase* nextSibling() const { + return m_pNextSibling.get(); + } + NodeBase* previousSibling() const { + return m_pPreviousSibling; + } + + void setUsePreprocess(bool value); + + private: + QSGNode* sgNode(); + + NodeBase* m_pParent{}; + std::unique_ptr m_pFirstChild; + NodeBase* m_pLastChild{}; + std::unique_ptr m_pNextSibling; + NodeBase* m_pPreviousSibling{}; +}; diff --git a/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp b/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp index 9be655c4ee4..f953cb9ad30 100644 --- a/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp +++ b/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp @@ -1,19 +1,6 @@ #include "rendergraph/opacitynode.h" -#include "opacitynode_impl.h" - using namespace rendergraph; -OpacityNode::OpacityNode(NodeImplBase* pImpl) - : Node(pImpl) { -} - -OpacityNode::OpacityNode() - : OpacityNode(new OpacityNode::Impl(this)) { -} - +OpacityNode::OpacityNode() = default; OpacityNode::~OpacityNode() = default; - -void OpacityNode::setOpacity(float opacity) { - static_cast(impl()).setOpacity(opacity); -} diff --git a/src/rendergraph/scenegraph/rendergraph/opacitynode.h b/src/rendergraph/scenegraph/rendergraph/opacitynode.h index a95bc3a58f4..09da86f94ea 100644 --- a/src/rendergraph/scenegraph/rendergraph/opacitynode.h +++ b/src/rendergraph/scenegraph/rendergraph/opacitynode.h @@ -1,19 +1,15 @@ #pragma once +#include + #include "rendergraph/node.h" namespace rendergraph { class OpacityNode; } // namespace rendergraph -class rendergraph::OpacityNode : public rendergraph::Node { +class rendergraph::OpacityNode : public QSGOpacityNode, public rendergraph::NodeBase { public: - class Impl; - OpacityNode(); ~OpacityNode(); - void setOpacity(float opacity); - - private: - OpacityNode(NodeImplBase* pImpl); }; diff --git a/src/rendergraph/scenegraph/rendergraph/scenegraph.cpp b/src/rendergraph/scenegraph/rendergraph/scenegraph.cpp index efb0f63a0f8..314e086991d 100644 --- a/src/rendergraph/scenegraph/rendergraph/scenegraph.cpp +++ b/src/rendergraph/scenegraph/rendergraph/scenegraph.cpp @@ -1,16 +1,12 @@ #include "scenegraph.h" -#include "context_impl.h" -#include "node_impl.h" +#include "rendergraph/context.h" +#include "rendergraph/node.h" using namespace rendergraph; -QSGNode* rendergraph::sgNode(Node* pNode) { - return pNode->impl().sgNode(); -} - std::unique_ptr rendergraph::createSgContext(QQuickWindow* window) { auto context = std::make_unique(); - context->impl().setWindow(window); + context->setWindow(window); return context; } diff --git a/src/rendergraph/scenegraph/rendergraph/scenegraph.h b/src/rendergraph/scenegraph/rendergraph/scenegraph.h index 3924cf35119..e28c299d0b8 100644 --- a/src/rendergraph/scenegraph/rendergraph/scenegraph.h +++ b/src/rendergraph/scenegraph/rendergraph/scenegraph.h @@ -1,13 +1,11 @@ #pragma once -#include -#include #include +class QQuickWindow; + namespace rendergraph { class Context; -class Node; std::unique_ptr createSgContext(QQuickWindow* window); -QSGNode* sgNode(Node* pNode); } // namespace rendergraph diff --git a/src/rendergraph/scenegraph/rendergraph/texture.cpp b/src/rendergraph/scenegraph/rendergraph/texture.cpp index 3d16c12189e..1102aeb7d51 100644 --- a/src/rendergraph/scenegraph/rendergraph/texture.cpp +++ b/src/rendergraph/scenegraph/rendergraph/texture.cpp @@ -1,19 +1,14 @@ #include "rendergraph/texture.h" -#include "texture_impl.h" +#include +#include -using namespace rendergraph; +#include "rendergraph/context.h" -Texture::Texture(Impl* pImpl) - : m_pImpl(pImpl) { -} +using namespace rendergraph; Texture::Texture(Context& context, const QImage& image) - : Texture(new Texture::Impl(context, image)) { + : m_pTexture(context.window()->createTextureFromImage(image)) { } Texture::~Texture() = default; - -Texture::Impl& Texture::impl() const { - return *m_pImpl; -} diff --git a/src/rendergraph/scenegraph/rendergraph/texture.h b/src/rendergraph/scenegraph/rendergraph/texture.h index 8069a8192bb..f289056b789 100644 --- a/src/rendergraph/scenegraph/rendergraph/texture.h +++ b/src/rendergraph/scenegraph/rendergraph/texture.h @@ -1,22 +1,26 @@ #pragma once -#include +#include + +class QSGTexture; +class QImage; namespace rendergraph { class Context; class Texture; } // namespace rendergraph +// We can't use inheritance because QSGTexture has pure virtuals that we can't +// implement, so we encapsulate instead. class rendergraph::Texture { public: - class Impl; - Texture(Context& context, const QImage& image); ~Texture(); - Impl& impl() const; - private: - Texture(Impl* pImpl); + QSGTexture* sgTexture() const { + return m_pTexture.get(); + } - const std::unique_ptr m_pImpl; + private: + std::unique_ptr m_pTexture{}; }; diff --git a/src/rendergraph/scenegraph/rendergraph/types.cpp b/src/rendergraph/scenegraph/rendergraph/types.cpp index 654fa6567e1..211538e5af4 100644 --- a/src/rendergraph/scenegraph/rendergraph/types.cpp +++ b/src/rendergraph/scenegraph/rendergraph/types.cpp @@ -1,19 +1,19 @@ #include "rendergraph/types.h" #include -#include #include #include #include +#include using namespace rendergraph; int rendergraph::sizeOf(PrimitiveType type) { switch (type) { case PrimitiveType::UInt: - return sizeof(GLuint); + return sizeof(uint32_t); case PrimitiveType::Float: - return sizeof(GLfloat); + return sizeof(float); } return 0; } @@ -21,28 +21,28 @@ int rendergraph::sizeOf(PrimitiveType type) { int rendergraph::sizeOf(Type type) { switch (type) { case Type::UInt: - return sizeof(GLuint); + return sizeof(uint32_t); case Type::Float: - return sizeof(GLfloat); + return sizeof(float); case Type::Vector2D: - return sizeof(GLfloat) * 2; + return sizeof(float) * 2; case Type::Vector3D: - return sizeof(GLfloat) * 3; + return sizeof(float) * 3; case Type::Vector4D: - return sizeof(GLfloat) * 4; + return sizeof(float) * 4; case Type::Matrix4x4: - return sizeof(GLfloat) * 4 * 4; + return sizeof(float) * 4 * 4; } return 0; } template<> -Type rendergraph::typeOf() { +Type rendergraph::typeOf() { return Type::UInt; } template<> -Type rendergraph::typeOf() { +Type rendergraph::typeOf() { return Type::Float; } @@ -67,12 +67,12 @@ Type rendergraph::typeOf() { } template<> -PrimitiveType rendergraph::primitiveTypeOf() { +PrimitiveType rendergraph::primitiveTypeOf() { return PrimitiveType::Float; } template<> -PrimitiveType rendergraph::primitiveTypeOf() { +PrimitiveType rendergraph::primitiveTypeOf() { return PrimitiveType::UInt; } @@ -90,11 +90,11 @@ PrimitiveType rendergraph::primitiveTypeOf() { } template<> -int rendergraph::tupleSizeOf() { +int rendergraph::tupleSizeOf() { return 1; } template<> -int rendergraph::tupleSizeOf() { +int rendergraph::tupleSizeOf() { return 1; } template<> diff --git a/src/rendergraph/scenegraph/texture_impl.cpp b/src/rendergraph/scenegraph/texture_impl.cpp deleted file mode 100644 index 1416d4312e4..00000000000 --- a/src/rendergraph/scenegraph/texture_impl.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "texture_impl.h" - -#include "context_impl.h" - -using namespace rendergraph; - -Texture::Impl::Impl(Context& context, const QImage& image) - : m_pTexture(context.impl().window()->createTextureFromImage(image)) { -} From 1967817d863d28db28536e92cab57c97b998f051 Mon Sep 17 00:00:00 2001 From: m0dB Date: Thu, 19 Sep 2024 01:58:57 +0200 Subject: [PATCH 16/64] cleanup and moved common rendergraph files to common/rendergraph --- .../rendergraph/attribute.h | 0 .../rendergraph/types.h | 0 .../{opengl => common}/rendergraph/uniform.h | 0 .../rendergraph/uniformscache.cpp | 0 .../rendergraph/uniformscache.h | 0 .../rendergraph/uniformset.cpp | 0 .../rendergraph/uniformset.h | 0 src/rendergraph/opengl/CMakeLists.txt | 14 ++-- src/rendergraph/opengl/rendergraph/geometry.h | 2 + src/rendergraph/opengl/rendergraph/types.h | 36 ---------- src/rendergraph/scenegraph/CMakeLists.txt | 14 ++-- .../scenegraph/rendergraph/attribute.h | 31 --------- .../scenegraph/rendergraph/geometry.h | 4 +- .../scenegraph/rendergraph/material.cpp | 5 +- .../scenegraph/rendergraph/material.h | 4 ++ .../scenegraph/rendergraph/uniform.h | 28 -------- .../scenegraph/rendergraph/uniformscache.cpp | 28 -------- .../scenegraph/rendergraph/uniformscache.h | 67 ------------------- .../scenegraph/rendergraph/uniformset.cpp | 20 ------ .../scenegraph/rendergraph/uniformset.h | 30 --------- 20 files changed, 26 insertions(+), 257 deletions(-) rename src/rendergraph/{opengl => common}/rendergraph/attribute.h (100%) rename src/rendergraph/{scenegraph => common}/rendergraph/types.h (100%) rename src/rendergraph/{opengl => common}/rendergraph/uniform.h (100%) rename src/rendergraph/{opengl => common}/rendergraph/uniformscache.cpp (100%) rename src/rendergraph/{opengl => common}/rendergraph/uniformscache.h (100%) rename src/rendergraph/{opengl => common}/rendergraph/uniformset.cpp (100%) rename src/rendergraph/{opengl => common}/rendergraph/uniformset.h (100%) delete mode 100644 src/rendergraph/opengl/rendergraph/types.h delete mode 100644 src/rendergraph/scenegraph/rendergraph/attribute.h delete mode 100644 src/rendergraph/scenegraph/rendergraph/uniform.h delete mode 100644 src/rendergraph/scenegraph/rendergraph/uniformscache.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/uniformscache.h delete mode 100644 src/rendergraph/scenegraph/rendergraph/uniformset.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/uniformset.h diff --git a/src/rendergraph/opengl/rendergraph/attribute.h b/src/rendergraph/common/rendergraph/attribute.h similarity index 100% rename from src/rendergraph/opengl/rendergraph/attribute.h rename to src/rendergraph/common/rendergraph/attribute.h diff --git a/src/rendergraph/scenegraph/rendergraph/types.h b/src/rendergraph/common/rendergraph/types.h similarity index 100% rename from src/rendergraph/scenegraph/rendergraph/types.h rename to src/rendergraph/common/rendergraph/types.h diff --git a/src/rendergraph/opengl/rendergraph/uniform.h b/src/rendergraph/common/rendergraph/uniform.h similarity index 100% rename from src/rendergraph/opengl/rendergraph/uniform.h rename to src/rendergraph/common/rendergraph/uniform.h diff --git a/src/rendergraph/opengl/rendergraph/uniformscache.cpp b/src/rendergraph/common/rendergraph/uniformscache.cpp similarity index 100% rename from src/rendergraph/opengl/rendergraph/uniformscache.cpp rename to src/rendergraph/common/rendergraph/uniformscache.cpp diff --git a/src/rendergraph/opengl/rendergraph/uniformscache.h b/src/rendergraph/common/rendergraph/uniformscache.h similarity index 100% rename from src/rendergraph/opengl/rendergraph/uniformscache.h rename to src/rendergraph/common/rendergraph/uniformscache.h diff --git a/src/rendergraph/opengl/rendergraph/uniformset.cpp b/src/rendergraph/common/rendergraph/uniformset.cpp similarity index 100% rename from src/rendergraph/opengl/rendergraph/uniformset.cpp rename to src/rendergraph/common/rendergraph/uniformset.cpp diff --git a/src/rendergraph/opengl/rendergraph/uniformset.h b/src/rendergraph/common/rendergraph/uniformset.h similarity index 100% rename from src/rendergraph/opengl/rendergraph/uniformset.h rename to src/rendergraph/common/rendergraph/uniformset.h diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 5b8c9f81969..37477d4f421 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -1,5 +1,4 @@ add_library(rendergraph_gl - rendergraph/attribute.h rendergraph/attributeset.cpp rendergraph/attributeset.h rendergraph/context.cpp @@ -21,12 +20,6 @@ add_library(rendergraph_gl rendergraph/texture.cpp rendergraph/texture.h rendergraph/types.cpp - rendergraph/types.h - rendergraph/uniform.h - rendergraph/uniformscache.cpp - rendergraph/uniformscache.h - rendergraph/uniformset.cpp - rendergraph/uniformset.h ../common/rendergraph/material/endoftrackmaterial.cpp ../common/rendergraph/material/endoftrackmaterial.h ../common/rendergraph/material/patternmaterial.cpp @@ -39,6 +32,13 @@ add_library(rendergraph_gl ../common/rendergraph/material/rgbmaterial.h ../common/rendergraph/material/unicolormaterial.cpp ../common/rendergraph/material/unicolormaterial.h + ../common/rendergraph/attribute.h + ../common/rendergraph/types.h + ../common/rendergraph/uniform.h + ../common/rendergraph/uniformscache.cpp + ../common/rendergraph/uniformscache.h + ../common/rendergraph/uniformset.cpp + ../common/rendergraph/uniformset.h rendergraph/graph.cpp rendergraph/graph.h rendergraph/openglnode.cpp diff --git a/src/rendergraph/opengl/rendergraph/geometry.h b/src/rendergraph/opengl/rendergraph/geometry.h index a4fdf2fa90c..f85228cdbe8 100644 --- a/src/rendergraph/opengl/rendergraph/geometry.h +++ b/src/rendergraph/opengl/rendergraph/geometry.h @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include "rendergraph/types.h" diff --git a/src/rendergraph/opengl/rendergraph/types.h b/src/rendergraph/opengl/rendergraph/types.h deleted file mode 100644 index c8aea683757..00000000000 --- a/src/rendergraph/opengl/rendergraph/types.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -namespace rendergraph { - -enum class PrimitiveType { - UInt, - Float, -}; - -enum class Type { - UInt, - Float, - Vector2D, - Vector3D, - Vector4D, - Matrix4x4 -}; - -int sizeOf(Type type); -int sizeOf(PrimitiveType primitiveType); - -template -Type typeOf(); - -template -PrimitiveType primitiveTypeOf(); - -template -int tupleSizeOf(); - -} // namespace rendergraph diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index ebd4a16d791..bbcfada9666 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -1,5 +1,4 @@ add_library(rendergraph_sg - rendergraph/attribute.h rendergraph/attributeset.cpp rendergraph/attributeset.h rendergraph/context.cpp @@ -23,12 +22,6 @@ add_library(rendergraph_sg rendergraph/texture.cpp rendergraph/texture.h rendergraph/types.cpp - rendergraph/types.h - rendergraph/uniform.h - rendergraph/uniformscache.cpp - rendergraph/uniformscache.h - rendergraph/uniformset.cpp - rendergraph/uniformset.h rendergraph/scenegraph.cpp rendergraph/scenegraph.h ../common/rendergraph/material/endoftrackmaterial.cpp @@ -43,6 +36,13 @@ add_library(rendergraph_sg ../common/rendergraph/material/texturematerial.h ../common/rendergraph/material/unicolormaterial.cpp ../common/rendergraph/material/unicolormaterial.h + ../common/rendergraph/attribute.h + ../common/rendergraph/types.h + ../common/rendergraph/uniform.h + ../common/rendergraph/uniformscache.cpp + ../common/rendergraph/uniformscache.h + ../common/rendergraph/uniformset.cpp + ../common/rendergraph/uniformset.h ) target_link_libraries(rendergraph_sg PUBLIC diff --git a/src/rendergraph/scenegraph/rendergraph/attribute.h b/src/rendergraph/scenegraph/rendergraph/attribute.h deleted file mode 100644 index 5fae9e3df54..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/attribute.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/types.h" - -namespace rendergraph { -struct Attribute; -} - -struct rendergraph::Attribute { - const int m_tupleSize; - const PrimitiveType m_primitiveType; - const QString m_name; - - Attribute(int tupleSize, PrimitiveType primitiveType) - : m_tupleSize{tupleSize}, - m_primitiveType{primitiveType} { - } - - Attribute(int tupleSize, PrimitiveType primitiveType, QString name) - : m_tupleSize{tupleSize}, - m_primitiveType{primitiveType}, - m_name{std::move(name)} { - } - - template - static Attribute create() { - return Attribute(tupleSizeOf(), primitiveTypeOf()); - } -}; diff --git a/src/rendergraph/scenegraph/rendergraph/geometry.h b/src/rendergraph/scenegraph/rendergraph/geometry.h index e527346d63a..edfeba17e49 100644 --- a/src/rendergraph/scenegraph/rendergraph/geometry.h +++ b/src/rendergraph/scenegraph/rendergraph/geometry.h @@ -53,6 +53,8 @@ class rendergraph::Geometry : public QSGGeometry { Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount); ~Geometry(); + void allocate(int vertexCount); + void setAttributeValues(int attributePosition, const float* data, int numTuples); float* vertexData(); @@ -62,8 +64,6 @@ class rendergraph::Geometry : public QSGGeometry { return static_cast(QSGGeometry::vertexData()); } - void allocate(int vertexCount); - DrawingMode drawingMode() const; void setDrawingMode(DrawingMode mode); diff --git a/src/rendergraph/scenegraph/rendergraph/material.cpp b/src/rendergraph/scenegraph/rendergraph/material.cpp index 485349eda2b..b66123e0b2f 100644 --- a/src/rendergraph/scenegraph/rendergraph/material.cpp +++ b/src/rendergraph/scenegraph/rendergraph/material.cpp @@ -20,6 +20,9 @@ bool Material::updateUniformsByteArray(QByteArray* buf) { } QSGMaterialShader* Material::createShader(QSGRendererInterface::RenderMode) const { - auto pShader = createShader().release(); // This leaks + // This looks like a leak but it isn't: we pass ownership to Qt. Qt will + // cache and reuse the shader for all Material of the same type. + // TODO make sure that RenderMode is always the same. + auto pShader = createShader().release(); return pShader; } diff --git a/src/rendergraph/scenegraph/rendergraph/material.h b/src/rendergraph/scenegraph/rendergraph/material.h index 259c9818838..2a7ef637c9c 100644 --- a/src/rendergraph/scenegraph/rendergraph/material.h +++ b/src/rendergraph/scenegraph/rendergraph/material.h @@ -46,6 +46,10 @@ class rendergraph::Material : public QSGMaterial { QSGMaterialShader* createShader(QSGRendererInterface::RenderMode) const override; + int compare(const QSGMaterial* other) const override { + return compare(dynamic_cast(other)); + } + bool updateUniformsByteArray(QByteArray* buf); private: diff --git a/src/rendergraph/scenegraph/rendergraph/uniform.h b/src/rendergraph/scenegraph/rendergraph/uniform.h deleted file mode 100644 index 19a6a9c74a3..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/uniform.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/types.h" - -namespace rendergraph { -struct Uniform; -} - -struct rendergraph::Uniform { - const Type m_type; - const QString m_name; - - Uniform(Type type) - : m_type{type} { - } - - Uniform(Type type, QString name) - : m_type{type}, - m_name{std::move(name)} { - } - - template - static Uniform create() { - return Uniform(typeOf()); - } -}; diff --git a/src/rendergraph/scenegraph/rendergraph/uniformscache.cpp b/src/rendergraph/scenegraph/rendergraph/uniformscache.cpp deleted file mode 100644 index 3e43b60aab6..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/uniformscache.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "rendergraph/uniformscache.h" - -#include "rendergraph/uniformset.h" - -using namespace rendergraph; - -UniformsCache::UniformsCache(const UniformSet& uniformSet) { - int offset = 0; - for (const auto& uniform : uniformSet.uniforms()) { - const int size = sizeOf(uniform.m_type); - m_infos.push_back({uniform.m_type, offset}); - offset += size; - } - m_byteArray.resize(offset); - m_byteArray.fill('\0'); -} - -UniformsCache::~UniformsCache() = default; - -void UniformsCache::set(int uniformIndex, Type type, const void* ptr, int size) { - assert(type == m_infos[uniformIndex].m_type); - memcpy(m_byteArray.data() + m_infos[uniformIndex].m_offset, ptr, size); -} - -void UniformsCache::get(int uniformIndex, Type type, void* ptr, int size) const { - assert(type == m_infos[uniformIndex].m_type); - memcpy(ptr, m_byteArray.data() + m_infos[uniformIndex].m_offset, size); -} diff --git a/src/rendergraph/scenegraph/rendergraph/uniformscache.h b/src/rendergraph/scenegraph/rendergraph/uniformscache.h deleted file mode 100644 index 5787570effd..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/uniformscache.h +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "rendergraph/types.h" - -namespace rendergraph { -class UniformSet; -class UniformsCache; -} // namespace rendergraph - -class rendergraph::UniformsCache { - public: - UniformsCache(const UniformSet& uniformSet); - ~UniformsCache(); - - template - void set(int uniformIndex, const T& value) { - set(uniformIndex, typeOf(), static_cast(&value), sizeOf(typeOf())); - } - - template - T get(int uniformIndex) const { - T value; - get(uniformIndex, typeOf(), static_cast(&value), sizeof(T)); - return value; - } - Type type(int uniformIndex) const { - return m_infos[uniformIndex].m_type; - } - - const char* data() const { - return m_byteArray.data(); - } - qsizetype size() const { - return m_byteArray.size(); - } - int count() const { - return static_cast(m_infos.size()); - } - - private: - void set(int uniformIndex, Type type, const void* ptr, int size); - void get(int uniformIndex, Type type, void* ptr, int size) const; - - struct Info { - const Type m_type; - const int m_offset; - }; - - std::vector m_infos; - QByteArray m_byteArray; -}; - -template<> -inline void rendergraph::UniformsCache::set(int uniformIndex, const QColor& color) { - set(uniformIndex, QVector4D{color.redF(), color.greenF(), color.blueF(), color.alphaF()}); -} - -template<> -inline void rendergraph::UniformsCache::set( - int uniformIndex, const QMatrix4x4& matrix) { - set(uniformIndex, typeOf(), matrix.constData(), sizeOf(typeOf())); -} diff --git a/src/rendergraph/scenegraph/rendergraph/uniformset.cpp b/src/rendergraph/scenegraph/rendergraph/uniformset.cpp deleted file mode 100644 index 68e077613bd..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/uniformset.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "rendergraph/uniformset.h" - -using namespace rendergraph; - -UniformSet::UniformSet(std::initializer_list list, const std::vector& names) { - int i = 0; - for (auto item : list) { - add(Uniform{item.m_type, names[i++]}); - } -} - -UniformSet::~UniformSet() = default; - -void UniformSet::add(const Uniform& uniform) { - m_uniforms.push_back(uniform); -} - -const std::vector& UniformSet::uniforms() const { - return m_uniforms; -} diff --git a/src/rendergraph/scenegraph/rendergraph/uniformset.h b/src/rendergraph/scenegraph/rendergraph/uniformset.h deleted file mode 100644 index afa1cfc2426..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/uniformset.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#include -#include - -#include "rendergraph/uniform.h" - -namespace rendergraph { -class UniformSet; -} - -class rendergraph::UniformSet { - public: - UniformSet(std::initializer_list list, const std::vector& names); - - ~UniformSet(); - - const std::vector& uniforms() const; - - private: - void add(const Uniform& uniform); - std::vector m_uniforms; -}; - -namespace rendergraph { -template -UniformSet makeUniformSet(const std::vector& names) { - return UniformSet({(Uniform::create())...}, names); -} -} // namespace rendergraph From 88013d4fd44df33f07686aa8fb97822a9eab7e52 Mon Sep 17 00:00:00 2001 From: m0dB Date: Thu, 19 Sep 2024 12:57:46 +0200 Subject: [PATCH 17/64] remove nodebase, use encapsulation for scenegraph Node --- .../examples/gl_example/window.cpp | 8 +-- .../examples/sg_example/customitem.cpp | 10 +-- .../examples/sg_example/customitem.h | 4 +- src/rendergraph/scenegraph/CMakeLists.txt | 2 - .../scenegraph/rendergraph/geometrynode.cpp | 5 +- .../scenegraph/rendergraph/geometrynode.h | 4 +- .../scenegraph/rendergraph/node.cpp | 52 +++++++++++++++- src/rendergraph/scenegraph/rendergraph/node.h | 61 +++++++++++++++++-- .../scenegraph/rendergraph/nodebase.cpp | 61 ------------------- .../scenegraph/rendergraph/nodebase.h | 46 -------------- .../scenegraph/rendergraph/opacitynode.cpp | 5 +- .../scenegraph/rendergraph/opacitynode.h | 2 +- 12 files changed, 127 insertions(+), 133 deletions(-) delete mode 100644 src/rendergraph/scenegraph/rendergraph/nodebase.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/nodebase.h diff --git a/src/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/examples/gl_example/window.cpp index a74fc3afab3..ef8f6ac111f 100644 --- a/src/rendergraph/examples/gl_example/window.cpp +++ b/src/rendergraph/examples/gl_example/window.cpp @@ -17,14 +17,14 @@ void Window::closeEvent(QCloseEvent*) { void Window::initializeGL() { auto node = std::make_unique(); - node->appendChildNode(std::make_unique()); - node->appendChildNode(std::make_unique()); - node->appendChildNode(std::make_unique()); + node->Node::appendChildNode(std::make_unique()); + node->Node::appendChildNode(std::make_unique()); + node->Node::appendChildNode(std::make_unique()); { QImage img(":/example/images/test.png"); rendergraph::Context context; - static_cast(node->lastChild()) + static_cast(node->Node::lastChild()) ->setTexture( std::make_unique(context, img)); } diff --git a/src/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/examples/sg_example/customitem.cpp index 5e2b2f78403..228e8abb364 100644 --- a/src/rendergraph/examples/sg_example/customitem.cpp +++ b/src/rendergraph/examples/sg_example/customitem.cpp @@ -32,19 +32,19 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { bgNode->setRect(boundingRect()); m_node = std::make_unique(); - m_node->appendChildNode(std::make_unique()); - m_node->appendChildNode(std::make_unique()); - m_node->appendChildNode(std::make_unique()); + m_node->Node::appendChildNode(std::make_unique()); + m_node->Node::appendChildNode(std::make_unique()); + m_node->Node::appendChildNode(std::make_unique()); { QImage img(":/example/images/test.png"); auto context = rendergraph::createSgContext(window()); - static_cast(m_node->lastChild()) + static_cast(m_node->Node::lastChild()) ->setTexture(std::make_unique( *context, img)); } - bgNode->appendChildNode(dynamic_cast(m_node.get())); + bgNode->appendChildNode(m_node->sgNode()); node = bgNode; } else { diff --git a/src/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/examples/sg_example/customitem.h index 23d9a021fc1..304fb5c8f5e 100644 --- a/src/rendergraph/examples/sg_example/customitem.h +++ b/src/rendergraph/examples/sg_example/customitem.h @@ -4,7 +4,7 @@ #include namespace rendergraph { -class NodeBase; +class Node; } class CustomItem : public QQuickItem { @@ -20,7 +20,7 @@ class CustomItem : public QQuickItem { void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override; bool m_geometryChanged{}; - std::unique_ptr m_node; + std::unique_ptr m_node; }; #endif // CUSTOMITEM_H diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index bbcfada9666..df2c07f227b 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -15,8 +15,6 @@ add_library(rendergraph_sg rendergraph/materialtype.h rendergraph/node.cpp rendergraph/node.h - rendergraph/nodebase.cpp - rendergraph/nodebase.h rendergraph/opacitynode.cpp rendergraph/opacitynode.h rendergraph/texture.cpp diff --git a/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp b/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp index 2a07129edd5..38b80500cb7 100644 --- a/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp +++ b/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp @@ -4,7 +4,10 @@ using namespace rendergraph; -GeometryNode::GeometryNode() = default; +GeometryNode::GeometryNode() + : Node(this) { +} + GeometryNode::~GeometryNode() = default; void GeometryNode::setGeometry(std::unique_ptr geometry) { diff --git a/src/rendergraph/scenegraph/rendergraph/geometrynode.h b/src/rendergraph/scenegraph/rendergraph/geometrynode.h index caeb0c58fd3..c098e69ce1d 100644 --- a/src/rendergraph/scenegraph/rendergraph/geometrynode.h +++ b/src/rendergraph/scenegraph/rendergraph/geometrynode.h @@ -3,7 +3,7 @@ #include #include "rendergraph/geometry.h" -#include "rendergraph/nodebase.h" +#include "rendergraph/node.h" namespace rendergraph { class GeometryNode; @@ -11,7 +11,7 @@ class Geometry; class Material; } // namespace rendergraph -class rendergraph::GeometryNode : public QSGGeometryNode, public rendergraph::NodeBase { +class rendergraph::GeometryNode : public QSGGeometryNode, public rendergraph::Node { public: GeometryNode(); ~GeometryNode(); diff --git a/src/rendergraph/scenegraph/rendergraph/node.cpp b/src/rendergraph/scenegraph/rendergraph/node.cpp index eeb5dac09fb..c5b852b5485 100644 --- a/src/rendergraph/scenegraph/rendergraph/node.cpp +++ b/src/rendergraph/scenegraph/rendergraph/node.cpp @@ -1,6 +1,54 @@ #include "rendergraph/node.h" +#include + using namespace rendergraph; -Node::Node() = default; -Node::~Node() = default; +void Node::setUsePreprocess(bool value) { + sgNode()->setFlag(QSGNode::UsePreprocess, value); +} + +void Node::appendChildNode(std::unique_ptr&& pChild) { + sgNode()->appendChildNode(pChild->sgNode()); + + auto pChildRawPtr = pChild.get(); + if (m_pLastChild) { + pChild->m_pPreviousSibling = m_pLastChild; + m_pLastChild->m_pNextSibling = std::move(pChild); + } else { + m_pFirstChild = std::move(pChild); + } + m_pLastChild = pChildRawPtr; + m_pLastChild->m_pParent = this; +} + +std::unique_ptr Node::removeAllChildNodes() { + sgNode()->removeAllChildNodes(); + + m_pLastChild = nullptr; + Node* pChild = m_pFirstChild.get(); + while (pChild) { + pChild->m_pParent = nullptr; + pChild = pChild->m_pNextSibling.get(); + } + return std::move(m_pFirstChild); +} + +std::unique_ptr Node::removeChildNode(Node* pChild) { + sgNode()->removeChildNode(pChild->sgNode()); + + std::unique_ptr pRemoved; + if (pChild == m_pFirstChild.get()) { + pRemoved = std::move(m_pFirstChild); + m_pFirstChild = std::move(pChild->m_pNextSibling); + } else { + pRemoved = std::move(pChild->m_pPreviousSibling->m_pNextSibling); + pChild->m_pPreviousSibling->m_pNextSibling = std::move(pChild->m_pNextSibling); + pChild->m_pPreviousSibling = nullptr; + } + if (pChild == m_pLastChild) { + m_pLastChild = nullptr; + } + pChild->m_pParent = nullptr; + return pRemoved; +} diff --git a/src/rendergraph/scenegraph/rendergraph/node.h b/src/rendergraph/scenegraph/rendergraph/node.h index e21000b3825..97677ea46ab 100644 --- a/src/rendergraph/scenegraph/rendergraph/node.h +++ b/src/rendergraph/scenegraph/rendergraph/node.h @@ -1,16 +1,65 @@ #pragma once #include - -#include "rendergraph/nodebase.h" +#include namespace rendergraph { class Node; -class NodeBase; } // namespace rendergraph -class rendergraph::Node : public QSGNode, public rendergraph::NodeBase { +class rendergraph::Node { public: - Node(); - ~Node(); + // We can't derive from QSGNode, as we need to avoid ambiguous names and + // the diamond problem, so for the base class we use encapsulation. The + // derived classes (GeometryNode, OpacityNode) do arrive from Node and + // from their Qt scene graph counterpart and pass their pointer to the + // constructor. + Node() + : m_pSgNode(new QSGNode), + m_ownSgNode(true) { + } + Node(QSGNode* sgNode) + : m_pSgNode(sgNode), + m_ownSgNode(false) { + } + virtual ~Node() { + if (m_ownSgNode) { + delete m_pSgNode; + } + } + + void appendChildNode(std::unique_ptr&& pChild); + std::unique_ptr removeAllChildNodes(); + std::unique_ptr removeChildNode(Node* pChild); + + Node* parent() const { + return m_pParent; + } + Node* firstChild() const { + return m_pFirstChild.get(); + } + Node* lastChild() const { + return m_pLastChild; + } + Node* nextSibling() const { + return m_pNextSibling.get(); + } + Node* previousSibling() const { + return m_pPreviousSibling; + } + + void setUsePreprocess(bool value); + + QSGNode* sgNode() { + return m_pSgNode; + } + + private: + QSGNode* m_pSgNode; + bool m_ownSgNode; + Node* m_pParent{}; + std::unique_ptr m_pFirstChild; + Node* m_pLastChild{}; + std::unique_ptr m_pNextSibling; + Node* m_pPreviousSibling{}; }; diff --git a/src/rendergraph/scenegraph/rendergraph/nodebase.cpp b/src/rendergraph/scenegraph/rendergraph/nodebase.cpp deleted file mode 100644 index 7f1d0b333fa..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/nodebase.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "rendergraph/nodebase.h" - -#include - -using namespace rendergraph; - -NodeBase::NodeBase() = default; -NodeBase::~NodeBase() = default; - -QSGNode* NodeBase::sgNode() { - return dynamic_cast(this); -} - -void NodeBase::setUsePreprocess(bool value) { - sgNode()->setFlag(QSGNode::UsePreprocess, value); -} - -void NodeBase::appendChildNode(std::unique_ptr&& pChild) { - sgNode()->appendChildNode(pChild->sgNode()); - - auto pChildRawPtr = pChild.get(); - if (m_pLastChild) { - pChild->m_pPreviousSibling = m_pLastChild; - m_pLastChild->m_pNextSibling = std::move(pChild); - } else { - m_pFirstChild = std::move(pChild); - } - m_pLastChild = pChildRawPtr; - m_pLastChild->m_pParent = this; -} - -std::unique_ptr NodeBase::removeAllChildNodes() { - sgNode()->removeAllChildNodes(); - - m_pLastChild = nullptr; - NodeBase* pChild = m_pFirstChild.get(); - while (pChild) { - pChild->m_pParent = nullptr; - pChild = pChild->m_pNextSibling.get(); - } - return std::move(m_pFirstChild); -} - -std::unique_ptr NodeBase::removeChildNode(NodeBase* pChild) { - sgNode()->removeChildNode(pChild->sgNode()); - - std::unique_ptr pRemoved; - if (pChild == m_pFirstChild.get()) { - pRemoved = std::move(m_pFirstChild); - m_pFirstChild = std::move(pChild->m_pNextSibling); - } else { - pRemoved = std::move(pChild->m_pPreviousSibling->m_pNextSibling); - pChild->m_pPreviousSibling->m_pNextSibling = std::move(pChild->m_pNextSibling); - pChild->m_pPreviousSibling = nullptr; - } - if (pChild == m_pLastChild) { - m_pLastChild = nullptr; - } - pChild->m_pParent = nullptr; - return pRemoved; -} diff --git a/src/rendergraph/scenegraph/rendergraph/nodebase.h b/src/rendergraph/scenegraph/rendergraph/nodebase.h deleted file mode 100644 index 193bb6bfe7a..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/nodebase.h +++ /dev/null @@ -1,46 +0,0 @@ -#pragma once - -#include - -class QSGNode; - -namespace rendergraph { -class NodeBase; -} // namespace rendergraph - -class rendergraph::NodeBase { - public: - NodeBase(); - virtual ~NodeBase(); - - void appendChildNode(std::unique_ptr&& pChild); - std::unique_ptr removeAllChildNodes(); - std::unique_ptr removeChildNode(NodeBase* pChild); - - NodeBase* parent() const { - return m_pParent; - } - NodeBase* firstChild() const { - return m_pFirstChild.get(); - } - NodeBase* lastChild() const { - return m_pLastChild; - } - NodeBase* nextSibling() const { - return m_pNextSibling.get(); - } - NodeBase* previousSibling() const { - return m_pPreviousSibling; - } - - void setUsePreprocess(bool value); - - private: - QSGNode* sgNode(); - - NodeBase* m_pParent{}; - std::unique_ptr m_pFirstChild; - NodeBase* m_pLastChild{}; - std::unique_ptr m_pNextSibling; - NodeBase* m_pPreviousSibling{}; -}; diff --git a/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp b/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp index f953cb9ad30..e4bb5e4a9c6 100644 --- a/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp +++ b/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp @@ -2,5 +2,8 @@ using namespace rendergraph; -OpacityNode::OpacityNode() = default; +OpacityNode::OpacityNode() + : Node(this) { +} + OpacityNode::~OpacityNode() = default; diff --git a/src/rendergraph/scenegraph/rendergraph/opacitynode.h b/src/rendergraph/scenegraph/rendergraph/opacitynode.h index 09da86f94ea..a8b93dfabf6 100644 --- a/src/rendergraph/scenegraph/rendergraph/opacitynode.h +++ b/src/rendergraph/scenegraph/rendergraph/opacitynode.h @@ -8,7 +8,7 @@ namespace rendergraph { class OpacityNode; } // namespace rendergraph -class rendergraph::OpacityNode : public QSGOpacityNode, public rendergraph::NodeBase { +class rendergraph::OpacityNode : public QSGOpacityNode, public rendergraph::Node { public: OpacityNode(); ~OpacityNode(); From b8bcb19c985f803e817f7210ea03bd6e4c0b891a Mon Sep 17 00:00:00 2001 From: m0dB Date: Thu, 19 Sep 2024 19:13:52 +0200 Subject: [PATCH 18/64] reorganized the code, with a public common API that is derived from the opengl or the scenegraph backend. --- src/rendergraph/README | 67 +++++++---- src/rendergraph/common/attributeset.cpp | 12 ++ .../node.cpp => common/basenode.cpp} | 29 ++--- src/rendergraph/common/node.cpp | 7 ++ .../rendergraph => common}/opacitynode.cpp | 4 +- .../rendergraph/attributeset.h | 16 +-- src/rendergraph/common/rendergraph/basenode.h | 60 ++++++++++ .../rendergraph/geometry.h | 15 +-- .../rendergraph/geometrynode.h | 14 +-- .../rendergraph/material.h | 18 +-- .../common/rendergraph/materialshader.h | 17 +++ .../common/rendergraph/materialtype.h | 10 ++ src/rendergraph/common/rendergraph/node.h | 13 +++ .../common/rendergraph/opacitynode.h | 14 +++ .../{opengl => common}/rendergraph/texture.h | 12 +- .../common/rendergraph/uniformscache.cpp | 1 - .../common/rendergraph/uniformscache.h | 2 +- .../common/rendergraph/uniformset.h | 1 + .../rendergraph => common}/types.cpp | 0 .../examples/common/examplenodes.cpp | 13 +++ .../examples/common/examplenodes.h | 7 ++ .../examples/gl_example/window.cpp | 28 ++--- src/rendergraph/examples/gl_example/window.h | 5 +- .../examples/sg_example/customitem.cpp | 18 +-- src/rendergraph/opengl/CMakeLists.txt | 105 ++++++++++------- .../opengl/backend/attributeset.cpp | 11 ++ src/rendergraph/opengl/backend/attributeset.h | 16 +++ src/rendergraph/opengl/backend/geometry.cpp | 41 +++++++ src/rendergraph/opengl/backend/geometry.h | 29 +++++ .../{rendergraph => backend}/geometrynode.cpp | 64 ++++------- src/rendergraph/opengl/backend/geometrynode.h | 19 ++++ .../{rendergraph => backend}/material.cpp | 17 +-- src/rendergraph/opengl/backend/material.h | 27 +++++ .../opengl/backend/materialshader.cpp | 18 +++ .../{rendergraph => backend}/materialshader.h | 23 ++-- src/rendergraph/opengl/backend/materialtype.h | 8 ++ src/rendergraph/opengl/backend/node.h | 44 +++++++ src/rendergraph/opengl/backend/opacitynode.h | 23 ++++ src/rendergraph/opengl/backend/openglnode.cpp | 21 ++++ src/rendergraph/opengl/backend/openglnode.h | 20 ++++ src/rendergraph/opengl/backend/shadercache.h | 48 ++++++++ src/rendergraph/opengl/backend/texture.h | 7 ++ src/rendergraph/opengl/basenode.cpp | 21 ++++ .../{rendergraph/graph.cpp => engine.cpp} | 44 ++++--- src/rendergraph/opengl/geometry.cpp | 44 +++++++ src/rendergraph/opengl/geometrynode.cpp | 23 ++++ src/rendergraph/opengl/material.cpp | 9 ++ .../{rendergraph => }/materialshader.cpp | 25 ---- src/rendergraph/opengl/openglnode.cpp | 7 ++ .../opengl/rendergraph/attributeset.cpp | 23 ---- .../opengl/rendergraph/context.cpp | 6 - src/rendergraph/opengl/rendergraph/context.h | 3 - src/rendergraph/opengl/rendergraph/engine.h | 29 +++++ .../rendergraph/examples/CMakeLists.txt | 11 -- .../opengl/rendergraph/examples/README | 6 - .../examples/common/CMakeLists.txt | 12 -- .../examples/common/examplenodes.cpp | 60 ---------- .../examples/common/examplenodes.h | 36 ------ .../examples/gl_example/CMakeLists.txt | 39 ------- .../examples/gl_example/images/test.png | Bin 12849 -> 0 bytes .../rendergraph/examples/gl_example/main.cpp | 12 -- .../examples/gl_example/window.cpp | 48 -------- .../rendergraph/examples/gl_example/window.h | 23 ---- .../examples/sg_example/CMakeLists.txt | 35 ------ .../examples/sg_example/customitem.cpp | 59 ---------- .../examples/sg_example/customitem.h | 26 ----- .../examples/sg_example/images/test.png | Bin 12849 -> 0 bytes .../rendergraph/examples/sg_example/main.cpp | 16 --- .../examples/sg_example/qml/main.qml | 13 --- .../opengl/rendergraph/geometry.cpp | 94 --------------- src/rendergraph/opengl/rendergraph/geometry.h | 83 -------------- src/rendergraph/opengl/rendergraph/graph.h | 28 ----- src/rendergraph/opengl/rendergraph/material.h | 63 ----------- .../material/endoftrackmaterial.cpp | 39 ------- .../rendergraph/material/endoftrackmaterial.h | 21 ---- .../rendergraph/material/patternmaterial.cpp | 39 ------- .../rendergraph/material/patternmaterial.h | 34 ------ .../rendergraph/material/rgbamaterial.cpp | 39 ------- .../rendergraph/material/rgbamaterial.h | 21 ---- .../rendergraph/material/rgbmaterial.cpp | 39 ------- .../opengl/rendergraph/material/rgbmaterial.h | 21 ---- .../rendergraph/material/texturematerial.cpp | 39 ------- .../rendergraph/material/texturematerial.h | 34 ------ .../rendergraph/material/unicolormaterial.cpp | 39 ------- .../rendergraph/material/unicolormaterial.h | 21 ---- .../opengl/rendergraph/materialtype.cpp | 6 - .../opengl/rendergraph/materialtype.h | 11 -- src/rendergraph/opengl/rendergraph/node.h | 74 ------------ .../opengl/rendergraph/opacitynode.cpp | 15 --- .../opengl/rendergraph/opacitynode.h | 18 --- .../opengl/rendergraph/openglnode.cpp | 22 ---- .../opengl/rendergraph/openglnode.h | 12 +- .../opengl/rendergraph/shadercache.h | 40 ------- src/rendergraph/opengl/rendergraph/types.cpp | 107 ------------------ .../opengl/{rendergraph => }/texture.cpp | 24 ++-- src/rendergraph/scenegraph/CMakeLists.txt | 95 +++++++++------- .../scenegraph/backend/attributeset.cpp | 32 ++++++ .../scenegraph/backend/attributeset.h | 40 +++++++ src/rendergraph/scenegraph/backend/geometry.h | 19 ++++ .../scenegraph/backend/geometrynode.h | 7 ++ .../scenegraph/backend/material.cpp | 28 +++++ src/rendergraph/scenegraph/backend/material.h | 19 ++++ .../scenegraph/backend/materialshader.cpp | 22 ++++ .../{rendergraph => backend}/materialshader.h | 18 ++- .../scenegraph/backend/materialtype.h | 10 ++ src/rendergraph/scenegraph/backend/node.h | 7 ++ .../scenegraph/backend/opacitynode.h | 7 ++ src/rendergraph/scenegraph/backend/texture.h | 7 ++ src/rendergraph/scenegraph/basenode.cpp | 19 ++++ src/rendergraph/scenegraph/context.cpp | 11 ++ .../scenegraph/{rendergraph => }/geometry.cpp | 48 ++++---- src/rendergraph/scenegraph/geometrynode.cpp | 25 ++++ src/rendergraph/scenegraph/material.cpp | 10 ++ src/rendergraph/scenegraph/materialshader.cpp | 13 +++ .../scenegraph/rendergraph/attributeset.cpp | 42 ------- .../scenegraph/rendergraph/attributeset.h | 49 -------- .../scenegraph/rendergraph/context.cpp | 15 --- .../scenegraph/rendergraph/context.h | 7 +- .../scenegraph/rendergraph/geometrynode.cpp | 29 ----- .../scenegraph/rendergraph/geometrynode.h | 35 ------ .../scenegraph/rendergraph/material.cpp | 28 ----- .../scenegraph/rendergraph/materialshader.cpp | 34 ------ .../scenegraph/rendergraph/materialtype.cpp | 6 - .../scenegraph/rendergraph/materialtype.h | 13 --- .../scenegraph/rendergraph/node.cpp | 54 --------- src/rendergraph/scenegraph/rendergraph/node.h | 65 ----------- .../scenegraph/rendergraph/opacitynode.h | 15 --- .../scenegraph/rendergraph/scenegraph.cpp | 12 -- .../scenegraph/rendergraph/scenegraph.h | 11 -- .../scenegraph/rendergraph/texture.h | 26 ----- .../scenegraph/{rendergraph => }/texture.cpp | 6 - .../allshader/waveformrendermark.cpp | 8 +- .../renderers/allshader/waveformrendermark.h | 4 +- .../allshader/waveformrendermarkrange.cpp | 2 +- .../widgets/allshader/waveformwidget.cpp | 23 ++-- .../widgets/allshader/waveformwidget.h | 4 +- 136 files changed, 1230 insertions(+), 2232 deletions(-) create mode 100644 src/rendergraph/common/attributeset.cpp rename src/rendergraph/{opengl/rendergraph/node.cpp => common/basenode.cpp} (68%) create mode 100644 src/rendergraph/common/node.cpp rename src/rendergraph/{scenegraph/rendergraph => common}/opacitynode.cpp (60%) rename src/rendergraph/{opengl => common}/rendergraph/attributeset.h (62%) create mode 100644 src/rendergraph/common/rendergraph/basenode.h rename src/rendergraph/{scenegraph => common}/rendergraph/geometry.h (81%) rename src/rendergraph/{opengl => common}/rendergraph/geometrynode.h (78%) rename src/rendergraph/{scenegraph => common}/rendergraph/material.h (71%) create mode 100644 src/rendergraph/common/rendergraph/materialshader.h create mode 100644 src/rendergraph/common/rendergraph/materialtype.h create mode 100644 src/rendergraph/common/rendergraph/node.h create mode 100644 src/rendergraph/common/rendergraph/opacitynode.h rename src/rendergraph/{opengl => common}/rendergraph/texture.h (52%) rename src/rendergraph/{scenegraph/rendergraph => common}/types.cpp (100%) create mode 100644 src/rendergraph/opengl/backend/attributeset.cpp create mode 100644 src/rendergraph/opengl/backend/attributeset.h create mode 100644 src/rendergraph/opengl/backend/geometry.cpp create mode 100644 src/rendergraph/opengl/backend/geometry.h rename src/rendergraph/opengl/{rendergraph => backend}/geometrynode.cpp (65%) create mode 100644 src/rendergraph/opengl/backend/geometrynode.h rename src/rendergraph/opengl/{rendergraph => backend}/material.cpp (56%) create mode 100644 src/rendergraph/opengl/backend/material.h create mode 100644 src/rendergraph/opengl/backend/materialshader.cpp rename src/rendergraph/opengl/{rendergraph => backend}/materialshader.h (58%) create mode 100644 src/rendergraph/opengl/backend/materialtype.h create mode 100644 src/rendergraph/opengl/backend/node.h create mode 100644 src/rendergraph/opengl/backend/opacitynode.h create mode 100644 src/rendergraph/opengl/backend/openglnode.cpp create mode 100644 src/rendergraph/opengl/backend/openglnode.h create mode 100644 src/rendergraph/opengl/backend/shadercache.h create mode 100644 src/rendergraph/opengl/backend/texture.h create mode 100644 src/rendergraph/opengl/basenode.cpp rename src/rendergraph/opengl/{rendergraph/graph.cpp => engine.cpp} (52%) create mode 100644 src/rendergraph/opengl/geometry.cpp create mode 100644 src/rendergraph/opengl/geometrynode.cpp create mode 100644 src/rendergraph/opengl/material.cpp rename src/rendergraph/opengl/{rendergraph => }/materialshader.cpp (55%) create mode 100644 src/rendergraph/opengl/openglnode.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/attributeset.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/context.cpp create mode 100644 src/rendergraph/opengl/rendergraph/engine.h delete mode 100644 src/rendergraph/opengl/rendergraph/examples/CMakeLists.txt delete mode 100644 src/rendergraph/opengl/rendergraph/examples/README delete mode 100644 src/rendergraph/opengl/rendergraph/examples/common/CMakeLists.txt delete mode 100644 src/rendergraph/opengl/rendergraph/examples/common/examplenodes.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/examples/common/examplenodes.h delete mode 100644 src/rendergraph/opengl/rendergraph/examples/gl_example/CMakeLists.txt delete mode 100644 src/rendergraph/opengl/rendergraph/examples/gl_example/images/test.png delete mode 100644 src/rendergraph/opengl/rendergraph/examples/gl_example/main.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/examples/gl_example/window.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/examples/gl_example/window.h delete mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/CMakeLists.txt delete mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.h delete mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/images/test.png delete mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/main.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/examples/sg_example/qml/main.qml delete mode 100644 src/rendergraph/opengl/rendergraph/geometry.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/geometry.h delete mode 100644 src/rendergraph/opengl/rendergraph/graph.h delete mode 100644 src/rendergraph/opengl/rendergraph/material.h delete mode 100644 src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.h delete mode 100644 src/rendergraph/opengl/rendergraph/material/patternmaterial.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/material/patternmaterial.h delete mode 100644 src/rendergraph/opengl/rendergraph/material/rgbamaterial.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/material/rgbamaterial.h delete mode 100644 src/rendergraph/opengl/rendergraph/material/rgbmaterial.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/material/rgbmaterial.h delete mode 100644 src/rendergraph/opengl/rendergraph/material/texturematerial.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/material/texturematerial.h delete mode 100644 src/rendergraph/opengl/rendergraph/material/unicolormaterial.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/material/unicolormaterial.h delete mode 100644 src/rendergraph/opengl/rendergraph/materialtype.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/materialtype.h delete mode 100644 src/rendergraph/opengl/rendergraph/node.h delete mode 100644 src/rendergraph/opengl/rendergraph/opacitynode.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/opacitynode.h delete mode 100644 src/rendergraph/opengl/rendergraph/openglnode.cpp delete mode 100644 src/rendergraph/opengl/rendergraph/shadercache.h delete mode 100644 src/rendergraph/opengl/rendergraph/types.cpp rename src/rendergraph/opengl/{rendergraph => }/texture.cpp (71%) create mode 100644 src/rendergraph/scenegraph/backend/attributeset.cpp create mode 100644 src/rendergraph/scenegraph/backend/attributeset.h create mode 100644 src/rendergraph/scenegraph/backend/geometry.h create mode 100644 src/rendergraph/scenegraph/backend/geometrynode.h create mode 100644 src/rendergraph/scenegraph/backend/material.cpp create mode 100644 src/rendergraph/scenegraph/backend/material.h create mode 100644 src/rendergraph/scenegraph/backend/materialshader.cpp rename src/rendergraph/scenegraph/{rendergraph => backend}/materialshader.h (60%) create mode 100644 src/rendergraph/scenegraph/backend/materialtype.h create mode 100644 src/rendergraph/scenegraph/backend/node.h create mode 100644 src/rendergraph/scenegraph/backend/opacitynode.h create mode 100644 src/rendergraph/scenegraph/backend/texture.h create mode 100644 src/rendergraph/scenegraph/basenode.cpp create mode 100644 src/rendergraph/scenegraph/context.cpp rename src/rendergraph/scenegraph/{rendergraph => }/geometry.cpp (81%) create mode 100644 src/rendergraph/scenegraph/geometrynode.cpp create mode 100644 src/rendergraph/scenegraph/material.cpp create mode 100644 src/rendergraph/scenegraph/materialshader.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/attributeset.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/attributeset.h delete mode 100644 src/rendergraph/scenegraph/rendergraph/context.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/geometrynode.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/geometrynode.h delete mode 100644 src/rendergraph/scenegraph/rendergraph/material.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/materialshader.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/materialtype.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/materialtype.h delete mode 100644 src/rendergraph/scenegraph/rendergraph/node.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/node.h delete mode 100644 src/rendergraph/scenegraph/rendergraph/opacitynode.h delete mode 100644 src/rendergraph/scenegraph/rendergraph/scenegraph.cpp delete mode 100644 src/rendergraph/scenegraph/rendergraph/scenegraph.h delete mode 100644 src/rendergraph/scenegraph/rendergraph/texture.h rename src/rendergraph/scenegraph/{rendergraph => }/texture.cpp (75%) diff --git a/src/rendergraph/README b/src/rendergraph/README index 8110ef888f8..ccc4db3fbb8 100644 --- a/src/rendergraph/README +++ b/src/rendergraph/README @@ -1,29 +1,58 @@ -rendergraph is an abstraction layer that can be compiled to be used with QtQuick scene graph classes -or with QOpenGL classes. This abstraction layer follows the design of the QtQuick scene graph, with -classes such as Material, Geometry, Node and GeometryNode, but it only gives access to a subset of -its functionality. +rendergraph is an abstraction layer that can be compiled with one of two backends: -The rendergraph/scenegraph implementation calls the underlying scenegraph classes directly or almost -directly. The opengl/layer implementation class implements classes that mimic the behaviour of the -scenegraph classes. +- scenegraph (QtQuick scene graph classes) +- opengl (custom classes using QOpenGL) -The objective is to be able to write code that can be used both within the context of a QWidgets -applications and of a QML application. This includes using the same Vulkan-style GLSL shader code for -both. (The QSGMaterialShader uses the qsb files, QOpenGLShader uses the OpenGL shader code generated -by qsb) +This abstraction layer follows the design of the QtQuick scene graph, with classes such as Material, Geometry, Node and GeometryNode, but it only gives access to and only uses a subset of its functionality. -The common code is in library rendergraph, src/rendergraph +The scenegraph backend class the underlying QtQuick scene graph classes directly or almost directly. The opengl layer implements classes that mimic the behaviour of the +Qt scene graph classes. -The scene graph implementation is in library rendergraph_sg, src/rendergraph/scenegraph +The objective of rendergraph is to be able to write code that can be used verbatim within the context of both QWidgets applications and QML applications. This includes using the same Vulkan-style GLSL shader code for both. (The QSGMaterialShader uses the qsb files, QOpenGLShader uses the OpenGL shader code generated by qsb) -The OpenGL implementation is in library rendergraph_gl, src/rendergraph/opengl +Primarily, rendering with rendergraph uses a graph of Node's, typically of type GeometryNode. A GeometryNode uses a Geometry, which contains the vertex data of what the node renders (positional, texture coordinates, color information...) and a Material, which is the interface to the underlying shader. Uniform data is set through the Material. The QtQuick scene graph documentation is a good started point to understand the design. -Example shader and nodes are in library rendergraph_examples, in src/rendergraph/examples. -Note that this code is agnostic of the layer that it will be linked against. +The code is organized as follows: -Example applications are in src/rendergraph/example/sg_example and src/rendergraph/examples/gl_example, -which each link with rendergraph_examples and respectively with rendergraph_gl and rendergraph_sg. +common/rendergraph + Public header files. This is the primary API, identical for both backends, and the only files that should be included to write code compatible with both backends. + +common + Implementation of the functionality declared in the common/rendergraph headers that is identical for both backends. + +common/rendergraph/material + Several basic 'materials' for common rendering operations (e.g. uniform or variying color, texture) + +scenegraph + Implementation of the functionality declared in the common/rendergraph headers that is specific to call the scenegraph backend + +scenegraph/rendergraph + Public header files specific for the opengl backend. This is the layer between QtQuick application code and the common rendergraph API. + +scenegraph/backend + The scenegraph backend implementation, the layer between the common/rendergraph API and the underlying QtQuick scene graph classes. + +opengl + Implementation of the functionality declared in the common/rendergraph headers that is specific to call the opengl backend + +opengl/rendergraph + Public header files specific for the opengl backend. This is the layer between QWidgets/QOpenGL application code and the common rendergraph API. + +opengl/backend + The opengl backend implementation, the layer between the common/rendergraph API and custom implemented classes that mimic the behaviour QtQuick scene graph classes. + +Furthermore, some simple examples: + +examples/sg_example + An example QtQuick application that uses the scenegraph backend + +examples/gl_example + An example QOpenGLWindow based application that uses the opengl backend + +examples/common + The graphics code that is identical for both example + +More advanced use of rendergraph can be found in the waveform/renderers/allshader classes, which have partially been ported the rendergraph. -This is still very much work in progress! m0dB diff --git a/src/rendergraph/common/attributeset.cpp b/src/rendergraph/common/attributeset.cpp new file mode 100644 index 00000000000..c72df9ef21f --- /dev/null +++ b/src/rendergraph/common/attributeset.cpp @@ -0,0 +1,12 @@ +#include "rendergraph/attributeset.h" + +using namespace rendergraph; + +AttributeSet::AttributeSet(std::initializer_list list, + const std::vector& names) + : backend::AttributeSet(list, names) { +} + +const std::vector& AttributeSet::attributes() const { + return m_attributes; +} diff --git a/src/rendergraph/opengl/rendergraph/node.cpp b/src/rendergraph/common/basenode.cpp similarity index 68% rename from src/rendergraph/opengl/rendergraph/node.cpp rename to src/rendergraph/common/basenode.cpp index 810aeef83e6..fc97bf65a7d 100644 --- a/src/rendergraph/opengl/rendergraph/node.cpp +++ b/src/rendergraph/common/basenode.cpp @@ -1,14 +1,10 @@ -#include "rendergraph/node.h" +#include "rendergraph/basenode.h" -#include "rendergraph/graph.h" +#include "backend/node.h" using namespace rendergraph; -Node::Node() = default; - -Node::~Node() = default; - -void Node::appendChildNode(std::unique_ptr&& pChild) { +void BaseNode::appendChildNode(std::unique_ptr&& pChild) { auto pChildRawPtr = pChild.get(); if (m_pLastChild) { pChild->m_pPreviousSibling = m_pLastChild; @@ -18,21 +14,26 @@ void Node::appendChildNode(std::unique_ptr&& pChild) { } m_pLastChild = pChildRawPtr; m_pLastChild->m_pParent = this; - if (graph() != nullptr && graph() != pChildRawPtr->graph()) { - graph()->addToGraph(pChildRawPtr); - } + + onAppendChildNode(pChildRawPtr); } -std::unique_ptr Node::removeAllChildNodes() { + +std::unique_ptr BaseNode::removeAllChildNodes() { + onRemoveAllChildNodes(); + m_pLastChild = nullptr; - Node* pChild = m_pFirstChild.get(); + BaseNode* pChild = m_pFirstChild.get(); while (pChild) { pChild->m_pParent = nullptr; pChild = pChild->m_pNextSibling.get(); } return std::move(m_pFirstChild); } -std::unique_ptr Node::removeChildNode(Node* pChild) { - std::unique_ptr pRemoved; + +std::unique_ptr BaseNode::removeChildNode(BaseNode* pChild) { + onRemoveChildNode(pChild); + + std::unique_ptr pRemoved; if (pChild == m_pFirstChild.get()) { pRemoved = std::move(m_pFirstChild); m_pFirstChild = std::move(pChild->m_pNextSibling); diff --git a/src/rendergraph/common/node.cpp b/src/rendergraph/common/node.cpp new file mode 100644 index 00000000000..61bb0406e3a --- /dev/null +++ b/src/rendergraph/common/node.cpp @@ -0,0 +1,7 @@ +#include "rendergraph/node.h" + +using namespace rendergraph; + +Node::Node() + : BaseNode(this) { +} diff --git a/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp b/src/rendergraph/common/opacitynode.cpp similarity index 60% rename from src/rendergraph/scenegraph/rendergraph/opacitynode.cpp rename to src/rendergraph/common/opacitynode.cpp index e4bb5e4a9c6..dfe705c5389 100644 --- a/src/rendergraph/scenegraph/rendergraph/opacitynode.cpp +++ b/src/rendergraph/common/opacitynode.cpp @@ -3,7 +3,5 @@ using namespace rendergraph; OpacityNode::OpacityNode() - : Node(this) { + : BaseNode(this) { } - -OpacityNode::~OpacityNode() = default; diff --git a/src/rendergraph/opengl/rendergraph/attributeset.h b/src/rendergraph/common/rendergraph/attributeset.h similarity index 62% rename from src/rendergraph/opengl/rendergraph/attributeset.h rename to src/rendergraph/common/rendergraph/attributeset.h index 8d21921ee5e..6b970b9e1fd 100644 --- a/src/rendergraph/opengl/rendergraph/attributeset.h +++ b/src/rendergraph/common/rendergraph/attributeset.h @@ -1,27 +1,15 @@ #pragma once -#include -#include - -#include "rendergraph/attribute.h" +#include "backend/attributeset.h" namespace rendergraph { class AttributeSet; } -class rendergraph::AttributeSet { +class rendergraph::AttributeSet : public rendergraph::backend::AttributeSet { public: - AttributeSet(); AttributeSet(std::initializer_list list, const std::vector& names); - - ~AttributeSet(); - const std::vector& attributes() const; - - private: - void add(const Attribute& attribute); - - std::vector m_attributes; }; namespace rendergraph { diff --git a/src/rendergraph/common/rendergraph/basenode.h b/src/rendergraph/common/rendergraph/basenode.h new file mode 100644 index 00000000000..5a74d699884 --- /dev/null +++ b/src/rendergraph/common/rendergraph/basenode.h @@ -0,0 +1,60 @@ +#pragma once + +#include + +#include "backend/node.h" + +namespace rendergraph { +class BaseNode; +} // namespace rendergraph + +class rendergraph::BaseNode { + public: + BaseNode(rendergraph::backend::Node* pBackendNode) + : m_pBackendNode(pBackendNode) { + } + virtual ~BaseNode() = default; + + void appendChildNode(std::unique_ptr&& pChild); + std::unique_ptr removeAllChildNodes(); + std::unique_ptr removeChildNode(BaseNode* pChild); + + BaseNode* parent() const { + return m_pParent; + } + BaseNode* firstChild() const { + return m_pFirstChild.get(); + } + BaseNode* lastChild() const { + return m_pLastChild; + } + BaseNode* nextSibling() const { + return m_pNextSibling.get(); + } + BaseNode* previousSibling() const { + return m_pPreviousSibling; + } + + void setUsePreprocess(bool value); + + rendergraph::backend::Node* backendNode() { + return m_pBackendNode; + } + + virtual void initialize() { + } + virtual void resize(int, int) { + } + + private: + void onAppendChildNode(BaseNode* pChild); + void onRemoveAllChildNodes(); + void onRemoveChildNode(BaseNode* pChild); + + rendergraph::backend::Node* m_pBackendNode; + BaseNode* m_pParent{}; + std::unique_ptr m_pFirstChild; + BaseNode* m_pLastChild{}; + std::unique_ptr m_pNextSibling; + BaseNode* m_pPreviousSibling{}; +}; diff --git a/src/rendergraph/scenegraph/rendergraph/geometry.h b/src/rendergraph/common/rendergraph/geometry.h similarity index 81% rename from src/rendergraph/scenegraph/rendergraph/geometry.h rename to src/rendergraph/common/rendergraph/geometry.h index edfeba17e49..d5bbd01cebd 100644 --- a/src/rendergraph/scenegraph/rendergraph/geometry.h +++ b/src/rendergraph/common/rendergraph/geometry.h @@ -1,15 +1,16 @@ #pragma once -#include #include #include +#include "backend/geometry.h" +#include "rendergraph/attributeset.h" + namespace rendergraph { class Geometry; -class AttributeSet; } // namespace rendergraph -class rendergraph::Geometry : public QSGGeometry { +class rendergraph::Geometry : public rendergraph::backend::Geometry { public: struct Point2D { QVector2D position2D; @@ -61,15 +62,9 @@ class rendergraph::Geometry : public QSGGeometry { template T* vertexDataAs() { - return static_cast(QSGGeometry::vertexData()); + return reinterpret_cast(vertexData()); } DrawingMode drawingMode() const; void setDrawingMode(DrawingMode mode); - - private: - static QSGGeometry::DrawingMode toSgDrawingMode(Geometry::DrawingMode mode); - static Geometry::DrawingMode fromSgDrawingMode(unsigned int mode); - - const int m_stride; }; diff --git a/src/rendergraph/opengl/rendergraph/geometrynode.h b/src/rendergraph/common/rendergraph/geometrynode.h similarity index 78% rename from src/rendergraph/opengl/rendergraph/geometrynode.h rename to src/rendergraph/common/rendergraph/geometrynode.h index 4804f123d93..d2096b2450f 100644 --- a/src/rendergraph/opengl/rendergraph/geometrynode.h +++ b/src/rendergraph/common/rendergraph/geometrynode.h @@ -1,20 +1,18 @@ #pragma once -#include - +#include "backend/geometrynode.h" +#include "rendergraph/basenode.h" #include "rendergraph/geometry.h" #include "rendergraph/material.h" -#include "rendergraph/node.h" namespace rendergraph { class GeometryNode; -class Material; } // namespace rendergraph -class rendergraph::GeometryNode : public rendergraph::Node, public QOpenGLFunctions { +class rendergraph::GeometryNode : public rendergraph::backend::GeometryNode, + public rendergraph::BaseNode { public: GeometryNode(); - ~GeometryNode(); template void initForRectangles(int numRectangles) { @@ -25,11 +23,9 @@ class rendergraph::GeometryNode : public rendergraph::Node, public QOpenGLFuncti geometry().setDrawingMode(Geometry::DrawingMode::Triangles); } - void initialize() override; - void render() override; - void setMaterial(std::unique_ptr material); void setGeometry(std::unique_ptr geometry); + Geometry& geometry() const; Material& material() const; diff --git a/src/rendergraph/scenegraph/rendergraph/material.h b/src/rendergraph/common/rendergraph/material.h similarity index 71% rename from src/rendergraph/scenegraph/rendergraph/material.h rename to src/rendergraph/common/rendergraph/material.h index 2a7ef637c9c..e3cb05b93cc 100644 --- a/src/rendergraph/scenegraph/rendergraph/material.h +++ b/src/rendergraph/common/rendergraph/material.h @@ -1,21 +1,19 @@ #pragma once -#include #include +#include "backend/material.h" +#include "rendergraph/materialshader.h" #include "rendergraph/materialtype.h" #include "rendergraph/texture.h" #include "rendergraph/uniformscache.h" +#include "rendergraph/uniformset.h" namespace rendergraph { -class UniformSet; class Material; -class MaterialShader; -class MaterialType; -class Texture; } // namespace rendergraph -class rendergraph::Material : public QSGMaterial { +class rendergraph::Material : public rendergraph::backend::Material { public: Material(const UniformSet& uniformSet); virtual ~Material(); @@ -44,14 +42,6 @@ class rendergraph::Material : public QSGMaterial { return nullptr; } - QSGMaterialShader* createShader(QSGRendererInterface::RenderMode) const override; - - int compare(const QSGMaterial* other) const override { - return compare(dynamic_cast(other)); - } - - bool updateUniformsByteArray(QByteArray* buf); - private: UniformsCache m_uniformsCache; bool m_uniformsCacheDirty{}; diff --git a/src/rendergraph/common/rendergraph/materialshader.h b/src/rendergraph/common/rendergraph/materialshader.h new file mode 100644 index 00000000000..a1e2411256a --- /dev/null +++ b/src/rendergraph/common/rendergraph/materialshader.h @@ -0,0 +1,17 @@ +#pragma once + +#include "backend/materialshader.h" +#include "rendergraph/attributeset.h" +#include "rendergraph/uniformset.h" + +namespace rendergraph { +class MaterialShader; +} // namespace rendergraph + +class rendergraph::MaterialShader : public rendergraph::backend::MaterialShader { + public: + MaterialShader(const char* vertexShaderFile, + const char* fragmentShaderFile, + const UniformSet& uniforms, + const AttributeSet& attributeSet); +}; diff --git a/src/rendergraph/common/rendergraph/materialtype.h b/src/rendergraph/common/rendergraph/materialtype.h new file mode 100644 index 00000000000..e2c85391049 --- /dev/null +++ b/src/rendergraph/common/rendergraph/materialtype.h @@ -0,0 +1,10 @@ +#pragma once + +#include "backend/materialtype.h" + +namespace rendergraph { +class MaterialType; +} + +class rendergraph::MaterialType : public rendergraph::backend::MaterialType { +}; diff --git a/src/rendergraph/common/rendergraph/node.h b/src/rendergraph/common/rendergraph/node.h new file mode 100644 index 00000000000..6eb1c8c737d --- /dev/null +++ b/src/rendergraph/common/rendergraph/node.h @@ -0,0 +1,13 @@ +#pragma once + +#include "backend/node.h" +#include "rendergraph/basenode.h" + +namespace rendergraph { +class Node; +} // namespace rendergraph + +class rendergraph::Node : public rendergraph::backend::Node, public rendergraph::BaseNode { + public: + Node(); +}; diff --git a/src/rendergraph/common/rendergraph/opacitynode.h b/src/rendergraph/common/rendergraph/opacitynode.h new file mode 100644 index 00000000000..2bd868daa12 --- /dev/null +++ b/src/rendergraph/common/rendergraph/opacitynode.h @@ -0,0 +1,14 @@ +#pragma once + +#include "backend/opacitynode.h" +#include "rendergraph/basenode.h" + +namespace rendergraph { +class OpacityNode; +} // namespace rendergraph + +class rendergraph::OpacityNode : public rendergraph::backend::OpacityNode, + public rendergraph::BaseNode { + public: + OpacityNode(); +}; diff --git a/src/rendergraph/opengl/rendergraph/texture.h b/src/rendergraph/common/rendergraph/texture.h similarity index 52% rename from src/rendergraph/opengl/rendergraph/texture.h rename to src/rendergraph/common/rendergraph/texture.h index a130e13d8b7..a9dac6d790e 100644 --- a/src/rendergraph/opengl/rendergraph/texture.h +++ b/src/rendergraph/common/rendergraph/texture.h @@ -1,9 +1,9 @@ #pragma once +#include #include -class QImage; -class QOpenGLTexture; +#include "backend/texture.h" namespace rendergraph { class Context; @@ -13,11 +13,11 @@ class Texture; class rendergraph::Texture { public: Texture(Context& context, const QImage& image); - ~Texture(); - QOpenGLTexture* glTexture() const; + backend::Texture* backendTexture() const { + return m_pTexture.get(); + } private: - const std::unique_ptr m_pTexture{}; - static QImage premultiplyAlpha(const QImage& image); + const std::unique_ptr m_pTexture{}; }; diff --git a/src/rendergraph/common/rendergraph/uniformscache.cpp b/src/rendergraph/common/rendergraph/uniformscache.cpp index 3e43b60aab6..81005f3ffac 100644 --- a/src/rendergraph/common/rendergraph/uniformscache.cpp +++ b/src/rendergraph/common/rendergraph/uniformscache.cpp @@ -1,5 +1,4 @@ #include "rendergraph/uniformscache.h" - #include "rendergraph/uniformset.h" using namespace rendergraph; diff --git a/src/rendergraph/common/rendergraph/uniformscache.h b/src/rendergraph/common/rendergraph/uniformscache.h index 5787570effd..f003fc30075 100644 --- a/src/rendergraph/common/rendergraph/uniformscache.h +++ b/src/rendergraph/common/rendergraph/uniformscache.h @@ -6,9 +6,9 @@ #include #include "rendergraph/types.h" +#include "rendergraph/uniformset.h" namespace rendergraph { -class UniformSet; class UniformsCache; } // namespace rendergraph diff --git a/src/rendergraph/common/rendergraph/uniformset.h b/src/rendergraph/common/rendergraph/uniformset.h index afa1cfc2426..34af87e5c94 100644 --- a/src/rendergraph/common/rendergraph/uniformset.h +++ b/src/rendergraph/common/rendergraph/uniformset.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/src/rendergraph/scenegraph/rendergraph/types.cpp b/src/rendergraph/common/types.cpp similarity index 100% rename from src/rendergraph/scenegraph/rendergraph/types.cpp rename to src/rendergraph/common/types.cpp diff --git a/src/rendergraph/examples/common/examplenodes.cpp b/src/rendergraph/examples/common/examplenodes.cpp index 420bbae40ca..ba2fd569b6c 100644 --- a/src/rendergraph/examples/common/examplenodes.cpp +++ b/src/rendergraph/examples/common/examplenodes.cpp @@ -58,3 +58,16 @@ ExampleNode3::ExampleNode3() { void ExampleNode3::setTexture(std::unique_ptr texture) { dynamic_cast(material()).setTexture(std::move(texture)); } + +ExampleTopNode::ExampleTopNode(rendergraph::Context& context) { + BaseNode::appendChildNode(std::make_unique()); + BaseNode::appendChildNode(std::make_unique()); + BaseNode::appendChildNode(std::make_unique()); + + { + QImage img(":/example/images/test.png"); + static_cast(BaseNode::lastChild()) + ->setTexture( + std::make_unique(context, img)); + } +} diff --git a/src/rendergraph/examples/common/examplenodes.h b/src/rendergraph/examples/common/examplenodes.h index 1ff3d01fb44..ca0efe73223 100644 --- a/src/rendergraph/examples/common/examplenodes.h +++ b/src/rendergraph/examples/common/examplenodes.h @@ -1,10 +1,12 @@ #include "rendergraph/geometrynode.h" +#include "rendergraph/node.h" #include "rendergraph/texture.h" namespace rendergraph { class ExampleNode1; class ExampleNode2; class ExampleNode3; +class ExampleTopNode; } // namespace rendergraph class rendergraph::ExampleNode1 : public rendergraph::GeometryNode { @@ -34,3 +36,8 @@ class rendergraph::ExampleNode3 : public rendergraph::GeometryNode { void setTexture(std::unique_ptr texture); }; + +class rendergraph::ExampleTopNode : public rendergraph::Node { + public: + ExampleTopNode(rendergraph::Context& context); +}; diff --git a/src/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/examples/gl_example/window.cpp index ef8f6ac111f..a5e5085d257 100644 --- a/src/rendergraph/examples/gl_example/window.cpp +++ b/src/rendergraph/examples/gl_example/window.cpp @@ -2,35 +2,23 @@ #include "examplenodes.h" #include "rendergraph/context.h" -#include "rendergraph/graph.h" Window::Window() { } -Window::~Window() = default; - void Window::closeEvent(QCloseEvent*) { // since this is the only and last window, we need to cleanup before destruction, // because at destruction the context can't be used anymore - m_rendergraph.reset(); + m_pEngine.reset(); } void Window::initializeGL() { - auto node = std::make_unique(); - node->Node::appendChildNode(std::make_unique()); - node->Node::appendChildNode(std::make_unique()); - node->Node::appendChildNode(std::make_unique()); - - { - QImage img(":/example/images/test.png"); - rendergraph::Context context; - static_cast(node->Node::lastChild()) - ->setTexture( - std::make_unique(context, img)); - } - - m_rendergraph = std::make_unique(std::move(node)); - m_rendergraph->initialize(); + rendergraph::Context context; + + auto node = std::make_unique(context); + + m_pEngine = std::make_unique(std::move(node)); + m_pEngine->initialize(); } void Window::resizeGL(int, int) { @@ -44,5 +32,5 @@ void Window::paintGL() { // so we need to do the same glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - m_rendergraph->render(); + m_pEngine->render(); } diff --git a/src/rendergraph/examples/gl_example/window.h b/src/rendergraph/examples/gl_example/window.h index 6d7d5f69749..8c2a5646bef 100644 --- a/src/rendergraph/examples/gl_example/window.h +++ b/src/rendergraph/examples/gl_example/window.h @@ -3,6 +3,8 @@ #include #include +#include "rendergraph/engine.h" + namespace rendergraph { class Graph; } @@ -10,7 +12,6 @@ class Graph; class Window : public QOpenGLWindow { public: Window(); - ~Window(); void initializeGL() override; void resizeGL(int w, int h) override; @@ -19,5 +20,5 @@ class Window : public QOpenGLWindow { void closeEvent(QCloseEvent* ev) override; private: - std::unique_ptr m_rendergraph; + std::unique_ptr m_pEngine; }; diff --git a/src/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/examples/sg_example/customitem.cpp index 228e8abb364..8651791c0a0 100644 --- a/src/rendergraph/examples/sg_example/customitem.cpp +++ b/src/rendergraph/examples/sg_example/customitem.cpp @@ -9,7 +9,6 @@ #include "examplenodes.h" #include "rendergraph/context.h" #include "rendergraph/node.h" -#include "rendergraph/scenegraph.h" CustomItem::CustomItem(QQuickItem* parent) : QQuickItem(parent) { @@ -31,20 +30,9 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { bgNode->setColor(QColor(0, 0, 0, 255)); bgNode->setRect(boundingRect()); - m_node = std::make_unique(); - m_node->Node::appendChildNode(std::make_unique()); - m_node->Node::appendChildNode(std::make_unique()); - m_node->Node::appendChildNode(std::make_unique()); - - { - QImage img(":/example/images/test.png"); - auto context = rendergraph::createSgContext(window()); - static_cast(m_node->Node::lastChild()) - ->setTexture(std::make_unique( - *context, img)); - } - - bgNode->appendChildNode(m_node->sgNode()); + rendergraph::Context context(window()); + m_node = std::make_unique(context); + bgNode->appendChildNode(m_node->backendNode()); node = bgNode; } else { diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 37477d4f421..66e2fb34c0d 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -1,48 +1,65 @@ add_library(rendergraph_gl - rendergraph/attributeset.cpp - rendergraph/attributeset.h - rendergraph/context.cpp - rendergraph/context.h - rendergraph/geometry.cpp - rendergraph/geometry.h - rendergraph/geometrynode.cpp - rendergraph/geometrynode.h - rendergraph/material.cpp - rendergraph/material.h - rendergraph/materialshader.cpp - rendergraph/materialshader.h - rendergraph/materialtype.cpp - rendergraph/materialtype.h - rendergraph/node.cpp - rendergraph/node.h - rendergraph/opacitynode.cpp - rendergraph/opacitynode.h - rendergraph/texture.cpp - rendergraph/texture.h - rendergraph/types.cpp - ../common/rendergraph/material/endoftrackmaterial.cpp - ../common/rendergraph/material/endoftrackmaterial.h - ../common/rendergraph/material/patternmaterial.cpp - ../common/rendergraph/material/patternmaterial.h - ../common/rendergraph/material/texturematerial.cpp - ../common/rendergraph/material/texturematerial.h - ../common/rendergraph/material/rgbamaterial.cpp - ../common/rendergraph/material/rgbamaterial.h - ../common/rendergraph/material/rgbmaterial.cpp - ../common/rendergraph/material/rgbmaterial.h - ../common/rendergraph/material/unicolormaterial.cpp - ../common/rendergraph/material/unicolormaterial.h - ../common/rendergraph/attribute.h - ../common/rendergraph/types.h - ../common/rendergraph/uniform.h - ../common/rendergraph/uniformscache.cpp - ../common/rendergraph/uniformscache.h - ../common/rendergraph/uniformset.cpp - ../common/rendergraph/uniformset.h - rendergraph/graph.cpp - rendergraph/graph.h - rendergraph/openglnode.cpp - rendergraph/openglnode.h +../common/attributeset.cpp +../common/basenode.cpp +../common/node.cpp +../common/opacitynode.cpp +../common/rendergraph/attribute.h +../common/rendergraph/attributeset.h +../common/rendergraph/basenode.h +../common/rendergraph/geometry.h +../common/rendergraph/geometrynode.h +../common/rendergraph/material.h +../common/rendergraph/material/endoftrackmaterial.cpp +../common/rendergraph/material/endoftrackmaterial.h +../common/rendergraph/material/patternmaterial.cpp +../common/rendergraph/material/patternmaterial.h +../common/rendergraph/material/rgbamaterial.cpp +../common/rendergraph/material/rgbamaterial.h +../common/rendergraph/material/rgbmaterial.cpp +../common/rendergraph/material/rgbmaterial.h +../common/rendergraph/material/texturematerial.cpp +../common/rendergraph/material/texturematerial.h +../common/rendergraph/material/unicolormaterial.cpp +../common/rendergraph/material/unicolormaterial.h +../common/rendergraph/materialshader.h +../common/rendergraph/materialtype.h +../common/rendergraph/node.h +../common/rendergraph/opacitynode.h +../common/rendergraph/texture.h +../common/rendergraph/types.h +../common/rendergraph/uniform.h +../common/rendergraph/uniformscache.cpp +../common/rendergraph/uniformscache.h +../common/rendergraph/uniformset.cpp +../common/rendergraph/uniformset.h +../common/types.cpp +backend/attributeset.cpp +backend/attributeset.h +backend/geometry.cpp +backend/geometry.h +backend/geometrynode.cpp +backend/geometrynode.h +backend/material.cpp +backend/material.h +backend/materialshader.cpp +backend/materialtype.h +backend/node.h +backend/opacitynode.h +backend/openglnode.cpp +backend/openglnode.h +backend/shadercache.h +backend/texture.h +basenode.cpp +engine.cpp +geometry.cpp +geometrynode.cpp +material.cpp +materialshader.cpp +openglnode.cpp +rendergraph/context.h +rendergraph/engine.h +rendergraph/openglnode.h +texture.cpp ) target_link_libraries(rendergraph_gl PUBLIC diff --git a/src/rendergraph/opengl/backend/attributeset.cpp b/src/rendergraph/opengl/backend/attributeset.cpp new file mode 100644 index 00000000000..c70790b44c8 --- /dev/null +++ b/src/rendergraph/opengl/backend/attributeset.cpp @@ -0,0 +1,11 @@ +#include "rendergraph/attributeset.h" + +using namespace rendergraph::backend; + +AttributeSet::AttributeSet(std::initializer_list list, + const std::vector& names) { + int i = 0; + for (auto item : list) { + m_attributes.push_back(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); + } +} diff --git a/src/rendergraph/opengl/backend/attributeset.h b/src/rendergraph/opengl/backend/attributeset.h new file mode 100644 index 00000000000..5db82d58066 --- /dev/null +++ b/src/rendergraph/opengl/backend/attributeset.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +#include "rendergraph/attribute.h" + +namespace rendergraph::backend { +class AttributeSet; +} + +class rendergraph::backend::AttributeSet { + protected: + AttributeSet(std::initializer_list list, const std::vector& names); + std::vector m_attributes; +}; diff --git a/src/rendergraph/opengl/backend/geometry.cpp b/src/rendergraph/opengl/backend/geometry.cpp new file mode 100644 index 00000000000..d9fc828ef55 --- /dev/null +++ b/src/rendergraph/opengl/backend/geometry.cpp @@ -0,0 +1,41 @@ +#include "backend/geometry.h" + +#include "rendergraph/geometry.h" + +using namespace rendergraph::backend; + +Geometry::Geometry( + const rendergraph::AttributeSet& attributeSet, int vertexCount) + : m_drawingMode(static_cast(rendergraph::Geometry::DrawingMode:: + TriangleStrip)) // to mimic sg default + , + m_vertexCount(vertexCount) { + int offset = 0; + for (const auto& attribute : attributeSet.attributes()) { + m_offsets.push_back(offset); + offset += attribute.m_tupleSize; + m_tupleSizes.push_back(attribute.m_tupleSize); + } + m_stride = offset * sizeof(float); + m_data.resize(offset * vertexCount); +} + +int Geometry::attributeCount() const { + return m_tupleSizes.size(); +} + +int Geometry::vertexCount() const { + return m_vertexCount; +} + +int Geometry::offset(int attributeIndex) const { + return m_offsets[attributeIndex]; +} + +int Geometry::tupleSize(int attributeIndex) const { + return m_tupleSizes[attributeIndex]; +} + +int Geometry::stride() const { + return m_stride; +} diff --git a/src/rendergraph/opengl/backend/geometry.h b/src/rendergraph/opengl/backend/geometry.h new file mode 100644 index 00000000000..2965668e152 --- /dev/null +++ b/src/rendergraph/opengl/backend/geometry.h @@ -0,0 +1,29 @@ +#pragma once + +#include + +#include "rendergraph/attributeset.h" + +namespace rendergraph::backend { +class Geometry; +} + +class rendergraph::backend::Geometry { + protected: + Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount); + + public: + int attributeCount() const; + int vertexCount() const; + int offset(int attributeIndex) const; + int tupleSize(int attributeIndex) const; + int stride() const; + + protected: + int m_drawingMode; + int m_vertexCount; + std::vector m_tupleSizes; + std::vector m_offsets; + int m_stride; + std::vector m_data; +}; diff --git a/src/rendergraph/opengl/rendergraph/geometrynode.cpp b/src/rendergraph/opengl/backend/geometrynode.cpp similarity index 65% rename from src/rendergraph/opengl/rendergraph/geometrynode.cpp rename to src/rendergraph/opengl/backend/geometrynode.cpp index 67df96e4d11..335792072cd 100644 --- a/src/rendergraph/opengl/rendergraph/geometrynode.cpp +++ b/src/rendergraph/opengl/backend/geometrynode.cpp @@ -1,52 +1,34 @@ -#include "rendergraph/geometrynode.h" +#include "backend/geometrynode.h" #include -#include "rendergraph/shadercache.h" +#include "backend/shadercache.h" +#include "rendergraph/geometrynode.h" #include "rendergraph/texture.h" -using namespace rendergraph; - -GeometryNode::GeometryNode() = default; - -GeometryNode::~GeometryNode() = default; - -void GeometryNode::setGeometry(std::unique_ptr pGeometry) { - m_pGeometry = std::move(pGeometry); -} - -void GeometryNode::setMaterial(std::unique_ptr pMaterial) { - m_pMaterial = std::move(pMaterial); -} - -Geometry& GeometryNode::geometry() const { - return *m_pGeometry; -} - -Material& GeometryNode::material() const { - return *m_pMaterial; -} - -void GeometryNode::initialize() { - initializeOpenGLFunctions(); - m_pMaterial->setShader(ShaderCache::getShaderForMaterial(m_pMaterial.get())); - Node::initialize(); -} +using namespace rendergraph::backend; namespace { -GLenum toGlDrawingMode(Geometry::DrawingMode mode) { +GLenum toGlDrawingMode(rendergraph::Geometry::DrawingMode mode) { switch (mode) { - case Geometry::DrawingMode::Triangles: + case rendergraph::Geometry::DrawingMode::Triangles: return GL_TRIANGLES; - case Geometry::DrawingMode::TriangleStrip: + case rendergraph::Geometry::DrawingMode::TriangleStrip: return GL_TRIANGLE_STRIP; } } } // namespace -void GeometryNode::render() { - Geometry& geometry = *m_pGeometry; - Material& material = *m_pMaterial; +void GeometryNode::initializeBackend() { + initializeOpenGLFunctions(); + rendergraph::GeometryNode* pThis = static_cast(this); + pThis->material().setShader(ShaderCache::getShaderForMaterial(&pThis->material())); +} + +void GeometryNode::renderBackend() { + rendergraph::GeometryNode* pThis = static_cast(this); + rendergraph::Geometry& geometry = pThis->geometry(); + rendergraph::Material& material = pThis->material(); if (geometry.vertexCount() == 0) { return; @@ -60,9 +42,9 @@ void GeometryNode::render() { QOpenGLShaderProgram& shader = material.shader(); shader.bind(); - if (m_pMaterial->clearUniformsCacheDirty() || !material.isLastModifierOfShader()) { + if (material.clearUniformsCacheDirty() || !material.isLastModifierOfShader()) { material.modifyShader(); - const UniformsCache& cache = m_pMaterial->uniformsCache(); + const UniformsCache& cache = material.uniformsCache(); for (int i = 0; i < cache.count(); i++) { int location = material.uniformLocation(i); switch (cache.type(i)) { @@ -98,15 +80,15 @@ void GeometryNode::render() { } // TODO multiple textures - auto pTexture = m_pMaterial->texture(1); + auto pTexture = material.texture(1); if (pTexture) { - pTexture->glTexture()->bind(); + pTexture->backendTexture()->bind(); } glDrawArrays(toGlDrawingMode(geometry.drawingMode()), 0, geometry.vertexCount()); if (pTexture) { - pTexture->glTexture()->release(); + pTexture->backendTexture()->release(); } for (int i = 0; i < geometry.attributeCount(); i++) { @@ -115,6 +97,4 @@ void GeometryNode::render() { } shader.release(); - - Node::render(); } diff --git a/src/rendergraph/opengl/backend/geometrynode.h b/src/rendergraph/opengl/backend/geometrynode.h new file mode 100644 index 00000000000..b60cd279441 --- /dev/null +++ b/src/rendergraph/opengl/backend/geometrynode.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include "backend/node.h" + +namespace rendergraph::backend { +class GeometryNode; +} + +class rendergraph::backend::GeometryNode : public rendergraph::backend::Node, + public QOpenGLFunctions { + protected: + GeometryNode() = default; + + public: + void initializeBackend() override; + void renderBackend() override; +}; diff --git a/src/rendergraph/opengl/rendergraph/material.cpp b/src/rendergraph/opengl/backend/material.cpp similarity index 56% rename from src/rendergraph/opengl/rendergraph/material.cpp rename to src/rendergraph/opengl/backend/material.cpp index 6c525b1ebf5..d74abbeea92 100644 --- a/src/rendergraph/opengl/rendergraph/material.cpp +++ b/src/rendergraph/opengl/backend/material.cpp @@ -1,21 +1,12 @@ -#include "rendergraph/material.h" +#include "backend/material.h" -#include "rendergraph/shadercache.h" -#include "rendergraph/texture.h" +using namespace rendergraph::backend; -using namespace rendergraph; - -Material::Material(const UniformSet& uniformSet) - : m_uniformsCache(uniformSet) { -} - -Material::~Material() = default; - -void Material::setShader(std::shared_ptr pShader) { +void Material::setShader(std::shared_ptr pShader) { m_pShader = pShader; } -MaterialShader& Material::shader() const { +rendergraph::MaterialShader& Material::shader() const { return *m_pShader; } diff --git a/src/rendergraph/opengl/backend/material.h b/src/rendergraph/opengl/backend/material.h new file mode 100644 index 00000000000..3574d69c78b --- /dev/null +++ b/src/rendergraph/opengl/backend/material.h @@ -0,0 +1,27 @@ +#pragma once + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" + +namespace rendergraph::backend { +class Material; +} + +class rendergraph::backend::Material { + protected: + Material() = default; + + public: + virtual rendergraph::MaterialType* type() const = 0; + + void setShader(std::shared_ptr pShader); + + rendergraph::MaterialShader& shader() const; + + int uniformLocation(int uniformIndex) const; + int attributeLocation(int attributeIndex) const; + + void modifyShader(); + bool isLastModifierOfShader() const; + std::shared_ptr m_pShader; +}; diff --git a/src/rendergraph/opengl/backend/materialshader.cpp b/src/rendergraph/opengl/backend/materialshader.cpp new file mode 100644 index 00000000000..e2c66519e10 --- /dev/null +++ b/src/rendergraph/opengl/backend/materialshader.cpp @@ -0,0 +1,18 @@ +#include "backend/materialshader.h" + +using namespace rendergraph::backend; + +int MaterialShader::attributeLocation(int attributeIndex) const { + return m_attributeLocations[attributeIndex]; +} + +int MaterialShader::uniformLocation(int uniformIndex) const { + return m_uniformLocations[uniformIndex]; +} + +Material* MaterialShader::lastModifiedByMaterial() const { + return m_pLastModifiedByMaterial; +} +void MaterialShader::setLastModifiedByMaterial(Material* pMaterial) { + m_pLastModifiedByMaterial = pMaterial; +} diff --git a/src/rendergraph/opengl/rendergraph/materialshader.h b/src/rendergraph/opengl/backend/materialshader.h similarity index 58% rename from src/rendergraph/opengl/rendergraph/materialshader.h rename to src/rendergraph/opengl/backend/materialshader.h index cc2ca699061..7e56a450791 100644 --- a/src/rendergraph/opengl/rendergraph/materialshader.h +++ b/src/rendergraph/opengl/backend/materialshader.h @@ -3,28 +3,19 @@ #include #include -namespace rendergraph { -class AttributeSet; -class UniformSet; -class MaterialShader; +namespace rendergraph::backend { class Material; -} // namespace rendergraph +class MaterialShader; +} // namespace rendergraph::backend -class rendergraph::MaterialShader : public QOpenGLShaderProgram { - public: - MaterialShader(const char* vertexShaderFile, - const char* fragmentShaderFile, - const UniformSet& uniforms, - const AttributeSet& attributeSet); - ~MaterialShader(); +class rendergraph::backend::MaterialShader : public QOpenGLShaderProgram { + protected: + MaterialShader() = default; - QOpenGLShaderProgram& glShader(); + public: int attributeLocation(int attributeIndex) const; int uniformLocation(int uniformIndex) const; - private: - friend Material; - Material* lastModifiedByMaterial() const; void setLastModifiedByMaterial(Material* pMaterial); diff --git a/src/rendergraph/opengl/backend/materialtype.h b/src/rendergraph/opengl/backend/materialtype.h new file mode 100644 index 00000000000..1e44b097016 --- /dev/null +++ b/src/rendergraph/opengl/backend/materialtype.h @@ -0,0 +1,8 @@ +#pragma once + +namespace rendergraph::backend { +class MaterialType; +} + +class rendergraph::backend::MaterialType { +}; diff --git a/src/rendergraph/opengl/backend/node.h b/src/rendergraph/opengl/backend/node.h new file mode 100644 index 00000000000..898d675885f --- /dev/null +++ b/src/rendergraph/opengl/backend/node.h @@ -0,0 +1,44 @@ +#pragma once + +namespace rendergraph { +class Engine; +} + +namespace rendergraph::backend { +class Node; +} + +class rendergraph::backend::Node { + protected: + Node() = default; + + public: + void setUsePreprocessFlag(bool value) { + m_usePreprocess = value; + } + bool usePreprocess() const { + return m_usePreprocess; + } + virtual bool isSubtreeBlocked() const { + return false; + } + virtual void preprocess() { + } + virtual void renderBackend() { + } + virtual void initializeBackend() { + } + virtual void resizeBackend(int, int) { + } + + void setEngine(Engine* pEngine) { + m_pEngine = pEngine; + } + Engine* engine() const { + return m_pEngine; + } + + private: + bool m_usePreprocess{}; + Engine* m_pEngine{}; +}; diff --git a/src/rendergraph/opengl/backend/opacitynode.h b/src/rendergraph/opengl/backend/opacitynode.h new file mode 100644 index 00000000000..3ba10f0ad6c --- /dev/null +++ b/src/rendergraph/opengl/backend/opacitynode.h @@ -0,0 +1,23 @@ +#pragma once + +#include "backend/node.h" + +namespace rendergraph::backend { +class OpacityNode; +} + +class rendergraph::backend::OpacityNode : public rendergraph::backend::Node { + protected: + OpacityNode() = default; + + public: + void setOpacity(float opacity) { + m_opacity = opacity; + } + bool isSubtreeBlocked() const override { + return m_opacity == 0.f; + } + + private: + float m_opacity{1.f}; +}; diff --git a/src/rendergraph/opengl/backend/openglnode.cpp b/src/rendergraph/opengl/backend/openglnode.cpp new file mode 100644 index 00000000000..ae12372ef3c --- /dev/null +++ b/src/rendergraph/opengl/backend/openglnode.cpp @@ -0,0 +1,21 @@ +#include "backend/openglnode.h" + +#include "rendergraph/openglnode.h" + +using namespace rendergraph::backend; + +void OpenGLNode::initializeBackend() { + initializeOpenGLFunctions(); + rendergraph::OpenGLNode* pThis = static_cast(this); + pThis->initializeGL(); +} + +void OpenGLNode::renderBackend() { + rendergraph::OpenGLNode* pThis = static_cast(this); + pThis->paintGL(); +} + +void OpenGLNode::resizeBackend(int w, int h) { + rendergraph::OpenGLNode* pThis = static_cast(this); + pThis->resizeGL(w, h); +} diff --git a/src/rendergraph/opengl/backend/openglnode.h b/src/rendergraph/opengl/backend/openglnode.h new file mode 100644 index 00000000000..9d6d379917b --- /dev/null +++ b/src/rendergraph/opengl/backend/openglnode.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include "backend/node.h" + +namespace rendergraph::backend { +class OpenGLNode; +} + +class rendergraph::backend::OpenGLNode : public rendergraph::backend::Node, + public QOpenGLFunctions { + protected: + OpenGLNode() = default; + + public: + void initializeBackend() override; + void renderBackend() override; + void resizeBackend(int w, int h) override; +}; diff --git a/src/rendergraph/opengl/backend/shadercache.h b/src/rendergraph/opengl/backend/shadercache.h new file mode 100644 index 00000000000..4f7eba2879d --- /dev/null +++ b/src/rendergraph/opengl/backend/shadercache.h @@ -0,0 +1,48 @@ +#pragma once + +#include + +#include "rendergraph/material.h" +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" + +namespace rendergraph::backend { +class ShaderCache; +} + +class rendergraph::backend::ShaderCache { + private: + static std::map>& + map() { + static std::map> + s_map; + return s_map; + } + + public: + static std::shared_ptr getShaderForMaterial( + rendergraph::Material* pMaterial) { + auto iter = map().find(pMaterial->type()); + if (iter != map().end()) { + return iter->second; + } + auto pResult = std::shared_ptr( + pMaterial->createShader().release()); + map().insert(std::pair>{ + pMaterial->type(), pResult}); + return pResult; + } + static void purge() { + auto iter = map().begin(); + while (iter != map().end()) { + if (iter->second.use_count() == 1) { + iter = map().erase(iter); + } else { + ++iter; + } + } + } +}; diff --git a/src/rendergraph/opengl/backend/texture.h b/src/rendergraph/opengl/backend/texture.h new file mode 100644 index 00000000000..2de1052269f --- /dev/null +++ b/src/rendergraph/opengl/backend/texture.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph::backend { +using Texture = QOpenGLTexture; +} diff --git a/src/rendergraph/opengl/basenode.cpp b/src/rendergraph/opengl/basenode.cpp new file mode 100644 index 00000000000..2f10fbab534 --- /dev/null +++ b/src/rendergraph/opengl/basenode.cpp @@ -0,0 +1,21 @@ +#include "rendergraph/basenode.h" +#include "rendergraph/engine.h" + +using namespace rendergraph; + +void BaseNode::setUsePreprocess(bool value) { + backendNode()->setUsePreprocessFlag(value); +} + +void BaseNode::onAppendChildNode(BaseNode* pChild) { + if (backendNode()->engine() != nullptr && + backendNode()->engine() != pChild->backendNode()->engine()) { + backendNode()->engine()->addToEngine(pChild); + } +} + +void BaseNode::onRemoveChildNode(BaseNode*) { +} + +void BaseNode::onRemoveAllChildNodes() { +} diff --git a/src/rendergraph/opengl/rendergraph/graph.cpp b/src/rendergraph/opengl/engine.cpp similarity index 52% rename from src/rendergraph/opengl/rendergraph/graph.cpp rename to src/rendergraph/opengl/engine.cpp index cbb61e9e45a..857b439e24a 100644 --- a/src/rendergraph/opengl/rendergraph/graph.cpp +++ b/src/rendergraph/opengl/engine.cpp @@ -1,4 +1,4 @@ -#include "rendergraph/graph.h" +#include "rendergraph/engine.h" #include @@ -6,23 +6,20 @@ using namespace rendergraph; -Graph::Graph(std::unique_ptr node) +Engine::Engine(std::unique_ptr node) : m_pTopNode(std::move(node)) { - if (m_pTopNode->graph() != this) { - addToGraph(m_pTopNode.get()); - } + addToEngine(m_pTopNode.get()); } -Graph::~Graph() = default; - -void Graph::initialize() { +void Engine::initialize() { for (auto pNode : m_pInitializeNodes) { + pNode->backendNode()->initializeBackend(); pNode->initialize(); } m_pInitializeNodes.clear(); } -void Graph::render() { +void Engine::render() { if (!m_pInitializeNodes.empty()) { initialize(); } @@ -31,30 +28,31 @@ void Graph::render() { } } -void Graph::resize(int w, int h) { +void Engine::resize(int w, int h) { resize(m_pTopNode.get(), w, h); } -void Graph::preprocess() { +void Engine::preprocess() { for (auto pNode : m_pPreprocessNodes) { - if (!pNode->isSubtreeBlocked()) { - pNode->preprocess(); + if (!pNode->backendNode()->isSubtreeBlocked()) { + pNode->backendNode()->preprocess(); } } } -void Graph::render(Node* pNode) { - pNode->render(); +void Engine::render(BaseNode* pNode) { + pNode->backendNode()->renderBackend(); pNode = pNode->firstChild(); while (pNode) { - if (!pNode->isSubtreeBlocked()) { + if (!pNode->backendNode()->isSubtreeBlocked()) { render(pNode); } pNode = pNode->nextSibling(); } } -void Graph::resize(Node* pNode, int w, int h) { +void Engine::resize(BaseNode* pNode, int w, int h) { + pNode->backendNode()->resizeBackend(w, h); pNode->resize(w, h); pNode = pNode->firstChild(); while (pNode) { @@ -63,18 +61,18 @@ void Graph::resize(Node* pNode, int w, int h) { } } -void Graph::addToGraph(Node* pNode) { - assert(pNode->graph() == nullptr); +void Engine::addToEngine(BaseNode* pNode) { + assert(pNode->backendNode()->engine() == nullptr); - pNode->setGraph(this); + pNode->backendNode()->setEngine(this); m_pInitializeNodes.push_back(pNode); - if (pNode->usePreprocess()) { + if (pNode->backendNode()->usePreprocess()) { m_pPreprocessNodes.push_back(pNode); } pNode = pNode->firstChild(); while (pNode) { - if (pNode->graph() != this) { - addToGraph(pNode); + if (pNode->backendNode()->engine() != this) { + addToEngine(pNode); } pNode = pNode->nextSibling(); } diff --git a/src/rendergraph/opengl/geometry.cpp b/src/rendergraph/opengl/geometry.cpp new file mode 100644 index 00000000000..aeb1828ed30 --- /dev/null +++ b/src/rendergraph/opengl/geometry.cpp @@ -0,0 +1,44 @@ +#include "rendergraph/geometry.h" + +#include "rendergraph/attributeset.h" + +using namespace rendergraph; + +Geometry::Geometry(const AttributeSet& attributeSet, int vertexCount) + : backend::Geometry(attributeSet, vertexCount) { +} + +Geometry::~Geometry() = default; + +void Geometry::setAttributeValues(int attributePosition, const float* from, int numTuples) { + const int offset = m_offsets[attributePosition]; + const int tupleSize = m_tupleSizes[attributePosition]; + const int skip = m_stride / sizeof(float) - tupleSize; + + float* to = m_data.data(); + to += offset; + while (numTuples--) { + int k = tupleSize; + while (k--) { + *to++ = *from++; + } + to += skip; + } +} + +float* Geometry::vertexData() { + return m_data.data(); +} + +void Geometry::allocate(int vertexCount) { + m_vertexCount = vertexCount; + m_data.resize((m_stride / sizeof(float)) * m_vertexCount); +} + +void Geometry::setDrawingMode(Geometry::DrawingMode mode) { + m_drawingMode = static_cast(mode); +} + +Geometry::DrawingMode Geometry::drawingMode() const { + return static_cast(m_drawingMode); +} diff --git a/src/rendergraph/opengl/geometrynode.cpp b/src/rendergraph/opengl/geometrynode.cpp new file mode 100644 index 00000000000..c5c5600b01c --- /dev/null +++ b/src/rendergraph/opengl/geometrynode.cpp @@ -0,0 +1,23 @@ +#include "rendergraph/geometrynode.h" + +using namespace rendergraph; + +GeometryNode::GeometryNode() + : BaseNode(this) { +} + +void GeometryNode::setGeometry(std::unique_ptr pGeometry) { + m_pGeometry = std::move(pGeometry); +} + +void GeometryNode::setMaterial(std::unique_ptr pMaterial) { + m_pMaterial = std::move(pMaterial); +} + +Geometry& GeometryNode::geometry() const { + return *m_pGeometry; +} + +Material& GeometryNode::material() const { + return *m_pMaterial; +} diff --git a/src/rendergraph/opengl/material.cpp b/src/rendergraph/opengl/material.cpp new file mode 100644 index 00000000000..4913e8d5b61 --- /dev/null +++ b/src/rendergraph/opengl/material.cpp @@ -0,0 +1,9 @@ +#include "rendergraph/material.h" + +using namespace rendergraph; + +Material::Material(const UniformSet& uniformSet) + : m_uniformsCache(uniformSet) { +} + +Material::~Material() = default; diff --git a/src/rendergraph/opengl/rendergraph/materialshader.cpp b/src/rendergraph/opengl/materialshader.cpp similarity index 55% rename from src/rendergraph/opengl/rendergraph/materialshader.cpp rename to src/rendergraph/opengl/materialshader.cpp index aaea06fff17..40a15f4e177 100644 --- a/src/rendergraph/opengl/rendergraph/materialshader.cpp +++ b/src/rendergraph/opengl/materialshader.cpp @@ -1,9 +1,5 @@ #include "rendergraph/materialshader.h" -#include - -#include "rendergraph/attributeset.h" -#include "rendergraph/uniformset.h" using namespace rendergraph; MaterialShader::MaterialShader(const char* vertexShaderFile, @@ -22,24 +18,3 @@ MaterialShader::MaterialShader(const char* vertexShaderFile, m_uniformLocations.push_back(location); } } - -MaterialShader::~MaterialShader() = default; - -QOpenGLShaderProgram& MaterialShader::glShader() { - return *this; -} - -int MaterialShader::attributeLocation(int attributeIndex) const { - return m_attributeLocations[attributeIndex]; -} - -int MaterialShader::uniformLocation(int uniformIndex) const { - return m_uniformLocations[uniformIndex]; -} - -Material* MaterialShader::lastModifiedByMaterial() const { - return m_pLastModifiedByMaterial; -} -void MaterialShader::setLastModifiedByMaterial(Material* pMaterial) { - m_pLastModifiedByMaterial = pMaterial; -} diff --git a/src/rendergraph/opengl/openglnode.cpp b/src/rendergraph/opengl/openglnode.cpp new file mode 100644 index 00000000000..cd7f84ab99d --- /dev/null +++ b/src/rendergraph/opengl/openglnode.cpp @@ -0,0 +1,7 @@ +#include "rendergraph/openglnode.h" + +using namespace rendergraph; + +OpenGLNode::OpenGLNode() + : BaseNode(this) { +} diff --git a/src/rendergraph/opengl/rendergraph/attributeset.cpp b/src/rendergraph/opengl/rendergraph/attributeset.cpp deleted file mode 100644 index 6ca9d378983..00000000000 --- a/src/rendergraph/opengl/rendergraph/attributeset.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "rendergraph/attributeset.h" - -using namespace rendergraph; - -AttributeSet::AttributeSet() = default; - -AttributeSet::AttributeSet(std::initializer_list list, const std::vector& names) - : AttributeSet() { - int i = 0; - for (auto item : list) { - add(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); - } -} - -AttributeSet::~AttributeSet() = default; - -void AttributeSet::add(const Attribute& attribute) { - m_attributes.push_back(attribute); -} - -const std::vector& AttributeSet::attributes() const { - return m_attributes; -} diff --git a/src/rendergraph/opengl/rendergraph/context.cpp b/src/rendergraph/opengl/rendergraph/context.cpp deleted file mode 100644 index c795cd2b00b..00000000000 --- a/src/rendergraph/opengl/rendergraph/context.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "rendergraph/context.h" - -using namespace rendergraph; - -Context::Context() = default; -Context::~Context() = default; diff --git a/src/rendergraph/opengl/rendergraph/context.h b/src/rendergraph/opengl/rendergraph/context.h index 99e7f8e0ec7..d5d0611408f 100644 --- a/src/rendergraph/opengl/rendergraph/context.h +++ b/src/rendergraph/opengl/rendergraph/context.h @@ -5,7 +5,4 @@ class Context; } class rendergraph::Context { - public: - Context(); - ~Context(); }; diff --git a/src/rendergraph/opengl/rendergraph/engine.h b/src/rendergraph/opengl/rendergraph/engine.h new file mode 100644 index 00000000000..9eab434ed33 --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/engine.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include + +#include "rendergraph/node.h" + +namespace rendergraph { +class Engine; +} // namespace rendergraph + +class rendergraph::Engine { + public: + Engine(std::unique_ptr node); + void initialize(); + void render(); + void resize(int w, int h); + void preprocess(); + void addToEngine(BaseNode* pNode); + + private: + void initialize(BaseNode* pNode); + void render(BaseNode* pNode); + void resize(BaseNode* pNode, int, int); + + const std::unique_ptr m_pTopNode; + std::vector m_pPreprocessNodes; + std::vector m_pInitializeNodes; +}; diff --git a/src/rendergraph/opengl/rendergraph/examples/CMakeLists.txt b/src/rendergraph/opengl/rendergraph/examples/CMakeLists.txt deleted file mode 100644 index bd918d2f9ad..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -cmake_minimum_required(VERSION 3.16) -project(rendergraph LANGUAGES CXX) - -find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick ShaderTools) - -qt_standard_project_setup() - -add_subdirectory(../ rendergraph) -add_subdirectory(gl_example) -add_subdirectory(sg_example) -add_subdirectory(common) diff --git a/src/rendergraph/opengl/rendergraph/examples/README b/src/rendergraph/opengl/rendergraph/examples/README deleted file mode 100644 index 6168efc09c4..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/README +++ /dev/null @@ -1,6 +0,0 @@ -Build examples with - -$ cd ../../../ -$ mkdir build-rendergraph_examples -$ cd build-rendergraph_examples -$ cmake -DCMAKE_PREFIX_PATH=~/Qt/6.7.2/macos/ ../src/rendergraph/examples diff --git a/src/rendergraph/opengl/rendergraph/examples/common/CMakeLists.txt b/src/rendergraph/opengl/rendergraph/examples/common/CMakeLists.txt deleted file mode 100644 index e7ee6c0160e..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/common/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_library(rendergraph_examples - examplenodes.cpp - examplenodes.h -) - -target_link_libraries(rendergraph_examples PUBLIC - Qt6::Core - Qt6::Gui - Qt6::OpenGL -) - -target_include_directories(rendergraph_examples PUBLIC ../../../ .) diff --git a/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.cpp b/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.cpp deleted file mode 100644 index 420bbae40ca..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.cpp +++ /dev/null @@ -1,60 +0,0 @@ -#include "examplenodes.h" - -#include -#include -#include - -#include "rendergraph/geometry.h" -#include "rendergraph/material/endoftrackmaterial.h" -#include "rendergraph/material/texturematerial.h" - -using namespace rendergraph; - -ExampleNode1::ExampleNode1() { - setMaterial(std::make_unique()); - setGeometry(std::make_unique(EndOfTrackMaterial::attributes(), 4)); - - geometry().setAttributeValues(0, positionArray, 4); - geometry().setAttributeValues(1, horizontalGradientArray, 4); - - QColor color("red"); - material().setUniform(0, - QVector4D{color.redF(), - color.greenF(), - color.blueF(), - color.alphaF()}); -} - -ExampleNode2::ExampleNode2() { - setMaterial(std::make_unique()); - setGeometry(std::make_unique(EndOfTrackMaterial::attributes(), 4)); - - geometry().setAttributeValues(0, positionArray, 4); - geometry().setAttributeValues(1, horizontalGradientArray, 4); - - QColor color("blue"); - material().setUniform(0, - QVector4D{color.redF(), - color.greenF(), - color.blueF(), - color.alphaF()}); -} - -ExampleNode3::ExampleNode3() { - auto* m = new TextureMaterial; - - setMaterial(std::make_unique()); - setGeometry(std::make_unique(TextureMaterial::attributes(), 4)); - - geometry().setAttributeValues(0, positionArray, 4); - geometry().setAttributeValues(1, texcoordArray, 4); - - QMatrix4x4 matrix; - - matrix.scale(0.3); - material().setUniform(0, matrix); -} - -void ExampleNode3::setTexture(std::unique_ptr texture) { - dynamic_cast(material()).setTexture(std::move(texture)); -} diff --git a/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.h b/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.h deleted file mode 100644 index 1ff3d01fb44..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/common/examplenodes.h +++ /dev/null @@ -1,36 +0,0 @@ -#include "rendergraph/geometrynode.h" -#include "rendergraph/texture.h" - -namespace rendergraph { -class ExampleNode1; -class ExampleNode2; -class ExampleNode3; -} // namespace rendergraph - -class rendergraph::ExampleNode1 : public rendergraph::GeometryNode { - public: - static constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; - static constexpr float verticalGradientArray[] = {1.f, 1.f, -1.f, -1.f}; - static constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; - - ExampleNode1(); -}; - -class rendergraph::ExampleNode2 : public rendergraph::GeometryNode { - public: - static constexpr float positionArray[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f}; - static constexpr float verticalGradientArray[] = {1.f, 1.f, 0.f, 0.f}; - static constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; - - ExampleNode2(); -}; - -class rendergraph::ExampleNode3 : public rendergraph::GeometryNode { - public: - static constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; - static constexpr float texcoordArray[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f}; - - ExampleNode3(); - - void setTexture(std::unique_ptr texture); -}; diff --git a/src/rendergraph/opengl/rendergraph/examples/gl_example/CMakeLists.txt b/src/rendergraph/opengl/rendergraph/examples/gl_example/CMakeLists.txt deleted file mode 100644 index 30f6a547b88..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/gl_example/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL) - -qt_add_executable(gl_example - window.cpp window.h - main.cpp -) - -set_target_properties(gl_example PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) - -target_link_libraries(gl_example PRIVATE - rendergraph_gl - rendergraph_examples - Qt6::Core - Qt6::Gui - Qt6::OpenGL -) - -qt_add_resources(gl_example "gl_example" - PREFIX - /example - FILES - images/test.png -) - -install(TARGETS gl_example - BUNDLE DESTINATION . - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} -) - -qt_generate_deploy_app_script( - TARGET gl_example - OUTPUT_SCRIPT deploy_script - NO_UNSUPPORTED_PLATFORM_ERROR -) -install(SCRIPT ${deploy_script}) diff --git a/src/rendergraph/opengl/rendergraph/examples/gl_example/images/test.png b/src/rendergraph/opengl/rendergraph/examples/gl_example/images/test.png deleted file mode 100644 index f9580346eb8b893f1d6acb3be80d2ee911bc20e5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12849 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 G4*q`+EtQY} diff --git a/src/rendergraph/opengl/rendergraph/examples/gl_example/main.cpp b/src/rendergraph/opengl/rendergraph/examples/gl_example/main.cpp deleted file mode 100644 index 7b62238b429..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/gl_example/main.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include - -#include "window.h" - -int main(int argc, char* argv[]) { - QGuiApplication app(argc, argv); - - Window window; - window.show(); - - return app.exec(); -} diff --git a/src/rendergraph/opengl/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/opengl/rendergraph/examples/gl_example/window.cpp deleted file mode 100644 index 81bc0db439b..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/gl_example/window.cpp +++ /dev/null @@ -1,48 +0,0 @@ -#include "window.h" - -#include "examplenodes.h" -#include "rendergraph/context.h" -#include "rendergraph/opengl/graph.h" - -Window::Window() { -} - -Window::~Window() = default; - -void Window::closeEvent(QCloseEvent*) { - // since this is the only and last window, we need to cleanup before destruction, - // because at destruction the context can't be used anymore - m_rendergraph.reset(); -} - -void Window::initializeGL() { - auto node = std::make_unique(); - node->appendChildNode(std::make_unique()); - node->appendChildNode(std::make_unique()); - node->appendChildNode(std::make_unique()); - - { - QImage img(":/example/images/test.png"); - rendergraph::Context context; - static_cast(node->lastChild()) - ->setTexture( - std::make_unique(context, img)); - } - - m_rendergraph = std::make_unique(std::move(node)); - m_rendergraph->initialize(); -} - -void Window::resizeGL(int, int) { -} - -void Window::paintGL() { - glClearColor(0.f, 0.f, 0.f, 1.f); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glEnable(GL_BLEND); - // qt scene graph uses premultiplied alpha color in the shader, - // so we need to do the same - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - - m_rendergraph->render(); -} diff --git a/src/rendergraph/opengl/rendergraph/examples/gl_example/window.h b/src/rendergraph/opengl/rendergraph/examples/gl_example/window.h deleted file mode 100644 index 6d7d5f69749..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/gl_example/window.h +++ /dev/null @@ -1,23 +0,0 @@ -#pragma once - -#include -#include - -namespace rendergraph { -class Graph; -} - -class Window : public QOpenGLWindow { - public: - Window(); - ~Window(); - - void initializeGL() override; - void resizeGL(int w, int h) override; - void paintGL() override; - - void closeEvent(QCloseEvent* ev) override; - - private: - std::unique_ptr m_rendergraph; -}; diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/CMakeLists.txt b/src/rendergraph/opengl/rendergraph/examples/sg_example/CMakeLists.txt deleted file mode 100644 index 096e131e47e..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/sg_example/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -qt_add_executable(sg_example WIN32 MACOSX_BUNDLE - customitem.cpp - customitem.h - main.cpp -) - -target_link_libraries(sg_example PRIVATE - rendergraph_sg - rendergraph_examples -) - -qt_add_qml_module(sg_example - URI RenderGraph - QML_FILES - qml/main.qml - RESOURCES - images/test.png - RESOURCE_PREFIX /example - NO_RESOURCE_TARGET_PATH -) - -install(TARGETS sg_example - BUNDLE DESTINATION . - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} -) - -qt_generate_deploy_qml_app_script( - TARGET sg_example - OUTPUT_SCRIPT deploy_script - MACOS_BUNDLE_POST_BUILD - NO_UNSUPPORTED_PLATFORM_ERROR - DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM -) -install(SCRIPT ${deploy_script}) diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.cpp deleted file mode 100644 index fcf1f0feb07..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.cpp +++ /dev/null @@ -1,59 +0,0 @@ -#include "customitem.h" - -#include -#include -#include -#include -#include - -#include "examplenodes.h" -#include "rendergraph/context.h" -#include "rendergraph/scenegraph/scenegraph.h" - -CustomItem::CustomItem(QQuickItem* parent) - : QQuickItem(parent) { - setFlag(ItemHasContents, true); -} - -CustomItem::~CustomItem() = default; - -void CustomItem::geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) { - m_geometryChanged = true; - update(); - QQuickItem::geometryChange(newGeometry, oldGeometry); -} - -QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { - QSGRectangleNode* bgNode; - if (!node) { - bgNode = window()->createRectangleNode(); - bgNode->setColor(QColor(0, 0, 0, 255)); - bgNode->setRect(boundingRect()); - - m_node = std::make_unique(); - m_node->appendChildNode(std::make_unique()); - m_node->appendChildNode(std::make_unique()); - m_node->appendChildNode(std::make_unique()); - - { - QImage img(":/example/images/test.png"); - auto context = rendergraph::createSgContext(window()); - static_cast(m_node->lastChild()) - ->setTexture(std::make_unique( - *context, img)); - } - - bgNode->appendChildNode(rendergraph::sgNode(m_node.get())); - - node = bgNode; - } else { - bgNode = static_cast(node); - } - - if (m_geometryChanged) { - bgNode->setRect(boundingRect()); - m_geometryChanged = false; - } - - return node; -} diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.h deleted file mode 100644 index 304fb5c8f5e..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/sg_example/customitem.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef CUSTOMITEM_H -#define CUSTOMITEM_H - -#include - -namespace rendergraph { -class Node; -} - -class CustomItem : public QQuickItem { - Q_OBJECT - QML_ELEMENT - - public: - explicit CustomItem(QQuickItem* parent = nullptr); - ~CustomItem(); - - protected: - QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*) override; - void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override; - - bool m_geometryChanged{}; - std::unique_ptr m_node; -}; - -#endif // CUSTOMITEM_H diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/images/test.png b/src/rendergraph/opengl/rendergraph/examples/sg_example/images/test.png deleted file mode 100644 index f9580346eb8b893f1d6acb3be80d2ee911bc20e5..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12849 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 G4*q`+EtQY} diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/main.cpp b/src/rendergraph/opengl/rendergraph/examples/sg_example/main.cpp deleted file mode 100644 index ab2e5b34072..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/sg_example/main.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include - -#include "customitem.h" - -int main(int argc, char** argv) { - QGuiApplication app(argc, argv); - - QQuickView view; - view.setResizeMode(QQuickView::SizeRootObjectToView); - view.setSource(QUrl("qrc:///example/qml/main.qml")); - view.show(); - - return app.exec(); -} diff --git a/src/rendergraph/opengl/rendergraph/examples/sg_example/qml/main.qml b/src/rendergraph/opengl/rendergraph/examples/sg_example/qml/main.qml deleted file mode 100644 index 2410ad1a560..00000000000 --- a/src/rendergraph/opengl/rendergraph/examples/sg_example/qml/main.qml +++ /dev/null @@ -1,13 +0,0 @@ -import QtQuick -import RenderGraph - -Item { - id: root - - width: 640 - height: 480 - - CustomItem { - anchors.fill: parent - } -} diff --git a/src/rendergraph/opengl/rendergraph/geometry.cpp b/src/rendergraph/opengl/rendergraph/geometry.cpp deleted file mode 100644 index c098f476e11..00000000000 --- a/src/rendergraph/opengl/rendergraph/geometry.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "rendergraph/geometry.h" - -#include "rendergraph/attributeset.h" - -using namespace rendergraph; - -Geometry::Geometry(const AttributeSet& attributeSet, int vertexCount) - : m_drawingMode(Geometry::DrawingMode::TriangleStrip) // to mimic sg default - , - m_vertexCount(vertexCount) { - int offset = 0; - for (const auto& attribute : attributeSet.attributes()) { - m_offsets.push_back(offset); - offset += attribute.m_tupleSize; - m_tupleSizes.push_back(attribute.m_tupleSize); - } - m_stride = offset * sizeof(float); - m_data.resize(offset * vertexCount); -} - -Geometry::~Geometry() = default; - -void Geometry::setAttributeValues(int attributePosition, const float* from, int numTuples) { - const int offset = m_offsets[attributePosition]; - const int tupleSize = m_tupleSizes[attributePosition]; - const int skip = m_stride / sizeof(float) - tupleSize; - - float* to = m_data.data(); - to += offset; - while (numTuples--) { - int k = tupleSize; - while (k--) { - *to++ = *from++; - } - to += skip; - } -} - -float* Geometry::vertexData() { - return m_data.data(); -} - -template -T* Geometry::vertexDataAs() { - return reinterpret_cast(vertexData()); -} - -template Geometry::Point2D* Geometry::vertexDataAs(); - -template Geometry::TexturedPoint2D* Geometry::vertexDataAs(); - -template Geometry::RGBColoredPoint2D* Geometry::vertexDataAs(); - -template Geometry::RGBAColoredPoint2D* Geometry::vertexDataAs(); - -void Geometry::allocate(int vertexCount) { - m_vertexCount = vertexCount; - m_data.resize((m_stride / sizeof(float)) * m_vertexCount); -} - -void Geometry::setDrawingMode(Geometry::DrawingMode mode) { - m_drawingMode = mode; -} - -Geometry::DrawingMode Geometry::drawingMode() const { - return m_drawingMode; -} - -int Geometry::attributeCount() const { - return m_tupleSizes.size(); -} - -int Geometry::vertexCount() const { - return m_vertexCount; -} - -int Geometry::offset(int attributeIndex) const { - return m_offsets[attributeIndex]; -} - -int Geometry::tupleSize(int attributeIndex) const { - return m_tupleSizes[attributeIndex]; -} - -int Geometry::stride() const { - return m_stride; -} - -Geometry::DrawingMode m_drawingMode; -int m_vertexCount; -std::vector m_tupleSizes; -std::vector m_offsets; -int m_stride; -std::vector m_data; diff --git a/src/rendergraph/opengl/rendergraph/geometry.h b/src/rendergraph/opengl/rendergraph/geometry.h deleted file mode 100644 index f85228cdbe8..00000000000 --- a/src/rendergraph/opengl/rendergraph/geometry.h +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "rendergraph/types.h" - -namespace rendergraph { -class Geometry; -class AttributeSet; -} // namespace rendergraph - -class rendergraph::Geometry { - public: - struct Point2D { - QVector2D position2D; - Point2D(float x, float y) - : position2D{x, y} { - } - }; - - struct TexturedPoint2D { - QVector2D position2D; - QVector2D texcoord2D; - TexturedPoint2D(float x, float y, float tx, float ty) - : position2D{x, y}, - texcoord2D{tx, ty} { - } - }; - - struct RGBColoredPoint2D { - QVector2D position2D; - QVector3D color3D; - RGBColoredPoint2D(float x, float y, float r, float g, float b) - : position2D{x, y}, - color3D{r, g, b} { - } - }; - - struct RGBAColoredPoint2D { - QVector2D position2D; - QVector4D color4D; - RGBAColoredPoint2D(float x, float y, float r, float g, float b, float a) - : position2D{x, y}, - color4D{r, g, b, a} { - } - }; - - enum class DrawingMode { - Triangles, - TriangleStrip - }; - - Geometry(const AttributeSet& attributeSet, int vertexCount); - ~Geometry(); - - void allocate(int vertexCount); - - void setAttributeValues(int attributePosition, const float* data, int numTuples); - - float* vertexData(); - - template - T* vertexDataAs(); - - DrawingMode drawingMode() const; - void setDrawingMode(DrawingMode mode); - - int attributeCount() const; - int vertexCount() const; - int offset(int attributeIndex) const; - int tupleSize(int attributeIndex) const; - int stride() const; - - private: - DrawingMode m_drawingMode; - int m_vertexCount; - std::vector m_tupleSizes; - std::vector m_offsets; - int m_stride; - std::vector m_data; -}; diff --git a/src/rendergraph/opengl/rendergraph/graph.h b/src/rendergraph/opengl/rendergraph/graph.h deleted file mode 100644 index e5179fdde78..00000000000 --- a/src/rendergraph/opengl/rendergraph/graph.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include -#include - -namespace rendergraph { -class Graph; -class Node; -} // namespace rendergraph - -class rendergraph::Graph { - public: - Graph(std::unique_ptr node); - ~Graph(); - void initialize(); - void render(); - void resize(int w, int h); - void preprocess(); - void addToGraph(Node* pNode); - - private: - void render(Node* pNode); - void resize(Node* pNode, int, int h); - - const std::unique_ptr m_pTopNode; - std::vector m_pPreprocessNodes; - std::vector m_pInitializeNodes; -}; diff --git a/src/rendergraph/opengl/rendergraph/material.h b/src/rendergraph/opengl/rendergraph/material.h deleted file mode 100644 index 8c54be251e2..00000000000 --- a/src/rendergraph/opengl/rendergraph/material.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/uniformscache.h" - -namespace rendergraph { -class UniformSet; -class Material; -class MaterialShader; -class MaterialType; -class Texture; -class GeometryNode; -} // namespace rendergraph - -class rendergraph::Material { - public: - Material(const UniformSet& uniformSet); - virtual ~Material(); - virtual int compare(const Material* other) const = 0; - virtual std::unique_ptr createShader() const = 0; - virtual MaterialType* type() const = 0; - - template - void setUniform(int uniformIndex, const T& value) { - m_uniformsCache.set(uniformIndex, value); - m_uniformsCacheDirty = true; - } - - void setShader(std::shared_ptr pShader); - - MaterialShader& shader() const; - - int uniformLocation(int uniformIndex) const; - int attributeLocation(int attributeIndex) const; - - private: - friend MaterialShader; - friend GeometryNode; - - void modifyShader(); - bool isLastModifierOfShader() const; - - const UniformsCache& uniformsCache() const { - return m_uniformsCache; - } - - bool clearUniformsCacheDirty() { - if (m_uniformsCacheDirty) { - m_uniformsCacheDirty = false; - return true; - } - return false; - } - - virtual Texture* texture(int /*binding*/) const { - return nullptr; - } - - std::shared_ptr m_pShader; - UniformsCache m_uniformsCache; - bool m_uniformsCacheDirty{}; -}; diff --git a/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.cpp b/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.cpp deleted file mode 100644 index fd9e5f73ec7..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "endoftrackmaterial.h" - -#include - -#include "rendergraph/materialshader.h" -#include "rendergraph/materialtype.h" -#include "rendergraph/uniformset.h" - -using namespace rendergraph; - -EndOfTrackMaterial::EndOfTrackMaterial() - : Material(uniforms()) { -} - -/* static */ const AttributeSet& EndOfTrackMaterial::attributes() { - static AttributeSet set = makeAttributeSet({"position", "gradient"}); - return set; -} - -/* static */ const UniformSet& EndOfTrackMaterial::uniforms() { - static UniformSet set = makeUniformSet({"ubuf.color"}); - return set; -} - -MaterialType* EndOfTrackMaterial::type() const { - static MaterialType type; - return &type; -} - -int EndOfTrackMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - -std::unique_ptr EndOfTrackMaterial::createShader() const { - return std::make_unique( - "endoftrack.vert", "endoftrack.frag", uniforms(), attributes()); -} diff --git a/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.h b/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.h deleted file mode 100644 index e66a825c164..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/endoftrackmaterial.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "rendergraph/attributeset.h" -#include "rendergraph/material.h" - -namespace rendergraph { -class EndOfTrackMaterial; -} - -class rendergraph::EndOfTrackMaterial : public rendergraph::Material { - public: - EndOfTrackMaterial(); - - static const AttributeSet& attributes(); - - static const UniformSet& uniforms(); - - MaterialType* type() const override; - - int compare(const Material* other) const override; - - std::unique_ptr createShader() const override; -}; diff --git a/src/rendergraph/opengl/rendergraph/material/patternmaterial.cpp b/src/rendergraph/opengl/rendergraph/material/patternmaterial.cpp deleted file mode 100644 index e16ca4213d7..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/patternmaterial.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "patternmaterial.h" - -#include -#include - -#include "rendergraph/materialshader.h" -#include "rendergraph/materialtype.h" - -using namespace rendergraph; - -PatternMaterial::PatternMaterial() - : Material(uniforms()) { -} - -/* static */ const AttributeSet& PatternMaterial::attributes() { - static AttributeSet set = makeAttributeSet({"position", "texcoord"}); - return set; -} - -/* static */ const UniformSet& PatternMaterial::uniforms() { - static UniformSet set = makeUniformSet({"ubuf.matrix"}); - return set; -} - -MaterialType* PatternMaterial::type() const { - static MaterialType type; - return &type; -} - -int PatternMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - -std::unique_ptr PatternMaterial::createShader() const { - return std::make_unique( - "pattern.vert", "pattern.frag", uniforms(), attributes()); -} diff --git a/src/rendergraph/opengl/rendergraph/material/patternmaterial.h b/src/rendergraph/opengl/rendergraph/material/patternmaterial.h deleted file mode 100644 index 0df75c07371..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/patternmaterial.h +++ /dev/null @@ -1,34 +0,0 @@ -#include "rendergraph/attributeset.h" -#include "rendergraph/material.h" -#include "rendergraph/texture.h" -#include "rendergraph/uniformset.h" - -namespace rendergraph { -class PatternMaterial; -} - -class rendergraph::PatternMaterial : public rendergraph::Material { - public: - PatternMaterial(); - - static const AttributeSet& attributes(); - - static const UniformSet& uniforms(); - - MaterialType* type() const override; - - int compare(const Material* other) const override; - - std::unique_ptr createShader() const override; - - Texture* texture(int /*binding*/) const override { - return m_pTexture.get(); - } - - void setTexture(std::unique_ptr texture) { - m_pTexture = std::move(texture); - } - - private: - std::unique_ptr m_pTexture; -}; diff --git a/src/rendergraph/opengl/rendergraph/material/rgbamaterial.cpp b/src/rendergraph/opengl/rendergraph/material/rgbamaterial.cpp deleted file mode 100644 index c1d53d3f8bc..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/rgbamaterial.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "rgbamaterial.h" - -#include - -#include "rendergraph/materialshader.h" -#include "rendergraph/materialtype.h" -#include "rendergraph/uniformset.h" - -using namespace rendergraph; - -RGBAMaterial::RGBAMaterial() - : Material(uniforms()) { -} - -/* static */ const AttributeSet& RGBAMaterial::attributes() { - static AttributeSet set = makeAttributeSet({"position", "color"}); - return set; -} - -/* static */ const UniformSet& RGBAMaterial::uniforms() { - static UniformSet set = makeUniformSet({"ubuf.matrix"}); - return set; -} - -MaterialType* RGBAMaterial::type() const { - static MaterialType type; - return &type; -} - -int RGBAMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - -std::unique_ptr RGBAMaterial::createShader() const { - return std::make_unique( - "rgba.vert", "rgba.frag", uniforms(), attributes()); -} diff --git a/src/rendergraph/opengl/rendergraph/material/rgbamaterial.h b/src/rendergraph/opengl/rendergraph/material/rgbamaterial.h deleted file mode 100644 index b5b72a949c9..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/rgbamaterial.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "rendergraph/attributeset.h" -#include "rendergraph/material.h" - -namespace rendergraph { -class RGBAMaterial; -} - -class rendergraph::RGBAMaterial : public rendergraph::Material { - public: - RGBAMaterial(); - - static const AttributeSet& attributes(); - - static const UniformSet& uniforms(); - - MaterialType* type() const override; - - int compare(const Material* other) const override; - - std::unique_ptr createShader() const override; -}; diff --git a/src/rendergraph/opengl/rendergraph/material/rgbmaterial.cpp b/src/rendergraph/opengl/rendergraph/material/rgbmaterial.cpp deleted file mode 100644 index 3a2f014d07e..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/rgbmaterial.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "rgbmaterial.h" - -#include - -#include "rendergraph/materialshader.h" -#include "rendergraph/materialtype.h" -#include "rendergraph/uniformset.h" - -using namespace rendergraph; - -RGBMaterial::RGBMaterial() - : Material(uniforms()) { -} - -/* static */ const AttributeSet& RGBMaterial::attributes() { - static AttributeSet set = makeAttributeSet({"position", "color"}); - return set; -} - -/* static */ const UniformSet& RGBMaterial::uniforms() { - static UniformSet set = makeUniformSet({"ubuf.matrix"}); - return set; -} - -MaterialType* RGBMaterial::type() const { - static MaterialType type; - return &type; -} - -int RGBMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - -std::unique_ptr RGBMaterial::createShader() const { - return std::make_unique( - "rgb.vert", "rgb.frag", uniforms(), attributes()); -} diff --git a/src/rendergraph/opengl/rendergraph/material/rgbmaterial.h b/src/rendergraph/opengl/rendergraph/material/rgbmaterial.h deleted file mode 100644 index 6d4d74b2514..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/rgbmaterial.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "rendergraph/attributeset.h" -#include "rendergraph/material.h" - -namespace rendergraph { -class RGBMaterial; -} - -class rendergraph::RGBMaterial : public rendergraph::Material { - public: - RGBMaterial(); - - static const AttributeSet& attributes(); - - static const UniformSet& uniforms(); - - MaterialType* type() const override; - - int compare(const Material* other) const override; - - std::unique_ptr createShader() const override; -}; diff --git a/src/rendergraph/opengl/rendergraph/material/texturematerial.cpp b/src/rendergraph/opengl/rendergraph/material/texturematerial.cpp deleted file mode 100644 index 090e6070d98..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/texturematerial.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "texturematerial.h" - -#include -#include - -#include "rendergraph/materialshader.h" -#include "rendergraph/materialtype.h" - -using namespace rendergraph; - -TextureMaterial::TextureMaterial() - : Material(uniforms()) { -} - -/* static */ const AttributeSet& TextureMaterial::attributes() { - static AttributeSet set = makeAttributeSet({"position", "texcoord"}); - return set; -} - -/* static */ const UniformSet& TextureMaterial::uniforms() { - static UniformSet set = makeUniformSet({"ubuf.matrix"}); - return set; -} - -MaterialType* TextureMaterial::type() const { - static MaterialType type; - return &type; -} - -int TextureMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - -std::unique_ptr TextureMaterial::createShader() const { - return std::make_unique( - "texture.vert", "texture.frag", uniforms(), attributes()); -} diff --git a/src/rendergraph/opengl/rendergraph/material/texturematerial.h b/src/rendergraph/opengl/rendergraph/material/texturematerial.h deleted file mode 100644 index 4e0ac39b989..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/texturematerial.h +++ /dev/null @@ -1,34 +0,0 @@ -#include "rendergraph/attributeset.h" -#include "rendergraph/material.h" -#include "rendergraph/texture.h" -#include "rendergraph/uniformset.h" - -namespace rendergraph { -class TextureMaterial; -} - -class rendergraph::TextureMaterial : public rendergraph::Material { - public: - TextureMaterial(); - - static const AttributeSet& attributes(); - - static const UniformSet& uniforms(); - - MaterialType* type() const override; - - int compare(const Material* other) const override; - - std::unique_ptr createShader() const override; - - Texture* texture(int /*binding*/) const override { - return m_pTexture.get(); - } - - void setTexture(std::unique_ptr texture) { - m_pTexture = std::move(texture); - } - - private: - std::unique_ptr m_pTexture; -}; diff --git a/src/rendergraph/opengl/rendergraph/material/unicolormaterial.cpp b/src/rendergraph/opengl/rendergraph/material/unicolormaterial.cpp deleted file mode 100644 index 8e4bf12ed9c..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/unicolormaterial.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "unicolormaterial.h" - -#include - -#include "rendergraph/materialshader.h" -#include "rendergraph/materialtype.h" -#include "rendergraph/uniformset.h" - -using namespace rendergraph; - -UniColorMaterial::UniColorMaterial() - : Material(uniforms()) { -} - -/* static */ const AttributeSet& UniColorMaterial::attributes() { - static AttributeSet set = makeAttributeSet({"position"}); - return set; -} - -/* static */ const UniformSet& UniColorMaterial::uniforms() { - static UniformSet set = makeUniformSet({"ubuf.matrix", "ubuf.color"}); - return set; -} - -MaterialType* UniColorMaterial::type() const { - static MaterialType type; - return &type; -} - -int UniColorMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - -std::unique_ptr UniColorMaterial::createShader() const { - return std::make_unique( - "unicolor.vert", "unicolor.frag", uniforms(), attributes()); -} diff --git a/src/rendergraph/opengl/rendergraph/material/unicolormaterial.h b/src/rendergraph/opengl/rendergraph/material/unicolormaterial.h deleted file mode 100644 index 9516bb8c731..00000000000 --- a/src/rendergraph/opengl/rendergraph/material/unicolormaterial.h +++ /dev/null @@ -1,21 +0,0 @@ -#include "rendergraph/attributeset.h" -#include "rendergraph/material.h" - -namespace rendergraph { -class UniColorMaterial; -} - -class rendergraph::UniColorMaterial : public rendergraph::Material { - public: - UniColorMaterial(); - - static const AttributeSet& attributes(); - - static const UniformSet& uniforms(); - - MaterialType* type() const override; - - int compare(const Material* other) const override; - - std::unique_ptr createShader() const override; -}; diff --git a/src/rendergraph/opengl/rendergraph/materialtype.cpp b/src/rendergraph/opengl/rendergraph/materialtype.cpp deleted file mode 100644 index 3839d6f5b8e..00000000000 --- a/src/rendergraph/opengl/rendergraph/materialtype.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "rendergraph/materialtype.h" - -using namespace rendergraph; - -MaterialType::MaterialType() = default; -MaterialType::~MaterialType() = default; diff --git a/src/rendergraph/opengl/rendergraph/materialtype.h b/src/rendergraph/opengl/rendergraph/materialtype.h deleted file mode 100644 index d5b5c980fbd..00000000000 --- a/src/rendergraph/opengl/rendergraph/materialtype.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -namespace rendergraph { -class MaterialType; -} - -class rendergraph::MaterialType { - public: - MaterialType(); - ~MaterialType(); -}; diff --git a/src/rendergraph/opengl/rendergraph/node.h b/src/rendergraph/opengl/rendergraph/node.h deleted file mode 100644 index f8f49a8bbeb..00000000000 --- a/src/rendergraph/opengl/rendergraph/node.h +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once - -#include -#include - -namespace rendergraph { -class Node; -class Graph; -} // namespace rendergraph - -class rendergraph::Node { - public: - Node(); - - virtual ~Node(); - - void appendChildNode(std::unique_ptr&& pChild); - std::unique_ptr removeAllChildNodes(); - std::unique_ptr removeChildNode(Node* pChild); - - Node* parent() const { - return m_pParent; - } - Node* firstChild() const { - return m_pFirstChild.get(); - } - Node* lastChild() const { - return m_pLastChild; - } - Node* nextSibling() const { - return m_pNextSibling.get(); - } - Node* previousSibling() const { - return m_pPreviousSibling; - } - - virtual bool isSubtreeBlocked() const { - return false; - } - - virtual void preprocess() { - } - - virtual void initialize() { - } - virtual void render() { - } - virtual void resize(int, int) { - } - - void setUsePreprocess(bool value) { - m_usePreprocess = value; - } - bool usePreprocess() const { - return m_usePreprocess; - } - - Graph* graph() const { - return m_pGraph; - } - void setGraph(Graph* pGraph) { - m_pGraph = pGraph; - } - - private: - Graph* m_pGraph{}; - Node* m_pParent{}; - std::unique_ptr m_pFirstChild; - Node* m_pLastChild{}; - std::unique_ptr m_pNextSibling; - Node* m_pPreviousSibling{}; - - bool m_usePreprocess{}; -}; diff --git a/src/rendergraph/opengl/rendergraph/opacitynode.cpp b/src/rendergraph/opengl/rendergraph/opacitynode.cpp deleted file mode 100644 index 3059ae0886b..00000000000 --- a/src/rendergraph/opengl/rendergraph/opacitynode.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "rendergraph/opacitynode.h" - -using namespace rendergraph; - -OpacityNode::OpacityNode() = default; - -OpacityNode::~OpacityNode() = default; - -void OpacityNode::setOpacity(float opacity) { - m_opacity = opacity; -} - -bool OpacityNode::isSubtreeBlocked() const { - return m_opacity == 0.f; -} diff --git a/src/rendergraph/opengl/rendergraph/opacitynode.h b/src/rendergraph/opengl/rendergraph/opacitynode.h deleted file mode 100644 index a9a7b0216df..00000000000 --- a/src/rendergraph/opengl/rendergraph/opacitynode.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "rendergraph/node.h" - -namespace rendergraph { -class OpacityNode; -} // namespace rendergraph - -class rendergraph::OpacityNode : public rendergraph::Node { - public: - OpacityNode(); - ~OpacityNode(); - void setOpacity(float opacity); - bool isSubtreeBlocked() const override; - - private: - float m_opacity{1.f}; -}; diff --git a/src/rendergraph/opengl/rendergraph/openglnode.cpp b/src/rendergraph/opengl/rendergraph/openglnode.cpp deleted file mode 100644 index f13844449e8..00000000000 --- a/src/rendergraph/opengl/rendergraph/openglnode.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "rendergraph/openglnode.h" - -using namespace rendergraph; - -OpenGLNode::OpenGLNode() = default; -OpenGLNode::~OpenGLNode() = default; - -void OpenGLNode::initialize() { - initializeOpenGLFunctions(); - initializeGL(); - Node::initialize(); -} - -void OpenGLNode::render() { - paintGL(); - Node::render(); -} - -void OpenGLNode::resize(int w, int h) { - resizeGL(w, h); - Node::resize(w, h); -} diff --git a/src/rendergraph/opengl/rendergraph/openglnode.h b/src/rendergraph/opengl/rendergraph/openglnode.h index 8ff3dedc74d..f2d188fcabb 100644 --- a/src/rendergraph/opengl/rendergraph/openglnode.h +++ b/src/rendergraph/opengl/rendergraph/openglnode.h @@ -1,17 +1,16 @@ #pragma once -#include - -#include "rendergraph/node.h" +#include "backend/openglnode.h" +#include "rendergraph/basenode.h" namespace rendergraph { class OpenGLNode; } // namespace rendergraph -class rendergraph::OpenGLNode : public rendergraph::Node, public QOpenGLFunctions { +class rendergraph::OpenGLNode : public rendergraph::backend::OpenGLNode, + public rendergraph::BaseNode { public: OpenGLNode(); - ~OpenGLNode(); virtual void initializeGL() { } @@ -19,7 +18,4 @@ class rendergraph::OpenGLNode : public rendergraph::Node, public QOpenGLFunction } virtual void resizeGL(int, int) { } - void initialize() override; - void render() override; - void resize(int w, int h) override; }; diff --git a/src/rendergraph/opengl/rendergraph/shadercache.h b/src/rendergraph/opengl/rendergraph/shadercache.h deleted file mode 100644 index 15a4aee6799..00000000000 --- a/src/rendergraph/opengl/rendergraph/shadercache.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/material.h" -#include "rendergraph/materialshader.h" - -namespace rendergraph { -class ShaderCache; -} - -class rendergraph::ShaderCache { - private: - static std::map>& map() { - static std::map> s_map; - return s_map; - } - - public: - static std::shared_ptr getShaderForMaterial(Material* pMaterial) { - auto iter = map().find(pMaterial->type()); - if (iter != map().end()) { - return iter->second; - } - auto pResult = std::shared_ptr(pMaterial->createShader().release()); - map().insert(std::pair>{ - pMaterial->type(), pResult}); - return pResult; - } - static void purge() { - auto iter = map().begin(); - while (iter != map().end()) { - if (iter->second.use_count() == 1) { - iter = map().erase(iter); - } else { - ++iter; - } - } - } -}; diff --git a/src/rendergraph/opengl/rendergraph/types.cpp b/src/rendergraph/opengl/rendergraph/types.cpp deleted file mode 100644 index a44d113d7f8..00000000000 --- a/src/rendergraph/opengl/rendergraph/types.cpp +++ /dev/null @@ -1,107 +0,0 @@ -#include "rendergraph/types.h" - -#include - -using namespace rendergraph; - -int rendergraph::sizeOf(PrimitiveType type) { - switch (type) { - case PrimitiveType::UInt: - return sizeof(GLuint); - case PrimitiveType::Float: - return sizeof(GLfloat); - } - return 0; -} - -int rendergraph::sizeOf(Type type) { - switch (type) { - case Type::UInt: - return sizeof(GLuint); - case Type::Float: - return sizeof(GLfloat); - case Type::Vector2D: - return sizeof(GLfloat) * 2; - case Type::Vector3D: - return sizeof(GLfloat) * 3; - case Type::Vector4D: - return sizeof(GLfloat) * 4; - case Type::Matrix4x4: - return sizeof(GLfloat) * 4 * 4; - } - return 0; -} - -template<> -Type rendergraph::typeOf() { - return Type::UInt; -} - -template<> -Type rendergraph::typeOf() { - return Type::Float; -} - -template<> -Type rendergraph::typeOf() { - return Type::Vector2D; -} - -template<> -Type rendergraph::typeOf() { - return Type::Vector3D; -} - -template<> -Type rendergraph::typeOf() { - return Type::Vector4D; -} - -template<> -Type rendergraph::typeOf() { - return Type::Matrix4x4; -} - -template<> -PrimitiveType rendergraph::primitiveTypeOf() { - return PrimitiveType::Float; -} - -template<> -PrimitiveType rendergraph::primitiveTypeOf() { - return PrimitiveType::UInt; -} - -template<> -PrimitiveType rendergraph::primitiveTypeOf() { - return PrimitiveType::Float; -} -template<> -PrimitiveType rendergraph::primitiveTypeOf() { - return PrimitiveType::Float; -} -template<> -PrimitiveType rendergraph::primitiveTypeOf() { - return PrimitiveType::Float; -} - -template<> -int rendergraph::tupleSizeOf() { - return 1; -} -template<> -int rendergraph::tupleSizeOf() { - return 1; -} -template<> -int rendergraph::tupleSizeOf() { - return 2; -} -template<> -int rendergraph::tupleSizeOf() { - return 3; -} -template<> -int rendergraph::tupleSizeOf() { - return 4; -} diff --git a/src/rendergraph/opengl/rendergraph/texture.cpp b/src/rendergraph/opengl/texture.cpp similarity index 71% rename from src/rendergraph/opengl/rendergraph/texture.cpp rename to src/rendergraph/opengl/texture.cpp index fd3c9e16b19..8851d927508 100644 --- a/src/rendergraph/opengl/rendergraph/texture.cpp +++ b/src/rendergraph/opengl/texture.cpp @@ -1,22 +1,11 @@ #include "rendergraph/texture.h" -#include +#include "rendergraph/context.h" using namespace rendergraph; -Texture::Texture(Context& context, const QImage& image) - : m_pTexture(new QOpenGLTexture(premultiplyAlpha(image))) { - m_pTexture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); - m_pTexture->setWrapMode(QOpenGLTexture::ClampToEdge); -} - -Texture::~Texture() = default; - -QOpenGLTexture* Texture::glTexture() const { - return m_pTexture.get(); -} - -QImage Texture::premultiplyAlpha(const QImage& image) { +namespace { +QImage premultiplyAlpha(const QImage& image) { if (image.format() == QImage::Format_RGBA8888_Premultiplied) { return QImage(image.bits(), image.width(), image.height(), QImage::Format_RGBA8888); } @@ -27,3 +16,10 @@ QImage Texture::premultiplyAlpha(const QImage& image) { image.height(), QImage::Format_RGBA8888); } +} // namespace + +Texture::Texture(Context& context, const QImage& image) + : m_pTexture(std::make_unique(premultiplyAlpha(image))) { + m_pTexture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); + m_pTexture->setWrapMode(QOpenGLTexture::ClampToEdge); +} diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index df2c07f227b..3c020079e20 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -1,46 +1,57 @@ add_library(rendergraph_sg - rendergraph/attributeset.cpp - rendergraph/attributeset.h - rendergraph/context.cpp - rendergraph/context.h - rendergraph/geometry.cpp - rendergraph/geometry.h - rendergraph/geometrynode.cpp - rendergraph/geometrynode.h - rendergraph/material.cpp - rendergraph/material.h - rendergraph/materialshader.cpp - rendergraph/materialshader.h - rendergraph/materialtype.cpp - rendergraph/materialtype.h - rendergraph/node.cpp - rendergraph/node.h - rendergraph/opacitynode.cpp - rendergraph/opacitynode.h - rendergraph/texture.cpp - rendergraph/texture.h - rendergraph/types.cpp - rendergraph/scenegraph.cpp - rendergraph/scenegraph.h - ../common/rendergraph/material/endoftrackmaterial.cpp - ../common/rendergraph/material/endoftrackmaterial.h - ../common/rendergraph/material/patternmaterial.cpp - ../common/rendergraph/material/patternmaterial.h - ../common/rendergraph/material/rgbamaterial.cpp - ../common/rendergraph/material/rgbamaterial.h - ../common/rendergraph/material/rgbmaterial.cpp - ../common/rendergraph/material/rgbmaterial.h - ../common/rendergraph/material/texturematerial.cpp - ../common/rendergraph/material/texturematerial.h - ../common/rendergraph/material/unicolormaterial.cpp - ../common/rendergraph/material/unicolormaterial.h - ../common/rendergraph/attribute.h - ../common/rendergraph/types.h - ../common/rendergraph/uniform.h - ../common/rendergraph/uniformscache.cpp - ../common/rendergraph/uniformscache.h - ../common/rendergraph/uniformset.cpp - ../common/rendergraph/uniformset.h +../common/attributeset.cpp +../common/basenode.cpp +../common/node.cpp +../common/opacitynode.cpp +../common/rendergraph/attribute.h +../common/rendergraph/attributeset.h +../common/rendergraph/basenode.h +../common/rendergraph/geometry.h +../common/rendergraph/geometrynode.h +../common/rendergraph/material.h +../common/rendergraph/material/endoftrackmaterial.cpp +../common/rendergraph/material/endoftrackmaterial.h +../common/rendergraph/material/patternmaterial.cpp +../common/rendergraph/material/patternmaterial.h +../common/rendergraph/material/rgbamaterial.cpp +../common/rendergraph/material/rgbamaterial.h +../common/rendergraph/material/rgbmaterial.cpp +../common/rendergraph/material/rgbmaterial.h +../common/rendergraph/material/texturematerial.cpp +../common/rendergraph/material/texturematerial.h +../common/rendergraph/material/unicolormaterial.cpp +../common/rendergraph/material/unicolormaterial.h +../common/rendergraph/materialshader.h +../common/rendergraph/materialtype.h +../common/rendergraph/node.h +../common/rendergraph/opacitynode.h +../common/rendergraph/texture.h +../common/rendergraph/types.h +../common/rendergraph/uniform.h +../common/rendergraph/uniformscache.cpp +../common/rendergraph/uniformscache.h +../common/rendergraph/uniformset.cpp +../common/rendergraph/uniformset.h +../common/types.cpp +backend/attributeset.cpp +backend/attributeset.h +backend/geometry.h +backend/geometrynode.h +backend/material.cpp +backend/material.h +backend/materialshader.cpp +backend/materialtype.h +backend/node.h +backend/opacitynode.h +backend/texture.h +basenode.cpp +context.cpp +geometry.cpp +geometrynode.cpp +material.cpp +materialshader.cpp +rendergraph/context.h +texture.cpp ) target_link_libraries(rendergraph_sg PUBLIC diff --git a/src/rendergraph/scenegraph/backend/attributeset.cpp b/src/rendergraph/scenegraph/backend/attributeset.cpp new file mode 100644 index 00000000000..b3733ce1547 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/attributeset.cpp @@ -0,0 +1,32 @@ +#include "backend/attributeset.h" + +using namespace rendergraph::backend; + +namespace { +int toQSGGeometryType(const rendergraph::PrimitiveType& t) { + switch (t) { + case rendergraph::PrimitiveType::Float: + return QSGGeometry::FloatType; + case rendergraph::PrimitiveType::UInt: + return QSGGeometry::UnsignedIntType; + } +} +} // namespace + +AttributeSetBase::AttributeSetBase(std::initializer_list list, + const std::vector& names) { + int i = 0; + for (auto item : list) { + m_attributes.push_back(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); + + const auto& attribute = m_attributes.back(); + + const int count = static_cast(m_sgAttributes.size()); + const bool isPosition = count == 0; + m_sgAttributes.push_back(QSGGeometry::Attribute::create(count, + attribute.m_tupleSize, + toQSGGeometryType(attribute.m_primitiveType), + isPosition)); + m_stride += attribute.m_tupleSize * sizeOf(attribute.m_primitiveType); + } +} diff --git a/src/rendergraph/scenegraph/backend/attributeset.h b/src/rendergraph/scenegraph/backend/attributeset.h new file mode 100644 index 00000000000..8b887c5ac81 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/attributeset.h @@ -0,0 +1,40 @@ +#pragma once + +#include +#include +#include + +#include "rendergraph/attribute.h" + +namespace rendergraph::backend { +class AttributeSet; +class AttributeSetBase; +} // namespace rendergraph::backend + +class rendergraph::backend::AttributeSetBase { + protected: + int m_stride{}; + + AttributeSetBase(std::initializer_list list, const std::vector& names); + + const std::vector& attributes() const { + return m_attributes; + } + + std::vector m_attributes; + QSGGeometry::AttributeSet m_sgAttributeSet{}; + std::vector m_sgAttributes; +}; + +class rendergraph::backend::AttributeSet + : protected rendergraph::backend::AttributeSetBase, + public QSGGeometry::AttributeSet { + protected: + AttributeSet(std::initializer_list list, + const std::vector& names) + : AttributeSetBase(list, names), + QSGGeometry::AttributeSet{static_cast(m_sgAttributes.size()), + m_stride, + m_sgAttributes.data()} { + } +}; diff --git a/src/rendergraph/scenegraph/backend/geometry.h b/src/rendergraph/scenegraph/backend/geometry.h new file mode 100644 index 00000000000..077c19e4450 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/geometry.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include "rendergraph/attributeset.h" + +namespace rendergraph::backend { +class Geometry; +} + +class rendergraph::backend::Geometry : public QSGGeometry { + protected: + Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount) + : QSGGeometry(attributeSet, vertexCount), + m_stride(attributeSet.stride) { + QSGGeometry::setDrawingMode(QSGGeometry::DrawTriangleStrip); + } + const int m_stride; +}; diff --git a/src/rendergraph/scenegraph/backend/geometrynode.h b/src/rendergraph/scenegraph/backend/geometrynode.h new file mode 100644 index 00000000000..3abf5888a41 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/geometrynode.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph::backend { +using GeometryNode = QSGGeometryNode; +} diff --git a/src/rendergraph/scenegraph/backend/material.cpp b/src/rendergraph/scenegraph/backend/material.cpp new file mode 100644 index 00000000000..26a0188feb8 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/material.cpp @@ -0,0 +1,28 @@ +#include "rendergraph/material.h" + +#include "rendergraph/materialshader.h" + +using namespace rendergraph::backend; + +bool Material::updateUniformsByteArray(QByteArray* buf) { + auto pThis = static_cast(this); + if (pThis->clearUniformsCacheDirty()) { + memcpy(buf->data(), pThis->uniformsCache().data(), pThis->uniformsCache().size()); + return true; + } + return false; +} + +int Material::compare(const QSGMaterial* other) const { + auto pThis = static_cast(this); + return pThis->compare(dynamic_cast(other)); +} + +QSGMaterialShader* Material::createShader(QSGRendererInterface::RenderMode) const { + // This looks like a leak but it isn't: we pass ownership to Qt. Qt will + // cache and reuse the shader for all Material of the same type. + // TODO make sure that RenderMode is always the same. + auto pThis = static_cast(this); + auto pShader = pThis->createShader().release(); + return pShader; +} diff --git a/src/rendergraph/scenegraph/backend/material.h b/src/rendergraph/scenegraph/backend/material.h new file mode 100644 index 00000000000..0f395f58199 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/material.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +namespace rendergraph::backend { +class Material; +} + +class rendergraph::backend::Material : public QSGMaterial { + protected: + Material() = default; + + public: + QSGMaterialShader* createShader(QSGRendererInterface::RenderMode) const override; + + int compare(const QSGMaterial* other) const override; + + bool updateUniformsByteArray(QByteArray* buf); +}; diff --git a/src/rendergraph/scenegraph/backend/materialshader.cpp b/src/rendergraph/scenegraph/backend/materialshader.cpp new file mode 100644 index 00000000000..cf03833c96a --- /dev/null +++ b/src/rendergraph/scenegraph/backend/materialshader.cpp @@ -0,0 +1,22 @@ +#include "backend/materialshader.h" + +#include + +#include "rendergraph/material.h" + +using namespace rendergraph::backend; + +bool MaterialShader::updateUniformData(RenderState& state, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) { + return static_cast(newMaterial)->updateUniformsByteArray(state.uniformData()); +} + +void MaterialShader::updateSampledImage(RenderState& state, + int binding, + QSGTexture** texture, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) { + *texture = static_cast(newMaterial)->texture(binding)->backendTexture(); + (*texture)->commitTextureOperations(state.rhi(), state.resourceUpdateBatch()); +} diff --git a/src/rendergraph/scenegraph/rendergraph/materialshader.h b/src/rendergraph/scenegraph/backend/materialshader.h similarity index 60% rename from src/rendergraph/scenegraph/rendergraph/materialshader.h rename to src/rendergraph/scenegraph/backend/materialshader.h index fd87d03f174..26a9d270135 100644 --- a/src/rendergraph/scenegraph/rendergraph/materialshader.h +++ b/src/rendergraph/scenegraph/backend/materialshader.h @@ -1,21 +1,17 @@ #pragma once #include +#include -namespace rendergraph { -class AttributeSet; -class UniformSet; +namespace rendergraph::backend { class MaterialShader; -} // namespace rendergraph +} -class rendergraph::MaterialShader : public QSGMaterialShader { - public: - MaterialShader(const char* vertexShaderFile, - const char* fragmentShaderFile, - const UniformSet& uniforms, - const AttributeSet& attributeSet); - ~MaterialShader(); +class rendergraph::backend::MaterialShader : public QSGMaterialShader { + protected: + MaterialShader() = default; + public: bool updateUniformData(RenderState& state, QSGMaterial* newMaterial, QSGMaterial* oldMaterial) override; diff --git a/src/rendergraph/scenegraph/backend/materialtype.h b/src/rendergraph/scenegraph/backend/materialtype.h new file mode 100644 index 00000000000..1587eb28b1a --- /dev/null +++ b/src/rendergraph/scenegraph/backend/materialtype.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace rendergraph::backend { +class MaterialType; +} + +class rendergraph::backend::MaterialType : public QSGMaterialType { +}; diff --git a/src/rendergraph/scenegraph/backend/node.h b/src/rendergraph/scenegraph/backend/node.h new file mode 100644 index 00000000000..1cbdf98bc97 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/node.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph::backend { +using Node = QSGNode; +} diff --git a/src/rendergraph/scenegraph/backend/opacitynode.h b/src/rendergraph/scenegraph/backend/opacitynode.h new file mode 100644 index 00000000000..18ad539cc9d --- /dev/null +++ b/src/rendergraph/scenegraph/backend/opacitynode.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph::backend { +using OpacityNode = QSGOpacityNode; +} diff --git a/src/rendergraph/scenegraph/backend/texture.h b/src/rendergraph/scenegraph/backend/texture.h new file mode 100644 index 00000000000..9ca05aa9262 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/texture.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph::backend { +using Texture = QSGTexture; +} diff --git a/src/rendergraph/scenegraph/basenode.cpp b/src/rendergraph/scenegraph/basenode.cpp new file mode 100644 index 00000000000..5ffcadfd8c4 --- /dev/null +++ b/src/rendergraph/scenegraph/basenode.cpp @@ -0,0 +1,19 @@ +#include "rendergraph/basenode.h" + +using namespace rendergraph; + +void BaseNode::setUsePreprocess(bool value) { + backendNode()->setFlag(QSGNode::UsePreprocess, value); +} + +void BaseNode::onAppendChildNode(BaseNode* pChild) { + backendNode()->appendChildNode(pChild->backendNode()); +} + +void BaseNode::onRemoveChildNode(BaseNode* pChild) { + backendNode()->removeChildNode(pChild->backendNode()); +} + +void BaseNode::onRemoveAllChildNodes() { + backendNode()->removeAllChildNodes(); +} diff --git a/src/rendergraph/scenegraph/context.cpp b/src/rendergraph/scenegraph/context.cpp new file mode 100644 index 00000000000..61c5e12caa7 --- /dev/null +++ b/src/rendergraph/scenegraph/context.cpp @@ -0,0 +1,11 @@ +#include "rendergraph/context.h" + +using namespace rendergraph; + +Context::Context(QQuickWindow* pWindow) + : m_pWindow(pWindow) { +} + +QQuickWindow* Context::window() const { + return m_pWindow; +} diff --git a/src/rendergraph/scenegraph/rendergraph/geometry.cpp b/src/rendergraph/scenegraph/geometry.cpp similarity index 81% rename from src/rendergraph/scenegraph/rendergraph/geometry.cpp rename to src/rendergraph/scenegraph/geometry.cpp index caf16a5d4c3..fbabdc36c77 100644 --- a/src/rendergraph/scenegraph/rendergraph/geometry.cpp +++ b/src/rendergraph/scenegraph/geometry.cpp @@ -1,13 +1,31 @@ #include "rendergraph/geometry.h" -#include "rendergraph/attributeset.h" - using namespace rendergraph; +namespace { +QSGGeometry::DrawingMode toSgDrawingMode(Geometry::DrawingMode mode) { + switch (mode) { + case Geometry::DrawingMode::Triangles: + return QSGGeometry::DrawTriangles; + case Geometry::DrawingMode::TriangleStrip: + return QSGGeometry::DrawTriangleStrip; + } +} + +Geometry::DrawingMode fromSgDrawingMode(unsigned int mode) { + switch (mode) { + case QSGGeometry::DrawTriangles: + return Geometry::DrawingMode::Triangles; + case QSGGeometry::DrawTriangleStrip: + return Geometry::DrawingMode::TriangleStrip; + default: + throw "not implemented"; + } +} +} // namespace + Geometry::Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount) - : QSGGeometry(attributeSet.sgAttributeSet(), vertexCount), - m_stride(attributeSet.sgAttributeSet().stride) { - QSGGeometry::setDrawingMode(QSGGeometry::DrawTriangleStrip); + : backend::Geometry(attributeSet, vertexCount) { } Geometry::~Geometry() = default; @@ -47,23 +65,3 @@ void Geometry::setDrawingMode(Geometry::DrawingMode mode) { Geometry::DrawingMode Geometry::drawingMode() const { return fromSgDrawingMode(QSGGeometry::drawingMode()); } - -QSGGeometry::DrawingMode Geometry::toSgDrawingMode(Geometry::DrawingMode mode) { - switch (mode) { - case Geometry::DrawingMode::Triangles: - return QSGGeometry::DrawTriangles; - case Geometry::DrawingMode::TriangleStrip: - return QSGGeometry::DrawTriangleStrip; - } -} - -Geometry::DrawingMode Geometry::fromSgDrawingMode(unsigned int mode) { - switch (mode) { - case QSGGeometry::DrawTriangles: - return Geometry::DrawingMode::Triangles; - case QSGGeometry::DrawTriangleStrip: - return Geometry::DrawingMode::TriangleStrip; - default: - throw "not implemented"; - } -} diff --git a/src/rendergraph/scenegraph/geometrynode.cpp b/src/rendergraph/scenegraph/geometrynode.cpp new file mode 100644 index 00000000000..5d35e7d76dd --- /dev/null +++ b/src/rendergraph/scenegraph/geometrynode.cpp @@ -0,0 +1,25 @@ +#include "rendergraph/geometrynode.h" + +using namespace rendergraph; + +GeometryNode::GeometryNode() + : BaseNode(this) { +} + +void GeometryNode::setGeometry(std::unique_ptr pGeometry) { + m_pGeometry = std::move(pGeometry); + QSGGeometryNode::setGeometry(m_pGeometry.get()); +} + +void GeometryNode::setMaterial(std::unique_ptr pMaterial) { + m_pMaterial = std::move(pMaterial); + QSGGeometryNode::setMaterial(m_pMaterial.get()); +} + +Geometry& GeometryNode::geometry() const { + return *m_pGeometry; +} + +Material& GeometryNode::material() const { + return *m_pMaterial; +} diff --git a/src/rendergraph/scenegraph/material.cpp b/src/rendergraph/scenegraph/material.cpp new file mode 100644 index 00000000000..79cd048b011 --- /dev/null +++ b/src/rendergraph/scenegraph/material.cpp @@ -0,0 +1,10 @@ +#include "rendergraph/material.h" + +using namespace rendergraph; + +Material::Material(const UniformSet& uniformSet) + : m_uniformsCache(uniformSet) { + setFlag(QSGMaterial::Blending); +} + +Material::~Material() = default; diff --git a/src/rendergraph/scenegraph/materialshader.cpp b/src/rendergraph/scenegraph/materialshader.cpp new file mode 100644 index 00000000000..9bba8e37c82 --- /dev/null +++ b/src/rendergraph/scenegraph/materialshader.cpp @@ -0,0 +1,13 @@ +#include "rendergraph/materialshader.h" + +using namespace rendergraph; + +MaterialShader::MaterialShader(const char* vertexShaderFile, + const char* fragmentShaderFile, + const UniformSet& uniformSet, + const AttributeSet& attributeSet) { + (void)uniformSet; + (void)attributeSet; + setShaderFileName(VertexStage, resource(vertexShaderFile)); + setShaderFileName(FragmentStage, resource(fragmentShaderFile)); +} diff --git a/src/rendergraph/scenegraph/rendergraph/attributeset.cpp b/src/rendergraph/scenegraph/rendergraph/attributeset.cpp deleted file mode 100644 index 8938350eb8c..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/attributeset.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "rendergraph/attributeset.h" - -using namespace rendergraph; - -AttributeSetBase::AttributeSetBase(std::initializer_list list, - const std::vector& names) { - int i = 0; - for (auto item : list) { - add(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); - } -} - -void AttributeSetBase::add(const Attribute& attribute) { - m_attributes.push_back(attribute); - - const int count = static_cast(m_sgAttributes.size()); - const bool isPosition = count == 0; - m_sgAttributes.push_back(QSGGeometry::Attribute::create(count, - attribute.m_tupleSize, - toQSGGeometryType(attribute.m_primitiveType), - isPosition)); - m_stride += attribute.m_tupleSize * sizeOf(attribute.m_primitiveType); -} - -int AttributeSetBase::toQSGGeometryType(const rendergraph::PrimitiveType& t) { - switch (t) { - case rendergraph::PrimitiveType::Float: - return QSGGeometry::FloatType; - case rendergraph::PrimitiveType::UInt: - return QSGGeometry::UnsignedIntType; - } -} - -AttributeSet::AttributeSet(std::initializer_list list, - const std::vector& names) - : AttributeSetBase(list, names), - QSGGeometry::AttributeSet{static_cast(m_sgAttributes.size()), - m_stride, - m_sgAttributes.data()} { -} - -AttributeSet::~AttributeSet() = default; diff --git a/src/rendergraph/scenegraph/rendergraph/attributeset.h b/src/rendergraph/scenegraph/rendergraph/attributeset.h deleted file mode 100644 index 2101dd46085..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/attributeset.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "rendergraph/attribute.h" - -namespace rendergraph { -class AttributeSetBase; -class AttributeSet; -} - -class rendergraph::AttributeSetBase { - protected: - int m_stride{}; - - AttributeSetBase(std::initializer_list list, const std::vector& names); - - private: - void add(const Attribute& attribute); - static int toQSGGeometryType(const rendergraph::PrimitiveType& t); - - protected: - std::vector m_attributes; - QSGGeometry::AttributeSet m_sgAttributeSet{}; - std::vector m_sgAttributes; -}; - -class rendergraph::AttributeSet : private rendergraph::AttributeSetBase, - public QSGGeometry::AttributeSet { - public: - AttributeSet(std::initializer_list list, const std::vector& names); - ~AttributeSet(); - - const std::vector& attributes() const { - return m_attributes; - } - const QSGGeometry::AttributeSet& sgAttributeSet() const { - return *this; - } -}; - -namespace rendergraph { -template -AttributeSet makeAttributeSet(const std::vector& names) { - return AttributeSet({(Attribute::create())...}, names); -} -} // namespace rendergraph diff --git a/src/rendergraph/scenegraph/rendergraph/context.cpp b/src/rendergraph/scenegraph/rendergraph/context.cpp deleted file mode 100644 index 18ee9d28f3c..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/context.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "rendergraph/context.h" - -using namespace rendergraph; - -Context::Context() = default; - -Context::~Context() = default; - -void Context::setWindow(QQuickWindow* pWindow) { - m_pWindow = pWindow; -} - -QQuickWindow* Context::window() const { - return m_pWindow; -} diff --git a/src/rendergraph/scenegraph/rendergraph/context.h b/src/rendergraph/scenegraph/rendergraph/context.h index b13b3c5b34e..e26e6eb7859 100644 --- a/src/rendergraph/scenegraph/rendergraph/context.h +++ b/src/rendergraph/scenegraph/rendergraph/context.h @@ -1,6 +1,6 @@ #pragma once -class QQuickWindow; +#include namespace rendergraph { class Context; @@ -8,10 +8,7 @@ class Context; class rendergraph::Context { public: - Context(); - ~Context(); - - void setWindow(QQuickWindow* pWindow); + Context(QQuickWindow* pWindow); QQuickWindow* window() const; private: diff --git a/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp b/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp deleted file mode 100644 index 38b80500cb7..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/geometrynode.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "rendergraph/geometrynode.h" - -#include "rendergraph/material.h" - -using namespace rendergraph; - -GeometryNode::GeometryNode() - : Node(this) { -} - -GeometryNode::~GeometryNode() = default; - -void GeometryNode::setGeometry(std::unique_ptr geometry) { - m_geometry = std::move(geometry); - QSGGeometryNode::setGeometry(m_geometry.get()); -} - -void GeometryNode::setMaterial(std::unique_ptr material) { - m_material = std::move(material); - QSGGeometryNode::setMaterial(m_material.get()); -} - -Geometry& GeometryNode::geometry() const { - return *m_geometry; -} - -Material& GeometryNode::material() const { - return *m_material; -} diff --git a/src/rendergraph/scenegraph/rendergraph/geometrynode.h b/src/rendergraph/scenegraph/rendergraph/geometrynode.h deleted file mode 100644 index c098e69ce1d..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/geometrynode.h +++ /dev/null @@ -1,35 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/geometry.h" -#include "rendergraph/node.h" - -namespace rendergraph { -class GeometryNode; -class Geometry; -class Material; -} // namespace rendergraph - -class rendergraph::GeometryNode : public QSGGeometryNode, public rendergraph::Node { - public: - GeometryNode(); - ~GeometryNode(); - - template - void initForRectangles(int numRectangles) { - setGeometry(std::make_unique(T_Material::attributes(), numRectangles * 6)); - setMaterial(std::make_unique()); - geometry().setDrawingMode(Geometry::DrawingMode::Triangles); - } - - void setMaterial(std::unique_ptr material); - void setGeometry(std::unique_ptr geometry); - - Geometry& geometry() const; - Material& material() const; - - private: - std::unique_ptr m_material; - std::unique_ptr m_geometry; -}; diff --git a/src/rendergraph/scenegraph/rendergraph/material.cpp b/src/rendergraph/scenegraph/rendergraph/material.cpp deleted file mode 100644 index b66123e0b2f..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/material.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "rendergraph/material.h" - -#include "rendergraph/materialshader.h" - -using namespace rendergraph; - -Material::Material(const UniformSet& uniformSet) - : m_uniformsCache(uniformSet) { - setFlag(QSGMaterial::Blending); -} - -Material::~Material() = default; - -bool Material::updateUniformsByteArray(QByteArray* buf) { - if (clearUniformsCacheDirty()) { - memcpy(buf->data(), uniformsCache().data(), uniformsCache().size()); - return true; - } - return false; -} - -QSGMaterialShader* Material::createShader(QSGRendererInterface::RenderMode) const { - // This looks like a leak but it isn't: we pass ownership to Qt. Qt will - // cache and reuse the shader for all Material of the same type. - // TODO make sure that RenderMode is always the same. - auto pShader = createShader().release(); - return pShader; -} diff --git a/src/rendergraph/scenegraph/rendergraph/materialshader.cpp b/src/rendergraph/scenegraph/rendergraph/materialshader.cpp deleted file mode 100644 index 7bc69b85144..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/materialshader.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "rendergraph/materialshader.h" - -#include - -#include "rendergraph/material.h" - -using namespace rendergraph; - -MaterialShader::MaterialShader(const char* vertexShaderFile, - const char* fragmentShaderFile, - const UniformSet& uniformSet, - const AttributeSet& attributeSet) { - (void)uniformSet; - (void)attributeSet; - setShaderFileName(VertexStage, resource(vertexShaderFile)); - setShaderFileName(FragmentStage, resource(fragmentShaderFile)); -} - -MaterialShader::~MaterialShader() = default; - -bool rendergraph::MaterialShader::updateUniformData(RenderState& state, - QSGMaterial* newMaterial, - QSGMaterial* oldMaterial) { - return static_cast(newMaterial)->updateUniformsByteArray(state.uniformData()); -} - -void MaterialShader::updateSampledImage(RenderState& state, - int binding, - QSGTexture** texture, - QSGMaterial* newMaterial, - QSGMaterial* oldMaterial) { - *texture = static_cast(newMaterial)->texture(binding)->sgTexture(); - (*texture)->commitTextureOperations(state.rhi(), state.resourceUpdateBatch()); -} diff --git a/src/rendergraph/scenegraph/rendergraph/materialtype.cpp b/src/rendergraph/scenegraph/rendergraph/materialtype.cpp deleted file mode 100644 index 3839d6f5b8e..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/materialtype.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "rendergraph/materialtype.h" - -using namespace rendergraph; - -MaterialType::MaterialType() = default; -MaterialType::~MaterialType() = default; diff --git a/src/rendergraph/scenegraph/rendergraph/materialtype.h b/src/rendergraph/scenegraph/rendergraph/materialtype.h deleted file mode 100644 index 61a3d039c21..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/materialtype.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -namespace rendergraph { -class MaterialType; -} - -class rendergraph::MaterialType : public QSGMaterialType { - public: - MaterialType(); - ~MaterialType(); -}; diff --git a/src/rendergraph/scenegraph/rendergraph/node.cpp b/src/rendergraph/scenegraph/rendergraph/node.cpp deleted file mode 100644 index c5b852b5485..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/node.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "rendergraph/node.h" - -#include - -using namespace rendergraph; - -void Node::setUsePreprocess(bool value) { - sgNode()->setFlag(QSGNode::UsePreprocess, value); -} - -void Node::appendChildNode(std::unique_ptr&& pChild) { - sgNode()->appendChildNode(pChild->sgNode()); - - auto pChildRawPtr = pChild.get(); - if (m_pLastChild) { - pChild->m_pPreviousSibling = m_pLastChild; - m_pLastChild->m_pNextSibling = std::move(pChild); - } else { - m_pFirstChild = std::move(pChild); - } - m_pLastChild = pChildRawPtr; - m_pLastChild->m_pParent = this; -} - -std::unique_ptr Node::removeAllChildNodes() { - sgNode()->removeAllChildNodes(); - - m_pLastChild = nullptr; - Node* pChild = m_pFirstChild.get(); - while (pChild) { - pChild->m_pParent = nullptr; - pChild = pChild->m_pNextSibling.get(); - } - return std::move(m_pFirstChild); -} - -std::unique_ptr Node::removeChildNode(Node* pChild) { - sgNode()->removeChildNode(pChild->sgNode()); - - std::unique_ptr pRemoved; - if (pChild == m_pFirstChild.get()) { - pRemoved = std::move(m_pFirstChild); - m_pFirstChild = std::move(pChild->m_pNextSibling); - } else { - pRemoved = std::move(pChild->m_pPreviousSibling->m_pNextSibling); - pChild->m_pPreviousSibling->m_pNextSibling = std::move(pChild->m_pNextSibling); - pChild->m_pPreviousSibling = nullptr; - } - if (pChild == m_pLastChild) { - m_pLastChild = nullptr; - } - pChild->m_pParent = nullptr; - return pRemoved; -} diff --git a/src/rendergraph/scenegraph/rendergraph/node.h b/src/rendergraph/scenegraph/rendergraph/node.h deleted file mode 100644 index 97677ea46ab..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/node.h +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -#include -#include - -namespace rendergraph { -class Node; -} // namespace rendergraph - -class rendergraph::Node { - public: - // We can't derive from QSGNode, as we need to avoid ambiguous names and - // the diamond problem, so for the base class we use encapsulation. The - // derived classes (GeometryNode, OpacityNode) do arrive from Node and - // from their Qt scene graph counterpart and pass their pointer to the - // constructor. - Node() - : m_pSgNode(new QSGNode), - m_ownSgNode(true) { - } - Node(QSGNode* sgNode) - : m_pSgNode(sgNode), - m_ownSgNode(false) { - } - virtual ~Node() { - if (m_ownSgNode) { - delete m_pSgNode; - } - } - - void appendChildNode(std::unique_ptr&& pChild); - std::unique_ptr removeAllChildNodes(); - std::unique_ptr removeChildNode(Node* pChild); - - Node* parent() const { - return m_pParent; - } - Node* firstChild() const { - return m_pFirstChild.get(); - } - Node* lastChild() const { - return m_pLastChild; - } - Node* nextSibling() const { - return m_pNextSibling.get(); - } - Node* previousSibling() const { - return m_pPreviousSibling; - } - - void setUsePreprocess(bool value); - - QSGNode* sgNode() { - return m_pSgNode; - } - - private: - QSGNode* m_pSgNode; - bool m_ownSgNode; - Node* m_pParent{}; - std::unique_ptr m_pFirstChild; - Node* m_pLastChild{}; - std::unique_ptr m_pNextSibling; - Node* m_pPreviousSibling{}; -}; diff --git a/src/rendergraph/scenegraph/rendergraph/opacitynode.h b/src/rendergraph/scenegraph/rendergraph/opacitynode.h deleted file mode 100644 index a8b93dfabf6..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/opacitynode.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/node.h" - -namespace rendergraph { -class OpacityNode; -} // namespace rendergraph - -class rendergraph::OpacityNode : public QSGOpacityNode, public rendergraph::Node { - public: - OpacityNode(); - ~OpacityNode(); -}; diff --git a/src/rendergraph/scenegraph/rendergraph/scenegraph.cpp b/src/rendergraph/scenegraph/rendergraph/scenegraph.cpp deleted file mode 100644 index 314e086991d..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/scenegraph.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "scenegraph.h" - -#include "rendergraph/context.h" -#include "rendergraph/node.h" - -using namespace rendergraph; - -std::unique_ptr rendergraph::createSgContext(QQuickWindow* window) { - auto context = std::make_unique(); - context->setWindow(window); - return context; -} diff --git a/src/rendergraph/scenegraph/rendergraph/scenegraph.h b/src/rendergraph/scenegraph/rendergraph/scenegraph.h deleted file mode 100644 index e28c299d0b8..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/scenegraph.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include - -class QQuickWindow; - -namespace rendergraph { -class Context; - -std::unique_ptr createSgContext(QQuickWindow* window); -} // namespace rendergraph diff --git a/src/rendergraph/scenegraph/rendergraph/texture.h b/src/rendergraph/scenegraph/rendergraph/texture.h deleted file mode 100644 index f289056b789..00000000000 --- a/src/rendergraph/scenegraph/rendergraph/texture.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include - -class QSGTexture; -class QImage; - -namespace rendergraph { -class Context; -class Texture; -} // namespace rendergraph - -// We can't use inheritance because QSGTexture has pure virtuals that we can't -// implement, so we encapsulate instead. -class rendergraph::Texture { - public: - Texture(Context& context, const QImage& image); - ~Texture(); - - QSGTexture* sgTexture() const { - return m_pTexture.get(); - } - - private: - std::unique_ptr m_pTexture{}; -}; diff --git a/src/rendergraph/scenegraph/rendergraph/texture.cpp b/src/rendergraph/scenegraph/texture.cpp similarity index 75% rename from src/rendergraph/scenegraph/rendergraph/texture.cpp rename to src/rendergraph/scenegraph/texture.cpp index 1102aeb7d51..773f08d3f96 100644 --- a/src/rendergraph/scenegraph/rendergraph/texture.cpp +++ b/src/rendergraph/scenegraph/texture.cpp @@ -1,8 +1,4 @@ #include "rendergraph/texture.h" - -#include -#include - #include "rendergraph/context.h" using namespace rendergraph; @@ -10,5 +6,3 @@ using namespace rendergraph; Texture::Texture(Context& context, const QImage& image) : m_pTexture(context.window()->createTextureFromImage(image)) { } - -Texture::~Texture() = default; diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 66948148246..514b127ba72 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -84,10 +84,10 @@ class WaveformMarkNodeGraphics : public WaveformMark::Graphics { float textureHeight() const { return waveformMarkNode()->textureHeight(); } - void setNode(std::unique_ptr&& pNode) { + void setNode(std::unique_ptr&& pNode) { m_pNode = std::move(pNode); } - void moveNodeToChildrenOf(Node* pParent) { + void moveNodeToChildrenOf(BaseNode* pParent) { pParent->appendChildNode(std::move(m_pNode)); } @@ -96,7 +96,7 @@ class WaveformMarkNodeGraphics : public WaveformMark::Graphics { return static_cast(m_pNode.get()); } - std::unique_ptr m_pNode; + std::unique_ptr m_pNode; }; // Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive @@ -248,7 +248,7 @@ void allshader::WaveformRenderMark::update() { const double playPosition = m_waveformRenderer->getTruePosSample(positionType); double nextMarkPosition = std::numeric_limits::max(); - Node* pRangeChild = m_pRangeNodesParent->firstChild(); + BaseNode* pRangeChild = m_pRangeNodesParent->firstChild(); for (const auto& pMark : std::as_const(m_marks)) { if (!pMark->isValid()) { diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index 585c147be94..730df0c8e12 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -64,8 +64,8 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, bool m_isSlipRenderer; - rendergraph::Node* m_pRangeNodesParent{}; - rendergraph::Node* m_pMarkNodesParent{}; + rendergraph::BaseNode* m_pRangeNodesParent{}; + rendergraph::BaseNode* m_pMarkNodesParent{}; rendergraph::GeometryNode* m_pPlayPosNode; DigitsRenderNode* m_pDigitsRenderNode{}; diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index 6821658c024..105489b495f 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -42,7 +42,7 @@ void WaveformRenderMarkRange::draw(QPainter* painter, QPaintEvent* event) { void WaveformRenderMarkRange::update() { const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - Node* pChild = firstChild(); + BaseNode* pChild = firstChild(); for (const auto& markRange : m_markRanges) { // If the mark range is not active we should not draw it. diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index ef86bc981ac..11328189f1e 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -5,7 +5,6 @@ #include #include -#include "rendergraph/shadercache.h" #include "waveform/renderers/allshader/waveformrenderbackground.h" #include "waveform/renderers/allshader/waveformrenderbeat.h" #include "waveform/renderers/allshader/waveformrendererendoftrack.h" @@ -22,11 +21,12 @@ #include "waveform/widgets/allshader/moc_waveformwidget.cpp" namespace { -void appendChildTo(std::unique_ptr& pNode, rendergraph::Node* pChild) { - pNode->appendChildNode(std::unique_ptr(pChild)); +void appendChildTo(std::unique_ptr& pNode, rendergraph::BaseNode* pChild) { + pNode->appendChildNode(std::unique_ptr(pChild)); } -void appendChildTo(std::unique_ptr& pNode, rendergraph::Node* pChild) { - pNode->appendChildNode(std::unique_ptr(pChild)); +void appendChildTo(std::unique_ptr& pNode, + rendergraph::BaseNode* pChild) { + pNode->appendChildNode(std::unique_ptr(pChild)); } } // namespace @@ -90,14 +90,13 @@ WaveformWidget::WaveformWidget(QWidget* parent, m_pOpacityNode = pOpacityNode.get(); pTopNode->appendChildNode(std::move(pOpacityNode)); - m_pGraph = std::make_unique(std::move(pTopNode)); + m_pEngine = std::make_unique(std::move(pTopNode)); } WaveformWidget::~WaveformWidget() { makeCurrentIfNeeded(); m_rendererStack.clear(); - m_pGraph.reset(); - rendergraph::ShaderCache::purge(); + m_pEngine.reset(); doneCurrent(); } @@ -153,8 +152,8 @@ void WaveformWidget::paintGL() { m_pWaveformRenderMark->update(); m_pWaveformRenderMarkRange->update(); - m_pGraph->preprocess(); - m_pGraph->render(); + m_pEngine->preprocess(); + m_pEngine->render(); } void WaveformWidget::castToQWidget() { @@ -162,11 +161,11 @@ void WaveformWidget::castToQWidget() { } void WaveformWidget::initializeGL() { - m_pGraph->initialize(); + m_pEngine->initialize(); } void WaveformWidget::resizeGL(int w, int h) { - m_pGraph->resize(w, h); + m_pEngine->resize(w, h); } void WaveformWidget::paintEvent(QPaintEvent* event) { diff --git a/src/waveform/widgets/allshader/waveformwidget.h b/src/waveform/widgets/allshader/waveformwidget.h index 2ee2a6f1dae..9bd57c608c8 100644 --- a/src/waveform/widgets/allshader/waveformwidget.h +++ b/src/waveform/widgets/allshader/waveformwidget.h @@ -1,6 +1,6 @@ #pragma once -#include "rendergraph/graph.h" +#include "rendergraph/engine.h" #include "rendergraph/opacitynode.h" #include "waveform/renderers/allshader/waveformrenderersignalbase.h" #include "waveform/widgets/waveformwidgetabstract.h" @@ -52,7 +52,7 @@ class allshader::WaveformWidget final : public ::WGLWidget, ::WaveformRendererAbstract::PositionSource positionSource); WaveformWidgetType::Type m_type; - std::unique_ptr m_pGraph; + std::unique_ptr m_pEngine; rendergraph::OpacityNode* m_pOpacityNode; WaveformRenderMark* m_pWaveformRenderMark; WaveformRenderMarkRange* m_pWaveformRenderMarkRange; From 319ffb0a2d10d59b4a902c69af15031067cba463 Mon Sep 17 00:00:00 2001 From: m0dB <79429057+m0dB@users.noreply.github.com> Date: Sun, 22 Sep 2024 12:49:06 +0200 Subject: [PATCH 19/64] Update src/rendergraph/common/rendergraph/material/patternmaterial.h un-name unused argument Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> --- src/rendergraph/common/rendergraph/material/patternmaterial.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rendergraph/common/rendergraph/material/patternmaterial.h b/src/rendergraph/common/rendergraph/material/patternmaterial.h index 0df75c07371..77127a6965d 100644 --- a/src/rendergraph/common/rendergraph/material/patternmaterial.h +++ b/src/rendergraph/common/rendergraph/material/patternmaterial.h @@ -21,7 +21,7 @@ class rendergraph::PatternMaterial : public rendergraph::Material { std::unique_ptr createShader() const override; - Texture* texture(int /*binding*/) const override { + Texture* texture(int) const override { return m_pTexture.get(); } From 390dd0e5988f7dd08abf742bc11a57898f1f20ec Mon Sep 17 00:00:00 2001 From: m0dB <79429057+m0dB@users.noreply.github.com> Date: Sun, 22 Sep 2024 12:49:28 +0200 Subject: [PATCH 20/64] Update src/rendergraph/common/rendergraph/material/rgbamaterial.cpp MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Schürmann --- src/rendergraph/common/rendergraph/material/rgbamaterial.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rendergraph/common/rendergraph/material/rgbamaterial.cpp b/src/rendergraph/common/rendergraph/material/rgbamaterial.cpp index c1d53d3f8bc..3179549381c 100644 --- a/src/rendergraph/common/rendergraph/material/rgbamaterial.cpp +++ b/src/rendergraph/common/rendergraph/material/rgbamaterial.cpp @@ -12,7 +12,8 @@ RGBAMaterial::RGBAMaterial() : Material(uniforms()) { } -/* static */ const AttributeSet& RGBAMaterial::attributes() { +// static +const AttributeSet& RGBAMaterial::attributes() { static AttributeSet set = makeAttributeSet({"position", "color"}); return set; } From afdc0eda6c4a3d03fb0f718fea81d594140cfe49 Mon Sep 17 00:00:00 2001 From: m0dB <79429057+m0dB@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:15:42 +0200 Subject: [PATCH 21/64] Update res/shaders/rendergraph/unicolor.frag Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> --- res/shaders/rendergraph/unicolor.frag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/shaders/rendergraph/unicolor.frag b/res/shaders/rendergraph/unicolor.frag index e4a8535e349..7099bb8f3dd 100644 --- a/res/shaders/rendergraph/unicolor.frag +++ b/res/shaders/rendergraph/unicolor.frag @@ -9,5 +9,5 @@ ubuf; layout(location = 0) out vec4 fragColor; void main() { - fragColor = vec4(ubuf.color.xyz * ubuf.color.w, ubuf.color.w); // premultiple alpha + fragColor = vec4(ubuf.color.xyz * ubuf.color.w, ubuf.color.w); // premultiply alpha } From dff3a31555f5fd91f211af7646e1003e45fabd52 Mon Sep 17 00:00:00 2001 From: m0dB <79429057+m0dB@users.noreply.github.com> Date: Sun, 22 Sep 2024 13:20:07 +0200 Subject: [PATCH 22/64] Update src/rendergraph/opengl/backend/shadercache.h direct conversion from unique_ptr to shader_ptr Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> --- src/rendergraph/opengl/backend/shadercache.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rendergraph/opengl/backend/shadercache.h b/src/rendergraph/opengl/backend/shadercache.h index 4f7eba2879d..850d039c826 100644 --- a/src/rendergraph/opengl/backend/shadercache.h +++ b/src/rendergraph/opengl/backend/shadercache.h @@ -29,7 +29,7 @@ class rendergraph::backend::ShaderCache { return iter->second; } auto pResult = std::shared_ptr( - pMaterial->createShader().release()); + pMaterial->createShader()); map().insert(std::pair>{ pMaterial->type(), pResult}); From c713d6a4f889f9505041a5de232bf2f95aae0e66 Mon Sep 17 00:00:00 2001 From: m0dB <79429057+m0dB@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:30:12 +0200 Subject: [PATCH 23/64] Update src/rendergraph/common/rendergraph/attribute.h simplify attribute constructor. Co-authored-by: Swiftb0y <12380386+Swiftb0y@users.noreply.github.com> --- src/rendergraph/common/rendergraph/attribute.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/rendergraph/common/rendergraph/attribute.h b/src/rendergraph/common/rendergraph/attribute.h index 5fae9e3df54..150ad00c3aa 100644 --- a/src/rendergraph/common/rendergraph/attribute.h +++ b/src/rendergraph/common/rendergraph/attribute.h @@ -13,12 +13,7 @@ struct rendergraph::Attribute { const PrimitiveType m_primitiveType; const QString m_name; - Attribute(int tupleSize, PrimitiveType primitiveType) - : m_tupleSize{tupleSize}, - m_primitiveType{primitiveType} { - } - - Attribute(int tupleSize, PrimitiveType primitiveType, QString name) + Attribute(int tupleSize, PrimitiveType primitiveType, QString name = {}) : m_tupleSize{tupleSize}, m_primitiveType{primitiveType}, m_name{std::move(name)} { From 6ebc9d5a022b5d6f776d2891788debf657edcc00 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 22 Sep 2024 13:18:47 +0200 Subject: [PATCH 24/64] removed accidental commit --- src/rendergraph/trash | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 src/rendergraph/trash diff --git a/src/rendergraph/trash b/src/rendergraph/trash deleted file mode 100644 index 55a577b26d0..00000000000 --- a/src/rendergraph/trash +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#pragma once - -#include -#include -#include -#include - -namespace rendergraph { -struct Attribute; -class AttributeSet; -struct Uniform; -class UniformSet; -class UniformsCache; -class MaterialType; -class MaterialShader; -class Texture; -class Material; -class Geometry; -class Node; -class GeometryNode; -class RenderGraph; -class Context; -} From 2a4a7d18fe04a45e56bb78bb3f0cd78f6157a01c Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 22 Sep 2024 18:57:19 +0200 Subject: [PATCH 25/64] removed backend:: namespace, minor changes based on reviews --- src/rendergraph/README | 1 + src/rendergraph/common/attributeset.cpp | 2 +- src/rendergraph/common/node.cpp | 2 +- src/rendergraph/common/opacitynode.cpp | 2 +- .../common/rendergraph/attributeset.h | 4 +- src/rendergraph/common/rendergraph/basenode.h | 60 ------------------- src/rendergraph/common/rendergraph/geometry.h | 4 +- .../common/rendergraph/geometrynode.h | 8 +-- src/rendergraph/common/rendergraph/material.h | 4 +- .../common/rendergraph/materialshader.h | 4 +- .../common/rendergraph/materialtype.h | 4 +- src/rendergraph/common/rendergraph/node.h | 6 +- .../common/rendergraph/opacitynode.h | 8 +-- src/rendergraph/common/rendergraph/texture.h | 6 +- src/rendergraph/common/rendergraph/treenode.h | 60 +++++++++++++++++++ .../common/{basenode.cpp => treenode.cpp} | 14 ++--- .../examples/common/examplenodes.cpp | 8 +-- src/rendergraph/opengl/CMakeLists.txt | 36 +++++------ src/rendergraph/opengl/backend/attributeset.h | 16 ----- ...{attributeset.cpp => baseattributeset.cpp} | 4 +- .../opengl/backend/baseattributeset.h | 16 +++++ .../{geometry.cpp => basegeometry.cpp} | 20 +++---- .../backend/{geometry.h => basegeometry.h} | 8 +-- ...{geometrynode.cpp => basegeometrynode.cpp} | 22 +++---- .../opengl/backend/basegeometrynode.h | 19 ++++++ .../opengl/backend/basematerial.cpp | 27 +++++++++ src/rendergraph/opengl/backend/basematerial.h | 27 +++++++++ .../opengl/backend/basematerialshader.cpp | 18 ++++++ .../opengl/backend/basematerialshader.h | 28 +++++++++ .../opengl/backend/basematerialtype.h | 6 ++ .../opengl/backend/{node.h => basenode.h} | 10 ++-- .../{opacitynode.h => baseopacitynode.h} | 10 ++-- .../opengl/backend/baseopenglnode.cpp | 21 +++++++ .../opengl/backend/baseopenglnode.h | 20 +++++++ src/rendergraph/opengl/backend/basetexture.h | 7 +++ src/rendergraph/opengl/backend/geometrynode.h | 19 ------ src/rendergraph/opengl/backend/material.cpp | 27 --------- src/rendergraph/opengl/backend/material.h | 27 --------- .../opengl/backend/materialshader.cpp | 18 ------ .../opengl/backend/materialshader.h | 28 --------- src/rendergraph/opengl/backend/materialtype.h | 8 --- src/rendergraph/opengl/backend/openglnode.cpp | 21 ------- src/rendergraph/opengl/backend/openglnode.h | 20 ------- src/rendergraph/opengl/backend/shadercache.h | 22 +++---- src/rendergraph/opengl/backend/texture.h | 7 --- src/rendergraph/opengl/engine.cpp | 12 ++-- src/rendergraph/opengl/geometry.cpp | 2 +- src/rendergraph/opengl/geometrynode.cpp | 2 +- src/rendergraph/opengl/openglnode.cpp | 2 +- src/rendergraph/opengl/rendergraph/engine.h | 16 ++--- .../opengl/rendergraph/openglnode.h | 8 +-- .../opengl/{basenode.cpp => treenode.cpp} | 11 ++-- src/rendergraph/scenegraph/CMakeLists.txt | 28 ++++----- .../scenegraph/backend/attributeset.h | 40 ------------- ...{attributeset.cpp => baseattributeset.cpp} | 12 ++-- .../scenegraph/backend/baseattributeset.h | 42 +++++++++++++ .../backend/{geometry.h => basegeometry.h} | 8 +-- .../scenegraph/backend/basegeometrynode.h | 7 +++ .../{material.cpp => basematerial.cpp} | 16 ++--- .../backend/{material.h => basematerial.h} | 8 +-- .../scenegraph/backend/basematerialshader.cpp | 24 ++++++++ ...{materialshader.h => basematerialshader.h} | 12 ++-- .../scenegraph/backend/basematerialtype.h | 7 +++ src/rendergraph/scenegraph/backend/basenode.h | 7 +++ .../scenegraph/backend/baseopacitynode.h | 7 +++ .../scenegraph/backend/basetexture.h | 7 +++ .../scenegraph/backend/geometrynode.h | 7 --- .../scenegraph/backend/materialshader.cpp | 22 ------- .../scenegraph/backend/materialtype.h | 10 ---- src/rendergraph/scenegraph/backend/node.h | 7 --- .../scenegraph/backend/opacitynode.h | 7 --- src/rendergraph/scenegraph/backend/texture.h | 7 --- src/rendergraph/scenegraph/geometry.cpp | 2 +- src/rendergraph/scenegraph/geometrynode.cpp | 2 +- .../scenegraph/{basenode.cpp => treenode.cpp} | 10 ++-- .../allshader/waveformrendermark.cpp | 8 +-- .../renderers/allshader/waveformrendermark.h | 4 +- .../allshader/waveformrendermarkrange.cpp | 2 +- .../widgets/allshader/waveformwidget.cpp | 8 +-- 79 files changed, 542 insertions(+), 541 deletions(-) delete mode 100644 src/rendergraph/common/rendergraph/basenode.h create mode 100644 src/rendergraph/common/rendergraph/treenode.h rename src/rendergraph/common/{basenode.cpp => treenode.cpp} (77%) delete mode 100644 src/rendergraph/opengl/backend/attributeset.h rename src/rendergraph/opengl/backend/{attributeset.cpp => baseattributeset.cpp} (69%) create mode 100644 src/rendergraph/opengl/backend/baseattributeset.h rename src/rendergraph/opengl/backend/{geometry.cpp => basegeometry.cpp} (58%) rename src/rendergraph/opengl/backend/{geometry.h => basegeometry.h} (73%) rename src/rendergraph/opengl/backend/{geometrynode.cpp => basegeometrynode.cpp} (81%) create mode 100644 src/rendergraph/opengl/backend/basegeometrynode.h create mode 100644 src/rendergraph/opengl/backend/basematerial.cpp create mode 100644 src/rendergraph/opengl/backend/basematerial.h create mode 100644 src/rendergraph/opengl/backend/basematerialshader.cpp create mode 100644 src/rendergraph/opengl/backend/basematerialshader.h create mode 100644 src/rendergraph/opengl/backend/basematerialtype.h rename src/rendergraph/opengl/backend/{node.h => basenode.h} (81%) rename src/rendergraph/opengl/backend/{opacitynode.h => baseopacitynode.h} (56%) create mode 100644 src/rendergraph/opengl/backend/baseopenglnode.cpp create mode 100644 src/rendergraph/opengl/backend/baseopenglnode.h create mode 100644 src/rendergraph/opengl/backend/basetexture.h delete mode 100644 src/rendergraph/opengl/backend/geometrynode.h delete mode 100644 src/rendergraph/opengl/backend/material.cpp delete mode 100644 src/rendergraph/opengl/backend/material.h delete mode 100644 src/rendergraph/opengl/backend/materialshader.cpp delete mode 100644 src/rendergraph/opengl/backend/materialshader.h delete mode 100644 src/rendergraph/opengl/backend/materialtype.h delete mode 100644 src/rendergraph/opengl/backend/openglnode.cpp delete mode 100644 src/rendergraph/opengl/backend/openglnode.h delete mode 100644 src/rendergraph/opengl/backend/texture.h rename src/rendergraph/opengl/{basenode.cpp => treenode.cpp} (57%) delete mode 100644 src/rendergraph/scenegraph/backend/attributeset.h rename src/rendergraph/scenegraph/backend/{attributeset.cpp => baseattributeset.cpp} (72%) create mode 100644 src/rendergraph/scenegraph/backend/baseattributeset.h rename src/rendergraph/scenegraph/backend/{geometry.h => basegeometry.h} (61%) create mode 100644 src/rendergraph/scenegraph/backend/basegeometrynode.h rename src/rendergraph/scenegraph/backend/{material.cpp => basematerial.cpp} (51%) rename src/rendergraph/scenegraph/backend/{material.h => basematerial.h} (66%) create mode 100644 src/rendergraph/scenegraph/backend/basematerialshader.cpp rename src/rendergraph/scenegraph/backend/{materialshader.h => basematerialshader.h} (58%) create mode 100644 src/rendergraph/scenegraph/backend/basematerialtype.h create mode 100644 src/rendergraph/scenegraph/backend/basenode.h create mode 100644 src/rendergraph/scenegraph/backend/baseopacitynode.h create mode 100644 src/rendergraph/scenegraph/backend/basetexture.h delete mode 100644 src/rendergraph/scenegraph/backend/geometrynode.h delete mode 100644 src/rendergraph/scenegraph/backend/materialshader.cpp delete mode 100644 src/rendergraph/scenegraph/backend/materialtype.h delete mode 100644 src/rendergraph/scenegraph/backend/node.h delete mode 100644 src/rendergraph/scenegraph/backend/opacitynode.h delete mode 100644 src/rendergraph/scenegraph/backend/texture.h rename src/rendergraph/scenegraph/{basenode.cpp => treenode.cpp} (53%) diff --git a/src/rendergraph/README b/src/rendergraph/README index ccc4db3fbb8..88066b195dd 100644 --- a/src/rendergraph/README +++ b/src/rendergraph/README @@ -19,6 +19,7 @@ common/rendergraph common Implementation of the functionality declared in the common/rendergraph headers that is identical for both backends. + The general guideline is "code duplicated between the backends should be in the common layer". common/rendergraph/material Several basic 'materials' for common rendering operations (e.g. uniform or variying color, texture) diff --git a/src/rendergraph/common/attributeset.cpp b/src/rendergraph/common/attributeset.cpp index c72df9ef21f..a2fef348d9c 100644 --- a/src/rendergraph/common/attributeset.cpp +++ b/src/rendergraph/common/attributeset.cpp @@ -4,7 +4,7 @@ using namespace rendergraph; AttributeSet::AttributeSet(std::initializer_list list, const std::vector& names) - : backend::AttributeSet(list, names) { + : BaseAttributeSet(list, names) { } const std::vector& AttributeSet::attributes() const { diff --git a/src/rendergraph/common/node.cpp b/src/rendergraph/common/node.cpp index 61bb0406e3a..24f5d29d3ee 100644 --- a/src/rendergraph/common/node.cpp +++ b/src/rendergraph/common/node.cpp @@ -3,5 +3,5 @@ using namespace rendergraph; Node::Node() - : BaseNode(this) { + : TreeNode(this) { } diff --git a/src/rendergraph/common/opacitynode.cpp b/src/rendergraph/common/opacitynode.cpp index dfe705c5389..caa6526626f 100644 --- a/src/rendergraph/common/opacitynode.cpp +++ b/src/rendergraph/common/opacitynode.cpp @@ -3,5 +3,5 @@ using namespace rendergraph; OpacityNode::OpacityNode() - : BaseNode(this) { + : TreeNode(this) { } diff --git a/src/rendergraph/common/rendergraph/attributeset.h b/src/rendergraph/common/rendergraph/attributeset.h index 6b970b9e1fd..589a6e51bfc 100644 --- a/src/rendergraph/common/rendergraph/attributeset.h +++ b/src/rendergraph/common/rendergraph/attributeset.h @@ -1,12 +1,12 @@ #pragma once -#include "backend/attributeset.h" +#include "backend/baseattributeset.h" namespace rendergraph { class AttributeSet; } -class rendergraph::AttributeSet : public rendergraph::backend::AttributeSet { +class rendergraph::AttributeSet : public rendergraph::BaseAttributeSet { public: AttributeSet(std::initializer_list list, const std::vector& names); const std::vector& attributes() const; diff --git a/src/rendergraph/common/rendergraph/basenode.h b/src/rendergraph/common/rendergraph/basenode.h deleted file mode 100644 index 5a74d699884..00000000000 --- a/src/rendergraph/common/rendergraph/basenode.h +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -#include - -#include "backend/node.h" - -namespace rendergraph { -class BaseNode; -} // namespace rendergraph - -class rendergraph::BaseNode { - public: - BaseNode(rendergraph::backend::Node* pBackendNode) - : m_pBackendNode(pBackendNode) { - } - virtual ~BaseNode() = default; - - void appendChildNode(std::unique_ptr&& pChild); - std::unique_ptr removeAllChildNodes(); - std::unique_ptr removeChildNode(BaseNode* pChild); - - BaseNode* parent() const { - return m_pParent; - } - BaseNode* firstChild() const { - return m_pFirstChild.get(); - } - BaseNode* lastChild() const { - return m_pLastChild; - } - BaseNode* nextSibling() const { - return m_pNextSibling.get(); - } - BaseNode* previousSibling() const { - return m_pPreviousSibling; - } - - void setUsePreprocess(bool value); - - rendergraph::backend::Node* backendNode() { - return m_pBackendNode; - } - - virtual void initialize() { - } - virtual void resize(int, int) { - } - - private: - void onAppendChildNode(BaseNode* pChild); - void onRemoveAllChildNodes(); - void onRemoveChildNode(BaseNode* pChild); - - rendergraph::backend::Node* m_pBackendNode; - BaseNode* m_pParent{}; - std::unique_ptr m_pFirstChild; - BaseNode* m_pLastChild{}; - std::unique_ptr m_pNextSibling; - BaseNode* m_pPreviousSibling{}; -}; diff --git a/src/rendergraph/common/rendergraph/geometry.h b/src/rendergraph/common/rendergraph/geometry.h index d5bbd01cebd..c44572c3b9a 100644 --- a/src/rendergraph/common/rendergraph/geometry.h +++ b/src/rendergraph/common/rendergraph/geometry.h @@ -3,14 +3,14 @@ #include #include -#include "backend/geometry.h" +#include "backend/basegeometry.h" #include "rendergraph/attributeset.h" namespace rendergraph { class Geometry; } // namespace rendergraph -class rendergraph::Geometry : public rendergraph::backend::Geometry { +class rendergraph::Geometry : public rendergraph::BaseGeometry { public: struct Point2D { QVector2D position2D; diff --git a/src/rendergraph/common/rendergraph/geometrynode.h b/src/rendergraph/common/rendergraph/geometrynode.h index d2096b2450f..44384b370bf 100644 --- a/src/rendergraph/common/rendergraph/geometrynode.h +++ b/src/rendergraph/common/rendergraph/geometrynode.h @@ -1,16 +1,16 @@ #pragma once -#include "backend/geometrynode.h" -#include "rendergraph/basenode.h" +#include "backend/basegeometrynode.h" #include "rendergraph/geometry.h" #include "rendergraph/material.h" +#include "rendergraph/treenode.h" namespace rendergraph { class GeometryNode; } // namespace rendergraph -class rendergraph::GeometryNode : public rendergraph::backend::GeometryNode, - public rendergraph::BaseNode { +class rendergraph::GeometryNode : public rendergraph::BaseGeometryNode, + public rendergraph::TreeNode { public: GeometryNode(); diff --git a/src/rendergraph/common/rendergraph/material.h b/src/rendergraph/common/rendergraph/material.h index e3cb05b93cc..910fa442862 100644 --- a/src/rendergraph/common/rendergraph/material.h +++ b/src/rendergraph/common/rendergraph/material.h @@ -2,7 +2,7 @@ #include -#include "backend/material.h" +#include "backend/basematerial.h" #include "rendergraph/materialshader.h" #include "rendergraph/materialtype.h" #include "rendergraph/texture.h" @@ -13,7 +13,7 @@ namespace rendergraph { class Material; } // namespace rendergraph -class rendergraph::Material : public rendergraph::backend::Material { +class rendergraph::Material : public rendergraph::BaseMaterial { public: Material(const UniformSet& uniformSet); virtual ~Material(); diff --git a/src/rendergraph/common/rendergraph/materialshader.h b/src/rendergraph/common/rendergraph/materialshader.h index a1e2411256a..43c811ebebd 100644 --- a/src/rendergraph/common/rendergraph/materialshader.h +++ b/src/rendergraph/common/rendergraph/materialshader.h @@ -1,6 +1,6 @@ #pragma once -#include "backend/materialshader.h" +#include "backend/basematerialshader.h" #include "rendergraph/attributeset.h" #include "rendergraph/uniformset.h" @@ -8,7 +8,7 @@ namespace rendergraph { class MaterialShader; } // namespace rendergraph -class rendergraph::MaterialShader : public rendergraph::backend::MaterialShader { +class rendergraph::MaterialShader : public rendergraph::BaseMaterialShader { public: MaterialShader(const char* vertexShaderFile, const char* fragmentShaderFile, diff --git a/src/rendergraph/common/rendergraph/materialtype.h b/src/rendergraph/common/rendergraph/materialtype.h index e2c85391049..67da71e91f3 100644 --- a/src/rendergraph/common/rendergraph/materialtype.h +++ b/src/rendergraph/common/rendergraph/materialtype.h @@ -1,10 +1,10 @@ #pragma once -#include "backend/materialtype.h" +#include "backend/basematerialtype.h" namespace rendergraph { class MaterialType; } -class rendergraph::MaterialType : public rendergraph::backend::MaterialType { +class rendergraph::MaterialType : public rendergraph::BaseMaterialType { }; diff --git a/src/rendergraph/common/rendergraph/node.h b/src/rendergraph/common/rendergraph/node.h index 6eb1c8c737d..7ce62dd08cc 100644 --- a/src/rendergraph/common/rendergraph/node.h +++ b/src/rendergraph/common/rendergraph/node.h @@ -1,13 +1,13 @@ #pragma once -#include "backend/node.h" -#include "rendergraph/basenode.h" +#include "backend/basenode.h" +#include "rendergraph/treenode.h" namespace rendergraph { class Node; } // namespace rendergraph -class rendergraph::Node : public rendergraph::backend::Node, public rendergraph::BaseNode { +class rendergraph::Node : public rendergraph::BaseNode, public rendergraph::TreeNode { public: Node(); }; diff --git a/src/rendergraph/common/rendergraph/opacitynode.h b/src/rendergraph/common/rendergraph/opacitynode.h index 2bd868daa12..ac64340520a 100644 --- a/src/rendergraph/common/rendergraph/opacitynode.h +++ b/src/rendergraph/common/rendergraph/opacitynode.h @@ -1,14 +1,14 @@ #pragma once -#include "backend/opacitynode.h" -#include "rendergraph/basenode.h" +#include "backend/baseopacitynode.h" +#include "rendergraph/treenode.h" namespace rendergraph { class OpacityNode; } // namespace rendergraph -class rendergraph::OpacityNode : public rendergraph::backend::OpacityNode, - public rendergraph::BaseNode { +class rendergraph::OpacityNode : public rendergraph::BaseOpacityNode, + public rendergraph::TreeNode { public: OpacityNode(); }; diff --git a/src/rendergraph/common/rendergraph/texture.h b/src/rendergraph/common/rendergraph/texture.h index a9dac6d790e..ec6d65b37a9 100644 --- a/src/rendergraph/common/rendergraph/texture.h +++ b/src/rendergraph/common/rendergraph/texture.h @@ -3,7 +3,7 @@ #include #include -#include "backend/texture.h" +#include "backend/basetexture.h" namespace rendergraph { class Context; @@ -14,10 +14,10 @@ class rendergraph::Texture { public: Texture(Context& context, const QImage& image); - backend::Texture* backendTexture() const { + BaseTexture* backendTexture() const { return m_pTexture.get(); } private: - const std::unique_ptr m_pTexture{}; + const std::unique_ptr m_pTexture{}; }; diff --git a/src/rendergraph/common/rendergraph/treenode.h b/src/rendergraph/common/rendergraph/treenode.h new file mode 100644 index 00000000000..a4850f17c9c --- /dev/null +++ b/src/rendergraph/common/rendergraph/treenode.h @@ -0,0 +1,60 @@ +#pragma once + +#include + +#include "backend/basenode.h" + +namespace rendergraph { +class TreeNode; +} // namespace rendergraph + +class rendergraph::TreeNode { + public: + TreeNode(rendergraph::BaseNode* pBackendNode) + : m_pBackendNode(pBackendNode) { + } + virtual ~TreeNode() = default; + + void appendChildNode(std::unique_ptr&& pChild); + std::unique_ptr removeAllChildNodes(); + std::unique_ptr removeChildNode(TreeNode* pChild); + + TreeNode* parent() const { + return m_pParent; + } + TreeNode* firstChild() const { + return m_pFirstChild.get(); + } + TreeNode* lastChild() const { + return m_pLastChild; + } + TreeNode* nextSibling() const { + return m_pNextSibling.get(); + } + TreeNode* previousSibling() const { + return m_pPreviousSibling; + } + + void setUsePreprocess(bool value); + + rendergraph::BaseNode* backendNode() { + return m_pBackendNode; + } + + virtual void initialize() { + } + virtual void resize(int, int) { + } + + private: + void onAppendChildNode(TreeNode* pChild); + void onRemoveAllChildNodes(); + void onRemoveChildNode(TreeNode* pChild); + + rendergraph::BaseNode* m_pBackendNode; + TreeNode* m_pParent{}; + std::unique_ptr m_pFirstChild; + TreeNode* m_pLastChild{}; + std::unique_ptr m_pNextSibling; + TreeNode* m_pPreviousSibling{}; +}; diff --git a/src/rendergraph/common/basenode.cpp b/src/rendergraph/common/treenode.cpp similarity index 77% rename from src/rendergraph/common/basenode.cpp rename to src/rendergraph/common/treenode.cpp index fc97bf65a7d..63fe5667ffc 100644 --- a/src/rendergraph/common/basenode.cpp +++ b/src/rendergraph/common/treenode.cpp @@ -1,10 +1,10 @@ -#include "rendergraph/basenode.h" +#include "rendergraph/treenode.h" -#include "backend/node.h" +#include "backend/basenode.h" using namespace rendergraph; -void BaseNode::appendChildNode(std::unique_ptr&& pChild) { +void TreeNode::appendChildNode(std::unique_ptr&& pChild) { auto pChildRawPtr = pChild.get(); if (m_pLastChild) { pChild->m_pPreviousSibling = m_pLastChild; @@ -18,11 +18,11 @@ void BaseNode::appendChildNode(std::unique_ptr&& pChild) { onAppendChildNode(pChildRawPtr); } -std::unique_ptr BaseNode::removeAllChildNodes() { +std::unique_ptr TreeNode::removeAllChildNodes() { onRemoveAllChildNodes(); m_pLastChild = nullptr; - BaseNode* pChild = m_pFirstChild.get(); + TreeNode* pChild = m_pFirstChild.get(); while (pChild) { pChild->m_pParent = nullptr; pChild = pChild->m_pNextSibling.get(); @@ -30,10 +30,10 @@ std::unique_ptr BaseNode::removeAllChildNodes() { return std::move(m_pFirstChild); } -std::unique_ptr BaseNode::removeChildNode(BaseNode* pChild) { +std::unique_ptr TreeNode::removeChildNode(TreeNode* pChild) { onRemoveChildNode(pChild); - std::unique_ptr pRemoved; + std::unique_ptr pRemoved; if (pChild == m_pFirstChild.get()) { pRemoved = std::move(m_pFirstChild); m_pFirstChild = std::move(pChild->m_pNextSibling); diff --git a/src/rendergraph/examples/common/examplenodes.cpp b/src/rendergraph/examples/common/examplenodes.cpp index ba2fd569b6c..588b5a43ef4 100644 --- a/src/rendergraph/examples/common/examplenodes.cpp +++ b/src/rendergraph/examples/common/examplenodes.cpp @@ -60,13 +60,13 @@ void ExampleNode3::setTexture(std::unique_ptr texture) { } ExampleTopNode::ExampleTopNode(rendergraph::Context& context) { - BaseNode::appendChildNode(std::make_unique()); - BaseNode::appendChildNode(std::make_unique()); - BaseNode::appendChildNode(std::make_unique()); + TreeNode::appendChildNode(std::make_unique()); + TreeNode::appendChildNode(std::make_unique()); + TreeNode::appendChildNode(std::make_unique()); { QImage img(":/example/images/test.png"); - static_cast(BaseNode::lastChild()) + static_cast(TreeNode::lastChild()) ->setTexture( std::make_unique(context, img)); } diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 66e2fb34c0d..0f8ebd06a15 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -1,11 +1,11 @@ add_library(rendergraph_gl ../common/attributeset.cpp -../common/basenode.cpp +../common/treenode.cpp ../common/node.cpp ../common/opacitynode.cpp ../common/rendergraph/attribute.h ../common/rendergraph/attributeset.h -../common/rendergraph/basenode.h +../common/rendergraph/treenode.h ../common/rendergraph/geometry.h ../common/rendergraph/geometrynode.h ../common/rendergraph/material.h @@ -33,23 +33,23 @@ add_library(rendergraph_gl ../common/rendergraph/uniformset.cpp ../common/rendergraph/uniformset.h ../common/types.cpp -backend/attributeset.cpp -backend/attributeset.h -backend/geometry.cpp -backend/geometry.h -backend/geometrynode.cpp -backend/geometrynode.h -backend/material.cpp -backend/material.h -backend/materialshader.cpp -backend/materialtype.h -backend/node.h -backend/opacitynode.h -backend/openglnode.cpp -backend/openglnode.h +backend/baseattributeset.cpp +backend/baseattributeset.h +backend/basegeometry.cpp +backend/basegeometry.h +backend/basegeometrynode.cpp +backend/basegeometrynode.h +backend/basematerial.cpp +backend/basematerial.h +backend/basematerialshader.cpp +backend/basematerialtype.h +backend/basenode.h +backend/baseopacitynode.h +backend/baseopenglnode.cpp +backend/baseopenglnode.h backend/shadercache.h -backend/texture.h -basenode.cpp +backend/basetexture.h +treenode.cpp engine.cpp geometry.cpp geometrynode.cpp diff --git a/src/rendergraph/opengl/backend/attributeset.h b/src/rendergraph/opengl/backend/attributeset.h deleted file mode 100644 index 5db82d58066..00000000000 --- a/src/rendergraph/opengl/backend/attributeset.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include -#include - -#include "rendergraph/attribute.h" - -namespace rendergraph::backend { -class AttributeSet; -} - -class rendergraph::backend::AttributeSet { - protected: - AttributeSet(std::initializer_list list, const std::vector& names); - std::vector m_attributes; -}; diff --git a/src/rendergraph/opengl/backend/attributeset.cpp b/src/rendergraph/opengl/backend/baseattributeset.cpp similarity index 69% rename from src/rendergraph/opengl/backend/attributeset.cpp rename to src/rendergraph/opengl/backend/baseattributeset.cpp index c70790b44c8..ce499f02774 100644 --- a/src/rendergraph/opengl/backend/attributeset.cpp +++ b/src/rendergraph/opengl/backend/baseattributeset.cpp @@ -1,8 +1,8 @@ #include "rendergraph/attributeset.h" -using namespace rendergraph::backend; +using namespace rendergraph; -AttributeSet::AttributeSet(std::initializer_list list, +BaseAttributeSet::BaseAttributeSet(std::initializer_list list, const std::vector& names) { int i = 0; for (auto item : list) { diff --git a/src/rendergraph/opengl/backend/baseattributeset.h b/src/rendergraph/opengl/backend/baseattributeset.h new file mode 100644 index 00000000000..57b7fcf76ec --- /dev/null +++ b/src/rendergraph/opengl/backend/baseattributeset.h @@ -0,0 +1,16 @@ +#pragma once + +#include +#include + +#include "rendergraph/attribute.h" + +namespace rendergraph { +class BaseAttributeSet; +} + +class rendergraph::BaseAttributeSet { + protected: + BaseAttributeSet(std::initializer_list list, const std::vector& names); + std::vector m_attributes; +}; diff --git a/src/rendergraph/opengl/backend/geometry.cpp b/src/rendergraph/opengl/backend/basegeometry.cpp similarity index 58% rename from src/rendergraph/opengl/backend/geometry.cpp rename to src/rendergraph/opengl/backend/basegeometry.cpp index d9fc828ef55..03ffd7ac988 100644 --- a/src/rendergraph/opengl/backend/geometry.cpp +++ b/src/rendergraph/opengl/backend/basegeometry.cpp @@ -1,12 +1,12 @@ -#include "backend/geometry.h" +#include "backend/basegeometry.h" #include "rendergraph/geometry.h" -using namespace rendergraph::backend; +using namespace rendergraph; -Geometry::Geometry( - const rendergraph::AttributeSet& attributeSet, int vertexCount) - : m_drawingMode(static_cast(rendergraph::Geometry::DrawingMode:: +BaseGeometry::BaseGeometry( + const AttributeSet& attributeSet, int vertexCount) + : m_drawingMode(static_cast(Geometry::DrawingMode:: TriangleStrip)) // to mimic sg default , m_vertexCount(vertexCount) { @@ -20,22 +20,22 @@ Geometry::Geometry( m_data.resize(offset * vertexCount); } -int Geometry::attributeCount() const { +int BaseGeometry::attributeCount() const { return m_tupleSizes.size(); } -int Geometry::vertexCount() const { +int BaseGeometry::vertexCount() const { return m_vertexCount; } -int Geometry::offset(int attributeIndex) const { +int BaseGeometry::offset(int attributeIndex) const { return m_offsets[attributeIndex]; } -int Geometry::tupleSize(int attributeIndex) const { +int BaseGeometry::tupleSize(int attributeIndex) const { return m_tupleSizes[attributeIndex]; } -int Geometry::stride() const { +int BaseGeometry::stride() const { return m_stride; } diff --git a/src/rendergraph/opengl/backend/geometry.h b/src/rendergraph/opengl/backend/basegeometry.h similarity index 73% rename from src/rendergraph/opengl/backend/geometry.h rename to src/rendergraph/opengl/backend/basegeometry.h index 2965668e152..60281f6cb4b 100644 --- a/src/rendergraph/opengl/backend/geometry.h +++ b/src/rendergraph/opengl/backend/basegeometry.h @@ -4,13 +4,13 @@ #include "rendergraph/attributeset.h" -namespace rendergraph::backend { -class Geometry; +namespace rendergraph { +class BaseGeometry; } -class rendergraph::backend::Geometry { +class rendergraph::BaseGeometry { protected: - Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount); + BaseGeometry(const AttributeSet& attributeSet, int vertexCount); public: int attributeCount() const; diff --git a/src/rendergraph/opengl/backend/geometrynode.cpp b/src/rendergraph/opengl/backend/basegeometrynode.cpp similarity index 81% rename from src/rendergraph/opengl/backend/geometrynode.cpp rename to src/rendergraph/opengl/backend/basegeometrynode.cpp index 335792072cd..889b654deca 100644 --- a/src/rendergraph/opengl/backend/geometrynode.cpp +++ b/src/rendergraph/opengl/backend/basegeometrynode.cpp @@ -1,4 +1,4 @@ -#include "backend/geometrynode.h" +#include "backend/basegeometrynode.h" #include @@ -6,29 +6,29 @@ #include "rendergraph/geometrynode.h" #include "rendergraph/texture.h" -using namespace rendergraph::backend; +using namespace rendergraph; namespace { -GLenum toGlDrawingMode(rendergraph::Geometry::DrawingMode mode) { +GLenum toGlDrawingMode(Geometry::DrawingMode mode) { switch (mode) { - case rendergraph::Geometry::DrawingMode::Triangles: + case Geometry::DrawingMode::Triangles: return GL_TRIANGLES; - case rendergraph::Geometry::DrawingMode::TriangleStrip: + case Geometry::DrawingMode::TriangleStrip: return GL_TRIANGLE_STRIP; } } } // namespace -void GeometryNode::initializeBackend() { +void BaseGeometryNode::initializeBackend() { initializeOpenGLFunctions(); - rendergraph::GeometryNode* pThis = static_cast(this); + GeometryNode* pThis = static_cast(this); pThis->material().setShader(ShaderCache::getShaderForMaterial(&pThis->material())); } -void GeometryNode::renderBackend() { - rendergraph::GeometryNode* pThis = static_cast(this); - rendergraph::Geometry& geometry = pThis->geometry(); - rendergraph::Material& material = pThis->material(); +void BaseGeometryNode::renderBackend() { + GeometryNode* pThis = static_cast(this); + Geometry& geometry = pThis->geometry(); + Material& material = pThis->material(); if (geometry.vertexCount() == 0) { return; diff --git a/src/rendergraph/opengl/backend/basegeometrynode.h b/src/rendergraph/opengl/backend/basegeometrynode.h new file mode 100644 index 00000000000..b215fa5dda3 --- /dev/null +++ b/src/rendergraph/opengl/backend/basegeometrynode.h @@ -0,0 +1,19 @@ +#pragma once + +#include + +#include "backend/basenode.h" + +namespace rendergraph { +class BaseGeometryNode; +} + +class rendergraph::BaseGeometryNode : public rendergraph::BaseNode, + public QOpenGLFunctions { + protected: + BaseGeometryNode() = default; + + public: + void initializeBackend() override; + void renderBackend() override; +}; diff --git a/src/rendergraph/opengl/backend/basematerial.cpp b/src/rendergraph/opengl/backend/basematerial.cpp new file mode 100644 index 00000000000..3ad056bae6c --- /dev/null +++ b/src/rendergraph/opengl/backend/basematerial.cpp @@ -0,0 +1,27 @@ +#include "backend/basematerial.h" + +using namespace rendergraph; + +void BaseMaterial::setShader(std::shared_ptr pShader) { + m_pShader = pShader; +} + +MaterialShader& BaseMaterial::shader() const { + return *m_pShader; +} + +int BaseMaterial::uniformLocation(int uniformIndex) const { + return m_pShader->uniformLocation(uniformIndex); +} + +int BaseMaterial::attributeLocation(int attributeIndex) const { + return m_pShader->attributeLocation(attributeIndex); +} + +void BaseMaterial::modifyShader() { + m_pShader->setLastModifiedByMaterial(this); +} + +bool BaseMaterial::isLastModifierOfShader() const { + return this == m_pShader->lastModifiedByMaterial(); +} diff --git a/src/rendergraph/opengl/backend/basematerial.h b/src/rendergraph/opengl/backend/basematerial.h new file mode 100644 index 00000000000..ccf135fea3d --- /dev/null +++ b/src/rendergraph/opengl/backend/basematerial.h @@ -0,0 +1,27 @@ +#pragma once + +#include "rendergraph/materialshader.h" +#include "rendergraph/materialtype.h" + +namespace rendergraph { +class BaseMaterial; +} + +class rendergraph::BaseMaterial { + protected: + BaseMaterial() = default; + + public: + virtual MaterialType* type() const = 0; + + void setShader(std::shared_ptr pShader); + + MaterialShader& shader() const; + + int uniformLocation(int uniformIndex) const; + int attributeLocation(int attributeIndex) const; + + void modifyShader(); + bool isLastModifierOfShader() const; + std::shared_ptr m_pShader; +}; diff --git a/src/rendergraph/opengl/backend/basematerialshader.cpp b/src/rendergraph/opengl/backend/basematerialshader.cpp new file mode 100644 index 00000000000..d4b245e482a --- /dev/null +++ b/src/rendergraph/opengl/backend/basematerialshader.cpp @@ -0,0 +1,18 @@ +#include "backend/basematerialshader.h" + +using namespace rendergraph; + +int BaseMaterialShader::attributeLocation(int attributeIndex) const { + return m_attributeLocations[attributeIndex]; +} + +int BaseMaterialShader::uniformLocation(int uniformIndex) const { + return m_uniformLocations[uniformIndex]; +} + +BaseMaterial* BaseMaterialShader::lastModifiedByMaterial() const { + return m_pLastModifiedByMaterial; +} +void BaseMaterialShader::setLastModifiedByMaterial(BaseMaterial* pMaterial) { + m_pLastModifiedByMaterial = pMaterial; +} diff --git a/src/rendergraph/opengl/backend/basematerialshader.h b/src/rendergraph/opengl/backend/basematerialshader.h new file mode 100644 index 00000000000..76527ee8269 --- /dev/null +++ b/src/rendergraph/opengl/backend/basematerialshader.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include + +namespace rendergraph { +class BaseMaterial; // fwd decl to avoid circular dependency +class BaseMaterialShader; +} // namespace rendergraph + +class rendergraph::BaseMaterialShader : public QOpenGLShaderProgram { + protected: + BaseMaterialShader() = default; + + public: + int attributeLocation(int attributeIndex) const; + int uniformLocation(int uniformIndex) const; + + BaseMaterial* lastModifiedByMaterial() const; + void setLastModifiedByMaterial(BaseMaterial* pMaterial); + + static QString resource(const QString& filename) { + return QString(":/shaders/rendergraph/%1.gl").arg(filename); + } + std::vector m_attributeLocations; + std::vector m_uniformLocations; + BaseMaterial* m_pLastModifiedByMaterial{}; +}; diff --git a/src/rendergraph/opengl/backend/basematerialtype.h b/src/rendergraph/opengl/backend/basematerialtype.h new file mode 100644 index 00000000000..50b925d0bf4 --- /dev/null +++ b/src/rendergraph/opengl/backend/basematerialtype.h @@ -0,0 +1,6 @@ +#pragma once + +namespace rendergraph { +class BaseMaterialType { +}; +} // namespace rendergraph diff --git a/src/rendergraph/opengl/backend/node.h b/src/rendergraph/opengl/backend/basenode.h similarity index 81% rename from src/rendergraph/opengl/backend/node.h rename to src/rendergraph/opengl/backend/basenode.h index 898d675885f..d224e4cc8b3 100644 --- a/src/rendergraph/opengl/backend/node.h +++ b/src/rendergraph/opengl/backend/basenode.h @@ -1,16 +1,16 @@ #pragma once namespace rendergraph { -class Engine; +class Engine; // fwd decl to avoid circular dependency } -namespace rendergraph::backend { -class Node; +namespace rendergraph { +class BaseNode; } -class rendergraph::backend::Node { +class rendergraph::BaseNode { protected: - Node() = default; + BaseNode() = default; public: void setUsePreprocessFlag(bool value) { diff --git a/src/rendergraph/opengl/backend/opacitynode.h b/src/rendergraph/opengl/backend/baseopacitynode.h similarity index 56% rename from src/rendergraph/opengl/backend/opacitynode.h rename to src/rendergraph/opengl/backend/baseopacitynode.h index 3ba10f0ad6c..e07f7d141fb 100644 --- a/src/rendergraph/opengl/backend/opacitynode.h +++ b/src/rendergraph/opengl/backend/baseopacitynode.h @@ -1,14 +1,14 @@ #pragma once -#include "backend/node.h" +#include "backend/basenode.h" -namespace rendergraph::backend { -class OpacityNode; +namespace rendergraph { +class BaseOpacityNode; } -class rendergraph::backend::OpacityNode : public rendergraph::backend::Node { +class rendergraph::BaseOpacityNode : public rendergraph::BaseNode { protected: - OpacityNode() = default; + BaseOpacityNode() = default; public: void setOpacity(float opacity) { diff --git a/src/rendergraph/opengl/backend/baseopenglnode.cpp b/src/rendergraph/opengl/backend/baseopenglnode.cpp new file mode 100644 index 00000000000..1ba41569660 --- /dev/null +++ b/src/rendergraph/opengl/backend/baseopenglnode.cpp @@ -0,0 +1,21 @@ +#include "backend/baseopenglnode.h" + +#include "rendergraph/openglnode.h" + +using namespace rendergraph; + +void BaseOpenGLNode::initializeBackend() { + initializeOpenGLFunctions(); + OpenGLNode* pThis = static_cast(this); + pThis->initializeGL(); +} + +void BaseOpenGLNode::renderBackend() { + OpenGLNode* pThis = static_cast(this); + pThis->paintGL(); +} + +void BaseOpenGLNode::resizeBackend(int w, int h) { + OpenGLNode* pThis = static_cast(this); + pThis->resizeGL(w, h); +} diff --git a/src/rendergraph/opengl/backend/baseopenglnode.h b/src/rendergraph/opengl/backend/baseopenglnode.h new file mode 100644 index 00000000000..70c33642413 --- /dev/null +++ b/src/rendergraph/opengl/backend/baseopenglnode.h @@ -0,0 +1,20 @@ +#pragma once + +#include + +#include "backend/basenode.h" + +namespace rendergraph { +class BaseOpenGLNode; +} + +class rendergraph::BaseOpenGLNode : public rendergraph::BaseNode, + public QOpenGLFunctions { + protected: + BaseOpenGLNode() = default; + + public: + void initializeBackend() override; + void renderBackend() override; + void resizeBackend(int w, int h) override; +}; diff --git a/src/rendergraph/opengl/backend/basetexture.h b/src/rendergraph/opengl/backend/basetexture.h new file mode 100644 index 00000000000..f260dc91ebb --- /dev/null +++ b/src/rendergraph/opengl/backend/basetexture.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph { +using BaseTexture = QOpenGLTexture; +} diff --git a/src/rendergraph/opengl/backend/geometrynode.h b/src/rendergraph/opengl/backend/geometrynode.h deleted file mode 100644 index b60cd279441..00000000000 --- a/src/rendergraph/opengl/backend/geometrynode.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include - -#include "backend/node.h" - -namespace rendergraph::backend { -class GeometryNode; -} - -class rendergraph::backend::GeometryNode : public rendergraph::backend::Node, - public QOpenGLFunctions { - protected: - GeometryNode() = default; - - public: - void initializeBackend() override; - void renderBackend() override; -}; diff --git a/src/rendergraph/opengl/backend/material.cpp b/src/rendergraph/opengl/backend/material.cpp deleted file mode 100644 index d74abbeea92..00000000000 --- a/src/rendergraph/opengl/backend/material.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "backend/material.h" - -using namespace rendergraph::backend; - -void Material::setShader(std::shared_ptr pShader) { - m_pShader = pShader; -} - -rendergraph::MaterialShader& Material::shader() const { - return *m_pShader; -} - -int Material::uniformLocation(int uniformIndex) const { - return m_pShader->uniformLocation(uniformIndex); -} - -int Material::attributeLocation(int attributeIndex) const { - return m_pShader->attributeLocation(attributeIndex); -} - -void Material::modifyShader() { - m_pShader->setLastModifiedByMaterial(this); -} - -bool Material::isLastModifierOfShader() const { - return this == m_pShader->lastModifiedByMaterial(); -} diff --git a/src/rendergraph/opengl/backend/material.h b/src/rendergraph/opengl/backend/material.h deleted file mode 100644 index 3574d69c78b..00000000000 --- a/src/rendergraph/opengl/backend/material.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "rendergraph/materialshader.h" -#include "rendergraph/materialtype.h" - -namespace rendergraph::backend { -class Material; -} - -class rendergraph::backend::Material { - protected: - Material() = default; - - public: - virtual rendergraph::MaterialType* type() const = 0; - - void setShader(std::shared_ptr pShader); - - rendergraph::MaterialShader& shader() const; - - int uniformLocation(int uniformIndex) const; - int attributeLocation(int attributeIndex) const; - - void modifyShader(); - bool isLastModifierOfShader() const; - std::shared_ptr m_pShader; -}; diff --git a/src/rendergraph/opengl/backend/materialshader.cpp b/src/rendergraph/opengl/backend/materialshader.cpp deleted file mode 100644 index e2c66519e10..00000000000 --- a/src/rendergraph/opengl/backend/materialshader.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "backend/materialshader.h" - -using namespace rendergraph::backend; - -int MaterialShader::attributeLocation(int attributeIndex) const { - return m_attributeLocations[attributeIndex]; -} - -int MaterialShader::uniformLocation(int uniformIndex) const { - return m_uniformLocations[uniformIndex]; -} - -Material* MaterialShader::lastModifiedByMaterial() const { - return m_pLastModifiedByMaterial; -} -void MaterialShader::setLastModifiedByMaterial(Material* pMaterial) { - m_pLastModifiedByMaterial = pMaterial; -} diff --git a/src/rendergraph/opengl/backend/materialshader.h b/src/rendergraph/opengl/backend/materialshader.h deleted file mode 100644 index 7e56a450791..00000000000 --- a/src/rendergraph/opengl/backend/materialshader.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once - -#include -#include - -namespace rendergraph::backend { -class Material; -class MaterialShader; -} // namespace rendergraph::backend - -class rendergraph::backend::MaterialShader : public QOpenGLShaderProgram { - protected: - MaterialShader() = default; - - public: - int attributeLocation(int attributeIndex) const; - int uniformLocation(int uniformIndex) const; - - Material* lastModifiedByMaterial() const; - void setLastModifiedByMaterial(Material* pMaterial); - - static QString resource(const char* filename) { - return QString(":/shaders/rendergraph/") + QString(filename) + QString(".gl"); - } - std::vector m_attributeLocations; - std::vector m_uniformLocations; - Material* m_pLastModifiedByMaterial{}; -}; diff --git a/src/rendergraph/opengl/backend/materialtype.h b/src/rendergraph/opengl/backend/materialtype.h deleted file mode 100644 index 1e44b097016..00000000000 --- a/src/rendergraph/opengl/backend/materialtype.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -namespace rendergraph::backend { -class MaterialType; -} - -class rendergraph::backend::MaterialType { -}; diff --git a/src/rendergraph/opengl/backend/openglnode.cpp b/src/rendergraph/opengl/backend/openglnode.cpp deleted file mode 100644 index ae12372ef3c..00000000000 --- a/src/rendergraph/opengl/backend/openglnode.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "backend/openglnode.h" - -#include "rendergraph/openglnode.h" - -using namespace rendergraph::backend; - -void OpenGLNode::initializeBackend() { - initializeOpenGLFunctions(); - rendergraph::OpenGLNode* pThis = static_cast(this); - pThis->initializeGL(); -} - -void OpenGLNode::renderBackend() { - rendergraph::OpenGLNode* pThis = static_cast(this); - pThis->paintGL(); -} - -void OpenGLNode::resizeBackend(int w, int h) { - rendergraph::OpenGLNode* pThis = static_cast(this); - pThis->resizeGL(w, h); -} diff --git a/src/rendergraph/opengl/backend/openglnode.h b/src/rendergraph/opengl/backend/openglnode.h deleted file mode 100644 index 9d6d379917b..00000000000 --- a/src/rendergraph/opengl/backend/openglnode.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include - -#include "backend/node.h" - -namespace rendergraph::backend { -class OpenGLNode; -} - -class rendergraph::backend::OpenGLNode : public rendergraph::backend::Node, - public QOpenGLFunctions { - protected: - OpenGLNode() = default; - - public: - void initializeBackend() override; - void renderBackend() override; - void resizeBackend(int w, int h) override; -}; diff --git a/src/rendergraph/opengl/backend/shadercache.h b/src/rendergraph/opengl/backend/shadercache.h index 850d039c826..9c4653e493c 100644 --- a/src/rendergraph/opengl/backend/shadercache.h +++ b/src/rendergraph/opengl/backend/shadercache.h @@ -6,32 +6,32 @@ #include "rendergraph/materialshader.h" #include "rendergraph/materialtype.h" -namespace rendergraph::backend { +namespace rendergraph { class ShaderCache; } -class rendergraph::backend::ShaderCache { +class rendergraph::ShaderCache { private: - static std::map>& + static std::map>& map() { - static std::map> + static std::map> s_map; return s_map; } public: - static std::shared_ptr getShaderForMaterial( - rendergraph::Material* pMaterial) { + static std::shared_ptr getShaderForMaterial( + Material* pMaterial) { auto iter = map().find(pMaterial->type()); if (iter != map().end()) { return iter->second; } - auto pResult = std::shared_ptr( + auto pResult = std::shared_ptr( pMaterial->createShader()); - map().insert(std::pair>{ + map().insert(std::pair>{ pMaterial->type(), pResult}); return pResult; } diff --git a/src/rendergraph/opengl/backend/texture.h b/src/rendergraph/opengl/backend/texture.h deleted file mode 100644 index 2de1052269f..00000000000 --- a/src/rendergraph/opengl/backend/texture.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -namespace rendergraph::backend { -using Texture = QOpenGLTexture; -} diff --git a/src/rendergraph/opengl/engine.cpp b/src/rendergraph/opengl/engine.cpp index 857b439e24a..700b3b8994c 100644 --- a/src/rendergraph/opengl/engine.cpp +++ b/src/rendergraph/opengl/engine.cpp @@ -6,8 +6,8 @@ using namespace rendergraph; -Engine::Engine(std::unique_ptr node) - : m_pTopNode(std::move(node)) { +Engine::Engine(std::unique_ptr pNode) + : m_pTopNode(std::move(pNode)) { addToEngine(m_pTopNode.get()); } @@ -23,7 +23,7 @@ void Engine::render() { if (!m_pInitializeNodes.empty()) { initialize(); } - if (!m_pTopNode->isSubtreeBlocked()) { + if (!m_pTopNode->backendNode()->isSubtreeBlocked()) { render(m_pTopNode.get()); } } @@ -40,7 +40,7 @@ void Engine::preprocess() { } } -void Engine::render(BaseNode* pNode) { +void Engine::render(TreeNode* pNode) { pNode->backendNode()->renderBackend(); pNode = pNode->firstChild(); while (pNode) { @@ -51,7 +51,7 @@ void Engine::render(BaseNode* pNode) { } } -void Engine::resize(BaseNode* pNode, int w, int h) { +void Engine::resize(TreeNode* pNode, int w, int h) { pNode->backendNode()->resizeBackend(w, h); pNode->resize(w, h); pNode = pNode->firstChild(); @@ -61,7 +61,7 @@ void Engine::resize(BaseNode* pNode, int w, int h) { } } -void Engine::addToEngine(BaseNode* pNode) { +void Engine::addToEngine(TreeNode* pNode) { assert(pNode->backendNode()->engine() == nullptr); pNode->backendNode()->setEngine(this); diff --git a/src/rendergraph/opengl/geometry.cpp b/src/rendergraph/opengl/geometry.cpp index aeb1828ed30..a45b325a152 100644 --- a/src/rendergraph/opengl/geometry.cpp +++ b/src/rendergraph/opengl/geometry.cpp @@ -5,7 +5,7 @@ using namespace rendergraph; Geometry::Geometry(const AttributeSet& attributeSet, int vertexCount) - : backend::Geometry(attributeSet, vertexCount) { + : BaseGeometry(attributeSet, vertexCount) { } Geometry::~Geometry() = default; diff --git a/src/rendergraph/opengl/geometrynode.cpp b/src/rendergraph/opengl/geometrynode.cpp index c5c5600b01c..ad5c4448dce 100644 --- a/src/rendergraph/opengl/geometrynode.cpp +++ b/src/rendergraph/opengl/geometrynode.cpp @@ -3,7 +3,7 @@ using namespace rendergraph; GeometryNode::GeometryNode() - : BaseNode(this) { + : TreeNode(this) { } void GeometryNode::setGeometry(std::unique_ptr pGeometry) { diff --git a/src/rendergraph/opengl/openglnode.cpp b/src/rendergraph/opengl/openglnode.cpp index cd7f84ab99d..c9e3e17ff87 100644 --- a/src/rendergraph/opengl/openglnode.cpp +++ b/src/rendergraph/opengl/openglnode.cpp @@ -3,5 +3,5 @@ using namespace rendergraph; OpenGLNode::OpenGLNode() - : BaseNode(this) { + : TreeNode(this) { } diff --git a/src/rendergraph/opengl/rendergraph/engine.h b/src/rendergraph/opengl/rendergraph/engine.h index 9eab434ed33..fc5935fafd0 100644 --- a/src/rendergraph/opengl/rendergraph/engine.h +++ b/src/rendergraph/opengl/rendergraph/engine.h @@ -11,19 +11,19 @@ class Engine; class rendergraph::Engine { public: - Engine(std::unique_ptr node); + Engine(std::unique_ptr pNode); void initialize(); void render(); void resize(int w, int h); void preprocess(); - void addToEngine(BaseNode* pNode); + void addToEngine(TreeNode* pNode); private: - void initialize(BaseNode* pNode); - void render(BaseNode* pNode); - void resize(BaseNode* pNode, int, int); + void initialize(TreeNode* pNode); + void render(TreeNode* pNode); + void resize(TreeNode* pNode, int, int); - const std::unique_ptr m_pTopNode; - std::vector m_pPreprocessNodes; - std::vector m_pInitializeNodes; + const std::unique_ptr m_pTopNode; + std::vector m_pPreprocessNodes; + std::vector m_pInitializeNodes; }; diff --git a/src/rendergraph/opengl/rendergraph/openglnode.h b/src/rendergraph/opengl/rendergraph/openglnode.h index f2d188fcabb..5cb3497edb3 100644 --- a/src/rendergraph/opengl/rendergraph/openglnode.h +++ b/src/rendergraph/opengl/rendergraph/openglnode.h @@ -1,14 +1,14 @@ #pragma once -#include "backend/openglnode.h" -#include "rendergraph/basenode.h" +#include "backend/baseopenglnode.h" +#include "rendergraph/treenode.h" namespace rendergraph { class OpenGLNode; } // namespace rendergraph -class rendergraph::OpenGLNode : public rendergraph::backend::OpenGLNode, - public rendergraph::BaseNode { +class rendergraph::OpenGLNode : public rendergraph::BaseOpenGLNode, + public rendergraph::TreeNode { public: OpenGLNode(); diff --git a/src/rendergraph/opengl/basenode.cpp b/src/rendergraph/opengl/treenode.cpp similarity index 57% rename from src/rendergraph/opengl/basenode.cpp rename to src/rendergraph/opengl/treenode.cpp index 2f10fbab534..949e6e10a2b 100644 --- a/src/rendergraph/opengl/basenode.cpp +++ b/src/rendergraph/opengl/treenode.cpp @@ -1,21 +1,22 @@ -#include "rendergraph/basenode.h" +#include "rendergraph/treenode.h" + #include "rendergraph/engine.h" using namespace rendergraph; -void BaseNode::setUsePreprocess(bool value) { +void TreeNode::setUsePreprocess(bool value) { backendNode()->setUsePreprocessFlag(value); } -void BaseNode::onAppendChildNode(BaseNode* pChild) { +void TreeNode::onAppendChildNode(TreeNode* pChild) { if (backendNode()->engine() != nullptr && backendNode()->engine() != pChild->backendNode()->engine()) { backendNode()->engine()->addToEngine(pChild); } } -void BaseNode::onRemoveChildNode(BaseNode*) { +void TreeNode::onRemoveChildNode(TreeNode*) { } -void BaseNode::onRemoveAllChildNodes() { +void TreeNode::onRemoveAllChildNodes() { } diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 3c020079e20..3fe8fd57bd9 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -1,11 +1,11 @@ add_library(rendergraph_sg ../common/attributeset.cpp -../common/basenode.cpp +../common/treenode.cpp ../common/node.cpp ../common/opacitynode.cpp ../common/rendergraph/attribute.h ../common/rendergraph/attributeset.h -../common/rendergraph/basenode.h +../common/rendergraph/treenode.h ../common/rendergraph/geometry.h ../common/rendergraph/geometrynode.h ../common/rendergraph/material.h @@ -33,18 +33,18 @@ add_library(rendergraph_sg ../common/rendergraph/uniformset.cpp ../common/rendergraph/uniformset.h ../common/types.cpp -backend/attributeset.cpp -backend/attributeset.h -backend/geometry.h -backend/geometrynode.h -backend/material.cpp -backend/material.h -backend/materialshader.cpp -backend/materialtype.h -backend/node.h -backend/opacitynode.h -backend/texture.h -basenode.cpp +backend/baseattributeset.cpp +backend/baseattributeset.h +backend/basegeometry.h +backend/basegeometrynode.h +backend/basematerial.cpp +backend/basematerial.h +backend/basematerialshader.cpp +backend/basematerialtype.h +backend/basenode.h +backend/baseopacitynode.h +backend/basetexture.h +treenode.cpp context.cpp geometry.cpp geometrynode.cpp diff --git a/src/rendergraph/scenegraph/backend/attributeset.h b/src/rendergraph/scenegraph/backend/attributeset.h deleted file mode 100644 index 8b887c5ac81..00000000000 --- a/src/rendergraph/scenegraph/backend/attributeset.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once - -#include -#include -#include - -#include "rendergraph/attribute.h" - -namespace rendergraph::backend { -class AttributeSet; -class AttributeSetBase; -} // namespace rendergraph::backend - -class rendergraph::backend::AttributeSetBase { - protected: - int m_stride{}; - - AttributeSetBase(std::initializer_list list, const std::vector& names); - - const std::vector& attributes() const { - return m_attributes; - } - - std::vector m_attributes; - QSGGeometry::AttributeSet m_sgAttributeSet{}; - std::vector m_sgAttributes; -}; - -class rendergraph::backend::AttributeSet - : protected rendergraph::backend::AttributeSetBase, - public QSGGeometry::AttributeSet { - protected: - AttributeSet(std::initializer_list list, - const std::vector& names) - : AttributeSetBase(list, names), - QSGGeometry::AttributeSet{static_cast(m_sgAttributes.size()), - m_stride, - m_sgAttributes.data()} { - } -}; diff --git a/src/rendergraph/scenegraph/backend/attributeset.cpp b/src/rendergraph/scenegraph/backend/baseattributeset.cpp similarity index 72% rename from src/rendergraph/scenegraph/backend/attributeset.cpp rename to src/rendergraph/scenegraph/backend/baseattributeset.cpp index b3733ce1547..b288da72e77 100644 --- a/src/rendergraph/scenegraph/backend/attributeset.cpp +++ b/src/rendergraph/scenegraph/backend/baseattributeset.cpp @@ -1,19 +1,19 @@ -#include "backend/attributeset.h" +#include "backend/baseattributeset.h" -using namespace rendergraph::backend; +using namespace rendergraph; namespace { -int toQSGGeometryType(const rendergraph::PrimitiveType& t) { +int toQSGGeometryType(const PrimitiveType& t) { switch (t) { - case rendergraph::PrimitiveType::Float: + case PrimitiveType::Float: return QSGGeometry::FloatType; - case rendergraph::PrimitiveType::UInt: + case PrimitiveType::UInt: return QSGGeometry::UnsignedIntType; } } } // namespace -AttributeSetBase::AttributeSetBase(std::initializer_list list, +BaseAttributeSetHelper::BaseAttributeSetHelper(std::initializer_list list, const std::vector& names) { int i = 0; for (auto item : list) { diff --git a/src/rendergraph/scenegraph/backend/baseattributeset.h b/src/rendergraph/scenegraph/backend/baseattributeset.h new file mode 100644 index 00000000000..1d6d35638c6 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/baseattributeset.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include + +#include "rendergraph/attribute.h" + +namespace rendergraph { +class BaseAttributeSet; +class BaseAttributeSetHelper; +} // namespace rendergraph + +class rendergraph::BaseAttributeSetHelper { + protected: + // helper base class for BaseAttributeSet to populate m_attributes, and m_sgAttributes + // needed to construct BaseAttributeSet's other base class, QSGGeometry::AttributeSet + int m_stride{}; + + BaseAttributeSetHelper(std::initializer_list list, + const std::vector& names); + + const std::vector& attributes() const { + return m_attributes; + } + + std::vector m_attributes; + std::vector m_sgAttributes; +}; + +class rendergraph::BaseAttributeSet + : protected rendergraph::BaseAttributeSetHelper, + public QSGGeometry::AttributeSet { + protected: + BaseAttributeSet(std::initializer_list list, + const std::vector& names) + : BaseAttributeSetHelper(list, names), + QSGGeometry::AttributeSet{static_cast(m_sgAttributes.size()), + m_stride, + m_sgAttributes.data()} { + } +}; diff --git a/src/rendergraph/scenegraph/backend/geometry.h b/src/rendergraph/scenegraph/backend/basegeometry.h similarity index 61% rename from src/rendergraph/scenegraph/backend/geometry.h rename to src/rendergraph/scenegraph/backend/basegeometry.h index 077c19e4450..4eb75b7be10 100644 --- a/src/rendergraph/scenegraph/backend/geometry.h +++ b/src/rendergraph/scenegraph/backend/basegeometry.h @@ -4,13 +4,13 @@ #include "rendergraph/attributeset.h" -namespace rendergraph::backend { -class Geometry; +namespace rendergraph { +class BaseGeometry; } -class rendergraph::backend::Geometry : public QSGGeometry { +class rendergraph::BaseGeometry : public QSGGeometry { protected: - Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount) + BaseGeometry(const AttributeSet& attributeSet, int vertexCount) : QSGGeometry(attributeSet, vertexCount), m_stride(attributeSet.stride) { QSGGeometry::setDrawingMode(QSGGeometry::DrawTriangleStrip); diff --git a/src/rendergraph/scenegraph/backend/basegeometrynode.h b/src/rendergraph/scenegraph/backend/basegeometrynode.h new file mode 100644 index 00000000000..e665e8451aa --- /dev/null +++ b/src/rendergraph/scenegraph/backend/basegeometrynode.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph { +using BaseGeometryNode = QSGGeometryNode; +} diff --git a/src/rendergraph/scenegraph/backend/material.cpp b/src/rendergraph/scenegraph/backend/basematerial.cpp similarity index 51% rename from src/rendergraph/scenegraph/backend/material.cpp rename to src/rendergraph/scenegraph/backend/basematerial.cpp index 26a0188feb8..4199f165d88 100644 --- a/src/rendergraph/scenegraph/backend/material.cpp +++ b/src/rendergraph/scenegraph/backend/basematerial.cpp @@ -2,10 +2,10 @@ #include "rendergraph/materialshader.h" -using namespace rendergraph::backend; +using namespace rendergraph; -bool Material::updateUniformsByteArray(QByteArray* buf) { - auto pThis = static_cast(this); +bool BaseMaterial::updateUniformsByteArray(QByteArray* buf) { + auto pThis = static_cast(this); if (pThis->clearUniformsCacheDirty()) { memcpy(buf->data(), pThis->uniformsCache().data(), pThis->uniformsCache().size()); return true; @@ -13,16 +13,16 @@ bool Material::updateUniformsByteArray(QByteArray* buf) { return false; } -int Material::compare(const QSGMaterial* other) const { - auto pThis = static_cast(this); - return pThis->compare(dynamic_cast(other)); +int BaseMaterial::compare(const QSGMaterial* other) const { + auto pThis = static_cast(this); + return pThis->compare(dynamic_cast(other)); } -QSGMaterialShader* Material::createShader(QSGRendererInterface::RenderMode) const { +QSGMaterialShader* BaseMaterial::createShader(QSGRendererInterface::RenderMode) const { // This looks like a leak but it isn't: we pass ownership to Qt. Qt will // cache and reuse the shader for all Material of the same type. // TODO make sure that RenderMode is always the same. - auto pThis = static_cast(this); + auto pThis = static_cast(this); auto pShader = pThis->createShader().release(); return pShader; } diff --git a/src/rendergraph/scenegraph/backend/material.h b/src/rendergraph/scenegraph/backend/basematerial.h similarity index 66% rename from src/rendergraph/scenegraph/backend/material.h rename to src/rendergraph/scenegraph/backend/basematerial.h index 0f395f58199..7c745f3d991 100644 --- a/src/rendergraph/scenegraph/backend/material.h +++ b/src/rendergraph/scenegraph/backend/basematerial.h @@ -2,13 +2,13 @@ #include -namespace rendergraph::backend { -class Material; +namespace rendergraph { +class BaseMaterial; } -class rendergraph::backend::Material : public QSGMaterial { +class rendergraph::BaseMaterial : public QSGMaterial { protected: - Material() = default; + BaseMaterial() = default; public: QSGMaterialShader* createShader(QSGRendererInterface::RenderMode) const override; diff --git a/src/rendergraph/scenegraph/backend/basematerialshader.cpp b/src/rendergraph/scenegraph/backend/basematerialshader.cpp new file mode 100644 index 00000000000..b75fc8cdf98 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/basematerialshader.cpp @@ -0,0 +1,24 @@ +#include "backend/basematerialshader.h" + +#include + +#include "rendergraph/material.h" + +using namespace rendergraph; + +bool BaseMaterialShader::updateUniformData(RenderState& state, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) { + return static_cast(newMaterial)->updateUniformsByteArray(state.uniformData()); +} + +// override for QSGMaterialShader; this function is called by the Qt scene graph to prepare use of +// sampled images in the shader, typically in the form of combined image samplers. +void BaseMaterialShader::updateSampledImage(RenderState& state, + int binding, + QSGTexture** texture, + QSGMaterial* newMaterial, + QSGMaterial* oldMaterial) { + *texture = static_cast(newMaterial)->texture(binding)->backendTexture(); + (*texture)->commitTextureOperations(state.rhi(), state.resourceUpdateBatch()); +} diff --git a/src/rendergraph/scenegraph/backend/materialshader.h b/src/rendergraph/scenegraph/backend/basematerialshader.h similarity index 58% rename from src/rendergraph/scenegraph/backend/materialshader.h rename to src/rendergraph/scenegraph/backend/basematerialshader.h index 26a9d270135..9b6a9773377 100644 --- a/src/rendergraph/scenegraph/backend/materialshader.h +++ b/src/rendergraph/scenegraph/backend/basematerialshader.h @@ -3,13 +3,13 @@ #include #include -namespace rendergraph::backend { -class MaterialShader; +namespace rendergraph { +class BaseMaterialShader; } -class rendergraph::backend::MaterialShader : public QSGMaterialShader { +class rendergraph::BaseMaterialShader : public QSGMaterialShader { protected: - MaterialShader() = default; + BaseMaterialShader() = default; public: bool updateUniformData(RenderState& state, @@ -22,7 +22,7 @@ class rendergraph::backend::MaterialShader : public QSGMaterialShader { QSGMaterial* newMaterial, QSGMaterial* oldMaterial) override; - static QString resource(const char* filename) { - return QString(":/shaders/rendergraph/") + QString(filename) + QString(".qsb"); + static QString resource(const QString& filename) { + return QString(":/shaders/rendergraph/%1.qsb").arg(filename); } }; diff --git a/src/rendergraph/scenegraph/backend/basematerialtype.h b/src/rendergraph/scenegraph/backend/basematerialtype.h new file mode 100644 index 00000000000..b3606003e03 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/basematerialtype.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph { +using BaseMaterialType = QSGMaterialType; +} diff --git a/src/rendergraph/scenegraph/backend/basenode.h b/src/rendergraph/scenegraph/backend/basenode.h new file mode 100644 index 00000000000..3ece5661d80 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/basenode.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph { +using BaseNode = QSGNode; +} diff --git a/src/rendergraph/scenegraph/backend/baseopacitynode.h b/src/rendergraph/scenegraph/backend/baseopacitynode.h new file mode 100644 index 00000000000..3a3ef1b8661 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/baseopacitynode.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph { +using BaseOpacityNode = QSGOpacityNode; +} diff --git a/src/rendergraph/scenegraph/backend/basetexture.h b/src/rendergraph/scenegraph/backend/basetexture.h new file mode 100644 index 00000000000..10840145d52 --- /dev/null +++ b/src/rendergraph/scenegraph/backend/basetexture.h @@ -0,0 +1,7 @@ +#pragma once + +#include + +namespace rendergraph { +using BaseTexture = QSGTexture; +} diff --git a/src/rendergraph/scenegraph/backend/geometrynode.h b/src/rendergraph/scenegraph/backend/geometrynode.h deleted file mode 100644 index 3abf5888a41..00000000000 --- a/src/rendergraph/scenegraph/backend/geometrynode.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -namespace rendergraph::backend { -using GeometryNode = QSGGeometryNode; -} diff --git a/src/rendergraph/scenegraph/backend/materialshader.cpp b/src/rendergraph/scenegraph/backend/materialshader.cpp deleted file mode 100644 index cf03833c96a..00000000000 --- a/src/rendergraph/scenegraph/backend/materialshader.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "backend/materialshader.h" - -#include - -#include "rendergraph/material.h" - -using namespace rendergraph::backend; - -bool MaterialShader::updateUniformData(RenderState& state, - QSGMaterial* newMaterial, - QSGMaterial* oldMaterial) { - return static_cast(newMaterial)->updateUniformsByteArray(state.uniformData()); -} - -void MaterialShader::updateSampledImage(RenderState& state, - int binding, - QSGTexture** texture, - QSGMaterial* newMaterial, - QSGMaterial* oldMaterial) { - *texture = static_cast(newMaterial)->texture(binding)->backendTexture(); - (*texture)->commitTextureOperations(state.rhi(), state.resourceUpdateBatch()); -} diff --git a/src/rendergraph/scenegraph/backend/materialtype.h b/src/rendergraph/scenegraph/backend/materialtype.h deleted file mode 100644 index 1587eb28b1a..00000000000 --- a/src/rendergraph/scenegraph/backend/materialtype.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include - -namespace rendergraph::backend { -class MaterialType; -} - -class rendergraph::backend::MaterialType : public QSGMaterialType { -}; diff --git a/src/rendergraph/scenegraph/backend/node.h b/src/rendergraph/scenegraph/backend/node.h deleted file mode 100644 index 1cbdf98bc97..00000000000 --- a/src/rendergraph/scenegraph/backend/node.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -namespace rendergraph::backend { -using Node = QSGNode; -} diff --git a/src/rendergraph/scenegraph/backend/opacitynode.h b/src/rendergraph/scenegraph/backend/opacitynode.h deleted file mode 100644 index 18ad539cc9d..00000000000 --- a/src/rendergraph/scenegraph/backend/opacitynode.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -namespace rendergraph::backend { -using OpacityNode = QSGOpacityNode; -} diff --git a/src/rendergraph/scenegraph/backend/texture.h b/src/rendergraph/scenegraph/backend/texture.h deleted file mode 100644 index 9ca05aa9262..00000000000 --- a/src/rendergraph/scenegraph/backend/texture.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include - -namespace rendergraph::backend { -using Texture = QSGTexture; -} diff --git a/src/rendergraph/scenegraph/geometry.cpp b/src/rendergraph/scenegraph/geometry.cpp index fbabdc36c77..6af25958564 100644 --- a/src/rendergraph/scenegraph/geometry.cpp +++ b/src/rendergraph/scenegraph/geometry.cpp @@ -25,7 +25,7 @@ Geometry::DrawingMode fromSgDrawingMode(unsigned int mode) { } // namespace Geometry::Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount) - : backend::Geometry(attributeSet, vertexCount) { + : BaseGeometry(attributeSet, vertexCount) { } Geometry::~Geometry() = default; diff --git a/src/rendergraph/scenegraph/geometrynode.cpp b/src/rendergraph/scenegraph/geometrynode.cpp index 5d35e7d76dd..bd9f26570e8 100644 --- a/src/rendergraph/scenegraph/geometrynode.cpp +++ b/src/rendergraph/scenegraph/geometrynode.cpp @@ -3,7 +3,7 @@ using namespace rendergraph; GeometryNode::GeometryNode() - : BaseNode(this) { + : TreeNode(this) { } void GeometryNode::setGeometry(std::unique_ptr pGeometry) { diff --git a/src/rendergraph/scenegraph/basenode.cpp b/src/rendergraph/scenegraph/treenode.cpp similarity index 53% rename from src/rendergraph/scenegraph/basenode.cpp rename to src/rendergraph/scenegraph/treenode.cpp index 5ffcadfd8c4..904afe7b0be 100644 --- a/src/rendergraph/scenegraph/basenode.cpp +++ b/src/rendergraph/scenegraph/treenode.cpp @@ -1,19 +1,19 @@ -#include "rendergraph/basenode.h" +#include "rendergraph/treenode.h" using namespace rendergraph; -void BaseNode::setUsePreprocess(bool value) { +void TreeNode::setUsePreprocess(bool value) { backendNode()->setFlag(QSGNode::UsePreprocess, value); } -void BaseNode::onAppendChildNode(BaseNode* pChild) { +void TreeNode::onAppendChildNode(TreeNode* pChild) { backendNode()->appendChildNode(pChild->backendNode()); } -void BaseNode::onRemoveChildNode(BaseNode* pChild) { +void TreeNode::onRemoveChildNode(TreeNode* pChild) { backendNode()->removeChildNode(pChild->backendNode()); } -void BaseNode::onRemoveAllChildNodes() { +void TreeNode::onRemoveAllChildNodes() { backendNode()->removeAllChildNodes(); } diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 514b127ba72..6c9d958df11 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -84,10 +84,10 @@ class WaveformMarkNodeGraphics : public WaveformMark::Graphics { float textureHeight() const { return waveformMarkNode()->textureHeight(); } - void setNode(std::unique_ptr&& pNode) { + void setNode(std::unique_ptr&& pNode) { m_pNode = std::move(pNode); } - void moveNodeToChildrenOf(BaseNode* pParent) { + void moveNodeToChildrenOf(TreeNode* pParent) { pParent->appendChildNode(std::move(m_pNode)); } @@ -96,7 +96,7 @@ class WaveformMarkNodeGraphics : public WaveformMark::Graphics { return static_cast(m_pNode.get()); } - std::unique_ptr m_pNode; + std::unique_ptr m_pNode; }; // Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive @@ -248,7 +248,7 @@ void allshader::WaveformRenderMark::update() { const double playPosition = m_waveformRenderer->getTruePosSample(positionType); double nextMarkPosition = std::numeric_limits::max(); - BaseNode* pRangeChild = m_pRangeNodesParent->firstChild(); + TreeNode* pRangeChild = m_pRangeNodesParent->firstChild(); for (const auto& pMark : std::as_const(m_marks)) { if (!pMark->isValid()) { diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index 730df0c8e12..2eedbadc604 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -64,8 +64,8 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, bool m_isSlipRenderer; - rendergraph::BaseNode* m_pRangeNodesParent{}; - rendergraph::BaseNode* m_pMarkNodesParent{}; + rendergraph::TreeNode* m_pRangeNodesParent{}; + rendergraph::TreeNode* m_pMarkNodesParent{}; rendergraph::GeometryNode* m_pPlayPosNode; DigitsRenderNode* m_pDigitsRenderNode{}; diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index 105489b495f..46a2e7fbe02 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -42,7 +42,7 @@ void WaveformRenderMarkRange::draw(QPainter* painter, QPaintEvent* event) { void WaveformRenderMarkRange::update() { const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - BaseNode* pChild = firstChild(); + TreeNode* pChild = firstChild(); for (const auto& markRange : m_markRanges) { // If the mark range is not active we should not draw it. diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index 11328189f1e..0690e37ae07 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -21,12 +21,12 @@ #include "waveform/widgets/allshader/moc_waveformwidget.cpp" namespace { -void appendChildTo(std::unique_ptr& pNode, rendergraph::BaseNode* pChild) { - pNode->appendChildNode(std::unique_ptr(pChild)); +void appendChildTo(std::unique_ptr& pNode, rendergraph::TreeNode* pChild) { + pNode->appendChildNode(std::unique_ptr(pChild)); } void appendChildTo(std::unique_ptr& pNode, - rendergraph::BaseNode* pChild) { - pNode->appendChildNode(std::unique_ptr(pChild)); + rendergraph::TreeNode* pChild) { + pNode->appendChildNode(std::unique_ptr(pChild)); } } // namespace From c5444fc1f368180b76ab018a2f517648f2128589 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 22 Sep 2024 19:06:27 +0200 Subject: [PATCH 26/64] added comment to explain return value of remove node functions --- src/rendergraph/common/rendergraph/treenode.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/rendergraph/common/rendergraph/treenode.h b/src/rendergraph/common/rendergraph/treenode.h index a4850f17c9c..2cd943ce838 100644 --- a/src/rendergraph/common/rendergraph/treenode.h +++ b/src/rendergraph/common/rendergraph/treenode.h @@ -16,7 +16,16 @@ class rendergraph::TreeNode { virtual ~TreeNode() = default; void appendChildNode(std::unique_ptr&& pChild); + + // remove all child nodes. returns the list of child nodes + // by returning the node in the list. the caller can keep + // the pointer, thus transferring ownership. otherwise the + // nodes will be destroyed std::unique_ptr removeAllChildNodes(); + + // remove a single child node for the list of child nodes. + // the caller can keep the pointer, thus transferring ownership. + // otherwise the node will be destroyed std::unique_ptr removeChildNode(TreeNode* pChild); TreeNode* parent() const { From ec3f8164e410dae33f96276c58840ca5974a774e Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 22 Sep 2024 20:35:01 +0200 Subject: [PATCH 27/64] use a generic Material::compare --- src/rendergraph/common/rendergraph/material.h | 27 +++++++++++++++++-- .../material/endoftrackmaterial.cpp | 6 ----- .../rendergraph/material/endoftrackmaterial.h | 2 -- .../rendergraph/material/patternmaterial.cpp | 6 ----- .../rendergraph/material/patternmaterial.h | 2 -- .../rendergraph/material/rgbamaterial.cpp | 6 ----- .../rendergraph/material/rgbamaterial.h | 2 -- .../rendergraph/material/rgbmaterial.cpp | 6 ----- .../common/rendergraph/material/rgbmaterial.h | 2 -- .../rendergraph/material/texturematerial.cpp | 6 ----- .../rendergraph/material/texturematerial.h | 2 -- .../rendergraph/material/unicolormaterial.cpp | 6 ----- .../rendergraph/material/unicolormaterial.h | 2 -- src/rendergraph/common/rendergraph/texture.h | 5 +++- .../common/rendergraph/uniformscache.h | 1 + src/rendergraph/opengl/CMakeLists.txt | 4 ++- .../opengl/backend/basematerial.cpp | 7 +++++ src/rendergraph/opengl/backend/basematerial.h | 3 +++ src/rendergraph/opengl/texture.cpp | 4 +++ src/rendergraph/scenegraph/CMakeLists.txt | 4 ++- .../scenegraph/backend/basematerial.cpp | 2 +- src/rendergraph/scenegraph/texture.cpp | 4 +++ 22 files changed, 55 insertions(+), 54 deletions(-) diff --git a/src/rendergraph/common/rendergraph/material.h b/src/rendergraph/common/rendergraph/material.h index 910fa442862..98e9e571d65 100644 --- a/src/rendergraph/common/rendergraph/material.h +++ b/src/rendergraph/common/rendergraph/material.h @@ -8,6 +8,7 @@ #include "rendergraph/texture.h" #include "rendergraph/uniformscache.h" #include "rendergraph/uniformset.h" +#include "util/assert.h" namespace rendergraph { class Material; @@ -17,7 +18,29 @@ class rendergraph::Material : public rendergraph::BaseMaterial { public: Material(const UniformSet& uniformSet); virtual ~Material(); - virtual int compare(const Material* other) const = 0; + + // see QSGMaterial::compare. + // TODO decide if this should be virtual. QSGMaterial::compare is virtual + // to concrete Material can implement a compare function, but in rendergraph + // we can compare the uniforms cache and texture already here, which seems + // sufficient. + int compare(const Material* pOther) const { + DEBUG_ASSERT(type() == pOther->type()); + int cacheCompareResult = std::memcmp(m_uniformsCache.data(), + pOther->m_uniformsCache.data(), + m_uniformsCache.size()); + if (cacheCompareResult != 0) { + return cacheCompareResult; + } + // TODO multiple textures + if (!texture(0) || !pOther->texture(0)) { + return texture(0) ? 1 : -1; + } + + const qint64 diff = texture(0)->comparisonKey() - pOther->texture(0)->comparisonKey(); + return diff < 0 ? -1 : (diff > 0 ? 1 : 0); + } + virtual std::unique_ptr createShader() const = 0; template @@ -38,7 +61,7 @@ class rendergraph::Material : public rendergraph::BaseMaterial { return false; } - virtual Texture* texture(int /*binding*/) const { + virtual Texture* texture(int) const { return nullptr; } diff --git a/src/rendergraph/common/rendergraph/material/endoftrackmaterial.cpp b/src/rendergraph/common/rendergraph/material/endoftrackmaterial.cpp index fd9e5f73ec7..ee35b465934 100644 --- a/src/rendergraph/common/rendergraph/material/endoftrackmaterial.cpp +++ b/src/rendergraph/common/rendergraph/material/endoftrackmaterial.cpp @@ -27,12 +27,6 @@ MaterialType* EndOfTrackMaterial::type() const { return &type; } -int EndOfTrackMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - std::unique_ptr EndOfTrackMaterial::createShader() const { return std::make_unique( "endoftrack.vert", "endoftrack.frag", uniforms(), attributes()); diff --git a/src/rendergraph/common/rendergraph/material/endoftrackmaterial.h b/src/rendergraph/common/rendergraph/material/endoftrackmaterial.h index e66a825c164..94c80693799 100644 --- a/src/rendergraph/common/rendergraph/material/endoftrackmaterial.h +++ b/src/rendergraph/common/rendergraph/material/endoftrackmaterial.h @@ -15,7 +15,5 @@ class rendergraph::EndOfTrackMaterial : public rendergraph::Material { MaterialType* type() const override; - int compare(const Material* other) const override; - std::unique_ptr createShader() const override; }; diff --git a/src/rendergraph/common/rendergraph/material/patternmaterial.cpp b/src/rendergraph/common/rendergraph/material/patternmaterial.cpp index e16ca4213d7..864f4a60adf 100644 --- a/src/rendergraph/common/rendergraph/material/patternmaterial.cpp +++ b/src/rendergraph/common/rendergraph/material/patternmaterial.cpp @@ -27,12 +27,6 @@ MaterialType* PatternMaterial::type() const { return &type; } -int PatternMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - std::unique_ptr PatternMaterial::createShader() const { return std::make_unique( "pattern.vert", "pattern.frag", uniforms(), attributes()); diff --git a/src/rendergraph/common/rendergraph/material/patternmaterial.h b/src/rendergraph/common/rendergraph/material/patternmaterial.h index 77127a6965d..661246abd05 100644 --- a/src/rendergraph/common/rendergraph/material/patternmaterial.h +++ b/src/rendergraph/common/rendergraph/material/patternmaterial.h @@ -17,8 +17,6 @@ class rendergraph::PatternMaterial : public rendergraph::Material { MaterialType* type() const override; - int compare(const Material* other) const override; - std::unique_ptr createShader() const override; Texture* texture(int) const override { diff --git a/src/rendergraph/common/rendergraph/material/rgbamaterial.cpp b/src/rendergraph/common/rendergraph/material/rgbamaterial.cpp index 3179549381c..e81382bf9ce 100644 --- a/src/rendergraph/common/rendergraph/material/rgbamaterial.cpp +++ b/src/rendergraph/common/rendergraph/material/rgbamaterial.cpp @@ -28,12 +28,6 @@ MaterialType* RGBAMaterial::type() const { return &type; } -int RGBAMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - std::unique_ptr RGBAMaterial::createShader() const { return std::make_unique( "rgba.vert", "rgba.frag", uniforms(), attributes()); diff --git a/src/rendergraph/common/rendergraph/material/rgbamaterial.h b/src/rendergraph/common/rendergraph/material/rgbamaterial.h index b5b72a949c9..0921ebb4fae 100644 --- a/src/rendergraph/common/rendergraph/material/rgbamaterial.h +++ b/src/rendergraph/common/rendergraph/material/rgbamaterial.h @@ -15,7 +15,5 @@ class rendergraph::RGBAMaterial : public rendergraph::Material { MaterialType* type() const override; - int compare(const Material* other) const override; - std::unique_ptr createShader() const override; }; diff --git a/src/rendergraph/common/rendergraph/material/rgbmaterial.cpp b/src/rendergraph/common/rendergraph/material/rgbmaterial.cpp index 3a2f014d07e..455555d1e97 100644 --- a/src/rendergraph/common/rendergraph/material/rgbmaterial.cpp +++ b/src/rendergraph/common/rendergraph/material/rgbmaterial.cpp @@ -27,12 +27,6 @@ MaterialType* RGBMaterial::type() const { return &type; } -int RGBMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - std::unique_ptr RGBMaterial::createShader() const { return std::make_unique( "rgb.vert", "rgb.frag", uniforms(), attributes()); diff --git a/src/rendergraph/common/rendergraph/material/rgbmaterial.h b/src/rendergraph/common/rendergraph/material/rgbmaterial.h index 6d4d74b2514..cfe1fde7782 100644 --- a/src/rendergraph/common/rendergraph/material/rgbmaterial.h +++ b/src/rendergraph/common/rendergraph/material/rgbmaterial.h @@ -15,7 +15,5 @@ class rendergraph::RGBMaterial : public rendergraph::Material { MaterialType* type() const override; - int compare(const Material* other) const override; - std::unique_ptr createShader() const override; }; diff --git a/src/rendergraph/common/rendergraph/material/texturematerial.cpp b/src/rendergraph/common/rendergraph/material/texturematerial.cpp index 090e6070d98..b3f61767626 100644 --- a/src/rendergraph/common/rendergraph/material/texturematerial.cpp +++ b/src/rendergraph/common/rendergraph/material/texturematerial.cpp @@ -27,12 +27,6 @@ MaterialType* TextureMaterial::type() const { return &type; } -int TextureMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - std::unique_ptr TextureMaterial::createShader() const { return std::make_unique( "texture.vert", "texture.frag", uniforms(), attributes()); diff --git a/src/rendergraph/common/rendergraph/material/texturematerial.h b/src/rendergraph/common/rendergraph/material/texturematerial.h index 4e0ac39b989..2fa5a2310cc 100644 --- a/src/rendergraph/common/rendergraph/material/texturematerial.h +++ b/src/rendergraph/common/rendergraph/material/texturematerial.h @@ -17,8 +17,6 @@ class rendergraph::TextureMaterial : public rendergraph::Material { MaterialType* type() const override; - int compare(const Material* other) const override; - std::unique_ptr createShader() const override; Texture* texture(int /*binding*/) const override { diff --git a/src/rendergraph/common/rendergraph/material/unicolormaterial.cpp b/src/rendergraph/common/rendergraph/material/unicolormaterial.cpp index 8e4bf12ed9c..d67fd16320c 100644 --- a/src/rendergraph/common/rendergraph/material/unicolormaterial.cpp +++ b/src/rendergraph/common/rendergraph/material/unicolormaterial.cpp @@ -27,12 +27,6 @@ MaterialType* UniColorMaterial::type() const { return &type; } -int UniColorMaterial::compare(const Material* other) const { - Q_ASSERT(other && type() == other->type()); - const auto* otherCasted = static_cast(other); - return otherCasted == this ? 0 : 1; -} - std::unique_ptr UniColorMaterial::createShader() const { return std::make_unique( "unicolor.vert", "unicolor.frag", uniforms(), attributes()); diff --git a/src/rendergraph/common/rendergraph/material/unicolormaterial.h b/src/rendergraph/common/rendergraph/material/unicolormaterial.h index 9516bb8c731..26225f4d3c6 100644 --- a/src/rendergraph/common/rendergraph/material/unicolormaterial.h +++ b/src/rendergraph/common/rendergraph/material/unicolormaterial.h @@ -15,7 +15,5 @@ class rendergraph::UniColorMaterial : public rendergraph::Material { MaterialType* type() const override; - int compare(const Material* other) const override; - std::unique_ptr createShader() const override; }; diff --git a/src/rendergraph/common/rendergraph/texture.h b/src/rendergraph/common/rendergraph/texture.h index ec6d65b37a9..8e095ca3120 100644 --- a/src/rendergraph/common/rendergraph/texture.h +++ b/src/rendergraph/common/rendergraph/texture.h @@ -4,9 +4,9 @@ #include #include "backend/basetexture.h" +#include "rendergraph/context.h" namespace rendergraph { -class Context; class Texture; } // namespace rendergraph @@ -18,6 +18,9 @@ class rendergraph::Texture { return m_pTexture.get(); } + // used by Material::compare + qint64 comparisonKey() const; + private: const std::unique_ptr m_pTexture{}; }; diff --git a/src/rendergraph/common/rendergraph/uniformscache.h b/src/rendergraph/common/rendergraph/uniformscache.h index f003fc30075..6fd01789c7a 100644 --- a/src/rendergraph/common/rendergraph/uniformscache.h +++ b/src/rendergraph/common/rendergraph/uniformscache.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "rendergraph/types.h" #include "rendergraph/uniformset.h" diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 0f8ebd06a15..fc63b20ae1f 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -68,4 +68,6 @@ target_link_libraries(rendergraph_gl PUBLIC Qt6::OpenGL ) -target_include_directories(rendergraph_gl PUBLIC . ../common) +target_include_directories(rendergraph_gl PUBLIC . ../common +../.. # needed for util/assert.h +) diff --git a/src/rendergraph/opengl/backend/basematerial.cpp b/src/rendergraph/opengl/backend/basematerial.cpp index 3ad056bae6c..ae6817ce878 100644 --- a/src/rendergraph/opengl/backend/basematerial.cpp +++ b/src/rendergraph/opengl/backend/basematerial.cpp @@ -1,5 +1,7 @@ #include "backend/basematerial.h" +#include "rendergraph/material.h" + using namespace rendergraph; void BaseMaterial::setShader(std::shared_ptr pShader) { @@ -25,3 +27,8 @@ void BaseMaterial::modifyShader() { bool BaseMaterial::isLastModifierOfShader() const { return this == m_pShader->lastModifiedByMaterial(); } + +int BaseMaterial::compare(const BaseMaterial* other) const { + auto pThis = static_cast(this); + return pThis->compare(static_cast(other)); +} diff --git a/src/rendergraph/opengl/backend/basematerial.h b/src/rendergraph/opengl/backend/basematerial.h index ccf135fea3d..c08b60daab2 100644 --- a/src/rendergraph/opengl/backend/basematerial.h +++ b/src/rendergraph/opengl/backend/basematerial.h @@ -14,6 +14,9 @@ class rendergraph::BaseMaterial { public: virtual MaterialType* type() const = 0; + // For parity with QSGMaterial, not used yet + int compare(const BaseMaterial* other) const; + void setShader(std::shared_ptr pShader); MaterialShader& shader() const; diff --git a/src/rendergraph/opengl/texture.cpp b/src/rendergraph/opengl/texture.cpp index 8851d927508..2ef65673e27 100644 --- a/src/rendergraph/opengl/texture.cpp +++ b/src/rendergraph/opengl/texture.cpp @@ -23,3 +23,7 @@ Texture::Texture(Context& context, const QImage& image) m_pTexture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); m_pTexture->setWrapMode(QOpenGLTexture::ClampToEdge); } + +qint64 Texture::comparisonKey() const { + return static_cast(m_pTexture->textureId()); +} diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 3fe8fd57bd9..efafb5d5590 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -61,4 +61,6 @@ target_link_libraries(rendergraph_sg PUBLIC Qt6::Quick ) -target_include_directories(rendergraph_sg PUBLIC . ../common) +target_include_directories(rendergraph_sg PUBLIC . ../common +../.. # needed for util/assert.h +) diff --git a/src/rendergraph/scenegraph/backend/basematerial.cpp b/src/rendergraph/scenegraph/backend/basematerial.cpp index 4199f165d88..e49606f8147 100644 --- a/src/rendergraph/scenegraph/backend/basematerial.cpp +++ b/src/rendergraph/scenegraph/backend/basematerial.cpp @@ -15,7 +15,7 @@ bool BaseMaterial::updateUniformsByteArray(QByteArray* buf) { int BaseMaterial::compare(const QSGMaterial* other) const { auto pThis = static_cast(this); - return pThis->compare(dynamic_cast(other)); + return pThis->compare(static_cast(other)); } QSGMaterialShader* BaseMaterial::createShader(QSGRendererInterface::RenderMode) const { diff --git a/src/rendergraph/scenegraph/texture.cpp b/src/rendergraph/scenegraph/texture.cpp index 773f08d3f96..87bb2c2b557 100644 --- a/src/rendergraph/scenegraph/texture.cpp +++ b/src/rendergraph/scenegraph/texture.cpp @@ -6,3 +6,7 @@ using namespace rendergraph; Texture::Texture(Context& context, const QImage& image) : m_pTexture(context.window()->createTextureFromImage(image)) { } + +qint64 Texture::comparisonKey() const { + return m_pTexture->comparisonKey(); +} From 86e5f0934509c2d61b4beb5113e9f4562cc6eb44 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 22 Sep 2024 21:43:21 +0200 Subject: [PATCH 28/64] added some DEBUG_ASSERTs and some vector.reserve calls --- .../common/rendergraph/uniformscache.cpp | 7 +++---- .../common/rendergraph/uniformscache.h | 16 +++++++++++----- .../opengl/backend/baseattributeset.cpp | 3 +++ .../scenegraph/backend/baseattributeset.cpp | 5 +++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/rendergraph/common/rendergraph/uniformscache.cpp b/src/rendergraph/common/rendergraph/uniformscache.cpp index 81005f3ffac..069469b0310 100644 --- a/src/rendergraph/common/rendergraph/uniformscache.cpp +++ b/src/rendergraph/common/rendergraph/uniformscache.cpp @@ -5,6 +5,7 @@ using namespace rendergraph; UniformsCache::UniformsCache(const UniformSet& uniformSet) { int offset = 0; + m_infos.reserve(uniformSet.uniforms().size()); for (const auto& uniform : uniformSet.uniforms()) { const int size = sizeOf(uniform.m_type); m_infos.push_back({uniform.m_type, offset}); @@ -16,12 +17,10 @@ UniformsCache::UniformsCache(const UniformSet& uniformSet) { UniformsCache::~UniformsCache() = default; -void UniformsCache::set(int uniformIndex, Type type, const void* ptr, int size) { - assert(type == m_infos[uniformIndex].m_type); +void UniformsCache::set(int uniformIndex, const void* ptr, int size) { memcpy(m_byteArray.data() + m_infos[uniformIndex].m_offset, ptr, size); } -void UniformsCache::get(int uniformIndex, Type type, void* ptr, int size) const { - assert(type == m_infos[uniformIndex].m_type); +void UniformsCache::get(int uniformIndex, void* ptr, int size) const { memcpy(ptr, m_byteArray.data() + m_infos[uniformIndex].m_offset, size); } diff --git a/src/rendergraph/common/rendergraph/uniformscache.h b/src/rendergraph/common/rendergraph/uniformscache.h index 6fd01789c7a..19cd71b74cb 100644 --- a/src/rendergraph/common/rendergraph/uniformscache.h +++ b/src/rendergraph/common/rendergraph/uniformscache.h @@ -8,6 +8,7 @@ #include "rendergraph/types.h" #include "rendergraph/uniformset.h" +#include "util/assert.h" namespace rendergraph { class UniformsCache; @@ -20,13 +21,17 @@ class rendergraph::UniformsCache { template void set(int uniformIndex, const T& value) { - set(uniformIndex, typeOf(), static_cast(&value), sizeOf(typeOf())); + DEBUG_ASSERT(type(uniformIndex) == typeOf()); + DEBUG_ASSERT(std::is_trivially_copyable()); + set(uniformIndex, static_cast(&value), sizeOf(typeOf())); } template T get(int uniformIndex) const { + DEBUG_ASSERT(type(uniformIndex) == typeOf()); + DEBUG_ASSERT(std::is_trivially_copyable()); T value; - get(uniformIndex, typeOf(), static_cast(&value), sizeof(T)); + get(uniformIndex, static_cast(&value), sizeof(T)); return value; } Type type(int uniformIndex) const { @@ -44,8 +49,8 @@ class rendergraph::UniformsCache { } private: - void set(int uniformIndex, Type type, const void* ptr, int size); - void get(int uniformIndex, Type type, void* ptr, int size) const; + void set(int uniformIndex, const void* ptr, int size); + void get(int uniformIndex, void* ptr, int size) const; struct Info { const Type m_type; @@ -64,5 +69,6 @@ inline void rendergraph::UniformsCache::set(int uniformIndex, const QCol template<> inline void rendergraph::UniformsCache::set( int uniformIndex, const QMatrix4x4& matrix) { - set(uniformIndex, typeOf(), matrix.constData(), sizeOf(typeOf())); + DEBUG_ASSERT(type(uniformIndex) == typeOf()); + set(uniformIndex, matrix.constData(), sizeOf(typeOf())); } diff --git a/src/rendergraph/opengl/backend/baseattributeset.cpp b/src/rendergraph/opengl/backend/baseattributeset.cpp index ce499f02774..10f16158076 100644 --- a/src/rendergraph/opengl/backend/baseattributeset.cpp +++ b/src/rendergraph/opengl/backend/baseattributeset.cpp @@ -1,10 +1,13 @@ #include "rendergraph/attributeset.h" +#include "util/assert.h" using namespace rendergraph; BaseAttributeSet::BaseAttributeSet(std::initializer_list list, const std::vector& names) { + DEBUG_ASSERT(list.size() == names.size()); int i = 0; + m_attributes.reserve(list.size()); for (auto item : list) { m_attributes.push_back(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); } diff --git a/src/rendergraph/scenegraph/backend/baseattributeset.cpp b/src/rendergraph/scenegraph/backend/baseattributeset.cpp index b288da72e77..d2c7cffa35c 100644 --- a/src/rendergraph/scenegraph/backend/baseattributeset.cpp +++ b/src/rendergraph/scenegraph/backend/baseattributeset.cpp @@ -1,5 +1,7 @@ #include "backend/baseattributeset.h" +#include "util/assert.h" + using namespace rendergraph; namespace { @@ -16,6 +18,9 @@ int toQSGGeometryType(const PrimitiveType& t) { BaseAttributeSetHelper::BaseAttributeSetHelper(std::initializer_list list, const std::vector& names) { int i = 0; + DEBUG_ASSERT(list.size() == names.size()); + m_attributes.reserve(list.size()); + m_sgAttributes.reserve(list.size()); for (auto item : list) { m_attributes.push_back(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); From bc32a9cfeba4f9563843b038327f55139c1dce42 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 22 Sep 2024 21:50:24 +0200 Subject: [PATCH 29/64] use string literal --- src/rendergraph/opengl/backend/basematerialshader.h | 2 +- src/rendergraph/scenegraph/backend/basematerialshader.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rendergraph/opengl/backend/basematerialshader.h b/src/rendergraph/opengl/backend/basematerialshader.h index 76527ee8269..04da60944ee 100644 --- a/src/rendergraph/opengl/backend/basematerialshader.h +++ b/src/rendergraph/opengl/backend/basematerialshader.h @@ -20,7 +20,7 @@ class rendergraph::BaseMaterialShader : public QOpenGLShaderProgram { void setLastModifiedByMaterial(BaseMaterial* pMaterial); static QString resource(const QString& filename) { - return QString(":/shaders/rendergraph/%1.gl").arg(filename); + return QStringLiteral(":/shaders/rendergraph/%1.gl").arg(filename); } std::vector m_attributeLocations; std::vector m_uniformLocations; diff --git a/src/rendergraph/scenegraph/backend/basematerialshader.h b/src/rendergraph/scenegraph/backend/basematerialshader.h index 9b6a9773377..c790ccd6425 100644 --- a/src/rendergraph/scenegraph/backend/basematerialshader.h +++ b/src/rendergraph/scenegraph/backend/basematerialshader.h @@ -23,6 +23,6 @@ class rendergraph::BaseMaterialShader : public QSGMaterialShader { QSGMaterial* oldMaterial) override; static QString resource(const QString& filename) { - return QString(":/shaders/rendergraph/%1.qsb").arg(filename); + return QStringLiteral(":/shaders/rendergraph/%1.qsb").arg(filename); } }; From eeae3ea0a36f47e257baba2d30dab15688939926 Mon Sep 17 00:00:00 2001 From: m0dB Date: Mon, 23 Sep 2024 01:36:19 +0200 Subject: [PATCH 30/64] use qshader to load qsb files for opengl Qt >= 6.6 --- res/shaders/rendergraph/CMakeLists.txt | 30 ++++++++---- src/rendergraph/CMakeLists.txt | 7 +++ .../examples/gl_example/CMakeLists.txt | 5 -- src/rendergraph/opengl/CMakeLists.txt | 11 +++-- .../opengl/backend/basematerialshader.h | 3 -- src/rendergraph/opengl/materialshader.cpp | 46 +++++++++++++++++-- .../scenegraph/backend/basematerialshader.h | 3 -- src/rendergraph/scenegraph/materialshader.cpp | 6 +++ 8 files changed, 85 insertions(+), 26 deletions(-) diff --git a/res/shaders/rendergraph/CMakeLists.txt b/res/shaders/rendergraph/CMakeLists.txt index 3241c5a84c9..dfcecc593a4 100644 --- a/res/shaders/rendergraph/CMakeLists.txt +++ b/res/shaders/rendergraph/CMakeLists.txt @@ -13,7 +13,7 @@ set(shaders unicolor.vert ) -qt6_add_shaders(rendergraph_sg "shaders-sg" +qt6_add_shaders(rendergraph_sg "shaders-qsb" BATCHABLE PRECOMPILE OPTIMIZED @@ -23,11 +23,25 @@ qt6_add_shaders(rendergraph_sg "shaders-sg" ${shaders} ) -include(generated_shaders_gl.cmake) +if(USE_QSHADER_FOR_GL) + message(STATUS "Adding qsb shaders to rendergraph_gl") + qt6_add_shaders(rendergraph_gl "shaders-qsb" + BATCHABLE + PRECOMPILE + OPTIMIZED + PREFIX + /shaders/rendergraph + FILES + ${shaders} + ) +else() + message(STATUS "Adding gl shaders to rendergraph_gl") + include(generated_shaders_gl.cmake) -qt_add_resources(rendergraph_gl "shaders-gl" - PREFIX - /shaders/rendergraph - FILES - ${generated_shaders_gl} -) + qt_add_resources(rendergraph_gl "shaders-gl" + PREFIX + /shaders/rendergraph + FILES + ${generated_shaders_gl} + ) +endif() diff --git a/src/rendergraph/CMakeLists.txt b/src/rendergraph/CMakeLists.txt index 91bcb99beb5..059bbdaa050 100644 --- a/src/rendergraph/CMakeLists.txt +++ b/src/rendergraph/CMakeLists.txt @@ -1,3 +1,10 @@ +find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core) +message(STATUS "Qt version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}") + +if (QT_VERSION_MINOR GREATER_EQUAL 6) +set(USE_QSHADER_FOR_GL ON) +endif() + add_subdirectory(opengl) add_subdirectory(scenegraph) add_subdirectory(../../res/shaders/rendergraph shaders) diff --git a/src/rendergraph/examples/gl_example/CMakeLists.txt b/src/rendergraph/examples/gl_example/CMakeLists.txt index 6a055ea5560..0d28d7a7d7d 100644 --- a/src/rendergraph/examples/gl_example/CMakeLists.txt +++ b/src/rendergraph/examples/gl_example/CMakeLists.txt @@ -1,5 +1,3 @@ -find_package(Qt6 REQUIRED COMPONENTS Core Gui OpenGL) - qt_add_executable(gl_example window.cpp window.h main.cpp @@ -13,9 +11,6 @@ set_target_properties(gl_example PROPERTIES target_link_libraries(gl_example PRIVATE rendergraph_gl - Qt6::Core - Qt6::Gui - Qt6::OpenGL ) target_include_directories(gl_example PRIVATE ../common) diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index fc63b20ae1f..968b690e3da 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -68,6 +68,11 @@ target_link_libraries(rendergraph_gl PUBLIC Qt6::OpenGL ) -target_include_directories(rendergraph_gl PUBLIC . ../common -../.. # needed for util/assert.h -) +# USE_QSHADER_FOR_GL is set in rendergraph/CMakeLists.txt +if(USE_QSHADER_FOR_GL) + message(STATUS "Using QShader to load qsb shaders for opengl") + target_link_libraries(rendergraph_gl PUBLIC Qt6::GuiPrivate) + target_compile_definitions(rendergraph_gl PRIVATE USE_QSHADER_FOR_GL) +endif() + +target_include_directories(rendergraph_gl PUBLIC . ../common) diff --git a/src/rendergraph/opengl/backend/basematerialshader.h b/src/rendergraph/opengl/backend/basematerialshader.h index 04da60944ee..f7082c15ef0 100644 --- a/src/rendergraph/opengl/backend/basematerialshader.h +++ b/src/rendergraph/opengl/backend/basematerialshader.h @@ -19,9 +19,6 @@ class rendergraph::BaseMaterialShader : public QOpenGLShaderProgram { BaseMaterial* lastModifiedByMaterial() const; void setLastModifiedByMaterial(BaseMaterial* pMaterial); - static QString resource(const QString& filename) { - return QStringLiteral(":/shaders/rendergraph/%1.gl").arg(filename); - } std::vector m_attributeLocations; std::vector m_uniformLocations; BaseMaterial* m_pLastModifiedByMaterial{}; diff --git a/src/rendergraph/opengl/materialshader.cpp b/src/rendergraph/opengl/materialshader.cpp index 40a15f4e177..e8fd233a21d 100644 --- a/src/rendergraph/opengl/materialshader.cpp +++ b/src/rendergraph/opengl/materialshader.cpp @@ -1,14 +1,52 @@ #include "rendergraph/materialshader.h" +#include +#ifdef USE_QSHADER_FOR_GL +#include +#endif + using namespace rendergraph; -MaterialShader::MaterialShader(const char* vertexShaderFile, - const char* fragmentShaderFile, +namespace { +#ifdef USE_QSHADER_FOR_GL +QString resource(const QString& filename) { + return QStringLiteral(":/shaders/rendergraph/%1.qsb").arg(filename); +} + +QByteArray loadShaderCodeFromFile(const QString& path) { + QFile file(path); + file.open(QIODeviceBase::ReadOnly); + QShader qsbShader = QShader::fromSerialized(file.readAll()); + QShaderKey key(QShader::GlslShader, 120); + return qsbShader.shader(key).shader(); +} +#else +QString resource(const QString& filename) { + return QStringLiteral(":/shaders/rendergraph/%1.gl").arg(filename); +} + +QByteArray loadShaderCodeFromFile(const QString& path) { + QFile file(path); + file.open(QIODeviceBase::ReadOnly); + return file.readAll(); +} +#endif +} // namespace + +MaterialShader::MaterialShader(const char* vertexShaderFilename, + const char* fragmentShaderFilename, const UniformSet& uniformSet, const AttributeSet& attributeSet) { - addShaderFromSourceFile(QOpenGLShader::Vertex, resource(vertexShaderFile)); - addShaderFromSourceFile(QOpenGLShader::Fragment, resource(fragmentShaderFile)); + const QString vertexShaderFileFullPath = resource(vertexShaderFilename); + const QString fragmentShaderFileFullPath = resource(fragmentShaderFilename); + + addShaderFromSourceCode(QOpenGLShader::Vertex, + loadShaderCodeFromFile(vertexShaderFileFullPath)); + addShaderFromSourceCode(QOpenGLShader::Fragment, + loadShaderCodeFromFile(fragmentShaderFileFullPath)); + link(); + for (const auto& attribute : attributeSet.attributes()) { int location = QOpenGLShaderProgram::attributeLocation(attribute.m_name); m_attributeLocations.push_back(location); diff --git a/src/rendergraph/scenegraph/backend/basematerialshader.h b/src/rendergraph/scenegraph/backend/basematerialshader.h index c790ccd6425..e9c0ef40d3f 100644 --- a/src/rendergraph/scenegraph/backend/basematerialshader.h +++ b/src/rendergraph/scenegraph/backend/basematerialshader.h @@ -22,7 +22,4 @@ class rendergraph::BaseMaterialShader : public QSGMaterialShader { QSGMaterial* newMaterial, QSGMaterial* oldMaterial) override; - static QString resource(const QString& filename) { - return QStringLiteral(":/shaders/rendergraph/%1.qsb").arg(filename); - } }; diff --git a/src/rendergraph/scenegraph/materialshader.cpp b/src/rendergraph/scenegraph/materialshader.cpp index 9bba8e37c82..3a34c80274d 100644 --- a/src/rendergraph/scenegraph/materialshader.cpp +++ b/src/rendergraph/scenegraph/materialshader.cpp @@ -2,6 +2,12 @@ using namespace rendergraph; +namespace { +static QString resource(const QString& filename) { + return QStringLiteral(":/shaders/rendergraph/%1.qsb").arg(filename); +} +} // namespace + MaterialShader::MaterialShader(const char* vertexShaderFile, const char* fragmentShaderFile, const UniformSet& uniformSet, From 0a691ad92666b05e4d8abafe8934acd05d14e979 Mon Sep 17 00:00:00 2001 From: m0dB Date: Mon, 23 Sep 2024 01:37:01 +0200 Subject: [PATCH 31/64] avoid adding entire src dir to include paths --- src/rendergraph/common/rendergraph/assert.h | 1 + src/rendergraph/common/rendergraph/material.h | 2 +- src/rendergraph/common/rendergraph/uniformscache.h | 2 +- src/rendergraph/opengl/backend/baseattributeset.cpp | 2 +- src/rendergraph/scenegraph/CMakeLists.txt | 4 +--- src/rendergraph/scenegraph/backend/baseattributeset.cpp | 2 +- 6 files changed, 6 insertions(+), 7 deletions(-) create mode 100644 src/rendergraph/common/rendergraph/assert.h diff --git a/src/rendergraph/common/rendergraph/assert.h b/src/rendergraph/common/rendergraph/assert.h new file mode 100644 index 00000000000..431ddbd12d7 --- /dev/null +++ b/src/rendergraph/common/rendergraph/assert.h @@ -0,0 +1 @@ +#include "../../../util/assert.h" diff --git a/src/rendergraph/common/rendergraph/material.h b/src/rendergraph/common/rendergraph/material.h index 98e9e571d65..e15ef5c0f1c 100644 --- a/src/rendergraph/common/rendergraph/material.h +++ b/src/rendergraph/common/rendergraph/material.h @@ -3,12 +3,12 @@ #include #include "backend/basematerial.h" +#include "rendergraph/assert.h" #include "rendergraph/materialshader.h" #include "rendergraph/materialtype.h" #include "rendergraph/texture.h" #include "rendergraph/uniformscache.h" #include "rendergraph/uniformset.h" -#include "util/assert.h" namespace rendergraph { class Material; diff --git a/src/rendergraph/common/rendergraph/uniformscache.h b/src/rendergraph/common/rendergraph/uniformscache.h index 19cd71b74cb..c391070aa24 100644 --- a/src/rendergraph/common/rendergraph/uniformscache.h +++ b/src/rendergraph/common/rendergraph/uniformscache.h @@ -6,9 +6,9 @@ #include #include +#include "rendergraph/assert.h" #include "rendergraph/types.h" #include "rendergraph/uniformset.h" -#include "util/assert.h" namespace rendergraph { class UniformsCache; diff --git a/src/rendergraph/opengl/backend/baseattributeset.cpp b/src/rendergraph/opengl/backend/baseattributeset.cpp index 10f16158076..9ddec230676 100644 --- a/src/rendergraph/opengl/backend/baseattributeset.cpp +++ b/src/rendergraph/opengl/backend/baseattributeset.cpp @@ -1,5 +1,5 @@ +#include "rendergraph/assert.h" #include "rendergraph/attributeset.h" -#include "util/assert.h" using namespace rendergraph; diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index efafb5d5590..3fe8fd57bd9 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -61,6 +61,4 @@ target_link_libraries(rendergraph_sg PUBLIC Qt6::Quick ) -target_include_directories(rendergraph_sg PUBLIC . ../common -../.. # needed for util/assert.h -) +target_include_directories(rendergraph_sg PUBLIC . ../common) diff --git a/src/rendergraph/scenegraph/backend/baseattributeset.cpp b/src/rendergraph/scenegraph/backend/baseattributeset.cpp index d2c7cffa35c..23c173285db 100644 --- a/src/rendergraph/scenegraph/backend/baseattributeset.cpp +++ b/src/rendergraph/scenegraph/backend/baseattributeset.cpp @@ -1,6 +1,6 @@ #include "backend/baseattributeset.h" -#include "util/assert.h" +#include "rendergraph/assert.h" using namespace rendergraph; From 9c607c1b00826ad652e0100a83ae9cbecaab2c6b Mon Sep 17 00:00:00 2001 From: m0dB Date: Mon, 23 Sep 2024 01:44:47 +0200 Subject: [PATCH 32/64] updated READMEs --- res/shaders/rendergraph/README | 7 ++++--- src/rendergraph/README | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/res/shaders/rendergraph/README b/res/shaders/rendergraph/README index 04bb5086e24..644c2ce7647 100644 --- a/res/shaders/rendergraph/README +++ b/res/shaders/rendergraph/README @@ -1,9 +1,10 @@ -Generate the GLSL shaders from the spirv shaders by running +The CMakeLists.txt in this folder generates qsb shader bundles from the spirv shaders. + +The qsb files can be used by QML / Qt scene graph QSGShader. Since Qt >= 6.6 we can load the qsb files and extract the glsl shaders +programmatically with QShader and use the with QOpenGLShader. For Qt < 6.6 the files have to generated manually with the script: generate_shaders_gl.pl (Make sure qsb and spirv commands are in your path. E.g: export PATH=$PATH:~/VulkanSDK/1.3.283.0/macOS/bin:~/Qt/6.7.2/macos/bin ) - -Since Qt 6.6 we should be able to access this programmatically with QShader, but for now I do it manually diff --git a/src/rendergraph/README b/src/rendergraph/README index 88066b195dd..8b1720e22c8 100644 --- a/src/rendergraph/README +++ b/src/rendergraph/README @@ -53,6 +53,10 @@ examples/gl_example examples/common The graphics code that is identical for both example +../../res/shaders/rendergraph/ + The qsb and (generated) gl shader files + See ../../res/shaders/rendergraph/README for more info + More advanced use of rendergraph can be found in the waveform/renderers/allshader classes, which have partially been ported the rendergraph. From 2f8e54856a9765cd49049233fe26479899170df6 Mon Sep 17 00:00:00 2001 From: m0dB Date: Mon, 23 Sep 2024 15:23:08 +0200 Subject: [PATCH 33/64] improved/added asserts --- src/rendergraph/common/rendergraph/uniformscache.h | 2 +- src/rendergraph/examples/CMakeLists.txt | 8 ++++++++ src/rendergraph/opengl/geometry.cpp | 13 +++++++++++-- src/rendergraph/scenegraph/geometry.cpp | 10 +++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/rendergraph/common/rendergraph/uniformscache.h b/src/rendergraph/common/rendergraph/uniformscache.h index c391070aa24..045887f0c37 100644 --- a/src/rendergraph/common/rendergraph/uniformscache.h +++ b/src/rendergraph/common/rendergraph/uniformscache.h @@ -69,6 +69,6 @@ inline void rendergraph::UniformsCache::set(int uniformIndex, const QCol template<> inline void rendergraph::UniformsCache::set( int uniformIndex, const QMatrix4x4& matrix) { - DEBUG_ASSERT(type(uniformIndex) == typeOf()); + DEBUG_ASSERT(type(uniformIndex) == typeOf()); set(uniformIndex, matrix.constData(), sizeOf(typeOf())); } diff --git a/src/rendergraph/examples/CMakeLists.txt b/src/rendergraph/examples/CMakeLists.txt index 61ba086297f..b826c663aa4 100644 --- a/src/rendergraph/examples/CMakeLists.txt +++ b/src/rendergraph/examples/CMakeLists.txt @@ -6,5 +6,13 @@ find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick ShaderTools) qt_standard_project_setup() add_subdirectory(../ rendergraph) + +target_compile_definitions(rendergraph_gl PUBLIC + $<$:MIXXX_DEBUG_ASSERTIONS_ENABLED> +) +target_compile_definitions(rendergraph_sg PUBLIC + $<$:MIXXX_DEBUG_ASSERTIONS_ENABLED> +) + add_subdirectory(gl_example) add_subdirectory(sg_example) diff --git a/src/rendergraph/opengl/geometry.cpp b/src/rendergraph/opengl/geometry.cpp index a45b325a152..0c4c7434ed6 100644 --- a/src/rendergraph/opengl/geometry.cpp +++ b/src/rendergraph/opengl/geometry.cpp @@ -1,5 +1,6 @@ #include "rendergraph/geometry.h" +#include "rendergraph/assert.h" #include "rendergraph/attributeset.h" using namespace rendergraph; @@ -13,10 +14,17 @@ Geometry::~Geometry() = default; void Geometry::setAttributeValues(int attributePosition, const float* from, int numTuples) { const int offset = m_offsets[attributePosition]; const int tupleSize = m_tupleSizes[attributePosition]; - const int skip = m_stride / sizeof(float) - tupleSize; + const int strideNumberOfFloats = m_stride / sizeof(float); + const int skip = strideNumberOfFloats - tupleSize; + + VERIFY_OR_DEBUG_ASSERT(offset + numTuples * strideNumberOfFloats - skip <= + static_cast(m_data.size())) { + return; + } float* to = m_data.data(); to += offset; + while (numTuples--) { int k = tupleSize; while (k--) { @@ -31,8 +39,9 @@ float* Geometry::vertexData() { } void Geometry::allocate(int vertexCount) { + const int strideNumberOfFloats = m_stride / sizeof(float); m_vertexCount = vertexCount; - m_data.resize((m_stride / sizeof(float)) * m_vertexCount); + m_data.resize(strideNumberOfFloats * m_vertexCount); } void Geometry::setDrawingMode(Geometry::DrawingMode mode) { diff --git a/src/rendergraph/scenegraph/geometry.cpp b/src/rendergraph/scenegraph/geometry.cpp index 6af25958564..6fff53e3789 100644 --- a/src/rendergraph/scenegraph/geometry.cpp +++ b/src/rendergraph/scenegraph/geometry.cpp @@ -1,5 +1,7 @@ #include "rendergraph/geometry.h" +#include "rendergraph/assert.h" + using namespace rendergraph; namespace { @@ -37,7 +39,13 @@ void Geometry::setAttributeValues(int attributePosition, const float* from, int offset += attributeArray[i].tupleSize; } const int tupleSize = attributeArray[attributePosition].tupleSize; - const int skip = m_stride / sizeof(float) - tupleSize; + const int strideNumberOfFloats = m_stride / sizeof(float); + const int skip = strideNumberOfFloats - tupleSize; + + VERIFY_OR_DEBUG_ASSERT(offset + numTuples * strideNumberOfFloats - skip <= + vertexCount() * strideNumberOfFloats) { + return; + } float* to = static_cast(QSGGeometry::vertexData()); to += offset; From c6cdb344a293e69454a445745ce428d7337e5eb7 Mon Sep 17 00:00:00 2001 From: m0dB Date: Mon, 23 Sep 2024 15:38:05 +0200 Subject: [PATCH 34/64] moved opengl node as baseclass for waveform renderers to derived class, so i can start porting some to geometrynode --- src/waveform/renderers/allshader/waveformrendererfiltered.h | 4 +++- src/waveform/renderers/allshader/waveformrendererhsv.h | 4 +++- src/waveform/renderers/allshader/waveformrendererrgb.h | 4 +++- .../renderers/allshader/waveformrenderersignalbase.h | 3 +-- src/waveform/renderers/allshader/waveformrenderersimple.h | 4 +++- src/waveform/renderers/allshader/waveformrendererstem.h | 4 +++- src/waveform/renderers/allshader/waveformrenderertextured.h | 3 ++- src/waveform/widgets/allshader/waveformwidget.cpp | 6 +++--- 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/waveform/renderers/allshader/waveformrendererfiltered.h b/src/waveform/renderers/allshader/waveformrendererfiltered.h index 158ff880c01..fcef9e634dc 100644 --- a/src/waveform/renderers/allshader/waveformrendererfiltered.h +++ b/src/waveform/renderers/allshader/waveformrendererfiltered.h @@ -9,7 +9,9 @@ namespace allshader { class WaveformRendererFiltered; } -class allshader::WaveformRendererFiltered final : public allshader::WaveformRendererSignalBase { +class allshader::WaveformRendererFiltered final + : public allshader::WaveformRendererSignalBase, + public rendergraph::OpenGLNode { public: explicit WaveformRendererFiltered(WaveformWidgetRenderer* waveformWidget, bool rgbStacked); diff --git a/src/waveform/renderers/allshader/waveformrendererhsv.h b/src/waveform/renderers/allshader/waveformrendererhsv.h index 0fa0b6bf863..fd7d8d10f15 100644 --- a/src/waveform/renderers/allshader/waveformrendererhsv.h +++ b/src/waveform/renderers/allshader/waveformrendererhsv.h @@ -10,7 +10,9 @@ namespace allshader { class WaveformRendererHSV; } -class allshader::WaveformRendererHSV final : public allshader::WaveformRendererSignalBase { +class allshader::WaveformRendererHSV final + : public allshader::WaveformRendererSignalBase, + public rendergraph::OpenGLNode { public: explicit WaveformRendererHSV(WaveformWidgetRenderer* waveformWidget); diff --git a/src/waveform/renderers/allshader/waveformrendererrgb.h b/src/waveform/renderers/allshader/waveformrendererrgb.h index e9c12b52a42..4ef93a88617 100644 --- a/src/waveform/renderers/allshader/waveformrendererrgb.h +++ b/src/waveform/renderers/allshader/waveformrendererrgb.h @@ -10,7 +10,9 @@ namespace allshader { class WaveformRendererRGB; } -class allshader::WaveformRendererRGB final : public allshader::WaveformRendererSignalBase { +class allshader::WaveformRendererRGB final + : public allshader::WaveformRendererSignalBase, + public rendergraph::OpenGLNode { public: explicit WaveformRendererRGB(WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type = diff --git a/src/waveform/renderers/allshader/waveformrenderersignalbase.h b/src/waveform/renderers/allshader/waveformrenderersignalbase.h index b09b528111a..b36639486f4 100644 --- a/src/waveform/renderers/allshader/waveformrenderersignalbase.h +++ b/src/waveform/renderers/allshader/waveformrenderersignalbase.h @@ -13,8 +13,7 @@ namespace allshader { class WaveformRendererSignalBase; } -class allshader::WaveformRendererSignalBase : public ::WaveformRendererSignalBase, - public rendergraph::OpenGLNode { +class allshader::WaveformRendererSignalBase : public ::WaveformRendererSignalBase { public: enum class Option { None = 0b0, diff --git a/src/waveform/renderers/allshader/waveformrenderersimple.h b/src/waveform/renderers/allshader/waveformrenderersimple.h index a1e92c8d2f0..7b0aee5c7b1 100644 --- a/src/waveform/renderers/allshader/waveformrenderersimple.h +++ b/src/waveform/renderers/allshader/waveformrenderersimple.h @@ -9,7 +9,9 @@ namespace allshader { class WaveformRendererSimple; } -class allshader::WaveformRendererSimple final : public allshader::WaveformRendererSignalBase { +class allshader::WaveformRendererSimple final + : public allshader::WaveformRendererSignalBase, + public rendergraph::OpenGLNode { public: explicit WaveformRendererSimple(WaveformWidgetRenderer* waveformWidget); diff --git a/src/waveform/renderers/allshader/waveformrendererstem.h b/src/waveform/renderers/allshader/waveformrendererstem.h index 757bfe763d3..fc678ce4fa1 100644 --- a/src/waveform/renderers/allshader/waveformrendererstem.h +++ b/src/waveform/renderers/allshader/waveformrendererstem.h @@ -15,7 +15,9 @@ namespace allshader { class WaveformRendererStem; } -class allshader::WaveformRendererStem final : public allshader::WaveformRendererSignalBase { +class allshader::WaveformRendererStem final + : public allshader::WaveformRendererSignalBase, + public rendergraph::OpenGLNode { public: explicit WaveformRendererStem(WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type = diff --git a/src/waveform/renderers/allshader/waveformrenderertextured.h b/src/waveform/renderers/allshader/waveformrenderertextured.h index 16680f1bc5d..d88a37e65be 100644 --- a/src/waveform/renderers/allshader/waveformrenderertextured.h +++ b/src/waveform/renderers/allshader/waveformrenderertextured.h @@ -20,7 +20,8 @@ class WaveformRendererTextured; // Based on GLSLWaveformRendererSignal (waveform/renderers/glslwaveformrenderersignal.h) class allshader::WaveformRendererTextured : public QObject, - public allshader::WaveformRendererSignalBase { + public allshader::WaveformRendererSignalBase, + public rendergraph::OpenGLNode { Q_OBJECT public: explicit WaveformRendererTextured(WaveformWidgetRenderer* waveformWidget, diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index 0690e37ae07..37ffba98cdc 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -55,7 +55,7 @@ WaveformWidget::WaveformWidget(QWidget* parent, allshader::WaveformRendererSignalBase* waveformSignalRenderer = addWaveformSignalRenderer( type, options, ::WaveformRendererAbstract::Play); - appendChildTo(pOpacityNode, waveformSignalRenderer); + appendChildTo(pOpacityNode, dynamic_cast(waveformSignalRenderer)); appendChildTo(pOpacityNode, addRenderer()); m_pWaveformRenderMark = addRenderer(); @@ -75,8 +75,8 @@ WaveformWidget::WaveformWidget(QWidget* parent, ::WaveformRendererAbstract::Slip)); #endif appendChildTo(pOpacityNode, - addWaveformSignalRenderer( - type, options, ::WaveformRendererAbstract::Slip)); + dynamic_cast(addWaveformSignalRenderer( + type, options, ::WaveformRendererAbstract::Slip))); appendChildTo(pOpacityNode, addRenderer( ::WaveformRendererAbstract::Slip)); From 92cd7535d99e2a9646f2cbf2ea31d359d8e781ff Mon Sep 17 00:00:00 2001 From: m0dB Date: Mon, 23 Sep 2024 16:22:57 +0200 Subject: [PATCH 35/64] fix typo --- .../renderers/allshader/rgbvertexupdater.h | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/waveform/renderers/allshader/rgbvertexupdater.h b/src/waveform/renderers/allshader/rgbvertexupdater.h index 580883cb6e1..e85f525a5ed 100644 --- a/src/waveform/renderers/allshader/rgbvertexupdater.h +++ b/src/waveform/renderers/allshader/rgbvertexupdater.h @@ -16,14 +16,14 @@ class rendergraph::RGBVertexUpdater { void addRectangle( QVector2D lt, QVector2D rb, - QVector4D rgb) { - addRectangle(lt.x(), lt.y(), rb.x(), rb.y(), rgb.x(), rgb.y(), rgb.z(), rgb.w()); + QVector3D rgb) { + addRectangle(lt.x(), lt.y(), rb.x(), rb.y(), rgb.x(), rgb.y(), rgb.z()); } void addRectangleVGradient( QVector2D lt, QVector2D rb, - QVector4D rgbt, - QVector4D rgbb) { + QVector3D rgbt, + QVector3D rgbb) { addRectangleVGradient(lt.x(), lt.y(), rb.x(), @@ -38,8 +38,8 @@ class rendergraph::RGBVertexUpdater { void addRectangleHGradient( QVector2D lt, QVector2D rb, - QVector4D rgbl, - QVector4D rgbr) { + QVector3D rgbl, + QVector3D rgbr) { addRectangleHGradient(lt.x(), lt.y(), rb.x(), @@ -52,8 +52,8 @@ class rendergraph::RGBVertexUpdater { rgbr.z()); } void addRectangle(float x1, float y1, float x2, float y2, float r, float g, float b) { - addTriangle(x1, y1, x2, y1, x1, y2, r, g, b, a); - addTriangle(x1, y2, x2, y2, x2, y1, r, g, b, a); + addTriangle(x1, y1, x2, y1, x1, y2, r, g, b); + addTriangle(x1, y2, x2, y2, x2, y1, r, g, b); } void addRectangleVGradient( float x1, @@ -79,7 +79,7 @@ class rendergraph::RGBVertexUpdater { float b1, float r2, float g2, - floar b2) { + float b2) { addTriangle(x1, y1, x2, y1, x1, y2, r1, g1, b1, r2, g2, b2, r1, g1, b1); addTriangle(x1, y2, x2, y2, x2, y1, r1, g1, b1, r2, g2, b2, r2, g2, b2); } @@ -112,9 +112,7 @@ class rendergraph::RGBVertexUpdater { float r3, float g3, - float b3, - - ) { + float b3) { *m_pWrite++ = Geometry::RGBColoredPoint2D{x1, y1, r1, g1, b1}; *m_pWrite++ = Geometry::RGBColoredPoint2D{x2, y2, r2, g2, b2}; *m_pWrite++ = Geometry::RGBColoredPoint2D{x3, y3, r3, g3, b3}; From 8e5128f2f0a4cbe64c554242fc10c029490d5580 Mon Sep 17 00:00:00 2001 From: m0dB Date: Mon, 23 Sep 2024 16:24:18 +0200 Subject: [PATCH 36/64] moved rendergraph::OpenGLNode to derived --- src/waveform/renderers/allshader/waveformrenderbackground.h | 5 ++++- src/waveform/renderers/allshader/waveformrenderer.h | 4 +--- src/waveform/renderers/allshader/waveformrendererfiltered.h | 1 + src/waveform/renderers/allshader/waveformrendererhsv.h | 1 + .../renderers/allshader/waveformrenderersignalbase.h | 1 - src/waveform/renderers/allshader/waveformrenderersimple.h | 1 + src/waveform/renderers/allshader/waveformrendererslipmode.h | 5 ++++- src/waveform/renderers/allshader/waveformrendererstem.h | 1 + src/waveform/renderers/allshader/waveformrenderertextured.h | 1 + 9 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/waveform/renderers/allshader/waveformrenderbackground.h b/src/waveform/renderers/allshader/waveformrenderbackground.h index 8a913e27742..97c82c7d122 100644 --- a/src/waveform/renderers/allshader/waveformrenderbackground.h +++ b/src/waveform/renderers/allshader/waveformrenderbackground.h @@ -2,6 +2,7 @@ #include +#include "rendergraph/openglnode.h" #include "util/class.h" #include "waveform/renderers/allshader/waveformrenderer.h" @@ -9,7 +10,9 @@ namespace allshader { class WaveformRenderBackground; } -class allshader::WaveformRenderBackground final : public allshader::WaveformRenderer { +class allshader::WaveformRenderBackground final + : public allshader::WaveformRenderer, + public rendergraph::OpenGLNode { public: explicit WaveformRenderBackground(WaveformWidgetRenderer* waveformWidgetRenderer); diff --git a/src/waveform/renderers/allshader/waveformrenderer.h b/src/waveform/renderers/allshader/waveformrenderer.h index 32dbc036b19..11c486eb49c 100644 --- a/src/waveform/renderers/allshader/waveformrenderer.h +++ b/src/waveform/renderers/allshader/waveformrenderer.h @@ -1,6 +1,5 @@ #pragma once -#include "rendergraph/openglnode.h" #include "waveform/renderers/waveformrendererabstract.h" class WaveformWidgetRenderer; @@ -9,8 +8,7 @@ namespace allshader { class WaveformRenderer; } -class allshader::WaveformRenderer : public ::WaveformRendererAbstract, - public rendergraph::OpenGLNode { +class allshader::WaveformRenderer : public ::WaveformRendererAbstract { public: explicit WaveformRenderer(WaveformWidgetRenderer* widget); diff --git a/src/waveform/renderers/allshader/waveformrendererfiltered.h b/src/waveform/renderers/allshader/waveformrendererfiltered.h index fcef9e634dc..43441adafa5 100644 --- a/src/waveform/renderers/allshader/waveformrendererfiltered.h +++ b/src/waveform/renderers/allshader/waveformrendererfiltered.h @@ -1,5 +1,6 @@ #pragma once +#include "rendergraph/openglnode.h" #include "shaders/unicolorshader.h" #include "util/class.h" #include "waveform/renderers/allshader/vertexdata.h" diff --git a/src/waveform/renderers/allshader/waveformrendererhsv.h b/src/waveform/renderers/allshader/waveformrendererhsv.h index fd7d8d10f15..a6fdbe95f51 100644 --- a/src/waveform/renderers/allshader/waveformrendererhsv.h +++ b/src/waveform/renderers/allshader/waveformrendererhsv.h @@ -1,5 +1,6 @@ #pragma once +#include "rendergraph/openglnode.h" #include "shaders/rgbshader.h" #include "util/class.h" #include "waveform/renderers/allshader/rgbdata.h" diff --git a/src/waveform/renderers/allshader/waveformrenderersignalbase.h b/src/waveform/renderers/allshader/waveformrenderersignalbase.h index b36639486f4..0c4217723d8 100644 --- a/src/waveform/renderers/allshader/waveformrenderersignalbase.h +++ b/src/waveform/renderers/allshader/waveformrenderersignalbase.h @@ -3,7 +3,6 @@ #include #include -#include "rendergraph/openglnode.h" #include "util/class.h" #include "waveform/renderers/waveformrenderersignalbase.h" diff --git a/src/waveform/renderers/allshader/waveformrenderersimple.h b/src/waveform/renderers/allshader/waveformrenderersimple.h index 7b0aee5c7b1..ba79752539c 100644 --- a/src/waveform/renderers/allshader/waveformrenderersimple.h +++ b/src/waveform/renderers/allshader/waveformrenderersimple.h @@ -1,5 +1,6 @@ #pragma once +#include "rendergraph/openglnode.h" #include "shaders/unicolorshader.h" #include "util/class.h" #include "waveform/renderers/allshader/vertexdata.h" diff --git a/src/waveform/renderers/allshader/waveformrendererslipmode.h b/src/waveform/renderers/allshader/waveformrendererslipmode.h index 5e7b189ca57..c5a8ce9e92c 100644 --- a/src/waveform/renderers/allshader/waveformrendererslipmode.h +++ b/src/waveform/renderers/allshader/waveformrendererslipmode.h @@ -3,6 +3,7 @@ #include #include +#include "rendergraph/openglnode.h" #include "shaders/slipmodeshader.h" #include "util/class.h" #include "util/performancetimer.h" @@ -16,7 +17,9 @@ namespace allshader { class WaveformRendererSlipMode; } -class allshader::WaveformRendererSlipMode final : public allshader::WaveformRenderer { +class allshader::WaveformRendererSlipMode final + : public allshader::WaveformRenderer, + public rendergraph::OpenGLNode { public: explicit WaveformRendererSlipMode( WaveformWidgetRenderer* waveformWidget); diff --git a/src/waveform/renderers/allshader/waveformrendererstem.h b/src/waveform/renderers/allshader/waveformrendererstem.h index fc678ce4fa1..99728194574 100644 --- a/src/waveform/renderers/allshader/waveformrendererstem.h +++ b/src/waveform/renderers/allshader/waveformrendererstem.h @@ -2,6 +2,7 @@ #include +#include "rendergraph/openglnode.h" #include "shaders/rgbashader.h" #include "shaders/textureshader.h" #include "util/class.h" diff --git a/src/waveform/renderers/allshader/waveformrenderertextured.h b/src/waveform/renderers/allshader/waveformrenderertextured.h index d88a37e65be..dccf1d975b6 100644 --- a/src/waveform/renderers/allshader/waveformrenderertextured.h +++ b/src/waveform/renderers/allshader/waveformrenderertextured.h @@ -2,6 +2,7 @@ #ifndef QT_OPENGL_ES_2 +#include "rendergraph/openglnode.h" #include "shaders/rgbshader.h" #include "track/track_decl.h" #include "util/class.h" From 07d1f6ac9cc40af2ef8337f6a2edb3328cd41ea9 Mon Sep 17 00:00:00 2001 From: m0dB Date: Mon, 23 Sep 2024 16:32:53 +0200 Subject: [PATCH 37/64] moved vertexupdaters --- .../common/rendergraph/vertexupdaters}/rgbavertexupdater.h | 0 .../common/rendergraph/vertexupdaters}/rgbvertexupdater.h | 0 .../rendergraph/vertexupdaters}/texturedvertexupdater.h | 0 .../common/rendergraph/vertexupdaters}/vertexupdater.h | 0 src/waveform/renderers/allshader/digitsrenderer.cpp | 2 +- src/waveform/renderers/allshader/waveformrenderbeat.cpp | 2 +- src/waveform/renderers/allshader/waveformrendererpreroll.cpp | 2 +- src/waveform/renderers/allshader/waveformrendermark.cpp | 4 ++-- src/waveform/renderers/allshader/waveformrendermarkrange.cpp | 2 +- 9 files changed, 6 insertions(+), 6 deletions(-) rename src/{waveform/renderers/allshader => rendergraph/common/rendergraph/vertexupdaters}/rgbavertexupdater.h (100%) rename src/{waveform/renderers/allshader => rendergraph/common/rendergraph/vertexupdaters}/rgbvertexupdater.h (100%) rename src/{waveform/renderers/allshader => rendergraph/common/rendergraph/vertexupdaters}/texturedvertexupdater.h (100%) rename src/{waveform/renderers/allshader => rendergraph/common/rendergraph/vertexupdaters}/vertexupdater.h (100%) diff --git a/src/waveform/renderers/allshader/rgbavertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/rgbavertexupdater.h similarity index 100% rename from src/waveform/renderers/allshader/rgbavertexupdater.h rename to src/rendergraph/common/rendergraph/vertexupdaters/rgbavertexupdater.h diff --git a/src/waveform/renderers/allshader/rgbvertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/rgbvertexupdater.h similarity index 100% rename from src/waveform/renderers/allshader/rgbvertexupdater.h rename to src/rendergraph/common/rendergraph/vertexupdaters/rgbvertexupdater.h diff --git a/src/waveform/renderers/allshader/texturedvertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/texturedvertexupdater.h similarity index 100% rename from src/waveform/renderers/allshader/texturedvertexupdater.h rename to src/rendergraph/common/rendergraph/vertexupdaters/texturedvertexupdater.h diff --git a/src/waveform/renderers/allshader/vertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/vertexupdater.h similarity index 100% rename from src/waveform/renderers/allshader/vertexupdater.h rename to src/rendergraph/common/rendergraph/vertexupdaters/vertexupdater.h diff --git a/src/waveform/renderers/allshader/digitsrenderer.cpp b/src/waveform/renderers/allshader/digitsrenderer.cpp index c4c2a77d349..156f3d9601f 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.cpp +++ b/src/waveform/renderers/allshader/digitsrenderer.cpp @@ -13,8 +13,8 @@ #include "rendergraph/context.h" #include "rendergraph/geometry.h" #include "rendergraph/material/texturematerial.h" +#include "rendergraph/vertexupdaters/texturedvertexupdater.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" -#include "waveform/renderers/allshader/texturedvertexupdater.h" // Render digits using a texture (generated) with digits with blurred dark outline diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.cpp b/src/waveform/renderers/allshader/waveformrenderbeat.cpp index 0dc552e6cfb..d71d0c31ef8 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.cpp +++ b/src/waveform/renderers/allshader/waveformrenderbeat.cpp @@ -4,9 +4,9 @@ #include "rendergraph/geometry.h" #include "rendergraph/material/unicolormaterial.h" +#include "rendergraph/vertexupdaters/vertexupdater.h" #include "skin/legacy/skincontext.h" #include "track/track.h" -#include "vertexupdater.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "widget/wskincolor.h" diff --git a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp index 0dc044db41d..45bfd402608 100644 --- a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp +++ b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp @@ -7,8 +7,8 @@ #include "rendergraph/context.h" #include "rendergraph/geometry.h" #include "rendergraph/material/patternmaterial.h" +#include "rendergraph/vertexupdaters/texturedvertexupdater.h" #include "skin/legacy/skincontext.h" -#include "texturedvertexupdater.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "widget/wskincolor.h" diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 6c9d958df11..bbdd0535ded 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -8,8 +8,8 @@ #include "rendergraph/material/rgbamaterial.h" #include "rendergraph/material/texturematerial.h" #include "rendergraph/texture.h" -#include "rgbavertexupdater.h" -#include "texturedvertexupdater.h" +#include "rendergraph/vertexupdaters/rgbavertexupdater.h" +#include "rendergraph/vertexupdaters/texturedvertexupdater.h" #include "track/track.h" #include "util/colorcomponents.h" #include "waveform/renderers/allshader/digitsrenderer.h" diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index 46a2e7fbe02..d7a77bfed1a 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -3,8 +3,8 @@ #include "rendergraph/geometry.h" #include "rendergraph/geometrynode.h" #include "rendergraph/material/unicolormaterial.h" +#include "rendergraph/vertexupdaters/vertexupdater.h" #include "skin/legacy/skincontext.h" -#include "vertexupdater.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" From b24e9ba476d85418a2adadf0306486069e306bcf Mon Sep 17 00:00:00 2001 From: m0dB Date: Mon, 23 Sep 2024 16:33:50 +0200 Subject: [PATCH 38/64] ported waveformrendererrgb to rendergraph, hurray! --- .../allshader/waveformrendererrgb.cpp | 77 +++++++++---------- .../renderers/allshader/waveformrendererrgb.h | 20 ++--- 2 files changed, 43 insertions(+), 54 deletions(-) diff --git a/src/waveform/renderers/allshader/waveformrendererrgb.cpp b/src/waveform/renderers/allshader/waveformrendererrgb.cpp index 31cd94f1a5d..6e36e1d78b4 100644 --- a/src/waveform/renderers/allshader/waveformrendererrgb.cpp +++ b/src/waveform/renderers/allshader/waveformrendererrgb.cpp @@ -1,11 +1,15 @@ #include "waveform/renderers/allshader/waveformrendererrgb.h" +#include "rendergraph/material/rgbmaterial.h" +#include "rendergraph/vertexupdaters/rgbvertexupdater.h" #include "track/track.h" #include "util/math.h" #include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" +using namespace rendergraph; + namespace allshader { namespace { @@ -20,20 +24,25 @@ WaveformRendererRGB::WaveformRendererRGB(WaveformWidgetRenderer* waveformWidget, : WaveformRendererSignalBase(waveformWidget), m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip), m_options(options) { + initForRectangles(0); + setUsePreprocess(true); } void WaveformRendererRGB::onSetup(const QDomNode& node) { Q_UNUSED(node); } -void WaveformRendererRGB::initializeGL() { - m_shader.init(); +void WaveformRendererRGB::preprocess() { + if (!preprocessInner()) { + geometry().allocate(0); + } } -void WaveformRendererRGB::paintGL() { +bool WaveformRendererRGB::preprocessInner() { TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); + if (!pTrack || (m_isSlipRenderer && !m_waveformRenderer->isSlipActive())) { - return; + return false; } auto positionType = m_isSlipRenderer ? ::WaveformRendererAbstract::Slip @@ -41,23 +50,23 @@ void WaveformRendererRGB::paintGL() { ConstWaveformPointer waveform = pTrack->getWaveform(); if (waveform.isNull()) { - return; + return false; } const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { - return; + return false; } const WaveformData* data = waveform->data(); if (data == nullptr) { - return; + return false; } #ifdef __STEM__ auto stemInfo = pTrack->getStemInfo(); // If this track is a stem track, skip the rendering if (!stemInfo.isEmpty() && waveform->hasStem()) { - return; + return false; } #endif @@ -107,16 +116,14 @@ void WaveformRendererRGB::paintGL() { // Slip rendere only render a single channel, so the vertices count doesn't change ((splitLeftRight && !m_isSlipRenderer ? length * 2 : length) + 1); - m_vertices.clear(); - m_vertices.reserve(reserved); - m_colors.clear(); - m_colors.reserve(reserved); + geometry().allocate(reserved); + // TODO set dirty for scenegraph - m_vertices.addRectangle(0.f, + RGBVertexUpdater vertexUpdater{geometry().vertexDataAs()}; + vertexUpdater.addRectangle(0.f, halfBreadth - 0.5f * devicePixelRatio, static_cast(length), - m_isSlipRenderer ? halfBreadth : halfBreadth + 0.5f * devicePixelRatio); - m_colors.addForRectangle( + m_isSlipRenderer ? halfBreadth : halfBreadth + 0.5f * devicePixelRatio, static_cast(m_axesColor_r), static_cast(m_axesColor_g), static_cast(m_axesColor_b)); @@ -214,51 +221,37 @@ void WaveformRendererRGB::paintGL() { // Lines are thin rectangles if (!splitLeftRight) { - m_vertices.addRectangle(fpos - 0.5f, + vertexUpdater.addRectangle(fpos - 0.5f, halfBreadth - heightFactorAbs * maxAllChn[0], fpos + 0.5f, m_isSlipRenderer ? halfBreadth - : halfBreadth + heightFactorAbs * maxAllChn[1]); + : halfBreadth + heightFactorAbs * maxAllChn[1], + red, + green, + blue); } else { // note: heightFactor is the same for left and right, // but negative for left (chn 0) and positive for right (chn 1) - m_vertices.addRectangle(fpos - 0.5f, + vertexUpdater.addRectangle(fpos - 0.5f, halfBreadth, fpos + 0.5f, - halfBreadth + heightFactor[chn] * maxAllChn[chn]); + halfBreadth + heightFactor[chn] * maxAllChn[chn], + red, + green, + blue); } - m_colors.addForRectangle(red, green, blue); } xVisualFrame += visualIncrementPerPixel; } - DEBUG_ASSERT(reserved == m_vertices.size()); - DEBUG_ASSERT(reserved == m_colors.size()); + DEBUG_ASSERT(reserved == vertexUpdater.index()); const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); + material().setUniform(0, matrix); - const int matrixLocation = m_shader.matrixLocation(); - const int positionLocation = m_shader.positionLocation(); - const int colorLocation = m_shader.colorLocation(); - - m_shader.bind(); - m_shader.enableAttributeArray(positionLocation); - m_shader.enableAttributeArray(colorLocation); - - m_shader.setUniformValue(matrixLocation, matrix); - - m_shader.setAttributeArray( - positionLocation, GL_FLOAT, m_vertices.constData(), 2); - m_shader.setAttributeArray( - colorLocation, GL_FLOAT, m_colors.constData(), 3); - - glDrawArrays(GL_TRIANGLES, 0, m_vertices.size()); - - m_shader.disableAttributeArray(positionLocation); - m_shader.disableAttributeArray(colorLocation); - m_shader.release(); + return true; } } // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrendererrgb.h b/src/waveform/renderers/allshader/waveformrendererrgb.h index 4ef93a88617..a829cf3af2f 100644 --- a/src/waveform/renderers/allshader/waveformrendererrgb.h +++ b/src/waveform/renderers/allshader/waveformrendererrgb.h @@ -1,9 +1,7 @@ #pragma once -#include "shaders/rgbshader.h" +#include "rendergraph/geometrynode.h" #include "util/class.h" -#include "waveform/renderers/allshader/rgbdata.h" -#include "waveform/renderers/allshader/vertexdata.h" #include "waveform/renderers/allshader/waveformrenderersignalbase.h" namespace allshader { @@ -12,30 +10,28 @@ class WaveformRendererRGB; class allshader::WaveformRendererRGB final : public allshader::WaveformRendererSignalBase, - public rendergraph::OpenGLNode { + public rendergraph::GeometryNode { public: explicit WaveformRendererRGB(WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type = ::WaveformRendererAbstract::Play, WaveformRendererSignalBase::Options options = WaveformRendererSignalBase::Option::None); - // override ::WaveformRendererSignalBase + // Pure virtual from WaveformRendererSignalBase, not used void onSetup(const QDomNode& node) override; - void initializeGL() override; - void paintGL() override; - bool supportsSlip() const override { return true; } - private: - mixxx::RGBShader m_shader; - VertexData m_vertices; - RGBData m_colors; + // Virtuals for rendergraph::Node + void preprocess() override; + private: bool m_isSlipRenderer; WaveformRendererSignalBase::Options m_options; + bool preprocessInner(); + DISALLOW_COPY_AND_ASSIGN(WaveformRendererRGB); }; From b817d6c802caf3ec91d18c8ad6a0307d66a80107 Mon Sep 17 00:00:00 2001 From: m0dB Date: Tue, 24 Sep 2024 18:55:08 +0200 Subject: [PATCH 39/64] removed class Attribute and use BaseGeometry::Attribute to reduce delta between opengl and scenegraph --- src/rendergraph/common/attributeset.cpp | 12 ----- .../common/rendergraph/attribute.h | 26 ---------- .../common/rendergraph/attributeinit.h | 17 +++++++ .../common/rendergraph/attributeset.h | 6 +-- src/rendergraph/common/rendergraph/geometry.h | 21 ++++++-- src/rendergraph/opengl/CMakeLists.txt | 4 +- src/rendergraph/opengl/attributeset.cpp | 8 +++ .../opengl/backend/baseattributeset.cpp | 8 ++- .../opengl/backend/baseattributeset.h | 18 +++++-- .../opengl/backend/basegeometry.cpp | 46 +++++------------ src/rendergraph/opengl/backend/basegeometry.h | 49 ++++++++++++++----- .../opengl/backend/basegeometrynode.cpp | 10 ++-- src/rendergraph/opengl/geometry.cpp | 34 +++++-------- src/rendergraph/scenegraph/CMakeLists.txt | 4 +- src/rendergraph/scenegraph/attributeset.cpp | 10 ++++ .../scenegraph/backend/baseattributeset.cpp | 16 ++---- .../scenegraph/backend/baseattributeset.h | 29 +++++------ .../scenegraph/backend/basegeometry.h | 12 +---- src/rendergraph/scenegraph/geometry.cpp | 26 ++++------ 19 files changed, 177 insertions(+), 179 deletions(-) delete mode 100644 src/rendergraph/common/attributeset.cpp delete mode 100644 src/rendergraph/common/rendergraph/attribute.h create mode 100644 src/rendergraph/common/rendergraph/attributeinit.h create mode 100644 src/rendergraph/opengl/attributeset.cpp create mode 100644 src/rendergraph/scenegraph/attributeset.cpp diff --git a/src/rendergraph/common/attributeset.cpp b/src/rendergraph/common/attributeset.cpp deleted file mode 100644 index a2fef348d9c..00000000000 --- a/src/rendergraph/common/attributeset.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#include "rendergraph/attributeset.h" - -using namespace rendergraph; - -AttributeSet::AttributeSet(std::initializer_list list, - const std::vector& names) - : BaseAttributeSet(list, names) { -} - -const std::vector& AttributeSet::attributes() const { - return m_attributes; -} diff --git a/src/rendergraph/common/rendergraph/attribute.h b/src/rendergraph/common/rendergraph/attribute.h deleted file mode 100644 index 150ad00c3aa..00000000000 --- a/src/rendergraph/common/rendergraph/attribute.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include - -#include "rendergraph/types.h" - -namespace rendergraph { -struct Attribute; -} - -struct rendergraph::Attribute { - const int m_tupleSize; - const PrimitiveType m_primitiveType; - const QString m_name; - - Attribute(int tupleSize, PrimitiveType primitiveType, QString name = {}) - : m_tupleSize{tupleSize}, - m_primitiveType{primitiveType}, - m_name{std::move(name)} { - } - - template - static Attribute create() { - return Attribute(tupleSizeOf(), primitiveTypeOf()); - } -}; diff --git a/src/rendergraph/common/rendergraph/attributeinit.h b/src/rendergraph/common/rendergraph/attributeinit.h new file mode 100644 index 00000000000..db1a2797090 --- /dev/null +++ b/src/rendergraph/common/rendergraph/attributeinit.h @@ -0,0 +1,17 @@ +#pragma once + +#include "rendergraph/types.h" + +namespace rendergraph { +struct AttributeInit; +} + +struct rendergraph::AttributeInit { + int m_tupleSize; + PrimitiveType m_primitiveType; + + template + static AttributeInit create() { + return AttributeInit{tupleSizeOf(), primitiveTypeOf()}; + } +}; diff --git a/src/rendergraph/common/rendergraph/attributeset.h b/src/rendergraph/common/rendergraph/attributeset.h index 589a6e51bfc..b79833934fe 100644 --- a/src/rendergraph/common/rendergraph/attributeset.h +++ b/src/rendergraph/common/rendergraph/attributeset.h @@ -1,6 +1,7 @@ #pragma once #include "backend/baseattributeset.h" +#include "rendergraph/attributeinit.h" namespace rendergraph { class AttributeSet; @@ -8,13 +9,12 @@ class AttributeSet; class rendergraph::AttributeSet : public rendergraph::BaseAttributeSet { public: - AttributeSet(std::initializer_list list, const std::vector& names); - const std::vector& attributes() const; + AttributeSet(std::initializer_list list, const std::vector& names); }; namespace rendergraph { template AttributeSet makeAttributeSet(const std::vector& names) { - return AttributeSet({(Attribute::create())...}, names); + return AttributeSet({(AttributeInit::create())...}, names); } } // namespace rendergraph diff --git a/src/rendergraph/common/rendergraph/geometry.h b/src/rendergraph/common/rendergraph/geometry.h index c44572c3b9a..398c9493715 100644 --- a/src/rendergraph/common/rendergraph/geometry.h +++ b/src/rendergraph/common/rendergraph/geometry.h @@ -52,13 +52,27 @@ class rendergraph::Geometry : public rendergraph::BaseGeometry { }; Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount); - ~Geometry(); - void allocate(int vertexCount); + const Attribute* attributes() const { + return BaseGeometry::attributes(); + } void setAttributeValues(int attributePosition, const float* data, int numTuples); - float* vertexData(); + int attributeCount() const { + return BaseGeometry::attributeCount(); + } + + void allocate(int vertexCount) { + BaseGeometry::allocate(vertexCount); + } + + int sizeOfVertex() const { + return BaseGeometry::sizeOfVertex(); + } + int vertexCount() const { + return BaseGeometry::vertexCount(); + } template T* vertexDataAs() { @@ -66,5 +80,6 @@ class rendergraph::Geometry : public rendergraph::BaseGeometry { } DrawingMode drawingMode() const; + void setDrawingMode(DrawingMode mode); }; diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 968b690e3da..a6f1dce0a42 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -1,9 +1,8 @@ add_library(rendergraph_gl -../common/attributeset.cpp ../common/treenode.cpp ../common/node.cpp ../common/opacitynode.cpp -../common/rendergraph/attribute.h +../common/rendergraph/attributeinit.h ../common/rendergraph/attributeset.h ../common/rendergraph/treenode.h ../common/rendergraph/geometry.h @@ -49,6 +48,7 @@ backend/baseopenglnode.cpp backend/baseopenglnode.h backend/shadercache.h backend/basetexture.h +attributeset.cpp treenode.cpp engine.cpp geometry.cpp diff --git a/src/rendergraph/opengl/attributeset.cpp b/src/rendergraph/opengl/attributeset.cpp new file mode 100644 index 00000000000..302c2ad5c9c --- /dev/null +++ b/src/rendergraph/opengl/attributeset.cpp @@ -0,0 +1,8 @@ +#include "rendergraph/attributeset.h" + +using namespace rendergraph; + +AttributeSet::AttributeSet(std::initializer_list list, + const std::vector& names) + : BaseAttributeSet(list, names) { +} diff --git a/src/rendergraph/opengl/backend/baseattributeset.cpp b/src/rendergraph/opengl/backend/baseattributeset.cpp index 9ddec230676..87e1ea333d0 100644 --- a/src/rendergraph/opengl/backend/baseattributeset.cpp +++ b/src/rendergraph/opengl/backend/baseattributeset.cpp @@ -3,12 +3,16 @@ using namespace rendergraph; -BaseAttributeSet::BaseAttributeSet(std::initializer_list list, +BaseAttributeSet::BaseAttributeSet(std::initializer_list list, const std::vector& names) { DEBUG_ASSERT(list.size() == names.size()); int i = 0; + int offset = 0; m_attributes.reserve(list.size()); for (auto item : list) { - m_attributes.push_back(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); + m_attributes.push_back(BaseGeometry::Attribute{ + offset, item.m_tupleSize, item.m_primitiveType, names[i++]}); + offset += item.m_tupleSize * sizeOf(item.m_primitiveType); } + m_sizeOfVertex = offset; } diff --git a/src/rendergraph/opengl/backend/baseattributeset.h b/src/rendergraph/opengl/backend/baseattributeset.h index 57b7fcf76ec..c2c1c2cda2a 100644 --- a/src/rendergraph/opengl/backend/baseattributeset.h +++ b/src/rendergraph/opengl/backend/baseattributeset.h @@ -3,7 +3,8 @@ #include #include -#include "rendergraph/attribute.h" +#include "backend/basegeometry.h" +#include "rendergraph/attributeinit.h" namespace rendergraph { class BaseAttributeSet; @@ -11,6 +12,17 @@ class BaseAttributeSet; class rendergraph::BaseAttributeSet { protected: - BaseAttributeSet(std::initializer_list list, const std::vector& names); - std::vector m_attributes; + BaseAttributeSet(std::initializer_list list, const std::vector& names); + + public: + const std::vector& attributes() const { + return m_attributes; + } + int sizeOfVertex() const { + return m_sizeOfVertex; + } + + protected: + std::vector m_attributes; + int m_sizeOfVertex; }; diff --git a/src/rendergraph/opengl/backend/basegeometry.cpp b/src/rendergraph/opengl/backend/basegeometry.cpp index 03ffd7ac988..81471400cb6 100644 --- a/src/rendergraph/opengl/backend/basegeometry.cpp +++ b/src/rendergraph/opengl/backend/basegeometry.cpp @@ -1,41 +1,21 @@ #include "backend/basegeometry.h" +#include "backend/baseattributeset.h" #include "rendergraph/geometry.h" using namespace rendergraph; -BaseGeometry::BaseGeometry( - const AttributeSet& attributeSet, int vertexCount) - : m_drawingMode(static_cast(Geometry::DrawingMode:: - TriangleStrip)) // to mimic sg default - , - m_vertexCount(vertexCount) { - int offset = 0; - for (const auto& attribute : attributeSet.attributes()) { - m_offsets.push_back(offset); - offset += attribute.m_tupleSize; - m_tupleSizes.push_back(attribute.m_tupleSize); - } - m_stride = offset * sizeof(float); - m_data.resize(offset * vertexCount); -} - -int BaseGeometry::attributeCount() const { - return m_tupleSizes.size(); -} - -int BaseGeometry::vertexCount() const { - return m_vertexCount; -} +namespace { +// to mimic sg default +constexpr int defaultDrawingMode = static_cast(Geometry::DrawingMode::TriangleStrip); +} // namespace -int BaseGeometry::offset(int attributeIndex) const { - return m_offsets[attributeIndex]; -} - -int BaseGeometry::tupleSize(int attributeIndex) const { - return m_tupleSizes[attributeIndex]; -} - -int BaseGeometry::stride() const { - return m_stride; +BaseGeometry::BaseGeometry( + const BaseAttributeSet& attributeSet, int vertexCount) + : m_pAttributes(attributeSet.attributes().data()), + m_attributeCount(attributeSet.attributes().size()), + m_sizeOfVertex(attributeSet.sizeOfVertex()), + m_drawingMode(defaultDrawingMode), + m_vertexCount(vertexCount), + m_vertexData(m_vertexCount * m_sizeOfVertex / sizeof(float)) { } diff --git a/src/rendergraph/opengl/backend/basegeometry.h b/src/rendergraph/opengl/backend/basegeometry.h index 60281f6cb4b..5b17f518494 100644 --- a/src/rendergraph/opengl/backend/basegeometry.h +++ b/src/rendergraph/opengl/backend/basegeometry.h @@ -1,29 +1,56 @@ #pragma once +#include #include -#include "rendergraph/attributeset.h" +#include "rendergraph/types.h" namespace rendergraph { +class BaseAttributeSet; // fwd decl to avoid circular dependency class BaseGeometry; } +// TODO this assumes all vertices consist of floats class rendergraph::BaseGeometry { protected: - BaseGeometry(const AttributeSet& attributeSet, int vertexCount); + BaseGeometry(const BaseAttributeSet& attributeSet, int vertexCount); public: - int attributeCount() const; - int vertexCount() const; - int offset(int attributeIndex) const; - int tupleSize(int attributeIndex) const; - int stride() const; + struct Attribute { + const int m_offset; + const int m_tupleSize; + const PrimitiveType m_primitiveType; + const QString m_name; + }; + + float* vertexData() { + return m_vertexData.data(); + } + const float* vertexData() const { + return m_vertexData.data(); + } + const Attribute* attributes() const { + return m_pAttributes; + } + int attributeCount() const { + return m_attributeCount; + } + int vertexCount() const { + return m_vertexCount; + } + int sizeOfVertex() const { // in bytes + return m_sizeOfVertex; + } + void allocate(int vertexCount) { + m_vertexCount = vertexCount; + m_vertexData.resize(m_vertexCount * sizeOfVertex() / sizeof(float)); + } protected: + const Attribute* m_pAttributes; + const int m_attributeCount; + const int m_sizeOfVertex; int m_drawingMode; int m_vertexCount; - std::vector m_tupleSizes; - std::vector m_offsets; - int m_stride; - std::vector m_data; + std::vector m_vertexData; }; diff --git a/src/rendergraph/opengl/backend/basegeometrynode.cpp b/src/rendergraph/opengl/backend/basegeometrynode.cpp index 889b654deca..14dcc4fc2e4 100644 --- a/src/rendergraph/opengl/backend/basegeometrynode.cpp +++ b/src/rendergraph/opengl/backend/basegeometrynode.cpp @@ -70,13 +70,17 @@ void BaseGeometryNode::renderBackend() { } } + // TODO this code assumes all vertices are floats + int vertexOffset = 0; for (int i = 0; i < geometry.attributeCount(); i++) { + const Geometry::Attribute& attribute = geometry.attributes()[i]; int location = material.attributeLocation(i); shader.enableAttributeArray(location); shader.setAttributeArray(location, - geometry.vertexData() + geometry.offset(i), - geometry.tupleSize(i), - geometry.stride()); + geometry.vertexDataAs() + vertexOffset, + attribute.m_tupleSize, + geometry.sizeOfVertex()); + vertexOffset += attribute.m_tupleSize; } // TODO multiple textures diff --git a/src/rendergraph/opengl/geometry.cpp b/src/rendergraph/opengl/geometry.cpp index 0c4c7434ed6..6d4a9d04c49 100644 --- a/src/rendergraph/opengl/geometry.cpp +++ b/src/rendergraph/opengl/geometry.cpp @@ -9,41 +9,33 @@ Geometry::Geometry(const AttributeSet& attributeSet, int vertexCount) : BaseGeometry(attributeSet, vertexCount) { } -Geometry::~Geometry() = default; - void Geometry::setAttributeValues(int attributePosition, const float* from, int numTuples) { - const int offset = m_offsets[attributePosition]; - const int tupleSize = m_tupleSizes[attributePosition]; - const int strideNumberOfFloats = m_stride / sizeof(float); - const int skip = strideNumberOfFloats - tupleSize; + // TODO this code assumes all vertices are floats + VERIFY_OR_DEBUG_ASSERT(attributePosition < attributeCount()) { + return; + } + const int vertexOffset = attributes()[attributePosition].m_offset / sizeof(float); + const int tupleSize = attributes()[attributePosition].m_tupleSize; + const int vertexStride = sizeOfVertex() / sizeof(float); + const int vertexSkip = vertexStride - tupleSize; - VERIFY_OR_DEBUG_ASSERT(offset + numTuples * strideNumberOfFloats - skip <= - static_cast(m_data.size())) { + VERIFY_OR_DEBUG_ASSERT(vertexOffset + numTuples * vertexStride - vertexSkip <= + static_cast(m_vertexData.size())) { return; } - float* to = m_data.data(); - to += offset; + float* to = m_vertexData.data(); + to += vertexOffset; while (numTuples--) { int k = tupleSize; while (k--) { *to++ = *from++; } - to += skip; + to += vertexSkip; } } -float* Geometry::vertexData() { - return m_data.data(); -} - -void Geometry::allocate(int vertexCount) { - const int strideNumberOfFloats = m_stride / sizeof(float); - m_vertexCount = vertexCount; - m_data.resize(strideNumberOfFloats * m_vertexCount); -} - void Geometry::setDrawingMode(Geometry::DrawingMode mode) { m_drawingMode = static_cast(mode); } diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 3fe8fd57bd9..497c127bfea 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -1,9 +1,8 @@ add_library(rendergraph_sg -../common/attributeset.cpp ../common/treenode.cpp ../common/node.cpp ../common/opacitynode.cpp -../common/rendergraph/attribute.h +../common/rendergraph/attributeinit.h ../common/rendergraph/attributeset.h ../common/rendergraph/treenode.h ../common/rendergraph/geometry.h @@ -44,6 +43,7 @@ backend/basematerialtype.h backend/basenode.h backend/baseopacitynode.h backend/basetexture.h +attributeset.cpp treenode.cpp context.cpp geometry.cpp diff --git a/src/rendergraph/scenegraph/attributeset.cpp b/src/rendergraph/scenegraph/attributeset.cpp new file mode 100644 index 00000000000..04d55fcae8f --- /dev/null +++ b/src/rendergraph/scenegraph/attributeset.cpp @@ -0,0 +1,10 @@ +#include "rendergraph/attributeset.h" + +#include "backend/baseattributeset.h" + +using namespace rendergraph; + +AttributeSet::AttributeSet(std::initializer_list list, const std::vector&) + : BaseAttributeSet(list) { + // names are not used in scenegraph +} diff --git a/src/rendergraph/scenegraph/backend/baseattributeset.cpp b/src/rendergraph/scenegraph/backend/baseattributeset.cpp index 23c173285db..0f0bf0b8e7a 100644 --- a/src/rendergraph/scenegraph/backend/baseattributeset.cpp +++ b/src/rendergraph/scenegraph/backend/baseattributeset.cpp @@ -1,7 +1,5 @@ #include "backend/baseattributeset.h" -#include "rendergraph/assert.h" - using namespace rendergraph; namespace { @@ -15,23 +13,15 @@ int toQSGGeometryType(const PrimitiveType& t) { } } // namespace -BaseAttributeSetHelper::BaseAttributeSetHelper(std::initializer_list list, - const std::vector& names) { +BaseAttributeSetHelper::BaseAttributeSetHelper(std::initializer_list list) { int i = 0; - DEBUG_ASSERT(list.size() == names.size()); - m_attributes.reserve(list.size()); m_sgAttributes.reserve(list.size()); for (auto item : list) { - m_attributes.push_back(Attribute{item.m_tupleSize, item.m_primitiveType, names[i++]}); - - const auto& attribute = m_attributes.back(); - const int count = static_cast(m_sgAttributes.size()); const bool isPosition = count == 0; m_sgAttributes.push_back(QSGGeometry::Attribute::create(count, - attribute.m_tupleSize, - toQSGGeometryType(attribute.m_primitiveType), + item.m_tupleSize, + toQSGGeometryType(item.m_primitiveType), isPosition)); - m_stride += attribute.m_tupleSize * sizeOf(attribute.m_primitiveType); } } diff --git a/src/rendergraph/scenegraph/backend/baseattributeset.h b/src/rendergraph/scenegraph/backend/baseattributeset.h index 1d6d35638c6..7c33e25192a 100644 --- a/src/rendergraph/scenegraph/backend/baseattributeset.h +++ b/src/rendergraph/scenegraph/backend/baseattributeset.h @@ -4,7 +4,7 @@ #include #include -#include "rendergraph/attribute.h" +#include "rendergraph/attributeinit.h" namespace rendergraph { class BaseAttributeSet; @@ -13,18 +13,7 @@ class BaseAttributeSetHelper; class rendergraph::BaseAttributeSetHelper { protected: - // helper base class for BaseAttributeSet to populate m_attributes, and m_sgAttributes - // needed to construct BaseAttributeSet's other base class, QSGGeometry::AttributeSet - int m_stride{}; - - BaseAttributeSetHelper(std::initializer_list list, - const std::vector& names); - - const std::vector& attributes() const { - return m_attributes; - } - - std::vector m_attributes; + BaseAttributeSetHelper(std::initializer_list list); std::vector m_sgAttributes; }; @@ -32,11 +21,17 @@ class rendergraph::BaseAttributeSet : protected rendergraph::BaseAttributeSetHelper, public QSGGeometry::AttributeSet { protected: - BaseAttributeSet(std::initializer_list list, - const std::vector& names) - : BaseAttributeSetHelper(list, names), + BaseAttributeSet(std::initializer_list list) + : BaseAttributeSetHelper(list), QSGGeometry::AttributeSet{static_cast(m_sgAttributes.size()), - m_stride, + calculateSizeOfVertex(list), m_sgAttributes.data()} { } + static int calculateSizeOfVertex(std::initializer_list list) { + int numBytes = 0; + for (auto item : list) { + numBytes += item.m_tupleSize * sizeOf(item.m_primitiveType); + } + return numBytes; + } }; diff --git a/src/rendergraph/scenegraph/backend/basegeometry.h b/src/rendergraph/scenegraph/backend/basegeometry.h index 4eb75b7be10..45cf8780309 100644 --- a/src/rendergraph/scenegraph/backend/basegeometry.h +++ b/src/rendergraph/scenegraph/backend/basegeometry.h @@ -5,15 +5,5 @@ #include "rendergraph/attributeset.h" namespace rendergraph { -class BaseGeometry; +using BaseGeometry = QSGGeometry; } - -class rendergraph::BaseGeometry : public QSGGeometry { - protected: - BaseGeometry(const AttributeSet& attributeSet, int vertexCount) - : QSGGeometry(attributeSet, vertexCount), - m_stride(attributeSet.stride) { - QSGGeometry::setDrawingMode(QSGGeometry::DrawTriangleStrip); - } - const int m_stride; -}; diff --git a/src/rendergraph/scenegraph/geometry.cpp b/src/rendergraph/scenegraph/geometry.cpp index 6fff53e3789..6f1ccd55c54 100644 --- a/src/rendergraph/scenegraph/geometry.cpp +++ b/src/rendergraph/scenegraph/geometry.cpp @@ -30,41 +30,33 @@ Geometry::Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCoun : BaseGeometry(attributeSet, vertexCount) { } -Geometry::~Geometry() = default; - void Geometry::setAttributeValues(int attributePosition, const float* from, int numTuples) { + // TODO this code assumes all vertices are floats const auto attributeArray = QSGGeometry::attributes(); - int offset = 0; + int vertexOffset = 0; for (int i = 0; i < attributePosition; i++) { - offset += attributeArray[i].tupleSize; + vertexOffset += attributeArray[i].tupleSize; } const int tupleSize = attributeArray[attributePosition].tupleSize; - const int strideNumberOfFloats = m_stride / sizeof(float); - const int skip = strideNumberOfFloats - tupleSize; + const int vertexStride = sizeOfVertex() / sizeof(float); + const int vertexSkip = vertexStride - tupleSize; - VERIFY_OR_DEBUG_ASSERT(offset + numTuples * strideNumberOfFloats - skip <= - vertexCount() * strideNumberOfFloats) { + VERIFY_OR_DEBUG_ASSERT(vertexOffset + numTuples * vertexStride - vertexSkip <= + vertexCount() * vertexStride) { return; } float* to = static_cast(QSGGeometry::vertexData()); - to += offset; + to += vertexOffset; while (numTuples--) { int k = tupleSize; while (k--) { *to++ = *from++; } - to += skip; + to += vertexSkip; } } -float* Geometry::vertexData() { - return static_cast(QSGGeometry::vertexData()); -} - -void Geometry::allocate(int vertexCount) { - QSGGeometry::allocate(vertexCount); -} void Geometry::setDrawingMode(Geometry::DrawingMode mode) { QSGGeometry::setDrawingMode(toSgDrawingMode(mode)); From 0e870ddf9a9d7eba574adc2c3e8b2fc5e910f201 Mon Sep 17 00:00:00 2001 From: m0dB Date: Tue, 24 Sep 2024 19:01:02 +0200 Subject: [PATCH 40/64] comment --- src/rendergraph/common/rendergraph/attributeinit.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rendergraph/common/rendergraph/attributeinit.h b/src/rendergraph/common/rendergraph/attributeinit.h index db1a2797090..ccbbbf16b9b 100644 --- a/src/rendergraph/common/rendergraph/attributeinit.h +++ b/src/rendergraph/common/rendergraph/attributeinit.h @@ -6,6 +6,7 @@ namespace rendergraph { struct AttributeInit; } +// helper to create an AttributeSet using an initializer_list struct rendergraph::AttributeInit { int m_tupleSize; PrimitiveType m_primitiveType; From 941f0cc52268b1282daf8ad939ce3cd16f685382 Mon Sep 17 00:00:00 2001 From: m0dB Date: Wed, 25 Sep 2024 11:02:32 +0200 Subject: [PATCH 41/64] put rendergraph_sg and rendergraph_gl in different namespaces --- src/rendergraph/examples/gl_example/CMakeLists.txt | 1 + src/rendergraph/examples/sg_example/CMakeLists.txt | 1 + src/rendergraph/opengl/CMakeLists.txt | 1 + src/rendergraph/scenegraph/CMakeLists.txt | 1 + 4 files changed, 4 insertions(+) diff --git a/src/rendergraph/examples/gl_example/CMakeLists.txt b/src/rendergraph/examples/gl_example/CMakeLists.txt index 0d28d7a7d7d..42c52fa7052 100644 --- a/src/rendergraph/examples/gl_example/CMakeLists.txt +++ b/src/rendergraph/examples/gl_example/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(gl_example PRIVATE rendergraph_gl ) target_include_directories(gl_example PRIVATE ../common) +target_compile_definitions(gl_example PRIVATE rendergraph=rendergraph_gl) qt_add_resources(gl_example "gl_example" PREFIX diff --git a/src/rendergraph/examples/sg_example/CMakeLists.txt b/src/rendergraph/examples/sg_example/CMakeLists.txt index 378e062fcf2..94865f0fb16 100644 --- a/src/rendergraph/examples/sg_example/CMakeLists.txt +++ b/src/rendergraph/examples/sg_example/CMakeLists.txt @@ -9,6 +9,7 @@ target_link_libraries(sg_example PRIVATE rendergraph_sg ) target_include_directories(sg_example PRIVATE ../common) +target_compile_definitions(sg_example PRIVATE rendergraph=rendergraph_sg) qt_add_qml_module(sg_example URI RenderGraph diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index a6f1dce0a42..0e185a71e68 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -67,6 +67,7 @@ target_link_libraries(rendergraph_gl PUBLIC Qt6::Gui Qt6::OpenGL ) +target_compile_definitions(rendergraph_gl PRIVATE rendergraph=rendergraph_gl) # USE_QSHADER_FOR_GL is set in rendergraph/CMakeLists.txt if(USE_QSHADER_FOR_GL) diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 497c127bfea..9d38df1b7fe 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -60,5 +60,6 @@ target_link_libraries(rendergraph_sg PUBLIC Qt6::Qml Qt6::Quick ) +target_compile_definitions(rendergraph_sg PRIVATE rendergraph=rendergraph_sg) target_include_directories(rendergraph_sg PUBLIC . ../common) From 1f10725a4d890e5f49350406aebe08d9af849ed3 Mon Sep 17 00:00:00 2001 From: m0dB Date: Fri, 27 Sep 2024 22:26:47 +0200 Subject: [PATCH 42/64] remove generated file --- res/shaders/rendergraph/texture.vert.qsb | Bin 607 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 res/shaders/rendergraph/texture.vert.qsb diff --git a/res/shaders/rendergraph/texture.vert.qsb b/res/shaders/rendergraph/texture.vert.qsb deleted file mode 100644 index 84fa7e916fe48a406e5e2205a9c2988b4c4e84dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 607 zcmV-l0-*f>00rZCoRw2eZ`wc*9ovM4B?JNqByB#HaOsDH(uh`-5LJ6>4mnh6?iFB2 zEfpLY8&OsH5&ez*6TMXJ%=+1^D%7fj*1Pj&=DpdmA)*qc=JKjhOcPqsm_q(V(4-E7qRXK9f}l+ct<+q`GzH-BX9(2R!MRm6R* z*e@ey=hZez{Es=<3)o%k{yN3`rB#68oGoSS?q@~(NcIA3&%h-vn> z(YxS%_$6QxSGaE$SJn)KuL3@q`2jz7p(XYVeiix0?AMTAHGQWu%s6V$tV4efnsvNC z4;uT>aG z$EEd0F8B{d~R-cRoORr*&f;Qt}ciq`hMvz$bWAe`&xmlsMc;wTx%dX!AnSEboz!?-7pC|LE? zeP5|$9!$e%CMi1M2SdwY^d*?z>g8m7sh2mC)i?|zzpsWdmyMEml1Adqfu6n#7eUM| t2vr#PT3UVl1mt{rU@=JK_VdU0sN|UR(oGxHPc6!OrL61c_8Su|ltEZLJ_G;& From ca5f780a1e8dbea3ea61630f2e7298b4a94c518c Mon Sep 17 00:00:00 2001 From: m0dB Date: Fri, 27 Sep 2024 23:24:40 +0200 Subject: [PATCH 43/64] also use rendergraph::Engine in scenegraph to initialize and resize nodes, add GeometryNode::markDirtyGeometry() and GeometryNode::markDirtyMaterial() --- CMakeLists.txt | 1 + src/rendergraph/common/engine.cpp | 16 +++++ .../{opengl => common}/rendergraph/engine.h | 0 .../common/rendergraph/geometrynode.h | 3 + src/rendergraph/common/rendergraph/treenode.h | 9 +++ .../examples/gl_example/window.cpp | 1 + .../examples/sg_example/customitem.cpp | 10 ++- .../examples/sg_example/customitem.h | 3 +- src/rendergraph/opengl/CMakeLists.txt | 13 ++-- src/rendergraph/opengl/backend/basenode.h | 12 ---- src/rendergraph/opengl/engine.cpp | 66 ++++++++----------- src/rendergraph/opengl/geometrynode.cpp | 8 +++ src/rendergraph/opengl/treenode.cpp | 6 +- src/rendergraph/scenegraph/CMakeLists.txt | 11 ++-- src/rendergraph/scenegraph/engine.cpp | 43 ++++++++++++ src/rendergraph/scenegraph/geometrynode.cpp | 8 +++ 16 files changed, 143 insertions(+), 67 deletions(-) create mode 100644 src/rendergraph/common/engine.cpp rename src/rendergraph/{opengl => common}/rendergraph/engine.h (100%) create mode 100644 src/rendergraph/scenegraph/engine.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 70a9ecf5997..7ef86831b1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3814,6 +3814,7 @@ endif() add_subdirectory(src/rendergraph/opengl) add_subdirectory(res/shaders/rendergraph) target_link_libraries(mixxx-lib PUBLIC rendergraph_gl) +target_compile_definitions(mixxx-lib PRIVATE rendergraph=rendergraph_gl) # WavPack audio file support find_package(wavpack) diff --git a/src/rendergraph/common/engine.cpp b/src/rendergraph/common/engine.cpp new file mode 100644 index 00000000000..6d0798bc408 --- /dev/null +++ b/src/rendergraph/common/engine.cpp @@ -0,0 +1,16 @@ +#include "rendergraph/engine.h" + +#include + +#include "rendergraph/node.h" + +using namespace rendergraph; + +Engine::Engine(std::unique_ptr pNode) + : m_pTopNode(std::move(pNode)) { + addToEngine(m_pTopNode.get()); +} + +void Engine::resize(int w, int h) { + resize(m_pTopNode.get(), w, h); +} diff --git a/src/rendergraph/opengl/rendergraph/engine.h b/src/rendergraph/common/rendergraph/engine.h similarity index 100% rename from src/rendergraph/opengl/rendergraph/engine.h rename to src/rendergraph/common/rendergraph/engine.h diff --git a/src/rendergraph/common/rendergraph/geometrynode.h b/src/rendergraph/common/rendergraph/geometrynode.h index 44384b370bf..951c6e9b96c 100644 --- a/src/rendergraph/common/rendergraph/geometrynode.h +++ b/src/rendergraph/common/rendergraph/geometrynode.h @@ -29,6 +29,9 @@ class rendergraph::GeometryNode : public rendergraph::BaseGeometryNode, Geometry& geometry() const; Material& material() const; + void markDirtyGeometry(); + void markDirtyMaterial(); + private: std::unique_ptr m_pMaterial; std::unique_ptr m_pGeometry; diff --git a/src/rendergraph/common/rendergraph/treenode.h b/src/rendergraph/common/rendergraph/treenode.h index 2cd943ce838..4d925cbf80a 100644 --- a/src/rendergraph/common/rendergraph/treenode.h +++ b/src/rendergraph/common/rendergraph/treenode.h @@ -5,6 +5,7 @@ #include "backend/basenode.h" namespace rendergraph { +class Engine; // fwd decl to avoid circular dependency class TreeNode; } // namespace rendergraph @@ -55,11 +56,19 @@ class rendergraph::TreeNode { virtual void resize(int, int) { } + void setEngine(Engine* pEngine) { + m_pEngine = pEngine; + } + Engine* engine() const { + return m_pEngine; + } + private: void onAppendChildNode(TreeNode* pChild); void onRemoveAllChildNodes(); void onRemoveChildNode(TreeNode* pChild); + Engine* m_pEngine{}; rendergraph::BaseNode* m_pBackendNode; TreeNode* m_pParent{}; std::unique_ptr m_pFirstChild; diff --git a/src/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/examples/gl_example/window.cpp index a5e5085d257..dc0818edd4b 100644 --- a/src/rendergraph/examples/gl_example/window.cpp +++ b/src/rendergraph/examples/gl_example/window.cpp @@ -2,6 +2,7 @@ #include "examplenodes.h" #include "rendergraph/context.h" +#include "rendergraph/engine.h" Window::Window() { } diff --git a/src/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/examples/sg_example/customitem.cpp index 8651791c0a0..59b278cea4f 100644 --- a/src/rendergraph/examples/sg_example/customitem.cpp +++ b/src/rendergraph/examples/sg_example/customitem.cpp @@ -8,6 +8,7 @@ #include "examplenodes.h" #include "rendergraph/context.h" +#include "rendergraph/engine.h" #include "rendergraph/node.h" CustomItem::CustomItem(QQuickItem* parent) @@ -31,8 +32,12 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { bgNode->setRect(boundingRect()); rendergraph::Context context(window()); - m_node = std::make_unique(context); - bgNode->appendChildNode(m_node->backendNode()); + + auto pTopNode = std::make_unique(context); + bgNode->appendChildNode(pTopNode->backendNode()); + + m_pEngine = std::make_unique(std::move(pTopNode)); + m_pEngine->initialize(); node = bgNode; } else { @@ -41,6 +46,7 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { if (m_geometryChanged) { bgNode->setRect(boundingRect()); + m_pEngine->resize(boundingRect().width(), boundingRect().height()); m_geometryChanged = false; } diff --git a/src/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/examples/sg_example/customitem.h index 304fb5c8f5e..7abd81a0524 100644 --- a/src/rendergraph/examples/sg_example/customitem.h +++ b/src/rendergraph/examples/sg_example/customitem.h @@ -5,6 +5,7 @@ namespace rendergraph { class Node; +class Engine; } class CustomItem : public QQuickItem { @@ -20,7 +21,7 @@ class CustomItem : public QQuickItem { void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override; bool m_geometryChanged{}; - std::unique_ptr m_node; + std::unique_ptr m_pEngine; }; #endif // CUSTOMITEM_H diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 0e185a71e68..015eea487dd 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -1,10 +1,10 @@ add_library(rendergraph_gl -../common/treenode.cpp +../common/engine.cpp ../common/node.cpp ../common/opacitynode.cpp ../common/rendergraph/attributeinit.h ../common/rendergraph/attributeset.h -../common/rendergraph/treenode.h +../common/rendergraph/engine.h ../common/rendergraph/geometry.h ../common/rendergraph/geometrynode.h ../common/rendergraph/material.h @@ -25,13 +25,16 @@ add_library(rendergraph_gl ../common/rendergraph/node.h ../common/rendergraph/opacitynode.h ../common/rendergraph/texture.h +../common/rendergraph/treenode.h ../common/rendergraph/types.h ../common/rendergraph/uniform.h ../common/rendergraph/uniformscache.cpp ../common/rendergraph/uniformscache.h ../common/rendergraph/uniformset.cpp ../common/rendergraph/uniformset.h +../common/treenode.cpp ../common/types.cpp +attributeset.cpp backend/baseattributeset.cpp backend/baseattributeset.h backend/basegeometry.cpp @@ -46,10 +49,8 @@ backend/basenode.h backend/baseopacitynode.h backend/baseopenglnode.cpp backend/baseopenglnode.h -backend/shadercache.h backend/basetexture.h -attributeset.cpp -treenode.cpp +backend/shadercache.h engine.cpp geometry.cpp geometrynode.cpp @@ -57,9 +58,9 @@ material.cpp materialshader.cpp openglnode.cpp rendergraph/context.h -rendergraph/engine.h rendergraph/openglnode.h texture.cpp +treenode.cpp ) target_link_libraries(rendergraph_gl PUBLIC diff --git a/src/rendergraph/opengl/backend/basenode.h b/src/rendergraph/opengl/backend/basenode.h index d224e4cc8b3..23c897c8316 100644 --- a/src/rendergraph/opengl/backend/basenode.h +++ b/src/rendergraph/opengl/backend/basenode.h @@ -1,9 +1,5 @@ #pragma once -namespace rendergraph { -class Engine; // fwd decl to avoid circular dependency -} - namespace rendergraph { class BaseNode; } @@ -31,14 +27,6 @@ class rendergraph::BaseNode { virtual void resizeBackend(int, int) { } - void setEngine(Engine* pEngine) { - m_pEngine = pEngine; - } - Engine* engine() const { - return m_pEngine; - } - private: bool m_usePreprocess{}; - Engine* m_pEngine{}; }; diff --git a/src/rendergraph/opengl/engine.cpp b/src/rendergraph/opengl/engine.cpp index 700b3b8994c..6b8875dff81 100644 --- a/src/rendergraph/opengl/engine.cpp +++ b/src/rendergraph/opengl/engine.cpp @@ -1,22 +1,23 @@ #include "rendergraph/engine.h" - #include -#include "rendergraph/node.h" - using namespace rendergraph; -Engine::Engine(std::unique_ptr pNode) - : m_pTopNode(std::move(pNode)) { - addToEngine(m_pTopNode.get()); -} +void Engine::addToEngine(TreeNode* pNode) { + assert(pNode->engine() == nullptr); -void Engine::initialize() { - for (auto pNode : m_pInitializeNodes) { - pNode->backendNode()->initializeBackend(); - pNode->initialize(); + pNode->setEngine(this); + m_pInitializeNodes.push_back(pNode); + if (pNode->backendNode()->usePreprocess()) { + m_pPreprocessNodes.push_back(pNode); + } + pNode = pNode->firstChild(); + while (pNode) { + if (pNode->engine() != this) { + addToEngine(pNode); + } + pNode = pNode->nextSibling(); } - m_pInitializeNodes.clear(); } void Engine::render() { @@ -28,8 +29,15 @@ void Engine::render() { } } -void Engine::resize(int w, int h) { - resize(m_pTopNode.get(), w, h); +void Engine::render(TreeNode* pNode) { + pNode->backendNode()->renderBackend(); + pNode = pNode->firstChild(); + while (pNode) { + if (!pNode->backendNode()->isSubtreeBlocked()) { + render(pNode); + } + pNode = pNode->nextSibling(); + } } void Engine::preprocess() { @@ -40,15 +48,12 @@ void Engine::preprocess() { } } -void Engine::render(TreeNode* pNode) { - pNode->backendNode()->renderBackend(); - pNode = pNode->firstChild(); - while (pNode) { - if (!pNode->backendNode()->isSubtreeBlocked()) { - render(pNode); - } - pNode = pNode->nextSibling(); +void Engine::initialize() { + for (auto pNode : m_pInitializeNodes) { + pNode->backendNode()->initializeBackend(); + pNode->initialize(); } + m_pInitializeNodes.clear(); } void Engine::resize(TreeNode* pNode, int w, int h) { @@ -60,20 +65,3 @@ void Engine::resize(TreeNode* pNode, int w, int h) { pNode = pNode->nextSibling(); } } - -void Engine::addToEngine(TreeNode* pNode) { - assert(pNode->backendNode()->engine() == nullptr); - - pNode->backendNode()->setEngine(this); - m_pInitializeNodes.push_back(pNode); - if (pNode->backendNode()->usePreprocess()) { - m_pPreprocessNodes.push_back(pNode); - } - pNode = pNode->firstChild(); - while (pNode) { - if (pNode->backendNode()->engine() != this) { - addToEngine(pNode); - } - pNode = pNode->nextSibling(); - } -} diff --git a/src/rendergraph/opengl/geometrynode.cpp b/src/rendergraph/opengl/geometrynode.cpp index ad5c4448dce..1af643cb8e2 100644 --- a/src/rendergraph/opengl/geometrynode.cpp +++ b/src/rendergraph/opengl/geometrynode.cpp @@ -21,3 +21,11 @@ Geometry& GeometryNode::geometry() const { Material& GeometryNode::material() const { return *m_pMaterial; } + +void GeometryNode::markDirtyGeometry() { + // not (yet) needed for opengl +} + +void GeometryNode::markDirtyMaterial() { + // not (yet) needed for opengl +} diff --git a/src/rendergraph/opengl/treenode.cpp b/src/rendergraph/opengl/treenode.cpp index 949e6e10a2b..0b9436a3e5f 100644 --- a/src/rendergraph/opengl/treenode.cpp +++ b/src/rendergraph/opengl/treenode.cpp @@ -9,9 +9,9 @@ void TreeNode::setUsePreprocess(bool value) { } void TreeNode::onAppendChildNode(TreeNode* pChild) { - if (backendNode()->engine() != nullptr && - backendNode()->engine() != pChild->backendNode()->engine()) { - backendNode()->engine()->addToEngine(pChild); + if (engine() != nullptr && + engine() != pChild->engine()) { + engine()->addToEngine(pChild); } } diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 9d38df1b7fe..1e26c6ef58c 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -1,10 +1,10 @@ add_library(rendergraph_sg -../common/treenode.cpp +../common/engine.cpp ../common/node.cpp ../common/opacitynode.cpp ../common/rendergraph/attributeinit.h ../common/rendergraph/attributeset.h -../common/rendergraph/treenode.h +../common/rendergraph/engine.h ../common/rendergraph/geometry.h ../common/rendergraph/geometrynode.h ../common/rendergraph/material.h @@ -25,13 +25,16 @@ add_library(rendergraph_sg ../common/rendergraph/node.h ../common/rendergraph/opacitynode.h ../common/rendergraph/texture.h +../common/rendergraph/treenode.h ../common/rendergraph/types.h ../common/rendergraph/uniform.h ../common/rendergraph/uniformscache.cpp ../common/rendergraph/uniformscache.h ../common/rendergraph/uniformset.cpp ../common/rendergraph/uniformset.h +../common/treenode.cpp ../common/types.cpp +attributeset.cpp backend/baseattributeset.cpp backend/baseattributeset.h backend/basegeometry.h @@ -43,15 +46,15 @@ backend/basematerialtype.h backend/basenode.h backend/baseopacitynode.h backend/basetexture.h -attributeset.cpp -treenode.cpp context.cpp +engine.cpp geometry.cpp geometrynode.cpp material.cpp materialshader.cpp rendergraph/context.h texture.cpp +treenode.cpp ) target_link_libraries(rendergraph_sg PUBLIC diff --git a/src/rendergraph/scenegraph/engine.cpp b/src/rendergraph/scenegraph/engine.cpp new file mode 100644 index 00000000000..9354e76e2d1 --- /dev/null +++ b/src/rendergraph/scenegraph/engine.cpp @@ -0,0 +1,43 @@ +#include "rendergraph/engine.h" + +#include + +using namespace rendergraph; + +void Engine::addToEngine(TreeNode* pNode) { + assert(pNode->engine() == nullptr); + + pNode->setEngine(this); + m_pInitializeNodes.push_back(pNode); + pNode = pNode->firstChild(); + while (pNode) { + if (pNode->engine() != this) { + addToEngine(pNode); + } + pNode = pNode->nextSibling(); + } +} + +void Engine::render() { + assert(false && "should not be called for scenegraph, rendering is handled by Qt"); +} + +void Engine::preprocess() { + assert(false && "should not be called for scenegraph, preprocess is handled by Qt"); +} + +void Engine::initialize() { + for (auto pNode : m_pInitializeNodes) { + pNode->initialize(); + } + m_pInitializeNodes.clear(); +} + +void Engine::resize(TreeNode* pNode, int w, int h) { + pNode->resize(w, h); + pNode = pNode->firstChild(); + while (pNode) { + resize(pNode, w, h); + pNode = pNode->nextSibling(); + } +} diff --git a/src/rendergraph/scenegraph/geometrynode.cpp b/src/rendergraph/scenegraph/geometrynode.cpp index bd9f26570e8..59455ed9e8f 100644 --- a/src/rendergraph/scenegraph/geometrynode.cpp +++ b/src/rendergraph/scenegraph/geometrynode.cpp @@ -23,3 +23,11 @@ Geometry& GeometryNode::geometry() const { Material& GeometryNode::material() const { return *m_pMaterial; } + +void GeometryNode::markDirtyMaterial() { + markDirty(QSGNode::DirtyMaterial); +} + +void GeometryNode::markDirtyGeometry() { + markDirty(QSGNode::DirtyGeometry); +} From bf7ed15166853567302909744b5f5ea0f516e704 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 6 Oct 2024 04:08:29 +0200 Subject: [PATCH 44/64] wip --- .../renderers/allshader/matrixforwidgetgeometry.cpp | 13 +------------ .../renderers/allshader/waveformrenderbeat.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp b/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp index 494bfc768ac..250c2abbaf8 100644 --- a/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp +++ b/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp @@ -4,16 +4,5 @@ QMatrix4x4 matrixForWidgetGeometry(WaveformWidgetRenderer* const waveformRenderer, bool applyDevicePixelRatio) { - const float ratio = applyDevicePixelRatio ? waveformRenderer->getDevicePixelRatio() : 1.f; - QMatrix4x4 matrix; - - matrix.ortho(QRectF(0.0f, - 0.0f, - waveformRenderer->getWidth() * ratio, - waveformRenderer->getHeight() * ratio)); - if (waveformRenderer->getOrientation() == Qt::Vertical) { - matrix.rotate(90.f, 0.0f, 0.0f, 1.0f); - matrix.translate(0.f, -waveformRenderer->getWidth() * ratio, 0.f); - } - return matrix; + return waveformRenderer->getMatrix(applyDevicePixelRatio); } diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.cpp b/src/waveform/renderers/allshader/waveformrenderbeat.cpp index d71d0c31ef8..5c35bdf30e6 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.cpp +++ b/src/waveform/renderers/allshader/waveformrenderbeat.cpp @@ -37,6 +37,7 @@ void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* event) { void WaveformRenderBeat::preprocess() { if (!preprocessInner()) { geometry().allocate(0); + markDirtyGeometry(); } } @@ -100,7 +101,6 @@ bool WaveformRenderBeat::preprocessInner() { const int reserved = numBeatsInRange * numVerticesPerLine; geometry().allocate(reserved); - // TODO set dirty for scenegraph VertexUpdater vertexUpdater{geometry().vertexDataAs()}; @@ -120,13 +120,15 @@ bool WaveformRenderBeat::preprocessInner() { vertexUpdater.addRectangle({x1, 0.f}, {x2, m_isSlipRenderer ? rendererBreadth / 2 : rendererBreadth}); } + markDirtyGeometry(); DEBUG_ASSERT(reserved == vertexUpdater.index()); - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); + const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(false); material().setUniform(0, matrix); material().setUniform(1, m_color); + markDirtyMaterial(); return true; } From 1e57aaeb3d547d18e135bcb6a15e1e6f0b92fe9c Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 19 Oct 2024 04:15:45 +0200 Subject: [PATCH 45/64] let matrix be handled by qt scenegraph or by the opengl engine, removed engine class from scenegraph, get context from m_waveformRenderer, various cleanups --- CMakeLists.txt | 1 - src/rendergraph/common/engine.cpp | 16 ---- src/rendergraph/common/rendergraph/texture.h | 2 +- src/rendergraph/common/rendergraph/treenode.h | 13 --- .../vertexupdaters/rgbavertexupdater.h | 47 ++++++++-- .../vertexupdaters/rgbvertexupdater.h | 41 +++++++-- .../vertexupdaters/texturedvertexupdater.h | 33 +++++-- .../vertexupdaters/vertexupdater.h | 13 +-- .../examples/common/examplenode.cpp | 52 +++++++++++ src/rendergraph/examples/common/examplenode.h | 12 +++ .../examples/common/examplenodes.cpp | 73 --------------- .../examples/common/examplenodes.h | 43 --------- .../examples/gl_example/CMakeLists.txt | 2 +- .../examples/gl_example/window.cpp | 12 +-- .../examples/sg_example/CMakeLists.txt | 2 +- .../examples/sg_example/customitem.cpp | 26 ++++-- .../examples/sg_example/customitem.h | 6 +- .../examples/sg_example/qml/main.qml | 13 ++- src/rendergraph/opengl/CMakeLists.txt | 3 +- .../opengl/backend/basegeometrynode.cpp | 12 ++- .../opengl/backend/basegeometrynode.h | 5 +- src/rendergraph/opengl/backend/basenode.h | 16 +++- .../opengl/backend/baseopenglnode.cpp | 6 +- .../opengl/backend/baseopenglnode.h | 6 +- src/rendergraph/opengl/engine.cpp | 56 +++++++----- .../{common => opengl}/rendergraph/engine.h | 9 +- src/rendergraph/opengl/texture.cpp | 2 +- src/rendergraph/opengl/treenode.cpp | 6 +- src/rendergraph/scenegraph/CMakeLists.txt | 3 - .../scenegraph/backend/basematerialshader.cpp | 11 ++- src/rendergraph/scenegraph/engine.cpp | 43 --------- src/rendergraph/scenegraph/texture.cpp | 4 +- .../renderers/allshader/digitsrenderer.cpp | 14 ++- .../renderers/allshader/digitsrenderer.h | 14 +-- .../allshader/matrixforwidgetgeometry.cpp | 8 -- .../allshader/waveformrenderbackground.cpp | 4 +- .../allshader/waveformrenderbackground.h | 2 +- .../allshader/waveformrenderbeat.cpp | 8 +- .../renderers/allshader/waveformrenderbeat.h | 2 +- .../allshader/waveformrendererendoftrack.cpp | 44 +++++++--- .../allshader/waveformrendererendoftrack.h | 6 +- .../allshader/waveformrendererfiltered.cpp | 3 +- .../allshader/waveformrendererhsv.cpp | 3 +- .../allshader/waveformrendererpreroll.cpp | 21 +++-- .../allshader/waveformrendererpreroll.h | 2 +- .../allshader/waveformrendererrgb.cpp | 73 ++++++++------- .../allshader/waveformrenderersimple.cpp | 2 +- .../allshader/waveformrendererslipmode.cpp | 9 +- .../allshader/waveformrendererslipmode.h | 2 +- .../allshader/waveformrendererstem.cpp | 3 +- .../allshader/waveformrendermark.cpp | 88 ++++++++----------- .../renderers/allshader/waveformrendermark.h | 15 ++-- .../allshader/waveformrendermarkrange.cpp | 12 +-- .../allshader/waveformrendermarkrange.h | 4 +- .../renderers/waveformwidgetrenderer.h | 14 +++ .../widgets/allshader/waveformwidget.cpp | 9 +- .../widgets/allshader/waveformwidget.h | 2 + 57 files changed, 487 insertions(+), 466 deletions(-) delete mode 100644 src/rendergraph/common/engine.cpp create mode 100644 src/rendergraph/examples/common/examplenode.cpp create mode 100644 src/rendergraph/examples/common/examplenode.h delete mode 100644 src/rendergraph/examples/common/examplenodes.cpp delete mode 100644 src/rendergraph/examples/common/examplenodes.h rename src/rendergraph/{common => opengl}/rendergraph/engine.h (78%) delete mode 100644 src/rendergraph/scenegraph/engine.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ef86831b1f..055f374b4c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1514,7 +1514,6 @@ if(QOPENGL) src/shaders/vinylqualityshader.cpp src/util/opengltexture2d.cpp src/waveform/renderers/allshader/digitsrenderer.cpp - src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp src/waveform/renderers/allshader/waveformrenderbackground.cpp src/waveform/renderers/allshader/waveformrenderbeat.cpp src/waveform/renderers/allshader/waveformrenderer.cpp diff --git a/src/rendergraph/common/engine.cpp b/src/rendergraph/common/engine.cpp deleted file mode 100644 index 6d0798bc408..00000000000 --- a/src/rendergraph/common/engine.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "rendergraph/engine.h" - -#include - -#include "rendergraph/node.h" - -using namespace rendergraph; - -Engine::Engine(std::unique_ptr pNode) - : m_pTopNode(std::move(pNode)) { - addToEngine(m_pTopNode.get()); -} - -void Engine::resize(int w, int h) { - resize(m_pTopNode.get(), w, h); -} diff --git a/src/rendergraph/common/rendergraph/texture.h b/src/rendergraph/common/rendergraph/texture.h index 8e095ca3120..aa6bbe95ccf 100644 --- a/src/rendergraph/common/rendergraph/texture.h +++ b/src/rendergraph/common/rendergraph/texture.h @@ -12,7 +12,7 @@ class Texture; class rendergraph::Texture { public: - Texture(Context& context, const QImage& image); + Texture(Context* pContext, const QImage& image); BaseTexture* backendTexture() const { return m_pTexture.get(); diff --git a/src/rendergraph/common/rendergraph/treenode.h b/src/rendergraph/common/rendergraph/treenode.h index 4d925cbf80a..47752c1dc48 100644 --- a/src/rendergraph/common/rendergraph/treenode.h +++ b/src/rendergraph/common/rendergraph/treenode.h @@ -51,24 +51,11 @@ class rendergraph::TreeNode { return m_pBackendNode; } - virtual void initialize() { - } - virtual void resize(int, int) { - } - - void setEngine(Engine* pEngine) { - m_pEngine = pEngine; - } - Engine* engine() const { - return m_pEngine; - } - private: void onAppendChildNode(TreeNode* pChild); void onRemoveAllChildNodes(); void onRemoveChildNode(TreeNode* pChild); - Engine* m_pEngine{}; rendergraph::BaseNode* m_pBackendNode; TreeNode* m_pParent{}; std::unique_ptr m_pFirstChild; diff --git a/src/rendergraph/common/rendergraph/vertexupdaters/rgbavertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/rgbavertexupdater.h index 2f2a46dc2eb..87a149ff60f 100644 --- a/src/rendergraph/common/rendergraph/vertexupdaters/rgbavertexupdater.h +++ b/src/rendergraph/common/rendergraph/vertexupdaters/rgbavertexupdater.h @@ -55,6 +55,48 @@ class rendergraph::RGBAVertexUpdater { rgbar.z(), rgbar.w()); } + int index() const { + return static_cast(m_pWrite - m_pData); + } + void addTriangle(QVector2D p1, QVector2D p2, QVector2D p3, QVector4D rgba) { + addTriangle(p1.x(), + p1.y(), + p2.x(), + p2.y(), + p3.x(), + p3.y(), + rgba.x(), + rgba.y(), + rgba.z(), + rgba.w()); + } + void addTriangle(QVector2D p1, + QVector2D p2, + QVector2D p3, + QVector4D rgba1, + QVector4D rgba2, + QVector4D rgba3) { + addTriangle(p1.x(), + p1.y(), + p2.x(), + p2.y(), + p3.x(), + p3.y(), + rgba1.x(), + rgba1.y(), + rgba1.z(), + rgba1.w(), + rgba2.x(), + rgba2.y(), + rgba2.z(), + rgba2.w(), + rgba3.x(), + rgba3.y(), + rgba3.z(), + rgba3.w()); + } + + private: void addRectangle(float x1, float y1, float x2, float y2, float r, float g, float b, float a) { addTriangle(x1, y1, x2, y1, x1, y2, r, g, b, a); addTriangle(x1, y2, x2, y2, x2, y1, r, g, b, a); @@ -127,11 +169,6 @@ class rendergraph::RGBAVertexUpdater { *m_pWrite++ = Geometry::RGBAColoredPoint2D{x2, y2, r2, g2, b2, a2}; *m_pWrite++ = Geometry::RGBAColoredPoint2D{x3, y3, r3, g3, b3, a3}; } - int index() const { - return static_cast(m_pWrite - m_pData); - } - - private: Geometry::RGBAColoredPoint2D* const m_pData; Geometry::RGBAColoredPoint2D* m_pWrite; }; diff --git a/src/rendergraph/common/rendergraph/vertexupdaters/rgbvertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/rgbvertexupdater.h index e85f525a5ed..873de8efee6 100644 --- a/src/rendergraph/common/rendergraph/vertexupdaters/rgbvertexupdater.h +++ b/src/rendergraph/common/rendergraph/vertexupdaters/rgbvertexupdater.h @@ -51,6 +51,36 @@ class rendergraph::RGBVertexUpdater { rgbr.y(), rgbr.z()); } + void addTriangle(QVector2D p1, QVector2D p2, QVector2D p3, QVector3D rgb) { + addTriangle(p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y(), rgb.x(), rgb.y(), rgb.z()); + } + void addTriangle(QVector2D p1, + QVector2D p2, + QVector2D p3, + QVector3D rgb1, + QVector3D rgb2, + QVector3D rgb3) { + addTriangle(p1.x(), + p1.y(), + p2.x(), + p2.y(), + p3.x(), + p3.y(), + rgb1.x(), + rgb1.y(), + rgb1.z(), + rgb2.x(), + rgb2.y(), + rgb2.z(), + rgb3.x(), + rgb3.y(), + rgb3.z()); + } + int index() const { + return static_cast(m_pWrite - m_pData); + } + + private: void addRectangle(float x1, float y1, float x2, float y2, float r, float g, float b) { addTriangle(x1, y1, x2, y1, x1, y2, r, g, b); addTriangle(x1, y2, x2, y2, x2, y1, r, g, b); @@ -66,8 +96,8 @@ class rendergraph::RGBVertexUpdater { float r2, float g2, float b2) { - addTriangle(x1, y1, x2, y1, x1, y2, r1, g1, b1, r2, g2, b2, r1, g1, b1); - addTriangle(x1, y2, x2, y2, x2, y1, r1, g1, b1, r2, g2, b2, r2, g2, b2); + addTriangle(x1, y1, x2, y1, x1, y2, r1, g1, b1, r1, g1, b1, r2, g2, b2); + addTriangle(x1, y2, x2, y2, x2, y1, r2, g2, b2, r2, g2, b2, r1, g1, b1); } void addRectangleHGradient( float x1, @@ -105,11 +135,9 @@ class rendergraph::RGBVertexUpdater { float r1, float g1, float b1, - float r2, float g2, float b2, - float r3, float g3, float b3) { @@ -117,11 +145,6 @@ class rendergraph::RGBVertexUpdater { *m_pWrite++ = Geometry::RGBColoredPoint2D{x2, y2, r2, g2, b2}; *m_pWrite++ = Geometry::RGBColoredPoint2D{x3, y3, r3, g3, b3}; } - int index() const { - return static_cast(m_pWrite - m_pData); - } - - private: Geometry::RGBColoredPoint2D* const m_pData; Geometry::RGBColoredPoint2D* m_pWrite; }; diff --git a/src/rendergraph/common/rendergraph/vertexupdaters/texturedvertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/texturedvertexupdater.h index e754fb509a0..172302854c7 100644 --- a/src/rendergraph/common/rendergraph/vertexupdaters/texturedvertexupdater.h +++ b/src/rendergraph/common/rendergraph/vertexupdaters/texturedvertexupdater.h @@ -12,10 +12,38 @@ class rendergraph::TexturedVertexUpdater { : m_pData(pData), m_pWrite(pData) { } + void addRectangle( + QVector2D lt, QVector2D rb) { + addRectangle(lt.x(), lt.y(), rb.x(), rb.y(), 0.f, 0.f, 1.f, 1.f); + } void addRectangle( QVector2D lt, QVector2D rb, QVector2D tlr, QVector2D trb) { addRectangle(lt.x(), lt.y(), rb.x(), rb.y(), tlr.x(), tlr.y(), trb.x(), trb.y()); } + void addTriangle(QVector2D p1, + QVector2D p2, + QVector2D p3, + QVector2D tp1, + QVector2D tp2, + QVector2D tp3) { + addTriangle(p1.x(), + p1.y(), + p2.x(), + p2.y(), + p3.x(), + p3.y(), + tp1.x(), + tp1.y(), + tp2.x(), + tp2.y(), + tp3.x(), + tp3.y()); + } + int index() const { + return static_cast(m_pWrite - m_pData); + } + + private: void addRectangle( float x1, float y1, float x2, float y2, float tx1, float ty1, float tx2, float ty2) { addTriangle(x1, y1, x2, y1, x1, y2, tx1, ty1, tx2, ty1, tx1, ty2); @@ -37,11 +65,6 @@ class rendergraph::TexturedVertexUpdater { *m_pWrite++ = Geometry::TexturedPoint2D{x2, y2, tx2, ty2}; *m_pWrite++ = Geometry::TexturedPoint2D{x3, y3, tx3, ty3}; } - int index() const { - return static_cast(m_pWrite - m_pData); - } - - private: Geometry::TexturedPoint2D* const m_pData; Geometry::TexturedPoint2D* m_pWrite; }; diff --git a/src/rendergraph/common/rendergraph/vertexupdaters/vertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/vertexupdater.h index d98d40f8c19..0e2791cb0fe 100644 --- a/src/rendergraph/common/rendergraph/vertexupdaters/vertexupdater.h +++ b/src/rendergraph/common/rendergraph/vertexupdaters/vertexupdater.h @@ -14,6 +14,14 @@ class rendergraph::VertexUpdater { QVector2D lt, QVector2D rb) { addRectangle(lt.x(), lt.y(), rb.x(), rb.y()); } + void addTriangle(QVector2D p1, QVector2D p2, QVector2D p3) { + addTriangle(p1.x(), p1.y(), p2.x(), p2.y(), p3.x(), p3.y()); + } + int index() const { + return static_cast(m_pWrite - m_pData); + } + + private: void addRectangle( float x1, float y1, @@ -27,11 +35,6 @@ class rendergraph::VertexUpdater { *m_pWrite++ = Geometry::Point2D{x2, y2}; *m_pWrite++ = Geometry::Point2D{x3, y3}; } - int index() const { - return static_cast(m_pWrite - m_pData); - } - - private: Geometry::Point2D* const m_pData; Geometry::Point2D* m_pWrite; }; diff --git a/src/rendergraph/examples/common/examplenode.cpp b/src/rendergraph/examples/common/examplenode.cpp new file mode 100644 index 00000000000..62500521aaf --- /dev/null +++ b/src/rendergraph/examples/common/examplenode.cpp @@ -0,0 +1,52 @@ +#include "examplenode.h" + +#include +#include +#include + +#include "rendergraph/geometry.h" +#include "rendergraph/material/rgbmaterial.h" +#include "rendergraph/material/texturematerial.h" +#include "rendergraph/material/unicolormaterial.h" +#include "rendergraph/vertexupdaters/rgbvertexupdater.h" +#include "rendergraph/vertexupdaters/texturedvertexupdater.h" +#include "rendergraph/vertexupdaters/vertexupdater.h" + +using namespace rendergraph; + +ExampleNode::ExampleNode(rendergraph::Context* pContext) { + { + TreeNode::appendChildNode(std::make_unique()); + auto pNode = static_cast(TreeNode::lastChild()); + pNode->initForRectangles(1); + auto& material = dynamic_cast(pNode->material()); + material.setTexture(std::make_unique( + pContext, QImage(":/example/images/test.png"))); + TexturedVertexUpdater vertexUpdater{ + pNode->geometry().vertexDataAs()}; + vertexUpdater.addRectangle({0, 0}, {100, 100}, {0.f, 0.f}, {1.f, 1.f}); + } + { + TreeNode::appendChildNode(std::make_unique()); + auto pNode = static_cast(TreeNode::lastChild()); + pNode->initForRectangles(2); + pNode->material().setUniform(1, QColor(255, 127, 0)); + pNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + rendergraph::VertexUpdater vertexUpdater{ + pNode->geometry() + .vertexDataAs()}; + vertexUpdater.addRectangle({100, 100}, {160, 160}); + vertexUpdater.addRectangle({200, 160}, {240, 190}); + } + { + TreeNode::appendChildNode(std::make_unique()); + auto pNode = static_cast(TreeNode::lastChild()); + pNode->initForRectangles(2); + pNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + rendergraph::RGBVertexUpdater vertexUpdater{ + pNode->geometry().vertexDataAs()}; + vertexUpdater.addRectangle({300, 100}, {340, 140}, {1.f, 0.f, 0.5f}); + vertexUpdater.addRectangleHGradient( + {340, 100}, {440, 130}, {0.f, 1.f, 0.5f}, {0.5f, 0.f, 1.f}); + } +} diff --git a/src/rendergraph/examples/common/examplenode.h b/src/rendergraph/examples/common/examplenode.h new file mode 100644 index 00000000000..d46ec2979ab --- /dev/null +++ b/src/rendergraph/examples/common/examplenode.h @@ -0,0 +1,12 @@ +#include "rendergraph/geometrynode.h" +#include "rendergraph/node.h" +#include "rendergraph/texture.h" + +namespace rendergraph { +class ExampleNode; +} // namespace rendergraph + +class rendergraph::ExampleNode : public rendergraph::Node { + public: + ExampleNode(rendergraph::Context* pContext); +}; diff --git a/src/rendergraph/examples/common/examplenodes.cpp b/src/rendergraph/examples/common/examplenodes.cpp deleted file mode 100644 index 588b5a43ef4..00000000000 --- a/src/rendergraph/examples/common/examplenodes.cpp +++ /dev/null @@ -1,73 +0,0 @@ -#include "examplenodes.h" - -#include -#include -#include - -#include "rendergraph/geometry.h" -#include "rendergraph/material/endoftrackmaterial.h" -#include "rendergraph/material/texturematerial.h" - -using namespace rendergraph; - -ExampleNode1::ExampleNode1() { - setMaterial(std::make_unique()); - setGeometry(std::make_unique(EndOfTrackMaterial::attributes(), 4)); - - geometry().setAttributeValues(0, positionArray, 4); - geometry().setAttributeValues(1, horizontalGradientArray, 4); - - QColor color("red"); - material().setUniform(0, - QVector4D{color.redF(), - color.greenF(), - color.blueF(), - color.alphaF()}); -} - -ExampleNode2::ExampleNode2() { - setMaterial(std::make_unique()); - setGeometry(std::make_unique(EndOfTrackMaterial::attributes(), 4)); - - geometry().setAttributeValues(0, positionArray, 4); - geometry().setAttributeValues(1, horizontalGradientArray, 4); - - QColor color("blue"); - material().setUniform(0, - QVector4D{color.redF(), - color.greenF(), - color.blueF(), - color.alphaF()}); -} - -ExampleNode3::ExampleNode3() { - auto* m = new TextureMaterial; - - setMaterial(std::make_unique()); - setGeometry(std::make_unique(TextureMaterial::attributes(), 4)); - - geometry().setAttributeValues(0, positionArray, 4); - geometry().setAttributeValues(1, texcoordArray, 4); - - QMatrix4x4 matrix; - - matrix.scale(0.3); - material().setUniform(0, matrix); -} - -void ExampleNode3::setTexture(std::unique_ptr texture) { - dynamic_cast(material()).setTexture(std::move(texture)); -} - -ExampleTopNode::ExampleTopNode(rendergraph::Context& context) { - TreeNode::appendChildNode(std::make_unique()); - TreeNode::appendChildNode(std::make_unique()); - TreeNode::appendChildNode(std::make_unique()); - - { - QImage img(":/example/images/test.png"); - static_cast(TreeNode::lastChild()) - ->setTexture( - std::make_unique(context, img)); - } -} diff --git a/src/rendergraph/examples/common/examplenodes.h b/src/rendergraph/examples/common/examplenodes.h deleted file mode 100644 index ca0efe73223..00000000000 --- a/src/rendergraph/examples/common/examplenodes.h +++ /dev/null @@ -1,43 +0,0 @@ -#include "rendergraph/geometrynode.h" -#include "rendergraph/node.h" -#include "rendergraph/texture.h" - -namespace rendergraph { -class ExampleNode1; -class ExampleNode2; -class ExampleNode3; -class ExampleTopNode; -} // namespace rendergraph - -class rendergraph::ExampleNode1 : public rendergraph::GeometryNode { - public: - static constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; - static constexpr float verticalGradientArray[] = {1.f, 1.f, -1.f, -1.f}; - static constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; - - ExampleNode1(); -}; - -class rendergraph::ExampleNode2 : public rendergraph::GeometryNode { - public: - static constexpr float positionArray[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f}; - static constexpr float verticalGradientArray[] = {1.f, 1.f, 0.f, 0.f}; - static constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; - - ExampleNode2(); -}; - -class rendergraph::ExampleNode3 : public rendergraph::GeometryNode { - public: - static constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; - static constexpr float texcoordArray[] = {0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f}; - - ExampleNode3(); - - void setTexture(std::unique_ptr texture); -}; - -class rendergraph::ExampleTopNode : public rendergraph::Node { - public: - ExampleTopNode(rendergraph::Context& context); -}; diff --git a/src/rendergraph/examples/gl_example/CMakeLists.txt b/src/rendergraph/examples/gl_example/CMakeLists.txt index 42c52fa7052..a4f26976f73 100644 --- a/src/rendergraph/examples/gl_example/CMakeLists.txt +++ b/src/rendergraph/examples/gl_example/CMakeLists.txt @@ -1,7 +1,7 @@ qt_add_executable(gl_example window.cpp window.h main.cpp - ../common/examplenodes.cpp + ../common/examplenode.cpp ) set_target_properties(gl_example PROPERTIES diff --git a/src/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/examples/gl_example/window.cpp index dc0818edd4b..0eb1570c8f9 100644 --- a/src/rendergraph/examples/gl_example/window.cpp +++ b/src/rendergraph/examples/gl_example/window.cpp @@ -1,10 +1,11 @@ #include "window.h" -#include "examplenodes.h" +#include "examplenode.h" #include "rendergraph/context.h" #include "rendergraph/engine.h" Window::Window() { + resize(640, 480); } void Window::closeEvent(QCloseEvent*) { @@ -16,17 +17,16 @@ void Window::closeEvent(QCloseEvent*) { void Window::initializeGL() { rendergraph::Context context; - auto node = std::make_unique(context); - + auto node = std::make_unique(&context); m_pEngine = std::make_unique(std::move(node)); - m_pEngine->initialize(); } -void Window::resizeGL(int, int) { +void Window::resizeGL(int w, int h) { + m_pEngine->resize(w, h); } void Window::paintGL() { - glClearColor(0.f, 0.f, 0.f, 1.f); + glClearColor(0.f, 0.f, 1.f, 1.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); // qt scene graph uses premultiplied alpha color in the shader, diff --git a/src/rendergraph/examples/sg_example/CMakeLists.txt b/src/rendergraph/examples/sg_example/CMakeLists.txt index 94865f0fb16..249f0b80299 100644 --- a/src/rendergraph/examples/sg_example/CMakeLists.txt +++ b/src/rendergraph/examples/sg_example/CMakeLists.txt @@ -2,7 +2,7 @@ qt_add_executable(sg_example WIN32 MACOSX_BUNDLE customitem.cpp customitem.h main.cpp - ../common/examplenodes.cpp + ../common/examplenode.cpp ) target_link_libraries(sg_example PRIVATE diff --git a/src/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/examples/sg_example/customitem.cpp index 59b278cea4f..b1ddaa0efb5 100644 --- a/src/rendergraph/examples/sg_example/customitem.cpp +++ b/src/rendergraph/examples/sg_example/customitem.cpp @@ -1,15 +1,18 @@ #include "customitem.h" +#include #include #include #include #include #include -#include "examplenodes.h" +#include "examplenode.h" #include "rendergraph/context.h" -#include "rendergraph/engine.h" +#include "rendergraph/geometrynode.h" +#include "rendergraph/material/unicolormaterial.h" #include "rendergraph/node.h" +#include "rendergraph/vertexupdaters/vertexupdater.h" CustomItem::CustomItem(QQuickItem* parent) : QQuickItem(parent) { @@ -28,16 +31,22 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { QSGRectangleNode* bgNode; if (!node) { bgNode = window()->createRectangleNode(); - bgNode->setColor(QColor(0, 0, 0, 255)); + bgNode->setColor(QColor(0, 0, 255, 255)); bgNode->setRect(boundingRect()); - rendergraph::Context context(window()); + QSGGeometry* geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 3); + + geometry->vertexDataAsPoint2D()[0].set(10, 10); + geometry->vertexDataAsPoint2D()[1].set(100, 10); + geometry->vertexDataAsPoint2D()[2].set(10, 100); - auto pTopNode = std::make_unique(context); - bgNode->appendChildNode(pTopNode->backendNode()); + QSGFlatColorMaterial* material = new QSGFlatColorMaterial; + material->setColor(QColor(255, 0, 0)); + + rendergraph::Context context(window()); + m_pExampleNode = std::make_unique(&context); - m_pEngine = std::make_unique(std::move(pTopNode)); - m_pEngine->initialize(); + bgNode->appendChildNode(m_pExampleNode->backendNode()); node = bgNode; } else { @@ -46,7 +55,6 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { if (m_geometryChanged) { bgNode->setRect(boundingRect()); - m_pEngine->resize(boundingRect().width(), boundingRect().height()); m_geometryChanged = false; } diff --git a/src/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/examples/sg_example/customitem.h index 7abd81a0524..de574d2a626 100644 --- a/src/rendergraph/examples/sg_example/customitem.h +++ b/src/rendergraph/examples/sg_example/customitem.h @@ -2,10 +2,10 @@ #define CUSTOMITEM_H #include +#include namespace rendergraph { class Node; -class Engine; } class CustomItem : public QQuickItem { @@ -21,7 +21,9 @@ class CustomItem : public QQuickItem { void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override; bool m_geometryChanged{}; - std::unique_ptr m_pEngine; + + private: + std::unique_ptr m_pExampleNode; }; #endif // CUSTOMITEM_H diff --git a/src/rendergraph/examples/sg_example/qml/main.qml b/src/rendergraph/examples/sg_example/qml/main.qml index 2410ad1a560..22404c8553c 100644 --- a/src/rendergraph/examples/sg_example/qml/main.qml +++ b/src/rendergraph/examples/sg_example/qml/main.qml @@ -4,10 +4,17 @@ import RenderGraph Item { id: root - width: 640 - height: 480 + width: 680 + height: 520 CustomItem { - anchors.fill: parent + anchors.top: parent.top + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + anchors.topMargin: 20 + anchors.bottomMargin: 20 + anchors.leftMargin: 20 + anchors.rightMargin: 20 } } diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 015eea487dd..ad5bc67a660 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -1,10 +1,8 @@ add_library(rendergraph_gl -../common/engine.cpp ../common/node.cpp ../common/opacitynode.cpp ../common/rendergraph/attributeinit.h ../common/rendergraph/attributeset.h -../common/rendergraph/engine.h ../common/rendergraph/geometry.h ../common/rendergraph/geometrynode.h ../common/rendergraph/material.h @@ -58,6 +56,7 @@ material.cpp materialshader.cpp openglnode.cpp rendergraph/context.h +rendergraph/engine.h rendergraph/openglnode.h texture.cpp treenode.cpp diff --git a/src/rendergraph/opengl/backend/basegeometrynode.cpp b/src/rendergraph/opengl/backend/basegeometrynode.cpp index 14dcc4fc2e4..1bd22a97a0c 100644 --- a/src/rendergraph/opengl/backend/basegeometrynode.cpp +++ b/src/rendergraph/opengl/backend/basegeometrynode.cpp @@ -3,6 +3,7 @@ #include #include "backend/shadercache.h" +#include "rendergraph/engine.h" #include "rendergraph/geometrynode.h" #include "rendergraph/texture.h" @@ -19,13 +20,14 @@ GLenum toGlDrawingMode(Geometry::DrawingMode mode) { } } // namespace -void BaseGeometryNode::initializeBackend() { +void BaseGeometryNode::initialize() { initializeOpenGLFunctions(); GeometryNode* pThis = static_cast(this); pThis->material().setShader(ShaderCache::getShaderForMaterial(&pThis->material())); + pThis->material().setUniform(0, engine()->matrix()); } -void BaseGeometryNode::renderBackend() { +void BaseGeometryNode::render() { GeometryNode* pThis = static_cast(this); Geometry& geometry = pThis->geometry(); Material& material = pThis->material(); @@ -102,3 +104,9 @@ void BaseGeometryNode::renderBackend() { shader.release(); } + +void BaseGeometryNode::resize(int, int) { + assert(engine() != nullptr); + GeometryNode* pThis = static_cast(this); + pThis->material().setUniform(0, engine()->matrix()); +} diff --git a/src/rendergraph/opengl/backend/basegeometrynode.h b/src/rendergraph/opengl/backend/basegeometrynode.h index b215fa5dda3..2f44f95d8e4 100644 --- a/src/rendergraph/opengl/backend/basegeometrynode.h +++ b/src/rendergraph/opengl/backend/basegeometrynode.h @@ -14,6 +14,7 @@ class rendergraph::BaseGeometryNode : public rendergraph::BaseNode, BaseGeometryNode() = default; public: - void initializeBackend() override; - void renderBackend() override; + void initialize() override; + void render() override; + void resize(int w, int h) override; }; diff --git a/src/rendergraph/opengl/backend/basenode.h b/src/rendergraph/opengl/backend/basenode.h index 23c897c8316..03c06dc3bb8 100644 --- a/src/rendergraph/opengl/backend/basenode.h +++ b/src/rendergraph/opengl/backend/basenode.h @@ -1,7 +1,10 @@ #pragma once +#include + namespace rendergraph { class BaseNode; +class Engine; } class rendergraph::BaseNode { @@ -20,13 +23,20 @@ class rendergraph::BaseNode { } virtual void preprocess() { } - virtual void renderBackend() { + virtual void render() { + } + virtual void initialize() { + } + virtual void resize(int, int) { } - virtual void initializeBackend() { + void setEngine(Engine* engine) { + m_pEngine = engine; } - virtual void resizeBackend(int, int) { + Engine* engine() const { + return m_pEngine; } private: + Engine* m_pEngine{}; bool m_usePreprocess{}; }; diff --git a/src/rendergraph/opengl/backend/baseopenglnode.cpp b/src/rendergraph/opengl/backend/baseopenglnode.cpp index 1ba41569660..1d591e02a02 100644 --- a/src/rendergraph/opengl/backend/baseopenglnode.cpp +++ b/src/rendergraph/opengl/backend/baseopenglnode.cpp @@ -4,18 +4,18 @@ using namespace rendergraph; -void BaseOpenGLNode::initializeBackend() { +void BaseOpenGLNode::initialize() { initializeOpenGLFunctions(); OpenGLNode* pThis = static_cast(this); pThis->initializeGL(); } -void BaseOpenGLNode::renderBackend() { +void BaseOpenGLNode::render() { OpenGLNode* pThis = static_cast(this); pThis->paintGL(); } -void BaseOpenGLNode::resizeBackend(int w, int h) { +void BaseOpenGLNode::resize(int w, int h) { OpenGLNode* pThis = static_cast(this); pThis->resizeGL(w, h); } diff --git a/src/rendergraph/opengl/backend/baseopenglnode.h b/src/rendergraph/opengl/backend/baseopenglnode.h index 70c33642413..73bff2e81d9 100644 --- a/src/rendergraph/opengl/backend/baseopenglnode.h +++ b/src/rendergraph/opengl/backend/baseopenglnode.h @@ -14,7 +14,7 @@ class rendergraph::BaseOpenGLNode : public rendergraph::BaseNode, BaseOpenGLNode() = default; public: - void initializeBackend() override; - void renderBackend() override; - void resizeBackend(int w, int h) override; + void initialize() override; + void render() override; + void resize(int w, int h) override; }; diff --git a/src/rendergraph/opengl/engine.cpp b/src/rendergraph/opengl/engine.cpp index 6b8875dff81..132bfa231d7 100644 --- a/src/rendergraph/opengl/engine.cpp +++ b/src/rendergraph/opengl/engine.cpp @@ -1,28 +1,37 @@ #include "rendergraph/engine.h" + +#include #include using namespace rendergraph; -void Engine::addToEngine(TreeNode* pNode) { - assert(pNode->engine() == nullptr); +Engine::Engine(std::unique_ptr pNode) + : m_pTopNode(std::move(pNode)) { + add(m_pTopNode.get()); +} - pNode->setEngine(this); - m_pInitializeNodes.push_back(pNode); - if (pNode->backendNode()->usePreprocess()) { - m_pPreprocessNodes.push_back(pNode); - } - pNode = pNode->firstChild(); - while (pNode) { - if (pNode->engine() != this) { - addToEngine(pNode); +void Engine::add(TreeNode* pNode) { + assert(pNode->backendNode()->engine() == nullptr || pNode->backendNode()->engine() == this); + if (pNode->backendNode()->engine() == nullptr) { + pNode->backendNode()->setEngine(this); + m_pInitializeNodes.push_back(pNode); + if (pNode->backendNode()->usePreprocess()) { + m_pPreprocessNodes.push_back(pNode); + } + pNode = pNode->firstChild(); + while (pNode) { + add(pNode); + pNode = pNode->nextSibling(); } - pNode = pNode->nextSibling(); } } void Engine::render() { if (!m_pInitializeNodes.empty()) { - initialize(); + for (auto pNode : m_pInitializeNodes) { + pNode->backendNode()->initialize(); + } + m_pInitializeNodes.clear(); } if (!m_pTopNode->backendNode()->isSubtreeBlocked()) { render(m_pTopNode.get()); @@ -30,7 +39,7 @@ void Engine::render() { } void Engine::render(TreeNode* pNode) { - pNode->backendNode()->renderBackend(); + pNode->backendNode()->render(); pNode = pNode->firstChild(); while (pNode) { if (!pNode->backendNode()->isSubtreeBlocked()) { @@ -48,17 +57,20 @@ void Engine::preprocess() { } } -void Engine::initialize() { - for (auto pNode : m_pInitializeNodes) { - pNode->backendNode()->initializeBackend(); - pNode->initialize(); - } - m_pInitializeNodes.clear(); +void Engine::resize(int w, int h) { + m_matrix.setToIdentity(); + m_matrix.ortho(QRectF(0.0f, 0.0f, w, h)); + // TODO + // if (waveformRenderer->getOrientation() == Qt::Vertical) { + // matrix.rotate(90.f, 0.0f, 0.0f, 1.0f); + // matrix.translate(0.f, -waveformRenderer->getWidth() * ratio, 0.f); + //} + + resize(m_pTopNode.get(), w, h); } void Engine::resize(TreeNode* pNode, int w, int h) { - pNode->backendNode()->resizeBackend(w, h); - pNode->resize(w, h); + pNode->backendNode()->resize(w, h); pNode = pNode->firstChild(); while (pNode) { resize(pNode, w, h); diff --git a/src/rendergraph/common/rendergraph/engine.h b/src/rendergraph/opengl/rendergraph/engine.h similarity index 78% rename from src/rendergraph/common/rendergraph/engine.h rename to src/rendergraph/opengl/rendergraph/engine.h index fc5935fafd0..b86ab2411f0 100644 --- a/src/rendergraph/common/rendergraph/engine.h +++ b/src/rendergraph/opengl/rendergraph/engine.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -12,17 +13,19 @@ class Engine; class rendergraph::Engine { public: Engine(std::unique_ptr pNode); - void initialize(); void render(); void resize(int w, int h); void preprocess(); - void addToEngine(TreeNode* pNode); + void add(TreeNode* pNode); + const QMatrix4x4& matrix() const { + return m_matrix; + } private: - void initialize(TreeNode* pNode); void render(TreeNode* pNode); void resize(TreeNode* pNode, int, int); + QMatrix4x4 m_matrix; const std::unique_ptr m_pTopNode; std::vector m_pPreprocessNodes; std::vector m_pInitializeNodes; diff --git a/src/rendergraph/opengl/texture.cpp b/src/rendergraph/opengl/texture.cpp index 2ef65673e27..1bd10cf7742 100644 --- a/src/rendergraph/opengl/texture.cpp +++ b/src/rendergraph/opengl/texture.cpp @@ -18,7 +18,7 @@ QImage premultiplyAlpha(const QImage& image) { } } // namespace -Texture::Texture(Context& context, const QImage& image) +Texture::Texture(Context*, const QImage& image) : m_pTexture(std::make_unique(premultiplyAlpha(image))) { m_pTexture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); m_pTexture->setWrapMode(QOpenGLTexture::ClampToEdge); diff --git a/src/rendergraph/opengl/treenode.cpp b/src/rendergraph/opengl/treenode.cpp index 0b9436a3e5f..50f676bd489 100644 --- a/src/rendergraph/opengl/treenode.cpp +++ b/src/rendergraph/opengl/treenode.cpp @@ -1,5 +1,4 @@ #include "rendergraph/treenode.h" - #include "rendergraph/engine.h" using namespace rendergraph; @@ -9,9 +8,8 @@ void TreeNode::setUsePreprocess(bool value) { } void TreeNode::onAppendChildNode(TreeNode* pChild) { - if (engine() != nullptr && - engine() != pChild->engine()) { - engine()->addToEngine(pChild); + if (backendNode()->engine()) { + backendNode()->engine()->add(pChild); } } diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 1e26c6ef58c..0539eff855f 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -1,10 +1,8 @@ add_library(rendergraph_sg -../common/engine.cpp ../common/node.cpp ../common/opacitynode.cpp ../common/rendergraph/attributeinit.h ../common/rendergraph/attributeset.h -../common/rendergraph/engine.h ../common/rendergraph/geometry.h ../common/rendergraph/geometrynode.h ../common/rendergraph/material.h @@ -47,7 +45,6 @@ backend/basenode.h backend/baseopacitynode.h backend/basetexture.h context.cpp -engine.cpp geometry.cpp geometrynode.cpp material.cpp diff --git a/src/rendergraph/scenegraph/backend/basematerialshader.cpp b/src/rendergraph/scenegraph/backend/basematerialshader.cpp index b75fc8cdf98..a2de0a4b46b 100644 --- a/src/rendergraph/scenegraph/backend/basematerialshader.cpp +++ b/src/rendergraph/scenegraph/backend/basematerialshader.cpp @@ -9,7 +9,16 @@ using namespace rendergraph; bool BaseMaterialShader::updateUniformData(RenderState& state, QSGMaterial* newMaterial, QSGMaterial* oldMaterial) { - return static_cast(newMaterial)->updateUniformsByteArray(state.uniformData()); + bool result = static_cast(newMaterial)->updateUniformsByteArray(state.uniformData()); + QByteArray* buf = state.uniformData(); + + if (state.isMatrixDirty()) { + const QMatrix4x4 m = state.combinedMatrix(); + memcpy(buf->data(), m.constData(), 64); + result = true; + } + + return result; } // override for QSGMaterialShader; this function is called by the Qt scene graph to prepare use of diff --git a/src/rendergraph/scenegraph/engine.cpp b/src/rendergraph/scenegraph/engine.cpp deleted file mode 100644 index 9354e76e2d1..00000000000 --- a/src/rendergraph/scenegraph/engine.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "rendergraph/engine.h" - -#include - -using namespace rendergraph; - -void Engine::addToEngine(TreeNode* pNode) { - assert(pNode->engine() == nullptr); - - pNode->setEngine(this); - m_pInitializeNodes.push_back(pNode); - pNode = pNode->firstChild(); - while (pNode) { - if (pNode->engine() != this) { - addToEngine(pNode); - } - pNode = pNode->nextSibling(); - } -} - -void Engine::render() { - assert(false && "should not be called for scenegraph, rendering is handled by Qt"); -} - -void Engine::preprocess() { - assert(false && "should not be called for scenegraph, preprocess is handled by Qt"); -} - -void Engine::initialize() { - for (auto pNode : m_pInitializeNodes) { - pNode->initialize(); - } - m_pInitializeNodes.clear(); -} - -void Engine::resize(TreeNode* pNode, int w, int h) { - pNode->resize(w, h); - pNode = pNode->firstChild(); - while (pNode) { - resize(pNode, w, h); - pNode = pNode->nextSibling(); - } -} diff --git a/src/rendergraph/scenegraph/texture.cpp b/src/rendergraph/scenegraph/texture.cpp index 87bb2c2b557..76bdad4c893 100644 --- a/src/rendergraph/scenegraph/texture.cpp +++ b/src/rendergraph/scenegraph/texture.cpp @@ -3,8 +3,8 @@ using namespace rendergraph; -Texture::Texture(Context& context, const QImage& image) - : m_pTexture(context.window()->createTextureFromImage(image)) { +Texture::Texture(Context* pContext, const QImage& image) + : m_pTexture(pContext->window()->createTextureFromImage(image)) { } qint64 Texture::comparisonKey() const { diff --git a/src/waveform/renderers/allshader/digitsrenderer.cpp b/src/waveform/renderers/allshader/digitsrenderer.cpp index 156f3d9601f..ea8883e5fb8 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.cpp +++ b/src/waveform/renderers/allshader/digitsrenderer.cpp @@ -14,7 +14,6 @@ #include "rendergraph/geometry.h" #include "rendergraph/material/texturematerial.h" #include "rendergraph/vertexupdaters/texturedvertexupdater.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" // Render digits using a texture (generated) with digits with blurred dark outline @@ -72,8 +71,10 @@ float allshader::DigitsRenderNode::height() const { return m_height; } -void allshader::DigitsRenderNode::updateTexture( - float fontPointSize, float maxHeight, float devicePixelRatio) { +void allshader::DigitsRenderNode::updateTexture(rendergraph::Context* pContext, + float fontPointSize, + float maxHeight, + float devicePixelRatio) { if (fontPointSize == m_fontPointSize && maxHeight == m_maxHeight) { return; } @@ -207,12 +208,11 @@ void allshader::DigitsRenderNode::updateTexture( m_offset[NUM_CHARS] = 1.f; } - Context context; dynamic_cast(material()) - .setTexture(std::make_unique(context, image)); + .setTexture(std::make_unique(pContext, image)); } -void allshader::DigitsRenderNode::update(const QMatrix4x4& matrix, +void allshader::DigitsRenderNode::update( float x, float y, bool multiLine, @@ -243,8 +243,6 @@ void allshader::DigitsRenderNode::update(const QMatrix4x4& matrix, } DEBUG_ASSERT(reserved == vertexUpdater.index()); - - material().setUniform(0, matrix); } void allshader::DigitsRenderNode::clear() { diff --git a/src/waveform/renderers/allshader/digitsrenderer.h b/src/waveform/renderers/allshader/digitsrenderer.h index b55c72b884b..9e7c1884e45 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.h +++ b/src/waveform/renderers/allshader/digitsrenderer.h @@ -1,26 +1,28 @@ #pragma once -#include - +#include "rendergraph/context.h" #include "rendergraph/geometrynode.h" #include "util/class.h" namespace rendergraph { class TexturedVertexUpdater; -} +} // namespace rendergraph namespace allshader { class DigitsRenderNode; -} +} // namespace allshader class allshader::DigitsRenderNode : public rendergraph::GeometryNode { public: DigitsRenderNode(); ~DigitsRenderNode(); - void updateTexture(float fontPointSize, float maxHeight, float devicePixelRatio); + void updateTexture(rendergraph::Context* pContext, + float fontPointSize, + float maxHeight, + float devicePixelRatio); - void update(const QMatrix4x4& matrix, + void update( float x, float y, bool multiLine, diff --git a/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp b/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp index 250c2abbaf8..e69de29bb2d 100644 --- a/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp +++ b/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp @@ -1,8 +0,0 @@ -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" - -#include "waveform/renderers/waveformwidgetrenderer.h" - -QMatrix4x4 matrixForWidgetGeometry(WaveformWidgetRenderer* const waveformRenderer, - bool applyDevicePixelRatio) { - return waveformRenderer->getMatrix(applyDevicePixelRatio); -} diff --git a/src/waveform/renderers/allshader/waveformrenderbackground.cpp b/src/waveform/renderers/allshader/waveformrenderbackground.cpp index beddbc000a5..504beade43c 100644 --- a/src/waveform/renderers/allshader/waveformrenderbackground.cpp +++ b/src/waveform/renderers/allshader/waveformrenderbackground.cpp @@ -11,10 +11,10 @@ WaveformRenderBackground::WaveformRenderBackground( } void WaveformRenderBackground::setup(const QDomNode& node, - const SkinContext& context) { + const SkinContext& skinContext) { m_backgroundColor = m_waveformRenderer->getWaveformSignalColors()->getBgColor(); - QString backgroundPixmapPath = context.selectString(node, "BgPixmap"); + QString backgroundPixmapPath = skinContext.selectString(node, "BgPixmap"); if (!backgroundPixmapPath.isEmpty()) { qWarning() << "WaveformView BgPixmap is not supported by " "allshader::WaveformRenderBackground"; diff --git a/src/waveform/renderers/allshader/waveformrenderbackground.h b/src/waveform/renderers/allshader/waveformrenderbackground.h index 97c82c7d122..7567d2da7df 100644 --- a/src/waveform/renderers/allshader/waveformrenderbackground.h +++ b/src/waveform/renderers/allshader/waveformrenderbackground.h @@ -16,7 +16,7 @@ class allshader::WaveformRenderBackground final public: explicit WaveformRenderBackground(WaveformWidgetRenderer* waveformWidgetRenderer); - void setup(const QDomNode& node, const SkinContext& context) override; + void setup(const QDomNode& node, const SkinContext& skinContext) override; void paintGL() override; private: diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.cpp b/src/waveform/renderers/allshader/waveformrenderbeat.cpp index 5c35bdf30e6..aa7de4ecfe5 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.cpp +++ b/src/waveform/renderers/allshader/waveformrenderbeat.cpp @@ -7,7 +7,6 @@ #include "rendergraph/vertexupdaters/vertexupdater.h" #include "skin/legacy/skincontext.h" #include "track/track.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "widget/wskincolor.h" @@ -23,8 +22,8 @@ WaveformRenderBeat::WaveformRenderBeat(WaveformWidgetRenderer* waveformWidget, setUsePreprocess(true); } -void WaveformRenderBeat::setup(const QDomNode& node, const SkinContext& context) { - m_color = QColor(context.selectString(node, "BeatColor")); +void WaveformRenderBeat::setup(const QDomNode& node, const SkinContext& skinContext) { + m_color = QColor(skinContext.selectString(node, "BeatColor")); m_color = WSkinColor::getCorrectColor(m_color).toRgb(); } @@ -124,9 +123,6 @@ bool WaveformRenderBeat::preprocessInner() { DEBUG_ASSERT(reserved == vertexUpdater.index()); - const QMatrix4x4 matrix = m_waveformRenderer->getMatrix(false); - - material().setUniform(0, matrix); material().setUniform(1, m_color); markDirtyMaterial(); diff --git a/src/waveform/renderers/allshader/waveformrenderbeat.h b/src/waveform/renderers/allshader/waveformrenderbeat.h index c0c13126dc2..f14520d8d39 100644 --- a/src/waveform/renderers/allshader/waveformrenderbeat.h +++ b/src/waveform/renderers/allshader/waveformrenderbeat.h @@ -25,7 +25,7 @@ class allshader::WaveformRenderBeat final // Pure virtual from WaveformRendererAbstract, not used void draw(QPainter* painter, QPaintEvent* event) override final; - void setup(const QDomNode& node, const SkinContext& context) override; + void setup(const QDomNode& node, const SkinContext& skinContext) override; // Virtuals for rendergraph::Node void preprocess() override; diff --git a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp index 6b5b5f12f1c..6f4b92aa501 100644 --- a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp +++ b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp @@ -6,7 +6,9 @@ #include "control/controlproxy.h" #include "rendergraph/geometry.h" -#include "rendergraph/material/endoftrackmaterial.h" +#include "rendergraph/material/rgbamaterial.h" +#include "rendergraph/vertexupdaters/rgbavertexupdater.h" +#include "util/colorcomponents.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveformwidgetfactory.h" #include "widget/wskincolor.h" @@ -26,13 +28,8 @@ WaveformRendererEndOfTrack::WaveformRendererEndOfTrack( : ::WaveformRendererAbstract(waveformWidget), m_pEndOfTrackControl(nullptr), m_pTimeRemainingControl(nullptr) { - setGeometry(std::make_unique(EndOfTrackMaterial::attributes(), 4)); - setMaterial(std::make_unique()); + initForRectangles(0); setUsePreprocess(true); - - geometry().setAttributeValues(0, positionArray, 4); - geometry().setAttributeValues(1, horizontalGradientArray, 4); - material().setUniform(0, QVector4D{0.f, 0.f, 0.f, 0.f}); } void WaveformRendererEndOfTrack::draw(QPainter* painter, QPaintEvent* event) { @@ -52,9 +49,9 @@ bool WaveformRendererEndOfTrack::init() { return true; } -void WaveformRendererEndOfTrack::setup(const QDomNode& node, const SkinContext& context) { +void WaveformRendererEndOfTrack::setup(const QDomNode& node, const SkinContext& skinContext) { m_color = QColor(200, 25, 20); - const QString endOfTrackColorName = context.selectString(node, "EndOfTrackColor"); + const QString endOfTrackColorName = skinContext.selectString(node, "EndOfTrackColor"); if (!endOfTrackColorName.isNull()) { m_color = QColor(endOfTrackColorName); m_color = WSkinColor::getCorrectColor(m_color); @@ -76,11 +73,32 @@ void WaveformRendererEndOfTrack::preprocess() { const double alpha = criticalIntensity * blinkIntensity; if (alpha != 0.0) { - QColor color = m_color; - color.setAlphaF(static_cast(alpha)); - - material().setUniform(0, color); + QSizeF size(m_waveformRenderer->getWidth(), m_waveformRenderer->getHeight()); + float r, g, b, a; + getRgbF(m_color, &r, &g, &b, &a); + + const float posx0 = 0.f; + const float posx1 = size.width() / 2.f; + const float posx2 = size.width(); + const float posy1 = 0.f; + const float posy2 = size.height(); + + float minAlpha = 0.5f * static_cast(alpha); + float maxAlpha = 0.83f * static_cast(alpha); + + geometry().allocate(6 * 2); + RGBAVertexUpdater vertexUpdater{geometry().vertexDataAs()}; + vertexUpdater.addRectangleHGradient( + {posx0, posy1}, {posx1, posy2}, {r, g, b, minAlpha}, {r, g, b, minAlpha}); + vertexUpdater.addRectangleHGradient( + {posx1, posy1}, {posx2, posy2}, {r, g, b, minAlpha}, {r, g, b, maxAlpha}); + + markDirtyGeometry(); + } else if (geometry().vertexCount() != 0) { + geometry().allocate(0); + markDirtyGeometry(); } + markDirtyMaterial(); } bool WaveformRendererEndOfTrack::isSubtreeBlocked() const { diff --git a/src/waveform/renderers/allshader/waveformrendererendoftrack.h b/src/waveform/renderers/allshader/waveformrendererendoftrack.h index 9b7ec182de5..8f6d69f7262 100644 --- a/src/waveform/renderers/allshader/waveformrendererendoftrack.h +++ b/src/waveform/renderers/allshader/waveformrendererendoftrack.h @@ -27,7 +27,7 @@ class allshader::WaveformRendererEndOfTrack final // Pure virtual from WaveformRendererAbstract, not used void draw(QPainter* painter, QPaintEvent* event) override final; - void setup(const QDomNode& node, const SkinContext& context) override; + void setup(const QDomNode& node, const SkinContext& skinContext) override; bool init() override; @@ -36,10 +36,6 @@ class allshader::WaveformRendererEndOfTrack final bool isSubtreeBlocked() const override; private: - static constexpr float positionArray[] = {-1.f, -1.f, 1.f, -1.f, -1.f, 1.f, 1.f, 1.f}; - static constexpr float verticalGradientArray[] = {1.f, 1.f, -1.f, -1.f}; - static constexpr float horizontalGradientArray[] = {-1.f, 1.f, -1.f, 1.f}; - std::unique_ptr m_pEndOfTrackControl; std::unique_ptr m_pTimeRemainingControl; diff --git a/src/waveform/renderers/allshader/waveformrendererfiltered.cpp b/src/waveform/renderers/allshader/waveformrendererfiltered.cpp index f48b1136f59..4e626da1b80 100644 --- a/src/waveform/renderers/allshader/waveformrendererfiltered.cpp +++ b/src/waveform/renderers/allshader/waveformrendererfiltered.cpp @@ -2,7 +2,6 @@ #include "track/track.h" #include "util/math.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" @@ -142,7 +141,7 @@ void WaveformRendererFiltered::paintGL() { xVisualFrame += visualIncrementPerPixel; } - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); + const QMatrix4x4 matrix; // TODO = m_waveformRenderer->getMatrix(true); const int matrixLocation = m_shader.matrixLocation(); const int colorLocation = m_shader.colorLocation(); diff --git a/src/waveform/renderers/allshader/waveformrendererhsv.cpp b/src/waveform/renderers/allshader/waveformrendererhsv.cpp index 75b34dbae00..23b9ca8c1e9 100644 --- a/src/waveform/renderers/allshader/waveformrendererhsv.cpp +++ b/src/waveform/renderers/allshader/waveformrendererhsv.cpp @@ -3,7 +3,6 @@ #include "track/track.h" #include "util/colorcomponents.h" #include "util/math.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" @@ -179,7 +178,7 @@ void WaveformRendererHSV::paintGL() { DEBUG_ASSERT(reserved == m_vertices.size()); DEBUG_ASSERT(reserved == m_colors.size()); - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); + const QMatrix4x4 matrix; // TODO = m_waveformRenderer->getMatrix(true); const int matrixLocation = m_shader.matrixLocation(); const int positionLocation = m_shader.positionLocation(); diff --git a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp index 45bfd402608..47caa6f3300 100644 --- a/src/waveform/renderers/allshader/waveformrendererpreroll.cpp +++ b/src/waveform/renderers/allshader/waveformrendererpreroll.cpp @@ -4,12 +4,10 @@ #include #include -#include "rendergraph/context.h" #include "rendergraph/geometry.h" #include "rendergraph/material/patternmaterial.h" #include "rendergraph/vertexupdaters/texturedvertexupdater.h" #include "skin/legacy/skincontext.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "widget/wskincolor.h" @@ -78,8 +76,8 @@ WaveformRendererPreroll::WaveformRendererPreroll( WaveformRendererPreroll::~WaveformRendererPreroll() = default; void WaveformRendererPreroll::setup( - const QDomNode& node, const SkinContext& context) { - m_color = QColor(context.selectString(node, "SignalColor")); + const QDomNode& node, const SkinContext& skinContext) { + m_color = QColor(skinContext.selectString(node, "SignalColor")); m_color = WSkinColor::getCorrectColor(m_color); } @@ -91,7 +89,13 @@ void WaveformRendererPreroll::draw(QPainter* painter, QPaintEvent* event) { void WaveformRendererPreroll::preprocess() { if (!preprocessInner()) { - geometry().allocate(0); + if (geometry().vertexCount() != 0) { + geometry().allocate(0); + markDirtyGeometry(); + } + } else { + markDirtyMaterial(); + markDirtyGeometry(); } } @@ -147,9 +151,8 @@ bool WaveformRendererPreroll::preprocessInner() { // has changed size last time. m_markerLength = markerLength; m_markerBreadth = markerBreadth; - Context context; dynamic_cast(material()) - .setTexture(std::make_unique(context, + .setTexture(std::make_unique(m_waveformRenderer->getContext(), drawPrerollImage(m_markerLength, m_markerBreadth, m_waveformRenderer->getDevicePixelRatio(), @@ -211,10 +214,6 @@ bool WaveformRendererPreroll::preprocessInner() { DEBUG_ASSERT(reserved == vertexUpdater.index()); - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - - material().setUniform(0, matrix); - return true; } diff --git a/src/waveform/renderers/allshader/waveformrendererpreroll.h b/src/waveform/renderers/allshader/waveformrendererpreroll.h index 7e3f10ea628..eb28459ef96 100644 --- a/src/waveform/renderers/allshader/waveformrendererpreroll.h +++ b/src/waveform/renderers/allshader/waveformrendererpreroll.h @@ -27,7 +27,7 @@ class allshader::WaveformRendererPreroll final // Pure virtual from WaveformRendererAbstract, not used void draw(QPainter* painter, QPaintEvent* event) override final; - void setup(const QDomNode& node, const SkinContext& context) override; + void setup(const QDomNode& node, const SkinContext& skinContext) override; // Virtual for rendergraph::Node void preprocess() override; diff --git a/src/waveform/renderers/allshader/waveformrendererrgb.cpp b/src/waveform/renderers/allshader/waveformrendererrgb.cpp index 6e36e1d78b4..6dbc8d1752d 100644 --- a/src/waveform/renderers/allshader/waveformrendererrgb.cpp +++ b/src/waveform/renderers/allshader/waveformrendererrgb.cpp @@ -4,7 +4,6 @@ #include "rendergraph/vertexupdaters/rgbvertexupdater.h" #include "track/track.h" #include "util/math.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" @@ -34,7 +33,10 @@ void WaveformRendererRGB::onSetup(const QDomNode& node) { void WaveformRendererRGB::preprocess() { if (!preprocessInner()) { - geometry().allocate(0); + if (geometry().vertexCount() != 0) { + geometry().allocate(0); + markDirtyGeometry(); + } } } @@ -71,7 +73,10 @@ bool WaveformRendererRGB::preprocessInner() { #endif const float devicePixelRatio = m_waveformRenderer->getDevicePixelRatio(); - const int length = static_cast(m_waveformRenderer->getLength() * devicePixelRatio); + const int length = static_cast(m_waveformRenderer->getLength()); + const int pixelLength = static_cast(m_waveformRenderer->getLength() * devicePixelRatio); + const float invDevicePixelRatio = 1.f / devicePixelRatio; + const float halfPixelSize = 0.5 / devicePixelRatio; // See waveformrenderersimple.cpp for a detailed explanation of the frame and index calculation const int visualFramesSize = dataSize / 2; @@ -82,14 +87,14 @@ bool WaveformRendererRGB::preprocessInner() { // Represents the # of visual frames per horizontal pixel. const double visualIncrementPerPixel = - (lastVisualFrame - firstVisualFrame) / static_cast(length); + (lastVisualFrame - firstVisualFrame) / static_cast(pixelLength); // Per-band gain from the EQ knobs. float allGain(1.0), lowGain(1.0), midGain(1.0), highGain(1.0); // applyCompensation = false, as we scale to match filtered.all getGains(&allGain, false, &lowGain, &midGain, &highGain); - const float breadth = static_cast(m_waveformRenderer->getBreadth()) * devicePixelRatio; + const float breadth = static_cast(m_waveformRenderer->getBreadth()); const float halfBreadth = breadth / 2.0f; const float heightFactorAbs = allGain * halfBreadth / m_maxValue; @@ -114,23 +119,24 @@ bool WaveformRendererRGB::preprocessInner() { const int reserved = numVerticesPerLine * // Slip rendere only render a single channel, so the vertices count doesn't change - ((splitLeftRight && !m_isSlipRenderer ? length * 2 : length) + 1); + ((splitLeftRight && !m_isSlipRenderer ? pixelLength * 2 : pixelLength) + 1); + geometry().setDrawingMode(Geometry::DrawingMode::Triangles); geometry().allocate(reserved); - // TODO set dirty for scenegraph + markDirtyGeometry(); RGBVertexUpdater vertexUpdater{geometry().vertexDataAs()}; - vertexUpdater.addRectangle(0.f, - halfBreadth - 0.5f * devicePixelRatio, - static_cast(length), - m_isSlipRenderer ? halfBreadth : halfBreadth + 0.5f * devicePixelRatio, - static_cast(m_axesColor_r), - static_cast(m_axesColor_g), - static_cast(m_axesColor_b)); + vertexUpdater.addRectangle({0.f, + halfBreadth - 0.5f}, + {static_cast(length), + m_isSlipRenderer ? halfBreadth : halfBreadth + 0.5f}, + {static_cast(m_axesColor_r), + static_cast(m_axesColor_g), + static_cast(m_axesColor_b)}); const double maxSamplingRange = visualIncrementPerPixel / 2.0; - for (int pos = 0; pos < length; ++pos) { + for (int pos = 0; pos < pixelLength; ++pos) { const int visualFrameStart = std::lround(xVisualFrame - maxSamplingRange); const int visualFrameStop = std::lround(xVisualFrame + maxSamplingRange); @@ -138,7 +144,7 @@ bool WaveformRendererRGB::preprocessInner() { const int visualIndexStop = std::min(std::max(visualFrameStop, visualFrameStart + 1) * 2, dataSize - 1); - const float fpos = static_cast(pos); + const float fpos = static_cast(pos) * invDevicePixelRatio; // Find the max values for low, mid, high and all in the waveform data. // - Max of left and right @@ -221,25 +227,25 @@ bool WaveformRendererRGB::preprocessInner() { // Lines are thin rectangles if (!splitLeftRight) { - vertexUpdater.addRectangle(fpos - 0.5f, - halfBreadth - heightFactorAbs * maxAllChn[0], - fpos + 0.5f, - m_isSlipRenderer - ? halfBreadth - : halfBreadth + heightFactorAbs * maxAllChn[1], - red, - green, - blue); + vertexUpdater.addRectangle({fpos - halfPixelSize, + halfBreadth - heightFactorAbs * maxAllChn[0]}, + {fpos + halfPixelSize, + m_isSlipRenderer + ? halfBreadth + : halfBreadth + heightFactorAbs * maxAllChn[1]}, + {red, + green, + blue}); } else { // note: heightFactor is the same for left and right, // but negative for left (chn 0) and positive for right (chn 1) - vertexUpdater.addRectangle(fpos - 0.5f, - halfBreadth, - fpos + 0.5f, - halfBreadth + heightFactor[chn] * maxAllChn[chn], - red, - green, - blue); + vertexUpdater.addRectangle({fpos - halfPixelSize, + halfBreadth}, + {fpos + halfPixelSize, + halfBreadth + heightFactor[chn] * maxAllChn[chn]}, + {red, + green, + blue}); } } @@ -248,8 +254,7 @@ bool WaveformRendererRGB::preprocessInner() { DEBUG_ASSERT(reserved == vertexUpdater.index()); - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); - material().setUniform(0, matrix); + markDirtyMaterial(); return true; } diff --git a/src/waveform/renderers/allshader/waveformrenderersimple.cpp b/src/waveform/renderers/allshader/waveformrenderersimple.cpp index 90a707d2373..e2614091ea5 100644 --- a/src/waveform/renderers/allshader/waveformrenderersimple.cpp +++ b/src/waveform/renderers/allshader/waveformrenderersimple.cpp @@ -137,7 +137,7 @@ void WaveformRendererSimple::paintGL() { xVisualFrame += visualIncrementPerPixel; } - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); + const QMatrix4x4 matrix; // TODO = m_waveformRenderer->getMatrix(true); const int matrixLocation = m_shader.matrixLocation(); const int colorLocation = m_shader.colorLocation(); diff --git a/src/waveform/renderers/allshader/waveformrendererslipmode.cpp b/src/waveform/renderers/allshader/waveformrendererslipmode.cpp index 8ddf0be80e5..667b43f915c 100644 --- a/src/waveform/renderers/allshader/waveformrendererslipmode.cpp +++ b/src/waveform/renderers/allshader/waveformrendererslipmode.cpp @@ -43,19 +43,20 @@ bool WaveformRendererSlipMode::init() { return true; } -void WaveformRendererSlipMode::setup(const QDomNode& node, const SkinContext& context) { - const QString slipModeOutlineColorName = context.selectString(node, "SlipBorderOutlineColor"); +void WaveformRendererSlipMode::setup(const QDomNode& node, const SkinContext& skinContext) { + const QString slipModeOutlineColorName = + skinContext.selectString(node, "SlipBorderOutlineColor"); if (!slipModeOutlineColorName.isNull()) { m_color = WSkinColor::getCorrectColor(QColor(slipModeOutlineColorName)); } else { m_color = kDefaultColor; } - const float slipBorderTopOutlineSize = context.selectFloat( + const float slipBorderTopOutlineSize = skinContext.selectFloat( node, "SlipBorderTopOutlineSize", m_slipBorderTopOutlineSize); if (slipBorderTopOutlineSize >= 0) { m_slipBorderTopOutlineSize = slipBorderTopOutlineSize; } - const float slipBorderBottomOutlineSize = context.selectFloat( + const float slipBorderBottomOutlineSize = skinContext.selectFloat( node, "SlipBorderBottomOutlineSize", m_slipBorderBottomOutlineSize); if (slipBorderBottomOutlineSize >= 0) { m_slipBorderBottomOutlineSize = slipBorderBottomOutlineSize; diff --git a/src/waveform/renderers/allshader/waveformrendererslipmode.h b/src/waveform/renderers/allshader/waveformrendererslipmode.h index c5a8ce9e92c..b481142797f 100644 --- a/src/waveform/renderers/allshader/waveformrendererslipmode.h +++ b/src/waveform/renderers/allshader/waveformrendererslipmode.h @@ -24,7 +24,7 @@ class allshader::WaveformRendererSlipMode final explicit WaveformRendererSlipMode( WaveformWidgetRenderer* waveformWidget); - void setup(const QDomNode& node, const SkinContext& context) override; + void setup(const QDomNode& node, const SkinContext& skinContext) override; bool init() override; diff --git a/src/waveform/renderers/allshader/waveformrendererstem.cpp b/src/waveform/renderers/allshader/waveformrendererstem.cpp index c8dbe5a949c..42c7bf6c155 100644 --- a/src/waveform/renderers/allshader/waveformrendererstem.cpp +++ b/src/waveform/renderers/allshader/waveformrendererstem.cpp @@ -6,7 +6,6 @@ #include "track/track.h" #include "util/math.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/allshader/rgbdata.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" @@ -180,7 +179,7 @@ void WaveformRendererStem::paintGL() { DEBUG_ASSERT(reserved == m_vertices.size()); DEBUG_ASSERT(reserved == m_colors.size()); - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, true); + const QMatrix4x4 matrix; // TODO = m_waveformRenderer->getMatrix(true); const int matrixLocation = m_shader.matrixLocation(); const int positionLocation = m_shader.positionLocation(); diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index bbdd0535ded..aee310ced67 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -13,7 +13,6 @@ #include "track/track.h" #include "util/colorcomponents.h" #include "waveform/renderers/allshader/digitsrenderer.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveformwidgetfactory.h" @@ -32,21 +31,18 @@ class WaveformMarkNode : public rendergraph::GeometryNode { public: WaveformMark* m_pOwner{}; - WaveformMarkNode(WaveformMark* pOwner, const QImage& image) + WaveformMarkNode(WaveformMark* pOwner, rendergraph::Context* pContext, const QImage& image) : m_pOwner(pOwner) { initForRectangles(1); - updateTexture(image); + updateTexture(pContext, image); } - void updateTexture(const QImage& image) { - Context context; + void updateTexture(rendergraph::Context* pContext, const QImage& image) { dynamic_cast(material()) - .setTexture(std::make_unique(context, image)); + .setTexture(std::make_unique(pContext, image)); m_textureWidth = image.width(); m_textureHeight = image.height(); } - void update(const QMatrix4x4& matrix, float x, float y, float devicePixelRatio) { - material().setUniform(0, matrix); - + void update(float x, float y, float devicePixelRatio) { TexturedVertexUpdater vertexUpdater{ geometry().vertexDataAs()}; vertexUpdater.addRectangle({x, y}, @@ -69,14 +65,17 @@ class WaveformMarkNode : public rendergraph::GeometryNode { class WaveformMarkNodeGraphics : public WaveformMark::Graphics { public: - WaveformMarkNodeGraphics(WaveformMark* pOwner, const QImage& image) - : m_pNode(std::make_unique(pOwner, image)) { + WaveformMarkNodeGraphics(WaveformMark* pOwner, + rendergraph::Context* pContext, + const QImage& image) + : m_pNode(std::make_unique( + pOwner, pContext, image)) { } - void updateTexture(const QImage& image) { - waveformMarkNode()->updateTexture(image); + void updateTexture(rendergraph::Context* pContext, const QImage& image) { + waveformMarkNode()->updateTexture(pContext, image); } - void update(const QMatrix4x4& matrix, float x, float y, float devicePixelRatio) { - waveformMarkNode()->update(matrix, x, y, devicePixelRatio); + void update(float x, float y, float devicePixelRatio) { + waveformMarkNode()->update(x, y, devicePixelRatio); } float textureWidth() const { return waveformMarkNode()->textureWidth(); @@ -131,7 +130,9 @@ allshader::WaveformRenderMark::WaveformRenderMark( m_beatsUntilMark(0), m_timeUntilMark(0.0), m_pTimeRemainingControl(nullptr), - m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) { + m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip), + m_playPosHeight(0.f), + m_playPosDevicePixelRatio(0.f) { appendChildNode(std::make_unique()); m_pRangeNodesParent = lastChild(); @@ -158,20 +159,7 @@ bool allshader::WaveformRenderMark::init() { return true; } -void allshader::WaveformRenderMark::initialize() { - // Will create textures so requires OpenGL context - updateMarkImages(); - updatePlayPosMarkTexture(); - const auto untilMarkTextPointSize = - WaveformWidgetFactory::instance()->getUntilMarkTextPointSize(); - m_pDigitsRenderNode->updateTexture(untilMarkTextPointSize, - getMaxHeightForText(), - m_waveformRenderer->getDevicePixelRatio()); - Node::initialize(); -} - void allshader::WaveformRenderMark::updateRangeNode(GeometryNode* pNode, - const QMatrix4x4& matrix, const QRectF& rect, QColor color) { // draw a gradient towards transparency at the upper and lower 25% of the waveform view @@ -193,8 +181,6 @@ void allshader::WaveformRenderMark::updateRangeNode(GeometryNode* pNode, {posx1, posy1}, {posx2, posy2}, {r, g, b, a}, {r, g, b, 0.f}); vertexUpdater.addRectangleVGradient( {posx1, posy4}, {posx2, posy3}, {r, g, b, a}, {r, g, b, 0.f}); - - pNode->material().setUniform(0, matrix); } bool allshader::WaveformRenderMark::isSubtreeBlocked() const { @@ -238,13 +224,13 @@ void allshader::WaveformRenderMark::update() { : m_waveformRenderer->getBreadth()); } + updatePlayPosMarkTexture(m_waveformRenderer->getContext()); + // Generate initial node or update its texture if needed for each of // the WaveformMarks (in which case updateMarkImage is called) // (Will create textures so requires OpenGL context) updateMarkImages(); - QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - const double playPosition = m_waveformRenderer->getTruePosSample(positionType); double nextMarkPosition = std::numeric_limits::max(); @@ -292,7 +278,7 @@ void allshader::WaveformRenderMark::update() { if (drawOffset > -markHalfWidth && drawOffset < m_waveformRenderer->getLength() + markHalfWidth) { - pMarkNodeGraphics->update(matrix, + pMarkNodeGraphics->update( drawOffset, !m_isSlipRenderer && slipActive ? m_waveformRenderer->getBreadth() / 2 @@ -326,7 +312,6 @@ void allshader::WaveformRenderMark::update() { } updateRangeNode(static_cast(pRangeChild), - matrix, QRectF(QPointF(currentMarkPoint, 0), QPointF(currentMarkEndPoint, m_waveformRenderer->getBreadth())), @@ -364,8 +349,6 @@ void allshader::WaveformRenderMark::update() { const float markHalfWidth = 11.f / 2.f; const float drawOffset = currentMarkPoint - markHalfWidth; - m_pPlayPosNode->material().setUniform(0, matrix); - TexturedVertexUpdater vertexUpdater{ m_pPlayPosNode->geometry() .vertexDataAs()}; @@ -378,18 +361,19 @@ void allshader::WaveformRenderMark::update() { if (WaveformWidgetFactory::instance()->getUntilMarkShowBeats() || WaveformWidgetFactory::instance()->getUntilMarkShowTime()) { updateUntilMark(playPosition, nextMarkPosition); - drawUntilMark(matrix, currentMarkPoint + 20); + drawUntilMark(currentMarkPoint + 20); } } -void allshader::WaveformRenderMark::drawUntilMark(const QMatrix4x4& matrix, float x) { +void allshader::WaveformRenderMark::drawUntilMark(float x) { const bool untilMarkShowBeats = WaveformWidgetFactory::instance()->getUntilMarkShowBeats(); const bool untilMarkShowTime = WaveformWidgetFactory::instance()->getUntilMarkShowTime(); const auto untilMarkAlign = WaveformWidgetFactory::instance()->getUntilMarkAlign(); const auto untilMarkTextPointSize = WaveformWidgetFactory::instance()->getUntilMarkTextPointSize(); - m_pDigitsRenderNode->updateTexture(untilMarkTextPointSize, + m_pDigitsRenderNode->updateTexture(m_waveformRenderer->getContext(), + untilMarkTextPointSize, getMaxHeightForText(), m_waveformRenderer->getDevicePixelRatio()); @@ -417,7 +401,7 @@ void allshader::WaveformRenderMark::drawUntilMark(const QMatrix4x4& matrix, floa } } - m_pDigitsRenderNode->update(matrix, + m_pDigitsRenderNode->update( x, y, multiLine, @@ -428,13 +412,19 @@ void allshader::WaveformRenderMark::drawUntilMark(const QMatrix4x4& matrix, floa // Generate the texture used to draw the play position marker. // Note that in the legacy waveform widgets this is drawn directly // in the WaveformWidgetRenderer itself. Doing it here is cleaner. -void allshader::WaveformRenderMark::updatePlayPosMarkTexture() { +void allshader::WaveformRenderMark::updatePlayPosMarkTexture(rendergraph::Context* pContext) { float imgwidth; float imgheight; const float height = m_waveformRenderer->getBreadth(); const float devicePixelRatio = m_waveformRenderer->getDevicePixelRatio(); + if (height == m_playPosHeight && devicePixelRatio == m_playPosDevicePixelRatio) { + return; + } + m_playPosHeight = height; + m_playPosDevicePixelRatio = devicePixelRatio; + const float lineX = 5.5f; imgwidth = 11.f; @@ -489,9 +479,8 @@ void allshader::WaveformRenderMark::updatePlayPosMarkTexture() { } painter.end(); - Context context; dynamic_cast(m_pPlayPosNode->material()) - .setTexture(std::make_unique(context, image)); + .setTexture(std::make_unique(pContext, image)); } void allshader::WaveformRenderMark::drawTriangle(QPainter* painter, @@ -508,21 +497,18 @@ void allshader::WaveformRenderMark::drawTriangle(QPainter* painter, painter->fillPath(triangle, fillColor); } -void allshader::WaveformRenderMark::resize(int, int) { - // Will create textures so requires OpenGL context - updateMarkImages(); - updatePlayPosMarkTexture(); -} - void allshader::WaveformRenderMark::updateMarkImage(WaveformMarkPointer pMark) { if (!pMark->m_pGraphics) { pMark->m_pGraphics = std::make_unique(pMark.get(), + m_waveformRenderer->getContext(), pMark->generateImage( m_waveformRenderer->getDevicePixelRatio())); } else { auto pGraphics = static_cast(pMark->m_pGraphics.get()); - pGraphics->updateTexture(pMark->generateImage(m_waveformRenderer->getDevicePixelRatio())); + pGraphics->updateTexture(m_waveformRenderer->getContext(), + pMark->generateImage( + m_waveformRenderer->getDevicePixelRatio())); } } diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index 2eedbadc604..99fc56c9161 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -6,10 +6,10 @@ #include "waveform/renderers/waveformrendermarkbase.h" class QDomNode; -class SkinContext; namespace rendergraph { class GeometryNode; +class Context; } namespace allshader { @@ -31,15 +31,12 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, void update(); - // Virtual for rendergraph::Node - void initialize() override; - void resize(int, int) override; bool isSubtreeBlocked() const override; private: void updateMarkImage(WaveformMarkPointer pMark) override; - void updatePlayPosMarkTexture(); + void updatePlayPosMarkTexture(rendergraph::Context* pContext); void drawTriangle(QPainter* painter, const QBrush& fillColor, @@ -47,12 +44,10 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, QPointF p2, QPointF p3); - void drawMark(const QMatrix4x4& matrix, const QRectF& rect, QColor color); void updateUntilMark(double playPosition, double markerPosition); - void drawUntilMark(const QMatrix4x4& matrix, float x); + void drawUntilMark(float x); float getMaxHeightForText() const; void updateRangeNode(rendergraph::GeometryNode* pNode, - const QMatrix4x4& matrix, const QRectF& rect, QColor color); @@ -66,7 +61,11 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, rendergraph::TreeNode* m_pRangeNodesParent{}; rendergraph::TreeNode* m_pMarkNodesParent{}; + rendergraph::GeometryNode* m_pPlayPosNode; + float m_playPosHeight; + float m_playPosDevicePixelRatio; + DigitsRenderNode* m_pDigitsRenderNode{}; DISALLOW_COPY_AND_ASSIGN(WaveformRenderMark); diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index d7a77bfed1a..9c8444d9caf 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -5,7 +5,6 @@ #include "rendergraph/material/unicolormaterial.h" #include "rendergraph/vertexupdaters/vertexupdater.h" #include "skin/legacy/skincontext.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" using namespace rendergraph; @@ -16,7 +15,7 @@ WaveformRenderMarkRange::WaveformRenderMarkRange(WaveformWidgetRenderer* wavefor : ::WaveformRendererAbstract(waveformWidget) { } -void WaveformRenderMarkRange::setup(const QDomNode& node, const SkinContext& context) { +void WaveformRenderMarkRange::setup(const QDomNode& node, const SkinContext& skinContext) { m_markRanges.clear(); QDomNode child = node.firstChild(); @@ -26,7 +25,7 @@ void WaveformRenderMarkRange::setup(const QDomNode& node, const SkinContext& con WaveformMarkRange( m_waveformRenderer->getGroup(), child, - context, + skinContext, *m_waveformRenderer->getWaveformSignalColors())); } child = child.nextSibling(); @@ -40,8 +39,6 @@ void WaveformRenderMarkRange::draw(QPainter* painter, QPaintEvent* event) { } void WaveformRenderMarkRange::update() { - const QMatrix4x4 matrix = matrixForWidgetGeometry(m_waveformRenderer, false); - TreeNode* pChild = firstChild(); for (const auto& markRange : m_markRanges) { @@ -83,7 +80,6 @@ void WaveformRenderMarkRange::update() { } updateNode(static_cast(pChild), - matrix, color, {static_cast(startPosition), 0.f}, {static_cast(endPosition) + 1.f, @@ -99,14 +95,14 @@ void WaveformRenderMarkRange::update() { } void WaveformRenderMarkRange::updateNode(GeometryNode* pChild, - const QMatrix4x4& matrix, QColor color, QVector2D lt, QVector2D rb) { VertexUpdater vertexUpdater{pChild->geometry().vertexDataAs()}; vertexUpdater.addRectangle(lt, rb); - pChild->material().setUniform(0, matrix); pChild->material().setUniform(1, color); + pChild->markDirtyGeometry(); + pChild->markDirtyMaterial(); } } // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.h b/src/waveform/renderers/allshader/waveformrendermarkrange.h index 416f9fce03d..cabab1bb887 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.h +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -29,13 +28,12 @@ class allshader::WaveformRenderMarkRange final : public ::WaveformRendererAbstra // Pure virtual from WaveformRendererAbstract, not used void draw(QPainter* painter, QPaintEvent* event) override final; - void setup(const QDomNode& node, const SkinContext& context) override; + void setup(const QDomNode& node, const SkinContext& skinContext) override; void update(); private: void updateNode(rendergraph::GeometryNode* pChild, - const QMatrix4x4& matrix, QColor color, QVector2D lt, QVector2D rb); diff --git a/src/waveform/renderers/waveformwidgetrenderer.h b/src/waveform/renderers/waveformwidgetrenderer.h index 47cd21b67a6..3f61921d4e0 100644 --- a/src/waveform/renderers/waveformwidgetrenderer.h +++ b/src/waveform/renderers/waveformwidgetrenderer.h @@ -15,6 +15,10 @@ class VSyncThread; class QPainter; class WaveformRendererAbstract; +namespace rendergraph { +class Context; +} + class WaveformWidgetRenderer { public: static const double s_waveformMinZoom; @@ -192,6 +196,14 @@ class WaveformWidgetRenderer { return m_trackSamples <= 0.0 || m_pos[::WaveformRendererAbstract::Play] == -1; } + void setContext(rendergraph::Context* pContext) { + m_pContext = pContext; + } + + rendergraph::Context* getContext() const { + return m_pContext; + } + protected: const QString m_group; TrackPointer m_pTrack; @@ -227,6 +239,8 @@ class WaveformWidgetRenderer { double m_scaleFactor; double m_playMarkerPosition; // 0.0 - left, 0.5 - center, 1.0 - right + rendergraph::Context* m_pContext; + #ifdef WAVEFORMWIDGETRENDERER_DEBUG PerformanceTimer* m_timer; int m_lastFrameTime; diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index 37ffba98cdc..5f4ffdb180b 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -161,11 +161,18 @@ void WaveformWidget::castToQWidget() { } void WaveformWidget::initializeGL() { - m_pEngine->initialize(); +} + +void WaveformWidget::resizeRenderer(int, int, float) { + // defer to resizeGL } void WaveformWidget::resizeGL(int w, int h) { + w = static_cast(std::lroundf(static_cast(w) / devicePixelRatio())); + h = static_cast(std::lroundf(static_cast(h) / devicePixelRatio())); + m_pEngine->resize(w, h); + WaveformWidgetRenderer::resizeRenderer(w, h, devicePixelRatio()); } void WaveformWidget::paintEvent(QPaintEvent* event) { diff --git a/src/waveform/widgets/allshader/waveformwidget.h b/src/waveform/widgets/allshader/waveformwidget.h index 9bd57c608c8..347a347aabd 100644 --- a/src/waveform/widgets/allshader/waveformwidget.h +++ b/src/waveform/widgets/allshader/waveformwidget.h @@ -27,6 +27,8 @@ class allshader::WaveformWidget final : public ::WGLWidget, return m_type; } + void resizeRenderer(int width, int height, float devicePixelRatio) override; + // override for WaveformWidgetAbstract mixxx::Duration render() override; From 8011f6104e6e59e1ffeb984af997a158e857401b Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 20 Oct 2024 18:10:13 +0200 Subject: [PATCH 46/64] remove treenode --- src/rendergraph/common/node.cpp | 7 -- src/rendergraph/common/opacitynode.cpp | 7 -- .../common/rendergraph/geometrynode.h | 6 +- src/rendergraph/common/rendergraph/node.h | 8 +-- .../common/rendergraph/opacitynode.h | 9 +-- src/rendergraph/common/rendergraph/treenode.h | 65 ------------------ src/rendergraph/common/treenode.cpp | 50 -------------- .../examples/common/examplenode.cpp | 12 ++-- .../examples/gl_example/window.cpp | 4 +- .../examples/sg_example/customitem.cpp | 4 +- .../examples/sg_example/customitem.h | 7 +- src/rendergraph/opengl/CMakeLists.txt | 7 +- .../opengl/backend/basegeometrynode.h | 3 +- src/rendergraph/opengl/backend/basenode.h | 32 ++++++++- .../opengl/backend/baseopacitynode.h | 4 +- .../opengl/backend/baseopenglnode.cpp | 7 +- .../opengl/backend/baseopenglnode.h | 11 +++- src/rendergraph/opengl/engine.cpp | 66 +++++++++++++------ src/rendergraph/opengl/geometrynode.cpp | 6 +- src/rendergraph/opengl/openglnode.cpp | 7 -- src/rendergraph/opengl/rendergraph/engine.h | 17 +++-- .../opengl/rendergraph/openglnode.h | 16 +---- src/rendergraph/opengl/treenode.cpp | 20 ------ src/rendergraph/scenegraph/CMakeLists.txt | 5 -- src/rendergraph/scenegraph/geometrynode.cpp | 6 +- src/rendergraph/scenegraph/treenode.cpp | 19 ------ .../allshader/waveformrendermark.cpp | 66 +++++++++++-------- .../renderers/allshader/waveformrendermark.h | 4 +- .../allshader/waveformrendermarkrange.cpp | 17 ++--- .../renderers/waveformrendererabstract.h | 6 +- .../widgets/allshader/waveformwidget.cpp | 52 +++++++-------- 31 files changed, 203 insertions(+), 347 deletions(-) delete mode 100644 src/rendergraph/common/node.cpp delete mode 100644 src/rendergraph/common/opacitynode.cpp delete mode 100644 src/rendergraph/common/rendergraph/treenode.h delete mode 100644 src/rendergraph/common/treenode.cpp delete mode 100644 src/rendergraph/opengl/openglnode.cpp delete mode 100644 src/rendergraph/opengl/treenode.cpp delete mode 100644 src/rendergraph/scenegraph/treenode.cpp diff --git a/src/rendergraph/common/node.cpp b/src/rendergraph/common/node.cpp deleted file mode 100644 index 24f5d29d3ee..00000000000 --- a/src/rendergraph/common/node.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "rendergraph/node.h" - -using namespace rendergraph; - -Node::Node() - : TreeNode(this) { -} diff --git a/src/rendergraph/common/opacitynode.cpp b/src/rendergraph/common/opacitynode.cpp deleted file mode 100644 index caa6526626f..00000000000 --- a/src/rendergraph/common/opacitynode.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "rendergraph/opacitynode.h" - -using namespace rendergraph; - -OpacityNode::OpacityNode() - : TreeNode(this) { -} diff --git a/src/rendergraph/common/rendergraph/geometrynode.h b/src/rendergraph/common/rendergraph/geometrynode.h index 951c6e9b96c..28cf0437111 100644 --- a/src/rendergraph/common/rendergraph/geometrynode.h +++ b/src/rendergraph/common/rendergraph/geometrynode.h @@ -3,16 +3,15 @@ #include "backend/basegeometrynode.h" #include "rendergraph/geometry.h" #include "rendergraph/material.h" -#include "rendergraph/treenode.h" namespace rendergraph { class GeometryNode; } // namespace rendergraph -class rendergraph::GeometryNode : public rendergraph::BaseGeometryNode, - public rendergraph::TreeNode { +class rendergraph::GeometryNode : public rendergraph::BaseGeometryNode { public: GeometryNode(); + virtual ~GeometryNode() = default; template void initForRectangles(int numRectangles) { @@ -23,6 +22,7 @@ class rendergraph::GeometryNode : public rendergraph::BaseGeometryNode, geometry().setDrawingMode(Geometry::DrawingMode::Triangles); } + void setUsePreprocess(bool value); void setMaterial(std::unique_ptr material); void setGeometry(std::unique_ptr geometry); diff --git a/src/rendergraph/common/rendergraph/node.h b/src/rendergraph/common/rendergraph/node.h index 7ce62dd08cc..9c4c16ba818 100644 --- a/src/rendergraph/common/rendergraph/node.h +++ b/src/rendergraph/common/rendergraph/node.h @@ -1,13 +1,7 @@ #pragma once #include "backend/basenode.h" -#include "rendergraph/treenode.h" namespace rendergraph { -class Node; +using Node = BaseNode; } // namespace rendergraph - -class rendergraph::Node : public rendergraph::BaseNode, public rendergraph::TreeNode { - public: - Node(); -}; diff --git a/src/rendergraph/common/rendergraph/opacitynode.h b/src/rendergraph/common/rendergraph/opacitynode.h index ac64340520a..6beb1e86898 100644 --- a/src/rendergraph/common/rendergraph/opacitynode.h +++ b/src/rendergraph/common/rendergraph/opacitynode.h @@ -1,14 +1,7 @@ #pragma once #include "backend/baseopacitynode.h" -#include "rendergraph/treenode.h" namespace rendergraph { -class OpacityNode; +using OpacityNode = BaseOpacityNode; } // namespace rendergraph - -class rendergraph::OpacityNode : public rendergraph::BaseOpacityNode, - public rendergraph::TreeNode { - public: - OpacityNode(); -}; diff --git a/src/rendergraph/common/rendergraph/treenode.h b/src/rendergraph/common/rendergraph/treenode.h deleted file mode 100644 index 47752c1dc48..00000000000 --- a/src/rendergraph/common/rendergraph/treenode.h +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -#include - -#include "backend/basenode.h" - -namespace rendergraph { -class Engine; // fwd decl to avoid circular dependency -class TreeNode; -} // namespace rendergraph - -class rendergraph::TreeNode { - public: - TreeNode(rendergraph::BaseNode* pBackendNode) - : m_pBackendNode(pBackendNode) { - } - virtual ~TreeNode() = default; - - void appendChildNode(std::unique_ptr&& pChild); - - // remove all child nodes. returns the list of child nodes - // by returning the node in the list. the caller can keep - // the pointer, thus transferring ownership. otherwise the - // nodes will be destroyed - std::unique_ptr removeAllChildNodes(); - - // remove a single child node for the list of child nodes. - // the caller can keep the pointer, thus transferring ownership. - // otherwise the node will be destroyed - std::unique_ptr removeChildNode(TreeNode* pChild); - - TreeNode* parent() const { - return m_pParent; - } - TreeNode* firstChild() const { - return m_pFirstChild.get(); - } - TreeNode* lastChild() const { - return m_pLastChild; - } - TreeNode* nextSibling() const { - return m_pNextSibling.get(); - } - TreeNode* previousSibling() const { - return m_pPreviousSibling; - } - - void setUsePreprocess(bool value); - - rendergraph::BaseNode* backendNode() { - return m_pBackendNode; - } - - private: - void onAppendChildNode(TreeNode* pChild); - void onRemoveAllChildNodes(); - void onRemoveChildNode(TreeNode* pChild); - - rendergraph::BaseNode* m_pBackendNode; - TreeNode* m_pParent{}; - std::unique_ptr m_pFirstChild; - TreeNode* m_pLastChild{}; - std::unique_ptr m_pNextSibling; - TreeNode* m_pPreviousSibling{}; -}; diff --git a/src/rendergraph/common/treenode.cpp b/src/rendergraph/common/treenode.cpp deleted file mode 100644 index 63fe5667ffc..00000000000 --- a/src/rendergraph/common/treenode.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "rendergraph/treenode.h" - -#include "backend/basenode.h" - -using namespace rendergraph; - -void TreeNode::appendChildNode(std::unique_ptr&& pChild) { - auto pChildRawPtr = pChild.get(); - if (m_pLastChild) { - pChild->m_pPreviousSibling = m_pLastChild; - m_pLastChild->m_pNextSibling = std::move(pChild); - } else { - m_pFirstChild = std::move(pChild); - } - m_pLastChild = pChildRawPtr; - m_pLastChild->m_pParent = this; - - onAppendChildNode(pChildRawPtr); -} - -std::unique_ptr TreeNode::removeAllChildNodes() { - onRemoveAllChildNodes(); - - m_pLastChild = nullptr; - TreeNode* pChild = m_pFirstChild.get(); - while (pChild) { - pChild->m_pParent = nullptr; - pChild = pChild->m_pNextSibling.get(); - } - return std::move(m_pFirstChild); -} - -std::unique_ptr TreeNode::removeChildNode(TreeNode* pChild) { - onRemoveChildNode(pChild); - - std::unique_ptr pRemoved; - if (pChild == m_pFirstChild.get()) { - pRemoved = std::move(m_pFirstChild); - m_pFirstChild = std::move(pChild->m_pNextSibling); - } else { - pRemoved = std::move(pChild->m_pPreviousSibling->m_pNextSibling); - pChild->m_pPreviousSibling->m_pNextSibling = std::move(pChild->m_pNextSibling); - pChild->m_pPreviousSibling = nullptr; - } - if (pChild == m_pLastChild) { - m_pLastChild = nullptr; - } - pChild->m_pParent = nullptr; - return pRemoved; -} diff --git a/src/rendergraph/examples/common/examplenode.cpp b/src/rendergraph/examples/common/examplenode.cpp index 62500521aaf..4ba6f9fa5ab 100644 --- a/src/rendergraph/examples/common/examplenode.cpp +++ b/src/rendergraph/examples/common/examplenode.cpp @@ -16,8 +16,7 @@ using namespace rendergraph; ExampleNode::ExampleNode(rendergraph::Context* pContext) { { - TreeNode::appendChildNode(std::make_unique()); - auto pNode = static_cast(TreeNode::lastChild()); + auto pNode = std::make_unique(); pNode->initForRectangles(1); auto& material = dynamic_cast(pNode->material()); material.setTexture(std::make_unique( @@ -25,10 +24,10 @@ ExampleNode::ExampleNode(rendergraph::Context* pContext) { TexturedVertexUpdater vertexUpdater{ pNode->geometry().vertexDataAs()}; vertexUpdater.addRectangle({0, 0}, {100, 100}, {0.f, 0.f}, {1.f, 1.f}); + appendChildNode(pNode.release()); } { - TreeNode::appendChildNode(std::make_unique()); - auto pNode = static_cast(TreeNode::lastChild()); + auto pNode = std::make_unique(); pNode->initForRectangles(2); pNode->material().setUniform(1, QColor(255, 127, 0)); pNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); @@ -37,10 +36,10 @@ ExampleNode::ExampleNode(rendergraph::Context* pContext) { .vertexDataAs()}; vertexUpdater.addRectangle({100, 100}, {160, 160}); vertexUpdater.addRectangle({200, 160}, {240, 190}); + appendChildNode(pNode.release()); } { - TreeNode::appendChildNode(std::make_unique()); - auto pNode = static_cast(TreeNode::lastChild()); + auto pNode = std::make_unique(); pNode->initForRectangles(2); pNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); rendergraph::RGBVertexUpdater vertexUpdater{ @@ -48,5 +47,6 @@ ExampleNode::ExampleNode(rendergraph::Context* pContext) { vertexUpdater.addRectangle({300, 100}, {340, 140}, {1.f, 0.f, 0.5f}); vertexUpdater.addRectangleHGradient( {340, 100}, {440, 130}, {0.f, 1.f, 0.5f}, {0.5f, 0.f, 1.f}); + appendChildNode(pNode.release()); } } diff --git a/src/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/examples/gl_example/window.cpp index 0eb1570c8f9..32378895a09 100644 --- a/src/rendergraph/examples/gl_example/window.cpp +++ b/src/rendergraph/examples/gl_example/window.cpp @@ -17,8 +17,8 @@ void Window::closeEvent(QCloseEvent*) { void Window::initializeGL() { rendergraph::Context context; - auto node = std::make_unique(&context); - m_pEngine = std::make_unique(std::move(node)); + auto pExampleNode = std::make_unique(&context); + m_pEngine = std::make_unique(pExampleNode.release()); } void Window::resizeGL(int w, int h) { diff --git a/src/rendergraph/examples/sg_example/customitem.cpp b/src/rendergraph/examples/sg_example/customitem.cpp index b1ddaa0efb5..720e6723278 100644 --- a/src/rendergraph/examples/sg_example/customitem.cpp +++ b/src/rendergraph/examples/sg_example/customitem.cpp @@ -44,9 +44,9 @@ QSGNode* CustomItem::updatePaintNode(QSGNode* node, UpdatePaintNodeData*) { material->setColor(QColor(255, 0, 0)); rendergraph::Context context(window()); - m_pExampleNode = std::make_unique(&context); + auto pExampleNode = std::make_unique(&context); - bgNode->appendChildNode(m_pExampleNode->backendNode()); + bgNode->appendChildNode(pExampleNode.release()); node = bgNode; } else { diff --git a/src/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/examples/sg_example/customitem.h index de574d2a626..86f8e19f813 100644 --- a/src/rendergraph/examples/sg_example/customitem.h +++ b/src/rendergraph/examples/sg_example/customitem.h @@ -4,9 +4,7 @@ #include #include -namespace rendergraph { -class Node; -} +#include "rendergraph/node.h" class CustomItem : public QQuickItem { Q_OBJECT @@ -21,9 +19,6 @@ class CustomItem : public QQuickItem { void geometryChange(const QRectF& newGeometry, const QRectF& oldGeometry) override; bool m_geometryChanged{}; - - private: - std::unique_ptr m_pExampleNode; }; #endif // CUSTOMITEM_H diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index ad5bc67a660..9501c2b2b15 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -1,6 +1,4 @@ add_library(rendergraph_gl -../common/node.cpp -../common/opacitynode.cpp ../common/rendergraph/attributeinit.h ../common/rendergraph/attributeset.h ../common/rendergraph/geometry.h @@ -23,14 +21,12 @@ add_library(rendergraph_gl ../common/rendergraph/node.h ../common/rendergraph/opacitynode.h ../common/rendergraph/texture.h -../common/rendergraph/treenode.h ../common/rendergraph/types.h ../common/rendergraph/uniform.h ../common/rendergraph/uniformscache.cpp ../common/rendergraph/uniformscache.h ../common/rendergraph/uniformset.cpp ../common/rendergraph/uniformset.h -../common/treenode.cpp ../common/types.cpp attributeset.cpp backend/baseattributeset.cpp @@ -44,6 +40,7 @@ backend/basematerial.h backend/basematerialshader.cpp backend/basematerialtype.h backend/basenode.h +backend/basenode.cpp backend/baseopacitynode.h backend/baseopenglnode.cpp backend/baseopenglnode.h @@ -54,12 +51,10 @@ geometry.cpp geometrynode.cpp material.cpp materialshader.cpp -openglnode.cpp rendergraph/context.h rendergraph/engine.h rendergraph/openglnode.h texture.cpp -treenode.cpp ) target_link_libraries(rendergraph_gl PUBLIC diff --git a/src/rendergraph/opengl/backend/basegeometrynode.h b/src/rendergraph/opengl/backend/basegeometrynode.h index 2f44f95d8e4..a795a67b134 100644 --- a/src/rendergraph/opengl/backend/basegeometrynode.h +++ b/src/rendergraph/opengl/backend/basegeometrynode.h @@ -10,8 +10,9 @@ class BaseGeometryNode; class rendergraph::BaseGeometryNode : public rendergraph::BaseNode, public QOpenGLFunctions { - protected: + public: BaseGeometryNode() = default; + virtual ~BaseGeometryNode() = default; public: void initialize() override; diff --git a/src/rendergraph/opengl/backend/basenode.h b/src/rendergraph/opengl/backend/basenode.h index 03c06dc3bb8..5ca86197a87 100644 --- a/src/rendergraph/opengl/backend/basenode.h +++ b/src/rendergraph/opengl/backend/basenode.h @@ -8,11 +8,11 @@ class Engine; } class rendergraph::BaseNode { - protected: + public: BaseNode() = default; + virtual ~BaseNode(); - public: - void setUsePreprocessFlag(bool value) { + void setUsePreprocess(bool value) { m_usePreprocess = value; } bool usePreprocess() const { @@ -36,7 +36,33 @@ class rendergraph::BaseNode { return m_pEngine; } + void appendChildNode(BaseNode* pChild); + void removeAllChildNodes(); + void removeChildNode(BaseNode* pChild); + + BaseNode* parent() const { + return m_pParent; + } + BaseNode* firstChild() const { + return m_pFirstChild; + } + BaseNode* lastChild() const { + return m_pLastChild; + } + BaseNode* nextSibling() const { + return m_pNextSibling; + } + BaseNode* previousSibling() const { + return m_pPreviousSibling; + } + private: Engine* m_pEngine{}; bool m_usePreprocess{}; + + BaseNode* m_pParent{}; + BaseNode* m_pFirstChild{}; + BaseNode* m_pLastChild{}; + BaseNode* m_pNextSibling{}; + BaseNode* m_pPreviousSibling{}; }; diff --git a/src/rendergraph/opengl/backend/baseopacitynode.h b/src/rendergraph/opengl/backend/baseopacitynode.h index e07f7d141fb..8917dfb10da 100644 --- a/src/rendergraph/opengl/backend/baseopacitynode.h +++ b/src/rendergraph/opengl/backend/baseopacitynode.h @@ -7,10 +7,10 @@ class BaseOpacityNode; } class rendergraph::BaseOpacityNode : public rendergraph::BaseNode { - protected: + public: BaseOpacityNode() = default; + virtual ~BaseOpacityNode() = default; - public: void setOpacity(float opacity) { m_opacity = opacity; } diff --git a/src/rendergraph/opengl/backend/baseopenglnode.cpp b/src/rendergraph/opengl/backend/baseopenglnode.cpp index 1d591e02a02..165275448cb 100644 --- a/src/rendergraph/opengl/backend/baseopenglnode.cpp +++ b/src/rendergraph/opengl/backend/baseopenglnode.cpp @@ -6,16 +6,15 @@ using namespace rendergraph; void BaseOpenGLNode::initialize() { initializeOpenGLFunctions(); - OpenGLNode* pThis = static_cast(this); - pThis->initializeGL(); + initializeGL(); } void BaseOpenGLNode::render() { OpenGLNode* pThis = static_cast(this); - pThis->paintGL(); + paintGL(); } void BaseOpenGLNode::resize(int w, int h) { OpenGLNode* pThis = static_cast(this); - pThis->resizeGL(w, h); + resizeGL(w, h); } diff --git a/src/rendergraph/opengl/backend/baseopenglnode.h b/src/rendergraph/opengl/backend/baseopenglnode.h index 73bff2e81d9..641d286b65e 100644 --- a/src/rendergraph/opengl/backend/baseopenglnode.h +++ b/src/rendergraph/opengl/backend/baseopenglnode.h @@ -10,11 +10,18 @@ class BaseOpenGLNode; class rendergraph::BaseOpenGLNode : public rendergraph::BaseNode, public QOpenGLFunctions { - protected: + public: BaseOpenGLNode() = default; + virtual ~BaseOpenGLNode() = default; - public: void initialize() override; void render() override; void resize(int w, int h) override; + + virtual void initializeGL() { + } + virtual void paintGL() { + } + virtual void resizeGL(int, int) { + } }; diff --git a/src/rendergraph/opengl/engine.cpp b/src/rendergraph/opengl/engine.cpp index 132bfa231d7..04e4b43337f 100644 --- a/src/rendergraph/opengl/engine.cpp +++ b/src/rendergraph/opengl/engine.cpp @@ -5,17 +5,21 @@ using namespace rendergraph; -Engine::Engine(std::unique_ptr pNode) - : m_pTopNode(std::move(pNode)) { - add(m_pTopNode.get()); +Engine::Engine(BaseNode* pRootNode) + : m_pRootNode(pRootNode) { + add(m_pRootNode); } -void Engine::add(TreeNode* pNode) { - assert(pNode->backendNode()->engine() == nullptr || pNode->backendNode()->engine() == this); - if (pNode->backendNode()->engine() == nullptr) { - pNode->backendNode()->setEngine(this); +Engine::~Engine() { + delete m_pRootNode; +} + +void Engine::add(BaseNode* pNode) { + assert(pNode->engine() == nullptr || pNode->engine() == this); + if (pNode->engine() == nullptr) { + pNode->setEngine(this); m_pInitializeNodes.push_back(pNode); - if (pNode->backendNode()->usePreprocess()) { + if (pNode->usePreprocess()) { m_pPreprocessNodes.push_back(pNode); } pNode = pNode->firstChild(); @@ -26,23 +30,45 @@ void Engine::add(TreeNode* pNode) { } } +void Engine::remove(BaseNode* pNode) { + assert(pNode->engine() == this); + pNode->setEngine(nullptr); + + { + auto it = std::find(m_pInitializeNodes.begin(), m_pInitializeNodes.end(), pNode); + if (it != m_pInitializeNodes.end()) { + m_pInitializeNodes.erase(it); + } + } + { + auto it = std::find(m_pPreprocessNodes.begin(), m_pPreprocessNodes.end(), pNode); + if (it != m_pPreprocessNodes.end()) { + m_pPreprocessNodes.erase(it); + } + } + + if (m_pRootNode == pNode) { + m_pRootNode = nullptr; + } +} + void Engine::render() { if (!m_pInitializeNodes.empty()) { for (auto pNode : m_pInitializeNodes) { - pNode->backendNode()->initialize(); + pNode->initialize(); } m_pInitializeNodes.clear(); } - if (!m_pTopNode->backendNode()->isSubtreeBlocked()) { - render(m_pTopNode.get()); + if (m_pRootNode && !m_pRootNode->isSubtreeBlocked()) { + render(m_pRootNode); } } -void Engine::render(TreeNode* pNode) { - pNode->backendNode()->render(); +void Engine::render(BaseNode* pNode) { + pNode->render(); pNode = pNode->firstChild(); while (pNode) { - if (!pNode->backendNode()->isSubtreeBlocked()) { + if (!pNode->isSubtreeBlocked()) { render(pNode); } pNode = pNode->nextSibling(); @@ -51,8 +77,8 @@ void Engine::render(TreeNode* pNode) { void Engine::preprocess() { for (auto pNode : m_pPreprocessNodes) { - if (!pNode->backendNode()->isSubtreeBlocked()) { - pNode->backendNode()->preprocess(); + if (!pNode->isSubtreeBlocked()) { + pNode->preprocess(); } } } @@ -66,11 +92,13 @@ void Engine::resize(int w, int h) { // matrix.translate(0.f, -waveformRenderer->getWidth() * ratio, 0.f); //} - resize(m_pTopNode.get(), w, h); + if (m_pRootNode) { + resize(m_pRootNode, w, h); + } } -void Engine::resize(TreeNode* pNode, int w, int h) { - pNode->backendNode()->resize(w, h); +void Engine::resize(BaseNode* pNode, int w, int h) { + pNode->resize(w, h); pNode = pNode->firstChild(); while (pNode) { resize(pNode, w, h); diff --git a/src/rendergraph/opengl/geometrynode.cpp b/src/rendergraph/opengl/geometrynode.cpp index 1af643cb8e2..7c5020974bc 100644 --- a/src/rendergraph/opengl/geometrynode.cpp +++ b/src/rendergraph/opengl/geometrynode.cpp @@ -2,8 +2,10 @@ using namespace rendergraph; -GeometryNode::GeometryNode() - : TreeNode(this) { +GeometryNode::GeometryNode() = default; + +void GeometryNode::setUsePreprocess(bool value) { + BaseNode::setUsePreprocess(value); } void GeometryNode::setGeometry(std::unique_ptr pGeometry) { diff --git a/src/rendergraph/opengl/openglnode.cpp b/src/rendergraph/opengl/openglnode.cpp deleted file mode 100644 index c9e3e17ff87..00000000000 --- a/src/rendergraph/opengl/openglnode.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "rendergraph/openglnode.h" - -using namespace rendergraph; - -OpenGLNode::OpenGLNode() - : TreeNode(this) { -} diff --git a/src/rendergraph/opengl/rendergraph/engine.h b/src/rendergraph/opengl/rendergraph/engine.h index b86ab2411f0..e96912b54c0 100644 --- a/src/rendergraph/opengl/rendergraph/engine.h +++ b/src/rendergraph/opengl/rendergraph/engine.h @@ -12,21 +12,24 @@ class Engine; class rendergraph::Engine { public: - Engine(std::unique_ptr pNode); + Engine(BaseNode* pRootNode); + ~Engine(); + void render(); void resize(int w, int h); void preprocess(); - void add(TreeNode* pNode); + void add(BaseNode* pNode); + void remove(BaseNode* pNode); const QMatrix4x4& matrix() const { return m_matrix; } private: - void render(TreeNode* pNode); - void resize(TreeNode* pNode, int, int); + void render(BaseNode* pNode); + void resize(BaseNode* pNode, int, int); QMatrix4x4 m_matrix; - const std::unique_ptr m_pTopNode; - std::vector m_pPreprocessNodes; - std::vector m_pInitializeNodes; + BaseNode* m_pRootNode{}; + std::vector m_pPreprocessNodes; + std::vector m_pInitializeNodes; }; diff --git a/src/rendergraph/opengl/rendergraph/openglnode.h b/src/rendergraph/opengl/rendergraph/openglnode.h index 5cb3497edb3..7499312cb08 100644 --- a/src/rendergraph/opengl/rendergraph/openglnode.h +++ b/src/rendergraph/opengl/rendergraph/openglnode.h @@ -1,21 +1,7 @@ #pragma once #include "backend/baseopenglnode.h" -#include "rendergraph/treenode.h" namespace rendergraph { -class OpenGLNode; +using OpenGLNode = BaseOpenGLNode; } // namespace rendergraph - -class rendergraph::OpenGLNode : public rendergraph::BaseOpenGLNode, - public rendergraph::TreeNode { - public: - OpenGLNode(); - - virtual void initializeGL() { - } - virtual void paintGL() { - } - virtual void resizeGL(int, int) { - } -}; diff --git a/src/rendergraph/opengl/treenode.cpp b/src/rendergraph/opengl/treenode.cpp deleted file mode 100644 index 50f676bd489..00000000000 --- a/src/rendergraph/opengl/treenode.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "rendergraph/treenode.h" -#include "rendergraph/engine.h" - -using namespace rendergraph; - -void TreeNode::setUsePreprocess(bool value) { - backendNode()->setUsePreprocessFlag(value); -} - -void TreeNode::onAppendChildNode(TreeNode* pChild) { - if (backendNode()->engine()) { - backendNode()->engine()->add(pChild); - } -} - -void TreeNode::onRemoveChildNode(TreeNode*) { -} - -void TreeNode::onRemoveAllChildNodes() { -} diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 0539eff855f..45c22885c13 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -1,6 +1,4 @@ add_library(rendergraph_sg -../common/node.cpp -../common/opacitynode.cpp ../common/rendergraph/attributeinit.h ../common/rendergraph/attributeset.h ../common/rendergraph/geometry.h @@ -23,14 +21,12 @@ add_library(rendergraph_sg ../common/rendergraph/node.h ../common/rendergraph/opacitynode.h ../common/rendergraph/texture.h -../common/rendergraph/treenode.h ../common/rendergraph/types.h ../common/rendergraph/uniform.h ../common/rendergraph/uniformscache.cpp ../common/rendergraph/uniformscache.h ../common/rendergraph/uniformset.cpp ../common/rendergraph/uniformset.h -../common/treenode.cpp ../common/types.cpp attributeset.cpp backend/baseattributeset.cpp @@ -51,7 +47,6 @@ material.cpp materialshader.cpp rendergraph/context.h texture.cpp -treenode.cpp ) target_link_libraries(rendergraph_sg PUBLIC diff --git a/src/rendergraph/scenegraph/geometrynode.cpp b/src/rendergraph/scenegraph/geometrynode.cpp index 59455ed9e8f..21196f2b8a3 100644 --- a/src/rendergraph/scenegraph/geometrynode.cpp +++ b/src/rendergraph/scenegraph/geometrynode.cpp @@ -2,8 +2,10 @@ using namespace rendergraph; -GeometryNode::GeometryNode() - : TreeNode(this) { +GeometryNode::GeometryNode() = default; + +void GeometryNode::setUsePreprocess(bool value) { + setFlag(QSGNode::UsePreprocess, value); } void GeometryNode::setGeometry(std::unique_ptr pGeometry) { diff --git a/src/rendergraph/scenegraph/treenode.cpp b/src/rendergraph/scenegraph/treenode.cpp deleted file mode 100644 index 904afe7b0be..00000000000 --- a/src/rendergraph/scenegraph/treenode.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "rendergraph/treenode.h" - -using namespace rendergraph; - -void TreeNode::setUsePreprocess(bool value) { - backendNode()->setFlag(QSGNode::UsePreprocess, value); -} - -void TreeNode::onAppendChildNode(TreeNode* pChild) { - backendNode()->appendChildNode(pChild->backendNode()); -} - -void TreeNode::onRemoveChildNode(TreeNode* pChild) { - backendNode()->removeChildNode(pChild->backendNode()); -} - -void TreeNode::onRemoveAllChildNodes() { - backendNode()->removeAllChildNodes(); -} diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index aee310ced67..6d3b5d250a1 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -83,11 +83,11 @@ class WaveformMarkNodeGraphics : public WaveformMark::Graphics { float textureHeight() const { return waveformMarkNode()->textureHeight(); } - void setNode(std::unique_ptr&& pNode) { + void setNode(std::unique_ptr&& pNode) { m_pNode = std::move(pNode); } - void moveNodeToChildrenOf(TreeNode* pParent) { - pParent->appendChildNode(std::move(m_pNode)); + void moveNodeToChildrenOf(Node* pParent) { + pParent->appendChildNode(m_pNode.release()); } private: @@ -95,7 +95,7 @@ class WaveformMarkNodeGraphics : public WaveformMark::Graphics { return static_cast(m_pNode.get()); } - std::unique_ptr m_pNode; + std::unique_ptr m_pNode; }; // Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive @@ -133,18 +133,30 @@ allshader::WaveformRenderMark::WaveformRenderMark( m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip), m_playPosHeight(0.f), m_playPosDevicePixelRatio(0.f) { - appendChildNode(std::make_unique()); - m_pRangeNodesParent = lastChild(); + { + auto pNode = std::make_unique(); + m_pRangeNodesParent = pNode.get(); + appendChildNode(pNode.release()); + } - appendChildNode(std::make_unique()); - m_pMarkNodesParent = lastChild(); + { + auto pNode = std::make_unique(); + m_pMarkNodesParent = pNode.get(); + appendChildNode(pNode.release()); + } - appendChildNode(std::make_unique()); - m_pDigitsRenderNode = static_cast(lastChild()); + { + auto pNode = std::make_unique(); + m_pDigitsRenderNode = pNode.get(); + appendChildNode(pNode.release()); + } - appendChildNode(std::make_unique()); - m_pPlayPosNode = static_cast(lastChild()); - m_pPlayPosNode->initForRectangles(1); + { + auto pNode = std::make_unique(); + m_pPlayPosNode = pNode.get(); + m_pPlayPosNode->initForRectangles(1); + appendChildNode(pNode.release()); + } } void allshader::WaveformRenderMark::draw(QPainter* painter, QPaintEvent* event) { @@ -202,14 +214,13 @@ void allshader::WaveformRenderMark::update() { // (transferring ownership). Later in this function we move the // visible nodes back to m_pMarkNodesParent children. while (auto pChild = m_pMarkNodesParent->firstChild()) { - // Pop child from front of m_pMarkNodesParent - auto pRemoved = m_pMarkNodesParent->removeChildNode(pChild); + std::unique_ptr pNode(static_cast(pChild)); + m_pMarkNodesParent->removeChildNode(pNode.get()); // Determine its WaveformMark - auto pMarkNode = static_cast(pRemoved.get()); - auto pMark = pMarkNode->m_pOwner; + auto pMark = pNode->m_pOwner; auto pGraphics = static_cast(pMark->m_pGraphics.get()); // Store the node with the WaveformMark - pGraphics->setNode(std::move(pRemoved)); + pGraphics->setNode(std::move(pNode)); } auto positionType = m_isSlipRenderer ? ::WaveformRendererAbstract::Slip @@ -234,7 +245,7 @@ void allshader::WaveformRenderMark::update() { const double playPosition = m_waveformRenderer->getTruePosSample(positionType); double nextMarkPosition = std::numeric_limits::max(); - TreeNode* pRangeChild = m_pRangeNodesParent->firstChild(); + GeometryNode* pRangeChild = static_cast(m_pRangeNodesParent->firstChild()); for (const auto& pMark : std::as_const(m_marks)) { if (!pMark->isValid()) { @@ -306,19 +317,20 @@ void allshader::WaveformRenderMark::update() { // Reuse, or create new when needed if (!pRangeChild) { - m_pRangeNodesParent->appendChildNode(std::make_unique()); - pRangeChild = m_pRangeNodesParent->lastChild(); - static_cast(pRangeChild)->initForRectangles(2); + auto pNode = std::make_unique(); + pNode->initForRectangles(2); + pRangeChild = pNode.get(); + m_pRangeNodesParent->appendChildNode(pNode.release()); } - updateRangeNode(static_cast(pRangeChild), + updateRangeNode(pRangeChild, QRectF(QPointF(currentMarkPoint, 0), QPointF(currentMarkEndPoint, m_waveformRenderer->getBreadth())), color); visible = true; - pRangeChild = pRangeChild->nextSibling(); + pRangeChild = static_cast(pRangeChild->nextSibling()); } } @@ -331,9 +343,9 @@ void allshader::WaveformRenderMark::update() { // Remove unused nodes while (pRangeChild) { - auto pNext = static_cast(pRangeChild->nextSibling()); - m_pRangeNodesParent->removeChildNode(pRangeChild); - pRangeChild = pNext; + auto pNode = std::unique_ptr(pRangeChild); + m_pRangeNodesParent->removeChildNode(pNode.get()); + pRangeChild = static_cast(pRangeChild->nextSibling()); } m_waveformRenderer->setMarkPositions(marksOnScreen); diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index 99fc56c9161..a1b8078d525 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -59,8 +59,8 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, bool m_isSlipRenderer; - rendergraph::TreeNode* m_pRangeNodesParent{}; - rendergraph::TreeNode* m_pMarkNodesParent{}; + rendergraph::Node* m_pRangeNodesParent{}; + rendergraph::Node* m_pMarkNodesParent{}; rendergraph::GeometryNode* m_pPlayPosNode; float m_playPosHeight; diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index 9c8444d9caf..de2bddb06bb 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -39,7 +39,7 @@ void WaveformRenderMarkRange::draw(QPainter* painter, QPaintEvent* event) { } void WaveformRenderMarkRange::update() { - TreeNode* pChild = firstChild(); + GeometryNode* pChild = static_cast(firstChild()); for (const auto& markRange : m_markRanges) { // If the mark range is not active we should not draw it. @@ -74,12 +74,13 @@ void WaveformRenderMarkRange::update() { color.setAlphaF(0.3f); if (!pChild) { - appendChildNode(std::make_unique()); - pChild = lastChild(); - static_cast(pChild)->initForRectangles(1); + auto pNode = std::make_unique(); + pChild = pNode.get(); + pChild->initForRectangles(1); + appendChildNode(pNode.release()); } - updateNode(static_cast(pChild), + updateNode(pChild, color, {static_cast(startPosition), 0.f}, {static_cast(endPosition) + 1.f, @@ -88,9 +89,9 @@ void WaveformRenderMarkRange::update() { pChild = static_cast(pChild->nextSibling()); } while (pChild) { - auto pNext = pChild->nextSibling(); - removeChildNode(pChild); - pChild = pNext; + std::unique_ptr pNode(pChild); + removeChildNode(pNode.get()); + pChild = static_cast(pChild->nextSibling()); } } diff --git a/src/waveform/renderers/waveformrendererabstract.h b/src/waveform/renderers/waveformrendererabstract.h index 9d4f84a629e..62ab0a3930e 100644 --- a/src/waveform/renderers/waveformrendererabstract.h +++ b/src/waveform/renderers/waveformrendererabstract.h @@ -2,14 +2,12 @@ #include +#include "rendergraph/node.h" + QT_FORWARD_DECLARE_CLASS(QDomNode) QT_FORWARD_DECLARE_CLASS(QPaintEvent) QT_FORWARD_DECLARE_CLASS(QPainter) -namespace rendergraph { -class Node; -} - class SkinContext; class WaveformWidgetRenderer; diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index 5f4ffdb180b..09235798a11 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -20,16 +20,6 @@ #include "waveform/renderers/allshader/waveformrendermarkrange.h" #include "waveform/widgets/allshader/moc_waveformwidget.cpp" -namespace { -void appendChildTo(std::unique_ptr& pNode, rendergraph::TreeNode* pChild) { - pNode->appendChildNode(std::unique_ptr(pChild)); -} -void appendChildTo(std::unique_ptr& pNode, - rendergraph::TreeNode* pChild) { - pNode->appendChildNode(std::unique_ptr(pChild)); -} -} // namespace - namespace allshader { WaveformWidget::WaveformWidget(QWidget* parent, @@ -40,47 +30,51 @@ WaveformWidget::WaveformWidget(QWidget* parent, auto pTopNode = std::make_unique(); auto pOpacityNode = std::make_unique(); - appendChildTo(pTopNode, addRenderer()); - appendChildTo(pOpacityNode, addRenderer()); - appendChildTo(pOpacityNode, addRenderer()); + pTopNode->appendChildNode(addRenderer()); + pOpacityNode->appendChildNode(addRenderer()); + pOpacityNode->appendChildNode(addRenderer()); m_pWaveformRenderMarkRange = addRenderer(); - appendChildTo(pOpacityNode, m_pWaveformRenderMarkRange); + pOpacityNode->appendChildNode(m_pWaveformRenderMarkRange); #ifdef __STEM__ // The following two renderers work in tandem: if the rendered waveform is // for a stem track, WaveformRendererSignalBase will skip rendering and let // WaveformRendererStem do the rendering, and vice-versa. - appendChildTo(pOpacityNode, addRenderer()); + pOpacityNode->appendChildNode(addRenderer()); #endif allshader::WaveformRendererSignalBase* waveformSignalRenderer = addWaveformSignalRenderer( type, options, ::WaveformRendererAbstract::Play); - appendChildTo(pOpacityNode, dynamic_cast(waveformSignalRenderer)); - - appendChildTo(pOpacityNode, addRenderer()); + auto pNode = dynamic_cast(waveformSignalRenderer); + if (pNode) { + pOpacityNode->appendChildNode(pNode); + } + pOpacityNode->appendChildNode(addRenderer()); m_pWaveformRenderMark = addRenderer(); - appendChildTo(pOpacityNode, m_pWaveformRenderMark); + pOpacityNode->appendChildNode(m_pWaveformRenderMark); // if the signal renderer supports slip, we add it again, now for slip, together with the // other slip renderers if (waveformSignalRenderer && waveformSignalRenderer->supportsSlip()) { // The following renderer will add an overlay waveform if a slip is in progress - appendChildTo(pOpacityNode, addRenderer()); - appendChildTo(pOpacityNode, + pOpacityNode->appendChildNode(addRenderer()); + pOpacityNode->appendChildNode( addRenderer( ::WaveformRendererAbstract::Slip)); #ifdef __STEM__ - appendChildTo(pOpacityNode, + pOpacityNode->appendChildNode( addRenderer( ::WaveformRendererAbstract::Slip)); #endif - appendChildTo(pOpacityNode, - dynamic_cast(addWaveformSignalRenderer( - type, options, ::WaveformRendererAbstract::Slip))); - appendChildTo(pOpacityNode, + auto pNode = dynamic_cast(addWaveformSignalRenderer( + type, options, ::WaveformRendererAbstract::Slip)); + if (pNode) { + pOpacityNode->appendChildNode(pNode); + } + pOpacityNode->appendChildNode( addRenderer( ::WaveformRendererAbstract::Slip)); - appendChildTo(pOpacityNode, + pOpacityNode->appendChildNode( addRenderer( ::WaveformRendererAbstract::Slip)); } @@ -88,9 +82,9 @@ WaveformWidget::WaveformWidget(QWidget* parent, m_initSuccess = init(); m_pOpacityNode = pOpacityNode.get(); - pTopNode->appendChildNode(std::move(pOpacityNode)); + pTopNode->appendChildNode(pOpacityNode.release()); - m_pEngine = std::make_unique(std::move(pTopNode)); + m_pEngine = std::make_unique(pTopNode.release()); } WaveformWidget::~WaveformWidget() { From 6b2442d7bacdfda7a9221a9fb41fb9a975689a65 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 20 Oct 2024 20:50:56 +0200 Subject: [PATCH 47/64] add nodeinterface for unique_ptr ownership methods --- .../common/rendergraph/geometrynode.h | 3 +- src/rendergraph/common/rendergraph/node.h | 6 +- .../common/rendergraph/nodeinterface.h | 19 +++++ .../common/rendergraph/opacitynode.h | 6 +- src/rendergraph/opengl/engine.cpp | 15 ++-- src/rendergraph/opengl/rendergraph/engine.h | 4 +- .../allshader/waveformrendermark.cpp | 32 +++++---- .../allshader/waveformrendermarkrange.cpp | 5 +- .../widgets/allshader/waveformwidget.cpp | 72 ++++++++++++------- .../widgets/allshader/waveformwidget.h | 12 +++- 10 files changed, 119 insertions(+), 55 deletions(-) create mode 100644 src/rendergraph/common/rendergraph/nodeinterface.h diff --git a/src/rendergraph/common/rendergraph/geometrynode.h b/src/rendergraph/common/rendergraph/geometrynode.h index 28cf0437111..96dc6798962 100644 --- a/src/rendergraph/common/rendergraph/geometrynode.h +++ b/src/rendergraph/common/rendergraph/geometrynode.h @@ -3,12 +3,13 @@ #include "backend/basegeometrynode.h" #include "rendergraph/geometry.h" #include "rendergraph/material.h" +#include "rendergraph/nodeinterface.h" namespace rendergraph { class GeometryNode; } // namespace rendergraph -class rendergraph::GeometryNode : public rendergraph::BaseGeometryNode { +class rendergraph::GeometryNode : public rendergraph::NodeInterface { public: GeometryNode(); virtual ~GeometryNode() = default; diff --git a/src/rendergraph/common/rendergraph/node.h b/src/rendergraph/common/rendergraph/node.h index 9c4c16ba818..3060648e846 100644 --- a/src/rendergraph/common/rendergraph/node.h +++ b/src/rendergraph/common/rendergraph/node.h @@ -1,7 +1,11 @@ #pragma once #include "backend/basenode.h" +#include "rendergraph/nodeinterface.h" namespace rendergraph { -using Node = BaseNode; +class Node; } // namespace rendergraph + +class rendergraph::Node : public rendergraph::NodeInterface { +}; diff --git a/src/rendergraph/common/rendergraph/nodeinterface.h b/src/rendergraph/common/rendergraph/nodeinterface.h new file mode 100644 index 00000000000..4b2d08f4d49 --- /dev/null +++ b/src/rendergraph/common/rendergraph/nodeinterface.h @@ -0,0 +1,19 @@ +#pragma once + +#include "backend/basenode.h" + +namespace rendergraph { + +template +class NodeInterface : public T_Node { + public: + void appendChildNode(std::unique_ptr&& pNode) { + T_Node::appendChildNode(pNode.release()); + } + std::unique_ptr detachChildNode(BaseNode* pNode) { + T_Node::removeChildNode(pNode); + return std::unique_ptr(pNode); + } +}; + +} // namespace rendergraph diff --git a/src/rendergraph/common/rendergraph/opacitynode.h b/src/rendergraph/common/rendergraph/opacitynode.h index 6beb1e86898..d69f0b1c42a 100644 --- a/src/rendergraph/common/rendergraph/opacitynode.h +++ b/src/rendergraph/common/rendergraph/opacitynode.h @@ -1,7 +1,11 @@ #pragma once #include "backend/baseopacitynode.h" +#include "rendergraph/nodeinterface.h" namespace rendergraph { -using OpacityNode = BaseOpacityNode; +class OpacityNode; } // namespace rendergraph + +class rendergraph::OpacityNode : public rendergraph::NodeInterface { +}; diff --git a/src/rendergraph/opengl/engine.cpp b/src/rendergraph/opengl/engine.cpp index 04e4b43337f..c5202918155 100644 --- a/src/rendergraph/opengl/engine.cpp +++ b/src/rendergraph/opengl/engine.cpp @@ -5,13 +5,12 @@ using namespace rendergraph; -Engine::Engine(BaseNode* pRootNode) - : m_pRootNode(pRootNode) { - add(m_pRootNode); +Engine::Engine(std::unique_ptr pRootNode) + : m_pRootNode(std::move(pRootNode)) { + add(m_pRootNode.get()); } Engine::~Engine() { - delete m_pRootNode; } void Engine::add(BaseNode* pNode) { @@ -47,8 +46,8 @@ void Engine::remove(BaseNode* pNode) { } } - if (m_pRootNode == pNode) { - m_pRootNode = nullptr; + if (m_pRootNode.get() == pNode) { + m_pRootNode.reset(); } } @@ -60,7 +59,7 @@ void Engine::render() { m_pInitializeNodes.clear(); } if (m_pRootNode && !m_pRootNode->isSubtreeBlocked()) { - render(m_pRootNode); + render(m_pRootNode.get()); } } @@ -93,7 +92,7 @@ void Engine::resize(int w, int h) { //} if (m_pRootNode) { - resize(m_pRootNode, w, h); + resize(m_pRootNode.get(), w, h); } } diff --git a/src/rendergraph/opengl/rendergraph/engine.h b/src/rendergraph/opengl/rendergraph/engine.h index e96912b54c0..83e480727e0 100644 --- a/src/rendergraph/opengl/rendergraph/engine.h +++ b/src/rendergraph/opengl/rendergraph/engine.h @@ -12,7 +12,7 @@ class Engine; class rendergraph::Engine { public: - Engine(BaseNode* pRootNode); + Engine(std::unique_ptr pRootNode); ~Engine(); void render(); @@ -29,7 +29,7 @@ class rendergraph::Engine { void resize(BaseNode* pNode, int, int); QMatrix4x4 m_matrix; - BaseNode* m_pRootNode{}; + std::unique_ptr m_pRootNode; std::vector m_pPreprocessNodes; std::vector m_pInitializeNodes; }; diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 6d3b5d250a1..32f7f377f84 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -83,11 +83,11 @@ class WaveformMarkNodeGraphics : public WaveformMark::Graphics { float textureHeight() const { return waveformMarkNode()->textureHeight(); } - void setNode(std::unique_ptr&& pNode) { + void setNode(std::unique_ptr&& pNode) { m_pNode = std::move(pNode); } void moveNodeToChildrenOf(Node* pParent) { - pParent->appendChildNode(m_pNode.release()); + pParent->appendChildNode(std::move(m_pNode)); } private: @@ -95,7 +95,7 @@ class WaveformMarkNodeGraphics : public WaveformMark::Graphics { return static_cast(m_pNode.get()); } - std::unique_ptr m_pNode; + std::unique_ptr m_pNode; }; // Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive @@ -136,26 +136,26 @@ allshader::WaveformRenderMark::WaveformRenderMark( { auto pNode = std::make_unique(); m_pRangeNodesParent = pNode.get(); - appendChildNode(pNode.release()); + appendChildNode(std::move(pNode)); } { auto pNode = std::make_unique(); m_pMarkNodesParent = pNode.get(); - appendChildNode(pNode.release()); + appendChildNode(std::move(pNode)); } { auto pNode = std::make_unique(); m_pDigitsRenderNode = pNode.get(); - appendChildNode(pNode.release()); + appendChildNode(std::move(pNode)); } { auto pNode = std::make_unique(); m_pPlayPosNode = pNode.get(); m_pPlayPosNode->initForRectangles(1); - appendChildNode(pNode.release()); + appendChildNode(std::move(pNode)); } } @@ -199,6 +199,16 @@ bool allshader::WaveformRenderMark::isSubtreeBlocked() const { return m_isSlipRenderer && !m_waveformRenderer->isSlipActive(); } +namespace { +template +std::unique_ptr castToUniquePtr(std::unique_ptr&& pNode) { + if (dynamic_cast(pNode.get())) { + return std::unique_ptr(dynamic_cast(pNode.release())); + } + return std::unique_ptr(); +} +} // namespace + void allshader::WaveformRenderMark::update() { if (isSubtreeBlocked()) { return; @@ -214,8 +224,7 @@ void allshader::WaveformRenderMark::update() { // (transferring ownership). Later in this function we move the // visible nodes back to m_pMarkNodesParent children. while (auto pChild = m_pMarkNodesParent->firstChild()) { - std::unique_ptr pNode(static_cast(pChild)); - m_pMarkNodesParent->removeChildNode(pNode.get()); + auto pNode = castToUniquePtr(m_pMarkNodesParent->detachChildNode(pChild)); // Determine its WaveformMark auto pMark = pNode->m_pOwner; auto pGraphics = static_cast(pMark->m_pGraphics.get()); @@ -320,7 +329,7 @@ void allshader::WaveformRenderMark::update() { auto pNode = std::make_unique(); pNode->initForRectangles(2); pRangeChild = pNode.get(); - m_pRangeNodesParent->appendChildNode(pNode.release()); + m_pRangeNodesParent->appendChildNode(std::move(pNode)); } updateRangeNode(pRangeChild, @@ -343,8 +352,7 @@ void allshader::WaveformRenderMark::update() { // Remove unused nodes while (pRangeChild) { - auto pNode = std::unique_ptr(pRangeChild); - m_pRangeNodesParent->removeChildNode(pNode.get()); + auto pNode = m_pRangeNodesParent->detachChildNode(pRangeChild); pRangeChild = static_cast(pRangeChild->nextSibling()); } diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index de2bddb06bb..6efb9a1410b 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -77,7 +77,7 @@ void WaveformRenderMarkRange::update() { auto pNode = std::make_unique(); pChild = pNode.get(); pChild->initForRectangles(1); - appendChildNode(pNode.release()); + appendChildNode(std::move(pNode)); } updateNode(pChild, @@ -89,8 +89,7 @@ void WaveformRenderMarkRange::update() { pChild = static_cast(pChild->nextSibling()); } while (pChild) { - std::unique_ptr pNode(pChild); - removeChildNode(pNode.get()); + auto pNode = detachChildNode(pChild); pChild = static_cast(pChild->nextSibling()); } } diff --git a/src/waveform/widgets/allshader/waveformwidget.cpp b/src/waveform/widgets/allshader/waveformwidget.cpp index 09235798a11..192392a57ed 100644 --- a/src/waveform/widgets/allshader/waveformwidget.cpp +++ b/src/waveform/widgets/allshader/waveformwidget.cpp @@ -22,6 +22,15 @@ namespace allshader { +template +std::unique_ptr castUniqueNodePtr(std::unique_ptr&& p) { + if (dynamic_cast(p.get())) { + return std::unique_ptr( + dynamic_cast(p.release())); + } + return std::unique_ptr(); +} + WaveformWidget::WaveformWidget(QWidget* parent, WaveformWidgetType::Type type, const QString& group, @@ -30,61 +39,64 @@ WaveformWidget::WaveformWidget(QWidget* parent, auto pTopNode = std::make_unique(); auto pOpacityNode = std::make_unique(); - pTopNode->appendChildNode(addRenderer()); - pOpacityNode->appendChildNode(addRenderer()); - pOpacityNode->appendChildNode(addRenderer()); - m_pWaveformRenderMarkRange = addRenderer(); - pOpacityNode->appendChildNode(m_pWaveformRenderMarkRange); + pTopNode->appendChildNode(addRendererNode()); + pOpacityNode->appendChildNode(addRendererNode()); + pOpacityNode->appendChildNode(addRendererNode()); + auto pWaveformRenderMarkRange = addRendererNode(); + m_pWaveformRenderMarkRange = pWaveformRenderMarkRange.get(); + pOpacityNode->appendChildNode(std::move(pWaveformRenderMarkRange)); #ifdef __STEM__ // The following two renderers work in tandem: if the rendered waveform is // for a stem track, WaveformRendererSignalBase will skip rendering and let // WaveformRendererStem do the rendering, and vice-versa. - pOpacityNode->appendChildNode(addRenderer()); + pOpacityNode->appendChildNode(addRendererNode()); #endif - allshader::WaveformRendererSignalBase* waveformSignalRenderer = - addWaveformSignalRenderer( - type, options, ::WaveformRendererAbstract::Play); - auto pNode = dynamic_cast(waveformSignalRenderer); + auto pWaveformSignalRenderer = addWaveformSignalRenderer( + type, options, ::WaveformRendererAbstract::Play); + const bool supportsSlip = pWaveformSignalRenderer && pWaveformSignalRenderer->supportsSlip(); + auto pNode = castUniqueNodePtr(std::move(pWaveformSignalRenderer)); if (pNode) { - pOpacityNode->appendChildNode(pNode); + pOpacityNode->appendChildNode(std::move(pNode)); } - pOpacityNode->appendChildNode(addRenderer()); - m_pWaveformRenderMark = addRenderer(); - pOpacityNode->appendChildNode(m_pWaveformRenderMark); + pOpacityNode->appendChildNode(addRendererNode()); + auto pWaveformRenderMark = addRendererNode(); + m_pWaveformRenderMark = pWaveformRenderMark.get(); + pOpacityNode->appendChildNode(std::move(pWaveformRenderMark)); // if the signal renderer supports slip, we add it again, now for slip, together with the // other slip renderers - if (waveformSignalRenderer && waveformSignalRenderer->supportsSlip()) { + if (supportsSlip) { // The following renderer will add an overlay waveform if a slip is in progress - pOpacityNode->appendChildNode(addRenderer()); + pOpacityNode->appendChildNode(addRendererNode()); pOpacityNode->appendChildNode( - addRenderer( + addRendererNode( ::WaveformRendererAbstract::Slip)); #ifdef __STEM__ pOpacityNode->appendChildNode( - addRenderer( + addRendererNode( ::WaveformRendererAbstract::Slip)); #endif - auto pNode = dynamic_cast(addWaveformSignalRenderer( - type, options, ::WaveformRendererAbstract::Slip)); + auto pWaveformSignalRenderer = addWaveformSignalRenderer( + type, options, ::WaveformRendererAbstract::Slip); + auto pNode = castUniqueNodePtr(std::move(pWaveformSignalRenderer)); if (pNode) { - pOpacityNode->appendChildNode(pNode); + pOpacityNode->appendChildNode(std::move(pNode)); } pOpacityNode->appendChildNode( - addRenderer( + addRendererNode( ::WaveformRendererAbstract::Slip)); pOpacityNode->appendChildNode( - addRenderer( + addRendererNode( ::WaveformRendererAbstract::Slip)); } m_initSuccess = init(); m_pOpacityNode = pOpacityNode.get(); - pTopNode->appendChildNode(pOpacityNode.release()); + pTopNode->appendChildNode(std::move(pOpacityNode)); - m_pEngine = std::make_unique(pTopNode.release()); + m_pEngine = std::make_unique(std::move(pTopNode)); } WaveformWidget::~WaveformWidget() { @@ -94,10 +106,18 @@ WaveformWidget::~WaveformWidget() { doneCurrent(); } -allshader::WaveformRendererSignalBase* +std::unique_ptr WaveformWidget::addWaveformSignalRenderer(WaveformWidgetType::Type type, WaveformRendererSignalBase::Options options, ::WaveformRendererAbstract::PositionSource positionSource) { + return std::unique_ptr( + addWaveformSignalRendererInner(type, options, positionSource)); +} + +allshader::WaveformRendererSignalBase* +WaveformWidget::addWaveformSignalRendererInner(WaveformWidgetType::Type type, + WaveformRendererSignalBase::Options options, + ::WaveformRendererAbstract::PositionSource positionSource) { #ifndef QT_OPENGL_ES_2 if (options & allshader::WaveformRendererSignalBase::Option::HighDetail) { switch (type) { diff --git a/src/waveform/widgets/allshader/waveformwidget.h b/src/waveform/widgets/allshader/waveformwidget.h index 347a347aabd..41c195118f3 100644 --- a/src/waveform/widgets/allshader/waveformwidget.h +++ b/src/waveform/widgets/allshader/waveformwidget.h @@ -42,13 +42,23 @@ class allshader::WaveformWidget final : public ::WGLWidget, static WaveformWidgetVars vars(); static WaveformRendererSignalBase::Options supportedOptions(WaveformWidgetType::Type type); + template + inline std::unique_ptr addRendererNode(Args&&... args) { + return std::unique_ptr(addRenderer(std::forward(args)...)); + } + private: void castToQWidget() override; void paintEvent(QPaintEvent* event) override; void wheelEvent(QWheelEvent* event) override; void leaveEvent(QEvent* event) override; - allshader::WaveformRendererSignalBase* addWaveformSignalRenderer( + std::unique_ptr addWaveformSignalRenderer( + WaveformWidgetType::Type type, + WaveformRendererSignalBase::Options options, + ::WaveformRendererAbstract::PositionSource positionSource); + + allshader::WaveformRendererSignalBase* addWaveformSignalRendererInner( WaveformWidgetType::Type type, WaveformRendererSignalBase::Options options, ::WaveformRendererAbstract::PositionSource positionSource); From 1a38137a831243a24fe545d6863ad9c32d8f4e48 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 20 Oct 2024 21:01:57 +0200 Subject: [PATCH 48/64] reduce delta with feat/qml-scrolling-waveform-with-sg-and-rendergraph --- .../common/rendergraph/geometrynode.h | 2 +- src/rendergraph/common/rendergraph/material.h | 2 +- src/rendergraph/examples/CMakeLists.txt | 4 +++- .../examples/common/examplenode.cpp | 6 ++--- .../examples/gl_example/CMakeLists.txt | 2 ++ .../examples/gl_example/window.cpp | 2 +- .../examples/sg_example/CMakeLists.txt | 23 ++++++++++++------- .../scenegraph/backend/basematerialshader.cpp | 4 ++++ src/rendergraph/scenegraph/texture.cpp | 4 ++++ 9 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/rendergraph/common/rendergraph/geometrynode.h b/src/rendergraph/common/rendergraph/geometrynode.h index 96dc6798962..fbcacba3647 100644 --- a/src/rendergraph/common/rendergraph/geometrynode.h +++ b/src/rendergraph/common/rendergraph/geometrynode.h @@ -16,7 +16,7 @@ class rendergraph::GeometryNode : public rendergraph::NodeInterface void initForRectangles(int numRectangles) { - const int verticesPerRectangle = 6; // 2 rectangles + const int verticesPerRectangle = 6; // 2 triangles setGeometry(std::make_unique(T_Material::attributes(), numRectangles * verticesPerRectangle)); setMaterial(std::make_unique()); diff --git a/src/rendergraph/common/rendergraph/material.h b/src/rendergraph/common/rendergraph/material.h index e15ef5c0f1c..ab18e89166a 100644 --- a/src/rendergraph/common/rendergraph/material.h +++ b/src/rendergraph/common/rendergraph/material.h @@ -30,7 +30,7 @@ class rendergraph::Material : public rendergraph::BaseMaterial { pOther->m_uniformsCache.data(), m_uniformsCache.size()); if (cacheCompareResult != 0) { - return cacheCompareResult; + return cacheCompareResult < 0 ? -1 : 1; } // TODO multiple textures if (!texture(0) || !pOther->texture(0)) { diff --git a/src/rendergraph/examples/CMakeLists.txt b/src/rendergraph/examples/CMakeLists.txt index b826c663aa4..8419ece7723 100644 --- a/src/rendergraph/examples/CMakeLists.txt +++ b/src/rendergraph/examples/CMakeLists.txt @@ -3,7 +3,9 @@ project(rendergraph LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick ShaderTools) -qt_standard_project_setup() +if(NOT(QT_VERSION VERSION_LESS "6.3.0")) + qt_standard_project_setup() +endif() add_subdirectory(../ rendergraph) diff --git a/src/rendergraph/examples/common/examplenode.cpp b/src/rendergraph/examples/common/examplenode.cpp index 4ba6f9fa5ab..452d4613b71 100644 --- a/src/rendergraph/examples/common/examplenode.cpp +++ b/src/rendergraph/examples/common/examplenode.cpp @@ -24,7 +24,7 @@ ExampleNode::ExampleNode(rendergraph::Context* pContext) { TexturedVertexUpdater vertexUpdater{ pNode->geometry().vertexDataAs()}; vertexUpdater.addRectangle({0, 0}, {100, 100}, {0.f, 0.f}, {1.f, 1.f}); - appendChildNode(pNode.release()); + appendChildNode(std::move(pNode)); } { auto pNode = std::make_unique(); @@ -36,7 +36,7 @@ ExampleNode::ExampleNode(rendergraph::Context* pContext) { .vertexDataAs()}; vertexUpdater.addRectangle({100, 100}, {160, 160}); vertexUpdater.addRectangle({200, 160}, {240, 190}); - appendChildNode(pNode.release()); + appendChildNode(std::move(pNode)); } { auto pNode = std::make_unique(); @@ -47,6 +47,6 @@ ExampleNode::ExampleNode(rendergraph::Context* pContext) { vertexUpdater.addRectangle({300, 100}, {340, 140}, {1.f, 0.f, 0.5f}); vertexUpdater.addRectangleHGradient( {340, 100}, {440, 130}, {0.f, 1.f, 0.5f}, {0.5f, 0.f, 1.f}); - appendChildNode(pNode.release()); + appendChildNode(std::move(pNode)); } } diff --git a/src/rendergraph/examples/gl_example/CMakeLists.txt b/src/rendergraph/examples/gl_example/CMakeLists.txt index a4f26976f73..5a4239d6e6c 100644 --- a/src/rendergraph/examples/gl_example/CMakeLists.txt +++ b/src/rendergraph/examples/gl_example/CMakeLists.txt @@ -28,9 +28,11 @@ install(TARGETS gl_example LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) +if(NOT(QT_VERSION VERSION_LESS "6.3.0")) qt_generate_deploy_app_script( TARGET gl_example OUTPUT_SCRIPT deploy_script NO_UNSUPPORTED_PLATFORM_ERROR ) install(SCRIPT ${deploy_script}) +endif() diff --git a/src/rendergraph/examples/gl_example/window.cpp b/src/rendergraph/examples/gl_example/window.cpp index 32378895a09..de643ee8ba7 100644 --- a/src/rendergraph/examples/gl_example/window.cpp +++ b/src/rendergraph/examples/gl_example/window.cpp @@ -18,7 +18,7 @@ void Window::initializeGL() { rendergraph::Context context; auto pExampleNode = std::make_unique(&context); - m_pEngine = std::make_unique(pExampleNode.release()); + m_pEngine = std::make_unique(std::move(pExampleNode)); } void Window::resizeGL(int w, int h) { diff --git a/src/rendergraph/examples/sg_example/CMakeLists.txt b/src/rendergraph/examples/sg_example/CMakeLists.txt index 249f0b80299..303987868d9 100644 --- a/src/rendergraph/examples/sg_example/CMakeLists.txt +++ b/src/rendergraph/examples/sg_example/CMakeLists.txt @@ -11,7 +11,12 @@ target_link_libraries(sg_example PRIVATE target_include_directories(sg_example PRIVATE ../common) target_compile_definitions(sg_example PRIVATE rendergraph=rendergraph_sg) +if(QT_VERSION VERSION_LESS "6.3.0") + set_target_properties(sg_example PROPERTIES AUTOMOC ON) +endif() + qt_add_qml_module(sg_example + VERSION 1.0 URI RenderGraph QML_FILES qml/main.qml @@ -27,11 +32,13 @@ install(TARGETS sg_example LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) -qt_generate_deploy_qml_app_script( - TARGET sg_example - OUTPUT_SCRIPT deploy_script - MACOS_BUNDLE_POST_BUILD - NO_UNSUPPORTED_PLATFORM_ERROR - DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM -) -install(SCRIPT ${deploy_script}) +if(NOT(QT_VERSION VERSION_LESS "6.3.0")) + qt_generate_deploy_qml_app_script( + TARGET sg_example + OUTPUT_SCRIPT deploy_script + MACOS_BUNDLE_POST_BUILD + NO_UNSUPPORTED_PLATFORM_ERROR + DEPLOY_USER_QML_MODULES_ON_UNSUPPORTED_PLATFORM + ) + install(SCRIPT ${deploy_script}) +endif() diff --git a/src/rendergraph/scenegraph/backend/basematerialshader.cpp b/src/rendergraph/scenegraph/backend/basematerialshader.cpp index a2de0a4b46b..7a49a3d5afd 100644 --- a/src/rendergraph/scenegraph/backend/basematerialshader.cpp +++ b/src/rendergraph/scenegraph/backend/basematerialshader.cpp @@ -28,6 +28,10 @@ void BaseMaterialShader::updateSampledImage(RenderState& state, QSGTexture** texture, QSGMaterial* newMaterial, QSGMaterial* oldMaterial) { + if (!newMaterial || !static_cast(newMaterial)->texture(binding)) { + *texture = nullptr; + return; + } *texture = static_cast(newMaterial)->texture(binding)->backendTexture(); (*texture)->commitTextureOperations(state.rhi(), state.resourceUpdateBatch()); } diff --git a/src/rendergraph/scenegraph/texture.cpp b/src/rendergraph/scenegraph/texture.cpp index 76bdad4c893..d697d85c7c9 100644 --- a/src/rendergraph/scenegraph/texture.cpp +++ b/src/rendergraph/scenegraph/texture.cpp @@ -5,6 +5,10 @@ using namespace rendergraph; Texture::Texture(Context* pContext, const QImage& image) : m_pTexture(pContext->window()->createTextureFromImage(image)) { + VERIFY_OR_DEBUG_ASSERT(pContext->window() != nullptr) { + return; + } + DEBUG_ASSERT(!m_pTexture->textureSize().isNull()); } qint64 Texture::comparisonKey() const { From cf17f15deb63048a5c28f74aa4a84d160b2c584d Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 20 Oct 2024 21:02:42 +0200 Subject: [PATCH 49/64] reduce delta with feat/qml-scrolling-waveform-with-sg-and-rendergraph --- src/rendergraph/scenegraph/texture.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rendergraph/scenegraph/texture.cpp b/src/rendergraph/scenegraph/texture.cpp index d697d85c7c9..130d10df821 100644 --- a/src/rendergraph/scenegraph/texture.cpp +++ b/src/rendergraph/scenegraph/texture.cpp @@ -1,4 +1,6 @@ #include "rendergraph/texture.h" + +#include "rendergraph/assert.h" #include "rendergraph/context.h" using namespace rendergraph; From 5220b3901549bc942329e06851733b0d5dfa50b3 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 20 Oct 2024 21:18:05 +0200 Subject: [PATCH 50/64] reduced delta with feat/qml-scrolling-waveform-with-sg-and-rendergraph --- src/rendergraph/opengl/backend/basenode.cpp | 59 ++++++++++ .../allshader/waveformrendermark.cpp | 107 +++++------------- .../renderers/allshader/waveformrendermark.h | 63 +++++++++++ 3 files changed, 151 insertions(+), 78 deletions(-) create mode 100644 src/rendergraph/opengl/backend/basenode.cpp diff --git a/src/rendergraph/opengl/backend/basenode.cpp b/src/rendergraph/opengl/backend/basenode.cpp new file mode 100644 index 00000000000..5a902f5cc92 --- /dev/null +++ b/src/rendergraph/opengl/backend/basenode.cpp @@ -0,0 +1,59 @@ +#include "backend/basenode.h" + +#include "rendergraph/assert.h" +#include "rendergraph/engine.h" + +using namespace rendergraph; + +BaseNode::~BaseNode() { + DEBUG_ASSERT(m_pParent == nullptr); + DEBUG_ASSERT(m_pEngine == nullptr); + + while (m_pFirstChild) { + std::unique_ptr pChild(m_pFirstChild); + removeChildNode(pChild.get()); + } +} + +void BaseNode::appendChildNode(BaseNode* pChild) { + if (m_pLastChild) { + pChild->m_pPreviousSibling = m_pLastChild; + m_pLastChild->m_pNextSibling = pChild; + } else { + m_pFirstChild = pChild; + } + m_pLastChild = pChild; + m_pLastChild->m_pParent = this; + + DEBUG_ASSERT(m_pLastChild->m_pNextSibling == nullptr); + + if (m_pEngine) { + m_pEngine->add(pChild); + } +} + +void BaseNode::removeAllChildNodes() { + while (m_pFirstChild) { + removeChildNode(m_pFirstChild); + } +} + +void BaseNode::removeChildNode(BaseNode* pChild) { + if (pChild == m_pFirstChild) { + m_pFirstChild = pChild->m_pNextSibling; + } else { + pChild->m_pPreviousSibling->m_pNextSibling = pChild->m_pNextSibling; + } + + if (pChild == m_pLastChild) { + m_pLastChild = nullptr; + } + + if (pChild->m_pEngine) { + pChild->m_pEngine->remove(pChild); + } + + pChild->m_pNextSibling = nullptr; + pChild->m_pPreviousSibling = nullptr; + pChild->m_pParent = nullptr; +} diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 32f7f377f84..239efc1cec1 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -18,85 +18,36 @@ using namespace rendergraph; -// On the use of QPainter: -// -// The renderers in this folder are optimized to use GLSL shaders and refrain -// from using QPainter on the QOpenGLWindow, which causes degredated performance. -// -// This renderer does use QPainter (indirectly, in WaveformMark::generateImage), but -// only to draw on a QImage. This is only done once when needed and the images are -// then used as textures to be drawn with a GLSL shader. - -class WaveformMarkNode : public rendergraph::GeometryNode { - public: - WaveformMark* m_pOwner{}; - - WaveformMarkNode(WaveformMark* pOwner, rendergraph::Context* pContext, const QImage& image) - : m_pOwner(pOwner) { - initForRectangles(1); - updateTexture(pContext, image); - } - void updateTexture(rendergraph::Context* pContext, const QImage& image) { - dynamic_cast(material()) - .setTexture(std::make_unique(pContext, image)); - m_textureWidth = image.width(); - m_textureHeight = image.height(); - } - void update(float x, float y, float devicePixelRatio) { - TexturedVertexUpdater vertexUpdater{ - geometry().vertexDataAs()}; - vertexUpdater.addRectangle({x, y}, - {x + m_textureWidth / devicePixelRatio, - y + m_textureHeight / devicePixelRatio}, - {0.f, 0.f}, - {1.f, 1.f}); - } - float textureWidth() const { - return m_textureWidth; - } - float textureHeight() const { - return m_textureHeight; - } - - public: - float m_textureWidth{}; - float m_textureHeight{}; -}; - -class WaveformMarkNodeGraphics : public WaveformMark::Graphics { - public: - WaveformMarkNodeGraphics(WaveformMark* pOwner, - rendergraph::Context* pContext, - const QImage& image) - : m_pNode(std::make_unique( - pOwner, pContext, image)) { - } - void updateTexture(rendergraph::Context* pContext, const QImage& image) { - waveformMarkNode()->updateTexture(pContext, image); - } - void update(float x, float y, float devicePixelRatio) { - waveformMarkNode()->update(x, y, devicePixelRatio); - } - float textureWidth() const { - return waveformMarkNode()->textureWidth(); - } - float textureHeight() const { - return waveformMarkNode()->textureHeight(); - } - void setNode(std::unique_ptr&& pNode) { - m_pNode = std::move(pNode); - } - void moveNodeToChildrenOf(Node* pParent) { - pParent->appendChildNode(std::move(m_pNode)); - } - - private: - WaveformMarkNode* waveformMarkNode() const { - return static_cast(m_pNode.get()); - } +allshader::WaveformMarkNode::WaveformMarkNode(WaveformMark* pOwner, + rendergraph::Context* pContext, + const QImage& image) + : m_pOwner(pOwner) { + initForRectangles(1); + updateTexture(pContext, image); +} - std::unique_ptr m_pNode; -}; +void allshader::WaveformMarkNode::updateTexture( + rendergraph::Context* pContext, const QImage& image) { + dynamic_cast(material()) + .setTexture(std::make_unique(pContext, image)); + m_textureWidth = image.width(); + m_textureHeight = image.height(); +} +void allshader::WaveformMarkNode::update(float x, float y, float devicePixelRatio) { + TexturedVertexUpdater vertexUpdater{ + geometry().vertexDataAs()}; + vertexUpdater.addRectangle({x, y}, + {x + m_textureWidth / devicePixelRatio, + y + m_textureHeight / devicePixelRatio}, + {0.f, 0.f}, + {1.f, 1.f}); +} +allshader::WaveformMarkNodeGraphics::WaveformMarkNodeGraphics(WaveformMark* pOwner, + rendergraph::Context* pContext, + const QImage& image) + : m_pNode(std::make_unique( + pOwner, pContext, image)) { +} // Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive // from WaveformRenderMarkBase. The base-class takes care of updating the marks diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index a1b8078d525..a0bff747f61 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -2,6 +2,7 @@ #include +#include "rendergraph/geometrynode.h" #include "rendergraph/node.h" #include "waveform/renderers/waveformrendermarkbase.h" @@ -15,6 +16,8 @@ class Context; namespace allshader { class DigitsRenderNode; class WaveformRenderMark; +class WaveformMarkNode; +class WaveformMarkNodeGraphics; } class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, @@ -70,3 +73,63 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, DISALLOW_COPY_AND_ASSIGN(WaveformRenderMark); }; + +// On the use of QPainter: +// +// The renderers in this folder are optimized to use GLSL shaders and refrain +// from using QPainter on the QOpenGLWindow, which causes degredated performance. +// +// This renderer does use QPainter (indirectly, in WaveformMark::generateImage), but +// only to draw on a QImage. This is only done once when needed and the images are +// then used as textures to be drawn with a GLSL shader. + +class allshader::WaveformMarkNode : public rendergraph::GeometryNode { + public: + WaveformMark* m_pOwner{}; + + WaveformMarkNode(WaveformMark* pOwner, rendergraph::Context* pContext, const QImage& image); + void updateTexture(rendergraph::Context* pContext, const QImage& image); + void update(float x, float y, float devicePixelRatio); + float textureWidth() const { + return m_textureWidth; + } + float textureHeight() const { + return m_textureHeight; + } + + public: + float m_textureWidth{}; + float m_textureHeight{}; +}; + +class allshader::WaveformMarkNodeGraphics : public ::WaveformMark::Graphics { + public: + WaveformMarkNodeGraphics(WaveformMark* pOwner, + rendergraph::Context* pContext, + const QImage& image); + void updateTexture(rendergraph::Context* pContext, const QImage& image) { + waveformMarkNode()->updateTexture(pContext, image); + } + void update(float x, float y, float devicePixelRatio) { + waveformMarkNode()->update(x, y, devicePixelRatio); + } + float textureWidth() const { + return waveformMarkNode()->textureWidth(); + } + float textureHeight() const { + return waveformMarkNode()->textureHeight(); + } + void setNode(std::unique_ptr&& pNode) { + m_pNode = std::move(pNode); + } + void moveNodeToChildrenOf(rendergraph::Node* pParent) { + pParent->appendChildNode(std::move(m_pNode)); + } + + private: + WaveformMarkNode* waveformMarkNode() const { + return static_cast(m_pNode.get()); + } + + std::unique_ptr m_pNode; +}; From b8f2268e85e07aa34dd41dabe32b9ca2c2987151 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 20 Oct 2024 23:11:19 +0200 Subject: [PATCH 51/64] some cleanup --- .../allshader/matrixforwidgetgeometry.cpp | 0 .../allshader/matrixforwidgetgeometry.h | 13 --- .../allshader/waveformrenderersimple.cpp | 1 - .../allshader/waveformrendermark.cpp | 109 +++++++++++++----- .../renderers/allshader/waveformrendermark.h | 62 ---------- 5 files changed, 80 insertions(+), 105 deletions(-) delete mode 100644 src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp delete mode 100644 src/waveform/renderers/allshader/matrixforwidgetgeometry.h diff --git a/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp b/src/waveform/renderers/allshader/matrixforwidgetgeometry.cpp deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/src/waveform/renderers/allshader/matrixforwidgetgeometry.h b/src/waveform/renderers/allshader/matrixforwidgetgeometry.h deleted file mode 100644 index 3240104085c..00000000000 --- a/src/waveform/renderers/allshader/matrixforwidgetgeometry.h +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -class WaveformWidgetRenderer; - -// Calculate the orthogonal project matrix for the WaveformWidgetRenderer, taking into account -// width and height, but also orientation (to rotate the matrix). -// Note that this allows us to basically use the same renderer code for horizontal and vertical -// orientation of the waveform, as we simply multiple the vertices with a rotated matrix in -// the vertex shaders. -QMatrix4x4 matrixForWidgetGeometry( - WaveformWidgetRenderer* const widget, bool applyDevicePixelRatio); diff --git a/src/waveform/renderers/allshader/waveformrenderersimple.cpp b/src/waveform/renderers/allshader/waveformrenderersimple.cpp index e2614091ea5..c53c9596a13 100644 --- a/src/waveform/renderers/allshader/waveformrenderersimple.cpp +++ b/src/waveform/renderers/allshader/waveformrenderersimple.cpp @@ -2,7 +2,6 @@ #include "track/track.h" #include "util/math.h" -#include "waveform/renderers/allshader/matrixforwidgetgeometry.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 239efc1cec1..eb1a5c2bc7b 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -18,36 +18,87 @@ using namespace rendergraph; -allshader::WaveformMarkNode::WaveformMarkNode(WaveformMark* pOwner, - rendergraph::Context* pContext, - const QImage& image) - : m_pOwner(pOwner) { - initForRectangles(1); - updateTexture(pContext, image); -} +namespace { +// On the use of QPainter: +// +// The renderers in this folder are optimized to use GLSL shaders and refrain +// from using QPainter on the QOpenGLWindow, which causes degredated performance. +// +// This renderer does use QPainter (indirectly, in WaveformMark::generateImage), but +// only to draw on a QImage. This is only done once when needed and the images are +// then used as textures to be drawn with a GLSL shader. + +class WaveformMarkNode : public rendergraph::GeometryNode { + public: + WaveformMark* m_pOwner{}; + + WaveformMarkNode(WaveformMark* pOwner, rendergraph::Context* pContext, const QImage& image) + : m_pOwner(pOwner) { + initForRectangles(1); + updateTexture(pContext, image); + } + void updateTexture(rendergraph::Context* pContext, const QImage& image) { + dynamic_cast(material()) + .setTexture(std::make_unique(pContext, image)); + m_textureWidth = image.width(); + m_textureHeight = image.height(); + } + void update(float x, float y, float devicePixelRatio) { + TexturedVertexUpdater vertexUpdater{ + geometry().vertexDataAs()}; + vertexUpdater.addRectangle({x, y}, + {x + m_textureWidth / devicePixelRatio, + y + m_textureHeight / devicePixelRatio}, + {0.f, 0.f}, + {1.f, 1.f}); + } + float textureWidth() const { + return m_textureWidth; + } + float textureHeight() const { + return m_textureHeight; + } -void allshader::WaveformMarkNode::updateTexture( - rendergraph::Context* pContext, const QImage& image) { - dynamic_cast(material()) - .setTexture(std::make_unique(pContext, image)); - m_textureWidth = image.width(); - m_textureHeight = image.height(); -} -void allshader::WaveformMarkNode::update(float x, float y, float devicePixelRatio) { - TexturedVertexUpdater vertexUpdater{ - geometry().vertexDataAs()}; - vertexUpdater.addRectangle({x, y}, - {x + m_textureWidth / devicePixelRatio, - y + m_textureHeight / devicePixelRatio}, - {0.f, 0.f}, - {1.f, 1.f}); -} -allshader::WaveformMarkNodeGraphics::WaveformMarkNodeGraphics(WaveformMark* pOwner, - rendergraph::Context* pContext, - const QImage& image) - : m_pNode(std::make_unique( - pOwner, pContext, image)) { -} + public: + float m_textureWidth{}; + float m_textureHeight{}; +}; + +class WaveformMarkNodeGraphics : public WaveformMark::Graphics { + public: + WaveformMarkNodeGraphics(WaveformMark* pOwner, + rendergraph::Context* pContext, + const QImage& image) + : m_pNode(std::make_unique( + pOwner, pContext, image)) { + } + void updateTexture(rendergraph::Context* pContext, const QImage& image) { + waveformMarkNode()->updateTexture(pContext, image); + } + void update(float x, float y, float devicePixelRatio) { + waveformMarkNode()->update(x, y, devicePixelRatio); + } + float textureWidth() const { + return waveformMarkNode()->textureWidth(); + } + float textureHeight() const { + return waveformMarkNode()->textureHeight(); + } + void setNode(std::unique_ptr&& pNode) { + m_pNode = std::move(pNode); + } + void moveNodeToChildrenOf(rendergraph::Node* pParent) { + pParent->appendChildNode(std::move(m_pNode)); + } + + private: + WaveformMarkNode* waveformMarkNode() const { + return static_cast(m_pNode.get()); + } + + std::unique_ptr m_pNode; +}; +} // namespace // Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive // from WaveformRenderMarkBase. The base-class takes care of updating the marks diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index a0bff747f61..f18b8559a5e 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -16,8 +16,6 @@ class Context; namespace allshader { class DigitsRenderNode; class WaveformRenderMark; -class WaveformMarkNode; -class WaveformMarkNodeGraphics; } class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, @@ -73,63 +71,3 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, DISALLOW_COPY_AND_ASSIGN(WaveformRenderMark); }; - -// On the use of QPainter: -// -// The renderers in this folder are optimized to use GLSL shaders and refrain -// from using QPainter on the QOpenGLWindow, which causes degredated performance. -// -// This renderer does use QPainter (indirectly, in WaveformMark::generateImage), but -// only to draw on a QImage. This is only done once when needed and the images are -// then used as textures to be drawn with a GLSL shader. - -class allshader::WaveformMarkNode : public rendergraph::GeometryNode { - public: - WaveformMark* m_pOwner{}; - - WaveformMarkNode(WaveformMark* pOwner, rendergraph::Context* pContext, const QImage& image); - void updateTexture(rendergraph::Context* pContext, const QImage& image); - void update(float x, float y, float devicePixelRatio); - float textureWidth() const { - return m_textureWidth; - } - float textureHeight() const { - return m_textureHeight; - } - - public: - float m_textureWidth{}; - float m_textureHeight{}; -}; - -class allshader::WaveformMarkNodeGraphics : public ::WaveformMark::Graphics { - public: - WaveformMarkNodeGraphics(WaveformMark* pOwner, - rendergraph::Context* pContext, - const QImage& image); - void updateTexture(rendergraph::Context* pContext, const QImage& image) { - waveformMarkNode()->updateTexture(pContext, image); - } - void update(float x, float y, float devicePixelRatio) { - waveformMarkNode()->update(x, y, devicePixelRatio); - } - float textureWidth() const { - return waveformMarkNode()->textureWidth(); - } - float textureHeight() const { - return waveformMarkNode()->textureHeight(); - } - void setNode(std::unique_ptr&& pNode) { - m_pNode = std::move(pNode); - } - void moveNodeToChildrenOf(rendergraph::Node* pParent) { - pParent->appendChildNode(std::move(m_pNode)); - } - - private: - WaveformMarkNode* waveformMarkNode() const { - return static_cast(m_pNode.get()); - } - - std::unique_ptr m_pNode; -}; From 3c76b1b99a493eafe95e81bf89c660ebe00831fc Mon Sep 17 00:00:00 2001 From: m0dB Date: Fri, 1 Nov 2024 20:42:09 +0100 Subject: [PATCH 52/64] merge changes from acolombier, clear and set owned by parent flag, more clear transfer of waveformrendermarknode --- .../common/rendergraph/nodeinterface.h | 19 --- src/rendergraph/opengl/CMakeLists.txt | 11 ++ src/rendergraph/opengl/engine.cpp | 2 + src/rendergraph/opengl/texture.cpp | 33 ++++- src/rendergraph/scenegraph/CMakeLists.txt | 11 ++ src/rendergraph/scenegraph/context.cpp | 4 +- .../scenegraph/rendergraph/context.h | 5 +- .../scenegraph/rendergraph/nodeinterface.h | 26 ++++ .../allshader/waveformrendererstem.cpp | 119 +++++++++--------- .../allshader/waveformrendererstem.h | 32 +++-- .../allshader/waveformrendermark.cpp | 118 +++++------------ .../renderers/allshader/waveformrendermark.h | 64 ++++++++++ 12 files changed, 259 insertions(+), 185 deletions(-) delete mode 100644 src/rendergraph/common/rendergraph/nodeinterface.h create mode 100644 src/rendergraph/scenegraph/rendergraph/nodeinterface.h diff --git a/src/rendergraph/common/rendergraph/nodeinterface.h b/src/rendergraph/common/rendergraph/nodeinterface.h deleted file mode 100644 index 4b2d08f4d49..00000000000 --- a/src/rendergraph/common/rendergraph/nodeinterface.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "backend/basenode.h" - -namespace rendergraph { - -template -class NodeInterface : public T_Node { - public: - void appendChildNode(std::unique_ptr&& pNode) { - T_Node::appendChildNode(pNode.release()); - } - std::unique_ptr detachChildNode(BaseNode* pNode) { - T_Node::removeChildNode(pNode); - return std::unique_ptr(pNode); - } -}; - -} // namespace rendergraph diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 9501c2b2b15..529ba2efdb7 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -62,6 +62,17 @@ target_link_libraries(rendergraph_gl PUBLIC Qt6::Gui Qt6::OpenGL ) +find_package(Microsoft.GSL CONFIG) +if(Microsoft.GSL_FOUND) + target_link_libraries(rendergraph_gl PRIVATE Microsoft.GSL::GSL) +else() + # check if the headers have been installed without cmake config (< 3.1.0) + check_include_file_cxx(gsl/gsl HAVE_GSL_GSL) + if(NOT HAVE_GSL_GSL) + unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag. + message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found") + endif() +endif() target_compile_definitions(rendergraph_gl PRIVATE rendergraph=rendergraph_gl) # USE_QSHADER_FOR_GL is set in rendergraph/CMakeLists.txt diff --git a/src/rendergraph/opengl/engine.cpp b/src/rendergraph/opengl/engine.cpp index c5202918155..bfdce71431a 100644 --- a/src/rendergraph/opengl/engine.cpp +++ b/src/rendergraph/opengl/engine.cpp @@ -11,6 +11,8 @@ Engine::Engine(std::unique_ptr pRootNode) } Engine::~Engine() { + // Explicitly remove the root node (and tree from the engine before deallocating its vectors) + remove(m_pRootNode.get()); } void Engine::add(BaseNode* pNode) { diff --git a/src/rendergraph/opengl/texture.cpp b/src/rendergraph/opengl/texture.cpp index 1bd10cf7742..88921bde9df 100644 --- a/src/rendergraph/opengl/texture.cpp +++ b/src/rendergraph/opengl/texture.cpp @@ -1,20 +1,49 @@ #include "rendergraph/texture.h" +#include +#include + +#include "rendergraph/assert.h" #include "rendergraph/context.h" using namespace rendergraph; namespace { QImage premultiplyAlpha(const QImage& image) { + // Since the image is passed by const reference, implicit copy cannot be + // used, and this Qimage::bits will return a ref the QImage buffer, which + // may have a shorter lifecycle that the texture buffer. In order to + // workaround this, and because we cannot copy the image as we need to use + // the raw bitmap with an explicit image format, we make a manual copy of + // the buffer + QImage result(image.width(), image.height(), QImage::Format_RGBA8888); + if (image.format() == QImage::Format_RGBA8888_Premultiplied) { + VERIFY_OR_DEBUG_ASSERT(result.sizeInBytes() == image.sizeInBytes()) { + result.fill(QColor(Qt::transparent).rgba()); + return result; + } + std::memcpy(result.bits(), image.bits(), result.sizeInBytes()); + } else { + auto convertedImage = image.convertToFormat(QImage::Format_RGBA8888_Premultiplied); + VERIFY_OR_DEBUG_ASSERT(result.sizeInBytes() == convertedImage.sizeInBytes()) { + result.fill(QColor(Qt::transparent).rgba()); + return result; + } + std::memcpy(result.bits(), convertedImage.bits(), result.sizeInBytes()); + } + return result; + /* TODO rendergraph ASK @acolombier to try if the following works as well + * (added the .copy()) if (image.format() == QImage::Format_RGBA8888_Premultiplied) { - return QImage(image.bits(), image.width(), image.height(), QImage::Format_RGBA8888); + return QImage(image.bits(), image.width(), image.height(), QImage::Format_RGBA8888).copy(); } return QImage( image.convertToFormat(QImage::Format_RGBA8888_Premultiplied) .bits(), image.width(), image.height(), - QImage::Format_RGBA8888); + QImage::Format_RGBA8888).copy(); + */ } } // namespace diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 45c22885c13..52c197e0ef3 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -55,6 +55,17 @@ target_link_libraries(rendergraph_sg PUBLIC Qt6::Qml Qt6::Quick ) +find_package(Microsoft.GSL CONFIG) +if(Microsoft.GSL_FOUND) + target_link_libraries(rendergraph_sg PRIVATE Microsoft.GSL::GSL) +else() + # check if the headers have been installed without cmake config (< 3.1.0) + check_include_file_cxx(gsl/gsl HAVE_GSL_GSL) + if(NOT HAVE_GSL_GSL) + unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag. + message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found") + endif() +endif() target_compile_definitions(rendergraph_sg PRIVATE rendergraph=rendergraph_sg) target_include_directories(rendergraph_sg PUBLIC . ../common) diff --git a/src/rendergraph/scenegraph/context.cpp b/src/rendergraph/scenegraph/context.cpp index 61c5e12caa7..29c3f567e25 100644 --- a/src/rendergraph/scenegraph/context.cpp +++ b/src/rendergraph/scenegraph/context.cpp @@ -2,10 +2,10 @@ using namespace rendergraph; -Context::Context(QQuickWindow* pWindow) +Context::Context(gsl::not_null pWindow) : m_pWindow(pWindow) { } -QQuickWindow* Context::window() const { +gsl::not_null Context::window() const { return m_pWindow; } diff --git a/src/rendergraph/scenegraph/rendergraph/context.h b/src/rendergraph/scenegraph/rendergraph/context.h index e26e6eb7859..431b41d027b 100644 --- a/src/rendergraph/scenegraph/rendergraph/context.h +++ b/src/rendergraph/scenegraph/rendergraph/context.h @@ -1,6 +1,7 @@ #pragma once #include +#include namespace rendergraph { class Context; @@ -8,8 +9,8 @@ class Context; class rendergraph::Context { public: - Context(QQuickWindow* pWindow); - QQuickWindow* window() const; + Context(gsl::not_null pWindow); + gsl::not_null window() const; private: QQuickWindow* m_pWindow; diff --git a/src/rendergraph/scenegraph/rendergraph/nodeinterface.h b/src/rendergraph/scenegraph/rendergraph/nodeinterface.h new file mode 100644 index 00000000000..6bfaebacfbe --- /dev/null +++ b/src/rendergraph/scenegraph/rendergraph/nodeinterface.h @@ -0,0 +1,26 @@ +#pragma once + +#include "backend/basenode.h" +#include "rendergraph/assert.h" + +namespace rendergraph { + +template +class NodeInterface : public T_Node { + public: + void appendChildNode(std::unique_ptr pNode) { + BaseNode* pRawNode = pNode.release(); + pRawNode->setFlag(QSNode::OwnedByParent, true); + T_Node::appendChildNode(pRawNode); + DEBUG_ASSERT(pNode->flags() & QSNode::OwnedByParent); + } + std::unique_ptr detachChildNode(BaseNode* pNode) { + DEBUG_ASSERT(pNode->flags() & QSNode::OwnedByParent); + pNode->setFlag(QSNode::OwnedByParent, false); + T_Node::removeChildNode(pNode); + DEBUG_ASSERT(!pNode->flags() & QSNode::OwnedByParent); + return std::unique_ptr(pNode); + } +}; + +} // namespace rendergraph diff --git a/src/waveform/renderers/allshader/waveformrendererstem.cpp b/src/waveform/renderers/allshader/waveformrendererstem.cpp index 42c7bf6c155..aa372f1dc76 100644 --- a/src/waveform/renderers/allshader/waveformrendererstem.cpp +++ b/src/waveform/renderers/allshader/waveformrendererstem.cpp @@ -4,12 +4,16 @@ #include #include +#include "rendergraph/material/rgbamaterial.h" +#include "rendergraph/vertexupdaters/rgbavertexupdater.h" #include "track/track.h" +#include "util/assert.h" #include "util/math.h" -#include "waveform/renderers/allshader/rgbdata.h" #include "waveform/renderers/waveformwidgetrenderer.h" #include "waveform/waveform.h" +using namespace rendergraph; + namespace { constexpr int kMaxSupportedStems = 4; } // anonymous namespace @@ -21,64 +25,81 @@ WaveformRendererStem::WaveformRendererStem( ::WaveformRendererAbstract::PositionSource type) : WaveformRendererSignalBase(waveformWidget), m_isSlipRenderer(type == ::WaveformRendererAbstract::Slip) { + initForRectangles(0); + setUsePreprocess(true); } void WaveformRendererStem::onSetup(const QDomNode& node) { Q_UNUSED(node); } -void WaveformRendererStem::initializeGL() { - m_shader.init(); - m_textureShader.init(); - auto group = m_pEQEnabled->getKey().group; +bool WaveformRendererStem::init() { + auto group = m_waveformRenderer->getGroup(); + VERIFY_OR_DEBUG_ASSERT(!group.isEmpty()) { + return false; + } for (int stemIdx = 1; stemIdx <= kMaxSupportedStems; stemIdx++) { DEBUG_ASSERT(group.endsWith("]")); QString stemGroup = QStringLiteral("%1Stem%2]") .arg(group.left(group.size() - 1), QString::number(stemIdx)); m_pStemGain.emplace_back( - std::make_unique(stemGroup, + std::make_unique(stemGroup, QStringLiteral("volume"))); - m_pStemMute.emplace_back(std::make_unique( + m_pStemMute.emplace_back(std::make_unique( stemGroup, QStringLiteral("mute"))); } + return true; } -void WaveformRendererStem::paintGL() { +void WaveformRendererStem::preprocess() { + if (!preprocessInner()) { + if (geometry().vertexCount() != 0) { + geometry().allocate(0); + markDirtyGeometry(); + } + } +} + +bool WaveformRendererStem::preprocessInner() { TrackPointer pTrack = m_waveformRenderer->getTrackInfo(); + if (!pTrack || (m_isSlipRenderer && !m_waveformRenderer->isSlipActive())) { - return; + return false; } auto stemInfo = pTrack->getStemInfo(); // If this track isn't a stem track, skip the rendering if (stemInfo.isEmpty()) { - return; + return false; } auto positionType = m_isSlipRenderer ? ::WaveformRendererAbstract::Slip : ::WaveformRendererAbstract::Play; ConstWaveformPointer waveform = pTrack->getWaveform(); if (waveform.isNull()) { - return; + return false; } const int dataSize = waveform->getDataSize(); if (dataSize <= 1) { - return; + return false; } const WaveformData* data = waveform->data(); if (data == nullptr) { - return; + return false; } // If this waveform doesn't contain stem data, skip the rendering if (!waveform->hasStem()) { - return; + return false; } const float devicePixelRatio = m_waveformRenderer->getDevicePixelRatio(); - const int length = static_cast(m_waveformRenderer->getLength() * devicePixelRatio); + const int length = static_cast(m_waveformRenderer->getLength()); + const int pixelLength = static_cast(m_waveformRenderer->getLength() * devicePixelRatio); + const float invDevicePixelRatio = 1.f / devicePixelRatio; + const float halfPixelSize = 0.5 / devicePixelRatio; // See waveformrenderersimple.cpp for a detailed explanation of the frame and index calculation const int visualFramesSize = dataSize / 2; @@ -89,14 +110,14 @@ void WaveformRendererStem::paintGL() { // Represents the # of visual frames per horizontal pixel. const double visualIncrementPerPixel = - (lastVisualFrame - firstVisualFrame) / static_cast(length); + (lastVisualFrame - firstVisualFrame) / static_cast(pixelLength); // Per-band gain from the EQ knobs. float allGain(1.0); // applyCompensation = true, as we scale to match filtered.all getGains(&allGain, false, nullptr, nullptr, nullptr); - const float breadth = static_cast(m_waveformRenderer->getBreadth()) * devicePixelRatio; + const float breadth = static_cast(m_waveformRenderer->getBreadth()); const float halfBreadth = breadth / 2.0f; const float heightFactor = allGain * halfBreadth / m_maxValue; @@ -107,22 +128,22 @@ void WaveformRendererStem::paintGL() { const int numVerticesPerLine = 6; // 2 triangles - const int reserved = numVerticesPerLine * (8 * length + 1); + const int reserved = numVerticesPerLine * (8 * pixelLength + 1); - m_vertices.clear(); - m_vertices.reserve(reserved); - m_colors.clear(); - m_colors.reserve(reserved); + geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + geometry().allocate(reserved); + markDirtyGeometry(); - m_vertices.addRectangle(0.f, - halfBreadth - 0.5f * devicePixelRatio, - static_cast(length), - m_isSlipRenderer ? halfBreadth : halfBreadth + 0.5f * devicePixelRatio); - m_colors.addForRectangle(0.f, 0.f, 0.f, 0.f); + RGBAVertexUpdater vertexUpdater{geometry().vertexDataAs()}; + vertexUpdater.addRectangle({0.f, + halfBreadth - 0.5f}, + {static_cast(length), + m_isSlipRenderer ? halfBreadth : halfBreadth + 0.5f}, + {0.f, 0.f, 0.f, 0.f}); const double maxSamplingRange = visualIncrementPerPixel / 2.0; - for (int visualIdx = 0; visualIdx < length; ++visualIdx) { + for (int visualIdx = 0; visualIdx < pixelLength; ++visualIdx) { for (int stemIdx = 0; stemIdx < 4; stemIdx++) { // Stem is drawn twice with different opacity level, this allow to // see the maximum signal by transparency @@ -139,7 +160,7 @@ void WaveformRendererStem::paintGL() { const int visualIndexStop = std::min(std::max(visualFrameStop, visualFrameStart + 1) * 2, dataSize - 1); - const float fVisualIdx = static_cast(visualIdx); + const float fVisualIdx = static_cast(visualIdx) * invDevicePixelRatio; // Find the max values for current eq in the waveform data. // - Max of left and right @@ -164,43 +185,23 @@ void WaveformRendererStem::paintGL() { } // Lines are thin rectangles - // shawdow - m_vertices.addRectangle(fVisualIdx - 0.5f, - halfBreadth - heightFactor * max, - fVisualIdx + 0.5f, - m_isSlipRenderer ? halfBreadth : halfBreadth + heightFactor * max); - - m_colors.addForRectangle(color_r, color_g, color_b, color_a); + // shadow + vertexUpdater.addRectangle({fVisualIdx - halfPixelSize, + halfBreadth - heightFactor * max}, + {fVisualIdx + halfPixelSize, + m_isSlipRenderer ? halfBreadth : halfBreadth + heightFactor * max}, + {color_r, color_g, color_b, color_a}); } } + xVisualFrame += visualIncrementPerPixel; } - DEBUG_ASSERT(reserved == m_vertices.size()); - DEBUG_ASSERT(reserved == m_colors.size()); - - const QMatrix4x4 matrix; // TODO = m_waveformRenderer->getMatrix(true); - - const int matrixLocation = m_shader.matrixLocation(); - const int positionLocation = m_shader.positionLocation(); - const int colorLocation = m_shader.colorLocation(); - - m_shader.bind(); - m_shader.enableAttributeArray(positionLocation); - m_shader.enableAttributeArray(colorLocation); - - m_shader.setUniformValue(matrixLocation, matrix); - - m_shader.setAttributeArray( - positionLocation, GL_FLOAT, m_vertices.constData(), 2); - m_shader.setAttributeArray( - colorLocation, GL_FLOAT, m_colors.constData(), 4); + DEBUG_ASSERT(reserved == vertexUpdater.index()); - glDrawArrays(GL_TRIANGLES, 0, m_vertices.size()); + markDirtyMaterial(); - m_shader.disableAttributeArray(positionLocation); - m_shader.disableAttributeArray(colorLocation); - m_shader.release(); + return true; } } // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrendererstem.h b/src/waveform/renderers/allshader/waveformrendererstem.h index 99728194574..1b8881d0cc6 100644 --- a/src/waveform/renderers/allshader/waveformrendererstem.h +++ b/src/waveform/renderers/allshader/waveformrendererstem.h @@ -2,12 +2,9 @@ #include -#include "rendergraph/openglnode.h" -#include "shaders/rgbashader.h" -#include "shaders/textureshader.h" +#include "control/pollingcontrolproxy.h" +#include "rendergraph/geometrynode.h" #include "util/class.h" -#include "waveform/renderers/allshader/rgbadata.h" -#include "waveform/renderers/allshader/vertexdata.h" #include "waveform/renderers/allshader/waveformrenderersignalbase.h" class QOpenGLTexture; @@ -18,30 +15,31 @@ class WaveformRendererStem; class allshader::WaveformRendererStem final : public allshader::WaveformRendererSignalBase, - public rendergraph::OpenGLNode { + public rendergraph::GeometryNode { public: explicit WaveformRendererStem(WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type = ::WaveformRendererAbstract::Play); - // override ::WaveformRendererSignalBase + // Pure virtual from WaveformRendererSignalBase, not used void onSetup(const QDomNode& node) override; - void initializeGL() override; - void paintGL() override; + bool init() override; - private: - mixxx::RGBAShader m_shader; - mixxx::TextureShader m_textureShader; - VertexData m_vertices; - RGBAData m_colors; + bool supportsSlip() const override { + return true; + } + + // Virtuals for rendergraph::Node + void preprocess() override; + private: bool m_isSlipRenderer; - std::vector> m_pStemGain; - std::vector> m_pStemMute; + std::vector> m_pStemGain; + std::vector> m_pStemMute; - void drawTexture(float x, float y, QOpenGLTexture* texture); + bool preprocessInner(); DISALLOW_COPY_AND_ASSIGN(WaveformRendererStem); }; diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index eb1a5c2bc7b..ca657d0b24b 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -18,87 +18,36 @@ using namespace rendergraph; -namespace { -// On the use of QPainter: -// -// The renderers in this folder are optimized to use GLSL shaders and refrain -// from using QPainter on the QOpenGLWindow, which causes degredated performance. -// -// This renderer does use QPainter (indirectly, in WaveformMark::generateImage), but -// only to draw on a QImage. This is only done once when needed and the images are -// then used as textures to be drawn with a GLSL shader. - -class WaveformMarkNode : public rendergraph::GeometryNode { - public: - WaveformMark* m_pOwner{}; - - WaveformMarkNode(WaveformMark* pOwner, rendergraph::Context* pContext, const QImage& image) - : m_pOwner(pOwner) { - initForRectangles(1); - updateTexture(pContext, image); - } - void updateTexture(rendergraph::Context* pContext, const QImage& image) { - dynamic_cast(material()) - .setTexture(std::make_unique(pContext, image)); - m_textureWidth = image.width(); - m_textureHeight = image.height(); - } - void update(float x, float y, float devicePixelRatio) { - TexturedVertexUpdater vertexUpdater{ - geometry().vertexDataAs()}; - vertexUpdater.addRectangle({x, y}, - {x + m_textureWidth / devicePixelRatio, - y + m_textureHeight / devicePixelRatio}, - {0.f, 0.f}, - {1.f, 1.f}); - } - float textureWidth() const { - return m_textureWidth; - } - float textureHeight() const { - return m_textureHeight; - } - - public: - float m_textureWidth{}; - float m_textureHeight{}; -}; - -class WaveformMarkNodeGraphics : public WaveformMark::Graphics { - public: - WaveformMarkNodeGraphics(WaveformMark* pOwner, - rendergraph::Context* pContext, - const QImage& image) - : m_pNode(std::make_unique( - pOwner, pContext, image)) { - } - void updateTexture(rendergraph::Context* pContext, const QImage& image) { - waveformMarkNode()->updateTexture(pContext, image); - } - void update(float x, float y, float devicePixelRatio) { - waveformMarkNode()->update(x, y, devicePixelRatio); - } - float textureWidth() const { - return waveformMarkNode()->textureWidth(); - } - float textureHeight() const { - return waveformMarkNode()->textureHeight(); - } - void setNode(std::unique_ptr&& pNode) { - m_pNode = std::move(pNode); - } - void moveNodeToChildrenOf(rendergraph::Node* pParent) { - pParent->appendChildNode(std::move(m_pNode)); - } - - private: - WaveformMarkNode* waveformMarkNode() const { - return static_cast(m_pNode.get()); - } +allshader::WaveformMarkNode::WaveformMarkNode(WaveformMark* pOwner, + rendergraph::Context* pContext, + const QImage& image) + : m_pOwner(pOwner) { + initForRectangles(1); + updateTexture(pContext, image); +} - std::unique_ptr m_pNode; -}; -} // namespace +void allshader::WaveformMarkNode::updateTexture( + rendergraph::Context* pContext, const QImage& image) { + dynamic_cast(material()) + .setTexture(std::make_unique(pContext, image)); + m_textureWidth = image.width(); + m_textureHeight = image.height(); +} +void allshader::WaveformMarkNode::update(float x, float y, float devicePixelRatio) { + TexturedVertexUpdater vertexUpdater{ + geometry().vertexDataAs()}; + vertexUpdater.addRectangle({x, y}, + {x + m_textureWidth / devicePixelRatio, + y + m_textureHeight / devicePixelRatio}, + {0.f, 0.f}, + {1.f, 1.f}); +} +allshader::WaveformMarkNodeGraphics::WaveformMarkNodeGraphics(WaveformMark* pOwner, + rendergraph::Context* pContext, + const QImage& image) + : m_pNode(std::make_unique( + pOwner, pContext, image)) { +} // Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive // from WaveformRenderMarkBase. The base-class takes care of updating the marks @@ -226,12 +175,13 @@ void allshader::WaveformRenderMark::update() { // (transferring ownership). Later in this function we move the // visible nodes back to m_pMarkNodesParent children. while (auto pChild = m_pMarkNodesParent->firstChild()) { - auto pNode = castToUniquePtr(m_pMarkNodesParent->detachChildNode(pChild)); + auto pNode = m_pMarkNodesParent->detachChildNode(pChild); + WaveformMarkNode* pWaveformMarkNode = static_cast(pNode.get()); // Determine its WaveformMark - auto pMark = pNode->m_pOwner; + auto pMark = pWaveformMarkNode->m_pOwner; auto pGraphics = static_cast(pMark->m_pGraphics.get()); // Store the node with the WaveformMark - pGraphics->setNode(std::move(pNode)); + pGraphics->attachNode(std::move(pNode)); } auto positionType = m_isSlipRenderer ? ::WaveformRendererAbstract::Slip @@ -308,7 +258,7 @@ void allshader::WaveformRenderMark::update() { devicePixelRatio); // transfer back to m_pMarkNodesParent children, for rendering - pMarkNodeGraphics->moveNodeToChildrenOf(m_pMarkNodesParent); + m_pMarkNodesParent->appendChildNode(pMarkNodeGraphics->detachNode()); visible = true; } diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index f18b8559a5e..98cf99c6ec0 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -16,6 +16,8 @@ class Context; namespace allshader { class DigitsRenderNode; class WaveformRenderMark; +class WaveformMarkNode; +class WaveformMarkNodeGraphics; } class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, @@ -71,3 +73,65 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, DISALLOW_COPY_AND_ASSIGN(WaveformRenderMark); }; + +// On the use of QPainter: +// +// The renderers in this folder are optimized to use GLSL shaders and refrain +// from using QPainter on the QOpenGLWindow, which causes degredated performance. +// +// This renderer does use QPainter (indirectly, in WaveformMark::generateImage), but +// only to draw on a QImage. This is only done once when needed and the images are +// then used as textures to be drawn with a GLSL shader. + +class allshader::WaveformMarkNode : public rendergraph::GeometryNode { + public: + WaveformMark* m_pOwner{}; + + WaveformMarkNode(WaveformMark* pOwner, rendergraph::Context* pContext, const QImage& image); + void updateTexture(rendergraph::Context* pContext, const QImage& image); + void update(float x, float y, float devicePixelRatio); + float textureWidth() const { + return m_textureWidth; + } + float textureHeight() const { + return m_textureHeight; + } + + public: + float m_textureWidth{}; + float m_textureHeight{}; +}; + +class allshader::WaveformMarkNodeGraphics : public ::WaveformMark::Graphics { + public: + WaveformMarkNodeGraphics(WaveformMark* pOwner, + rendergraph::Context* pContext, + const QImage& image); + void updateTexture(rendergraph::Context* pContext, const QImage& image) { + waveformMarkNode()->updateTexture(pContext, image); + } + void update(float x, float y, float devicePixelRatio) { + waveformMarkNode()->update(x, y, devicePixelRatio); + } + float textureWidth() const { + return waveformMarkNode()->textureWidth(); + } + float textureHeight() const { + return waveformMarkNode()->textureHeight(); + } + void attachNode(std::unique_ptr pNode) { + DEBUG_ASSERT(!m_pNode); + m_pNode = std::move(pNode); + } + std::unique_ptr detachNode() { + return std::move(m_pNode); + } + + private: + WaveformMarkNode* waveformMarkNode() const { + DEBUG_ASSERT(!m_pNode); + return static_cast(m_pNode.get()); + } + + std::unique_ptr m_pNode; +}; From 2de8dedf3119546c733d71a0451f690a4b8093eb Mon Sep 17 00:00:00 2001 From: m0dB Date: Fri, 1 Nov 2024 20:44:05 +0100 Subject: [PATCH 53/64] missing file --- .../opengl/rendergraph/nodeinterface.h | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/rendergraph/opengl/rendergraph/nodeinterface.h diff --git a/src/rendergraph/opengl/rendergraph/nodeinterface.h b/src/rendergraph/opengl/rendergraph/nodeinterface.h new file mode 100644 index 00000000000..5740df2a9fb --- /dev/null +++ b/src/rendergraph/opengl/rendergraph/nodeinterface.h @@ -0,0 +1,21 @@ +#pragma once + +#include "backend/basenode.h" +#include "rendergraph/assert.h" + +namespace rendergraph { + +template +class NodeInterface : public T_Node { + public: + void appendChildNode(std::unique_ptr pNode) { + BaseNode* pRawNode = pNode.release(); + T_Node::appendChildNode(pRawNode); + } + std::unique_ptr detachChildNode(BaseNode* pNode) { + T_Node::removeChildNode(pNode); + return std::unique_ptr(pNode); + } +}; + +} // namespace rendergraph From d12d463e4cebb617435757cac06a427fb5d18517 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 2 Nov 2024 13:48:00 +0100 Subject: [PATCH 54/64] typo --- src/rendergraph/opengl/rendergraph/nodeinterface.h | 1 - src/rendergraph/scenegraph/rendergraph/nodeinterface.h | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/rendergraph/opengl/rendergraph/nodeinterface.h b/src/rendergraph/opengl/rendergraph/nodeinterface.h index 5740df2a9fb..c9ff1acaad5 100644 --- a/src/rendergraph/opengl/rendergraph/nodeinterface.h +++ b/src/rendergraph/opengl/rendergraph/nodeinterface.h @@ -1,7 +1,6 @@ #pragma once #include "backend/basenode.h" -#include "rendergraph/assert.h" namespace rendergraph { diff --git a/src/rendergraph/scenegraph/rendergraph/nodeinterface.h b/src/rendergraph/scenegraph/rendergraph/nodeinterface.h index 6bfaebacfbe..f5c42cadf46 100644 --- a/src/rendergraph/scenegraph/rendergraph/nodeinterface.h +++ b/src/rendergraph/scenegraph/rendergraph/nodeinterface.h @@ -10,15 +10,15 @@ class NodeInterface : public T_Node { public: void appendChildNode(std::unique_ptr pNode) { BaseNode* pRawNode = pNode.release(); - pRawNode->setFlag(QSNode::OwnedByParent, true); + pRawNode->setFlag(QSGNode::OwnedByParent, true); T_Node::appendChildNode(pRawNode); - DEBUG_ASSERT(pNode->flags() & QSNode::OwnedByParent); + DEBUG_ASSERT(pRawNode->flags() & QSGNode::OwnedByParent); } std::unique_ptr detachChildNode(BaseNode* pNode) { - DEBUG_ASSERT(pNode->flags() & QSNode::OwnedByParent); - pNode->setFlag(QSNode::OwnedByParent, false); + DEBUG_ASSERT(pNode->flags() & QSGNode::OwnedByParent); + pNode->setFlag(QSGNode::OwnedByParent, false); T_Node::removeChildNode(pNode); - DEBUG_ASSERT(!pNode->flags() & QSNode::OwnedByParent); + DEBUG_ASSERT(!pNode->flags() & QSGNode::OwnedByParent); return std::unique_ptr(pNode); } }; From c2d6c445dd057902b4120cac2363f2f46976968e Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 2 Nov 2024 14:41:45 +0100 Subject: [PATCH 55/64] various cleanup, acting on review --- src/rendergraph/common/rendergraph/assert.h | 2 ++ src/rendergraph/common/rendergraph/geometry.h | 22 ++----------------- .../common/rendergraph/geometrynode.h | 2 +- src/rendergraph/common/rendergraph/types.h | 5 +++++ .../vertexupdaters/rgbavertexupdater.h | 12 +++++----- .../vertexupdaters/rgbvertexupdater.h | 14 +++++++----- .../vertexupdaters/texturedvertexupdater.h | 6 ++--- .../vertexupdaters/vertexupdater.h | 6 ++--- .../examples/common/examplenode.cpp | 4 ++-- .../examples/sg_example/customitem.h | 5 +---- src/rendergraph/opengl/CMakeLists.txt | 20 +++++++++-------- .../opengl/backend/basegeometry.cpp | 2 +- src/rendergraph/opengl/backend/basegeometry.h | 2 +- .../opengl/backend/basegeometrynode.cpp | 6 ++--- .../opengl/backend/basegeometrynode.h | 2 +- src/rendergraph/opengl/backend/basematerial.h | 2 ++ .../opengl/backend/basematerialshader.cpp | 1 + .../opengl/backend/basematerialshader.h | 1 + src/rendergraph/opengl/backend/basenode.cpp | 19 +++++++++------- src/rendergraph/opengl/backend/basenode.h | 6 +++-- .../opengl/backend/baseopacitynode.h | 2 +- .../opengl/backend/baseopenglnode.cpp | 2 -- .../opengl/backend/baseopenglnode.h | 2 +- src/rendergraph/opengl/backend/basetexture.h | 2 +- src/rendergraph/opengl/backend/shadercache.h | 8 +++---- src/rendergraph/opengl/geometry.cpp | 8 +++---- src/rendergraph/scenegraph/CMakeLists.txt | 20 +++++++++-------- .../scenegraph/backend/basegeometry.h | 2 +- .../scenegraph/backend/basegeometrynode.h | 2 +- .../scenegraph/backend/basematerial.h | 2 +- .../scenegraph/backend/basematerialshader.h | 2 +- .../scenegraph/backend/basematerialtype.h | 2 +- src/rendergraph/scenegraph/backend/basenode.h | 2 +- .../scenegraph/backend/baseopacitynode.h | 2 +- .../scenegraph/backend/basetexture.h | 2 +- src/rendergraph/scenegraph/geometry.cpp | 17 +++++++------- 36 files changed, 107 insertions(+), 109 deletions(-) diff --git a/src/rendergraph/common/rendergraph/assert.h b/src/rendergraph/common/rendergraph/assert.h index 431ddbd12d7..6b47ad6a7f4 100644 --- a/src/rendergraph/common/rendergraph/assert.h +++ b/src/rendergraph/common/rendergraph/assert.h @@ -1 +1,3 @@ +// rendergraph is a module but we want to include util/assert.h from Mixxx, +// without adding the entire src/ dir to the include paths. #include "../../../util/assert.h" diff --git a/src/rendergraph/common/rendergraph/geometry.h b/src/rendergraph/common/rendergraph/geometry.h index 398c9493715..47108777493 100644 --- a/src/rendergraph/common/rendergraph/geometry.h +++ b/src/rendergraph/common/rendergraph/geometry.h @@ -12,43 +12,25 @@ class Geometry; class rendergraph::Geometry : public rendergraph::BaseGeometry { public: + using DrawingMode = rendergraph::DrawingMode; + struct Point2D { QVector2D position2D; - Point2D(float x, float y) - : position2D{x, y} { - } }; struct TexturedPoint2D { QVector2D position2D; QVector2D texcoord2D; - TexturedPoint2D(float x, float y, float tx, float ty) - : position2D{x, y}, - texcoord2D{tx, ty} { - } }; struct RGBColoredPoint2D { QVector2D position2D; QVector3D color3D; - RGBColoredPoint2D(float x, float y, float r, float g, float b) - : position2D{x, y}, - color3D{r, g, b} { - } }; struct RGBAColoredPoint2D { QVector2D position2D; QVector4D color4D; - RGBAColoredPoint2D(float x, float y, float r, float g, float b, float a) - : position2D{x, y}, - color4D{r, g, b, a} { - } - }; - - enum class DrawingMode { - Triangles, - TriangleStrip }; Geometry(const rendergraph::AttributeSet& attributeSet, int vertexCount); diff --git a/src/rendergraph/common/rendergraph/geometrynode.h b/src/rendergraph/common/rendergraph/geometrynode.h index fbcacba3647..37db115ce40 100644 --- a/src/rendergraph/common/rendergraph/geometrynode.h +++ b/src/rendergraph/common/rendergraph/geometrynode.h @@ -20,7 +20,7 @@ class rendergraph::GeometryNode : public rendergraph::NodeInterface(T_Material::attributes(), numRectangles * verticesPerRectangle)); setMaterial(std::make_unique()); - geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + geometry().setDrawingMode(DrawingMode::Triangles); } void setUsePreprocess(bool value); diff --git a/src/rendergraph/common/rendergraph/types.h b/src/rendergraph/common/rendergraph/types.h index 768738964fd..f92e8de6cda 100644 --- a/src/rendergraph/common/rendergraph/types.h +++ b/src/rendergraph/common/rendergraph/types.h @@ -2,6 +2,11 @@ namespace rendergraph { +enum class DrawingMode { + Triangles, + TriangleStrip +}; + enum class PrimitiveType { UInt, Float, diff --git a/src/rendergraph/common/rendergraph/vertexupdaters/rgbavertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/rgbavertexupdater.h index 87a149ff60f..afa7e466d1c 100644 --- a/src/rendergraph/common/rendergraph/vertexupdaters/rgbavertexupdater.h +++ b/src/rendergraph/common/rendergraph/vertexupdaters/rgbavertexupdater.h @@ -143,9 +143,9 @@ class rendergraph::RGBAVertexUpdater { float g, float b, float a) { - *m_pWrite++ = Geometry::RGBAColoredPoint2D{x1, y1, r, g, b, a}; - *m_pWrite++ = Geometry::RGBAColoredPoint2D{x2, y2, r, g, b, a}; - *m_pWrite++ = Geometry::RGBAColoredPoint2D{x3, y3, r, g, b, a}; + *m_pWrite++ = Geometry::RGBAColoredPoint2D{{x1, y1}, {r, g, b, a}}; + *m_pWrite++ = Geometry::RGBAColoredPoint2D{{x2, y2}, {r, g, b, a}}; + *m_pWrite++ = Geometry::RGBAColoredPoint2D{{x3, y3}, {r, g, b, a}}; } void addTriangle(float x1, float y1, @@ -165,9 +165,9 @@ class rendergraph::RGBAVertexUpdater { float g3, float b3, float a3) { - *m_pWrite++ = Geometry::RGBAColoredPoint2D{x1, y1, r1, g1, b1, a1}; - *m_pWrite++ = Geometry::RGBAColoredPoint2D{x2, y2, r2, g2, b2, a2}; - *m_pWrite++ = Geometry::RGBAColoredPoint2D{x3, y3, r3, g3, b3, a3}; + *m_pWrite++ = Geometry::RGBAColoredPoint2D{{x1, y1}, {r1, g1, b1, a1}}; + *m_pWrite++ = Geometry::RGBAColoredPoint2D{{x2, y2}, {r2, g2, b2, a2}}; + *m_pWrite++ = Geometry::RGBAColoredPoint2D{{x3, y3}, {r3, g3, b3, a3}}; } Geometry::RGBAColoredPoint2D* const m_pData; Geometry::RGBAColoredPoint2D* m_pWrite; diff --git a/src/rendergraph/common/rendergraph/vertexupdaters/rgbvertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/rgbvertexupdater.h index 873de8efee6..c7191e902ec 100644 --- a/src/rendergraph/common/rendergraph/vertexupdaters/rgbvertexupdater.h +++ b/src/rendergraph/common/rendergraph/vertexupdaters/rgbvertexupdater.h @@ -122,9 +122,9 @@ class rendergraph::RGBVertexUpdater { float r, float g, float b) { - *m_pWrite++ = Geometry::RGBColoredPoint2D{x1, y1, r, g, b}; - *m_pWrite++ = Geometry::RGBColoredPoint2D{x2, y2, r, g, b}; - *m_pWrite++ = Geometry::RGBColoredPoint2D{x3, y3, r, g, b}; + *m_pWrite++ = Geometry::RGBColoredPoint2D{{x1, y1}, {r, g, b}}; + *m_pWrite++ = Geometry::RGBColoredPoint2D{{x2, y2}, {r, g, b}}; + *m_pWrite++ = Geometry::RGBColoredPoint2D{{x3, y3}, {r, g, b}}; } void addTriangle(float x1, float y1, @@ -141,10 +141,12 @@ class rendergraph::RGBVertexUpdater { float r3, float g3, float b3) { - *m_pWrite++ = Geometry::RGBColoredPoint2D{x1, y1, r1, g1, b1}; - *m_pWrite++ = Geometry::RGBColoredPoint2D{x2, y2, r2, g2, b2}; - *m_pWrite++ = Geometry::RGBColoredPoint2D{x3, y3, r3, g3, b3}; + *m_pWrite++ = Geometry::RGBColoredPoint2D{{x1, y1}, {r1, g1, b1}}; + *m_pWrite++ = Geometry::RGBColoredPoint2D{{x2, y2}, {r2, g2, b2}}; + *m_pWrite++ = Geometry::RGBColoredPoint2D{{x3, y3}, {r3, g3, b3}}; } + + private: Geometry::RGBColoredPoint2D* const m_pData; Geometry::RGBColoredPoint2D* m_pWrite; }; diff --git a/src/rendergraph/common/rendergraph/vertexupdaters/texturedvertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/texturedvertexupdater.h index 172302854c7..29aa5beca04 100644 --- a/src/rendergraph/common/rendergraph/vertexupdaters/texturedvertexupdater.h +++ b/src/rendergraph/common/rendergraph/vertexupdaters/texturedvertexupdater.h @@ -61,9 +61,9 @@ class rendergraph::TexturedVertexUpdater { float ty2, float tx3, float ty3) { - *m_pWrite++ = Geometry::TexturedPoint2D{x1, y1, tx1, ty1}; - *m_pWrite++ = Geometry::TexturedPoint2D{x2, y2, tx2, ty2}; - *m_pWrite++ = Geometry::TexturedPoint2D{x3, y3, tx3, ty3}; + *m_pWrite++ = Geometry::TexturedPoint2D{{x1, y1}, {tx1, ty1}}; + *m_pWrite++ = Geometry::TexturedPoint2D{{x2, y2}, {tx2, ty2}}; + *m_pWrite++ = Geometry::TexturedPoint2D{{x3, y3}, {tx3, ty3}}; } Geometry::TexturedPoint2D* const m_pData; Geometry::TexturedPoint2D* m_pWrite; diff --git a/src/rendergraph/common/rendergraph/vertexupdaters/vertexupdater.h b/src/rendergraph/common/rendergraph/vertexupdaters/vertexupdater.h index 0e2791cb0fe..4ae381db209 100644 --- a/src/rendergraph/common/rendergraph/vertexupdaters/vertexupdater.h +++ b/src/rendergraph/common/rendergraph/vertexupdaters/vertexupdater.h @@ -31,9 +31,9 @@ class rendergraph::VertexUpdater { addTriangle(x1, y2, x2, y2, x2, y1); } void addTriangle(float x1, float y1, float x2, float y2, float x3, float y3) { - *m_pWrite++ = Geometry::Point2D{x1, y1}; - *m_pWrite++ = Geometry::Point2D{x2, y2}; - *m_pWrite++ = Geometry::Point2D{x3, y3}; + *m_pWrite++ = Geometry::Point2D{{x1, y1}}; + *m_pWrite++ = Geometry::Point2D{{x2, y2}}; + *m_pWrite++ = Geometry::Point2D{{x3, y3}}; } Geometry::Point2D* const m_pData; Geometry::Point2D* m_pWrite; diff --git a/src/rendergraph/examples/common/examplenode.cpp b/src/rendergraph/examples/common/examplenode.cpp index 452d4613b71..8af058ad3a2 100644 --- a/src/rendergraph/examples/common/examplenode.cpp +++ b/src/rendergraph/examples/common/examplenode.cpp @@ -30,7 +30,7 @@ ExampleNode::ExampleNode(rendergraph::Context* pContext) { auto pNode = std::make_unique(); pNode->initForRectangles(2); pNode->material().setUniform(1, QColor(255, 127, 0)); - pNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + pNode->geometry().setDrawingMode(DrawingMode::Triangles); rendergraph::VertexUpdater vertexUpdater{ pNode->geometry() .vertexDataAs()}; @@ -41,7 +41,7 @@ ExampleNode::ExampleNode(rendergraph::Context* pContext) { { auto pNode = std::make_unique(); pNode->initForRectangles(2); - pNode->geometry().setDrawingMode(Geometry::DrawingMode::Triangles); + pNode->geometry().setDrawingMode(DrawingMode::Triangles); rendergraph::RGBVertexUpdater vertexUpdater{ pNode->geometry().vertexDataAs()}; vertexUpdater.addRectangle({300, 100}, {340, 140}, {1.f, 0.f, 0.5f}); diff --git a/src/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/examples/sg_example/customitem.h index 86f8e19f813..a02d0b4f0df 100644 --- a/src/rendergraph/examples/sg_example/customitem.h +++ b/src/rendergraph/examples/sg_example/customitem.h @@ -1,5 +1,4 @@ -#ifndef CUSTOMITEM_H -#define CUSTOMITEM_H +#pragma once #include #include @@ -20,5 +19,3 @@ class CustomItem : public QQuickItem { bool m_geometryChanged{}; }; - -#endif // CUSTOMITEM_H diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index 529ba2efdb7..d6ca282017b 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -62,15 +62,17 @@ target_link_libraries(rendergraph_gl PUBLIC Qt6::Gui Qt6::OpenGL ) -find_package(Microsoft.GSL CONFIG) -if(Microsoft.GSL_FOUND) - target_link_libraries(rendergraph_gl PRIVATE Microsoft.GSL::GSL) -else() - # check if the headers have been installed without cmake config (< 3.1.0) - check_include_file_cxx(gsl/gsl HAVE_GSL_GSL) - if(NOT HAVE_GSL_GSL) - unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag. - message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found") +if(WIN32) + find_package(Microsoft.GSL CONFIG) + if(Microsoft.GSL_FOUND) + target_link_libraries(rendergraph_gl PRIVATE Microsoft.GSL::GSL) + else() + # check if the headers have been installed without cmake config (< 3.1.0) + check_include_file_cxx(gsl/gsl HAVE_GSL_GSL) + if(NOT HAVE_GSL_GSL) + unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag. + message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found") + endif() endif() endif() target_compile_definitions(rendergraph_gl PRIVATE rendergraph=rendergraph_gl) diff --git a/src/rendergraph/opengl/backend/basegeometry.cpp b/src/rendergraph/opengl/backend/basegeometry.cpp index 81471400cb6..09854386dbe 100644 --- a/src/rendergraph/opengl/backend/basegeometry.cpp +++ b/src/rendergraph/opengl/backend/basegeometry.cpp @@ -7,7 +7,7 @@ using namespace rendergraph; namespace { // to mimic sg default -constexpr int defaultDrawingMode = static_cast(Geometry::DrawingMode::TriangleStrip); +constexpr auto defaultDrawingMode = DrawingMode::TriangleStrip; } // namespace BaseGeometry::BaseGeometry( diff --git a/src/rendergraph/opengl/backend/basegeometry.h b/src/rendergraph/opengl/backend/basegeometry.h index 5b17f518494..b2e26a32b42 100644 --- a/src/rendergraph/opengl/backend/basegeometry.h +++ b/src/rendergraph/opengl/backend/basegeometry.h @@ -50,7 +50,7 @@ class rendergraph::BaseGeometry { const Attribute* m_pAttributes; const int m_attributeCount; const int m_sizeOfVertex; - int m_drawingMode; + DrawingMode m_drawingMode; int m_vertexCount; std::vector m_vertexData; }; diff --git a/src/rendergraph/opengl/backend/basegeometrynode.cpp b/src/rendergraph/opengl/backend/basegeometrynode.cpp index 1bd22a97a0c..a4b2e303f86 100644 --- a/src/rendergraph/opengl/backend/basegeometrynode.cpp +++ b/src/rendergraph/opengl/backend/basegeometrynode.cpp @@ -10,11 +10,11 @@ using namespace rendergraph; namespace { -GLenum toGlDrawingMode(Geometry::DrawingMode mode) { +GLenum toGlDrawingMode(DrawingMode mode) { switch (mode) { - case Geometry::DrawingMode::Triangles: + case DrawingMode::Triangles: return GL_TRIANGLES; - case Geometry::DrawingMode::TriangleStrip: + case DrawingMode::TriangleStrip: return GL_TRIANGLE_STRIP; } } diff --git a/src/rendergraph/opengl/backend/basegeometrynode.h b/src/rendergraph/opengl/backend/basegeometrynode.h index a795a67b134..a4a7f609c4a 100644 --- a/src/rendergraph/opengl/backend/basegeometrynode.h +++ b/src/rendergraph/opengl/backend/basegeometrynode.h @@ -14,7 +14,7 @@ class rendergraph::BaseGeometryNode : public rendergraph::BaseNode, BaseGeometryNode() = default; virtual ~BaseGeometryNode() = default; - public: + // called by Engine void initialize() override; void render() override; void resize(int w, int h) override; diff --git a/src/rendergraph/opengl/backend/basematerial.h b/src/rendergraph/opengl/backend/basematerial.h index c08b60daab2..6f2a22ccba2 100644 --- a/src/rendergraph/opengl/backend/basematerial.h +++ b/src/rendergraph/opengl/backend/basematerial.h @@ -26,5 +26,7 @@ class rendergraph::BaseMaterial { void modifyShader(); bool isLastModifierOfShader() const; + + private: std::shared_ptr m_pShader; }; diff --git a/src/rendergraph/opengl/backend/basematerialshader.cpp b/src/rendergraph/opengl/backend/basematerialshader.cpp index d4b245e482a..498ed8fbe4f 100644 --- a/src/rendergraph/opengl/backend/basematerialshader.cpp +++ b/src/rendergraph/opengl/backend/basematerialshader.cpp @@ -13,6 +13,7 @@ int BaseMaterialShader::uniformLocation(int uniformIndex) const { BaseMaterial* BaseMaterialShader::lastModifiedByMaterial() const { return m_pLastModifiedByMaterial; } + void BaseMaterialShader::setLastModifiedByMaterial(BaseMaterial* pMaterial) { m_pLastModifiedByMaterial = pMaterial; } diff --git a/src/rendergraph/opengl/backend/basematerialshader.h b/src/rendergraph/opengl/backend/basematerialshader.h index f7082c15ef0..f5e1b3e195e 100644 --- a/src/rendergraph/opengl/backend/basematerialshader.h +++ b/src/rendergraph/opengl/backend/basematerialshader.h @@ -19,6 +19,7 @@ class rendergraph::BaseMaterialShader : public QOpenGLShaderProgram { BaseMaterial* lastModifiedByMaterial() const; void setLastModifiedByMaterial(BaseMaterial* pMaterial); + protected: std::vector m_attributeLocations; std::vector m_uniformLocations; BaseMaterial* m_pLastModifiedByMaterial{}; diff --git a/src/rendergraph/opengl/backend/basenode.cpp b/src/rendergraph/opengl/backend/basenode.cpp index 5a902f5cc92..a413325ee29 100644 --- a/src/rendergraph/opengl/backend/basenode.cpp +++ b/src/rendergraph/opengl/backend/basenode.cpp @@ -10,11 +10,16 @@ BaseNode::~BaseNode() { DEBUG_ASSERT(m_pEngine == nullptr); while (m_pFirstChild) { - std::unique_ptr pChild(m_pFirstChild); - removeChildNode(pChild.get()); + auto pChild = m_pFirstChild; + removeChildNode(pChild); + delete pChild; } } +// This mimics QSGNode::appendChildNode. +// Use NodeInterface::appendChildNode(std::unique_ptr pNode) +// for a more clear transfer of ownership. pChild is considered owned by +// this at this point. void BaseNode::appendChildNode(BaseNode* pChild) { if (m_pLastChild) { pChild->m_pPreviousSibling = m_pLastChild; @@ -32,12 +37,10 @@ void BaseNode::appendChildNode(BaseNode* pChild) { } } -void BaseNode::removeAllChildNodes() { - while (m_pFirstChild) { - removeChildNode(m_pFirstChild); - } -} - +// This mimics QSGNode::removeChildNode. +// Use NodeInterface::detachChildNode(BaseNode* pNode) +// for a more clear transfer of ownership. Otherwise, +// deleting pChild is responsibility of the caller. void BaseNode::removeChildNode(BaseNode* pChild) { if (pChild == m_pFirstChild) { m_pFirstChild = pChild->m_pNextSibling; diff --git a/src/rendergraph/opengl/backend/basenode.h b/src/rendergraph/opengl/backend/basenode.h index 5ca86197a87..b0079954697 100644 --- a/src/rendergraph/opengl/backend/basenode.h +++ b/src/rendergraph/opengl/backend/basenode.h @@ -5,7 +5,7 @@ namespace rendergraph { class BaseNode; class Engine; -} +} // namespace rendergraph class rendergraph::BaseNode { public: @@ -36,8 +36,9 @@ class rendergraph::BaseNode { return m_pEngine; } + // Prefer using NodeInterface::appendChildNode(std::unique_ptr pNode); void appendChildNode(BaseNode* pChild); - void removeAllChildNodes(); + // Prefer using std::unique_ptr NodeInterface::detachChildNode(BaseNode* pNode); void removeChildNode(BaseNode* pChild); BaseNode* parent() const { @@ -60,6 +61,7 @@ class rendergraph::BaseNode { Engine* m_pEngine{}; bool m_usePreprocess{}; + // Mimicking scenegraph node hierarchy. A parent owns its children. BaseNode* m_pParent{}; BaseNode* m_pFirstChild{}; BaseNode* m_pLastChild{}; diff --git a/src/rendergraph/opengl/backend/baseopacitynode.h b/src/rendergraph/opengl/backend/baseopacitynode.h index 8917dfb10da..1bd11da2fe0 100644 --- a/src/rendergraph/opengl/backend/baseopacitynode.h +++ b/src/rendergraph/opengl/backend/baseopacitynode.h @@ -4,7 +4,7 @@ namespace rendergraph { class BaseOpacityNode; -} +} // namespace rendergraph class rendergraph::BaseOpacityNode : public rendergraph::BaseNode { public: diff --git a/src/rendergraph/opengl/backend/baseopenglnode.cpp b/src/rendergraph/opengl/backend/baseopenglnode.cpp index 165275448cb..13c3bdfc783 100644 --- a/src/rendergraph/opengl/backend/baseopenglnode.cpp +++ b/src/rendergraph/opengl/backend/baseopenglnode.cpp @@ -10,11 +10,9 @@ void BaseOpenGLNode::initialize() { } void BaseOpenGLNode::render() { - OpenGLNode* pThis = static_cast(this); paintGL(); } void BaseOpenGLNode::resize(int w, int h) { - OpenGLNode* pThis = static_cast(this); resizeGL(w, h); } diff --git a/src/rendergraph/opengl/backend/baseopenglnode.h b/src/rendergraph/opengl/backend/baseopenglnode.h index 641d286b65e..545f5381630 100644 --- a/src/rendergraph/opengl/backend/baseopenglnode.h +++ b/src/rendergraph/opengl/backend/baseopenglnode.h @@ -6,7 +6,7 @@ namespace rendergraph { class BaseOpenGLNode; -} +} // namespace rendergraph class rendergraph::BaseOpenGLNode : public rendergraph::BaseNode, public QOpenGLFunctions { diff --git a/src/rendergraph/opengl/backend/basetexture.h b/src/rendergraph/opengl/backend/basetexture.h index f260dc91ebb..1a47541fe24 100644 --- a/src/rendergraph/opengl/backend/basetexture.h +++ b/src/rendergraph/opengl/backend/basetexture.h @@ -4,4 +4,4 @@ namespace rendergraph { using BaseTexture = QOpenGLTexture; -} +} // namespace rendergraph diff --git a/src/rendergraph/opengl/backend/shadercache.h b/src/rendergraph/opengl/backend/shadercache.h index 9c4653e493c..bf8cc9a7198 100644 --- a/src/rendergraph/opengl/backend/shadercache.h +++ b/src/rendergraph/opengl/backend/shadercache.h @@ -1,6 +1,6 @@ #pragma once -#include +#include #include "rendergraph/material.h" #include "rendergraph/materialshader.h" @@ -8,14 +8,14 @@ namespace rendergraph { class ShaderCache; -} +} // namespace rendergraph class rendergraph::ShaderCache { private: - static std::map>& map() { - static std::map> s_map; return s_map; diff --git a/src/rendergraph/opengl/geometry.cpp b/src/rendergraph/opengl/geometry.cpp index 6d4a9d04c49..b2fbfbbcd2a 100644 --- a/src/rendergraph/opengl/geometry.cpp +++ b/src/rendergraph/opengl/geometry.cpp @@ -36,10 +36,10 @@ void Geometry::setAttributeValues(int attributePosition, const float* from, int } } -void Geometry::setDrawingMode(Geometry::DrawingMode mode) { - m_drawingMode = static_cast(mode); +void Geometry::setDrawingMode(DrawingMode mode) { + m_drawingMode = mode; } -Geometry::DrawingMode Geometry::drawingMode() const { - return static_cast(m_drawingMode); +DrawingMode Geometry::drawingMode() const { + return m_drawingMode; } diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index 52c197e0ef3..ad96eb1e491 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -55,15 +55,17 @@ target_link_libraries(rendergraph_sg PUBLIC Qt6::Qml Qt6::Quick ) -find_package(Microsoft.GSL CONFIG) -if(Microsoft.GSL_FOUND) - target_link_libraries(rendergraph_sg PRIVATE Microsoft.GSL::GSL) -else() - # check if the headers have been installed without cmake config (< 3.1.0) - check_include_file_cxx(gsl/gsl HAVE_GSL_GSL) - if(NOT HAVE_GSL_GSL) - unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag. - message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found") +if(WIN32) + find_package(Microsoft.GSL CONFIG) + if(Microsoft.GSL_FOUND) + target_link_libraries(rendergraph_sg PRIVATE Microsoft.GSL::GSL) + else() + # check if the headers have been installed without cmake config (< 3.1.0) + check_include_file_cxx(gsl/gsl HAVE_GSL_GSL) + if(NOT HAVE_GSL_GSL) + unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag. + message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found") + endif() endif() endif() target_compile_definitions(rendergraph_sg PRIVATE rendergraph=rendergraph_sg) diff --git a/src/rendergraph/scenegraph/backend/basegeometry.h b/src/rendergraph/scenegraph/backend/basegeometry.h index 45cf8780309..6d15a9f49dd 100644 --- a/src/rendergraph/scenegraph/backend/basegeometry.h +++ b/src/rendergraph/scenegraph/backend/basegeometry.h @@ -6,4 +6,4 @@ namespace rendergraph { using BaseGeometry = QSGGeometry; -} +} // namespace rendergraph diff --git a/src/rendergraph/scenegraph/backend/basegeometrynode.h b/src/rendergraph/scenegraph/backend/basegeometrynode.h index e665e8451aa..26dd0b323bc 100644 --- a/src/rendergraph/scenegraph/backend/basegeometrynode.h +++ b/src/rendergraph/scenegraph/backend/basegeometrynode.h @@ -4,4 +4,4 @@ namespace rendergraph { using BaseGeometryNode = QSGGeometryNode; -} +} // namespace rendergraph diff --git a/src/rendergraph/scenegraph/backend/basematerial.h b/src/rendergraph/scenegraph/backend/basematerial.h index 7c745f3d991..ac434248d2f 100644 --- a/src/rendergraph/scenegraph/backend/basematerial.h +++ b/src/rendergraph/scenegraph/backend/basematerial.h @@ -4,7 +4,7 @@ namespace rendergraph { class BaseMaterial; -} +} // namespace rendergraph class rendergraph::BaseMaterial : public QSGMaterial { protected: diff --git a/src/rendergraph/scenegraph/backend/basematerialshader.h b/src/rendergraph/scenegraph/backend/basematerialshader.h index e9c0ef40d3f..cbf5cb206f3 100644 --- a/src/rendergraph/scenegraph/backend/basematerialshader.h +++ b/src/rendergraph/scenegraph/backend/basematerialshader.h @@ -5,7 +5,7 @@ namespace rendergraph { class BaseMaterialShader; -} +} // namespace rendergraph class rendergraph::BaseMaterialShader : public QSGMaterialShader { protected: diff --git a/src/rendergraph/scenegraph/backend/basematerialtype.h b/src/rendergraph/scenegraph/backend/basematerialtype.h index b3606003e03..3bcefcf54e6 100644 --- a/src/rendergraph/scenegraph/backend/basematerialtype.h +++ b/src/rendergraph/scenegraph/backend/basematerialtype.h @@ -4,4 +4,4 @@ namespace rendergraph { using BaseMaterialType = QSGMaterialType; -} +} // namespace rendergraph diff --git a/src/rendergraph/scenegraph/backend/basenode.h b/src/rendergraph/scenegraph/backend/basenode.h index 3ece5661d80..0eac56e1e0e 100644 --- a/src/rendergraph/scenegraph/backend/basenode.h +++ b/src/rendergraph/scenegraph/backend/basenode.h @@ -4,4 +4,4 @@ namespace rendergraph { using BaseNode = QSGNode; -} +} // namespace rendergraph diff --git a/src/rendergraph/scenegraph/backend/baseopacitynode.h b/src/rendergraph/scenegraph/backend/baseopacitynode.h index 3a3ef1b8661..14ea7e9d75f 100644 --- a/src/rendergraph/scenegraph/backend/baseopacitynode.h +++ b/src/rendergraph/scenegraph/backend/baseopacitynode.h @@ -4,4 +4,4 @@ namespace rendergraph { using BaseOpacityNode = QSGOpacityNode; -} +} // namespace rendergraph diff --git a/src/rendergraph/scenegraph/backend/basetexture.h b/src/rendergraph/scenegraph/backend/basetexture.h index 10840145d52..287319af829 100644 --- a/src/rendergraph/scenegraph/backend/basetexture.h +++ b/src/rendergraph/scenegraph/backend/basetexture.h @@ -4,4 +4,4 @@ namespace rendergraph { using BaseTexture = QSGTexture; -} +} // namespace rendergraph diff --git a/src/rendergraph/scenegraph/geometry.cpp b/src/rendergraph/scenegraph/geometry.cpp index 6f1ccd55c54..b320e71d09c 100644 --- a/src/rendergraph/scenegraph/geometry.cpp +++ b/src/rendergraph/scenegraph/geometry.cpp @@ -5,21 +5,21 @@ using namespace rendergraph; namespace { -QSGGeometry::DrawingMode toSgDrawingMode(Geometry::DrawingMode mode) { +QSGGeometry::DrawingMode toSgDrawingMode(DrawingMode mode) { switch (mode) { - case Geometry::DrawingMode::Triangles: + case DrawingMode::Triangles: return QSGGeometry::DrawTriangles; - case Geometry::DrawingMode::TriangleStrip: + case DrawingMode::TriangleStrip: return QSGGeometry::DrawTriangleStrip; } } -Geometry::DrawingMode fromSgDrawingMode(unsigned int mode) { +DrawingMode fromSgDrawingMode(unsigned int mode) { switch (mode) { case QSGGeometry::DrawTriangles: - return Geometry::DrawingMode::Triangles; + return DrawingMode::Triangles; case QSGGeometry::DrawTriangleStrip: - return Geometry::DrawingMode::TriangleStrip; + return DrawingMode::TriangleStrip; default: throw "not implemented"; } @@ -57,11 +57,10 @@ void Geometry::setAttributeValues(int attributePosition, const float* from, int } } - -void Geometry::setDrawingMode(Geometry::DrawingMode mode) { +void Geometry::setDrawingMode(DrawingMode mode) { QSGGeometry::setDrawingMode(toSgDrawingMode(mode)); } -Geometry::DrawingMode Geometry::drawingMode() const { +DrawingMode Geometry::drawingMode() const { return fromSgDrawingMode(QSGGeometry::drawingMode()); } From 8b25d13296dace794454b31728ddf507d23bbc27 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 2 Nov 2024 15:02:43 +0100 Subject: [PATCH 56/64] improved attributeset from niko --- src/rendergraph/common/rendergraph/attributeset.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/rendergraph/common/rendergraph/attributeset.h b/src/rendergraph/common/rendergraph/attributeset.h index b79833934fe..717f47a3084 100644 --- a/src/rendergraph/common/rendergraph/attributeset.h +++ b/src/rendergraph/common/rendergraph/attributeset.h @@ -4,17 +4,17 @@ #include "rendergraph/attributeinit.h" namespace rendergraph { -class AttributeSet; -} -class rendergraph::AttributeSet : public rendergraph::BaseAttributeSet { +class AttributeSet : public BaseAttributeSet { public: AttributeSet(std::initializer_list list, const std::vector& names); }; -namespace rendergraph { -template -AttributeSet makeAttributeSet(const std::vector& names) { - return AttributeSet({(AttributeInit::create())...}, names); +template +AttributeSet makeAttributeSet(const QString (&names)[N]) { + static_assert(sizeof...(Ts) == N); + return AttributeSet({(AttributeInit::create())...}, + std::vector(std::cbegin(names), std::cend(names))); } + } // namespace rendergraph From a57b8230306488c205881cd0c7e57bdde7e830b5 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 2 Nov 2024 15:03:10 +0100 Subject: [PATCH 57/64] cleanup and comments --- src/rendergraph/examples/sg_example/customitem.h | 2 +- src/rendergraph/opengl/rendergraph/nodeinterface.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rendergraph/examples/sg_example/customitem.h b/src/rendergraph/examples/sg_example/customitem.h index a02d0b4f0df..87938f41653 100644 --- a/src/rendergraph/examples/sg_example/customitem.h +++ b/src/rendergraph/examples/sg_example/customitem.h @@ -11,7 +11,7 @@ class CustomItem : public QQuickItem { public: explicit CustomItem(QQuickItem* parent = nullptr); - ~CustomItem(); + ~CustomItem() override; protected: QSGNode* updatePaintNode(QSGNode*, UpdatePaintNodeData*) override; diff --git a/src/rendergraph/opengl/rendergraph/nodeinterface.h b/src/rendergraph/opengl/rendergraph/nodeinterface.h index c9ff1acaad5..45159724c49 100644 --- a/src/rendergraph/opengl/rendergraph/nodeinterface.h +++ b/src/rendergraph/opengl/rendergraph/nodeinterface.h @@ -8,10 +8,21 @@ template class NodeInterface : public T_Node { public: void appendChildNode(std::unique_ptr pNode) { + // Transfers ownership to this. BaseNode* pRawNode = pNode.release(); + // Note: Ideally we would use unique_ptrs internally, but + // Qt uses raw pointers for QSGNode hierarchy. For simplicity + // we mimic this. + T_Node::appendChildNode(pRawNode); } + std::unique_ptr detachChildNode(BaseNode* pNode) { + // After removeChildNode, the caller has the responsibility + // to deal with the child node. By returning a unique_ptr + // we preoprtly transfer ownership to the caller (which + // can result in deleting pNode if the caller doesn't + // take the unique_ptr). T_Node::removeChildNode(pNode); return std::unique_ptr(pNode); } From c7a3c7af2842e2b43655e562c8f823483b4787b2 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 2 Nov 2024 15:10:36 +0100 Subject: [PATCH 58/64] use std::erase --- src/rendergraph/examples/CMakeLists.txt | 2 ++ src/rendergraph/opengl/backend/shadercache.h | 12 ++++-------- src/rendergraph/opengl/engine.cpp | 14 ++------------ 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/rendergraph/examples/CMakeLists.txt b/src/rendergraph/examples/CMakeLists.txt index 8419ece7723..fb5b7c40e5d 100644 --- a/src/rendergraph/examples/CMakeLists.txt +++ b/src/rendergraph/examples/CMakeLists.txt @@ -1,6 +1,8 @@ cmake_minimum_required(VERSION 3.16) project(rendergraph LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 20) + find_package(Qt6 REQUIRED COMPONENTS Core Gui Qml Quick ShaderTools) if(NOT(QT_VERSION VERSION_LESS "6.3.0")) diff --git a/src/rendergraph/opengl/backend/shadercache.h b/src/rendergraph/opengl/backend/shadercache.h index bf8cc9a7198..557a0b6a582 100644 --- a/src/rendergraph/opengl/backend/shadercache.h +++ b/src/rendergraph/opengl/backend/shadercache.h @@ -36,13 +36,9 @@ class rendergraph::ShaderCache { return pResult; } static void purge() { - auto iter = map().begin(); - while (iter != map().end()) { - if (iter->second.use_count() == 1) { - iter = map().erase(iter); - } else { - ++iter; - } - } + std::erase_if(map(), [](const auto& item) { + auto const& [key, value] = item; + return value.use_count() == 1; + }); } }; diff --git a/src/rendergraph/opengl/engine.cpp b/src/rendergraph/opengl/engine.cpp index bfdce71431a..f8188375e36 100644 --- a/src/rendergraph/opengl/engine.cpp +++ b/src/rendergraph/opengl/engine.cpp @@ -35,18 +35,8 @@ void Engine::remove(BaseNode* pNode) { assert(pNode->engine() == this); pNode->setEngine(nullptr); - { - auto it = std::find(m_pInitializeNodes.begin(), m_pInitializeNodes.end(), pNode); - if (it != m_pInitializeNodes.end()) { - m_pInitializeNodes.erase(it); - } - } - { - auto it = std::find(m_pPreprocessNodes.begin(), m_pPreprocessNodes.end(), pNode); - if (it != m_pPreprocessNodes.end()) { - m_pPreprocessNodes.erase(it); - } - } + std::erase(m_pInitializeNodes, pNode); + std::erase(m_pPreprocessNodes, pNode); if (m_pRootNode.get() == pNode) { m_pRootNode.reset(); From f409455ff76c786dcd1ab66a04dfec4e049c22c8 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 2 Nov 2024 15:19:53 +0100 Subject: [PATCH 59/64] reduce delta with qml-rendergraph-fixes --- .../allshader/waveformrendererendoftrack.cpp | 56 ++++++++++--------- .../allshader/waveformrendererendoftrack.h | 3 +- .../allshader/waveformrendermark.cpp | 11 +--- .../renderers/allshader/waveformrendermark.h | 2 +- .../allshader/waveformrendermarkrange.cpp | 11 ++-- .../allshader/waveformrendermarkrange.h | 9 ++- src/waveform/renderers/waveformmark.h | 2 +- src/waveform/renderers/waveformmarkrange.h | 2 +- .../renderers/waveformrendermarkbase.cpp | 4 ++ .../renderers/waveformrendermarkbase.h | 2 + .../renderers/waveformwidgetrenderer.cpp | 18 ++---- .../renderers/waveformwidgetrenderer.h | 6 +- 12 files changed, 62 insertions(+), 64 deletions(-) diff --git a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp index 6f4b92aa501..197d147b831 100644 --- a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp +++ b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp @@ -59,6 +59,17 @@ void WaveformRendererEndOfTrack::setup(const QDomNode& node, const SkinContext& } void WaveformRendererEndOfTrack::preprocess() { + if (!preprocessInner()) { + geometry().allocate(0); + markDirtyGeometry(); + } +} + +bool WaveformRendererEndOfTrack::preprocessInner() { + if (!m_pEndOfTrackControl->toBool()) { + return false; + } + const int elapsed = m_timer.elapsed().toIntegerMillis() % kBlinkingPeriodMillis; const double blinkIntensity = (double)(2 * abs(elapsed - kBlinkingPeriodMillis / 2)) / @@ -70,39 +81,32 @@ void WaveformRendererEndOfTrack::preprocess() { const double criticalIntensity = (remainingTimeTriggerSeconds - remainingTime) / remainingTimeTriggerSeconds; - const double alpha = criticalIntensity * blinkIntensity; + const double alpha = std::min(1.0, std::max(0.0, criticalIntensity * blinkIntensity)); - if (alpha != 0.0) { - QSizeF size(m_waveformRenderer->getWidth(), m_waveformRenderer->getHeight()); - float r, g, b, a; - getRgbF(m_color, &r, &g, &b, &a); + QSizeF size(m_waveformRenderer->getWidth(), m_waveformRenderer->getHeight()); + float r, g, b, a; + getRgbF(m_color, &r, &g, &b, &a); - const float posx0 = 0.f; - const float posx1 = size.width() / 2.f; - const float posx2 = size.width(); - const float posy1 = 0.f; - const float posy2 = size.height(); + const float posx0 = 0.f; + const float posx1 = size.width() / 2.f; + const float posx2 = size.width(); + const float posy1 = 0.f; + const float posy2 = size.height(); - float minAlpha = 0.5f * static_cast(alpha); - float maxAlpha = 0.83f * static_cast(alpha); + float minAlpha = 0.5f * static_cast(alpha); + float maxAlpha = 0.83f * static_cast(alpha); - geometry().allocate(6 * 2); - RGBAVertexUpdater vertexUpdater{geometry().vertexDataAs()}; - vertexUpdater.addRectangleHGradient( - {posx0, posy1}, {posx1, posy2}, {r, g, b, minAlpha}, {r, g, b, minAlpha}); - vertexUpdater.addRectangleHGradient( - {posx1, posy1}, {posx2, posy2}, {r, g, b, minAlpha}, {r, g, b, maxAlpha}); + geometry().allocate(6 * 2); + RGBAVertexUpdater vertexUpdater{geometry().vertexDataAs()}; + vertexUpdater.addRectangleHGradient( + {posx0, posy1}, {posx1, posy2}, {r, g, b, minAlpha}, {r, g, b, minAlpha}); + vertexUpdater.addRectangleHGradient( + {posx1, posy1}, {posx2, posy2}, {r, g, b, minAlpha}, {r, g, b, maxAlpha}); - markDirtyGeometry(); - } else if (geometry().vertexCount() != 0) { - geometry().allocate(0); - markDirtyGeometry(); - } + markDirtyGeometry(); markDirtyMaterial(); -} -bool WaveformRendererEndOfTrack::isSubtreeBlocked() const { - return !m_pEndOfTrackControl->toBool(); + return true; } } // namespace allshader diff --git a/src/waveform/renderers/allshader/waveformrendererendoftrack.h b/src/waveform/renderers/allshader/waveformrendererendoftrack.h index 8f6d69f7262..d43d901f677 100644 --- a/src/waveform/renderers/allshader/waveformrendererendoftrack.h +++ b/src/waveform/renderers/allshader/waveformrendererendoftrack.h @@ -33,7 +33,6 @@ class allshader::WaveformRendererEndOfTrack final // Virtual for rendergraph::Node void preprocess() override; - bool isSubtreeBlocked() const override; private: std::unique_ptr m_pEndOfTrackControl; @@ -42,5 +41,7 @@ class allshader::WaveformRendererEndOfTrack final QColor m_color; PerformanceTimer m_timer; + bool preprocessInner(); + DISALLOW_COPY_AND_ASSIGN(WaveformRendererEndOfTrack); }; diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index ca657d0b24b..cec1b60c334 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -119,6 +119,7 @@ void allshader::WaveformRenderMark::draw(QPainter* painter, QPaintEvent* event) bool allshader::WaveformRenderMark::init() { m_pTimeRemainingControl = std::make_unique( m_waveformRenderer->getGroup(), "time_remaining"); + ::WaveformRenderMarkBase::init(); return true; } @@ -150,16 +151,6 @@ bool allshader::WaveformRenderMark::isSubtreeBlocked() const { return m_isSlipRenderer && !m_waveformRenderer->isSlipActive(); } -namespace { -template -std::unique_ptr castToUniquePtr(std::unique_ptr&& pNode) { - if (dynamic_cast(pNode.get())) { - return std::unique_ptr(dynamic_cast(pNode.release())); - } - return std::unique_ptr(); -} -} // namespace - void allshader::WaveformRenderMark::update() { if (isSubtreeBlocked()) { return; diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index 98cf99c6ec0..e0ef9e1d386 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -129,7 +129,7 @@ class allshader::WaveformMarkNodeGraphics : public ::WaveformMark::Graphics { private: WaveformMarkNode* waveformMarkNode() const { - DEBUG_ASSERT(!m_pNode); + DEBUG_ASSERT(m_pNode); return static_cast(m_pNode.get()); } diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp index 6efb9a1410b..1de0c3c88af 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.cpp +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.cpp @@ -21,12 +21,11 @@ void WaveformRenderMarkRange::setup(const QDomNode& node, const SkinContext& ski QDomNode child = node.firstChild(); while (!child.isNull()) { if (child.nodeName() == "MarkRange") { - m_markRanges.push_back( - WaveformMarkRange( - m_waveformRenderer->getGroup(), - child, - skinContext, - *m_waveformRenderer->getWaveformSignalColors())); + addRange(WaveformMarkRange( + m_waveformRenderer->getGroup(), + child, + skinContext, + *m_waveformRenderer->getWaveformSignalColors())); } child = child.nextSibling(); } diff --git a/src/waveform/renderers/allshader/waveformrendermarkrange.h b/src/waveform/renderers/allshader/waveformrendermarkrange.h index cabab1bb887..140eca76c34 100644 --- a/src/waveform/renderers/allshader/waveformrendermarkrange.h +++ b/src/waveform/renderers/allshader/waveformrendermarkrange.h @@ -2,7 +2,6 @@ #include #include -#include #include "rendergraph/node.h" #include "util/class.h" @@ -14,17 +13,21 @@ class SkinContext; namespace rendergraph { class GeometryNode; -} +} // namespace rendergraph namespace allshader { class WaveformRenderMarkRange; -} +} // namespace allshader class allshader::WaveformRenderMarkRange final : public ::WaveformRendererAbstract, public rendergraph::Node { public: explicit WaveformRenderMarkRange(WaveformWidgetRenderer* waveformWidget); + void addRange(WaveformMarkRange&& range) { + m_markRanges.push_back(std::move(range)); + } + // Pure virtual from WaveformRendererAbstract, not used void draw(QPainter* painter, QPaintEvent* event) override final; diff --git a/src/waveform/renderers/waveformmark.h b/src/waveform/renderers/waveformmark.h index 66a9bbc40cf..623feb89ef6 100644 --- a/src/waveform/renderers/waveformmark.h +++ b/src/waveform/renderers/waveformmark.h @@ -5,10 +5,10 @@ #include "control/controlproxy.h" #include "track/cue.h" +#include "waveform/renderers/waveformsignalcolors.h" #include "waveform/waveformmarklabel.h" class SkinContext; -class WaveformSignalColors; class QOpenGLTexture; namespace allshader { diff --git a/src/waveform/renderers/waveformmarkrange.h b/src/waveform/renderers/waveformmarkrange.h index 15100bf8f03..5ac530e86af 100644 --- a/src/waveform/renderers/waveformmarkrange.h +++ b/src/waveform/renderers/waveformmarkrange.h @@ -56,7 +56,7 @@ class WaveformMarkRange { WaveformMarkLabel m_durationLabel; private: - void generateImage(int weidth, int height); + void generateImage(int width, int height); std::unique_ptr m_markStartPointControl; std::unique_ptr m_markEndPointControl; diff --git a/src/waveform/renderers/waveformrendermarkbase.cpp b/src/waveform/renderers/waveformrendermarkbase.cpp index f250b73acc1..b2293d1448d 100644 --- a/src/waveform/renderers/waveformrendermarkbase.cpp +++ b/src/waveform/renderers/waveformrendermarkbase.cpp @@ -14,9 +14,13 @@ WaveformRenderMarkBase::WaveformRenderMarkBase( void WaveformRenderMarkBase::setup(const QDomNode& node, const SkinContext& context) { WaveformSignalColors signalColors = *m_waveformRenderer->getWaveformSignalColors(); m_marks.setup(m_waveformRenderer->getGroup(), node, context, signalColors); +} + +bool WaveformRenderMarkBase::init() { m_marks.connectSamplePositionChanged(this, &WaveformRenderMarkBase::onMarkChanged); m_marks.connectSampleEndPositionChanged(this, &WaveformRenderMarkBase::onMarkChanged); m_marks.connectVisibleChanged(this, &WaveformRenderMarkBase::onMarkChanged); + return true; } void WaveformRenderMarkBase::onSetTrack() { diff --git a/src/waveform/renderers/waveformrendermarkbase.h b/src/waveform/renderers/waveformrendermarkbase.h index b5e4d51dd25..8efc35aebd4 100644 --- a/src/waveform/renderers/waveformrendermarkbase.h +++ b/src/waveform/renderers/waveformrendermarkbase.h @@ -17,6 +17,8 @@ class WaveformRenderMarkBase : public QObject, public WaveformRendererAbstract { void setup(const QDomNode& node, const SkinContext& context) override; + bool init() override; + // Called when a new track is loaded. void onSetTrack() override; diff --git a/src/waveform/renderers/waveformwidgetrenderer.cpp b/src/waveform/renderers/waveformwidgetrenderer.cpp index ffefe5d6d45..0d5726b6054 100644 --- a/src/waveform/renderers/waveformwidgetrenderer.cpp +++ b/src/waveform/renderers/waveformwidgetrenderer.cpp @@ -36,13 +36,11 @@ WaveformWidgetRenderer::WaveformWidgetRenderer(const QString& group) // Really create some to manage those; m_visualPlayPosition(nullptr), m_totalVSamples(0), - m_pRateRatioCO(nullptr), - m_pGainControlObject(nullptr), m_gain(1.0), - m_pTrackSamplesControlObject(nullptr), - m_trackSamples(0), + m_trackSamples(0.0), m_scaleFactor(1.0), m_playMarkerPosition(s_defaultPlayMarkerPosition), + m_pContext(nullptr), m_passthroughEnabled(false) { //qDebug() << "WaveformWidgetRenderer"; for (int type = ::WaveformRendererAbstract::Play; @@ -76,10 +74,6 @@ WaveformWidgetRenderer::~WaveformWidgetRenderer() { delete m_rendererStack[i]; } - delete m_pRateRatioCO; - delete m_pGainControlObject; - delete m_pTrackSamplesControlObject; - #ifdef WAVEFORMWIDGETRENDERER_DEBUG delete m_timer; #endif @@ -90,11 +84,11 @@ bool WaveformWidgetRenderer::init() { m_visualPlayPosition = VisualPlayPosition::getVisualPlayPosition(m_group); - m_pRateRatioCO = new ControlProxy( + m_pRateRatioCO = std::make_unique( m_group, "rate_ratio"); - m_pGainControlObject = new ControlProxy( + m_pGainControlObject = std::make_unique( m_group, "total_gain"); - m_pTrackSamplesControlObject = new ControlProxy( + m_pTrackSamplesControlObject = std::make_unique( m_group, "track_samples"); for (int i = 0; i < m_rendererStack.size(); ++i) { @@ -419,7 +413,7 @@ void WaveformWidgetRenderer::setDisplayBeatGridAlpha(int alpha) { void WaveformWidgetRenderer::setTrack(TrackPointer track) { m_pTrack = track; //used to postpone first display until track sample is actually available - m_trackSamples = -1; + m_trackSamples = -1.0; for (int i = 0; i < m_rendererStack.size(); ++i) { m_rendererStack[i]->onSetTrack(); diff --git a/src/waveform/renderers/waveformwidgetrenderer.h b/src/waveform/renderers/waveformwidgetrenderer.h index 3f61921d4e0..fc79ecf7b51 100644 --- a/src/waveform/renderers/waveformwidgetrenderer.h +++ b/src/waveform/renderers/waveformwidgetrenderer.h @@ -231,10 +231,10 @@ class WaveformWidgetRenderer { QSharedPointer m_visualPlayPosition; int m_posVSample[2]; int m_totalVSamples; - ControlProxy* m_pRateRatioCO; - ControlProxy* m_pGainControlObject; + std::unique_ptr m_pRateRatioCO; + std::unique_ptr m_pGainControlObject; + std::unique_ptr m_pTrackSamplesControlObject; double m_gain; - ControlProxy* m_pTrackSamplesControlObject; double m_trackSamples; double m_scaleFactor; double m_playMarkerPosition; // 0.0 - left, 0.5 - center, 1.0 - right From 709f8ca9cf828986bdd06315f29636f202a8bb44 Mon Sep 17 00:00:00 2001 From: Antoine C Date: Sat, 23 Nov 2024 12:39:43 +0000 Subject: [PATCH 60/64] Move back local classes in the private namespace --- .../allshader/waveformrendermark.cpp | 111 +++++++++++++----- .../renderers/allshader/waveformrendermark.h | 66 +---------- 2 files changed, 83 insertions(+), 94 deletions(-) diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index cec1b60c334..6b00207aba3 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -18,36 +18,89 @@ using namespace rendergraph; -allshader::WaveformMarkNode::WaveformMarkNode(WaveformMark* pOwner, - rendergraph::Context* pContext, - const QImage& image) - : m_pOwner(pOwner) { - initForRectangles(1); - updateTexture(pContext, image); -} +namespace { +// On the use of QPainter: +// +// The renderers in this folder are optimized to use GLSL shaders and refrain +// from using QPainter on the QOpenGLWindow, which causes degredated performance. +// +// This renderer does use QPainter (indirectly, in WaveformMark::generateImage), but +// only to draw on a QImage. This is only done once when needed and the images are +// then used as textures to be drawn with a GLSL shader. + +class WaveformMarkNode : public rendergraph::GeometryNode { + public: + WaveformMark* m_pOwner{}; + + WaveformMarkNode(WaveformMark* pOwner, rendergraph::Context* pContext, const QImage& image) + : m_pOwner(pOwner) { + initForRectangles(1); + updateTexture(pContext, image); + } + void updateTexture(rendergraph::Context* pContext, const QImage& image) { + dynamic_cast(material()) + .setTexture(std::make_unique(pContext, image)); + m_textureWidth = image.width(); + m_textureHeight = image.height(); + } + void update(float x, float y, float devicePixelRatio) { + TexturedVertexUpdater vertexUpdater{ + geometry().vertexDataAs()}; + vertexUpdater.addRectangle({x, y}, + {x + m_textureWidth / devicePixelRatio, + y + m_textureHeight / devicePixelRatio}, + {0.f, 0.f}, + {1.f, 1.f}); + } + float textureWidth() const { + return m_textureWidth; + } + float textureHeight() const { + return m_textureHeight; + } -void allshader::WaveformMarkNode::updateTexture( - rendergraph::Context* pContext, const QImage& image) { - dynamic_cast(material()) - .setTexture(std::make_unique(pContext, image)); - m_textureWidth = image.width(); - m_textureHeight = image.height(); -} -void allshader::WaveformMarkNode::update(float x, float y, float devicePixelRatio) { - TexturedVertexUpdater vertexUpdater{ - geometry().vertexDataAs()}; - vertexUpdater.addRectangle({x, y}, - {x + m_textureWidth / devicePixelRatio, - y + m_textureHeight / devicePixelRatio}, - {0.f, 0.f}, - {1.f, 1.f}); -} -allshader::WaveformMarkNodeGraphics::WaveformMarkNodeGraphics(WaveformMark* pOwner, - rendergraph::Context* pContext, - const QImage& image) - : m_pNode(std::make_unique( - pOwner, pContext, image)) { -} + public: + float m_textureWidth{}; + float m_textureHeight{}; +}; + +class WaveformMarkNodeGraphics : public WaveformMark::Graphics { + public: + WaveformMarkNodeGraphics(WaveformMark* pOwner, + rendergraph::Context* pContext, + const QImage& image) + : m_pNode(std::make_unique( + pOwner, pContext, image)) { + } + void updateTexture(rendergraph::Context* pContext, const QImage& image) { + waveformMarkNode()->updateTexture(pContext, image); + } + void update(float x, float y, float devicePixelRatio) { + waveformMarkNode()->update(x, y, devicePixelRatio); + } + float textureWidth() const { + return waveformMarkNode()->textureWidth(); + } + float textureHeight() const { + return waveformMarkNode()->textureHeight(); + } + void attachNode(std::unique_ptr pNode) { + DEBUG_ASSERT(!m_pNode); + m_pNode = std::move(pNode); + } + std::unique_ptr detachNode() { + return std::move(m_pNode); + } + + private: + WaveformMarkNode* waveformMarkNode() const { + DEBUG_ASSERT(m_pNode); + return static_cast(m_pNode.get()); + } + + std::unique_ptr m_pNode; +}; +} // namespace // Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive // from WaveformRenderMarkBase. The base-class takes care of updating the marks diff --git a/src/waveform/renderers/allshader/waveformrendermark.h b/src/waveform/renderers/allshader/waveformrendermark.h index e0ef9e1d386..010a25b5061 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.h +++ b/src/waveform/renderers/allshader/waveformrendermark.h @@ -16,9 +16,7 @@ class Context; namespace allshader { class DigitsRenderNode; class WaveformRenderMark; -class WaveformMarkNode; -class WaveformMarkNodeGraphics; -} +} // namespace allshader class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, public rendergraph::Node { @@ -73,65 +71,3 @@ class allshader::WaveformRenderMark : public ::WaveformRenderMarkBase, DISALLOW_COPY_AND_ASSIGN(WaveformRenderMark); }; - -// On the use of QPainter: -// -// The renderers in this folder are optimized to use GLSL shaders and refrain -// from using QPainter on the QOpenGLWindow, which causes degredated performance. -// -// This renderer does use QPainter (indirectly, in WaveformMark::generateImage), but -// only to draw on a QImage. This is only done once when needed and the images are -// then used as textures to be drawn with a GLSL shader. - -class allshader::WaveformMarkNode : public rendergraph::GeometryNode { - public: - WaveformMark* m_pOwner{}; - - WaveformMarkNode(WaveformMark* pOwner, rendergraph::Context* pContext, const QImage& image); - void updateTexture(rendergraph::Context* pContext, const QImage& image); - void update(float x, float y, float devicePixelRatio); - float textureWidth() const { - return m_textureWidth; - } - float textureHeight() const { - return m_textureHeight; - } - - public: - float m_textureWidth{}; - float m_textureHeight{}; -}; - -class allshader::WaveformMarkNodeGraphics : public ::WaveformMark::Graphics { - public: - WaveformMarkNodeGraphics(WaveformMark* pOwner, - rendergraph::Context* pContext, - const QImage& image); - void updateTexture(rendergraph::Context* pContext, const QImage& image) { - waveformMarkNode()->updateTexture(pContext, image); - } - void update(float x, float y, float devicePixelRatio) { - waveformMarkNode()->update(x, y, devicePixelRatio); - } - float textureWidth() const { - return waveformMarkNode()->textureWidth(); - } - float textureHeight() const { - return waveformMarkNode()->textureHeight(); - } - void attachNode(std::unique_ptr pNode) { - DEBUG_ASSERT(!m_pNode); - m_pNode = std::move(pNode); - } - std::unique_ptr detachNode() { - return std::move(m_pNode); - } - - private: - WaveformMarkNode* waveformMarkNode() const { - DEBUG_ASSERT(m_pNode); - return static_cast(m_pNode.get()); - } - - std::unique_ptr m_pNode; -}; From 42a53d1adfb81700e91f9ac2251aabadd2705d70 Mon Sep 17 00:00:00 2001 From: Antoine C Date: Sat, 23 Nov 2024 17:35:39 +0000 Subject: [PATCH 61/64] Round texture coordinate to prevent glitch --- src/waveform/renderers/allshader/waveformrendermark.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 6b00207aba3..eba057b6702 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -46,7 +46,7 @@ class WaveformMarkNode : public rendergraph::GeometryNode { void update(float x, float y, float devicePixelRatio) { TexturedVertexUpdater vertexUpdater{ geometry().vertexDataAs()}; - vertexUpdater.addRectangle({x, y}, + vertexUpdater.addRectangle({std::round(x), std::round(y)}, {x + m_textureWidth / devicePixelRatio, y + m_textureHeight / devicePixelRatio}, {0.f, 0.f}, From ebc1108c3f27b4fc7dc691508f30a6204d545826 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 30 Nov 2024 17:37:14 +0100 Subject: [PATCH 62/64] minor changes to fix compilation --- .../common/rendergraph/attributeset.h | 2 +- src/rendergraph/examples/README | 4 ++++ src/rendergraph/opengl/CMakeLists.txt | 20 +++++++++---------- .../opengl/backend/basegeometrynode.cpp | 3 +++ src/rendergraph/scenegraph/CMakeLists.txt | 20 +++++++++---------- src/rendergraph/scenegraph/geometry.cpp | 6 +++++- .../allshader/waveformrendererendoftrack.cpp | 2 +- 7 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/rendergraph/common/rendergraph/attributeset.h b/src/rendergraph/common/rendergraph/attributeset.h index 717f47a3084..a7dbab0f3c9 100644 --- a/src/rendergraph/common/rendergraph/attributeset.h +++ b/src/rendergraph/common/rendergraph/attributeset.h @@ -12,7 +12,7 @@ class AttributeSet : public BaseAttributeSet { template AttributeSet makeAttributeSet(const QString (&names)[N]) { - static_assert(sizeof...(Ts) == N); + static_assert(sizeof...(Ts) == N, "Mismatch between number of attribute types and names"); return AttributeSet({(AttributeInit::create())...}, std::vector(std::cbegin(names), std::cend(names))); } diff --git a/src/rendergraph/examples/README b/src/rendergraph/examples/README index 6168efc09c4..4e0532a61a8 100644 --- a/src/rendergraph/examples/README +++ b/src/rendergraph/examples/README @@ -4,3 +4,7 @@ $ cd ../../../ $ mkdir build-rendergraph_examples $ cd build-rendergraph_examples $ cmake -DCMAKE_PREFIX_PATH=~/Qt/6.7.2/macos/ ../src/rendergraph/examples + +or if you want to use the mixxx vcpkg: +$ export MIXXX_VCPKG_ROOT=~/git/vcpkg/ +$ cmake -DVCPKG_INSTALLED_DIR:PATH=$MIXXX_VCPKG_ROOT/installed -DVCPKG_TARGET_TRIPLET:STRING=arm64-osx-release -DCMAKE_TOOLCHAIN_FILE=$MIXXX_VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake ../src/rendergraph/examples diff --git a/src/rendergraph/opengl/CMakeLists.txt b/src/rendergraph/opengl/CMakeLists.txt index d6ca282017b..602378fb8dc 100644 --- a/src/rendergraph/opengl/CMakeLists.txt +++ b/src/rendergraph/opengl/CMakeLists.txt @@ -62,17 +62,15 @@ target_link_libraries(rendergraph_gl PUBLIC Qt6::Gui Qt6::OpenGL ) -if(WIN32) - find_package(Microsoft.GSL CONFIG) - if(Microsoft.GSL_FOUND) - target_link_libraries(rendergraph_gl PRIVATE Microsoft.GSL::GSL) - else() - # check if the headers have been installed without cmake config (< 3.1.0) - check_include_file_cxx(gsl/gsl HAVE_GSL_GSL) - if(NOT HAVE_GSL_GSL) - unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag. - message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found") - endif() +find_package(Microsoft.GSL CONFIG) +if(Microsoft.GSL_FOUND) + target_link_libraries(rendergraph_gl PUBLIC Microsoft.GSL::GSL) +else() + # check if the headers have been installed without cmake config (< 3.1.0) + check_include_file_cxx(gsl/gsl HAVE_GSL_GSL) + if(NOT HAVE_GSL_GSL) + unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag. + message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found") endif() endif() target_compile_definitions(rendergraph_gl PRIVATE rendergraph=rendergraph_gl) diff --git a/src/rendergraph/opengl/backend/basegeometrynode.cpp b/src/rendergraph/opengl/backend/basegeometrynode.cpp index a4b2e303f86..31075d5f873 100644 --- a/src/rendergraph/opengl/backend/basegeometrynode.cpp +++ b/src/rendergraph/opengl/backend/basegeometrynode.cpp @@ -1,6 +1,7 @@ #include "backend/basegeometrynode.h" #include +#include #include "backend/shadercache.h" #include "rendergraph/engine.h" @@ -16,6 +17,8 @@ GLenum toGlDrawingMode(DrawingMode mode) { return GL_TRIANGLES; case DrawingMode::TriangleStrip: return GL_TRIANGLE_STRIP; + default: + throw std::runtime_error("not implemented"); } } } // namespace diff --git a/src/rendergraph/scenegraph/CMakeLists.txt b/src/rendergraph/scenegraph/CMakeLists.txt index ad96eb1e491..5bd74ecc957 100644 --- a/src/rendergraph/scenegraph/CMakeLists.txt +++ b/src/rendergraph/scenegraph/CMakeLists.txt @@ -55,17 +55,15 @@ target_link_libraries(rendergraph_sg PUBLIC Qt6::Qml Qt6::Quick ) -if(WIN32) - find_package(Microsoft.GSL CONFIG) - if(Microsoft.GSL_FOUND) - target_link_libraries(rendergraph_sg PRIVATE Microsoft.GSL::GSL) - else() - # check if the headers have been installed without cmake config (< 3.1.0) - check_include_file_cxx(gsl/gsl HAVE_GSL_GSL) - if(NOT HAVE_GSL_GSL) - unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag. - message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found") - endif() +find_package(Microsoft.GSL CONFIG) +if(Microsoft.GSL_FOUND) + target_link_libraries(rendergraph_sg PUBLIC Microsoft.GSL::GSL) +else() + # check if the headers have been installed without cmake config (< 3.1.0) + check_include_file_cxx(gsl/gsl HAVE_GSL_GSL) + if(NOT HAVE_GSL_GSL) + unset(HAVE_GSL_GSL CACHE) # unset cache to re-evaluate this until it succeeds. check_include_file_cxx() has no REQUIRED flag. + message(FATAL_ERROR "ms-gsl development headers (libmsgsl-dev) not found") endif() endif() target_compile_definitions(rendergraph_sg PRIVATE rendergraph=rendergraph_sg) diff --git a/src/rendergraph/scenegraph/geometry.cpp b/src/rendergraph/scenegraph/geometry.cpp index b320e71d09c..fcc63f030ff 100644 --- a/src/rendergraph/scenegraph/geometry.cpp +++ b/src/rendergraph/scenegraph/geometry.cpp @@ -1,5 +1,7 @@ #include "rendergraph/geometry.h" +#include + #include "rendergraph/assert.h" using namespace rendergraph; @@ -11,6 +13,8 @@ QSGGeometry::DrawingMode toSgDrawingMode(DrawingMode mode) { return QSGGeometry::DrawTriangles; case DrawingMode::TriangleStrip: return QSGGeometry::DrawTriangleStrip; + default: + throw std::runtime_error("not implemented"); } } @@ -21,7 +25,7 @@ DrawingMode fromSgDrawingMode(unsigned int mode) { case QSGGeometry::DrawTriangleStrip: return DrawingMode::TriangleStrip; default: - throw "not implemented"; + throw std::runtime_error("not implemented"); } } } // namespace diff --git a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp index 197d147b831..8ee649e2a2c 100644 --- a/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp +++ b/src/waveform/renderers/allshader/waveformrendererendoftrack.cpp @@ -81,7 +81,7 @@ bool WaveformRendererEndOfTrack::preprocessInner() { const double criticalIntensity = (remainingTimeTriggerSeconds - remainingTime) / remainingTimeTriggerSeconds; - const double alpha = std::min(1.0, std::max(0.0, criticalIntensity * blinkIntensity)); + const double alpha = std::clamp(criticalIntensity * blinkIntensity, 0.0, 1.0); QSizeF size(m_waveformRenderer->getWidth(), m_waveformRenderer->getHeight()); float r, g, b, a; From b27ab9a06c7a4f8815e5db733d9d3af5bf4408c9 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sat, 30 Nov 2024 19:12:21 +0100 Subject: [PATCH 63/64] improve alignment of markers, avoid images that are half empty --- .../allshader/waveformrendermark.cpp | 105 +++++++++--------- src/waveform/renderers/waveformmark.cpp | 55 ++++++--- src/waveform/renderers/waveformmark.h | 5 + src/waveform/renderers/waveformrendermark.cpp | 23 ++-- .../renderers/waveformwidgetrenderer.cpp | 4 +- 5 files changed, 102 insertions(+), 90 deletions(-) diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index eba057b6702..901bed353ed 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -46,7 +46,7 @@ class WaveformMarkNode : public rendergraph::GeometryNode { void update(float x, float y, float devicePixelRatio) { TexturedVertexUpdater vertexUpdater{ geometry().vertexDataAs()}; - vertexUpdater.addRectangle({std::round(x), std::round(y)}, + vertexUpdater.addRectangle({x, y}, {x + m_textureWidth / devicePixelRatio, y + m_textureHeight / devicePixelRatio}, {0.f, 0.f}, @@ -100,21 +100,10 @@ class WaveformMarkNodeGraphics : public WaveformMark::Graphics { std::unique_ptr m_pNode; }; -} // namespace -// Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive -// from WaveformRenderMarkBase. The base-class takes care of updating the marks -// when needed and flagging them when their image needs to be updated (resizing, -// cue changes, position changes) -// -// While in the case of ::WaveformRenderMark those images can be updated immediately, -// in the case of allshader::WaveformRenderMark we need to do that when we have an -// openGL context, as we create new textures. -// -// The boolean argument for the WaveformRenderMarkBase constructor indicates -// that updateMarkImages should not be called immediately. +constexpr float kPlayPosWidth{11.f}; +constexpr float kPlayPosOffset{-(kPlayPosWidth - 1.f) / 2.f}; -namespace { QString timeSecToString(double timeSec) { int hundredths = std::lround(timeSec * 100.0); int seconds = hundredths / 100; @@ -125,8 +114,31 @@ QString timeSecToString(double timeSec) { return QString::asprintf("%d:%02d.%02d", minutes, seconds, hundredths); } +struct RoundToPixel { + const float m_devicePixelRatio; + RoundToPixel(float devicePixelRatio) + : m_devicePixelRatio(devicePixelRatio) { + } + // round to nearest pixel, taking into account the devicePixelRatio + float operator()(float pos) const { + return std::round(pos * m_devicePixelRatio) / m_devicePixelRatio; + } +}; + } // namespace +// Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive +// from WaveformRenderMarkBase. The base-class takes care of updating the marks +// when needed and flagging them when their image needs to be updated (resizing, +// cue changes, position changes) +// +// While in the case of ::WaveformRenderMark those images can be updated immediately, +// in the case of allshader::WaveformRenderMark we need to do that when we have an +// openGL context, as we create new textures. +// +// The boolean argument for the WaveformRenderMarkBase constructor indicates +// that updateMarkImages should not be called immediately. + allshader::WaveformRenderMark::WaveformRenderMark( WaveformWidgetRenderer* waveformWidget, ::WaveformRendererAbstract::PositionSource type) @@ -235,6 +247,8 @@ void allshader::WaveformRenderMark::update() { const float devicePixelRatio = m_waveformRenderer->getDevicePixelRatio(); QList marksOnScreen; + RoundToPixel roundToPixel{devicePixelRatio}; + for (const auto& pMark : std::as_const(m_marks)) { pMark->setBreadth(slipActive ? m_waveformRenderer->getBreadth() / 2 : m_waveformRenderer->getBreadth()); @@ -268,14 +282,9 @@ void allshader::WaveformRenderMark::update() { if (!pMarkGraphics) // is this even possible? continue; - const float currentMarkPoint = - std::round( - static_cast( - m_waveformRenderer - ->transformSamplePositionInRendererWorld( - samplePosition, positionType)) * - devicePixelRatio) / - devicePixelRatio; + const float currentMarkPos = static_cast( + m_waveformRenderer->transformSamplePositionInRendererWorld( + samplePosition, positionType)); if (pMark->isShowUntilNext() && samplePosition >= playPosition + 1.0 && samplePosition < nextMarkPosition) { @@ -283,21 +292,17 @@ void allshader::WaveformRenderMark::update() { } const double sampleEndPosition = pMark->getSampleEndPosition(); - // Pixmaps are expected to have the mark stroke at the center, - // and preferably have an odd width in order to have the stroke - // exactly at the sample position. - const float markHalfWidth = pMarkNodeGraphics->textureWidth() / devicePixelRatio / 2.f; - const float drawOffset = currentMarkPoint - markHalfWidth; + const float markWidth = pMarkNodeGraphics->textureWidth() / devicePixelRatio; + const float drawOffset = currentMarkPos + pMark->getOffset(); bool visible = false; // Check if the current point needs to be displayed. - if (drawOffset > -markHalfWidth && - drawOffset < m_waveformRenderer->getLength() + - markHalfWidth) { + if (drawOffset > -markWidth && + drawOffset < m_waveformRenderer->getLength()) { pMarkNodeGraphics->update( - drawOffset, + roundToPixel(drawOffset), !m_isSlipRenderer && slipActive - ? m_waveformRenderer->getBreadth() / 2 + ? roundToPixel(m_waveformRenderer->getBreadth() / 2.f) : 0, devicePixelRatio); @@ -310,13 +315,10 @@ void allshader::WaveformRenderMark::update() { // Check if the range needs to be displayed. if (samplePosition != sampleEndPosition && sampleEndPosition != Cue::kNoPosition) { DEBUG_ASSERT(samplePosition < sampleEndPosition); - const float currentMarkEndPoint = static_cast< - float>( - m_waveformRenderer - ->transformSamplePositionInRendererWorld( - sampleEndPosition, positionType)); - - if (visible || currentMarkEndPoint > 0) { + const float currentMarkEndPos = static_cast( + m_waveformRenderer->transformSamplePositionInRendererWorld( + sampleEndPosition, positionType)); + if (visible || currentMarkEndPos > 0.f) { QColor color = pMark->fillColor(); color.setAlphaF(0.4f); @@ -329,9 +331,9 @@ void allshader::WaveformRenderMark::update() { } updateRangeNode(pRangeChild, - QRectF(QPointF(currentMarkPoint, 0), - QPointF(currentMarkEndPoint, - m_waveformRenderer->getBreadth())), + QRectF(QPointF(roundToPixel(currentMarkPos), 0.f), + QPointF(roundToPixel(currentMarkEndPos), + roundToPixel(m_waveformRenderer->getBreadth()))), color); visible = true; @@ -354,22 +356,15 @@ void allshader::WaveformRenderMark::update() { m_waveformRenderer->setMarkPositions(marksOnScreen); - const float currentMarkPoint = - std::round(static_cast( - m_waveformRenderer->getPlayMarkerPosition() * - m_waveformRenderer->getLength()) * - devicePixelRatio) / - devicePixelRatio; - + const float playMarkerPos = m_waveformRenderer->getPlayMarkerPosition() * + m_waveformRenderer->getLength(); { - const float markHalfWidth = 11.f / 2.f; - const float drawOffset = currentMarkPoint - markHalfWidth; - + const float drawOffset = roundToPixel(playMarkerPos + kPlayPosOffset); TexturedVertexUpdater vertexUpdater{ m_pPlayPosNode->geometry() .vertexDataAs()}; vertexUpdater.addRectangle({drawOffset, 0.f}, - {drawOffset + 11.f, static_cast(m_waveformRenderer->getBreadth())}, + {drawOffset + kPlayPosWidth, static_cast(m_waveformRenderer->getBreadth())}, {0.f, 0.f}, {1.f, 1.f}); } @@ -377,7 +372,7 @@ void allshader::WaveformRenderMark::update() { if (WaveformWidgetFactory::instance()->getUntilMarkShowBeats() || WaveformWidgetFactory::instance()->getUntilMarkShowTime()) { updateUntilMark(playPosition, nextMarkPosition); - drawUntilMark(currentMarkPoint + 20); + drawUntilMark(roundToPixel(playMarkerPos + 20.f)); } } @@ -443,7 +438,7 @@ void allshader::WaveformRenderMark::updatePlayPosMarkTexture(rendergraph::Contex const float lineX = 5.5f; - imgwidth = 11.f; + imgwidth = kPlayPosWidth; imgheight = height; QImage image(static_cast(imgwidth * devicePixelRatio), diff --git a/src/waveform/renderers/waveformmark.cpp b/src/waveform/renderers/waveformmark.cpp index 809e633e551..5014694ea94 100644 --- a/src/waveform/renderers/waveformmark.cpp +++ b/src/waveform/renderers/waveformmark.cpp @@ -100,6 +100,7 @@ WaveformMark::WaveformMark(const QString& group, const WaveformSignalColors& signalColors, int hotCue) : m_linePosition{}, + m_offset{}, m_breadth{}, m_level{}, m_iPriority(priority), @@ -278,6 +279,15 @@ struct MarkerGeometry { const Qt::Alignment alignH = align & Qt::AlignHorizontal_Mask; const Qt::Alignment alignV = align & Qt::AlignVertical_Mask; const bool alignHCenter{alignH == Qt::AlignHCenter}; + + // The image width is the label rect width + 1, so that the label rect + // left and right positions can be at an integer + 0.5. This is so that + // the label rect is drawn at an exact pixel positions. + // + // Likewise, the line position also has to fall on an integer + 0.5. + // When center aligning, the image width has to be odd, so that the + // center is an integer + 0.5. For the image width to be odd, to + // label rect width has to be even. const qreal widthRounding{alignHCenter ? 2.f : 1.f}; m_labelRect = QRectF{0.f, @@ -286,17 +296,9 @@ struct MarkerGeometry { widthRounding, std::ceil(capHeight + 2.f * margin)}; - m_imageSize = QSizeF{alignHCenter ? m_labelRect.width() + 1.f - : 2.f * m_labelRect.width() + 1.f, - breadth}; + m_imageSize = QSizeF{m_labelRect.width() + 1.f, breadth}; - if (alignH == Qt::AlignHCenter) { - m_labelRect.moveLeft((m_imageSize.width() - m_labelRect.width()) / 2.f); - } else if (alignH == Qt::AlignRight) { - m_labelRect.moveRight(m_imageSize.width() - 0.5f); - } else { - m_labelRect.moveLeft(0.5f); - } + m_labelRect.moveLeft(0.5f); const float increment = overlappingMarkerIncrement( static_cast(m_labelRect.height()), breadth); @@ -373,22 +375,39 @@ QImage WaveformMark::generateImage(float devicePixelRatio) { painter.setWorldMatrixEnabled(false); - // Draw marker lines - const auto hcenter = markerGeometry.m_imageSize.width() / 2.f; - m_linePosition = static_cast(hcenter); + const Qt::Alignment alignH = m_align & Qt::AlignHorizontal_Mask; + switch (alignH) { + case Qt::AlignHCenter: + m_linePosition = markerGeometry.m_imageSize.width() / 2.f; + m_offset = -(markerGeometry.m_imageSize.width() - 1.f) / 2.f; + DEBUG_ASSERT(linePos - std::roundf(linePos) < 0.000001f); + break; + case Qt::AlignLeft: + m_linePosition = markerGeometry.m_imageSize.width() - 1.5f; + m_offset = -markerGeometry.m_imageSize.width() + 2.f; + break; + case Qt::AlignRight: + default: + m_linePosition = 1.5f; + m_offset = -1.f; + break; + } + + // Note: linePos has to be at integer + 0.5 to draw correctly + const float linePos = m_linePosition; // Draw the center line painter.setPen(fillColor()); - painter.drawLine(QLineF(hcenter, 0.f, hcenter, markerGeometry.m_imageSize.height())); + painter.drawLine(QLineF(linePos, 0.f, linePos, markerGeometry.m_imageSize.height())); painter.setPen(borderColor()); - painter.drawLine(QLineF(hcenter - 1.f, + painter.drawLine(QLineF(linePos - 1.f, 0.f, - hcenter - 1.f, + linePos - 1.f, markerGeometry.m_imageSize.height())); - painter.drawLine(QLineF(hcenter + 1.f, + painter.drawLine(QLineF(linePos + 1.f, 0.f, - hcenter + 1.f, + linePos + 1.f, markerGeometry.m_imageSize.height())); if (useIcon || label.length() != 0) { diff --git a/src/waveform/renderers/waveformmark.h b/src/waveform/renderers/waveformmark.h index 623feb89ef6..c40af8927d9 100644 --- a/src/waveform/renderers/waveformmark.h +++ b/src/waveform/renderers/waveformmark.h @@ -37,6 +37,10 @@ class WaveformMark { WaveformMark(const WaveformMark&) = delete; WaveformMark& operator=(const WaveformMark&) = delete; + float getOffset() const { + return m_offset; + } + int getHotCue() const { return m_iHotCue; }; @@ -158,6 +162,7 @@ class WaveformMark { QString m_iconPath; float m_linePosition; + float m_offset; float m_breadth; // When there are overlapping marks, level is increased for each overlapping mark, diff --git a/src/waveform/renderers/waveformrendermark.cpp b/src/waveform/renderers/waveformrendermark.cpp index 4f0c4693f06..2e17368a109 100644 --- a/src/waveform/renderers/waveformrendermark.cpp +++ b/src/waveform/renderers/waveformrendermark.cpp @@ -37,17 +37,13 @@ void WaveformRenderMark::draw(QPainter* painter, QPaintEvent* /*event*/) { m_waveformRenderer->transformSamplePositionInRendererWorld(samplePosition); const double sampleEndPosition = pMark->getSampleEndPosition(); if (m_waveformRenderer->getOrientation() == Qt::Horizontal) { - // Pixmaps are expected to have the mark stroke at the center, - // and preferably have an odd width in order to have the stroke - // exactly at the sample position. - const int markHalfWidth = - static_cast(image.width() / 2.0 / - m_waveformRenderer->getDevicePixelRatio()); - const int drawOffset = static_cast(currentMarkPoint) - markHalfWidth; + const int markWidth = std::lround(image.width() / + m_waveformRenderer->getDevicePixelRatio()); + const int drawOffset = std::lround(currentMarkPoint + pMark->getOffset()); bool visible = false; // Check if the current point needs to be displayed. - if (currentMarkPoint > -markHalfWidth && currentMarkPoint < m_waveformRenderer->getWidth() + markHalfWidth) { + if (drawOffset > -markWidth && drawOffset < m_waveformRenderer->getWidth()) { painter->drawImage(drawOffset, 0, image); visible = true; } @@ -84,16 +80,13 @@ void WaveformRenderMark::draw(QPainter* painter, QPaintEvent* /*event*/) { pMark, drawOffset}); } } else { - const int markHalfHeight = - static_cast(image.height() / 2.0 / - m_waveformRenderer->getDevicePixelRatio()); - const int drawOffset = static_cast(currentMarkPoint) - markHalfHeight; + const int markHeight = std::lroundf(image.height() / + m_waveformRenderer->getDevicePixelRatio()); + const int drawOffset = std::lroundf(currentMarkPoint + pMark->getOffset()); bool visible = false; // Check if the current point needs to be displayed. - if (currentMarkPoint > -markHalfHeight && - currentMarkPoint < m_waveformRenderer->getHeight() + - markHalfHeight) { + if (drawOffset > -markHeight && drawOffset < m_waveformRenderer->getHeight()) { painter->drawImage(0, drawOffset, image); visible = true; } diff --git a/src/waveform/renderers/waveformwidgetrenderer.cpp b/src/waveform/renderers/waveformwidgetrenderer.cpp index 0d5726b6054..ce5f992a35a 100644 --- a/src/waveform/renderers/waveformwidgetrenderer.cpp +++ b/src/waveform/renderers/waveformwidgetrenderer.cpp @@ -256,8 +256,8 @@ void WaveformWidgetRenderer::draw(QPainter* painter, QPaintEvent* event) { } void WaveformWidgetRenderer::drawPlayPosmarker(QPainter* painter) { - const int lineX = static_cast(m_width * m_playMarkerPosition); - const int lineY = static_cast(m_height * m_playMarkerPosition); + const int lineX = std::lround(m_width * m_playMarkerPosition); + const int lineY = std::lround(m_height * m_playMarkerPosition); // draw dim outlines to increase playpos/waveform contrast painter->setOpacity(0.5); From 368776d6f5da3bf3add7ca4b517c8b73975a2528 Mon Sep 17 00:00:00 2001 From: m0dB Date: Sun, 1 Dec 2024 20:47:41 +0100 Subject: [PATCH 64/64] draw rounded to pixel --- .../renderers/allshader/digitsrenderer.cpp | 37 ++++++++++--------- .../allshader/waveformrendermark.cpp | 28 ++++++++------ src/waveform/renderers/waveformmark.cpp | 3 +- 3 files changed, 37 insertions(+), 31 deletions(-) diff --git a/src/waveform/renderers/allshader/digitsrenderer.cpp b/src/waveform/renderers/allshader/digitsrenderer.cpp index ea8883e5fb8..7a610b80009 100644 --- a/src/waveform/renderers/allshader/digitsrenderer.cpp +++ b/src/waveform/renderers/allshader/digitsrenderer.cpp @@ -96,7 +96,6 @@ void allshader::DigitsRenderNode::updateTexture(rendergraph::Context* pContext, QFont font; QFontMetricsF metrics{font}; font.setFamily("Open Sans"); - qreal totalTextWidth; qreal maxTextHeight; bool retry = false; do { @@ -113,14 +112,12 @@ void allshader::DigitsRenderNode::updateTexture(rendergraph::Context* pContext, metrics = QFontMetricsF{font}; - totalTextWidth = 0; maxTextHeight = 0; for (int i = 0; i < NUM_CHARS; i++) { const QString text(indexToChar(i)); const auto rect = metrics.tightBoundingRect(text); maxTextHeight = std::max(maxTextHeight, rect.height()); - totalTextWidth += metrics.horizontalAdvance(text); } if (m_adjustedFontPointSize == 0.f && !retry && maxTextHeight > maxHeightWithoutSpace) { // We need to adjust the font size to fit in the maxHeight. @@ -137,12 +134,25 @@ void allshader::DigitsRenderNode::updateTexture(rendergraph::Context* pContext, m_height = static_cast(std::ceil(maxTextHeight) + space * 2 + 1); - // Space around the digits - totalTextWidth += (space * 2 + 1) * NUM_CHARS; - totalTextWidth = std::ceil(totalTextWidth); - const qreal y = maxTextHeight + space - 0.5; + qreal totalTextWidth{}; + std::array xs; + for (int i = 0; i < NUM_CHARS; i++) { + const QString text(indexToChar(i)); + xs[i] = totalTextWidth; + qreal w = std::round(metrics.horizontalAdvance(text) * + devicePixelRatio / devicePixelRatio) + + space + space + 1.0; + totalTextWidth += w; + m_width[i] = static_cast(w); + } + for (int i = 0; i < NUM_CHARS; i++) { + // position and width of character at index i in the texture, normalized + m_offset[i] = static_cast(xs[i] / totalTextWidth); + } + m_offset[NUM_CHARS] = 1.f; + QImage image(std::lround(totalTextWidth * devicePixelRatio), std::lround(m_height * devicePixelRatio), QImage::Format_ARGB32_Premultiplied); @@ -159,12 +169,10 @@ void allshader::DigitsRenderNode::updateTexture(rendergraph::Context* pContext, painter.setBrush(QColor(0, 0, 0, OUTLINE_ALPHA)); painter.setPen(pen); painter.setFont(font); - qreal x = 0; QPainterPath path; for (int i = 0; i < NUM_CHARS; i++) { const QString text(indexToChar(i)); - path.addText(QPointF(x + space + 0.5, y), font, text); - x += metrics.horizontalAdvance(text) + space + space + 1; + path.addText(QPointF(xs[i] + space + 0.5, y), font, text); } painter.drawPath(path); } @@ -193,19 +201,12 @@ void allshader::DigitsRenderNode::updateTexture(rendergraph::Context* pContext, painter.setPen(Qt::white); painter.setBrush(Qt::white); - qreal x = 0; QPainterPath path; for (int i = 0; i < NUM_CHARS; i++) { const QString text(indexToChar(i)); - path.addText(QPointF(x + space + 0.5, y), font, text); - // position and width of character at index i in the texture - m_offset[i] = static_cast(x / totalTextWidth); - const auto xp = x; - x += metrics.horizontalAdvance(text) + space + space + 1; - m_width[i] = static_cast(x - xp); + path.addText(QPointF(xs[i] + space + 0.5, y), font, text); } painter.drawPath(path); - m_offset[NUM_CHARS] = 1.f; } dynamic_cast(material()) diff --git a/src/waveform/renderers/allshader/waveformrendermark.cpp b/src/waveform/renderers/allshader/waveformrendermark.cpp index 901bed353ed..ed1990876ca 100644 --- a/src/waveform/renderers/allshader/waveformrendermark.cpp +++ b/src/waveform/renderers/allshader/waveformrendermark.cpp @@ -18,7 +18,6 @@ using namespace rendergraph; -namespace { // On the use of QPainter: // // The renderers in this folder are optimized to use GLSL shaders and refrain @@ -28,6 +27,19 @@ namespace { // only to draw on a QImage. This is only done once when needed and the images are // then used as textures to be drawn with a GLSL shader. +namespace { + +struct RoundToPixel { + const float m_devicePixelRatio; + RoundToPixel(float devicePixelRatio) + : m_devicePixelRatio{devicePixelRatio} { + } + // round to nearest pixel, taking into account the devicePixelRatio + float operator()(float pos) const { + return std::round(pos * m_devicePixelRatio) / m_devicePixelRatio; + } +}; + class WaveformMarkNode : public rendergraph::GeometryNode { public: WaveformMark* m_pOwner{}; @@ -44,6 +56,9 @@ class WaveformMarkNode : public rendergraph::GeometryNode { m_textureHeight = image.height(); } void update(float x, float y, float devicePixelRatio) { + [[maybe_unused]] const float epsilon = 1e-6f; + DEBUG_ASSERT(std::abs(x - RoundToPixel(devicePixelRatio)(x)) < epsilon); + DEBUG_ASSERT(std::abs(y - RoundToPixel(devicePixelRatio)(y)) < epsilon); TexturedVertexUpdater vertexUpdater{ geometry().vertexDataAs()}; vertexUpdater.addRectangle({x, y}, @@ -114,17 +129,6 @@ QString timeSecToString(double timeSec) { return QString::asprintf("%d:%02d.%02d", minutes, seconds, hundredths); } -struct RoundToPixel { - const float m_devicePixelRatio; - RoundToPixel(float devicePixelRatio) - : m_devicePixelRatio(devicePixelRatio) { - } - // round to nearest pixel, taking into account the devicePixelRatio - float operator()(float pos) const { - return std::round(pos * m_devicePixelRatio) / m_devicePixelRatio; - } -}; - } // namespace // Both allshader::WaveformRenderMark and the non-GL ::WaveformRenderMark derive diff --git a/src/waveform/renderers/waveformmark.cpp b/src/waveform/renderers/waveformmark.cpp index 5014694ea94..286f6d2d34e 100644 --- a/src/waveform/renderers/waveformmark.cpp +++ b/src/waveform/renderers/waveformmark.cpp @@ -380,7 +380,6 @@ QImage WaveformMark::generateImage(float devicePixelRatio) { case Qt::AlignHCenter: m_linePosition = markerGeometry.m_imageSize.width() / 2.f; m_offset = -(markerGeometry.m_imageSize.width() - 1.f) / 2.f; - DEBUG_ASSERT(linePos - std::roundf(linePos) < 0.000001f); break; case Qt::AlignLeft: m_linePosition = markerGeometry.m_imageSize.width() - 1.5f; @@ -395,6 +394,8 @@ QImage WaveformMark::generateImage(float devicePixelRatio) { // Note: linePos has to be at integer + 0.5 to draw correctly const float linePos = m_linePosition; + [[maybe_unused]] const float epsilon = 1e-6f; + DEBUG_ASSERT(std::abs(linePos - std::floor(linePos) - 0.5) < epsilon); // Draw the center line painter.setPen(fillColor());