Huge changes #3
+19
-89
@@ -10,10 +10,13 @@
|
|||||||
|
|
||||||
#define GLM_FORCE_RADIANS
|
#define GLM_FORCE_RADIANS
|
||||||
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||||
|
#include <imgui.h>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "buffer.hpp"
|
#include "buffer.hpp"
|
||||||
#include "device.hpp"
|
#include "device.hpp"
|
||||||
|
#include "imgui_renderer.hpp"
|
||||||
#include "mesh.hpp"
|
#include "mesh.hpp"
|
||||||
#include "pipelines/graphics_pipeline.hpp"
|
#include "pipelines/graphics_pipeline.hpp"
|
||||||
#include "render_context.hpp"
|
#include "render_context.hpp"
|
||||||
@@ -49,72 +52,10 @@ class Application::Impl {
|
|||||||
device{&window},
|
device{&window},
|
||||||
renderContext{window, device} {}
|
renderContext{window, device} {}
|
||||||
|
|
||||||
/*void run(const std::string& vertShaderPath,
|
|
||||||
const std::string& fragShaderPath) {
|
|
||||||
log::info("Running Render Triangle Test...");
|
|
||||||
|
|
||||||
RenderContext renderContext{window, device};
|
|
||||||
|
|
||||||
auto vertexShader = Shader::Builder()
|
|
||||||
.fromGLSL(vertShaderPath)
|
|
||||||
.setStage(ShaderStage::VERTEX)
|
|
||||||
.build();
|
|
||||||
auto fragmentShader = Shader::Builder()
|
|
||||||
.fromGLSL(fragShaderPath)
|
|
||||||
.setStage(ShaderStage::FRAGMENT)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
vk::PushConstantRange pushConstantRange{};
|
|
||||||
pushConstantRange.stageFlags =
|
|
||||||
vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment;
|
|
||||||
pushConstantRange.offset = 0;
|
|
||||||
pushConstantRange.size = sizeof(PushConstants);
|
|
||||||
|
|
||||||
vk::PipelineLayoutCreateInfo pipelineLayoutInfo{};
|
|
||||||
pipelineLayoutInfo.pushConstantRangeCount = 1;
|
|
||||||
pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange;
|
|
||||||
|
|
||||||
vk::UniquePipelineLayout pipelineLayout =
|
|
||||||
device.get()->createPipelineLayoutUnique(pipelineLayoutInfo);
|
|
||||||
|
|
||||||
std::vector<vk::VertexInputBindingDescription> bindingDescriptions{
|
|
||||||
{0, sizeof(Vertex), vk::VertexInputRate::eVertex}};
|
|
||||||
std::vector<vk::VertexInputAttributeDescription> attributeDescriptions{
|
|
||||||
{0, 0, vk::Format::eR32G32Sfloat, offsetof(Vertex, position)},
|
|
||||||
{1, 0, vk::Format::eR32G32B32Sfloat, offsetof(Vertex, color)}};
|
|
||||||
|
|
||||||
std::unique_ptr<sophia::GraphicsPipeline> graphicsPipeline =
|
|
||||||
GraphicsPipeline::Builder(device)
|
|
||||||
.setVertexShader(*vertexShader)
|
|
||||||
.setFragmentShader(*fragmentShader)
|
|
||||||
.setPipelineLayout(pipelineLayout.get())
|
|
||||||
.setColorAttachmentFormats({renderContext.getImageFormat()})
|
|
||||||
.setVertexInput(bindingDescriptions, attributeDescriptions)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
// Oversized triangle covering the full screen so the fragment shader runs
|
|
||||||
// for every pixel.
|
|
||||||
std::vector<Vertex> vertices{
|
|
||||||
{{-1.0f, -1.0f}, {1.0f, 0.0f, 0.0f}},
|
|
||||||
{{3.0f, -1.0f}, {0.0f, 1.0f, 0.0f}},
|
|
||||||
{{-1.0f, 3.0f}, {0.0f, 0.0f, 1.0f}},
|
|
||||||
};
|
|
||||||
|
|
||||||
Buffer vertexBuffer{device, sizeof(Vertex),
|
|
||||||
static_cast<u32>(vertices.size()),
|
|
||||||
vk::BufferUsageFlagBits::eVertexBuffer,
|
|
||||||
vk::MemoryPropertyFlagBits::eHostVisible |
|
|
||||||
vk::MemoryPropertyFlagBits::eHostCoherent};
|
|
||||||
vertexBuffer.map();
|
|
||||||
vertexBuffer.writeToBuffer(vertices.data(),
|
|
||||||
sizeof(Vertex) * vertices.size());
|
|
||||||
vertexBuffer.unmap();
|
|
||||||
|
|
||||||
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void run() {
|
void run() {
|
||||||
ModelRenderSystem modelRenderSystem{device, renderContext};
|
ModelRenderSystem modelRenderSystem{device, renderContext};
|
||||||
|
ImGuiRenderer imguiRenderer{window, device, renderContext.getImageFormat(),
|
||||||
|
renderContext.getImageCount()};
|
||||||
|
|
||||||
this->application.onCreate();
|
this->application.onCreate();
|
||||||
|
|
||||||
@@ -139,7 +80,6 @@ class Application::Impl {
|
|||||||
static_cast<float>(extent.height)),
|
static_cast<float>(extent.height)),
|
||||||
this->application.camera};
|
this->application.camera};
|
||||||
this->application.onUpdate(frameInfo);
|
this->application.onUpdate(frameInfo);
|
||||||
this->application.onRender();
|
|
||||||
this->application.camera.setProjection(
|
this->application.camera.setProjection(
|
||||||
-frameInfo.currentFramebufferExtent.x / 2.f,
|
-frameInfo.currentFramebufferExtent.x / 2.f,
|
||||||
frameInfo.currentFramebufferExtent.x / 2.f,
|
frameInfo.currentFramebufferExtent.x / 2.f,
|
||||||
@@ -151,6 +91,11 @@ class Application::Impl {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
imguiRenderer.beginFrame();
|
||||||
|
|
||||||
|
this->application.panelRegistry.update(frameInfo);
|
||||||
|
this->application.onRender();
|
||||||
|
|
||||||
renderContext.transitionCurrentImage(
|
renderContext.transitionCurrentImage(
|
||||||
commandBuffer, vk::ImageLayout::eColorAttachmentOptimal);
|
commandBuffer, vk::ImageLayout::eColorAttachmentOptimal);
|
||||||
|
|
||||||
@@ -194,6 +139,8 @@ class Application::Impl {
|
|||||||
modelRenderSystem.render(commandBuffer, instances, frameInfo);
|
modelRenderSystem.render(commandBuffer, instances, frameInfo);
|
||||||
this->drawCalls.clear();
|
this->drawCalls.clear();
|
||||||
|
|
||||||
|
imguiRenderer.endFrame(commandBuffer);
|
||||||
|
|
||||||
commandBuffer.endRendering();
|
commandBuffer.endRendering();
|
||||||
|
|
||||||
renderContext.transitionCurrentImage(commandBuffer,
|
renderContext.transitionCurrentImage(commandBuffer,
|
||||||
@@ -233,24 +180,11 @@ class Application::Impl {
|
|||||||
this->meshes.clear();
|
this->meshes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
MeshHandle createMesh(std::vector<CanvasVertex> vertices,
|
void drawMesh(const Mesh& mesh, const glm::mat4& transform) {
|
||||||
std::vector<u32> indices) {
|
this->drawCalls.push_back({&mesh, transform});
|
||||||
Mesh::Builder builder{};
|
|
||||||
builder.vertices.reserve(vertices.size());
|
|
||||||
for (const CanvasVertex& vertex : vertices) {
|
|
||||||
builder.vertices.push_back({vertex.position, vertex.color});
|
|
||||||
}
|
|
||||||
builder.indices = std::move(indices);
|
|
||||||
|
|
||||||
this->persistentMeshes.push_back(
|
|
||||||
std::make_unique<Mesh>(this->device, builder));
|
|
||||||
return static_cast<MeshHandle>(this->persistentMeshes.size() - 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawMesh(MeshHandle handle, const glm::mat4& transform) {
|
Device& getDevice() { return device; }
|
||||||
this->drawCalls.push_back(
|
|
||||||
{this->persistentMeshes[handle].get(), transform});
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Application& application;
|
Application& application;
|
||||||
@@ -260,7 +194,6 @@ class Application::Impl {
|
|||||||
RenderContext renderContext;
|
RenderContext renderContext;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<Mesh>> meshes;
|
std::vector<std::unique_ptr<Mesh>> meshes;
|
||||||
std::vector<std::unique_ptr<Mesh>> persistentMeshes;
|
|
||||||
std::vector<ModelRenderSystem::MeshInstance> drawCalls;
|
std::vector<ModelRenderSystem::MeshInstance> drawCalls;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -271,7 +204,9 @@ void Application::setCommandLineArgs(int argc, const char* const* argv) {
|
|||||||
Application::Application(const Config& config)
|
Application::Application(const Config& config)
|
||||||
: impl{std::make_unique<Impl>(*this, config)},
|
: impl{std::make_unique<Impl>(*this, config)},
|
||||||
canvas{this},
|
canvas{this},
|
||||||
args{std::move(commandLineArgs)} {}
|
args{std::move(commandLineArgs)},
|
||||||
|
assetRegistry{impl->getDevice()},
|
||||||
|
_debugUI{this->panelRegistry} {}
|
||||||
|
|
||||||
Application::~Application() = default;
|
Application::~Application() = default;
|
||||||
|
|
||||||
@@ -284,13 +219,8 @@ void Application::pushMesh(std::vector<CanvasVertex> vertices,
|
|||||||
|
|
||||||
void Application::clearMeshes() { impl->clearMeshes(); }
|
void Application::clearMeshes() { impl->clearMeshes(); }
|
||||||
|
|
||||||
MeshHandle Application::createMesh(std::vector<CanvasVertex> vertices,
|
|
||||||
std::vector<u32> indices) {
|
|
||||||
return impl->createMesh(std::move(vertices), std::move(indices));
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::drawMesh(MeshHandle handle, const glm::mat4& transform) {
|
void Application::drawMesh(MeshHandle handle, const glm::mat4& transform) {
|
||||||
impl->drawMesh(handle, transform);
|
impl->drawMesh(assetRegistry.get<Mesh>(handle), transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace sophia
|
} // namespace sophia
|
||||||
|
|||||||
Reference in New Issue
Block a user