commit
This commit is contained in:
parent
dfe9b1abe9
commit
c82c8c0887
35 changed files with 245 additions and 10 deletions
80
examples/VulkanShader/main.cpp
Normal file
80
examples/VulkanShader/main.cpp
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
Crafter®.Graphics
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 3.0 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "../../lib/VulkanInitializers.hpp"
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
//required for the camera matrix.
|
||||
import Crafter.Math;
|
||||
import Crafter.Event;
|
||||
import Crafter.Graphics;
|
||||
using namespace Crafter;
|
||||
|
||||
typedef VulkanShader<"CustomShader.spirv", "main", VK_SHADER_STAGE_MESH_BIT_EXT, 1, {{{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 0}}}> CustomShaderSpirv;
|
||||
typedef VulkanShader<"FragmentShaderVertexColor.spirv", "main", VK_SHADER_STAGE_FRAGMENT_BIT, 0, {}> FragmentShader;
|
||||
typedef VulkanPipeline<CustomShaderSpirv, FragmentShader> Pipeline;
|
||||
|
||||
|
||||
class CustomShader {
|
||||
public:
|
||||
/*
|
||||
Define a buffer holding our color vectors.
|
||||
*/
|
||||
Buffer<Vector<float, 4>> colors;
|
||||
/*
|
||||
Initialze our buffer as shader visible storage buffer with the size of the colors vector.
|
||||
*/
|
||||
CustomShader(const std::vector<Vector<float, 4>>& colors) : colors(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, colors.size()) {
|
||||
memcpy(this->colors.value, colors.data(), colors.size()*sizeof(Vector<float, 4>));
|
||||
}
|
||||
void WriteDescriptors(VkDescriptorSet set) {
|
||||
/*
|
||||
Write the color buffer descriptor to the set.
|
||||
*/
|
||||
VkWriteDescriptorSet write[1] = {
|
||||
vks::initializers::writeDescriptorSet(set, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 0, &colors.descriptor),
|
||||
};
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 1, &write[0], 0, nullptr);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main() {
|
||||
VulkanDevice::CreateDevice();
|
||||
CustomShaderSpirv::CreateShader();
|
||||
FragmentShader::CreateShader();
|
||||
Pipeline::CreatePipeline();
|
||||
|
||||
WindowWaylandVulkan window("HelloWindow", 1280, 720);
|
||||
|
||||
DescriptorSet<CustomShaderSpirv, FragmentShader> descriptors;
|
||||
CustomShader customShader({{1,0,0,1}, {0,1,0,1}, {0,0,1,1}});
|
||||
customShader.WriteDescriptors(descriptors.set[0]);
|
||||
|
||||
EventListener<VkCommandBuffer> listener(&window.onDraw, [&descriptors](VkCommandBuffer cmd){
|
||||
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipelineLayout, 0, 2, &descriptors.set[0], 0, NULL);
|
||||
vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS, Pipeline::pipeline);
|
||||
VulkanDevice::vkCmdDrawMeshTasksEXTProc(cmd, 1, 1, 1);
|
||||
});
|
||||
|
||||
window.StartSync();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue