Added viewport
This commit is contained in:
parent
6074fdc492
commit
5758f841ed
2
.idea/.name
generated
2
.idea/.name
generated
@ -1 +1 @@
|
||||
CreatePBR
|
||||
Onyx
|
@ -103,6 +103,8 @@ file(GLOB_RECURSE CORE_SOURCES CONFIGURE_DEPENDS
|
||||
add_library(Core STATIC
|
||||
${CORE_SOURCES}
|
||||
src/core/systems/MACROS.h
|
||||
src/core/renderer/Renderer.cpp
|
||||
src/core/renderer/Renderer.h
|
||||
)
|
||||
|
||||
target_include_directories(Core PUBLIC src/core)
|
||||
@ -124,6 +126,8 @@ add_executable(Editor ${APP_SOURCES}
|
||||
src/editor/Editor.h
|
||||
src/editor/Windows/LoggerWindow.cpp
|
||||
src/editor/Windows/LoggerWindow.h
|
||||
src/editor/Windows/Viewport.cpp
|
||||
src/editor/Windows/Viewport.h
|
||||
)
|
||||
|
||||
target_include_directories(Editor PRIVATE
|
||||
|
7
main.cpp
7
main.cpp
@ -8,12 +8,9 @@
|
||||
|
||||
int main()
|
||||
{
|
||||
OX::Core core{};
|
||||
|
||||
constexpr const char* VERSION = "0.1.0"; // Format: 0.<release><commit_count>
|
||||
|
||||
OX::Core core(std::string(OX_ENGINE_VERSION) + " (" + VERSION + ")");
|
||||
|
||||
core.AddLayer(std::make_unique<OX::Editor>("Obsidian Editor"));
|
||||
core.AddLayer(std::make_unique<OX::Editor>(OX_EDITOR_VERSION));
|
||||
|
||||
//core.AddLayer(std::make_unique<OX::DummyLayer>("Dummy Layer"));
|
||||
|
||||
|
@ -33,6 +33,7 @@ namespace OX
|
||||
|
||||
|
||||
for (const auto &layer : m_layers) {
|
||||
|
||||
Logger::LogDebug("Initializing Layer: '%s'", layer->GetName().c_str());
|
||||
layer->Init(*this);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "Layer.h"
|
||||
#include "renderer/Renderer.h"
|
||||
#include "systems/Logger.h"
|
||||
#include "systems/Profiler.h"
|
||||
#include "systems/WindowManager.h"
|
||||
@ -25,6 +26,10 @@ namespace OX
|
||||
{
|
||||
};
|
||||
|
||||
Core() : m_name(OX_ENGINE_VERSION)
|
||||
{
|
||||
};
|
||||
|
||||
~Core() = default;
|
||||
|
||||
void Init();
|
||||
@ -35,7 +40,7 @@ namespace OX
|
||||
|
||||
|
||||
WindowManager &GetWindow() { return window; }
|
||||
|
||||
Renderer &GetRenderer() { return renderer; }
|
||||
|
||||
void AddLayer(std::unique_ptr<Layer> layer);
|
||||
|
||||
@ -47,6 +52,7 @@ namespace OX
|
||||
|
||||
std::vector<std::unique_ptr<Layer> > m_layers;
|
||||
WindowManager window;
|
||||
Renderer renderer;
|
||||
|
||||
bool m_running = false;
|
||||
std::string m_name = "Application";
|
||||
@ -78,8 +84,5 @@ namespace OX
|
||||
Logger::LogDebug("%s Shutdown", m_name.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
#endif // CORE_H
|
||||
|
8
src/core/renderer/Renderer.cpp
Normal file
8
src/core/renderer/Renderer.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
//
|
||||
// Created by spenc on 5/21/2025.
|
||||
//
|
||||
|
||||
#include "Renderer.h"
|
||||
|
||||
namespace OX {
|
||||
} // OX
|
26
src/core/renderer/Renderer.h
Normal file
26
src/core/renderer/Renderer.h
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Created by spenc on 5/21/2025.
|
||||
//
|
||||
|
||||
#ifndef RENDERER_H
|
||||
#define RENDERER_H
|
||||
|
||||
#include "glfw/glfw3.h"
|
||||
#include "glm/glm.hpp"
|
||||
|
||||
namespace OX {
|
||||
|
||||
class Renderer {
|
||||
public:
|
||||
Renderer() = default;
|
||||
~Renderer() = default;
|
||||
|
||||
[[nodiscard]] GLuint GetRenderTarget() const {return m_renderTarget; }
|
||||
|
||||
private:
|
||||
GLuint m_renderTarget;
|
||||
};
|
||||
|
||||
} // OX
|
||||
|
||||
#endif //RENDERER_H
|
@ -7,8 +7,9 @@
|
||||
#include <imgui.h>
|
||||
#include <imgui_impl_opengl3.h>
|
||||
#include <imgui_impl_glfw.h>
|
||||
#include "Windows/LoggerWindow.h"
|
||||
|
||||
#include "Windows/LoggerWindow.h"
|
||||
#include "Windows/Viewport.h"
|
||||
|
||||
namespace OX {
|
||||
|
||||
@ -33,6 +34,8 @@ namespace OX {
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(core.GetWindow().GetHandle(), true);
|
||||
ImGui_ImplOpenGL3_Init("#version 330 core");
|
||||
|
||||
primaryViewport = new Viewport(); // The first time ive ever use the new keywork...
|
||||
}
|
||||
|
||||
void Editor::Update(Core& core)
|
||||
@ -72,6 +75,7 @@ namespace OX {
|
||||
ImGui::DockSpace(dockspaceID, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_PassthruCentralNode);
|
||||
|
||||
LoggerWindow::Draw();
|
||||
primaryViewport->Draw(core);
|
||||
|
||||
|
||||
ImGui::Begin("Profiler");
|
||||
@ -127,6 +131,11 @@ namespace OX {
|
||||
|
||||
void Editor::Shutdown(Core& core)
|
||||
{
|
||||
|
||||
delete primaryViewport;
|
||||
primaryViewport = nullptr;
|
||||
|
||||
|
||||
Logger::LogOk("Editor::Shutdown");
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
|
@ -4,24 +4,31 @@
|
||||
|
||||
#ifndef EDITOR_H
|
||||
#define EDITOR_H
|
||||
#define OX_EDITOR_VERSION "Obsidian Editor (0.3.2)"
|
||||
#include "Layer.h"
|
||||
#include "Core.h"
|
||||
namespace OX {
|
||||
|
||||
|
||||
namespace OX
|
||||
{
|
||||
class Viewport;
|
||||
|
||||
class Editor final : public Layer {
|
||||
public:
|
||||
using Layer::Layer;
|
||||
class Editor final : public Layer
|
||||
{
|
||||
public:
|
||||
using Layer::Layer;
|
||||
|
||||
void Init(Core& core) override;
|
||||
void Update(Core& core) override;
|
||||
void Draw(Core& core) override;
|
||||
void Shutdown(Core& core) override;
|
||||
};
|
||||
void Init(Core &core) override;
|
||||
|
||||
void Update(Core &core) override;
|
||||
|
||||
void Draw(Core &core) override;
|
||||
|
||||
void Shutdown(Core &core) override;
|
||||
|
||||
private:
|
||||
Viewport* primaryViewport;
|
||||
};
|
||||
} // OX
|
||||
|
||||
#endif //EDITOR_H
|
||||
|
37
src/editor/Windows/Viewport.cpp
Normal file
37
src/editor/Windows/Viewport.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
//
|
||||
// Created by spenc on 5/21/2025.
|
||||
//
|
||||
|
||||
#include "Viewport.h"
|
||||
#include <imgui.h>
|
||||
|
||||
namespace OX
|
||||
{
|
||||
int Viewport::s_nextID = 0;
|
||||
|
||||
void Viewport::Draw(Core &core) const
|
||||
{
|
||||
// Construct title
|
||||
std::string title = m_name + " (" + std::to_string(m_id) + ")";
|
||||
|
||||
// Remove window padding
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
|
||||
|
||||
// Begin full viewport window
|
||||
ImGui::Begin(title.c_str(), nullptr, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
|
||||
|
||||
// Get size of available region
|
||||
ImVec2 viewportSize = ImGui::GetContentRegionAvail();
|
||||
|
||||
// === Fullscreen image ===
|
||||
GLuint textureID = core.GetRenderer().GetRenderTarget(); // You must define this method
|
||||
if (textureID != 0) {
|
||||
ImGui::Image(textureID, viewportSize, ImVec2(0, 1), ImVec2(1, 0));
|
||||
} else {
|
||||
ImGui::Text("No Render Target.");
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar(); // Restore padding
|
||||
}
|
||||
};
|
36
src/editor/Windows/Viewport.h
Normal file
36
src/editor/Windows/Viewport.h
Normal file
@ -0,0 +1,36 @@
|
||||
//
|
||||
// Created by spenc on 5/21/2025.
|
||||
//
|
||||
|
||||
#ifndef VIEWPORT_H
|
||||
#define VIEWPORT_H
|
||||
|
||||
#include <string>
|
||||
#include "Core.h"
|
||||
|
||||
namespace OX
|
||||
{
|
||||
class Viewport
|
||||
{
|
||||
public:
|
||||
explicit Viewport(std::string name = "Viewport")
|
||||
: m_name(std::move(name))
|
||||
{
|
||||
m_id = s_nextID++;
|
||||
}
|
||||
|
||||
void Draw(Core& core) const;
|
||||
|
||||
[[nodiscard]] int GetID() const { return m_id; }
|
||||
[[nodiscard]] const std::string& GetName() const { return m_name; }
|
||||
|
||||
private:
|
||||
int m_id;
|
||||
std::string m_name;
|
||||
|
||||
static int s_nextID;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user