Dandelion
2.0.0
A light-weight 3D builder for educational usage
Toggle main menu visibility
载入中...
搜索中...
未找到
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 "
../render/preview_renderer.h
"
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
*/
31
class
Platform
32
{
33
public
:
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
58
private
:
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 实时更新的窗口长宽。*/
88
int
window_width
,
window_height
;
89
///@}
90
/*! \~chinese 屏幕分辨率,实际是 PPI (Pixels Per Inch),称为 DPI 只是出于习惯。 */
91
double
dpi
;
92
/*! \~chinese 用于实时预览的渲染器实例。 */
93
PreviewRenderer
renderer
;
94
};
95
96
#endif
Platform::window_height
int window_height
定义
platform.h:88
Platform::renderer
PreviewRenderer renderer
定义
platform.h:93
Platform::Platform
Platform()
初始化 OpenGL Context、创建窗口、初始化 Dear ImGui、创建预览场景用的 shader。
定义
platform.cpp:25
Platform::eventloop
void eventloop()
事件循环主体。
定义
platform.cpp:101
Platform::create_context
bool create_context(int major, int minor) noexcept
定义
platform.cpp:171
Platform::get_dpi
double get_dpi() noexcept
定义
platform.cpp:124
Platform::window_width
int window_width
定义
platform.h:88
Platform::resize_window
void resize_window() noexcept
定义
platform.cpp:146
Platform::window
GLFWwindow * window
定义
platform.h:85
Platform::dpi
double dpi
定义
platform.h:91
Platform::set_opengl_properties
void set_opengl_properties() noexcept
定义
platform.cpp:189
Platform::on_framebuffer_resized
static void on_framebuffer_resized(GLFWwindow *window, GLsizei width, GLsizei height)
定义
platform.cpp:222
Platform::init_ui
bool init_ui()
定义
platform.cpp:196
Platform::logger
std::shared_ptr< spdlog::logger > logger
定义
platform.h:83
PreviewRenderer
用于实时预览的渲染器。
定义
preview_renderer.h:28
preview_renderer.h
用于实时预览的渲染器。
src
platform
platform.h
制作者
1.18.0