Compare commits
5 Commits
b6098d4dc6
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 0f0b0d1434 | |||
| 777e407d67 | |||
| e32e5f911f | |||
| 5b2d50a925 | |||
| f6f4f8b7c9 |
@@ -36,17 +36,14 @@ Buffer::~Buffer() {
|
||||
vmaDestroyBuffer(this->device.getAllocator(), this->buffer, this->allocation);
|
||||
}
|
||||
|
||||
// VMA always maps the whole allocation, so `size` only exists to keep the
|
||||
// interface; `offset` is applied to the returned pointer.
|
||||
vk::Result Buffer::map(vk::DeviceSize size, vk::DeviceSize offset) {
|
||||
vk::Result Buffer::map() {
|
||||
SOPHIA_ASSERT(buffer && allocation, "Called map on buffer before create");
|
||||
(void)size;
|
||||
|
||||
void* base = nullptr;
|
||||
vk::Result result = static_cast<vk::Result>(
|
||||
vmaMapMemory(this->device.getAllocator(), this->allocation, &base));
|
||||
if (result == vk::Result::eSuccess) {
|
||||
this->mapped = static_cast<char*>(base) + offset;
|
||||
this->mapped = base;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -19,8 +19,7 @@ class Buffer {
|
||||
vk::DeviceSize minOffsetAlignment = 1);
|
||||
~Buffer();
|
||||
|
||||
vk::Result map(vk::DeviceSize size = VK_WHOLE_SIZE,
|
||||
vk::DeviceSize offset = 0);
|
||||
vk::Result map();
|
||||
void unmap();
|
||||
|
||||
void writeToBuffer(void* data, vk::DeviceSize size = VK_WHOLE_SIZE,
|
||||
@@ -41,7 +40,7 @@ class Buffer {
|
||||
void* getMappedMemory() const { return mapped; }
|
||||
uint32_t getInstanceCount() const { return instanceCount; }
|
||||
vk::DeviceSize getInstanceSize() const { return instanceSize; }
|
||||
vk::DeviceSize getAlignmentSize() const { return instanceSize; }
|
||||
vk::DeviceSize getAlignmentSize() const { return alignmentSize; }
|
||||
vk::BufferUsageFlags getUsageFlags() const { return usageFlags; }
|
||||
vk::MemoryPropertyFlags getMemoryPropertyFlags() const {
|
||||
return memoryPropertyFlags;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
add_executable(conway_game_of_life main.cpp)
|
||||
|
||||
target_link_libraries(conway_game_of_life PRIVATE ${PROJECT_NAME})
|
||||
@@ -0,0 +1,3 @@
|
||||
#version 450
|
||||
|
||||
void main(){}
|
||||
@@ -0,0 +1,13 @@
|
||||
#include <iostream>
|
||||
#include <sophia/application.hpp>
|
||||
|
||||
class ConwayGameOfLife : public sophia::Application {
|
||||
public:
|
||||
ConwayGameOfLife()
|
||||
: Application{{.width = 800, .height = 600, .name = "ConwayGameOfLife"}} {
|
||||
}
|
||||
|
||||
void onCreate() override {}
|
||||
};
|
||||
|
||||
SOPHIA_MAIN(ConwayGameOfLife)
|
||||
+68
-9
@@ -1,18 +1,77 @@
|
||||
#define GLFW_INCLUDE_VULKAN
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <glm/mat4x4.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <vector>
|
||||
#include <sophia/scene_registry.hpp>
|
||||
#include <sophia/scene_view.hpp>
|
||||
#include <tracy/Tracy.hpp>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#include "renderer/render_context.hpp"
|
||||
#include "renderer/render_graph.hpp"
|
||||
#include "renderer/scene_renderer.hpp"
|
||||
#include "resources/resource_registry.hpp"
|
||||
#include "vulkan/device.hpp"
|
||||
#include "window.hpp"
|
||||
|
||||
constexpr uint32_t WIDTH = 1280;
|
||||
constexpr uint32_t HEIGHT = 720;
|
||||
constexpr const char* NAME = "";
|
||||
constexpr const char* NAME = "sandbox";
|
||||
|
||||
int main() { return EXIT_SUCCESS; }
|
||||
int main() {
|
||||
sophia::Window window{WIDTH, HEIGHT, NAME};
|
||||
sophia::Device device{&window};
|
||||
sophia::RenderContext renderContext{window, device};
|
||||
sophia::ResourceRegistry resourceRegistry{device,
|
||||
renderContext.getImageFormat()};
|
||||
|
||||
sophia::SceneRegistry sceneRegistry;
|
||||
sophia::SceneRenderer sceneRenderer{sceneRegistry, resourceRegistry, device,
|
||||
renderContext.getImageFormat()};
|
||||
|
||||
sophia::SceneView view;
|
||||
view.scene = sceneRegistry.create();
|
||||
view.clearColor = {0.01f, 0.01f, 0.02f, 1.0f};
|
||||
view.camera = sceneRegistry.get(view.scene).createCamera();
|
||||
|
||||
while (!window.shouldClose()) {
|
||||
glfwPollEvents();
|
||||
|
||||
vk::CommandBuffer commandBuffer = renderContext.beginFrame();
|
||||
if (!commandBuffer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
sceneRenderer.beginFrame(renderContext.getFrameIndex());
|
||||
|
||||
sophia::RenderGraph graph{renderContext.getTracyContext()};
|
||||
sophia::ImageRef color = graph.importImage(renderContext.getCurrentImage(),
|
||||
sophia::Access::Present);
|
||||
sophia::ImageRef depth = graph.importImage(
|
||||
renderContext.getCurrentDepthImage(), sophia::Access::DepthWrite);
|
||||
|
||||
graph.addPass(
|
||||
"scene",
|
||||
[&](sophia::RenderGraph::PassBuilder& pass) {
|
||||
const sophia::vec4& c = view.clearColor;
|
||||
pass.writeColor(color, vk::AttachmentLoadOp::eClear,
|
||||
{c.r, c.g, c.b, c.a});
|
||||
pass.writeDepth(depth, vk::AttachmentLoadOp::eClear);
|
||||
},
|
||||
[&](vk::CommandBuffer commandBuffer) {
|
||||
ZoneScopedN("scene pass");
|
||||
sceneRenderer.render(commandBuffer, view, view.camera,
|
||||
renderContext.getExtent());
|
||||
});
|
||||
|
||||
graph.execute(commandBuffer);
|
||||
|
||||
renderContext.endFrame();
|
||||
FrameMark;
|
||||
}
|
||||
|
||||
device.waitIdle();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user