change keycode HEAD HZ to PM, change input impl to cpp

This commit is contained in:
2025-11-28 18:50:04 +08:00
parent 018a4cb2c6
commit 75965135af
11 changed files with 176 additions and 140 deletions

View File

@ -38,7 +38,7 @@ namespace Prism
{ {
ImGuiIO& io = ImGui::GetIO(); ImGuiIO& io = ImGui::GetIO();
Application& app = Application::Get(); Application& app = Application::Get();
io.DisplaySize = ImVec2(app.GetWindow().GetWidth(), app.GetWindow().GetHeight()); io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight());
// Rendering // Rendering
ImGui::Render(); ImGui::Render();
@ -67,8 +67,10 @@ namespace Prism
//io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge;
/*
ImFont* pFont = io.Fonts->AddFontFromFileTTF(R"(C:\Windows\Fonts\segoeui.ttf)", 18.0f); ImFont* pFont = io.Fonts->AddFontFromFileTTF(R"(C:\Windows\Fonts\segoeui.ttf)", 18.0f);
io.FontDefault = io.Fonts->Fonts.back(); io.FontDefault = io.Fonts->Fonts.back();
*/
// Setup Dear ImGui style // Setup Dear ImGui style
ImGui::StyleColorsDark(); ImGui::StyleColorsDark();

View File

@ -0,0 +1,27 @@
//
// Created by sfd on 25-11-28.
//
#include "Input.h"
namespace Prism
{
bool Input::IsKeyPressed(const int keycode)
{
return s_Instance->IsKeyPressedImpl(keycode);
}
bool Input::IsMouseButtonPressed(const int button)
{
return s_Instance->IsMouseButtonPressedImpl(button);
}
float Input::GetMouseX()
{
return s_Instance->GetMouseXImpl();
}
float Input::GetMouseY()
{
return s_Instance->GetMouseYImpl();
}
}

View File

@ -7,14 +7,15 @@
namespace Prism namespace Prism
{ {
class Input class PRISM_API Input
{ {
public: public:
static bool IsKeyPressed(const int keycode) { return s_Instance->IsKeyPressedImpl(keycode); } static bool IsKeyPressed(const int keycode);
static bool IsMouseButtonPressed(const int button);
static float GetMouseX();
static float GetMouseY();
inline static bool IsMouseButtonPressed(const int button) { return s_Instance->IsMouseButtonPressedImpl(button); }
inline static float GetMouseX() { return s_Instance->GetMouseXImpl(); }
inline static float GetMouseY() { return s_Instance->GetMouseYImpl(); }
protected: protected:
virtual bool IsKeyPressedImpl(int keycode) = 0; virtual bool IsKeyPressedImpl(int keycode) = 0;
virtual bool IsMouseButtonPressedImpl(int button) = 0; virtual bool IsMouseButtonPressedImpl(int button) = 0;

View File

@ -8,127 +8,127 @@
#pragma once #pragma once
// From glfw3.h // From glfw3.h
#define HZ_KEY_SPACE 32 #define PM_KEY_SPACE 32
#define HZ_KEY_APOSTROPHE 39 /* ' */ #define PM_KEY_APOSTROPHE 39 /* ' */
#define HZ_KEY_COMMA 44 /* , */ #define PM_KEY_COMMA 44 /* , */
#define HZ_KEY_MINUS 45 /* - */ #define PM_KEY_MINUS 45 /* - */
#define HZ_KEY_PERIOD 46 /* . */ #define PM_KEY_PERIOD 46 /* . */
#define HZ_KEY_SLASH 47 /* / */ #define PM_KEY_SLASH 47 /* / */
#define HZ_KEY_0 48 #define PM_KEY_0 48
#define HZ_KEY_1 49 #define PM_KEY_1 49
#define HZ_KEY_2 50 #define PM_KEY_2 50
#define HZ_KEY_3 51 #define PM_KEY_3 51
#define HZ_KEY_4 52 #define PM_KEY_4 52
#define HZ_KEY_5 53 #define PM_KEY_5 53
#define HZ_KEY_6 54 #define PM_KEY_6 54
#define HZ_KEY_7 55 #define PM_KEY_7 55
#define HZ_KEY_8 56 #define PM_KEY_8 56
#define HZ_KEY_9 57 #define PM_KEY_9 57
#define HZ_KEY_SEMICOLON 59 /* ; */ #define PM_KEY_SEMICOLON 59 /* ; */
#define HZ_KEY_EQUAL 61 /* = */ #define PM_KEY_EQUAL 61 /* = */
#define HZ_KEY_A 65 #define PM_KEY_A 65
#define HZ_KEY_B 66 #define PM_KEY_B 66
#define HZ_KEY_C 67 #define PM_KEY_C 67
#define HZ_KEY_D 68 #define PM_KEY_D 68
#define HZ_KEY_E 69 #define PM_KEY_E 69
#define HZ_KEY_F 70 #define PM_KEY_F 70
#define HZ_KEY_G 71 #define PM_KEY_G 71
#define HZ_KEY_H 72 #define PM_KEY_H 72
#define HZ_KEY_I 73 #define PM_KEY_I 73
#define HZ_KEY_J 74 #define PM_KEY_J 74
#define HZ_KEY_K 75 #define PM_KEY_K 75
#define HZ_KEY_L 76 #define PM_KEY_L 76
#define HZ_KEY_M 77 #define PM_KEY_M 77
#define HZ_KEY_N 78 #define PM_KEY_N 78
#define HZ_KEY_O 79 #define PM_KEY_O 79
#define HZ_KEY_P 80 #define PM_KEY_P 80
#define HZ_KEY_Q 81 #define PM_KEY_Q 81
#define HZ_KEY_R 82 #define PM_KEY_R 82
#define HZ_KEY_S 83 #define PM_KEY_S 83
#define HZ_KEY_T 84 #define PM_KEY_T 84
#define HZ_KEY_U 85 #define PM_KEY_U 85
#define HZ_KEY_V 86 #define PM_KEY_V 86
#define HZ_KEY_W 87 #define PM_KEY_W 87
#define HZ_KEY_X 88 #define PM_KEY_X 88
#define HZ_KEY_Y 89 #define PM_KEY_Y 89
#define HZ_KEY_Z 90 #define PM_KEY_Z 90
#define HZ_KEY_LEFT_BRACKET 91 /* [ */ #define PM_KEY_LEFT_BRACKET 91 /* [ */
#define HZ_KEY_BACKSLASH 92 /* \ */ #define PM_KEY_BACKSLASH 92 /* \ */
#define HZ_KEY_RIGHT_BRACKET 93 /* ] */ #define PM_KEY_RIGHT_BRACKET 93 /* ] */
#define HZ_KEY_GRAVE_ACCENT 96 /* ` */ #define PM_KEY_GRAVE_ACCENT 96 /* ` */
#define HZ_KEY_WORLD_1 161 /* non-US #1 */ #define PM_KEY_WORLD_1 161 /* non-US #1 */
#define HZ_KEY_WORLD_2 162 /* non-US #2 */ #define PM_KEY_WORLD_2 162 /* non-US #2 */
/* Function keys */ /* Function keys */
#define HZ_KEY_ESCAPE 256 #define PM_KEY_ESCAPE 256
#define HZ_KEY_ENTER 257 #define PM_KEY_ENTER 257
#define HZ_KEY_TAB 258 #define PM_KEY_TAB 258
#define HZ_KEY_BACKSPACE 259 #define PM_KEY_BACKSPACE 259
#define HZ_KEY_INSERT 260 #define PM_KEY_INSERT 260
#define HZ_KEY_DELETE 261 #define PM_KEY_DELETE 261
#define HZ_KEY_RIGHT 262 #define PM_KEY_RIGHT 262
#define HZ_KEY_LEFT 263 #define PM_KEY_LEFT 263
#define HZ_KEY_DOWN 264 #define PM_KEY_DOWN 264
#define HZ_KEY_UP 265 #define PM_KEY_UP 265
#define HZ_KEY_PAGE_UP 266 #define PM_KEY_PAGE_UP 266
#define HZ_KEY_PAGE_DOWN 267 #define PM_KEY_PAGE_DOWN 267
#define HZ_KEY_HOME 268 #define PM_KEY_HOME 268
#define HZ_KEY_END 269 #define PM_KEY_END 269
#define HZ_KEY_CAPS_LOCK 280 #define PM_KEY_CAPS_LOCK 280
#define HZ_KEY_SCROLL_LOCK 281 #define PM_KEY_SCROLL_LOCK 281
#define HZ_KEY_NUM_LOCK 282 #define PM_KEY_NUM_LOCK 282
#define HZ_KEY_PRINT_SCREEN 283 #define PM_KEY_PRINT_SCREEN 283
#define HZ_KEY_PAUSE 284 #define PM_KEY_PAUSE 284
#define HZ_KEY_F1 290 #define PM_KEY_F1 290
#define HZ_KEY_F2 291 #define PM_KEY_F2 291
#define HZ_KEY_F3 292 #define PM_KEY_F3 292
#define HZ_KEY_F4 293 #define PM_KEY_F4 293
#define HZ_KEY_F5 294 #define PM_KEY_F5 294
#define HZ_KEY_F6 295 #define PM_KEY_F6 295
#define HZ_KEY_F7 296 #define PM_KEY_F7 296
#define HZ_KEY_F8 297 #define PM_KEY_F8 297
#define HZ_KEY_F9 298 #define PM_KEY_F9 298
#define HZ_KEY_F10 299 #define PM_KEY_F10 299
#define HZ_KEY_F11 300 #define PM_KEY_F11 300
#define HZ_KEY_F12 301 #define PM_KEY_F12 301
#define HZ_KEY_F13 302 #define PM_KEY_F13 302
#define HZ_KEY_F14 303 #define PM_KEY_F14 303
#define HZ_KEY_F15 304 #define PM_KEY_F15 304
#define HZ_KEY_F16 305 #define PM_KEY_F16 305
#define HZ_KEY_F17 306 #define PM_KEY_F17 306
#define HZ_KEY_F18 307 #define PM_KEY_F18 307
#define HZ_KEY_F19 308 #define PM_KEY_F19 308
#define HZ_KEY_F20 309 #define PM_KEY_F20 309
#define HZ_KEY_F21 310 #define PM_KEY_F21 310
#define HZ_KEY_F22 311 #define PM_KEY_F22 311
#define HZ_KEY_F23 312 #define PM_KEY_F23 312
#define HZ_KEY_F24 313 #define PM_KEY_F24 313
#define HZ_KEY_F25 314 #define PM_KEY_F25 314
#define HZ_KEY_KP_0 320 #define PM_KEY_KP_0 320
#define HZ_KEY_KP_1 321 #define PM_KEY_KP_1 321
#define HZ_KEY_KP_2 322 #define PM_KEY_KP_2 322
#define HZ_KEY_KP_3 323 #define PM_KEY_KP_3 323
#define HZ_KEY_KP_4 324 #define PM_KEY_KP_4 324
#define HZ_KEY_KP_5 325 #define PM_KEY_KP_5 325
#define HZ_KEY_KP_6 326 #define PM_KEY_KP_6 326
#define HZ_KEY_KP_7 327 #define PM_KEY_KP_7 327
#define HZ_KEY_KP_8 328 #define PM_KEY_KP_8 328
#define HZ_KEY_KP_9 329 #define PM_KEY_KP_9 329
#define HZ_KEY_KP_DECIMAL 330 #define PM_KEY_KP_DECIMAL 330
#define HZ_KEY_KP_DIVIDE 331 #define PM_KEY_KP_DIVIDE 331
#define HZ_KEY_KP_MULTIPLY 332 #define PM_KEY_KP_MULTIPLY 332
#define HZ_KEY_KP_SUBTRACT 333 #define PM_KEY_KP_SUBTRACT 333
#define HZ_KEY_KP_ADD 334 #define PM_KEY_KP_ADD 334
#define HZ_KEY_KP_ENTER 335 #define PM_KEY_KP_ENTER 335
#define HZ_KEY_KP_EQUAL 336 #define PM_KEY_KP_EQUAL 336
#define HZ_KEY_LEFT_SHIFT 340 #define PM_KEY_LEFT_SHIFT 340
#define HZ_KEY_LEFT_CONTROL 341 #define PM_KEY_LEFT_CONTROL 341
#define HZ_KEY_LEFT_ALT 342 #define PM_KEY_LEFT_ALT 342
#define HZ_KEY_LEFT_SUPER 343 #define PM_KEY_LEFT_SUPER 343
#define HZ_KEY_RIGHT_SHIFT 344 #define PM_KEY_RIGHT_SHIFT 344
#define HZ_KEY_RIGHT_CONTROL 345 #define PM_KEY_RIGHT_CONTROL 345
#define HZ_KEY_RIGHT_ALT 346 #define PM_KEY_RIGHT_ALT 346
#define HZ_KEY_RIGHT_SUPER 347 #define PM_KEY_RIGHT_SUPER 347
#define HZ_KEY_MENU 348 #define PM_KEY_MENU 348
#endif //KEYCODES_H #endif //KEYCODES_H

View File

@ -12,9 +12,9 @@ namespace Prism
OpenGLShader::OpenGLShader(const std::string& filepath) OpenGLShader::OpenGLShader(const std::string& filepath)
: m_AssetPath(filepath) : m_AssetPath(filepath)
{ {
size_t found = filepath.find_last_of("/\\"); const size_t found = filepath.find_last_of("/\\");
m_Name = found != std::string::npos ? filepath.substr(found + 1) : filepath; m_Name = found != std::string::npos ? filepath.substr(found + 1) : filepath;
Reload(); OpenGLShader::Reload();
} }
@ -254,7 +254,7 @@ namespace Prism
if (outPosition) if (outPosition)
*outPosition = end; *outPosition = end;
const uint32_t length = end - str + 1; const auto length = end - str + 1;
return std::string(str, length); return std::string(str, length);
} }
@ -266,7 +266,7 @@ namespace Prism
if (outPosition) if (outPosition)
*outPosition = end; *outPosition = end;
const uint32_t length = end - str + 1; const auto length = end - str + 1;
return std::string(str, length); return std::string(str, length);
} }
@ -592,7 +592,7 @@ namespace Prism
for (const auto& kv : m_ShaderSource) for (const auto& kv : m_ShaderSource)
{ {
GLenum type = kv.first; const GLenum type = kv.first;
const std::string& source = kv.second; const std::string& source = kv.second;
GLuint shaderRendererID = glCreateShader(type); GLuint shaderRendererID = glCreateShader(type);
const GLchar* sourcePtr = source.c_str(); const GLchar* sourcePtr = source.c_str();

View File

@ -12,6 +12,10 @@
#include "glm/gtx/quaternion.hpp" #include "glm/gtx/quaternion.hpp"
#include "Prism/Core/Input.h" #include "Prism/Core/Input.h"
#ifndef M_PI
#define M_PI 3.1415926f
#endif
namespace Prism namespace Prism
{ {

View File

@ -14,10 +14,11 @@
#define GLM_ENABLE_EXPERIMENTAL #define GLM_ENABLE_EXPERIMENTAL
#include "glm/gtx/quaternion.hpp" #include "glm/gtx/quaternion.hpp"
#include "Prism/Core/Log.h"
namespace Prism namespace Prism
{ {
const unsigned int s_ImportFlags = constexpr unsigned int s_ImportFlags =
aiProcess_CalcTangentSpace | // Create binormals/tangents just in case aiProcess_CalcTangentSpace | // Create binormals/tangents just in case
aiProcess_Triangulate | // Make sure we're triangles aiProcess_Triangulate | // Make sure we're triangles
aiProcess_SortByPType | // Split meshes by primitive type aiProcess_SortByPType | // Split meshes by primitive type

View File

@ -60,7 +60,7 @@ namespace Prism
do{\ do{\
struct PM_RENDER_UNIQUE(PMRenderCommand) \ struct PM_RENDER_UNIQUE(PMRenderCommand) \
{\ {\
PM_RENDER_UNIQUE(PMRenderCommand)(typename ::std::remove_const<typename ::std::remove_reference<decltype(arg0)>::type>::type arg0) \ explicit PM_RENDER_UNIQUE(PMRenderCommand)(typename ::std::remove_const<typename ::std::remove_reference<decltype(arg0)>::type>::type arg0) \
: m_arg0(arg0) {}\ : m_arg0(arg0) {}\
\ \
static void Execute(void* argBuffer)\ static void Execute(void* argBuffer)\
@ -79,7 +79,7 @@ namespace Prism
#define PM_RENDER_2(arg0, arg1, code) \ #define PM_RENDER_2(arg0, arg1, code) \
struct PM_RENDER_UNIQUE(PMRenderCommand) \ struct PM_RENDER_UNIQUE(PMRenderCommand) \
{\ {\
PM_RENDER_UNIQUE(PMRenderCommand)(typename ::std::remove_const<typename ::std::remove_reference<decltype(arg0)>::type>::type arg0,\ explicit PM_RENDER_UNIQUE(PMRenderCommand)(typename ::std::remove_const<typename ::std::remove_reference<decltype(arg0)>::type>::type arg0,\
typename ::std::remove_const<typename ::std::remove_reference<decltype(arg1)>::type>::type arg1) \ typename ::std::remove_const<typename ::std::remove_reference<decltype(arg1)>::type>::type arg1) \
: m_arg0(arg0), m_arg1(arg1) {}\ : m_arg0(arg0), m_arg1(arg1) {}\
\ \
@ -101,7 +101,7 @@ namespace Prism
#define PM_RENDER_3(arg0, arg1, arg2, code) \ #define PM_RENDER_3(arg0, arg1, arg2, code) \
struct PM_RENDER_UNIQUE(PMRenderCommand) \ struct PM_RENDER_UNIQUE(PMRenderCommand) \
{\ {\
PM_RENDER_UNIQUE(PMRenderCommand)(typename ::std::remove_const<typename ::std::remove_reference<decltype(arg0)>::type>::type arg0,\ explicit PM_RENDER_UNIQUE(PMRenderCommand)(typename ::std::remove_const<typename ::std::remove_reference<decltype(arg0)>::type>::type arg0,\
typename ::std::remove_const<typename ::std::remove_reference<decltype(arg1)>::type>::type arg1,\ typename ::std::remove_const<typename ::std::remove_reference<decltype(arg1)>::type>::type arg1,\
typename ::std::remove_const<typename ::std::remove_reference<decltype(arg2)>::type>::type arg2) \ typename ::std::remove_const<typename ::std::remove_reference<decltype(arg2)>::type>::type arg2) \
: m_arg0(arg0), m_arg1(arg1), m_arg2(arg2) {}\ : m_arg0(arg0), m_arg1(arg1), m_arg2(arg2) {}\
@ -126,7 +126,7 @@ namespace Prism
#define PM_RENDER_4(arg0, arg1, arg2, arg3, code) \ #define PM_RENDER_4(arg0, arg1, arg2, arg3, code) \
struct PM_RENDER_UNIQUE(PMRenderCommand) \ struct PM_RENDER_UNIQUE(PMRenderCommand) \
{\ {\
PM_RENDER_UNIQUE(PMRenderCommand)(typename ::std::remove_const<typename ::std::remove_reference<decltype(arg0)>::type>::type arg0,\ explicit PM_RENDER_UNIQUE(PMRenderCommand)(typename ::std::remove_const<typename ::std::remove_reference<decltype(arg0)>::type>::type arg0,\
typename ::std::remove_const<typename ::std::remove_reference<decltype(arg1)>::type>::type arg1,\ typename ::std::remove_const<typename ::std::remove_reference<decltype(arg1)>::type>::type arg1,\
typename ::std::remove_const<typename ::std::remove_reference<decltype(arg2)>::type>::type arg2,\ typename ::std::remove_const<typename ::std::remove_reference<decltype(arg2)>::type>::type arg2,\
typename ::std::remove_const<typename ::std::remove_reference<decltype(arg3)>::type>::type arg3)\ typename ::std::remove_const<typename ::std::remove_reference<decltype(arg3)>::type>::type arg3)\

View File

@ -307,7 +307,6 @@ void DemoLayer::OnUpdate(const Prism::TimeStep deltaTime)
m_GridShader->SetFloat("u_Scale", m_GridScale); m_GridShader->SetFloat("u_Scale", m_GridScale);
m_GridShader->SetFloat("u_Res", m_GridSize); m_GridShader->SetFloat("u_Res", m_GridSize);
m_PlaneMesh->Render(deltaTime, m_GridShader.get()); m_PlaneMesh->Render(deltaTime, m_GridShader.get());
m_Framebuffer->Unbind(); m_Framebuffer->Unbind();
m_FinalPresentBuffer->Bind(); m_FinalPresentBuffer->Bind();

View File

@ -4,6 +4,8 @@
#include "TestLayer.h" #include "TestLayer.h"
#include <memory>
#include "imgui.h" #include "imgui.h"
#include "glm/gtc/type_ptr.hpp" #include "glm/gtc/type_ptr.hpp"
#include "Prism/Renderer/Renderer.h" #include "Prism/Renderer/Renderer.h"
@ -176,7 +178,7 @@ void TestLayer::OnAttach()
m_Shader.reset(Prism::Shader::Create("assets/shaders/demo.glsl")); m_Shader.reset(Prism::Shader::Create("assets/shaders/demo.glsl"));
m_HDRShader.reset(Prism::Shader::Create("assets/shaders/hdr.glsl")); m_HDRShader.reset(Prism::Shader::Create("assets/shaders/hdr.glsl"));
m_Mesh.reset(new Prism::Mesh("assets/meshes/cerberus.fbx")); m_Mesh = std::make_unique<Prism::Mesh>("assets/meshes/cerberus.fbx");
} }
void TestLayer::OnDetach() void TestLayer::OnDetach()

View File

@ -18,8 +18,8 @@ public:
virtual void OnInit() override virtual void OnInit() override
{ {
// PushLayer(new TestLayer()); PushLayer(new TestLayer());
PushLayer(new DemoLayer()); // PushLayer(new DemoLayer());
} }
}; };