fix(RHI): 修复 OpenGL 测试接口不匹配问题

- 修复 RHIDeviceInfo 缺少 majorVersion/minorVersion
- 修复 OpenGLTexture 使用 GetTextureType 替代 GetType
- 修复 OpenGLSampler 使用 OpenGLSamplerDesc
- 修复 BlendFactor::OneMinusSrcAlpha -> InvSrcAlpha
- 修复 OpenGLRenderTargetViewDesc/OpenGLDepthStencilViewDesc 重定义问题
- 恢复 OpenGL 测试文件到 CMakeLists
This commit is contained in:
2026-03-17 19:43:20 +08:00
parent 94bf04f06c
commit 0a2f8050e5
9 changed files with 23 additions and 21 deletions

View File

@@ -19,7 +19,7 @@ enum class DepthStencilType {
TextureCube TextureCube
}; };
struct DepthStencilViewDesc { struct OpenGLDepthStencilViewDesc {
DepthStencilType type = DepthStencilType::Texture2D; DepthStencilType type = DepthStencilType::Texture2D;
int mipLevel = 0; int mipLevel = 0;
int baseArraySlice = 0; int baseArraySlice = 0;
@@ -32,7 +32,7 @@ public:
OpenGLDepthStencilView(); OpenGLDepthStencilView();
~OpenGLDepthStencilView(); ~OpenGLDepthStencilView();
bool Initialize(unsigned int texture, const DepthStencilViewDesc& desc); bool Initialize(unsigned int texture, const OpenGLDepthStencilViewDesc& desc);
bool Initialize(unsigned int texture, int mipLevel = 0); bool Initialize(unsigned int texture, int mipLevel = 0);
bool InitializeCubemap(unsigned int cubemap, int face, int mipLevel = 0); bool InitializeCubemap(unsigned int cubemap, int face, int mipLevel = 0);
void Shutdown(); void Shutdown();

View File

@@ -15,7 +15,7 @@ enum class RenderTargetType {
TextureCubeArray TextureCubeArray
}; };
struct RenderTargetViewDesc { struct OpenGLRenderTargetViewDesc {
RenderTargetType type = RenderTargetType::Texture2D; RenderTargetType type = RenderTargetType::Texture2D;
int mipLevel = 0; int mipLevel = 0;
int baseArraySlice = 0; int baseArraySlice = 0;
@@ -29,7 +29,7 @@ public:
OpenGLRenderTargetView(); OpenGLRenderTargetView();
~OpenGLRenderTargetView(); ~OpenGLRenderTargetView();
bool Initialize(unsigned int texture, const RenderTargetViewDesc& desc); bool Initialize(unsigned int texture, const OpenGLRenderTargetViewDesc& desc);
bool Initialize(unsigned int texture, int mipLevel = 0); bool Initialize(unsigned int texture, int mipLevel = 0);
bool InitializeCubemap(unsigned int cubemap, int face, int mipLevel = 0); bool InitializeCubemap(unsigned int cubemap, int face, int mipLevel = 0);
void Shutdown(); void Shutdown();

View File

@@ -253,6 +253,8 @@ struct RHIDeviceInfo {
std::wstring vendor; std::wstring vendor;
std::wstring renderer; std::wstring renderer;
std::wstring version; std::wstring version;
uint32_t majorVersion = 0;
uint32_t minorVersion = 0;
uint64_t dedicatedVideoMemory = 0; uint64_t dedicatedVideoMemory = 0;
uint64_t dedicatedSystemMemory = 0; uint64_t dedicatedSystemMemory = 0;
uint64_t sharedSystemMemory = 0; uint64_t sharedSystemMemory = 0;

View File

@@ -20,7 +20,7 @@ OpenGLDepthStencilView::~OpenGLDepthStencilView() {
Shutdown(); Shutdown();
} }
bool OpenGLDepthStencilView::Initialize(unsigned int texture, const DepthStencilViewDesc& desc) { bool OpenGLDepthStencilView::Initialize(unsigned int texture, const OpenGLDepthStencilViewDesc& desc) {
m_texture = texture; m_texture = texture;
m_mipLevel = desc.mipLevel; m_mipLevel = desc.mipLevel;
m_type = desc.type; m_type = desc.type;
@@ -53,7 +53,7 @@ bool OpenGLDepthStencilView::Initialize(unsigned int texture, const DepthStencil
} }
bool OpenGLDepthStencilView::Initialize(unsigned int texture, int mipLevel) { bool OpenGLDepthStencilView::Initialize(unsigned int texture, int mipLevel) {
DepthStencilViewDesc desc; OpenGLDepthStencilViewDesc desc;
desc.mipLevel = mipLevel; desc.mipLevel = mipLevel;
return Initialize(texture, desc); return Initialize(texture, desc);
} }

View File

@@ -30,7 +30,7 @@ OpenGLRenderTargetView::~OpenGLRenderTargetView() {
Shutdown(); Shutdown();
} }
bool OpenGLRenderTargetView::Initialize(unsigned int texture, const RenderTargetViewDesc& desc) { bool OpenGLRenderTargetView::Initialize(unsigned int texture, const OpenGLRenderTargetViewDesc& desc) {
m_texture = texture; m_texture = texture;
m_mipLevel = desc.mipLevel; m_mipLevel = desc.mipLevel;
m_type = desc.type; m_type = desc.type;
@@ -69,7 +69,7 @@ bool OpenGLRenderTargetView::Initialize(unsigned int texture, const RenderTarget
} }
bool OpenGLRenderTargetView::Initialize(unsigned int texture, int mipLevel) { bool OpenGLRenderTargetView::Initialize(unsigned int texture, int mipLevel) {
RenderTargetViewDesc desc; OpenGLRenderTargetViewDesc desc;
desc.type = RenderTargetType::Texture2D; desc.type = RenderTargetType::Texture2D;
desc.mipLevel = mipLevel; desc.mipLevel = mipLevel;
return Initialize(texture, desc); return Initialize(texture, desc);

View File

@@ -20,17 +20,17 @@ find_package(GTest REQUIRED)
set(TEST_SOURCES set(TEST_SOURCES
${CMAKE_SOURCE_DIR}/tests/OpenGL/package/src/glad.c ${CMAKE_SOURCE_DIR}/tests/OpenGL/package/src/glad.c
fixtures/OpenGLTestFixture.cpp fixtures/OpenGLTestFixture.cpp
# test_device.cpp # RHIDeviceInfo 不匹配 test_device.cpp
# test_buffer.cpp # test_buffer.cpp
# test_fence.cpp # test_fence.cpp
# test_texture.cpp # OpenGLTexture 缺少 GetType test_texture.cpp
# test_sampler.cpp # SamplerDesc 类型不匹配 test_sampler.cpp
# test_shader.cpp # test_shader.cpp
# test_pipeline_state.cpp # BlendFunc 枚举问题 test_pipeline_state.cpp
test_vertex_array.cpp test_vertex_array.cpp
test_command_list.cpp test_command_list.cpp
# test_render_target_view.cpp # 结构体重定义 test_render_target_view.cpp
# test_depth_stencil_view.cpp # 结构体重定义 test_depth_stencil_view.cpp
test_swap_chain.cpp test_swap_chain.cpp
) )

View File

@@ -29,7 +29,7 @@ TEST_F(OpenGLTestFixture, PipelineState_SetBlendState) {
BlendState state; BlendState state;
state.blendEnable = true; state.blendEnable = true;
state.srcBlend = BlendFactor::SrcAlpha; state.srcBlend = BlendFactor::SrcAlpha;
state.dstBlend = BlendFactor::OneMinusSrcAlpha; state.dstBlend = BlendFactor::InvSrcAlpha;
pipeline.SetBlendState(state); pipeline.SetBlendState(state);
pipeline.ApplyBlend(); pipeline.ApplyBlend();

View File

@@ -5,7 +5,7 @@ using namespace XCEngine::RHI;
TEST_F(OpenGLTestFixture, Sampler_Initialize_Default) { TEST_F(OpenGLTestFixture, Sampler_Initialize_Default) {
OpenGLSampler sampler; OpenGLSampler sampler;
SamplerDesc desc; OpenGLSamplerDesc desc;
bool result = sampler.Initialize(desc); bool result = sampler.Initialize(desc);
@@ -17,7 +17,7 @@ TEST_F(OpenGLTestFixture, Sampler_Initialize_Default) {
TEST_F(OpenGLTestFixture, Sampler_Initialize_Custom) { TEST_F(OpenGLTestFixture, Sampler_Initialize_Custom) {
OpenGLSampler sampler; OpenGLSampler sampler;
SamplerDesc desc; OpenGLSamplerDesc desc;
desc.minFilter = SamplerFilter::LinearMipmapLinear; desc.minFilter = SamplerFilter::LinearMipmapLinear;
desc.magFilter = SamplerFilter::Linear; desc.magFilter = SamplerFilter::Linear;
desc.wrapS = SamplerWrapMode::Repeat; desc.wrapS = SamplerWrapMode::Repeat;
@@ -34,7 +34,7 @@ TEST_F(OpenGLTestFixture, Sampler_Initialize_Custom) {
TEST_F(OpenGLTestFixture, Sampler_Bind_Unbind) { TEST_F(OpenGLTestFixture, Sampler_Bind_Unbind) {
OpenGLSampler sampler; OpenGLSampler sampler;
SamplerDesc desc; OpenGLSamplerDesc desc;
sampler.Initialize(desc); sampler.Initialize(desc);
sampler.Bind(0); sampler.Bind(0);
@@ -51,7 +51,7 @@ TEST_F(OpenGLTestFixture, Sampler_Bind_Unbind) {
TEST_F(OpenGLTestFixture, Sampler_GetID_ReturnsValid) { TEST_F(OpenGLTestFixture, Sampler_GetID_ReturnsValid) {
OpenGLSampler sampler; OpenGLSampler sampler;
SamplerDesc desc; OpenGLSamplerDesc desc;
sampler.Initialize(desc); sampler.Initialize(desc);
EXPECT_NE(sampler.GetID(), 0u); EXPECT_NE(sampler.GetID(), 0u);

View File

@@ -12,7 +12,7 @@ TEST_F(OpenGLTestFixture, Texture_Initialize_2DTexture) {
EXPECT_NE(texture.GetID(), 0u); EXPECT_NE(texture.GetID(), 0u);
EXPECT_EQ(texture.GetWidth(), 64); EXPECT_EQ(texture.GetWidth(), 64);
EXPECT_EQ(texture.GetHeight(), 64); EXPECT_EQ(texture.GetHeight(), 64);
EXPECT_EQ(texture.GetType(), OpenGLTextureType::Texture2D); EXPECT_EQ(texture.GetTextureType(), TextureType::Texture2D);
texture.Shutdown(); texture.Shutdown();
} }
@@ -26,7 +26,7 @@ TEST_F(OpenGLTestFixture, Texture_Initialize_CubeMap) {
EXPECT_NE(texture.GetID(), 0u); EXPECT_NE(texture.GetID(), 0u);
EXPECT_EQ(texture.GetWidth(), 64); EXPECT_EQ(texture.GetWidth(), 64);
EXPECT_EQ(texture.GetHeight(), 64); EXPECT_EQ(texture.GetHeight(), 64);
EXPECT_EQ(texture.GetType(), OpenGLTextureType::TextureCube); EXPECT_EQ(texture.GetTextureType(), TextureType::TextureCube);
texture.Shutdown(); texture.Shutdown();
} }