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
2 changes: 1 addition & 1 deletion example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function(add_example FOLDER_NAME)
file(GLOB_RECURSE SOURCE_FILES ${FOLDER_NAME}/*.cpp ${FOLDER_NAME}/*.h)
add_executable(${EXAMPLE_NAME} ${SOURCE_FILES})
target_link_libraries(${EXAMPLE_NAME} PRIVATE paimon)
target_include_directories(${EXAMPLE_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/${FOLDER_NAME})

# Set output directory to the example's folder
set_target_properties(${EXAMPLE_NAME} PROPERTIES
Expand All @@ -40,7 +41,6 @@ function(add_example FOLDER_NAME)
copy_example_assets(${FOLDER_NAME})
endfunction()

add_example(application)
add_example(compute_shader)
add_example(context)
add_example(damaged_helmet)
Expand Down
4 changes: 0 additions & 4 deletions example/application/asset/model/test.obj

This file was deleted.

6 changes: 0 additions & 6 deletions example/application/asset/shader/test.glsl

This file was deleted.

111 changes: 0 additions & 111 deletions example/application/main.cpp

This file was deleted.

8 changes: 4 additions & 4 deletions example/damaged_helmet/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#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"
Expand All @@ -17,15 +18,14 @@ using namespace paimon;
class HelmetApp : public Application {
public:
HelmetApp() : Application() {
// Get default scene from application
auto* scene = getScene();

// 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>());
renderer->setViewportPanel(&editorLayer->getViewportPanel());
}
};

Expand Down
43 changes: 30 additions & 13 deletions example/damaged_helmet/renderer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "renderer.h"

#include <imgui.h>

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

using namespace paimon;

Expand All @@ -10,30 +12,45 @@ Renderer::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() {
auto* scene = Application::getInstance().getScene();
if (!scene) return;
auto& scene = Application::getInstance().getScene();

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

// Set the rendered texture to viewport
if (m_viewportPanel) {
m_viewportPanel->setTexture(m_color_pass.getColorTexture());
}

// 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) {
return onViewportResize(e);
m_resolution = glm::ivec2(e.getWidth(), e.getHeight());
return false;
});
}

bool Renderer::onViewportResize(const ViewportResizeEvent& event) {
m_resolution = glm::ivec2(event.getWidth(), event.getHeight());
return false; // Allow other layers to handle this event too
void Renderer::onImGuiRender() {
// Get the Viewport window and draw the rendered texture
if (ImGui::Begin("Viewport")) {
ImVec2 viewportSize = ImGui::GetContentRegionAvail();

if (viewportSize.x > 0 && viewportSize.y > 0) {
GLuint textureId = m_color_pass.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)
);
}
}
ImGui::End();
}
15 changes: 2 additions & 13 deletions example/damaged_helmet/renderer.h
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
#pragma once

#include "paimon/app/layer.h"
#include "paimon/app/event/application_event.h"
#include "paimon/rendering/render_context.h"

#include "color_pass.h"
#include "final_pass.h"

namespace paimon {

class ViewportPanel;

class Renderer : public Layer {
public:
Renderer();

void onAttach() override {}
void onAttach() override;
void onDetach() override {}
void onUpdate() override;
void onEvent(Event &event) override;
void onImGuiRender() override {}

void setViewportPanel(ViewportPanel* viewport) { m_viewportPanel = viewport; }

private:
bool onViewportResize(const ViewportResizeEvent& event);

void onImGuiRender() override;
private:
std::unique_ptr<RenderContext> m_renderContext;

ViewportPanel* m_viewportPanel = nullptr;

glm::ivec2 m_resolution;

ColorPass m_color_pass;
Expand Down
42 changes: 3 additions & 39 deletions source/paimon/app/application.cpp
Original file line number Diff line number Diff line change
@@ -1,48 +1,26 @@
#include "paimon/app/application.h"

#include "paimon/app/application.h"
#include "paimon/app/event/application_event.h"
#include "paimon/app/event/event.h"
#include "paimon/app/window.h"
#include "paimon/config.h"
#include "paimon/core/ecs/scene.h"

namespace paimon {

Application* Application::s_instance = nullptr;

Application::Application(const ApplicationConfig& config) : m_running(false) {
Application::Application(const ApplicationConfig& config) {

s_instance = this;

// Create window
m_window = Window::create(config.windowConfig, config.contextFormat);

// Set event callback
m_window->setEventCallback([this](Event& event) {
onEvent(event);
});
m_scene = ecs::Scene::create();

m_shaderManager.load(PAIMON_SHADER_DIR);

// Create default empty scene
m_scene = std::make_unique<ecs::Scene>();

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

m_running = true;
}

void Application::onEvent(Event& event) {
// Handle application-level events
EventDispatcher dispatcher(event);
dispatcher.dispatch<WindowCloseEvent>([this](WindowCloseEvent& e) {
return onWindowClose(e);
});
dispatcher.dispatch<WindowResizeEvent>([this](WindowResizeEvent& e) {
return onWindowResize(e);
});

// Dispatch to layers
for (auto& layer : m_layers) {
layer->onEvent(event);
Expand All @@ -51,7 +29,7 @@ void Application::onEvent(Event& event) {
}

void Application::run() {
while (m_running) {
while (!m_window->shouldClose()) {

// Poll events
m_window->pollEvents();
Expand All @@ -73,18 +51,4 @@ void Application::run() {
}
}

bool Application::onWindowClose(const WindowCloseEvent& event) {
m_running = false;
return true;
}

bool Application::onWindowResize(const WindowResizeEvent& event) {

// for (auto& layer : m_layers) {
// layer->onResize(event.getWidth(), event.getHeight());
// }

return true;
}

} // namespace paimon
14 changes: 4 additions & 10 deletions source/paimon/app/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <memory>
#include <vector>

#include "paimon/app/event/application_event.h"
#include "paimon/app/event/event.h"
#include "paimon/app/imgui/imgui_layer.h"
#include "paimon/app/layer.h"
Expand Down Expand Up @@ -47,25 +46,20 @@ class Application {
const ShaderManager& getShaderManager() const { return m_shaderManager; }

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

private:
bool onWindowClose(const WindowCloseEvent& event);
bool onWindowResize(const WindowResizeEvent& event);
ecs::Scene& getScene() { return *m_scene; }
const ecs::Scene& getScene() const { return *m_scene; }

private:
static Application* s_instance;

std::unique_ptr<Window> m_window;

std::unique_ptr<ecs::Scene> m_scene;

ShaderManager m_shaderManager;

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

std::unique_ptr<ecs::Scene> m_scene;

bool m_running;
};

} // namespace paimon
Loading
Loading