various little fixes
This commit is contained in:
@@ -3,8 +3,12 @@
|
|||||||
|
|
||||||
#include <open_engine.hpp>
|
#include <open_engine.hpp>
|
||||||
|
|
||||||
|
#include "open_engine/events/mouse_event.hpp"
|
||||||
#include "open_engine/input/input_system.hpp"
|
#include "open_engine/input/input_system.hpp"
|
||||||
|
#include "open_engine/input/mouse_codes.hpp"
|
||||||
#include "open_engine/renderer/render_command.hpp"
|
#include "open_engine/renderer/render_command.hpp"
|
||||||
|
#include "open_engine/renderer/renderer2d.hpp"
|
||||||
|
#include "open_engine/scene/components.hpp"
|
||||||
#include "panels/scene_hierarchy.hpp"
|
#include "panels/scene_hierarchy.hpp"
|
||||||
|
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
@@ -76,6 +80,20 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
editor_camera = EditorCamera(30.0f, 1920.0f/1080.0f, 0.1f, 1000.0f);
|
editor_camera = EditorCamera(30.0f, 1920.0f/1080.0f, 0.1f, 1000.0f);
|
||||||
|
|
||||||
|
/*
|
||||||
|
for (float i = 0; i < 200; i++) {
|
||||||
|
for (float y = 0; y < 200; y++) {
|
||||||
|
Entity entity = scene->CreateEntity("entity");
|
||||||
|
entities.push_back(entity);
|
||||||
|
auto& tc = entity.AddComponents<TransformComponent>();
|
||||||
|
tc.translation = { i / 10, y / 10, 0.0f };
|
||||||
|
tc.scale = { 0.1f, 0.1f, 1.0f };
|
||||||
|
auto& sprite = entity.AddComponents<SpriteRendererComponent>();
|
||||||
|
sprite.color = { i / 100.0f, y / 100.0f, 1.0f, 1.0f };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
scene_hierarchy.SetContext(scene);
|
scene_hierarchy.SetContext(scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,7 +119,7 @@ namespace OpenEngine {
|
|||||||
Renderer2D::ResetStats();
|
Renderer2D::ResetStats();
|
||||||
RenderCommand::SetClearColor({0.11f, 0.11f, 0.15f, 1.0f});
|
RenderCommand::SetClearColor({0.11f, 0.11f, 0.15f, 1.0f});
|
||||||
RenderCommand::Clear();
|
RenderCommand::Clear();
|
||||||
RenderCommand::ClearBufferI(1, -1);
|
framebuffer->ClearBufferI(1, -1);
|
||||||
|
|
||||||
editor_camera.OnUpdate();
|
editor_camera.OnUpdate();
|
||||||
|
|
||||||
@@ -117,10 +135,18 @@ namespace OpenEngine {
|
|||||||
int mouse_x = (int)mx;
|
int mouse_x = (int)mx;
|
||||||
int mouse_y = (int)my;
|
int mouse_y = (int)my;
|
||||||
|
|
||||||
if (mouse_x >= 0 && mouse_y >= 0 && mouse_x < (int)viewport_size.x && (int)viewport_size.y) {
|
static bool clicked = false;
|
||||||
int id = framebuffer->ReadPixel(1, mouse_x, mouse_y);
|
if (Input::IsMouseButtonPressed(MouseCode::ButtonLeft) && mouse_x >= 0 && mouse_y >= 0 && mouse_x < (int)viewport_size.x && (int)viewport_size.y) {
|
||||||
if (Input::IsMouseButtonPressed(Mouse::ButtonLeft) && id != -1)
|
if (!clicked) {
|
||||||
scene_hierarchy.SetSelectedEntity({ (entt::entity)id, scene.get() });
|
int id = framebuffer->ReadPixel(1, mouse_x, mouse_y);
|
||||||
|
|
||||||
|
if (id != -1)
|
||||||
|
scene_hierarchy.SetSelectedEntity({ (entt::entity)id, scene.get() });
|
||||||
|
}
|
||||||
|
|
||||||
|
clicked = true;
|
||||||
|
} else {
|
||||||
|
clicked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
framebuffer->Unbind();
|
framebuffer->Unbind();
|
||||||
@@ -223,24 +249,14 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
viewport_size = { viewport_panel_size.x, viewport_panel_size.y };
|
viewport_size = { viewport_panel_size.x, viewport_panel_size.y };
|
||||||
|
|
||||||
ImVec2 imgui_cursor_position = ImGui::GetCursorPos();
|
ImVec2 imgui_cursor_position = ImGui::GetCursorScreenPos();
|
||||||
|
|
||||||
uint32_t texture_id = framebuffer->GetColorAttachmentRendererID();
|
uint32_t texture_id = framebuffer->GetColorAttachmentRendererID();
|
||||||
ImGui::Image((void*)(uint64_t)texture_id, ImVec2{ viewport_size.x, viewport_size.y }, ImVec2{ 0, 1 }, ImVec2{ 1, 0 });
|
ImGui::Image((void*)(uint64_t)texture_id, ImVec2{ viewport_size.x, viewport_size.y }, ImVec2{ 0, 1 }, ImVec2{ 1, 0 });
|
||||||
|
|
||||||
int max_x = viewport_size.x + imgui_cursor_position.x;
|
viewport_bounds[0] = { imgui_cursor_position.x, imgui_cursor_position.y };
|
||||||
int max_y = viewport_size.y + imgui_cursor_position.y;
|
viewport_bounds[1] = { imgui_cursor_position.x + viewport_size.x,
|
||||||
|
imgui_cursor_position.y + viewport_size.y };
|
||||||
auto window_size = ImGui::GetWindowSize();
|
|
||||||
ImVec2 min_bound = ImGui::GetWindowPos();
|
|
||||||
|
|
||||||
min_bound.x += imgui_cursor_position.x;
|
|
||||||
min_bound.y += imgui_cursor_position.y;
|
|
||||||
|
|
||||||
ImVec2 max_bound = { min_bound.x + window_size.x, min_bound.y + window_size.y };
|
|
||||||
|
|
||||||
viewport_bounds[0] = { min_bound.x, min_bound.y};
|
|
||||||
viewport_bounds[1] = { max_bound.x, max_bound.y};
|
|
||||||
|
|
||||||
DrawGuizmos();
|
DrawGuizmos();
|
||||||
|
|
||||||
@@ -277,9 +293,10 @@ namespace OpenEngine {
|
|||||||
ImGuizmo::SetDrawlist();
|
ImGuizmo::SetDrawlist();
|
||||||
ImGuizmo::Enable(!editor_camera.GetMoving());
|
ImGuizmo::Enable(!editor_camera.GetMoving());
|
||||||
|
|
||||||
auto window_position = ImGui::GetWindowPos();
|
ImGuizmo::SetRect(viewport_bounds[0].x, viewport_bounds[0].y,
|
||||||
auto window_size = ImGui::GetWindowSize();
|
viewport_bounds[1].x - viewport_bounds[0].x,
|
||||||
ImGuizmo::SetRect(window_position.x, window_position.y, window_size.x, window_size.y);
|
viewport_bounds[1].y - viewport_bounds[0].y);
|
||||||
|
|
||||||
|
|
||||||
const glm::mat4& camera_projection = editor_camera.GetProjection();
|
const glm::mat4& camera_projection = editor_camera.GetProjection();
|
||||||
glm::mat4 camera_view = editor_camera.GetViewMatrix();
|
glm::mat4 camera_view = editor_camera.GetViewMatrix();
|
||||||
@@ -379,7 +396,7 @@ namespace OpenEngine {
|
|||||||
int guizmo_operation = -1;
|
int guizmo_operation = -1;
|
||||||
|
|
||||||
Ref<Scene> scene;
|
Ref<Scene> scene;
|
||||||
Entity sq_entity;
|
std::vector<Entity> entities;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
virtual void Resize(uint32_t width, uint32_t height) override;
|
virtual void Resize(uint32_t width, uint32_t height) override;
|
||||||
virtual int ReadPixel(uint32_t index, int x, int y) override;
|
virtual int ReadPixel(uint32_t index, int x, int y) override;
|
||||||
|
virtual void ClearBufferI(int index, int value) override;
|
||||||
|
|
||||||
virtual uint32_t GetColorAttachmentRendererID(uint32_t index = 0) const override {
|
virtual uint32_t GetColorAttachmentRendererID(uint32_t index = 0) const override {
|
||||||
OE_CORE_ASSERT(index < color_attachment_ids.size(), "Index is greater than color attachment count.");
|
OE_CORE_ASSERT(index < color_attachment_ids.size(), "Index is greater than color attachment count.");
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ namespace OpenEngine {
|
|||||||
virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override;
|
virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override;
|
||||||
|
|
||||||
virtual void SetClearColor(const glm::vec4& color) override;
|
virtual void SetClearColor(const glm::vec4& color) override;
|
||||||
virtual void ClearBufferI(int buffer, int value) override;
|
|
||||||
virtual void Clear() override;
|
virtual void Clear() override;
|
||||||
|
|
||||||
virtual void DrawIndexed(const Ref<VertexArray>& vertex_array, uint32_t index_count = 0) override;
|
virtual void DrawIndexed(const Ref<VertexArray>& vertex_array, uint32_t index_count = 0) override;
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
virtual void Resize(uint32_t width, uint32_t height) = 0;
|
virtual void Resize(uint32_t width, uint32_t height) = 0;
|
||||||
virtual int ReadPixel(uint32_t index, int x, int y) = 0;
|
virtual int ReadPixel(uint32_t index, int x, int y) = 0;
|
||||||
|
virtual void ClearBufferI(int index, int value) = 0;
|
||||||
|
|
||||||
virtual uint32_t GetColorAttachmentRendererID(uint32_t index = 0) const = 0;
|
virtual uint32_t GetColorAttachmentRendererID(uint32_t index = 0) const = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -24,11 +24,6 @@ namespace OpenEngine {
|
|||||||
api->SetClearColor(color);
|
api->SetClearColor(color);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline static void ClearBufferI(int buffer, int value)
|
|
||||||
{
|
|
||||||
api->ClearBufferI(buffer, value);
|
|
||||||
};
|
|
||||||
|
|
||||||
inline static void Clear()
|
inline static void Clear()
|
||||||
{
|
{
|
||||||
api->Clear();
|
api->Clear();
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ namespace OpenEngine {
|
|||||||
virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0;
|
virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0;
|
||||||
|
|
||||||
virtual void SetClearColor(const glm::vec4& color) = 0;
|
virtual void SetClearColor(const glm::vec4& color) = 0;
|
||||||
virtual void ClearBufferI(int buffer, int value) = 0;
|
|
||||||
virtual void Clear() = 0;
|
virtual void Clear() = 0;
|
||||||
|
|
||||||
virtual void DrawIndexed(const Ref<VertexArray>& vertex_array, uint32_t count = 0) = 0;
|
virtual void DrawIndexed(const Ref<VertexArray>& vertex_array, uint32_t count = 0) = 0;
|
||||||
|
|||||||
@@ -201,4 +201,8 @@ namespace OpenEngine {
|
|||||||
|
|
||||||
return pixel_data;
|
return pixel_data;
|
||||||
}
|
}
|
||||||
|
void OpenGLFramebuffer::ClearBufferI(int index, int value)
|
||||||
|
{
|
||||||
|
glClearTexImage(color_attachment_ids[index], 0, GL_RED_INTEGER, GL_INT, &value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,11 +57,6 @@ namespace OpenEngine {
|
|||||||
glClearColor(color.r, color.g, color.b, color.a);
|
glClearColor(color.r, color.g, color.b, color.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLRendererAPI::ClearBufferI(int buffer, int value)
|
|
||||||
{
|
|
||||||
glClearBufferiv(GL_COLOR, buffer, &value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OpenGLRendererAPI::Clear()
|
void OpenGLRendererAPI::Clear()
|
||||||
{
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|||||||
@@ -1,5 +1,32 @@
|
|||||||
Scene: N/A
|
Scene: N/A
|
||||||
Entities:
|
Entities:
|
||||||
|
- Entity: 412741205
|
||||||
|
TagComponent:
|
||||||
|
Tag: square 3
|
||||||
|
TransformComponent:
|
||||||
|
Translation: [-1.49011612e-08, 0.299999774, -0.499999911]
|
||||||
|
Rotation: [-1.57079685, 0, 0]
|
||||||
|
Scale: [0.605000019, 0.60496217, 0.60496217]
|
||||||
|
SpriteRendererComponent:
|
||||||
|
Color: [1, 1, 1, 1]
|
||||||
|
- Entity: 412741205
|
||||||
|
TagComponent:
|
||||||
|
Tag: "square 2 "
|
||||||
|
TransformComponent:
|
||||||
|
Translation: [0, 0, -0.200000003]
|
||||||
|
Rotation: [0, 0, 0]
|
||||||
|
Scale: [0.600000024, 0.600000083, 0.600000024]
|
||||||
|
SpriteRendererComponent:
|
||||||
|
Color: [0.882352948, 0.745098054, 0.376470596, 1]
|
||||||
|
- Entity: 412741205
|
||||||
|
TagComponent:
|
||||||
|
Tag: square
|
||||||
|
TransformComponent:
|
||||||
|
Translation: [0.299827427, -9.68575478e-08, -0.499896437]
|
||||||
|
Rotation: [0, 1.57079637, 0]
|
||||||
|
Scale: [0.6049999, 0.604999959, 0.6049999]
|
||||||
|
SpriteRendererComponent:
|
||||||
|
Color: [0.517647088, 0.0901960805, 1, 1]
|
||||||
- Entity: 412741205
|
- Entity: 412741205
|
||||||
TagComponent:
|
TagComponent:
|
||||||
Tag: camera
|
Tag: camera
|
||||||
@@ -18,21 +45,3 @@ Entities:
|
|||||||
OrthographicFar: 1
|
OrthographicFar: 1
|
||||||
Primary: true
|
Primary: true
|
||||||
FixedAspectRatio: false
|
FixedAspectRatio: false
|
||||||
- Entity: 412741205
|
|
||||||
TagComponent:
|
|
||||||
Tag: square
|
|
||||||
TransformComponent:
|
|
||||||
Translation: [0, 1.79999995, 0]
|
|
||||||
Rotation: [0, 0, 0]
|
|
||||||
Scale: [1, 1, 1]
|
|
||||||
SpriteRendererComponent:
|
|
||||||
Color: [0.517647088, 0.0901960805, 1, 1]
|
|
||||||
- Entity: 412741205
|
|
||||||
TagComponent:
|
|
||||||
Tag: "square 2 "
|
|
||||||
TransformComponent:
|
|
||||||
Translation: [0, 0, 0]
|
|
||||||
Rotation: [0, 0, 0]
|
|
||||||
Scale: [1, 1, 1]
|
|
||||||
SpriteRendererComponent:
|
|
||||||
Color: [0.882352948, 0.745098054, 0.376470596, 1]
|
|
||||||
Reference in New Issue
Block a user