Dandelion 1.1.2
A light-weight 3D builder for educational usage
载入中...
搜索中...
未找到
platform.h
浏览该文件的文档.
1#ifndef DANDELION_PLATFORM_PLATFORM_H
2#define DANDELION_PLATFORM_PLATFORM_H
3
4/*!
5 * \file platform/platform.h
6 */
7
8#include <memory>
9
10#ifdef _WIN32
11 #include <Windows.h>
12#endif
13#include <glad/glad.h>
14#include <GLFW/glfw3.h>
15#include <imgui/imgui.h>
16#include <imgui/imgui_impl_glfw.h>
17#include <imgui/imgui_impl_opengl3.h>
18#include <spdlog/spdlog.h>
19
20#include "shader.hpp"
21
22/*!
23 * \ingroup platform
24 * \~english
25 * \brief The Platform class manages the platform-dependent window and some platform-
26 * dependent parameters.
27 *
28 * \~chinese
29 * \brief 这个类管理平台相关的窗口、配置信息以及应用启动的入口和事件循环。
30 */
32{
33public:
34
35 /*!
36 * \~chinese
37 * \brief 初始化 OpenGL Context、创建窗口、初始化 Dear ImGui、创建预览场景用的 shader。
38 *
39 * 构造函数按照 4.6 -> 4.3 -> 3.3 的版本顺序尝试创建 OpenGL Context,若全部失败,
40 * 则程序终止直接退出(OpenGL 3.3 是使用 GLSL shader 的最低要求)。
41 *
42 * OpenGL Context 创建成功后,构造函数加载 OpenGL API 并创建窗口,再探测用户显示器的
43 * DPI 来决定程序的全局缩放比例。Dear ImGui 的初始化过程依赖于全局缩放。
44 * 最后,构造函数编译、链接渲染预览场景的 shader。
45 */
46 Platform();
47 /*! \~chinese 执行 OpenGL 销毁窗口的操作。 */
48 ~Platform();
49 /*!
50 * \~chinese
51 * \brief 事件循环主体。
52 *
53 * 这是 GUI 的主循环,负责接收消息(输入)并转发给 Controller 对象。
54 * 此循环内的过程基本上是与平台 (OpenGL / GLFW) 相关的,平台无关的处理则移交 Controller。
55 */
56 void eventloop();
57
58private:
59
60 static constexpr float mouse_wheel_threshold = 1e-2f;
61 /*! \~chinese 检测显示器 DPI。 */
62 double get_dpi() noexcept;
63 /*! \~chinese 按 DPI 缩放窗口。 */
64 void resize_window() noexcept;
65 /*!
66 * \~chinese
67 * 创建 `major.minor` 版本的 OpenGL Context。
68 * \param major OpenGL 主版本
69 * \param minor OpenGL 次版本(小版本)
70 * \returns 创建是否成功
71 */
72 bool create_context(int major, int minor) noexcept;
73 /*! \~chinese
74 * 设置一些全局通用的 OpenGL 属性,例如开启深度测试等。
75 */
76 void set_opengl_properties() noexcept;
77 /*! \~chinese 初始化 Dear ImGui,加载字体、设置缩放和基础样式。 */
78 bool init_ui();
79 /*! \~chinese 处理窗口缩放的回调函数。 */
80 static void on_framebuffer_resized(GLFWwindow* window, GLsizei width, GLsizei height);
81
82 /*! \~chinese 持有的日志记录器。 */
83 std::shared_ptr<spdlog::logger> logger;
84 /*! \~chinese 窗口对象。 */
85 GLFWwindow* window;
86 ///@{
87 /*! \~chinese 实时更新的窗口长宽。*/
89 ///@}
90 /*! \~chinese 屏幕分辨率,实际是 PPI (Pixels Per Inch),称为 DPI 只是出于习惯。 */
91 double dpi;
92 /*! \~chinese 用于实时渲染预览窗口的 OpenGL Shader 封装对象。 */
93 std::unique_ptr<Shader> shader;
94};
95
96#endif
int window_height
定义 platform.h:88
~Platform()
定义 platform.cpp:90
Platform()
初始化 OpenGL Context、创建窗口、初始化 Dear ImGui、创建预览场景用的 shader。
定义 platform.cpp:25
void eventloop()
事件循环主体。
定义 platform.cpp:102
bool create_context(int major, int minor) noexcept
定义 platform.cpp:172
std::unique_ptr< Shader > shader
定义 platform.h:93
double get_dpi() noexcept
定义 platform.cpp:125
int window_width
定义 platform.h:88
void resize_window() noexcept
定义 platform.cpp:147
GLFWwindow * window
定义 platform.h:85
double dpi
定义 platform.h:91
void set_opengl_properties() noexcept
定义 platform.cpp:190
static void on_framebuffer_resized(GLFWwindow *window, GLsizei width, GLsizei height)
定义 platform.cpp:224
bool init_ui()
定义 platform.cpp:197
std::shared_ptr< spdlog::logger > logger
定义 platform.h:83