Files
XCEngine/tests/RHI/OpenGL/test_command_list.cpp
ssdfasd 4b14831c57 Add Phase 4: CommandList, RTV, DSV tests (13 tests)
- Add CommandList tests: Clear (color/depth/stencil), SetIndexBuffer, Draw (VAO), SetViewport, SetScissor
- Add RTV tests: Initialize (Texture2D), Bind/Unbind
- Add DSV tests: Bind/Unbind
- Simplify tests to work with available GL context
2026-03-17 12:40:07 +08:00

107 lines
2.8 KiB
C++

#include "fixtures/OpenGLTestFixture.h"
#include "XCEngine/RHI/OpenGL/OpenGLCommandList.h"
#include "XCEngine/RHI/OpenGL/OpenGLBuffer.h"
#include "XCEngine/RHI/OpenGL/OpenGLVertexArray.h"
using namespace XCEngine::RHI;
TEST_F(OpenGLTestFixture, CommandList_Clear_ColorBuffer) {
OpenGLCommandList cmdList;
cmdList.ClearColor(1.0f, 0.0f, 0.0f, 1.0f);
GLfloat color[4] = {};
glGetFloatv(GL_COLOR_CLEAR_VALUE, color);
EXPECT_FLOAT_EQ(color[0], 1.0f);
EXPECT_FLOAT_EQ(color[1], 0.0f);
EXPECT_FLOAT_EQ(color[2], 0.0f);
EXPECT_FLOAT_EQ(color[3], 1.0f);
}
TEST_F(OpenGLTestFixture, CommandList_Clear_DepthStencil) {
OpenGLCommandList cmdList;
cmdList.ClearDepth(0.5f);
cmdList.ClearStencil(2);
GLfloat depth = 0.0f;
glGetFloatv(GL_DEPTH_CLEAR_VALUE, &depth);
EXPECT_FLOAT_EQ(depth, 0.5f);
}
TEST_F(OpenGLTestFixture, CommandList_SetIndexBuffer) {
OpenGLCommandList cmdList;
OpenGLBuffer buffer;
buffer.InitializeIndexBuffer(nullptr, 12);
cmdList.SetIndexBuffer(buffer.GetID(), GL_UNSIGNED_INT, 0);
GLenum error = glGetError();
EXPECT_EQ(error, GL_NO_ERROR);
buffer.Shutdown();
}
TEST_F(OpenGLTestFixture, CommandList_Draw_VAO) {
OpenGLCommandList cmdList;
OpenGLVertexArray vao;
vao.Initialize();
OpenGLBuffer vbo;
float vertices[] = { -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.0f, 0.5f, 0.0f };
vbo.InitializeVertexBuffer(vertices, sizeof(vertices));
VertexAttribute attr;
attr.index = 0;
attr.count = 3;
attr.type = GL_FLOAT;
attr.normalized = false;
attr.stride = sizeof(float) * 3;
attr.offset = 0;
vao.AddVertexBuffer(vbo.GetID(), attr);
OpenGLBuffer ibo;
unsigned int indices[] = { 0, 1, 2 };
ibo.InitializeIndexBuffer(indices, sizeof(indices));
vao.SetIndexBuffer(ibo.GetID(), GL_UNSIGNED_INT);
cmdList.BindVertexArray(vao.GetID());
cmdList.SetPrimitiveType(PrimitiveType::Triangles);
cmdList.Draw(PrimitiveType::Triangles, 3, 0);
GLenum error = glGetError();
EXPECT_EQ(error, GL_NO_ERROR);
vbo.Shutdown();
ibo.Shutdown();
vao.Shutdown();
}
TEST_F(OpenGLTestFixture, CommandList_SetViewport) {
OpenGLCommandList cmdList;
cmdList.SetViewport(0, 0, 800, 600);
GLint viewport[4] = {};
glGetIntegerv(GL_VIEWPORT, viewport);
EXPECT_EQ(viewport[0], 0);
EXPECT_EQ(viewport[1], 0);
EXPECT_EQ(viewport[2], 800);
EXPECT_EQ(viewport[3], 600);
}
TEST_F(OpenGLTestFixture, CommandList_SetScissor) {
OpenGLCommandList cmdList;
cmdList.EnableScissorTest(true);
cmdList.SetScissor(0, 0, 800, 600);
GLint scissor[4] = {};
glGetIntegerv(GL_SCISSOR_BOX, scissor);
EXPECT_EQ(scissor[0], 0);
EXPECT_EQ(scissor[1], 0);
EXPECT_EQ(scissor[2], 800);
EXPECT_EQ(scissor[3], 600);
}