add custom Ref and RefCounded to replace shared_ptr
This commit is contained in:
@ -28,14 +28,13 @@ namespace Prism
|
||||
return result;
|
||||
}
|
||||
|
||||
void Property(const std::string& name, float& value, float min = -1.0f, float max = 1.0f,
|
||||
PropertyFlag flags = PropertyFlag::None)
|
||||
void Property(const std::string& name, float& value, const float min = -1.0f, const float max = 1.0f, PropertyFlag flags = PropertyFlag::None)
|
||||
{
|
||||
ImGui::Text(name.c_str());
|
||||
ImGui::NextColumn();
|
||||
ImGui::PushItemWidth(-1);
|
||||
|
||||
std::string id = "##" + name;
|
||||
const std::string id = "##" + name;
|
||||
ImGui::SliderFloat(id.c_str(), &value, min, max);
|
||||
|
||||
ImGui::PopItemWidth();
|
||||
@ -43,8 +42,7 @@ namespace Prism
|
||||
}
|
||||
|
||||
|
||||
void Property(const std::string& name, glm::vec3& value, float min = -1.0f, float max = 1.0f,
|
||||
PropertyFlag flags = PropertyFlag::None)
|
||||
void Property(const std::string& name, glm::vec3& value, const float min = -1.0f, const float max = 1.0f, PropertyFlag flags = PropertyFlag::None)
|
||||
{
|
||||
ImGui::Text(name.c_str());
|
||||
ImGui::NextColumn();
|
||||
@ -66,8 +64,7 @@ namespace Prism
|
||||
}
|
||||
|
||||
|
||||
void Property(const std::string& name, glm::vec4& value, float min = -1.0f, float max = 1.0f,
|
||||
PropertyFlag flags = PropertyFlag::None)
|
||||
void Property(const std::string& name, glm::vec4& value, const float min = -1.0f, const float max = 1.0f, PropertyFlag flags = PropertyFlag::None)
|
||||
{
|
||||
ImGui::Text(name.c_str());
|
||||
ImGui::NextColumn();
|
||||
@ -83,26 +80,26 @@ namespace Prism
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
|
||||
void Property(const std::string& name, glm::vec4& value, PropertyFlag flags)
|
||||
void Property(const std::string& name, glm::vec4& value, const PropertyFlag flags)
|
||||
{
|
||||
Property(name, value, -1.0f, 1.0f, flags);
|
||||
}
|
||||
|
||||
|
||||
void Property(const std::string& name, glm::vec2& value, float min, float max, PropertyFlag flags)
|
||||
void Property(const std::string& name, glm::vec2& value, const float min, const float max, PropertyFlag flags)
|
||||
{
|
||||
ImGui::Text(name.c_str());
|
||||
ImGui::NextColumn();
|
||||
ImGui::PushItemWidth(-1);
|
||||
|
||||
std::string id = "##" + name;
|
||||
const std::string id = "##" + name;
|
||||
ImGui::SliderFloat2(id.c_str(), glm::value_ptr(value), min, max);
|
||||
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::NextColumn();
|
||||
}
|
||||
|
||||
void Property(const std::string& name, glm::vec2& value, PropertyFlag flags)
|
||||
void Property(const std::string& name, glm::vec2& value, const PropertyFlag flags)
|
||||
{
|
||||
Property(name, value, -1.0f, 1.0f, flags);
|
||||
}
|
||||
@ -136,31 +133,31 @@ namespace Prism
|
||||
|
||||
// Model Scene
|
||||
{
|
||||
m_Scene = CreateRef<Scene>("Model Scene");
|
||||
m_Scene = Ref<Scene>::Create("Model Scene");
|
||||
m_Scene->SetCamera(Camera(glm::perspectiveFov(glm::radians(45.0f), 1280.0f, 720.0f, 0.1f, 10000.0f)));
|
||||
|
||||
m_Scene->SetEnvironment(environment);
|
||||
|
||||
m_MeshEntity = m_Scene->CreateEntity("test Entity");
|
||||
auto mesh = CreateRef<Mesh>("assets/meshes/TestScene.fbx");
|
||||
auto mesh = Ref<Mesh>::Create("assets/meshes/TestScene.fbx");
|
||||
m_MeshEntity->SetMesh(mesh);
|
||||
|
||||
m_MeshMaterial = mesh->GetMaterial();
|
||||
|
||||
auto secondEntity = m_Scene->CreateEntity("Gun Entity");
|
||||
secondEntity->Transform() = glm::translate(glm::mat4(1.0f), { 5, 5, 5 }) * glm::scale(glm::mat4(1.0f), {10, 10, 10});
|
||||
mesh = CreateRef<Mesh>("assets/models/m1911/M1911Materials.fbx");
|
||||
mesh = Ref<Mesh>::Create("assets/models/m1911/M1911Materials.fbx");
|
||||
secondEntity->SetMesh(mesh);
|
||||
}
|
||||
|
||||
// Sphere Scene
|
||||
{
|
||||
m_SphereScene = CreateRef<Scene>("PBR Sphere Scene");
|
||||
m_SphereScene = Ref<Scene>::Create("PBR Sphere Scene");
|
||||
m_SphereScene->SetCamera(Camera(glm::perspectiveFov(glm::radians(45.0f), 1280.0f, 720.0f, 0.1f, 10000.0f)));
|
||||
|
||||
m_SphereScene->SetEnvironment(environment);
|
||||
|
||||
auto sphereMesh = CreateRef<Mesh>("assets/models/Sphere1m.fbx");
|
||||
auto sphereMesh = Ref<Mesh>::Create("assets/models/Sphere1m.fbx");
|
||||
m_SphereBaseMaterial = sphereMesh->GetMaterial();
|
||||
|
||||
float x = -4.0f;
|
||||
@ -169,7 +166,7 @@ namespace Prism
|
||||
{
|
||||
auto sphereEntity = m_SphereScene->CreateEntity();
|
||||
|
||||
Ref<MaterialInstance> mi = CreateRef<MaterialInstance>(m_SphereBaseMaterial);
|
||||
Ref<MaterialInstance> mi = Ref<MaterialInstance>::Create(m_SphereBaseMaterial);
|
||||
mi->Set("u_Metalness", 1.0f);
|
||||
mi->Set("u_Roughness", roughness);
|
||||
x += 1.1f;
|
||||
@ -203,7 +200,7 @@ namespace Prism
|
||||
m_ActiveScene = m_Scene;
|
||||
m_SceneHierarchyPanel = CreateScope<SceneHierarchyPanel>(m_ActiveScene);
|
||||
|
||||
m_PlaneMesh.reset(new Mesh("assets/models/Plane1m.obj"));
|
||||
m_PlaneMesh = Ref<Mesh>::Create("assets/models/Plane1m.obj");
|
||||
|
||||
// Editor
|
||||
m_CheckerboardTex = Texture2D::Create("assets/editor/Checkerboard.tga");
|
||||
@ -487,7 +484,7 @@ namespace Prism
|
||||
std::string filename = Application::Get().OpenFile("");
|
||||
if (!filename.empty())
|
||||
{
|
||||
auto newMesh = CreateRef<Mesh>(filename);
|
||||
auto newMesh = Ref<Mesh>::Create(filename);
|
||||
// m_MeshMaterial.reset(new MaterialInstance(newMesh->GetMaterial()));
|
||||
// m_MeshEntity->SetMaterial(m_MeshMaterial);
|
||||
m_MeshEntity->SetMesh(newMesh);
|
||||
@ -757,7 +754,7 @@ namespace Prism
|
||||
auto [origin, direction] = CastRay(mouseX, mouseY);
|
||||
|
||||
m_SelectedSubmeshes.clear();
|
||||
const auto mesh = m_MeshEntity->GetMesh();
|
||||
auto mesh = m_MeshEntity->GetMesh();
|
||||
auto& submeshes = mesh->GetSubmeshes();
|
||||
float lastT = std::numeric_limits<float>::max();
|
||||
for (uint32_t i = 0; i < submeshes.size(); i++)
|
||||
@ -769,7 +766,7 @@ namespace Prism
|
||||
};
|
||||
|
||||
float t;
|
||||
bool intersects = ray.IntersectsAABB(submesh.BoundingBox, t);
|
||||
const bool intersects = ray.IntersectsAABB(submesh.BoundingBox, t);
|
||||
if (intersects)
|
||||
{
|
||||
const auto& triangleCache = mesh->GetTriangleCache(i);
|
||||
@ -814,9 +811,9 @@ namespace Prism
|
||||
return { (mx / viewportWidth) * 2.0f - 1.0f, ((my / viewportHeight) * 2.0f - 1.0f) * -1.0f };
|
||||
}
|
||||
|
||||
std::pair<glm::vec3, glm::vec3> EditorLayer::CastRay(const float mx, const float my) const
|
||||
std::pair<glm::vec3, glm::vec3> EditorLayer::CastRay(const float mx, const float my)
|
||||
{
|
||||
glm::vec4 mouseClipPos = { mx, my, -1.0f, 1.0f };
|
||||
const glm::vec4 mouseClipPos = { mx, my, -1.0f, 1.0f };
|
||||
|
||||
const auto inverseProj = glm::inverse(m_Scene->GetCamera().GetProjectionMatrix());
|
||||
const auto inverseView = glm::inverse(glm::mat3(m_Scene->GetCamera().GetViewMatrix()));
|
||||
|
||||
@ -30,7 +30,7 @@ namespace Prism
|
||||
|
||||
private:
|
||||
std::pair<float, float> GetMouseViewportSpace() const;
|
||||
std::pair<glm::vec3, glm::vec3> CastRay(float mx, float my) const;
|
||||
std::pair<glm::vec3, glm::vec3> CastRay(float mx, float my);
|
||||
|
||||
private:
|
||||
Scope<SceneHierarchyPanel> m_SceneHierarchyPanel;
|
||||
@ -51,7 +51,7 @@ namespace Prism
|
||||
|
||||
|
||||
// Imguizmo
|
||||
glm::vec2 m_ViewportBounds[2];
|
||||
glm::vec2 m_ViewportBounds[2] = {};
|
||||
int m_GizmoType = -1; // -1 = no gizmo
|
||||
float m_SnapValue = 0.5f;
|
||||
|
||||
|
||||
@ -7,10 +7,8 @@
|
||||
|
||||
#include "glad/glad.h"
|
||||
#include "Prism/Renderer/Renderer.h"
|
||||
#include "Log.h"
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "Prism/Renderer/FrameBuffer.h"
|
||||
#include "Prism/Renderer/RendererAPI.h"
|
||||
|
||||
#include "tinyfiledialogs.h"
|
||||
|
||||
@ -194,10 +192,7 @@ namespace Prism
|
||||
Renderer::Submit([=]() { glViewport(0, 0, width, height); });
|
||||
auto& fbs = FrameBufferPool::GetGlobal()->GetAll();
|
||||
for (auto& fb : fbs)
|
||||
{
|
||||
if (const auto fbp = fb.lock())
|
||||
fbp->Resize(width, height);
|
||||
}
|
||||
fb->Resize(width, height);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -68,6 +68,7 @@ namespace Prism
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
template<typename T>
|
||||
using Ref = std::shared_ptr<T>;
|
||||
|
||||
@ -76,6 +77,7 @@ namespace Prism
|
||||
{
|
||||
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
#endif //CORE_H
|
||||
|
||||
@ -48,7 +48,8 @@ virtual const char* GetName() const override { return #type; }
|
||||
{
|
||||
friend class EventDispatcher;
|
||||
public:
|
||||
bool Handled = false;
|
||||
virtual ~Event() = default;
|
||||
bool Handled = false;
|
||||
|
||||
virtual EventType GetEventType() const = 0;
|
||||
virtual const char* GetName() const = 0;
|
||||
|
||||
@ -7,26 +7,27 @@
|
||||
|
||||
#include "Event.h"
|
||||
#include "KeyEvent.h"
|
||||
#include "Prism/Core/KeyCodes.h"
|
||||
|
||||
namespace Prism {
|
||||
|
||||
class PRISM_API KeyEvent : public Event
|
||||
{
|
||||
public:
|
||||
inline int GetKeyCode() const { return m_KeyCode; }
|
||||
inline KeyCode GetKeyCode() const { return m_KeyCode; }
|
||||
|
||||
EVENT_CLASS_CATEGORY(EventCategoryKeyboard | EventCategoryInput)
|
||||
protected:
|
||||
KeyEvent(const int keycode)
|
||||
KeyEvent(const KeyCode keycode)
|
||||
: m_KeyCode(keycode) {}
|
||||
|
||||
int m_KeyCode;
|
||||
KeyCode m_KeyCode;
|
||||
};
|
||||
|
||||
class PRISM_API KeyPressedEvent : public KeyEvent
|
||||
{
|
||||
public:
|
||||
KeyPressedEvent(const int keycode, const int repeatCount)
|
||||
KeyPressedEvent(const KeyCode keycode, const int repeatCount)
|
||||
: KeyEvent(keycode), m_RepeatCount(repeatCount) {}
|
||||
|
||||
inline int GetRepeatCount() const { return m_RepeatCount; }
|
||||
@ -46,7 +47,7 @@ namespace Prism {
|
||||
class PRISM_API KeyReleasedEvent : public KeyEvent
|
||||
{
|
||||
public:
|
||||
KeyReleasedEvent(const int keycode)
|
||||
KeyReleasedEvent(const KeyCode keycode)
|
||||
: KeyEvent(keycode) {}
|
||||
|
||||
std::string ToString() const override
|
||||
@ -62,7 +63,7 @@ namespace Prism {
|
||||
class PRISM_API KeyTypedEvent : public KeyEvent
|
||||
{
|
||||
public:
|
||||
KeyTypedEvent(const int keycode)
|
||||
KeyTypedEvent(const KeyCode keycode)
|
||||
: KeyEvent(keycode) {}
|
||||
|
||||
std::string ToString() const override
|
||||
|
||||
@ -5,12 +5,14 @@
|
||||
#ifndef INPUT_H
|
||||
#define INPUT_H
|
||||
|
||||
#include "KeyCodes.h"
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
class PRISM_API Input
|
||||
{
|
||||
public:
|
||||
static bool IsKeyPressed(int keycode);
|
||||
static bool IsKeyPressed(KeyCode keycode);
|
||||
|
||||
static bool IsMouseButtonPressed(int button);
|
||||
static float GetMouseX();
|
||||
|
||||
@ -5,131 +5,267 @@
|
||||
#ifndef KEYCODES_H
|
||||
#define KEYCODES_H
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
typedef enum class KeyCode : uint16_t
|
||||
{
|
||||
SPACE = 32,
|
||||
APOSTROPHE = 39, /* ' */
|
||||
COMMA = 44, /* , */
|
||||
MINUS = 45, /* - */
|
||||
PERIOD = 46, /* . */
|
||||
SLASH = 47, /* / */
|
||||
NUM0 = 48,
|
||||
NUM1 = 49,
|
||||
NUM2 = 50,
|
||||
NUM3 = 51,
|
||||
NUM4 = 52,
|
||||
NUM5 = 53,
|
||||
NUM6 = 54,
|
||||
NUM7 = 55,
|
||||
NUM8 = 56,
|
||||
NUM9 = 57,
|
||||
SEMICOLON = 59, /* ; */
|
||||
EQUAL = 61, /* = */
|
||||
A = 65,
|
||||
B = 66,
|
||||
C = 67,
|
||||
D = 68,
|
||||
E = 69,
|
||||
F = 70,
|
||||
G = 71,
|
||||
H = 72,
|
||||
I = 73,
|
||||
J = 74,
|
||||
K = 75,
|
||||
L = 76,
|
||||
M = 77,
|
||||
N = 78,
|
||||
O = 79,
|
||||
P = 80,
|
||||
Q = 81,
|
||||
R = 82,
|
||||
S = 83,
|
||||
T = 84,
|
||||
U = 85,
|
||||
V = 86,
|
||||
W = 87,
|
||||
X = 88,
|
||||
Y = 89,
|
||||
Z = 90,
|
||||
LEFT_BRACKET = 91, /* [ */
|
||||
BACKSLASH = 92, /* \ */
|
||||
RIGHT_BRACKET = 93, /* ] */
|
||||
GRAVE_ACCENT = 96, /* ` */
|
||||
WORLD_1 = 161, /* non-US #1 */
|
||||
WORLD_2 = 162, /* non-US #2 */
|
||||
|
||||
ESCAPE = 256,
|
||||
ENTER = 257,
|
||||
TAB = 258,
|
||||
BACKSPACE = 259,
|
||||
INSERT = 260,
|
||||
DELETE = 261,
|
||||
RIGHT = 262,
|
||||
LEFT = 263,
|
||||
DOWN = 264,
|
||||
UP = 265,
|
||||
PAGE_UP = 266,
|
||||
PAGE_DOWN = 267,
|
||||
HOME = 268,
|
||||
END = 269,
|
||||
CAPS_LOCK = 280,
|
||||
SCROLL_LOCK = 281,
|
||||
NUM_LOCK = 282,
|
||||
PRINT_SCREEN = 283,
|
||||
PAUSE = 284,
|
||||
F1 = 290,
|
||||
F2 = 291,
|
||||
F3 = 292,
|
||||
F4 = 293,
|
||||
F5 = 294,
|
||||
F6 = 295,
|
||||
F7 = 296,
|
||||
F8 = 297,
|
||||
F9 = 298,
|
||||
F10 = 299,
|
||||
F11 = 300,
|
||||
F12 = 301,
|
||||
F13 = 302,
|
||||
F14 = 303,
|
||||
F15 = 304,
|
||||
F16 = 305,
|
||||
F17 = 306,
|
||||
F18 = 307,
|
||||
F19 = 308,
|
||||
F20 = 309,
|
||||
F21 = 310,
|
||||
F22 = 311,
|
||||
F23 = 312,
|
||||
F24 = 313,
|
||||
F25 = 314,
|
||||
KP_0 = 320,
|
||||
KP_1 = 321,
|
||||
KP_2 = 322,
|
||||
KP_3 = 323,
|
||||
KP_4 = 324,
|
||||
KP_5 = 325,
|
||||
KP_6 = 326,
|
||||
KP_7 = 327,
|
||||
KP_8 = 328,
|
||||
KP_9 = 329,
|
||||
KP_DECIMAL = 330,
|
||||
KP_DIVIDE = 331,
|
||||
KP_MULTIPLY = 332,
|
||||
KP_SUBTRACT = 333,
|
||||
KP_ADD = 334,
|
||||
KP_ENTER = 335,
|
||||
KP_EQUAL = 336,
|
||||
LEFT_SHIFT = 340,
|
||||
LEFT_CONTROL = 341,
|
||||
LEFT_ALT = 342,
|
||||
LEFT_SUPER = 343,
|
||||
RIGHT_SHIFT = 344,
|
||||
RIGHT_CONTROL = 345,
|
||||
RIGHT_ALT = 346,
|
||||
RIGHT_SUPER = 347,
|
||||
MENU = 348,
|
||||
} Key;
|
||||
|
||||
inline std::ostream& operator<<(std::ostream& os, KeyCode keyCode)
|
||||
{
|
||||
os << static_cast<int32_t>(keyCode);
|
||||
return os;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// From glfw3.h
|
||||
#define PM_KEY_SPACE 32
|
||||
#define PM_KEY_APOSTROPHE 39 /* ' */
|
||||
#define PM_KEY_COMMA 44 /* , */
|
||||
#define PM_KEY_MINUS 45 /* - */
|
||||
#define PM_KEY_PERIOD 46 /* . */
|
||||
#define PM_KEY_SLASH 47 /* / */
|
||||
#define PM_KEY_0 48
|
||||
#define PM_KEY_1 49
|
||||
#define PM_KEY_2 50
|
||||
#define PM_KEY_3 51
|
||||
#define PM_KEY_4 52
|
||||
#define PM_KEY_5 53
|
||||
#define PM_KEY_6 54
|
||||
#define PM_KEY_7 55
|
||||
#define PM_KEY_8 56
|
||||
#define PM_KEY_9 57
|
||||
#define PM_KEY_SEMICOLON 59 /* ; */
|
||||
#define PM_KEY_EQUAL 61 /* = */
|
||||
#define PM_KEY_A 65
|
||||
#define PM_KEY_B 66
|
||||
#define PM_KEY_C 67
|
||||
#define PM_KEY_D 68
|
||||
#define PM_KEY_E 69
|
||||
#define PM_KEY_F 70
|
||||
#define PM_KEY_G 71
|
||||
#define PM_KEY_H 72
|
||||
#define PM_KEY_I 73
|
||||
#define PM_KEY_J 74
|
||||
#define PM_KEY_K 75
|
||||
#define PM_KEY_L 76
|
||||
#define PM_KEY_M 77
|
||||
#define PM_KEY_N 78
|
||||
#define PM_KEY_O 79
|
||||
#define PM_KEY_P 80
|
||||
#define PM_KEY_Q 81
|
||||
#define PM_KEY_R 82
|
||||
#define PM_KEY_S 83
|
||||
#define PM_KEY_T 84
|
||||
#define PM_KEY_U 85
|
||||
#define PM_KEY_V 86
|
||||
#define PM_KEY_W 87
|
||||
#define PM_KEY_X 88
|
||||
#define PM_KEY_Y 89
|
||||
#define PM_KEY_Z 90
|
||||
#define PM_KEY_LEFT_BRACKET 91 /* [ */
|
||||
#define PM_KEY_BACKSLASH 92 /* \ */
|
||||
#define PM_KEY_RIGHT_BRACKET 93 /* ] */
|
||||
#define PM_KEY_GRAVE_ACCENT 96 /* ` */
|
||||
#define PM_KEY_WORLD_1 161 /* non-US #1 */
|
||||
#define PM_KEY_WORLD_2 162 /* non-US #2 */
|
||||
#define PM_KEY_SPACE ::Prism::Key::SPACE
|
||||
#define PM_KEY_APOSTROPHE ::Prism::Key::APOSTROPHE /* ' */
|
||||
#define PM_KEY_COMMA ::Prism::Key::COMMA /* , */
|
||||
#define PM_KEY_MINUS ::Prism::Key::MINUS /* - */
|
||||
#define PM_KEY_PERIOD ::Prism::Key::PERIOD /* . */
|
||||
#define PM_KEY_SLASH ::Prism::Key::SLASH /* / */
|
||||
#define PM_KEY_0 ::Prism::Key::NUM0
|
||||
#define PM_KEY_1 ::Prism::Key::NUM1
|
||||
#define PM_KEY_2 ::Prism::Key::NUM2
|
||||
#define PM_KEY_3 ::Prism::Key::NUM3
|
||||
#define PM_KEY_4 ::Prism::Key::NUM4
|
||||
#define PM_KEY_5 ::Prism::Key::NUM5
|
||||
#define PM_KEY_6 ::Prism::Key::NUM6
|
||||
#define PM_KEY_7 ::Prism::Key::NUM7
|
||||
#define PM_KEY_8 ::Prism::Key::NUM8
|
||||
#define PM_KEY_9 ::Prism::Key::NUM9
|
||||
#define PM_KEY_SEMICOLON ::Prism::Key::SEMICOLON /* ; */
|
||||
#define PM_KEY_EQUAL ::Prism::Key::EQUAL /* = */
|
||||
#define PM_KEY_A ::Prism::Key::A
|
||||
#define PM_KEY_B ::Prism::Key::B
|
||||
#define PM_KEY_C ::Prism::Key::C
|
||||
#define PM_KEY_D ::Prism::Key::D
|
||||
#define PM_KEY_E ::Prism::Key::E
|
||||
#define PM_KEY_F ::Prism::Key::F
|
||||
#define PM_KEY_G ::Prism::Key::G
|
||||
#define PM_KEY_H ::Prism::Key::H
|
||||
#define PM_KEY_I ::Prism::Key::I
|
||||
#define PM_KEY_J ::Prism::Key::J
|
||||
#define PM_KEY_K ::Prism::Key::K
|
||||
#define PM_KEY_L ::Prism::Key::L
|
||||
#define PM_KEY_M ::Prism::Key::M
|
||||
#define PM_KEY_N ::Prism::Key::N
|
||||
#define PM_KEY_O ::Prism::Key::O
|
||||
#define PM_KEY_P ::Prism::Key::P
|
||||
#define PM_KEY_Q ::Prism::Key::Q
|
||||
#define PM_KEY_R ::Prism::Key::R
|
||||
#define PM_KEY_S ::Prism::Key::S
|
||||
#define PM_KEY_T ::Prism::Key::T
|
||||
#define PM_KEY_U ::Prism::Key::U
|
||||
#define PM_KEY_V ::Prism::Key::V
|
||||
#define PM_KEY_W ::Prism::Key::W
|
||||
#define PM_KEY_X ::Prism::Key::X
|
||||
#define PM_KEY_Y ::Prism::Key::Y
|
||||
#define PM_KEY_Z ::Prism::Key::Z
|
||||
#define PM_KEY_LEFT_BRACKET ::Prism::Key::LEFT_BRACKET /* [ */
|
||||
#define PM_KEY_BACKSLASH ::Prism::Key::BACKSLASM /* \ */
|
||||
#define PM_KEY_RIGHT_BRACKET ::Prism::Key::RIGHT_BRACKET /* ] */
|
||||
#define PM_KEY_GRAVE_ACCENT ::Prism::Key::GRAVE_ACCENT /* ` */
|
||||
#define PM_KEY_WORLD_1 ::Prism::Key::WORLD_1 /* non-US #1 */
|
||||
#define PM_KEY_WORLD_2 ::Prism::Key::WROLD_2 /* non-US #2 */
|
||||
|
||||
/* Function keys */
|
||||
#define PM_KEY_ESCAPE 256
|
||||
#define PM_KEY_ENTER 257
|
||||
#define PM_KEY_TAB 258
|
||||
#define PM_KEY_BACKSPACE 259
|
||||
#define PM_KEY_INSERT 260
|
||||
#define PM_KEY_DELETE 261
|
||||
#define PM_KEY_RIGHT 262
|
||||
#define PM_KEY_LEFT 263
|
||||
#define PM_KEY_DOWN 264
|
||||
#define PM_KEY_UP 265
|
||||
#define PM_KEY_PAGE_UP 266
|
||||
#define PM_KEY_PAGE_DOWN 267
|
||||
#define PM_KEY_HOME 268
|
||||
#define PM_KEY_END 269
|
||||
#define PM_KEY_CAPS_LOCK 280
|
||||
#define PM_KEY_SCROLL_LOCK 281
|
||||
#define PM_KEY_NUM_LOCK 282
|
||||
#define PM_KEY_PRINT_SCREEN 283
|
||||
#define PM_KEY_PAUSE 284
|
||||
#define PM_KEY_F1 290
|
||||
#define PM_KEY_F2 291
|
||||
#define PM_KEY_F3 292
|
||||
#define PM_KEY_F4 293
|
||||
#define PM_KEY_F5 294
|
||||
#define PM_KEY_F6 295
|
||||
#define PM_KEY_F7 296
|
||||
#define PM_KEY_F8 297
|
||||
#define PM_KEY_F9 298
|
||||
#define PM_KEY_F10 299
|
||||
#define PM_KEY_F11 300
|
||||
#define PM_KEY_F12 301
|
||||
#define PM_KEY_F13 302
|
||||
#define PM_KEY_F14 303
|
||||
#define PM_KEY_F15 304
|
||||
#define PM_KEY_F16 305
|
||||
#define PM_KEY_F17 306
|
||||
#define PM_KEY_F18 307
|
||||
#define PM_KEY_F19 308
|
||||
#define PM_KEY_F20 309
|
||||
#define PM_KEY_F21 310
|
||||
#define PM_KEY_F22 311
|
||||
#define PM_KEY_F23 312
|
||||
#define PM_KEY_F24 313
|
||||
#define PM_KEY_F25 314
|
||||
#define PM_KEY_KP_0 320
|
||||
#define PM_KEY_KP_1 321
|
||||
#define PM_KEY_KP_2 322
|
||||
#define PM_KEY_KP_3 323
|
||||
#define PM_KEY_KP_4 324
|
||||
#define PM_KEY_KP_5 325
|
||||
#define PM_KEY_KP_6 326
|
||||
#define PM_KEY_KP_7 327
|
||||
#define PM_KEY_KP_8 328
|
||||
#define PM_KEY_KP_9 329
|
||||
#define PM_KEY_KP_DECIMAL 330
|
||||
#define PM_KEY_KP_DIVIDE 331
|
||||
#define PM_KEY_KP_MULTIPLY 332
|
||||
#define PM_KEY_KP_SUBTRACT 333
|
||||
#define PM_KEY_KP_ADD 334
|
||||
#define PM_KEY_KP_ENTER 335
|
||||
#define PM_KEY_KP_EQUAL 336
|
||||
#define PM_KEY_LEFT_SHIFT 340
|
||||
#define PM_KEY_LEFT_CONTROL 341
|
||||
#define PM_KEY_LEFT_ALT 342
|
||||
#define PM_KEY_LEFT_SUPER 343
|
||||
#define PM_KEY_RIGHT_SHIFT 344
|
||||
#define PM_KEY_RIGHT_CONTROL 345
|
||||
#define PM_KEY_RIGHT_ALT 346
|
||||
#define PM_KEY_RIGHT_SUPER 347
|
||||
#define PM_KEY_MENU 348
|
||||
#define PM_KEY_ESCAPE ::Prism::Key::ESCAPE
|
||||
#define PM_KEY_ENTER ::Prism::Key::ENTER
|
||||
#define PM_KEY_TAB ::Prism::Key::TAB
|
||||
#define PM_KEY_BACKSPACE ::Prism::Key::BACKSPACE
|
||||
#define PM_KEY_INSERT ::Prism::Key::INSERT
|
||||
#define PM_KEY_DELETE ::Prism::Key::DELETE
|
||||
#define PM_KEY_RIGHT ::Prism::Key::RIGHT
|
||||
#define PM_KEY_LEFT ::Prism::Key::LEFT
|
||||
#define PM_KEY_DOWN ::Prism::Key::DOWN
|
||||
#define PM_KEY_UP ::Prism::Key::UP
|
||||
#define PM_KEY_PAGE_UP ::Prism::Key::PAGE_UP
|
||||
#define PM_KEY_PAGE_DOWN ::Prism::Key::PAGE_DOWN
|
||||
#define PM_KEY_HOME ::Prism::Key::HOME
|
||||
#define PM_KEY_END ::Prism::Key::END
|
||||
#define PM_KEY_CAPS_LOCK ::Prism::Key::CAPS_LOCK
|
||||
#define PM_KEY_SCROLL_LOCK ::Prism::Key::SCROLL_LOCK
|
||||
#define PM_KEY_NUM_LOCK ::Prism::Key::NUM_LOCK
|
||||
#define PM_KEY_PRINT_SCREEN ::Prism::Key::PRINT_SCREEN
|
||||
#define PM_KEY_PAUSE ::Prism::Key::PAUSE
|
||||
#define PM_KEY_F1 ::Prism::Key::F1
|
||||
#define PM_KEY_F2 ::Prism::Key::F2
|
||||
#define PM_KEY_F3 ::Prism::Key::F3
|
||||
#define PM_KEY_F4 ::Prism::Key::F4
|
||||
#define PM_KEY_F5 ::Prism::Key::F5
|
||||
#define PM_KEY_F6 ::Prism::Key::F6
|
||||
#define PM_KEY_F7 ::Prism::Key::F7
|
||||
#define PM_KEY_F8 ::Prism::Key::F8
|
||||
#define PM_KEY_F9 ::Prism::Key::F9
|
||||
#define PM_KEY_F10 ::Prism::Key::F10
|
||||
#define PM_KEY_F11 ::Prism::Key::F11
|
||||
#define PM_KEY_F12 ::Prism::Key::F12
|
||||
#define PM_KEY_F13 ::Prism::Key::F13
|
||||
#define PM_KEY_F14 ::Prism::Key::F14
|
||||
#define PM_KEY_F15 ::Prism::Key::F15
|
||||
#define PM_KEY_F16 ::Prism::Key::F16
|
||||
#define PM_KEY_F17 ::Prism::Key::F17
|
||||
#define PM_KEY_F18 ::Prism::Key::F18
|
||||
#define PM_KEY_F19 ::Prism::Key::F19
|
||||
#define PM_KEY_F20 ::Prism::Key::F20
|
||||
#define PM_KEY_F21 ::Prism::Key::F21
|
||||
#define PM_KEY_F22 ::Prism::Key::F22
|
||||
#define PM_KEY_F23 ::Prism::Key::F23
|
||||
#define PM_KEY_F24 ::Prism::Key::F24
|
||||
#define PM_KEY_F25 ::Prism::Key::F25
|
||||
#define PM_KEY_KP_0 ::Prism::Key::KP_0
|
||||
#define PM_KEY_KP_1 ::Prism::Key::KP_1
|
||||
#define PM_KEY_KP_2 ::Prism::Key::KP_2
|
||||
#define PM_KEY_KP_3 ::Prism::Key::KP_3
|
||||
#define PM_KEY_KP_4 ::Prism::Key::KP_4
|
||||
#define PM_KEY_KP_5 ::Prism::Key::KP_5
|
||||
#define PM_KEY_KP_6 ::Prism::Key::KP_6
|
||||
#define PM_KEY_KP_7 ::Prism::Key::KP_7
|
||||
#define PM_KEY_KP_8 ::Prism::Key::KP_8
|
||||
#define PM_KEY_KP_9 ::Prism::Key::KP_9
|
||||
#define PM_KEY_KP_DECIMAL ::Prism::Key::KP_DECIMAL
|
||||
#define PM_KEY_KP_DIVIDE ::Prism::Key::KP_DIVIDE
|
||||
#define PM_KEY_KP_MULTIPLY ::Prism::Key::KP_MULTIPLY
|
||||
#define PM_KEY_KP_SUBTRACT ::Prism::Key::KP_SUBTRACT
|
||||
#define PM_KEY_KP_ADD ::Prism::Key::KP_ADD
|
||||
#define PM_KEY_KP_ENTER ::Prism::Key::KP_ENTER
|
||||
#define PM_KEY_KP_EQUAL ::Prism::Key::KP_EQUAL
|
||||
#define PM_KEY_LEFT_SHIFT ::Prism::Key::LEFT_SHIFT
|
||||
#define PM_KEY_LEFT_CONTROL ::Prism::Key::LEFT_CONTROL
|
||||
#define PM_KEY_LEFT_ALT ::Prism::Key::LEFT_ALT
|
||||
#define PM_KEY_LEFT_SUPER ::Prism::Key::LEFT_SUPER
|
||||
#define PM_KEY_RIGHT_SHIFT ::Prism::Key::RIGHT_SHIFT
|
||||
#define PM_KEY_RIGHT_CONTROL ::Prism::Key::RIGHT_CONTROL
|
||||
#define PM_KEY_RIGHT_ALT ::Prism::Key::RIGHT_ALT
|
||||
#define PM_KEY_RIGHT_SUPER ::Prism::Key::RIGHT_SUPER
|
||||
#define PM_KEY_MENU ::Prism::Key::MENU
|
||||
|
||||
#define PM_MOUSE_BUTTON_LEFT 0
|
||||
#define PM_MOUSE_BUTTON_RIGHT 1
|
||||
#define PM_MOUSE_BUTTON_LEFT 0
|
||||
#define PM_MOUSE_BUTTON_RIGHT 1
|
||||
#define PM_MOUSE_BUTTON_MIDDLE 2
|
||||
|
||||
#endif //KEYCODES_H
|
||||
|
||||
158
Prism/src/Prism/Core/Ref.h
Normal file
158
Prism/src/Prism/Core/Ref.h
Normal file
@ -0,0 +1,158 @@
|
||||
//
|
||||
// Created by sfd on 25-12-5.
|
||||
//
|
||||
|
||||
#ifndef REF_H
|
||||
#define REF_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
class PRISM_API RefCounted
|
||||
{
|
||||
public:
|
||||
void IncRefCount()
|
||||
{
|
||||
m_RefCount ++;
|
||||
}
|
||||
|
||||
void DecRefCount()
|
||||
{
|
||||
m_RefCount --;
|
||||
}
|
||||
|
||||
uint32_t GetRefCount() const { return m_RefCount; }
|
||||
private:
|
||||
mutable uint32_t m_RefCount = 0; // TODO: atomic
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class Ref
|
||||
{
|
||||
public:
|
||||
Ref() : m_Instance(nullptr) {}
|
||||
Ref(const std::nullptr_t n) : m_Instance(nullptr) {}
|
||||
|
||||
Ref(T* instance)
|
||||
: m_Instance(instance)
|
||||
{
|
||||
static_assert(std::is_base_of_v<RefCounted, T>, "Class is not RefCounted!");
|
||||
|
||||
IncRef();
|
||||
}
|
||||
|
||||
|
||||
template<typename T2>
|
||||
Ref(const Ref<T2>& other)
|
||||
{
|
||||
m_Instance = other.m_Instance;
|
||||
IncRef();
|
||||
}
|
||||
|
||||
template<typename T2>
|
||||
Ref(Ref&& other)
|
||||
{
|
||||
m_Instance = other.m_Instance;
|
||||
other.m_Instance = nullptr;
|
||||
}
|
||||
|
||||
~Ref()
|
||||
{
|
||||
DecRef();
|
||||
}
|
||||
|
||||
Ref(const Ref& other)
|
||||
: m_Instance(other.m_Instance)
|
||||
{
|
||||
IncRef();
|
||||
}
|
||||
|
||||
Ref& operator=(std::nullptr_t)
|
||||
{
|
||||
DecRef();
|
||||
m_Instance = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Ref& operator=(const Ref& other)
|
||||
{
|
||||
other.IncRef();
|
||||
DecRef();
|
||||
|
||||
m_Instance = other.m_Instance;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T2>
|
||||
Ref& operator=(const Ref<T2>& other)
|
||||
{
|
||||
other.IncRef();
|
||||
DecRef();
|
||||
|
||||
m_Instance = other.m_Instance;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T2>
|
||||
Ref& operator=(Ref&& other)
|
||||
{
|
||||
DecRef();
|
||||
m_Instance = other.m_Instance;
|
||||
other.m_Instance = nullptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
explicit operator bool() { return m_Instance != nullptr; }
|
||||
explicit operator bool() const { return m_Instance != nullptr; }
|
||||
|
||||
T* operator->() { return m_Instance; }
|
||||
const T* operator->() const { return m_Instance; }
|
||||
|
||||
T& operator*() { return *m_Instance; }
|
||||
const T& operator*() const { return *m_Instance; }
|
||||
|
||||
T* Raw() { return m_Instance; }
|
||||
const T* Raw() const { return m_Instance; }
|
||||
|
||||
void Reset(T* instance = nullptr)
|
||||
{
|
||||
DecRef();
|
||||
m_Instance = instance;
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
static Ref<T> Create(Args&&... args)
|
||||
{
|
||||
return Ref<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
private:
|
||||
void IncRef() const
|
||||
{
|
||||
if (m_Instance) m_Instance->IncRefCount();
|
||||
}
|
||||
|
||||
void DecRef() const
|
||||
{
|
||||
if (m_Instance)
|
||||
{
|
||||
m_Instance->DecRefCount();
|
||||
if (m_Instance->GetRefCount() == 0)
|
||||
{
|
||||
delete m_Instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
template<typename T2>
|
||||
friend class Ref;
|
||||
|
||||
T* m_Instance;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //REF_H
|
||||
35
Prism/src/Prism/Core/Timer.h
Normal file
35
Prism/src/Prism/Core/Timer.h
Normal file
@ -0,0 +1,35 @@
|
||||
//
|
||||
// Created by sfd on 25-12-5.
|
||||
//
|
||||
|
||||
#ifndef TIMER_H
|
||||
#define TIMER_H
|
||||
#include <chrono>
|
||||
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
void Reset()
|
||||
{
|
||||
m_Start = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
float Elapsed() const
|
||||
{
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - m_Start).count() * 0.001f * 0.001f * 0.001f;
|
||||
}
|
||||
|
||||
float ElapsedMillis() const
|
||||
{
|
||||
return Elapsed() * 1000.0f;
|
||||
}
|
||||
|
||||
private:
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> m_Start;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //TIMER_H
|
||||
@ -7,6 +7,7 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include "Ref.h"
|
||||
#include "Events/Event.h"
|
||||
#include "Prism/Core/Core.h"
|
||||
|
||||
@ -27,7 +28,7 @@ namespace Prism
|
||||
}
|
||||
};
|
||||
|
||||
class PRISM_API Window
|
||||
class PRISM_API Window : public RefCounted
|
||||
{
|
||||
public:
|
||||
using EventCallbackFn = std::function<void(Event&)>;
|
||||
|
||||
@ -85,9 +85,9 @@ namespace Prism
|
||||
void SceneHierarchyPanel::DrawEntityNode(Entity* entity, uint32_t& imguiEntityID, uint32_t& imguiMeshID)
|
||||
{
|
||||
const char* name = entity->GetName().c_str();
|
||||
static char imguiName[128];
|
||||
static char imguiName[128] = {};
|
||||
memset(imguiName, 0, 128);
|
||||
sprintf(imguiName, "%s##%d", name, imguiEntityID++);
|
||||
snprintf(imguiName, sizeof(imguiName), "%s##%d", name, imguiEntityID++);
|
||||
if (ImGui::TreeNode(imguiName))
|
||||
{
|
||||
auto mesh = entity->GetMesh();
|
||||
@ -113,9 +113,9 @@ namespace Prism
|
||||
|
||||
void SceneHierarchyPanel::DrawMeshNode(const Ref<Mesh>& mesh, uint32_t& imguiMeshID)
|
||||
{
|
||||
static char imguiName[128];
|
||||
static char imguiName[128] = {};
|
||||
memset(imguiName, 0, 128);
|
||||
sprintf(imguiName, "Mesh##%d", imguiMeshID++);
|
||||
snprintf(imguiName, sizeof(imguiName), "Mesh##%d", imguiMeshID++);
|
||||
|
||||
// Mesh Hierarchy
|
||||
if (ImGui::TreeNode(imguiName))
|
||||
|
||||
@ -77,6 +77,16 @@ namespace Prism
|
||||
}
|
||||
|
||||
|
||||
OpenGLIndexBuffer::OpenGLIndexBuffer(uint32_t size)
|
||||
: m_Size(size)
|
||||
{
|
||||
Renderer::Submit([this]()
|
||||
{
|
||||
glCreateBuffers(1, &m_RendererID);
|
||||
glNamedBufferData(m_RendererID, m_Size, nullptr, GL_DYNAMIC_DRAW);
|
||||
});
|
||||
}
|
||||
|
||||
// ******************************************
|
||||
// IndexBuffer
|
||||
// ******************************************
|
||||
|
||||
@ -47,6 +47,7 @@ namespace Prism
|
||||
class OpenGLIndexBuffer : public IndexBuffer
|
||||
{
|
||||
public:
|
||||
OpenGLIndexBuffer(uint32_t size);
|
||||
OpenGLIndexBuffer(void* data, uint32_t size);
|
||||
virtual ~OpenGLIndexBuffer();
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ namespace Prism
|
||||
OpenGLRenderPass(const RenderPassSpecification& spec);
|
||||
virtual ~OpenGLRenderPass();
|
||||
|
||||
virtual const RenderPassSpecification& GetSpecification() const override { return m_spec; }
|
||||
virtual RenderPassSpecification& GetSpecification() override { return m_spec; }
|
||||
|
||||
private:
|
||||
RenderPassSpecification m_spec;
|
||||
|
||||
@ -24,7 +24,7 @@ namespace Prism
|
||||
|
||||
Ref<OpenGLShader> OpenGLShader::CreateFromString(const std::string& source)
|
||||
{
|
||||
Ref<OpenGLShader> shader = std::make_shared<OpenGLShader>();
|
||||
Ref<OpenGLShader> shader = Ref<OpenGLShader>::Create();
|
||||
shader->Load(source);
|
||||
return shader;
|
||||
}
|
||||
|
||||
@ -27,8 +27,8 @@ namespace Prism
|
||||
private:
|
||||
RendererID m_RendererID = 0;
|
||||
uint32_t m_VertexBufferIndex = 0;
|
||||
std::vector<std::shared_ptr<VertexBuffer>> m_VertexBuffers;
|
||||
std::shared_ptr<IndexBuffer> m_IndexBuffer;
|
||||
std::vector<Ref<VertexBuffer>> m_VertexBuffers;
|
||||
Ref<IndexBuffer> m_IndexBuffer;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -7,13 +7,14 @@
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "Prism/Core/Input.h"
|
||||
#include "Prism/Core/KeyCodes.h"
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
bool Input::IsKeyPressed(int keycode)
|
||||
bool Input::IsKeyPressed(KeyCode keycode)
|
||||
{
|
||||
const auto& window = dynamic_cast<WindowsWindow&>(Application::Get().GetWindow());
|
||||
const auto state = glfwGetKey(static_cast<GLFWwindow*>(window.GetNativeWindow()), keycode);
|
||||
const auto state = glfwGetKey(static_cast<GLFWwindow*>(window.GetNativeWindow()), static_cast<uint32_t>(keycode));
|
||||
return state == GLFW_PRESS || state == GLFW_REPEAT;
|
||||
}
|
||||
bool Input::IsMouseButtonPressed(int button)
|
||||
@ -41,6 +42,6 @@ namespace Prism
|
||||
double xpos, ypos;
|
||||
glfwGetCursorPos(static_cast<GLFWwindow*>(window.GetNativeWindow()), &xpos, &ypos);
|
||||
|
||||
return {xpos, ypos};
|
||||
return {(float)xpos, (float)ypos};
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,19 +125,19 @@ namespace Prism
|
||||
{
|
||||
case GLFW_PRESS:
|
||||
{
|
||||
KeyPressedEvent event(key, 0);
|
||||
KeyPressedEvent event((KeyCode)(key), 0);
|
||||
data.EventCallback(event);
|
||||
break;
|
||||
}
|
||||
case GLFW_RELEASE:
|
||||
{
|
||||
KeyReleasedEvent event(key);
|
||||
KeyReleasedEvent event((KeyCode)key);
|
||||
data.EventCallback(event);
|
||||
break;
|
||||
}
|
||||
case GLFW_REPEAT:
|
||||
{
|
||||
KeyPressedEvent event(key, 1);
|
||||
KeyPressedEvent event((KeyCode)key, 1);
|
||||
data.EventCallback(event);
|
||||
break;
|
||||
}
|
||||
@ -169,7 +169,7 @@ namespace Prism
|
||||
{
|
||||
auto& data = *((WindowData*)glfwGetWindowUserPointer(window));
|
||||
|
||||
KeyTypedEvent event((int)codepoint);
|
||||
KeyTypedEvent event((KeyCode)codepoint);
|
||||
data.EventCallback(event);
|
||||
});
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ namespace Prism
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: return nullptr;
|
||||
case RendererAPIType::OpenGL: return CreateRef<OpenGLVertexBuffer>(data, size, usage);
|
||||
case RendererAPIType::OpenGL: return Ref<OpenGLVertexBuffer>::Create(data, size, usage);
|
||||
}
|
||||
PM_CORE_ASSERT(false, "Unknown RendererAPI");
|
||||
return nullptr;
|
||||
@ -24,20 +24,30 @@ namespace Prism
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: return nullptr;
|
||||
case RendererAPIType::OpenGL: return CreateRef<OpenGLVertexBuffer>(size, usage);
|
||||
case RendererAPIType::OpenGL: return Ref<OpenGLVertexBuffer>::Create(size, usage);
|
||||
}
|
||||
PM_CORE_ASSERT(false, "Unknown RendererAPI");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
Ref<IndexBuffer> IndexBuffer::Create(uint32_t size)
|
||||
{
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: return nullptr;
|
||||
case RendererAPIType::OpenGL: return Ref<OpenGLIndexBuffer>::Create(size);
|
||||
}
|
||||
PM_CORE_ASSERT(false, "Unknown RendererAPI");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Ref<IndexBuffer> IndexBuffer::Create(void* data, uint32_t size)
|
||||
{
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: return nullptr;
|
||||
case RendererAPIType::OpenGL: return CreateRef<OpenGLIndexBuffer>(data, size);
|
||||
case RendererAPIType::OpenGL: return Ref<OpenGLIndexBuffer>::Create(data, size);
|
||||
}
|
||||
PM_CORE_ASSERT(false, "Unknown RendererAPI");
|
||||
return nullptr;
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#ifndef RENDERER_BUFFER_H
|
||||
#define RENDERER_BUFFER_H
|
||||
#include "RendererAPI.h"
|
||||
#include "Prism/Core/Ref.h"
|
||||
|
||||
|
||||
namespace Prism
|
||||
@ -116,7 +117,7 @@ namespace Prism
|
||||
};
|
||||
|
||||
|
||||
class PRISM_API VertexBuffer
|
||||
class PRISM_API VertexBuffer : public RefCounted
|
||||
{
|
||||
public:
|
||||
virtual ~VertexBuffer() {}
|
||||
@ -136,11 +137,12 @@ namespace Prism
|
||||
};
|
||||
|
||||
|
||||
class PRISM_API IndexBuffer
|
||||
class PRISM_API IndexBuffer : public RefCounted
|
||||
{
|
||||
public:
|
||||
virtual ~IndexBuffer() {}
|
||||
|
||||
static Ref<IndexBuffer> Create(uint32_t size);
|
||||
static Ref<IndexBuffer> Create(void* data, uint32_t size = 0);
|
||||
|
||||
virtual void SetData(void* buffer, uint32_t size, uint32_t offset = 0) = 0;
|
||||
|
||||
@ -43,7 +43,7 @@ namespace Prism
|
||||
|
||||
void Camera::OnUpdate(TimeStep deltaTime)
|
||||
{
|
||||
if (Input::IsKeyPressed(GLFW_KEY_LEFT_ALT))
|
||||
if (Input::IsKeyPressed(Key::LEFT_ALT))
|
||||
{
|
||||
const glm::vec2& mouse{ Input::GetMouseX(), Input::GetMouseY() };
|
||||
glm::vec2 delta = mouse - m_InitialMousePosition;
|
||||
|
||||
@ -14,7 +14,7 @@ namespace Prism
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: return nullptr;
|
||||
case RendererAPIType::OpenGL: result = CreateRef<OpenGLFrameBuffer>(spec);
|
||||
case RendererAPIType::OpenGL: result = Ref<OpenGLFrameBuffer>::Create(spec);
|
||||
}
|
||||
FrameBufferPool::GetGlobal()->Add(result);
|
||||
return result;
|
||||
@ -44,7 +44,7 @@ namespace Prism
|
||||
return s_Instance;
|
||||
}
|
||||
|
||||
void FrameBufferPool::Add(std::weak_ptr<FrameBuffer> framebuffer)
|
||||
void FrameBufferPool::Add(const Ref<FrameBuffer>& framebuffer)
|
||||
{
|
||||
m_Pool.push_back(framebuffer);
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#define FRAMEBUFFER_H
|
||||
#include "RendererAPI.h"
|
||||
#include "glm/glm.hpp"
|
||||
#include "Prism/Core/Ref.h"
|
||||
|
||||
|
||||
namespace Prism
|
||||
@ -29,13 +30,14 @@ namespace Prism
|
||||
bool SwapChainTarget = false;
|
||||
};
|
||||
|
||||
class PRISM_API FrameBuffer
|
||||
class PRISM_API FrameBuffer : public RefCounted
|
||||
{
|
||||
public:
|
||||
virtual ~FrameBuffer() {}
|
||||
|
||||
static Ref<FrameBuffer> Create(const FramebufferSpecification& spec);
|
||||
|
||||
|
||||
virtual const FramebufferSpecification& GetSpecification() const = 0;
|
||||
virtual void Bind() const = 0;
|
||||
virtual void Unbind() const = 0;
|
||||
@ -56,14 +58,14 @@ namespace Prism
|
||||
~FrameBufferPool();
|
||||
|
||||
std::weak_ptr<FrameBuffer> AllocateBuffer();
|
||||
void Add(std::weak_ptr<FrameBuffer> framebuffer);
|
||||
void Add(const Ref<FrameBuffer>& framebuffer);
|
||||
|
||||
const std::vector<std::weak_ptr<FrameBuffer>>& GetAll() const { return m_Pool; }
|
||||
std::vector<Ref<FrameBuffer>>& GetAll() { return m_Pool; }
|
||||
|
||||
static FrameBufferPool* GetGlobal();
|
||||
|
||||
private:
|
||||
std::vector<std::weak_ptr<FrameBuffer>> m_Pool;
|
||||
std::vector<Ref<FrameBuffer>> m_Pool;
|
||||
|
||||
static FrameBufferPool* s_Instance;
|
||||
};
|
||||
|
||||
@ -22,7 +22,7 @@ namespace Prism
|
||||
|
||||
Ref<Material> Material::Create(const Ref<Shader>& shader)
|
||||
{
|
||||
return CreateRef<Material>(shader);
|
||||
return Ref<Material>::Create(shader);
|
||||
}
|
||||
|
||||
|
||||
@ -99,7 +99,7 @@ namespace Prism
|
||||
return m_VSUniformStorageBuffer;
|
||||
}
|
||||
|
||||
void Material::Bind() const
|
||||
void Material::Bind()
|
||||
{
|
||||
m_Shader->Bind();
|
||||
|
||||
@ -136,7 +136,7 @@ namespace Prism
|
||||
|
||||
Ref<MaterialInstance> MaterialInstance::Create(const Ref<Material>& material)
|
||||
{
|
||||
return CreateRef<MaterialInstance>(material);
|
||||
return Ref<MaterialInstance>::Create(material);
|
||||
}
|
||||
|
||||
void MaterialInstance::OnShaderReloaded()
|
||||
@ -192,7 +192,7 @@ namespace Prism
|
||||
return m_VSUniformStorageBuffer;
|
||||
}
|
||||
|
||||
void MaterialInstance::Bind() const
|
||||
void MaterialInstance::Bind()
|
||||
{
|
||||
m_Material->m_Shader->Bind();
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ namespace Prism
|
||||
Blend = BIT(2)
|
||||
};
|
||||
|
||||
class PRISM_API Material
|
||||
class PRISM_API Material : public RefCounted
|
||||
{
|
||||
friend class MaterialInstance;
|
||||
public:
|
||||
@ -33,7 +33,7 @@ namespace Prism
|
||||
|
||||
static Ref<Material> Create(const Ref<Shader>& shader);
|
||||
|
||||
void Bind() const;
|
||||
void Bind();
|
||||
|
||||
uint32_t GetFlags() const { return m_MaterialFlags; }
|
||||
void SetFlag(MaterialFlag flag) { m_MaterialFlags |= (uint32_t)flag; }
|
||||
@ -83,7 +83,7 @@ namespace Prism
|
||||
|
||||
|
||||
|
||||
class PRISM_API MaterialInstance
|
||||
class PRISM_API MaterialInstance : public RefCounted
|
||||
{
|
||||
friend class Material;
|
||||
public:
|
||||
@ -122,7 +122,7 @@ namespace Prism
|
||||
Set(name, (const Ref<Texture>&)texture);
|
||||
}
|
||||
|
||||
void Bind() const;
|
||||
void Bind();
|
||||
|
||||
uint32_t GetFlags() const { return m_Material->m_MaterialFlags; }
|
||||
bool GetFlag(MaterialFlag flag) const { return (uint32_t)flag & m_Material->m_MaterialFlags; }
|
||||
|
||||
@ -115,7 +115,7 @@ namespace Prism
|
||||
|
||||
m_IsAnimated = scene->mAnimations != nullptr;
|
||||
m_MeshShader = m_IsAnimated ? Renderer::GetShaderLibrary()->Get("PBRShader_Anim") : Renderer::GetShaderLibrary()->Get("PBRShader_Static");
|
||||
m_BaseMaterial = CreateRef<Material>(m_MeshShader);
|
||||
m_BaseMaterial = Ref<Material>::Create(m_MeshShader);
|
||||
m_InverseTransform = glm::inverse(Mat4FromAssimpMat4(scene->mRootNode->mTransformation));
|
||||
|
||||
uint32_t vertexCount = 0;
|
||||
@ -259,7 +259,7 @@ namespace Prism
|
||||
auto aiMaterial = scene->mMaterials[i];
|
||||
auto aiMaterialName = aiMaterial->GetName();
|
||||
|
||||
auto mi = CreateRef<MaterialInstance>(m_BaseMaterial);
|
||||
auto mi = Ref<MaterialInstance>::Create(m_BaseMaterial);
|
||||
m_Materials[i] = mi;
|
||||
|
||||
PM_MESH_LOG(" {0} (Index = {1})", aiMaterialName.data, i);
|
||||
|
||||
@ -100,7 +100,7 @@ namespace Prism
|
||||
std::string NodeName, MeshName;
|
||||
};
|
||||
|
||||
class PRISM_API Mesh
|
||||
class PRISM_API Mesh : public RefCounted
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ namespace Prism
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: PM_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr;
|
||||
case RendererAPIType::OpenGL: return std::make_shared<OpenGLRenderPass>(spec);
|
||||
case RendererAPIType::OpenGL: return Ref<OpenGLRenderPass>::Create(spec);
|
||||
}
|
||||
|
||||
PM_CORE_ASSERT(false, "Unknown RendererAPI!");
|
||||
|
||||
@ -14,12 +14,12 @@ namespace Prism
|
||||
Ref<FrameBuffer> TargetFramebuffer;
|
||||
};
|
||||
|
||||
class PRISM_API RenderPass
|
||||
class PRISM_API RenderPass : public RefCounted
|
||||
{
|
||||
public:
|
||||
virtual ~RenderPass() {}
|
||||
|
||||
virtual const RenderPassSpecification& GetSpecification() const = 0;
|
||||
virtual RenderPassSpecification& GetSpecification() = 0;
|
||||
|
||||
static Ref<RenderPass> Create(const RenderPassSpecification& spec);
|
||||
};
|
||||
|
||||
@ -46,13 +46,13 @@ namespace Prism
|
||||
};
|
||||
|
||||
s_Data.m_FullscreenQuadVertexArray = VertexArray::Create();
|
||||
const auto quadVB = VertexBuffer::Create(fullScreenQuadVertex, sizeof(float) * sizeof(fullScreenQuadVertex));
|
||||
auto quadVB = VertexBuffer::Create(fullScreenQuadVertex, sizeof(float) * sizeof(fullScreenQuadVertex));
|
||||
quadVB->SetLayout({
|
||||
{ ShaderDataType::Float3, "a_Position" },
|
||||
{ ShaderDataType::Float2, "a_TexCoord" }
|
||||
});
|
||||
|
||||
const auto quadIB = IndexBuffer::Create(fullScreenQuadIndices, sizeof(fullScreenQuadIndices) * sizeof(uint32_t));
|
||||
auto quadIB = IndexBuffer::Create(fullScreenQuadIndices, sizeof(fullScreenQuadIndices) * sizeof(uint32_t));
|
||||
s_Data.m_FullscreenQuadVertexArray->AddVertexBuffer(quadVB);
|
||||
s_Data.m_FullscreenQuadVertexArray->SetIndexBuffer(quadIB);
|
||||
|
||||
@ -104,7 +104,7 @@ namespace Prism
|
||||
s_Data.m_CommandQueue.Execute();
|
||||
}
|
||||
|
||||
void Renderer::BeginRenderPass(const Ref<RenderPass>& renderPass, bool clear)
|
||||
void Renderer::BeginRenderPass(Ref<RenderPass> renderPass, const bool clear)
|
||||
{
|
||||
PM_CORE_ASSERT(renderPass, "Render pass cannot be null!");
|
||||
|
||||
@ -129,7 +129,7 @@ namespace Prism
|
||||
s_Data.m_ActiveRenderPass = nullptr;
|
||||
}
|
||||
|
||||
void Renderer::SubmitQuad(const Ref<MaterialInstance>& material, const glm::mat4& transform)
|
||||
void Renderer::SubmitQuad(Ref<MaterialInstance>& material, const glm::mat4& transform)
|
||||
{
|
||||
bool depthTest = true;
|
||||
if (material)
|
||||
@ -145,7 +145,7 @@ namespace Prism
|
||||
Renderer::DrawIndexed(6, PrimitiveType::Triangles, depthTest);
|
||||
}
|
||||
|
||||
void Renderer::SubmitFullscreenQuad(const Ref<MaterialInstance>& material)
|
||||
void Renderer::SubmitFullscreenQuad(Ref<MaterialInstance> material)
|
||||
{
|
||||
bool depthTest = true;
|
||||
if (material)
|
||||
@ -158,7 +158,7 @@ namespace Prism
|
||||
Renderer::DrawIndexed(6, PrimitiveType::Triangles, depthTest);
|
||||
}
|
||||
|
||||
void Renderer::SubmitMesh(const Ref<Mesh>& mesh, const glm::mat4& transform, const Ref<MaterialInstance>& overrideMaterial)
|
||||
void Renderer::SubmitMesh(Ref<Mesh>& mesh, const glm::mat4& transform, const Ref<MaterialInstance>& overrideMaterial)
|
||||
{
|
||||
// auto material = overrideMaterial ? overrideMaterial : mesh->GetMaterialInstance();
|
||||
// auto shader = material->GetShader();
|
||||
|
||||
@ -49,12 +49,12 @@ namespace Prism
|
||||
|
||||
|
||||
public:
|
||||
static void BeginRenderPass(const Ref<RenderPass>& renderPass, bool clear = true);
|
||||
static void BeginRenderPass(Ref<RenderPass> renderPass, bool clear = true);
|
||||
static void EndRenderPass();
|
||||
|
||||
static void SubmitQuad(const Ref<MaterialInstance>& material, const glm::mat4& transform = glm::mat4(1.0f));
|
||||
static void SubmitFullscreenQuad(const Ref<MaterialInstance>& material);
|
||||
static void SubmitMesh(const Ref<Mesh>& mesh, const glm::mat4& transform, const Ref<MaterialInstance>& overrideMaterial = nullptr);
|
||||
static void SubmitQuad(Ref<MaterialInstance>& material, const glm::mat4& transform = glm::mat4(1.0f));
|
||||
static void SubmitFullscreenQuad(Ref<MaterialInstance> material);
|
||||
static void SubmitMesh(Ref<Mesh>& mesh, const glm::mat4& transform, const Ref<MaterialInstance>& overrideMaterial = nullptr);
|
||||
|
||||
static void DrawAABB(const AABB& aabb, const glm::mat4& transform, const glm::vec4& color = glm::vec4(1.0f));
|
||||
static void DrawAABB(const Ref<Mesh>& mesh,const glm::mat4& transform, const glm::vec4& color = glm::vec4(1.0f));
|
||||
|
||||
@ -169,7 +169,7 @@ namespace Prism
|
||||
|
||||
void Renderer2D::EndScene()
|
||||
{
|
||||
uint32_t dataSize = (uint8_t*)s_Data.QuadVertexBufferPtr - (uint8_t*)s_Data.QuadVertexBufferBase;
|
||||
uint32_t dataSize = (uint32_t)((uint8_t*)s_Data.QuadVertexBufferPtr - (uint8_t*)s_Data.QuadVertexBufferBase);
|
||||
if (dataSize)
|
||||
{
|
||||
s_Data.QuadVertexBuffer->SetData(s_Data.QuadVertexBufferBase, dataSize);
|
||||
@ -185,7 +185,7 @@ namespace Prism
|
||||
s_Data.Stats.DrawCalls++;
|
||||
}
|
||||
|
||||
dataSize = (uint8_t*)s_Data.LineVertexBufferPtr - (uint8_t*)s_Data.LineVertexBufferBase;
|
||||
dataSize = (uint32_t)((uint8_t*)s_Data.LineVertexBufferPtr - (uint8_t*)s_Data.LineVertexBufferBase);
|
||||
if (dataSize)
|
||||
{
|
||||
s_Data.LineVertexBuffer->SetData(s_Data.LineVertexBufferBase, dataSize);
|
||||
@ -263,7 +263,7 @@ namespace Prism
|
||||
float textureIndex = 0.0f;
|
||||
for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
|
||||
{
|
||||
if (*s_Data.TextureSlots[i].get() == *texture.get())
|
||||
if (*s_Data.TextureSlots[i].Raw() == *texture.Raw())
|
||||
{
|
||||
textureIndex = (float)i;
|
||||
break;
|
||||
@ -341,7 +341,7 @@ namespace Prism
|
||||
float textureIndex = 0.0f;
|
||||
for (uint32_t i = 1; i < s_Data.TextureSlotIndex; i++)
|
||||
{
|
||||
if (*s_Data.TextureSlots[i].get() == *texture.get())
|
||||
if (*s_Data.TextureSlots[i].Raw() == *texture.Raw())
|
||||
{
|
||||
textureIndex = (float)i;
|
||||
break;
|
||||
|
||||
@ -137,7 +137,8 @@ namespace Prism
|
||||
if (!equirectangularConversionShader)
|
||||
equirectangularConversionShader = Shader::Create("assets/shaders/EquirectangularToCubeMap.glsl");
|
||||
Ref<Texture2D> envEquirect = Texture2D::Create(filepath);
|
||||
PM_CORE_ASSERT(envEquirect->GetFormat() == TextureFormat::Float16, "Texture is not HDR!");
|
||||
if (envEquirect->GetFormat() != TextureFormat::Float16)
|
||||
PM_CORE_WARN("Texture is not HDR!");
|
||||
|
||||
equirectangularConversionShader->Bind();
|
||||
envEquirect->Bind();
|
||||
|
||||
@ -18,7 +18,7 @@ namespace Prism
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: return nullptr;
|
||||
case RendererAPIType::OpenGL: result = CreateRef<OpenGLShader>(filepath);
|
||||
case RendererAPIType::OpenGL: result = Ref<OpenGLShader>::Create(filepath);
|
||||
}
|
||||
|
||||
s_AllShaders.push_back(result);
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "glm/gtc/type_ptr.hpp"
|
||||
#include "Prism/Core/Buffer.h"
|
||||
#include "ShaderUniform.h"
|
||||
#include "Prism/Core/Ref.h"
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
@ -95,7 +96,7 @@ namespace Prism
|
||||
|
||||
};
|
||||
|
||||
class PRISM_API Shader
|
||||
class PRISM_API Shader : public RefCounted
|
||||
{
|
||||
public:
|
||||
using ShaderReloadedCallback = std::function<void()>;
|
||||
|
||||
@ -33,7 +33,7 @@ namespace Prism
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: return nullptr;
|
||||
case RendererAPIType::OpenGL: return CreateRef<OpenGLTexture2D>(format, width, height, wrap);
|
||||
case RendererAPIType::OpenGL: return Ref<OpenGLTexture2D>::Create(format, width, height, wrap);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -44,7 +44,7 @@ namespace Prism
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: return nullptr;
|
||||
case RendererAPIType::OpenGL: return CreateRef<OpenGLTexture2D>(path, srgb);
|
||||
case RendererAPIType::OpenGL: return Ref<OpenGLTexture2D>::Create(path, srgb);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -54,7 +54,7 @@ namespace Prism
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: return nullptr;
|
||||
case RendererAPIType::OpenGL: return CreateRef<OpenGLTextureCube>(format, width, height);
|
||||
case RendererAPIType::OpenGL: return Ref<OpenGLTextureCube>::Create(format, width, height);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -64,7 +64,7 @@ namespace Prism
|
||||
switch (RendererAPI::Current())
|
||||
{
|
||||
case RendererAPIType::None: return nullptr;
|
||||
case RendererAPIType::OpenGL: return CreateRef<OpenGLTextureCube>(path);
|
||||
case RendererAPIType::OpenGL: return Ref<OpenGLTextureCube>::Create(path);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#define TEXTURE_H
|
||||
#include "RendererAPI.h"
|
||||
#include "Prism/Core/Buffer.h"
|
||||
#include "Prism/Core/Ref.h"
|
||||
|
||||
|
||||
namespace Prism
|
||||
@ -26,7 +27,7 @@ namespace Prism
|
||||
Repeat = 2
|
||||
};
|
||||
|
||||
class PRISM_API Texture
|
||||
class PRISM_API Texture : public RefCounted
|
||||
{
|
||||
public:
|
||||
virtual ~Texture() {}
|
||||
|
||||
@ -14,7 +14,7 @@ namespace Prism
|
||||
{
|
||||
case RendererAPIType::None: PM_CORE_ASSERT(false, "RendererAPI::None is currently not supported!");
|
||||
return nullptr;
|
||||
case RendererAPIType::OpenGL: return std::make_shared<OpenGLVertexArray>();
|
||||
case RendererAPIType::OpenGL: return Ref<OpenGLVertexArray>::Create();
|
||||
}
|
||||
|
||||
PM_CORE_ASSERT(false, "Unknown RendererAPI");
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
namespace Prism
|
||||
{
|
||||
class PRISM_API VertexArray
|
||||
class PRISM_API VertexArray : public RefCounted
|
||||
{
|
||||
public:
|
||||
virtual ~VertexArray() {}
|
||||
|
||||
@ -29,7 +29,8 @@ namespace Prism
|
||||
float Multiplier = 1.0f;
|
||||
};
|
||||
|
||||
class PRISM_API Scene{
|
||||
class PRISM_API Scene : public RefCounted
|
||||
{
|
||||
public:
|
||||
Scene(const std::string& debugName = "Scene");
|
||||
~Scene();
|
||||
|
||||
Reference in New Issue
Block a user