Files
XCEngine/docs/api/rhi/opengl/device/device.md
ssdfasd b414bc5326 refactor(docs): Fix broken links across multiple modules
Fixed broken references:
- texture-import-settings: Fix 16 files referencing wrong overview filename
- math/rectint: Fix 9 method links (rectint-* → get*, contains, intersects)
- rhi/opengl/device: Fix 8 cross-references (opengl-* → */**)
- resources/mesh: Fix meshsection and vertexattribute links
- rhi/d3d12/sampler: Fix RHISampler reference path
- math/vector3: Fix projectonplane → project-on-plane
- rhi/opengl/command-list: Remove broken ClearFlag enum ref
- rhi/opengl/device: Create 2 new method docs (MakeContextCurrent, GetNativeContext)
- rhi/device: Fix device-info types reference

All 0 broken references remaining.
2026-03-26 02:41:00 +08:00

86 lines
2.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# OpenGLDevice
**命名空间**: `XCEngine::RHI`
**继承自**: `RHIDevice`
**描述**: OpenGL 设备的实现,基于 Windows 原生窗口HWND和 Glad 提供 OpenGL 图形渲染能力。
## 概述
`OpenGLDevice` 是 XCEngine RHI 模块的 OpenGL 后端实现,通过 Windows HWND 管理窗口上下文,使用 Glad 加载 OpenGL 函数。它继承自抽象接口 `RHIDevice`,提供与具体图形 API 无关的统一接口。
### 主要功能
- 基于 Windows HWND 的窗口管理和事件处理
- OpenGL 3.3 Core Profile 上下文初始化
- 使用 Glad 动态加载 OpenGL 函数
- 设备能力查询和信息收集
- 渲染资源创建(缓冲区、纹理、着色器等)
## 公共方法
| 方法 | 描述 |
|------|------|
| [`OpenGLDevice`](constructor.md) | 构造函数 |
| [`~OpenGLDevice`](destructor.md) | 析构函数 |
| [`Initialize`](initialize.md) | 初始化设备 |
| [`Shutdown`](shutdown.md) | 关闭设备 |
| [`InitializeWithExistingWindow`](initialize-with-existing-window.md) | 使用现有窗口初始化 |
| [`MakeContextCurrent`](make-context-current.md) | 使 OpenGL 上下文为当前上下文 |
| [`GetNativeContext`](get-native-context.md) | 获取 OpenGL 渲染上下文句柄 |
| [`CreateBuffer`](create-buffer.md) | 创建缓冲区 |
| [`CreateTexture`](create-texture.md) | 创建纹理 |
| [`CreateSwapChain`](create-swap-chain.md) | 创建交换链 |
| [`CreateCommandList`](create-command-list.md) | 创建命令列表 |
| [`CreateCommandQueue`](create-command-queue.md) | 创建命令队列 |
| [`CreateShader`](../../device/create-shader.md) | 创建着色器 |
| [`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;
}
// 渲染循环
// (OpenGL 采用立即模式,渲染逻辑在主循环中执行)
// 清理
device.Shutdown();
```
### 使用已有 Windows 窗口
```cpp
OpenGLDevice device;
HWND existingWindow = /* 获取 Windows 窗口句柄 */;
if (device.InitializeWithExistingWindow(existingWindow)) {
// 使用已有窗口继续渲染
}
```
## 相关文档
- [OpenGL 后端总览](../opengl.md)
- [RHIDevice](../../device/device.md) - 抽象设备接口