Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 1 addition & 27 deletions example/damaged_helmet/main.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
#include <memory>

#include <GLFW/glfw3.h>
#include <glad/gl.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

#include "paimon/app/application.h"
#include "paimon/app/panel/editor_layer.h"
#include "paimon/app/panel/interaction_layer.h"
#include "paimon/core/log_system.h"

#include "renderer.h"

using namespace paimon;

class HelmetApp : public Application {
public:
HelmetApp() : Application() {
// Setup editor layer first
auto* editorLayer = pushLayer(std::make_unique<EditorLayer>());

// Setup interaction layer for camera control
auto* interactionLayer = pushLayer(std::make_unique<InteractionLayer>());

// Setup renderer with the scene and viewport
auto *renderer = pushLayer(std::make_unique<Renderer>());
}
};

int main() {
LogSystem::init();

HelmetApp app;
Application app;
app.run();

return 0;
Expand Down
56 changes: 0 additions & 56 deletions example/damaged_helmet/renderer.cpp

This file was deleted.

10 changes: 9 additions & 1 deletion source/paimon/app/application.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "paimon/app/application.h"

#include "paimon/app/panel/editor_layer.h"
#include "paimon/app/panel/interaction_layer.h"
#include "paimon/config.h"

namespace paimon {
Expand All @@ -17,7 +19,13 @@ Application::Application(const ApplicationConfig& config) {

m_shaderManager.load(PAIMON_SHADER_DIR);

m_imguiLayer = pushLayer(std::make_unique<ImGuiLayer>("ImGuiLayer"));
m_imguiLayer = pushLayer(std::make_unique<ImGuiLayer>());

pushLayer(std::make_unique<EditorLayer>());

pushLayer(std::make_unique<InteractionLayer>());

m_renderer = pushLayer(std::make_unique<Renderer>());
}

void Application::onEvent(Event& event) {
Expand Down
31 changes: 20 additions & 11 deletions source/paimon/app/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "paimon/app/window.h"
#include "paimon/core/ecs/scene.h"
#include "paimon/platform/context.h"
#include "paimon/rendering/renderer.h"
#include "paimon/rendering/shader_manager.h"

namespace paimon {
Expand All @@ -20,13 +21,13 @@ struct ApplicationConfig {

class Application {
public:
static Application& getInstance() { return *s_instance; }
static Application &getInstance() { return *s_instance; }

Application(const ApplicationConfig& config = {});
Application(const ApplicationConfig &config = {});
virtual ~Application() = default;

Application(const Application&) = delete;
Application& operator=(const Application&) = delete;
Application(const Application &) = delete;
Application &operator=(const Application &) = delete;

template <class T>
requires std::is_base_of<Layer, T>::value
Expand All @@ -36,21 +37,28 @@ class Application {
return static_cast<T *>(m_layers.back().get());
}

void onEvent(Event& event);
void onEvent(Event &event);

void run();

Window* getWindow() const { return m_window.get(); }
Window *getWindow() const { return m_window.get(); }

ShaderManager& getShaderManager() { return m_shaderManager; }
const ShaderManager& getShaderManager() const { return m_shaderManager; }
ShaderManager &getShaderManager() { return m_shaderManager; }
const ShaderManager &getShaderManager() const { return m_shaderManager; }

// Scene management
ecs::Scene& getScene() { return *m_scene; }
const ecs::Scene& getScene() const { return *m_scene; }
ecs::Scene &getScene() { return *m_scene; }
const ecs::Scene &getScene() const { return *m_scene; }

void setScene(std::unique_ptr<ecs::Scene> scene) {
m_scene = std::move(scene);
}

Renderer& getRenderer() { return *m_renderer; }
const Renderer& getRenderer() const { return *m_renderer; }

private:
static Application* s_instance;
static Application *s_instance;

std::unique_ptr<Window> m_window;

Expand All @@ -60,6 +68,7 @@ class Application {

std::vector<std::unique_ptr<Layer>> m_layers;
ImGuiLayer *m_imguiLayer;
Renderer *m_renderer;
};

} // namespace paimon
4 changes: 2 additions & 2 deletions source/paimon/app/imgui/imgui_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ using namespace paimon;

bool ImGuiLayer::s_showDockSpace = true;

ImGuiLayer::ImGuiLayer(const std::string &name)
: Layer(name) {}
ImGuiLayer::ImGuiLayer()
: Layer("ImGuiLayer") {}

void ImGuiLayer::onAttach() {

Expand Down
2 changes: 1 addition & 1 deletion source/paimon/app/imgui/imgui_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace paimon {

class ImGuiLayer : public Layer {
public:
ImGuiLayer(const std::string &name);
ImGuiLayer();

~ImGuiLayer() = default;

Expand Down
55 changes: 33 additions & 22 deletions source/paimon/app/panel/viewport_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,69 +14,80 @@ ViewportPanel::ViewportPanel() = default;
ViewportPanel::~ViewportPanel() = default;

void ViewportPanel::onImGuiRender() {
auto &app = Application::getInstance();

ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::Begin("Viewport");

// Get available content region
ImVec2 viewportSize = ImGui::GetContentRegionAvail();


auto textureId =
app.getRenderer().getColorPass().getColorTexture()->get_name();

// Display the texture using ImGui::Image
// Note: OpenGL uses bottom-left origin, so flip UV coordinates
ImGui::Image((ImTextureID)(intptr_t)textureId, viewportSize,
ImVec2(0, 1), // UV top-left (flipped)
ImVec2(1, 0) // UV bottom-right (flipped)
);

// Check if viewport size changed
glm::ivec2 newSize = glm::ivec2(viewportSize.x, viewportSize.y);
if (newSize.x > 0 && newSize.y > 0 && newSize != m_viewportSize) {
m_viewportSize = newSize;

// Dispatch viewport resize event
ViewportResizeEvent event(newSize.x, newSize.y);
Application::getInstance().onEvent(event);
app.onEvent(event);
}

// Handle camera control input when viewport is focused and hovered
if (ImGui::IsWindowFocused() && ImGui::IsWindowHovered()) {
auto& io = ImGui::GetIO();
// Handle camera control input when viewport is hovered
if (ImGui::IsWindowHovered()) {
auto &io = ImGui::GetIO();

// Handle right mouse button (camera rotation)
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
m_isRightButtonPressed = true;
MouseButtonPressedEvent event(MouseCode::Right);
Application::getInstance().onEvent(event);
app.onEvent(event);
}
if (ImGui::IsMouseReleased(ImGuiMouseButton_Right)) {
m_isRightButtonPressed = false;
MouseButtonReleasedEvent event(MouseCode::Right);
Application::getInstance().onEvent(event);
app.onEvent(event);
}

// Handle middle mouse button (camera panning)
if (ImGui::IsMouseClicked(ImGuiMouseButton_Middle)) {
m_isMiddleButtonPressed = true;
MouseButtonPressedEvent event(MouseCode::Middle);
Application::getInstance().onEvent(event);
app.onEvent(event);
}
if (ImGui::IsMouseReleased(ImGuiMouseButton_Middle)) {
m_isMiddleButtonPressed = false;
MouseButtonReleasedEvent event(MouseCode::Middle);
Application::getInstance().onEvent(event);
app.onEvent(event);
}

// Handle mouse movement (only when right or middle button is pressed)
if (m_isRightButtonPressed || m_isMiddleButtonPressed) {
ImVec2 mousePos = ImGui::GetMousePos();
ImVec2 windowPos = ImGui::GetWindowPos();
ImVec2 relativePos = ImVec2(mousePos.x - windowPos.x, mousePos.y - windowPos.y);

ImVec2 relativePos =
ImVec2(mousePos.x - windowPos.x, mousePos.y - windowPos.y);

MouseMovedEvent event(relativePos.x, relativePos.y);
Application::getInstance().onEvent(event);
app.onEvent(event);
}

// Handle mouse scroll (camera zoom)
if (io.MouseWheel != 0.0f) {
MouseScrolledEvent event(0.0f, io.MouseWheel);
Application::getInstance().onEvent(event);
app.onEvent(event);
}
}

// Viewport content will be rendered by Renderer in its onImGuiRender


ImGui::End();
ImGui::PopStyleVar();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "color_pass.h"
#include "paimon/rendering/render_pass/color_pass.h"

#include <glad/gl.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <memory>

#include "paimon/core/ecs/scene.h"
#include "paimon/opengl/buffer.h"
#include "paimon/opengl/sampler.h"
#include "paimon/opengl/texture.h"
#include "paimon/rendering/graphics_pipeline.h"
#include "paimon/rendering/render_context.h"
#include "paimon/core/ecs/scene.h"

namespace paimon {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "final_pass.h"
#include "paimon/rendering/render_pass/final_pass.h"

#include <glad/gl.h>

Expand Down
41 changes: 41 additions & 0 deletions source/paimon/rendering/renderer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include "paimon/rendering/renderer.h"

#include <imgui.h>

#include "paimon/app/application.h"
#include "paimon/app/event/application_event.h"

using namespace paimon;

Renderer::Renderer()
: Layer("Renderer"), m_renderContext(std::make_unique<RenderContext>()),
m_color_pass(*m_renderContext), m_final_pass(*m_renderContext) {}

void Renderer::onAttach() {
// Initialization if needed
}

void Renderer::onUpdate() {
if (m_resolution.x == 0 || m_resolution.y == 0) {
return; // Skip rendering if resolution is zero
}

auto &scene = Application::getInstance().getScene();

// First Pass: Render to FBO
m_color_pass.draw(*m_renderContext, m_resolution, scene);

// Second Pass: Render FBO texture to screen (optional, for debugging)
// m_final_pass.draw(*m_renderContext, *m_color_pass.getColorTexture(),
// m_resolution);
}

void Renderer::onEvent(Event &event) {
EventDispatcher dispatcher(event);
dispatcher.dispatch<ViewportResizeEvent>([this](ViewportResizeEvent &e) {
m_resolution = glm::ivec2(e.getWidth(), e.getHeight());
return false;
});
}

void Renderer::onImGuiRender() {}
Loading
Loading