andy-thomason / Vookoo

A set of utilities for taking the pain out of Vulkan in header only modern C++
MIT License
521 stars 52 forks source link

"return *this" api #41

Closed pocdn closed 3 years ago

pocdn commented 3 years ago

Hi, in prior version of Vooko I seem to recall there was some more use of "return this" approach. I added an example using modified vku.h from shadertoy (https://www.shadertoy.com/view/wdGXzK) to demo vku.h with added "return this" usage. The change allows code like

pm.shader(vk::ShaderStageFlagBits::eVertex, vert) .shader(vk::ShaderStageFlagBits::eFragment, frag) .vertexBinding(0, sizeof(Vertex)) .vertexAttribute(0, 0, vk::Format::eR32G32Sfloat, offsetof(Vertex, pos)) .viewport(viewport) .frontFace(vk::FrontFace::eCounterClockwise) .cullMode(vk::CullModeFlagBits::eBack);

instead of the repetitive (IMHO), for example, use of "pm" such as required sometimes as

pm.shader(vk::ShaderStageFlagBits::eVertex, vert); pm.shader(vk::ShaderStageFlagBits::eFragment, frag); pm.vertexBinding(0, sizeof(Vertex)); pm.vertexAttribute(0, 0, vk::Format::eR32G32Sfloat, offsetof(Vertex, pos)); pm.viewport(viewport); pm.frontFace(vk::FrontFace::eCounterClockwise); pm.cullMode(vk::CullModeFlagBits::eBack);

All the prior examples 01-06 are unaffected so they still compile and run without any changes. It's a matter of style I suppose, but seems the performance hit if any would be minor at most and the benefit of code "readability" is a good gain.

Thanks for the great library. It is helping me to learn and understand vulkan much more clearly (or quickly) than the overly verbose strict-C version from Khronos and even it's own c++ wrapper.

Cheers, Todd

andy-thomason commented 3 years ago

This looks nice.

Good to see more examples.

pocdn commented 3 years ago

I have some more examples if you like to use them as examples with vookoo. They are not all in complete shape. But as they get cleaned up and such I will add them. For example, I added a simple one (examples/helloInstancing/) that demonstrates drawing multiple quads via instancing.

andy-thomason commented 3 years ago

Best to make separate PRs.

Shall I merge this one?

pocdn commented 3 years ago

Yes please merge, but with the caveat following.

About cybertruck.frag ... I emailed the auther of this particular cybertruck fragment shader with creative commons license from shaderytoy about sharing it as an example with your vookoo library. He responded "As long as you keep the comment block at the top of the shader, and a link to the original, both of which you did it seems, that should be fine!" If that is okay with you then it would be a nice example. If not, then I can work on a different fragment shader -- no where as artistc though -- but leaving the c++ code unchanged.

As I make some other examples I'll do seperate PRs from now on.

andy-thomason commented 3 years ago

The license is a CCbySA one:

License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

You have kept the attribution, which is important.