cleaned up renderer
This commit is contained in:
parent
afe23851f0
commit
d661c88ee2
58 changed files with 3030 additions and 4722 deletions
|
|
@ -2,18 +2,19 @@ import Crafter.Graphics;
|
|||
import std;
|
||||
using namespace Crafter;
|
||||
|
||||
constexpr std::uint32_t width = 1280;
|
||||
constexpr std::uint32_t height = 720;
|
||||
|
||||
int main() {
|
||||
constexpr std::uint_fast32_t width = 1280;
|
||||
constexpr std::uint_fast32_t height = 720;
|
||||
Device::Initialize();
|
||||
Window window(width, height, "Hello Drawing!");
|
||||
|
||||
WindowWayland window(width, height, "Hello Drawing!");
|
||||
|
||||
for(std::uint_fast32_t x = 0; x < width; x++) {
|
||||
for(std::uint_fast32_t y = 0; y < height; y++) {
|
||||
window.framebuffer[x*height+y].r = 255;
|
||||
window.framebuffer[x*height+y].g = 0;
|
||||
window.framebuffer[x*height+y].b = 0;
|
||||
window.framebuffer[x*height+y].a = 255;
|
||||
for(std::uint32_t x = 0; x < width; x++) {
|
||||
for(std::uint32_t y = 0; y < height; y++) {
|
||||
window.renderer.buffer[x*height+y].r = 255;
|
||||
window.renderer.buffer[x*height+y].g = 0;
|
||||
window.renderer.buffer[x*height+y].b = 0;
|
||||
window.renderer.buffer[x*height+y].a = 255;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@
|
|||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-wayland"
|
||||
"configuration":"lib-wayland-debug"
|
||||
}
|
||||
]
|
||||
],
|
||||
"debug": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,16 +4,17 @@ import std;
|
|||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
WindowWayland window(1280, 720, "Hello Input!");
|
||||
Device::Initialize();
|
||||
Window window(1280, 720, "Hello Drawing!");
|
||||
|
||||
RenderingElement<true, true, false> element(
|
||||
RenderingElement2D<true, true, false> element(
|
||||
{
|
||||
FractionalToMapped<std::int32_t>(0.5), //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
|
||||
FractionalToMapped<std::int32_t>(0.5), //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor
|
||||
FractionalToMapped<std::int32_t>(0.5), //relativeSizeX: the relative x size this element should be scaled to compared to its parent
|
||||
FractionalToMapped<std::int32_t>(0.5), //relativeSizeY: the relative y size this element should be scaled to compared to its parent
|
||||
FractionalToMapped<std::int32_t>(0.5), //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle)
|
||||
FractionalToMapped<std::int32_t>(0.5), //anchorOffsetY: the amount this element's anchor should be offset from the top left corner (0.5 to place it in the middle)
|
||||
0.5, //anchorX: relative position where this elements x anchor (top-left) is placed to its parent x anchor
|
||||
0.5, //anchorY: relative position where this elements y anchor (top-left) is placed to its parent y anchor
|
||||
0.5, //relativeSizeX: the relative x size this element should be scaled to compared to its parent
|
||||
0.5, //relativeSizeY: the relative y size this element should be scaled to compared to its parent
|
||||
0.5, //anchorOffsetX: the amount this element's anchor should be offset from the top left corner (0.5 to in the middle)
|
||||
0.5, //anchorOffsetY: the amount this element's anchor should be offset from the top left corner (0.5 to place it in the middle)
|
||||
0 //z: this elements Z position
|
||||
},
|
||||
OpaqueType::FullyOpaque,
|
||||
|
|
@ -23,20 +24,14 @@ int main() {
|
|||
|
||||
MouseElement mouse(window);
|
||||
element.children.push_back(&mouse);
|
||||
window.elements.push_back(&element);
|
||||
window.renderer.elements.push_back(&element);
|
||||
|
||||
element.scalingBuffer = {{255, 0, 0 ,255}, {0, 255, 0 ,255}};
|
||||
element.UpdatePosition(window);
|
||||
element.UpdatePosition(window.renderer);
|
||||
|
||||
EventListener<MousePoint> clickListener(&mouse.onMouseLeftClick, [&mouse, &window](MousePoint point) {
|
||||
// Print the coordinates where the user clicked relative to the element's top left corner.
|
||||
std::println("Clicked on Mapped X:{} Y:{}!\nClicked on Fraction X:{} Y:{}!\nClicked on Screen X:{} Y:{}!\n",
|
||||
//Mapped space
|
||||
point.x, point.y,
|
||||
// Fraction space
|
||||
MappedToFractionalBoundless(point.x), MappedToFractionalBoundless(point.y),
|
||||
// Screen space
|
||||
MappedToAbsoluteBoundless(point.x, MappedToAbsoluteBoundless(mouse.mouseScaled.width, window.width)), MappedToAbsoluteBoundless(point.y, MappedToAbsoluteBoundless(mouse.mouseScaled.width, window.height))
|
||||
EventListener<void> clickListener(&mouse.onMouseLeftClick, [&window]() {
|
||||
std::println("Clicked on X:{} Y:{}!",
|
||||
window.currentMousePos.x, window.currentMousePos.y
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import std;
|
|||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
WindowWayland window(1280, 720, "Hello Window!");
|
||||
Device::Initialize();
|
||||
Window window(1280, 720, "Hello Window!");
|
||||
window.StartSync();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,10 @@
|
|||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-wayland"
|
||||
"configuration":"lib-wayland-debug"
|
||||
}
|
||||
]
|
||||
],
|
||||
"debug": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ typedef DescriptorSetLayoutVulkanConst<1, {{
|
|||
}}> descriptorSetLayoutImage;
|
||||
|
||||
int main() {
|
||||
VulkanDevice::CreateDevice();
|
||||
Device::CreateDevice();
|
||||
WindowVulkan window(1280, 720, "HelloVulkan");
|
||||
VkCommandBuffer cmd = window.StartInit();
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ int main() {
|
|||
std::array<std::uint32_t, 3> index {{2,1,0}};
|
||||
triangleMesh.Build(verts, index, cmd);
|
||||
|
||||
RenderingElement3DVulkan renderer = {
|
||||
RenderingElement3D renderer = {
|
||||
.instance = {
|
||||
.instanceCustomIndex = 0,
|
||||
.mask = 0xFF,
|
||||
|
|
@ -70,16 +70,16 @@ int main() {
|
|||
}
|
||||
};
|
||||
|
||||
RenderingElement3DVulkan::elements.emplace_back(&renderer);
|
||||
RenderingElement3D::elements.emplace_back(&renderer);
|
||||
MatrixRowMajor<float, 4, 3, 1> transform = MatrixRowMajor<float, 4, 3, 1>::Identity();
|
||||
std::memcpy(renderer.instance.transform.matrix, transform.m, sizeof(transform.m));
|
||||
|
||||
RenderingElement3DVulkan::tlases.resize(WindowVulkan::numFrames);
|
||||
RenderingElement3DVulkan::BuildTLAS(cmd, 0);
|
||||
RenderingElement3DVulkan::BuildTLAS(cmd, 1);
|
||||
RenderingElement3DVulkan::BuildTLAS(cmd, 2);
|
||||
RenderingElement3D::tlases.resize(Window::numFrames);
|
||||
RenderingElement3D::BuildTLAS(cmd, 0);
|
||||
RenderingElement3D::BuildTLAS(cmd, 1);
|
||||
RenderingElement3D::BuildTLAS(cmd, 2);
|
||||
|
||||
VkDescriptorImageInfo imageInfo[WindowVulkan::numFrames] = {
|
||||
VkDescriptorImageInfo imageInfo[Window::numFrames] = {
|
||||
{
|
||||
.imageView = window.imageViews[0],
|
||||
.imageLayout = VK_IMAGE_LAYOUT_GENERAL
|
||||
|
|
@ -97,7 +97,7 @@ int main() {
|
|||
VkWriteDescriptorSetAccelerationStructureKHR writeDescriptorSetAccelerationStructure {
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR,
|
||||
.accelerationStructureCount = 1,
|
||||
.pAccelerationStructures = &RenderingElement3DVulkan::tlases[0].accelerationStructure
|
||||
.pAccelerationStructures = &RenderingElement3D::tlases[0].accelerationStructure
|
||||
};
|
||||
|
||||
VkWriteDescriptorSet write[4];
|
||||
|
|
@ -112,7 +112,7 @@ int main() {
|
|||
.descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR,
|
||||
};
|
||||
|
||||
for(std::uint32_t i = 0; i < WindowVulkan::numFrames; i++) {
|
||||
for(std::uint32_t i = 0; i < Window::numFrames; i++) {
|
||||
write[i+1] = {
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET,
|
||||
.dstSet = pool.sets[i+1],
|
||||
|
|
@ -123,7 +123,7 @@ int main() {
|
|||
.pImageInfo = &imageInfo[i]
|
||||
};
|
||||
}
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 4, write, 0, nullptr);
|
||||
vkUpdateDescriptorSets(Device::device, 4, write, 0, nullptr);
|
||||
window.descriptorsRt = {pool.sets[0], pool.sets[1]};
|
||||
|
||||
/*
|
||||
|
|
@ -147,12 +147,12 @@ int main() {
|
|||
|
||||
MatrixRowMajor<float, 4, 3, 1> transform = MatrixRowMajor<float, 4, 3, 1>::Translation(value, 0, 0);
|
||||
std::memcpy(renderer.instance.transform.matrix, transform.m, sizeof(transform.m));
|
||||
RenderingElement3DVulkan::BuildTLAS(window.drawCmdBuffers[window.currentBuffer], window.currentBuffer);
|
||||
RenderingElement3D::BuildTLAS(window.drawCmdBuffers[window.currentBuffer], window.currentBuffer);
|
||||
|
||||
VkWriteDescriptorSetAccelerationStructureKHR writeDescriptorSetAccelerationStructure {
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR,
|
||||
.accelerationStructureCount = 1,
|
||||
.pAccelerationStructures = &RenderingElement3DVulkan::tlases[window.currentBuffer].accelerationStructure
|
||||
.pAccelerationStructures = &RenderingElement3D::tlases[window.currentBuffer].accelerationStructure
|
||||
};
|
||||
|
||||
VkWriteDescriptorSet write = {
|
||||
|
|
@ -164,7 +164,7 @@ int main() {
|
|||
.descriptorCount = 1,
|
||||
.descriptorType = VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR,
|
||||
};
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 1, &write, 0, nullptr);
|
||||
vkUpdateDescriptorSets(Device::device, 1, &write, 0, nullptr);
|
||||
|
||||
window.descriptorsRt[1] = pool.sets[window.currentBuffer+1];
|
||||
});
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ A blue tinted vulkan window with a white triangle in the center.
|
|||
EventListener<VkCommandBuffer> listener(&window.onDraw, [&descriptors, &meshShader](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, meshShader.threadCount, 1, 1);
|
||||
Device::vkCmdDrawMeshTasksEXTProc(cmd, meshShader.threadCount, 1, 1);
|
||||
});
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,8 @@ typedef DescriptorSetLayoutVulkanConst<3, {{
|
|||
}}> descriptorSetLayout;
|
||||
|
||||
int main() {
|
||||
VulkanDevice::CreateDevice();
|
||||
WindowVulkan window(1280, 720, "HelloVulkan");
|
||||
Device::Initialize();
|
||||
Window window(1280, 720, "HelloVulkan");
|
||||
VkCommandBuffer cmd = window.StartInit();
|
||||
|
||||
Raygenspv::CreateShader();
|
||||
|
|
@ -61,7 +61,7 @@ int main() {
|
|||
std::array<std::uint32_t, 3> index {{2,1,0}};
|
||||
triangleMesh.Build(verts, index, cmd);
|
||||
|
||||
RenderingElement3DVulkan renderer = {
|
||||
RenderingElement3D renderer = {
|
||||
.instance = {
|
||||
.instanceCustomIndex = 0,
|
||||
.mask = 0xFF,
|
||||
|
|
@ -71,12 +71,12 @@ int main() {
|
|||
}
|
||||
};
|
||||
|
||||
RenderingElement3DVulkan::elements.emplace_back(&renderer);
|
||||
RenderingElement3D::elements.emplace_back(&renderer);
|
||||
|
||||
MatrixRowMajor<float, 4, 3, 1> transform = MatrixRowMajor<float, 4, 3, 1>::Identity();
|
||||
std::memcpy(renderer.instance.transform.matrix, transform.m, sizeof(transform.m));
|
||||
RenderingElement3DVulkan::tlases.resize(1);
|
||||
RenderingElement3DVulkan::BuildTLAS(cmd, 0);
|
||||
RenderingElement3D::tlases.resize(1);
|
||||
RenderingElement3D::BuildTLAS(cmd, 0);
|
||||
|
||||
VkDescriptorImageInfo imageInfo = {
|
||||
.imageView = window.imageViews[0],
|
||||
|
|
@ -86,7 +86,7 @@ int main() {
|
|||
VkWriteDescriptorSetAccelerationStructureKHR writeDescriptorSetAccelerationStructure {
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR,
|
||||
.accelerationStructureCount = 1,
|
||||
.pAccelerationStructures = &RenderingElement3DVulkan::tlases[0].accelerationStructure
|
||||
.pAccelerationStructures = &RenderingElement3D::tlases[0].accelerationStructure
|
||||
};
|
||||
|
||||
VulkanBuffer<std::uint32_t, true, false, false> lightBuffer;
|
||||
|
|
@ -121,7 +121,7 @@ int main() {
|
|||
.pBufferInfo = &lightBuffer.descriptor
|
||||
}
|
||||
};
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 3, write, 0, nullptr);
|
||||
vkUpdateDescriptorSets(Device::device, 3, write, 0, nullptr);
|
||||
|
||||
|
||||
window.SetPipelineRT<Pipeline>();
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@
|
|||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-vulkan"
|
||||
"configuration":"lib-win32-vulkan-debug"
|
||||
}
|
||||
],
|
||||
"target": "x86_64-w64-mingw32",
|
||||
"debug": true,
|
||||
"shaders": [
|
||||
{
|
||||
"path":"raygen.glsl",
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ A blue tinted vulkan window with a white triangle in the center.
|
|||
EventListener<VkCommandBuffer> listener(&window.onDraw, [&descriptors, &meshShader](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, meshShader.threadCount, 1, 1);
|
||||
Device::vkCmdDrawMeshTasksEXTProc(cmd, meshShader.threadCount, 1, 1);
|
||||
});
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import Crafter.Math;
|
|||
|
||||
|
||||
int main() {
|
||||
VulkanDevice::CreateDevice();
|
||||
Device::CreateDevice();
|
||||
WindowVulkan window(1280, 720, "HelloVulkan");
|
||||
VkCommandBuffer cmd = window.StartInit();
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ int main() {
|
|||
std::array<Vector<float, 3, 3>, 3> verts {{{-150, -150, 100}, {0, 150, 100}, {150, -150, 100}}};
|
||||
std::array<std::uint32_t, 3> index {{2,1,0}};
|
||||
triangleMesh.Build(verts, index, cmd);
|
||||
RenderingElement3DVulkan renderer = {
|
||||
RenderingElement3D renderer = {
|
||||
.instance = {
|
||||
.instanceCustomIndex = 0,
|
||||
.mask = 0xFF,
|
||||
|
|
@ -92,9 +92,9 @@ int main() {
|
|||
};
|
||||
MatrixRowMajor<float, 4, 3, 1> transform = MatrixRowMajor<float, 4, 3, 1>::Identity();
|
||||
std::memcpy(renderer.instance.transform.matrix, transform.m, sizeof(transform.m));
|
||||
RenderingElement3DVulkan::tlases.resize(1);
|
||||
RenderingElement3DVulkan::elements.push_back(&renderer);
|
||||
RenderingElement3DVulkan::BuildTLAS(cmd, 0);
|
||||
RenderingElement3D::tlases.resize(1);
|
||||
RenderingElement3D::elements.push_back(&renderer);
|
||||
RenderingElement3D::BuildTLAS(cmd, 0);
|
||||
|
||||
VkDescriptorImageInfo imageInfo = {
|
||||
.imageView = window.imageViews[0],
|
||||
|
|
@ -104,7 +104,7 @@ int main() {
|
|||
VkWriteDescriptorSetAccelerationStructureKHR writeDescriptorSetAccelerationStructure {
|
||||
.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR,
|
||||
.accelerationStructureCount = 1,
|
||||
.pAccelerationStructures = &RenderingElement3DVulkan::tlases[0].accelerationStructure
|
||||
.pAccelerationStructures = &RenderingElement3D::tlases[0].accelerationStructure
|
||||
};
|
||||
|
||||
VkWriteDescriptorSet write[2] = {
|
||||
|
|
@ -127,7 +127,7 @@ int main() {
|
|||
.pImageInfo = &imageInfo
|
||||
}
|
||||
};
|
||||
vkUpdateDescriptorSets(VulkanDevice::device, 2, write, 0, nullptr);
|
||||
vkUpdateDescriptorSets(Device::device, 2, write, 0, nullptr);
|
||||
|
||||
window.SetPipelineRT(pipeline);
|
||||
window.descriptorsRt = pool.sets;
|
||||
|
|
|
|||
|
|
@ -1,25 +0,0 @@
|
|||
# HelloWindow Example
|
||||
|
||||
## Description
|
||||
|
||||
This example demonstrates the minimal code needed to create a vulkan window and show it on the screen.
|
||||
|
||||
## Expected Result
|
||||
|
||||
A blue tinted vulkan window with the title "HelloWindow" shows onscreen, with debug info in the console.
|
||||
|
||||
## Highlighted Code Snippet
|
||||
|
||||
```cpp
|
||||
VulkanDevice::CreateDevice();
|
||||
WindowWaylandVulkan window("HelloWindow", 1280, 720);
|
||||
VkCommandBuffer cmd = window.StartInit();
|
||||
window.FinishInit();
|
||||
window.StartSync();
|
||||
```
|
||||
|
||||
## How to Run
|
||||
|
||||
```bash
|
||||
crafter-build build executable -r
|
||||
```
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
#include "vulkan/vulkan.h"
|
||||
|
||||
import Crafter.Graphics;
|
||||
using namespace Crafter;
|
||||
|
||||
int main() {
|
||||
/*
|
||||
This sets up all necessary things and creates the vulkan device.
|
||||
This must be called before any vulkan related things.
|
||||
Things like VkDevice are static members of the VulkanDevice class.
|
||||
*/
|
||||
VulkanDevice::CreateDevice();
|
||||
WindowVulkan window(1280, 720, "HelloVulkan");
|
||||
|
||||
// /*
|
||||
// StartInit gives you a VkCommandBuffer to use before the event loop starts
|
||||
// Use this for inititializing things like textures.
|
||||
// */
|
||||
// VkCommandBuffer cmd = window.StartInit();
|
||||
|
||||
// /*
|
||||
// FinishInit executes all commands recorded to StartInit.
|
||||
// This must be called before the the event loops starts if you called StartInit before.
|
||||
// */
|
||||
// window.FinishInit();
|
||||
|
||||
window.Render();
|
||||
window.StartSync();
|
||||
}
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
{
|
||||
"name": "crafter-graphics",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "executable",
|
||||
"implementations": ["main"],
|
||||
"dependencies": [
|
||||
{
|
||||
"path":"../../project.json",
|
||||
"configuration":"lib-vulkan"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue