From 1d181f1109a14211fec02e9458f3e0905bb17fd7 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Tue, 17 Mar 2026 12:27:47 +0800 Subject: [PATCH] Add Phase 2: Texture and Sampler tests (9 tests) - Add Texture tests: 2DTexture, CubeMap, Bind/Unbind, GenerateMipmap, SetFiltering/SetWrapping - Add Sampler tests: Initialize (default/custom), Bind/Unbind, GetID --- tests/RHI/OpenGL/CMakeLists.txt | 2 + tests/RHI/OpenGL/test_sampler.cpp | 60 +++++++++++++++++++++++++ tests/RHI/OpenGL/test_texture.cpp | 73 +++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+) create mode 100644 tests/RHI/OpenGL/test_sampler.cpp create mode 100644 tests/RHI/OpenGL/test_texture.cpp diff --git a/tests/RHI/OpenGL/CMakeLists.txt b/tests/RHI/OpenGL/CMakeLists.txt index 4f210b8b..4d95cf7e 100644 --- a/tests/RHI/OpenGL/CMakeLists.txt +++ b/tests/RHI/OpenGL/CMakeLists.txt @@ -23,6 +23,8 @@ set(TEST_SOURCES test_device.cpp test_buffer.cpp test_fence.cpp + test_texture.cpp + test_sampler.cpp ) add_executable(opengl_engine_tests ${TEST_SOURCES}) diff --git a/tests/RHI/OpenGL/test_sampler.cpp b/tests/RHI/OpenGL/test_sampler.cpp new file mode 100644 index 00000000..61c446f9 --- /dev/null +++ b/tests/RHI/OpenGL/test_sampler.cpp @@ -0,0 +1,60 @@ +#include "fixtures/OpenGLTestFixture.h" +#include "XCEngine/RHI/OpenGL/OpenGLSampler.h" + +using namespace XCEngine::RHI; + +TEST_F(OpenGLTestFixture, Sampler_Initialize_Default) { + OpenGLSampler sampler; + SamplerDesc desc; + + bool result = sampler.Initialize(desc); + + ASSERT_TRUE(result); + EXPECT_NE(sampler.GetID(), 0u); + + sampler.Shutdown(); +} + +TEST_F(OpenGLTestFixture, Sampler_Initialize_Custom) { + OpenGLSampler sampler; + SamplerDesc desc; + desc.minFilter = SamplerFilter::LinearMipmapLinear; + desc.magFilter = SamplerFilter::Linear; + desc.wrapS = SamplerWrapMode::Repeat; + desc.wrapT = SamplerWrapMode::Repeat; + desc.wrapR = SamplerWrapMode::ClampToEdge; + + bool result = sampler.Initialize(desc); + + ASSERT_TRUE(result); + EXPECT_NE(sampler.GetID(), 0u); + + sampler.Shutdown(); +} + +TEST_F(OpenGLTestFixture, Sampler_Bind_Unbind) { + OpenGLSampler sampler; + SamplerDesc desc; + sampler.Initialize(desc); + + sampler.Bind(0); + GLint boundSampler = 0; + glGetIntegerv(GL_SAMPLER_BINDING, &boundSampler); + EXPECT_EQ(boundSampler, static_cast(sampler.GetID())); + + sampler.Unbind(0); + glGetIntegerv(GL_SAMPLER_BINDING, &boundSampler); + EXPECT_EQ(boundSampler, 0); + + sampler.Shutdown(); +} + +TEST_F(OpenGLTestFixture, Sampler_GetID_ReturnsValid) { + OpenGLSampler sampler; + SamplerDesc desc; + sampler.Initialize(desc); + + EXPECT_NE(sampler.GetID(), 0u); + + sampler.Shutdown(); +} diff --git a/tests/RHI/OpenGL/test_texture.cpp b/tests/RHI/OpenGL/test_texture.cpp new file mode 100644 index 00000000..3cffa521 --- /dev/null +++ b/tests/RHI/OpenGL/test_texture.cpp @@ -0,0 +1,73 @@ +#include "fixtures/OpenGLTestFixture.h" +#include "XCEngine/RHI/OpenGL/OpenGLTexture.h" + +using namespace XCEngine::RHI; + +TEST_F(OpenGLTestFixture, Texture_Initialize_2DTexture) { + OpenGLTexture texture; + + bool result = texture.Initialize2D(64, 64, 4, nullptr, false); + + ASSERT_TRUE(result); + EXPECT_NE(texture.GetID(), 0u); + EXPECT_EQ(texture.GetWidth(), 64); + EXPECT_EQ(texture.GetHeight(), 64); + EXPECT_EQ(texture.GetType(), OpenGLTextureType::Texture2D); + + texture.Shutdown(); +} + +TEST_F(OpenGLTestFixture, Texture_Initialize_CubeMap) { + OpenGLTexture texture; + + bool result = texture.InitializeCubeMap(64, 1, OpenGLFormat::RGBA8, nullptr); + + ASSERT_TRUE(result); + EXPECT_NE(texture.GetID(), 0u); + EXPECT_EQ(texture.GetWidth(), 64); + EXPECT_EQ(texture.GetHeight(), 64); + EXPECT_EQ(texture.GetType(), OpenGLTextureType::TextureCube); + + texture.Shutdown(); +} + +TEST_F(OpenGLTestFixture, Texture_Bind_Unbind) { + OpenGLTexture texture; + texture.Initialize2D(64, 64, 4, nullptr, false); + + texture.Bind(0); + GLint boundTexture = 0; + glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTexture); + EXPECT_EQ(boundTexture, static_cast(texture.GetID())); + + texture.Unbind(); + glGetIntegerv(GL_TEXTURE_BINDING_2D, &boundTexture); + EXPECT_EQ(boundTexture, 0); + + texture.Shutdown(); +} + +TEST_F(OpenGLTestFixture, Texture_GenerateMipmap) { + OpenGLTexture texture; + texture.Initialize2D(64, 64, 4, nullptr, false); + + texture.GenerateMipmap(); + + GLenum error = glGetError(); + EXPECT_EQ(error, GL_NO_ERROR); + + texture.Shutdown(); +} + +TEST_F(OpenGLTestFixture, Texture_SetFiltering_SetWrapping) { + OpenGLTexture texture; + texture.Initialize2D(64, 64, 4, nullptr, false); + + texture.SetFiltering(GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR); + texture.SetWrapping(GL_REPEAT, GL_REPEAT, GL_REPEAT); + + GLenum error = glGetError(); + EXPECT_EQ(error, GL_NO_ERROR); + + texture.Shutdown(); +}