refactor(RHI): 完成 Shader uniform 设置迁移到 CommandList
- 删除 RHIShader 的 OpenGL 风格 SetMat4/SetVec3/SetInt 等方法 - 添加 UniformInfo 结构体和 GetUniformInfos/GetUniformInfo 接口 - D3D12Shader 和 OpenGLShader 实现 CacheUniformInfos - RHICommandList 添加 SetUniform*/SetGlobal* 统一接口 - D3D12 实现 D3D12PipelineLayout 管理 root signature 映射 - 修复 D3D12CommandList::SetPipelineStateInternal 在 Reset 后未重新应用 root signature 的问题 - 更新 OpenGL 集成测试使用新的 SetUniform* API - 所有单元测试和集成测试通过 (8/8 integration tests)
This commit is contained in:
@@ -161,7 +161,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
}
|
||||
Log("[INFO] Shaders compiled successfully");
|
||||
|
||||
shader.SetInt("uTexture", 0);
|
||||
commandList.SetShader(&shader);
|
||||
commandList.SetUniformInt("uTexture", 0);
|
||||
|
||||
OpenGLPipelineState pipelineState;
|
||||
OpenGLRasterizerState rasterizerState;
|
||||
|
||||
@@ -283,10 +283,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
||||
int viewLoc = shader.GetUniformLocation("gViewMatrix");
|
||||
int projLoc = shader.GetUniformLocation("gProjectionMatrix");
|
||||
Log("[DEBUG] Uniform locations - gModelMatrix: %d, gViewMatrix: %d, gProjectionMatrix: %d", modelLoc, viewLoc, projLoc);
|
||||
shader.SetMat4("gModelMatrix", modelMatrix);
|
||||
shader.SetMat4("gViewMatrix", viewMatrix);
|
||||
shader.SetMat4("gProjectionMatrix", projectionMatrix);
|
||||
shader.SetInt("uTexture", 0);
|
||||
commandList.SetShader(&shader);
|
||||
commandList.SetUniformMat4("gModelMatrix", modelMatrix);
|
||||
commandList.SetUniformMat4("gViewMatrix", viewMatrix);
|
||||
commandList.SetUniformMat4("gProjectionMatrix", projectionMatrix);
|
||||
commandList.SetUniformInt("uTexture", 0);
|
||||
|
||||
OpenGLTexture texture;
|
||||
if (!texture.LoadFromFile("Res/Image/earth.png", true)) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "fixtures/OpenGLTestFixture.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLShader.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLCommandList.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
|
||||
@@ -102,15 +103,17 @@ TEST_F(OpenGLTestFixture, Shader_SetUniforms) {
|
||||
shader.Compile(vs, fs);
|
||||
ASSERT_TRUE(shader.IsValid());
|
||||
|
||||
shader.Use();
|
||||
auto cmdList = static_cast<OpenGLCommandList*>(GetDevice()->CreateCommandList(CommandListDesc{}));
|
||||
ASSERT_NE(cmdList, nullptr);
|
||||
|
||||
shader.SetInt("uIntValue", 42);
|
||||
shader.SetFloat("uFloatValue", 3.14f);
|
||||
shader.SetVec3("uVec3Value", 1.0f, 2.0f, 3.0f);
|
||||
cmdList->SetShader(&shader);
|
||||
cmdList->SetUniformInt("uIntValue", 42);
|
||||
cmdList->SetUniformFloat("uFloatValue", 3.14f);
|
||||
cmdList->SetUniformVec3("uVec3Value", 1.0f, 2.0f, 3.0f);
|
||||
|
||||
float mat[16] = {};
|
||||
mat[0] = 1.0f; mat[5] = 1.0f; mat[10] = 1.0f; mat[15] = 1.0f;
|
||||
shader.SetMat4("uMat4Value", mat);
|
||||
cmdList->SetUniformMat4("uMat4Value", mat);
|
||||
|
||||
GLenum error = glGetError();
|
||||
EXPECT_EQ(error, GL_NO_ERROR);
|
||||
|
||||
Reference in New Issue
Block a user