Skip to content

Commit

Permalink
rendering improvements;
Browse files Browse the repository at this point in the history
  • Loading branch information
NateSeymour committed Nov 13, 2024
1 parent 65d053f commit 64276d3
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 11 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,27 @@ add_library(unlogic STATIC
src/compiler/std/RuntimeLibrary.cpp
src/compiler/std/RuntimeLibrary.h
src/compiler/transformer/IRGenerationContext.h
src/graphic/Scene.cpp
src/graphic/Scene.h
src/graphic/Color.cpp
src/graphic/Color.h
)
target_link_libraries(unlogic PUBLIC ${llvm_libs} buffalo)
target_include_directories(unlogic PUBLIC ${LLVM_INCLUDE_DIRS} src)

# CALCULATOR
qt_standard_project_setup()
qt_add_executable(unlogic-calculator
src/calculator/main.cpp
src/calculator/Window.cpp
src/calculator/Window.h
src/calculator/renderer/VulkanRenderer.h
src/calculator/renderer/VulkanWindow.h
src/calculator/renderer/VulkanWindow.cpp
src/calculator/renderer/VulkanInstance.h
src/calculator/renderer/VulkanInstance.cpp
)
target_link_libraries(unlogic-calculator PRIVATE Qt6::Widgets Qt6::Gui)
target_link_libraries(unlogic-calculator PRIVATE Qt6::Widgets Qt6::Gui unlogic)
set_target_properties(unlogic-calculator PROPERTIES
WIN32_EXECUTABLE ON
MACOSX_BUNDLE ON
Expand Down
13 changes: 10 additions & 3 deletions src/calculator/Window.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,28 @@ namespace ui
class Window : public QMainWindow
{
QTextEdit *editor_ = nullptr;
QWidget *renderer_ = nullptr;
VulkanRenderer *renderer_ = nullptr;
QWidget *renderer_widget_ = nullptr;

std::unique_ptr<unlogic::Scene> scene_;

public:
Window()
{
this->scene_ = std::make_unique<unlogic::Scene>();

auto splitter = new QSplitter;

this->editor_ = new QTextEdit;
splitter->addWidget(this->editor_);

auto render_window = new VulkanWindow;
render_window->setVulkanInstance(ui::vk_global);
this->scene_->background = unlogic::Color::Green;
render_window->setScene(this->scene_.get());

this->renderer_ = QWidget::createWindowContainer(render_window);
splitter->addWidget(this->renderer_);
this->renderer_widget_ = QWidget::createWindowContainer(render_window);
splitter->addWidget(this->renderer_widget_);

this->setCentralWidget(splitter);
}
Expand Down
33 changes: 27 additions & 6 deletions src/calculator/renderer/VulkanRenderer.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
#ifndef UNLOGIC_VULKANRENDERER_H
#define UNLOGIC_VULKANRENDERER_H

#include <iostream>
#include <QVulkanWindowRenderer>
#include <QVulkanDeviceFunctions>
#include "graphic/Scene.h"

namespace ui
{
class VulkanRenderer : public QVulkanWindowRenderer
class VulkanRenderer : public QObject, public QVulkanWindowRenderer
{
Q_OBJECT

QVulkanWindow *window_ = nullptr;
QVulkanDeviceFunctions *device_functions_ = nullptr;
float green = 0;

unlogic::Scene *scene_ = nullptr;

public slots:
void setScene(unlogic::Scene *scene)
{
if(scene != this->scene_)
{
this->scene_ = scene;
this->window_->requestUpdate();
}
}

public:
void initResources() override
Expand All @@ -20,13 +35,19 @@ namespace ui

void startNextFrame() override
{
this->green += 0.005f;
if (this->green > 1.0f)
if(!this->scene_)
{
this->green = 0.0f;
this->window_->frameReady();
this->window_->requestUpdate();
return;
}

VkClearColorValue clearColor = {{ 0.0f, this->green, 0.0f, 1.0f }};
VkClearColorValue clearColor = {
this->scene_->background.r,
this->scene_->background.g,
this->scene_->background.b,
this->scene_->background.a,
};
VkClearDepthStencilValue clearDS = { 1.0f, 0 };
VkClearValue clearValues[2];
memset(clearValues, 0, sizeof(clearValues));
Expand Down
10 changes: 10 additions & 0 deletions src/calculator/renderer/VulkanWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "VulkanWindow.h"

#include <iostream>

using namespace ui;

void VulkanWindow::setScene(unlogic::Scene *scene)
{
emit sceneChanged(scene);
}
15 changes: 14 additions & 1 deletion src/calculator/renderer/VulkanWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,29 @@

#include <QVulkanWindow>
#include "VulkanRenderer.h"
#include "graphic/Scene.h"

namespace ui
{
class VulkanWindow : public QVulkanWindow
{
Q_OBJECT

public:
QVulkanWindowRenderer *createRenderer() override
{
return new VulkanRenderer(this);
auto renderer = new VulkanRenderer(this);

QObject::connect(this, &VulkanWindow::sceneChanged, renderer, &VulkanRenderer::setScene);

return renderer;
}

public slots:
void setScene(unlogic::Scene *scene);

signals:
void sceneChanged(unlogic::Scene *scene);
};
} // ui

Expand Down
13 changes: 13 additions & 0 deletions src/graphic/Color.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// Created by Nathan on 11/12/2024.
//

#include "Color.h"

using namespace unlogic;

Color Color::White = { 0.0, 0.0, 0.0 };
Color Color::Black = { 1.0, 1.0, 1.0 };
Color Color::Red = { 1.0, 0.0, 0.0 };
Color Color::Green = { 0.0, 1.0, 0.0 };
Color Color::Blue = { 0.0, 0.0, 1.0 };
21 changes: 21 additions & 0 deletions src/graphic/Color.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef COLOR_H
#define COLOR_H

namespace unlogic
{
struct Color
{
float r = 0.0;
float g = 0.0;
float b = 0.0;
float a = 1.0;

static Color White;
static Color Black;
static Color Red;
static Color Green;
static Color Blue;
};
}

#endif //COLOR_H
8 changes: 8 additions & 0 deletions src/graphic/Scene.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//
// Created by Nathan on 11/12/2024.
//

#include "Scene.h"

namespace unlogic {
} // unlogic
18 changes: 18 additions & 0 deletions src/graphic/Scene.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by Nathan on 11/12/2024.
//

#ifndef SCENE_H
#define SCENE_H

#include "Color.h"

namespace unlogic
{
struct Scene
{
Color background = Color::White;
};
} // unlogic

#endif //SCENE_H

0 comments on commit 64276d3

Please sign in to comment.