Luka Juric
unread,Jul 5, 2021, 4:58:35 PM7/5/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to vsg-users : VulkanSceneGraph Developer Discussion Group
Hi All,
More questions came up on my way to understanding VSG.:
Sorry in advance, the questions are rather noobish because I'm new relatively new to C++ and CG programming with Vulkan
1. The Plugin
I tried to write a ReaderWriter, which only implements the reading, like this:
class TestPlugin : vsg::ReaderWriter{
public:
TestPlugin();
virtual vsg::ref_ptr<vsg::Object> read(const vsg::Path& /*filename*/, vsg::ref_ptr<const vsg::Options> = {}) const;
virtual vsg::ref_ptr<vsg::Object> read(std::istream& /*fin*/, vsg::ref_ptr<const vsg::Options> = {}) const;
};
vsg::ref_ptr<vsg::Object> TestPlugin::read(const vsg::Path& filename, vsg::ref_ptr<const vsg::Options> options) const
{
//implementation one
}
vsg::ref_ptr<vsg::Object> TestPlugin::read(std::istream& stream, vsg::ref_ptr<const vsg::Options> options) const
{
//implementation two
}
But I can't seem to figure out where to specify which file extension actually corresponds to the plugin (like supportsExtension() in OSG).
Also how do I add it to the options? I tried it like this:
TestPlugin* myPlugin = new TestPlugin;
auto options = vsg::Options::create();
options->readerWriters.push_back(static_cast<vsg::ref_ptr<vsg::ReaderWriter>>(myPlugin));
but it tells me 'type cast': conversion from 'R *' to 'T *' exists, but is inaccessible.
when I change the inheritence from
class TestPlugin : vsg::ReaderWriter
to
class TestPlugin : public vsg::ReaderWriter
I get a linking error.
2. the vsgdraw example / shaders in VSG
The following problem contains much text, but is also rather simple.
I tried to modify the vsgdraw example to not use a texture, but just one gray-scale float-color per vertex. So I started building a basic shader for that, using the given shaders in vsgExamples, but I noticed the following:
the source code uses the vert_PushConstants.spv and frag_PushConstants.spv. I assumed they are compiled from shader_PushConstants.frag and shader_PushConstants.vert,
but if I compile the exact same sources to the spv format myself (using vsgconv) and use them, I get an access violation error in VSG, not with the given spv's tho.
Also the compiled files differ by a fraction of a KB, so i assume they stem from a slightly different source, which I would need to have an example of how to structure own shaders to use in VSG.
Here is the shader source code for what I tried to do:
Vertex:
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(push_constant) uniform PushConstants {
mat4 projection;
mat4 modelview;
} pc;
layout(location = 0) in vec3 inPosition;
layout(location = 1) in float inColor;
layout(location = 0) out float fragColor;
out gl_PerVertex {
vec4 gl_Position;
};
void main() {
gl_Position = (pc.projection * pc.modelview) * vec4(inPosition, 1.0);
fragColor = inColor;
}
Fragment:
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in float fragColor;
void main() {
outColor = vec4(vec3(fragColor),1.0f);
}
The source code is basically the vsgdraw example, but i removed the descriptors
for the texture since I don't use one:
auto pipelineLayout = vsg::PipelineLayout::create(vsg::DescriptorSetLayouts{ }, pushConstantRanges);
also I modified the bindings and attributes to only use the vert position (vsg::vec3Array) + color (vsg::floatArray) which I pass with the BindVertexBuffers.
I get an error when I try to add my source as an attachment, so I'll add it as a comment on this thread. The code is even shorter than the vsgdraw example, but I really can't figure it out.
I assume that I didn't set up the pipeline correctly.
Thank you all very much in advance,
Luke