forked from mixxxdj/mixxx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
m0dB
authored and
m0dB
committed
Dec 14, 2024
1 parent
d273b5a
commit 07bca3d
Showing
26 changed files
with
433 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# included from src/rendergraph/CMakeLists.txt | ||
|
||
set( | ||
shaders | ||
pattern.frag | ||
pattern.vert | ||
rgb.frag | ||
rgb.vert | ||
rgba.frag | ||
rgba.vert | ||
texture.frag | ||
texture.vert | ||
unicolor.frag | ||
unicolor.vert | ||
) | ||
|
||
qt6_add_shaders(rendergraph_sg "shaders-qsb" | ||
BATCHABLE | ||
PRECOMPILE | ||
OPTIMIZED | ||
PREFIX | ||
/shaders/rendergraph | ||
FILES | ||
${shaders} | ||
) | ||
|
||
# USE_QSHADER_FOR_GL is set in src/rendergraph/CMakeLists.txt when Qt >= 6.6 | ||
if(USE_QSHADER_FOR_GL) | ||
# Add the .qsb shader bundles; rendergraph::MaterialShader will use | ||
# QShader to extract the GLSL shader from the bundle. | ||
message(STATUS "Adding qsb shaders to rendergraph_gl") | ||
qt6_add_shaders(rendergraph_gl "shaders-qsb" | ||
BATCHABLE | ||
PRECOMPILE | ||
OPTIMIZED | ||
PREFIX | ||
/shaders/rendergraph | ||
FILES | ||
${shaders} | ||
) | ||
else() | ||
# Use GLSL shaders extracted from the .qsb shader bundles using | ||
# generate_shaders_gl.pl | ||
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} | ||
) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# rendergraph shaders | ||
|
||
The CMakeLists.txt in this folder generates qsb shader bundles from spirv shaders, to | ||
be used by `rendergraph::MaterialShader`. | ||
|
||
## For use with QML / Qt scene graph | ||
|
||
The qsb files can be used directly through `QSGShader`. This includes the scenegraph | ||
implementation of rendergraph. | ||
|
||
## For use with OpenGL | ||
|
||
Depending on the Qt version, the opengl implementation of `rendergraph::MaterialShader` | ||
uses either the .qsb shader bundles directly, or the extracted GLSL shaders: | ||
|
||
### Qt >= 6.6 | ||
|
||
The GLSL shaders are extracted programmatically with `QShader` and then used with | ||
`QOpenGLShader`. | ||
|
||
### Qt < 6.6 | ||
|
||
The GLSL shader have to extracted from the qsb shader bundles to be used by `QOpenGLShader`. | ||
This can be done using the script `generate_shaders_gl.pl`. To use this script, make sure | ||
that the qsb and spirv commands are in your path. qsb is part of Qt. spirv is part of the | ||
Vulkan SDK and can be downloaded from <https://vulkan.org> | ||
|
||
The script also generates the file ```generated_shaders_gl.cmake``` which sets a cmake | ||
variable containing a list of all GLSL shaders, used by the CMakeLists.txt in this folder. |
68 changes: 68 additions & 0 deletions
68
src/rendergraph/shaders/rendergraph/generate_shaders_gl.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 (<INFILE>) | ||
{ | ||
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; |
13 changes: 13 additions & 0 deletions
13
src/rendergraph/shaders/rendergraph/generated_shaders_gl.cmake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
set( | ||
generated_shaders_gl | ||
pattern.vert.gl | ||
rgb.vert.gl | ||
rgba.vert.gl | ||
texture.vert.gl | ||
unicolor.vert.gl | ||
pattern.frag.gl | ||
rgb.frag.gl | ||
rgba.frag.gl | ||
texture.frag.gl | ||
unicolor.frag.gl | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 vec2 texcoord; | ||
layout(location = 0) out vec2 vTexcoord; | ||
|
||
void main() { | ||
vTexcoord = texcoord; | ||
gl_Position = ubuf.matrix * position; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#version 120 | ||
//// GENERATED - EDITS WILL BE OVERWRITTEN | ||
|
||
varying vec3 vColor; | ||
|
||
void main() | ||
{ | ||
gl_FragData[0] = vec4(vColor, 1.0); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 vec2 texcoord; | ||
layout(location = 0) out vec2 vTexcoord; | ||
|
||
void main() { | ||
vTexcoord = texcoord; | ||
gl_Position = ubuf.matrix * position; | ||
} |
Oops, something went wrong.