docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
# OpenGLDevice
|
|
|
|
|
|
|
|
|
|
|
|
**命名空间**: `XCEngine::RHI`
|
|
|
|
|
|
|
2026-03-20 02:35:45 +08:00
|
|
|
|
**继承自**: `RHIDevice`
|
|
|
|
|
|
|
2026-03-26 01:58:45 +08:00
|
|
|
|
**描述**: OpenGL 设备的实现,基于 Windows 原生窗口(HWND)和 Glad 提供 OpenGL 图形渲染能力。
|
2026-03-20 02:35:45 +08:00
|
|
|
|
|
|
|
|
|
|
## 概述
|
|
|
|
|
|
|
2026-03-26 01:58:45 +08:00
|
|
|
|
`OpenGLDevice` 是 XCEngine RHI 模块的 OpenGL 后端实现,通过 Windows HWND 管理窗口上下文,使用 Glad 加载 OpenGL 函数。它继承自抽象接口 `RHIDevice`,提供与具体图形 API 无关的统一接口。
|
2026-03-20 02:35:45 +08:00
|
|
|
|
|
|
|
|
|
|
### 主要功能
|
|
|
|
|
|
|
2026-03-26 01:58:45 +08:00
|
|
|
|
- 基于 Windows HWND 的窗口管理和事件处理
|
2026-03-20 02:35:45 +08:00
|
|
|
|
- OpenGL 3.3 Core Profile 上下文初始化
|
|
|
|
|
|
- 使用 Glad 动态加载 OpenGL 函数
|
|
|
|
|
|
- 设备能力查询和信息收集
|
|
|
|
|
|
- 渲染资源创建(缓冲区、纹理、着色器等)
|
|
|
|
|
|
|
2026-03-19 02:01:18 +08:00
|
|
|
|
## 公共方法
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
|
2026-03-19 02:01:18 +08:00
|
|
|
|
| 方法 | 描述 |
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
|------|------|
|
2026-03-20 02:35:45 +08:00
|
|
|
|
| [`OpenGLDevice`](constructor.md) | 构造函数 |
|
|
|
|
|
|
| [`~OpenGLDevice`](destructor.md) | 析构函数 |
|
|
|
|
|
|
| [`Initialize`](initialize.md) | 初始化设备 |
|
|
|
|
|
|
| [`Shutdown`](shutdown.md) | 关闭设备 |
|
2026-03-19 02:01:18 +08:00
|
|
|
|
| [`InitializeWithExistingWindow`](initialize-with-existing-window.md) | 使用现有窗口初始化 |
|
2026-03-26 01:58:45 +08:00
|
|
|
|
| [`MakeContextCurrent`](make-context-current.md) | 使 OpenGL 上下文为当前上下文 |
|
|
|
|
|
|
| [`GetNativeContext`](get-native-context.md) | 获取 OpenGL 渲染上下文句柄 |
|
2026-03-20 02:35:45 +08:00
|
|
|
|
| [`CreateBuffer`](create-buffer.md) | 创建缓冲区 |
|
|
|
|
|
|
| [`CreateTexture`](create-texture.md) | 创建纹理 |
|
|
|
|
|
|
| [`CreateSwapChain`](create-swap-chain.md) | 创建交换链 |
|
|
|
|
|
|
| [`CreateCommandList`](create-command-list.md) | 创建命令列表 |
|
|
|
|
|
|
| [`CreateCommandQueue`](create-command-queue.md) | 创建命令队列 |
|
2026-03-26 02:41:00 +08:00
|
|
|
|
| [`CreateShader`](../../device/create-shader.md) | 创建着色器 |
|
2026-03-20 02:35:45 +08:00
|
|
|
|
| [`CreatePipelineState`](create-pipeline-state.md) | 创建管线状态 |
|
|
|
|
|
|
| [`CreateFence`](create-fence.md) | 创建栅栏 |
|
|
|
|
|
|
| [`CreateSampler`](create-sampler.md) | 创建采样器 |
|
|
|
|
|
|
| [`GetCapabilities`](get-capabilities.md) | 获取设备能力 |
|
|
|
|
|
|
| [`GetDeviceInfo`](get-device-info.md) | 获取设备信息 |
|
|
|
|
|
|
| [`GetNativeDevice`](get-native-device.md) | 获取原生设备 |
|
|
|
|
|
|
| [`GetNativeHandle`](get-native-handle.md) | 获取原生句柄 |
|
|
|
|
|
|
|
|
|
|
|
|
## 使用示例
|
|
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLDevice.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
|
|
|
|
|
|
|
|
// 创建并初始化 OpenGL 设备
|
|
|
|
|
|
OpenGLDevice device;
|
|
|
|
|
|
RHIDeviceDesc desc;
|
|
|
|
|
|
desc.width = 1280;
|
|
|
|
|
|
desc.height = 720;
|
|
|
|
|
|
desc.appName = L"XCEngine App";
|
|
|
|
|
|
desc.enableDebugLayer = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (!device.Initialize(desc)) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 渲染循环
|
2026-03-26 01:58:45 +08:00
|
|
|
|
// (OpenGL 采用立即模式,渲染逻辑在主循环中执行)
|
2026-03-20 02:35:45 +08:00
|
|
|
|
|
|
|
|
|
|
// 清理
|
|
|
|
|
|
device.Shutdown();
|
|
|
|
|
|
```
|
|
|
|
|
|
|
2026-03-26 01:58:45 +08:00
|
|
|
|
### 使用已有 Windows 窗口
|
2026-03-20 02:35:45 +08:00
|
|
|
|
|
|
|
|
|
|
```cpp
|
|
|
|
|
|
OpenGLDevice device;
|
2026-03-26 01:58:45 +08:00
|
|
|
|
HWND existingWindow = /* 获取 Windows 窗口句柄 */;
|
2026-03-20 02:35:45 +08:00
|
|
|
|
if (device.InitializeWithExistingWindow(existingWindow)) {
|
|
|
|
|
|
// 使用已有窗口继续渲染
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
|
|
|
|
|
|
## 相关文档
|
|
|
|
|
|
|
2026-03-26 01:29:00 +08:00
|
|
|
|
- [OpenGL 后端总览](../opengl.md)
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
- [RHIDevice](../../device/device.md) - 抽象设备接口
|