#include "fixtures/OpenGLTestFixture.h" #include "XCEngine/RHI/OpenGL/OpenGLPipelineState.h" using namespace XCEngine::RHI; TEST_F(OpenGLTestFixture, PipelineState_SetDepthStencilState) { OpenGLPipelineState pipeline; OpenGLDepthStencilState 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; OpenGLBlendState state; state.blendEnable = true; state.srcBlend = BlendFactor::SrcAlpha; state.dstBlend = BlendFactor::InvSrcAlpha; pipeline.SetBlendState(state); pipeline.ApplyBlend(); GLint blend = 0; glGetIntegerv(GL_BLEND, &blend); EXPECT_EQ(blend, 1); } TEST_F(OpenGLTestFixture, PipelineState_ApplyDepthStencil_UsesSeparateStencilFaces) { OpenGLPipelineState pipeline; DepthStencilStateDesc state = {}; state.depthTestEnable = true; state.depthWriteEnable = true; state.depthFunc = static_cast(ComparisonFunc::LessEqual); state.stencilEnable = true; state.stencilReadMask = 0x3F; state.stencilWriteMask = 0x1F; state.front.func = static_cast(ComparisonFunc::Equal); state.front.failOp = static_cast(StencilOp::Replace); state.front.passOp = static_cast(StencilOp::Incr); state.front.depthFailOp = static_cast(StencilOp::DecrSat); state.back.func = static_cast(ComparisonFunc::NotEqual); state.back.failOp = static_cast(StencilOp::Invert); state.back.passOp = static_cast(StencilOp::Decr); state.back.depthFailOp = static_cast(StencilOp::Zero); pipeline.SetDepthStencilState(state); pipeline.ApplyDepthStencil(); EXPECT_TRUE(glIsEnabled(GL_STENCIL_TEST)); GLint frontFunc = 0; GLint backFunc = 0; GLint frontRef = 0; GLint backRef = 0; GLint frontValueMask = 0; GLint backValueMask = 0; GLint frontWriteMask = 0; GLint backWriteMask = 0; GLint frontFail = 0; GLint backFail = 0; GLint frontPassDepthPass = 0; GLint backPassDepthPass = 0; glGetIntegerv(GL_STENCIL_FUNC, &frontFunc); glGetIntegerv(GL_STENCIL_BACK_FUNC, &backFunc); glGetIntegerv(GL_STENCIL_REF, &frontRef); glGetIntegerv(GL_STENCIL_BACK_REF, &backRef); glGetIntegerv(GL_STENCIL_VALUE_MASK, &frontValueMask); glGetIntegerv(GL_STENCIL_BACK_VALUE_MASK, &backValueMask); glGetIntegerv(GL_STENCIL_WRITEMASK, &frontWriteMask); glGetIntegerv(GL_STENCIL_BACK_WRITEMASK, &backWriteMask); glGetIntegerv(GL_STENCIL_FAIL, &frontFail); glGetIntegerv(GL_STENCIL_BACK_FAIL, &backFail); glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &frontPassDepthPass); glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_PASS, &backPassDepthPass); EXPECT_EQ(frontFunc, GL_EQUAL); EXPECT_EQ(backFunc, GL_NOTEQUAL); EXPECT_EQ(frontRef, 0); EXPECT_EQ(backRef, 0); EXPECT_EQ(frontValueMask, 0x3F); EXPECT_EQ(backValueMask, 0x3F); EXPECT_EQ(frontWriteMask, 0x1F); EXPECT_EQ(backWriteMask, 0x1F); EXPECT_EQ(frontFail, GL_REPLACE); EXPECT_EQ(backFail, GL_INVERT); EXPECT_EQ(frontPassDepthPass, GL_INCR_WRAP); EXPECT_EQ(backPassDepthPass, GL_DECR_WRAP); } TEST_F(OpenGLTestFixture, PipelineState_ApplyRasterizer_EnablesPolygonOffset) { OpenGLPipelineState pipeline; RasterizerDesc state = {}; state.fillMode = static_cast(FillMode::Solid); state.cullMode = static_cast(CullMode::Back); state.frontFace = static_cast(FrontFace::CounterClockwise); state.slopeScaledDepthBias = 1.5f; state.depthBias = 3; pipeline.SetRasterizerState(state); pipeline.ApplyRasterizer(); EXPECT_TRUE(glIsEnabled(GL_POLYGON_OFFSET_FILL)); GLfloat factor = 0.0f; GLfloat units = 0.0f; glGetFloatv(GL_POLYGON_OFFSET_FACTOR, &factor); glGetFloatv(GL_POLYGON_OFFSET_UNITS, &units); EXPECT_FLOAT_EQ(factor, 1.5f); EXPECT_FLOAT_EQ(units, 3.0f); } 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); }