Skip to content

Commit a50082b

Browse files
committed
Miscellaneous vsgshadertoy cleanup
- Use vsg::Path for paths instead of strings - Got rid of the redundant push constant - Removed `using std` as that is not the convention in vsgExamples - Changed the title so that it always display "vsgshadertoy"
1 parent 8ad69a7 commit a50082b

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

examples/app/vsgshadertoy/vsgshadertoy.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
#include <vsg/all.h>
2020
#include <chrono>
2121

22-
using namespace std;
23-
2422
struct ToyUniform {
2523
vsg::ivec2 iResolution;
2624
vsg::vec2 iMouse;
@@ -59,20 +57,21 @@ void main()
5957
)";
6058

6159

62-
string readFile(const string& filename)
60+
std::string readFile(const vsg::Path& filename)
6361
{
64-
ifstream fh(filename);
62+
std::ifstream fh(filename);
6563

6664
if (!fh.good())
67-
throw runtime_error(std::string("Error opening file \"") + filename + "\" for input!");
65+
throw std::runtime_error(std::string("Error opening file \"") + filename + "\" for input!");
6866

69-
string ret;
70-
ret.assign((istreambuf_iterator<char>(fh)), istreambuf_iterator<char>());
67+
std::string ret;
68+
ret.assign((std::istreambuf_iterator<char>(fh)),
69+
std::istreambuf_iterator<char>());
7170
fh.close();
7271
return ret;
7372
}
7473

75-
const string defaultShader = R"(
74+
const std::string defaultShader = R"(
7675
void mainImage( out vec4 fragColor, in vec2 fragCoord )
7776
{
7877
// Normalized coordinates
@@ -86,7 +85,7 @@ void mainImage( out vec4 fragColor, in vec2 fragCoord )
8685
}
8786
)";
8887

89-
string shaderToyToFragmentShader(const string& toyShader)
88+
std::string shaderToyToFragmentShader(const std::string& toyShader)
9089
{
9190
return R"(
9291
#version 450
@@ -119,8 +118,8 @@ void main()
119118
}
120119

121120

122-
// Create a vsg node containing an image
123-
vsg::ref_ptr<vsg::Node> createToyNode(string toyShader,
121+
// Create a vsg node containing the shadertoy command
122+
vsg::ref_ptr<vsg::Node> createToyNode(const std::string& toyShader,
124123
// output
125124
vsg::ref_ptr<ToyUniformValue>& toyUniform)
126125
{
@@ -165,14 +164,9 @@ vsg::ref_ptr<vsg::Node> createToyNode(string toyShader,
165164
vsg::ColorBlendState::create(),
166165
vsg::DepthStencilState::create()};
167166

168-
// Do I need this when having a constant V,M, and P?
169-
vsg::PushConstantRanges pushConstantRanges{
170-
{VK_SHADER_STAGE_VERTEX_BIT, 0, 128} // projection, view, and model matrices, actual push constant calls automatically provided by the VSG's RecordTraversal
171-
};
172-
173167
auto toyUniformDescriptor = vsg::DescriptorBuffer::create(toyUniform, 0, 0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER);
174168

175-
auto pipelineLayout = vsg::PipelineLayout::create(vsg::DescriptorSetLayouts{descriptorSetLayout}, pushConstantRanges);
169+
auto pipelineLayout = vsg::PipelineLayout::create(vsg::DescriptorSetLayouts{descriptorSetLayout}, vsg::PushConstantRanges {});
176170
auto graphicsPipeline = vsg::GraphicsPipeline::create(pipelineLayout, vsg::ShaderStages{vertexShader, fragmentShader}, pipelineStates);
177171
auto bindGraphicsPipeline = vsg::BindGraphicsPipeline::create(graphicsPipeline);
178172

@@ -254,11 +248,12 @@ int main(int argc, char** argv)
254248
windowTraits->windowTitle = "vsgshadertoy";
255249
toyShader = defaultShader;
256250
}
257-
else {
258-
toyShader = readFile(argv[1]);
251+
else
252+
{
259253
vsg::Path filePath(argv[1]);
254+
toyShader = readFile(filePath);
260255

261-
windowTraits->windowTitle = vsg::simpleFilename(filePath) + vsg::fileExtension(filePath);
256+
windowTraits->windowTitle = std::string("vsgshadertoy: ") + vsg::simpleFilename(filePath) + vsg::fileExtension(filePath);
262257
}
263258

264259

0 commit comments

Comments
 (0)