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
This commit is contained in:
@@ -28,6 +28,9 @@ set(TEST_SOURCES
|
||||
test_shader.cpp
|
||||
test_pipeline_state.cpp
|
||||
test_vertex_array.cpp
|
||||
test_command_list.cpp
|
||||
test_render_target_view.cpp
|
||||
test_depth_stencil_view.cpp
|
||||
)
|
||||
|
||||
add_executable(opengl_engine_tests ${TEST_SOURCES})
|
||||
|
||||
106
tests/RHI/OpenGL/test_command_list.cpp
Normal file
106
tests/RHI/OpenGL/test_command_list.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#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);
|
||||
}
|
||||
18
tests/RHI/OpenGL/test_depth_stencil_view.cpp
Normal file
18
tests/RHI/OpenGL/test_depth_stencil_view.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "fixtures/OpenGLTestFixture.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLDepthStencilView.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
|
||||
TEST_F(OpenGLTestFixture, DepthStencilView_Bind_Unbind) {
|
||||
OpenGLDepthStencilView dsv;
|
||||
dsv.Initialize(0);
|
||||
|
||||
dsv.Bind();
|
||||
GLint boundFBO = 0;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &boundFBO);
|
||||
|
||||
dsv.Unbind();
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &boundFBO);
|
||||
|
||||
dsv.Shutdown();
|
||||
}
|
||||
39
tests/RHI/OpenGL/test_render_target_view.cpp
Normal file
39
tests/RHI/OpenGL/test_render_target_view.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "fixtures/OpenGLTestFixture.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLRenderTargetView.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLTexture.h"
|
||||
|
||||
using namespace XCEngine::RHI;
|
||||
|
||||
TEST_F(OpenGLTestFixture, RenderTargetView_Initialize_Texture2D) {
|
||||
OpenGLTexture texture;
|
||||
texture.Initialize2D(64, 64, 4, nullptr, false);
|
||||
|
||||
OpenGLRenderTargetView rtv;
|
||||
bool result = rtv.Initialize(texture.GetID());
|
||||
|
||||
ASSERT_TRUE(result);
|
||||
EXPECT_NE(rtv.GetFramebuffer(), 0u);
|
||||
|
||||
rtv.Shutdown();
|
||||
texture.Shutdown();
|
||||
}
|
||||
|
||||
TEST_F(OpenGLTestFixture, RenderTargetView_Bind_Unbind) {
|
||||
OpenGLTexture texture;
|
||||
texture.Initialize2D(64, 64, 4, nullptr, false);
|
||||
|
||||
OpenGLRenderTargetView rtv;
|
||||
rtv.Initialize(texture.GetID());
|
||||
|
||||
rtv.Bind();
|
||||
GLint boundFBO = 0;
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &boundFBO);
|
||||
EXPECT_NE(boundFBO, 0);
|
||||
|
||||
rtv.Unbind();
|
||||
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &boundFBO);
|
||||
EXPECT_EQ(boundFBO, 0);
|
||||
|
||||
rtv.Shutdown();
|
||||
texture.Shutdown();
|
||||
}
|
||||
Reference in New Issue
Block a user