Files
XCEngine/tests/RHI/OpenGL/test_pipeline_state.cpp
ssdfasd 276a9c476a Add Phase 3: Shader, PipelineState, VertexArray tests (11 tests)
- Add Shader tests: VertexFragment, Geometry, InvalidSource, SetUniforms
- Add PipelineState tests: DepthStencilState, BlendState, Viewport/Scissor
- Add VertexArray tests: Initialize, AddVertexBuffer, SetIndexBuffer, Bind/Unbind
2026-03-17 12:31:05 +08:00

69 lines
1.7 KiB
C++

#include "fixtures/OpenGLTestFixture.h"
#include "XCEngine/RHI/OpenGL/OpenGLPipelineState.h"
using namespace XCEngine::RHI;
TEST_F(OpenGLTestFixture, PipelineState_SetDepthStencilState) {
OpenGLPipelineState pipeline;
DepthStencilState state;
state.depthTestEnable = true;
state.depthWriteEnable = true;
state.depthFunc = ComparisonFunc::Less;
pipeline.SetDepthStencilState(state);
pipeline.ApplyDepthStencil();
GLint depthTest = 0;
glGetIntegerv(GL_DEPTH_TEST, &depthTest);
EXPECT_EQ(depthTest, 1);
GLint depthMask = 0;
glGetIntegerv(GL_DEPTH_WRITEMASK, &depthMask);
EXPECT_EQ(depthMask, 1);
}
TEST_F(OpenGLTestFixture, PipelineState_SetBlendState) {
OpenGLPipelineState pipeline;
BlendState state;
state.blendEnable = true;
state.srcBlend = BlendFactor::SrcAlpha;
state.dstBlend = BlendFactor::OneMinusSrcAlpha;
pipeline.SetBlendState(state);
pipeline.ApplyBlend();
GLint blend = 0;
glGetIntegerv(GL_BLEND, &blend);
EXPECT_EQ(blend, 1);
}
TEST_F(OpenGLTestFixture, PipelineState_SetViewport_SetScissor) {
OpenGLPipelineState pipeline;
ViewportState viewport;
viewport.x = 0;
viewport.y = 0;
viewport.width = 800;
viewport.height = 600;
ScissorState scissor;
scissor.enable = true;
scissor.x = 0;
scissor.y = 0;
scissor.width = 800;
scissor.height = 600;
pipeline.SetViewport(viewport);
pipeline.SetScissor(scissor);
pipeline.ApplyViewport();
GLint viewportArr[4] = {};
glGetIntegerv(GL_VIEWPORT, viewportArr);
EXPECT_EQ(viewportArr[0], 0);
EXPECT_EQ(viewportArr[1], 0);
EXPECT_EQ(viewportArr[2], 800);
EXPECT_EQ(viewportArr[3], 600);
}