Files
XCEngine/docs/api/rhi/opengl/shader/set-mat4-array.md

44 lines
1.1 KiB
Markdown
Raw Normal View History

# OpenGLShader::SetMat4Array
设置 4x4 矩阵数组 uniform 变量。
```cpp
void SetMat4Array(const char* name, const float* values, unsigned int count);
```
通过名称查找并设置着色器中的 4x4 矩阵数组 uniform 变量。矩阵按列主序存储。
**参数:**
- `name` - uniform 变量名称
- `values` - 指向 `count * 16` 个 float 元素的数组指针(列主序排列)
- `count` - 矩阵数量
**返回:** 无
**线程安全:** ❌(需要在渲染线程调用)
**示例:**
```cpp
// 设置多个变换矩阵(例如骨骼动画)
const unsigned int boneCount = 4;
float boneMatrices[4 * 16] = {
// 第一个矩阵
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
// 第二个矩阵
0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
// ...更多矩阵
};
shader->SetMat4Array("u_boneMatrices", boneMatrices, boneCount);
```
## 相关文档
- [OpenGLShader 总览](shader.md) - 返回类总览
- [SetMat4 (single)](../../shader/set-mat4.md) - 设置单个 4x4 矩阵