Add OpenGL test infrastructure - Phase 1: Device, Buffer, Fence tests (17 tests)
- Create test directory structure at tests/RHI/OpenGL/
- Implement OpenGLTestFixture with GLFW/GLAD initialization
- Add Device tests: CreateRenderWindow, InitializeWithExistingWindow, GetDeviceInfo, SwapBuffers, PollEvents
- Add Buffer tests: VertexBuffer, IndexBuffer, UniformBuffer, Dynamic, Bind/Unbind, Map/Unmap
- Add Fence tests: Initialize (signaled/unsignaled), Signal, Wait, IsSignaled, GetStatus
- Add CMakeLists.txt with proper GLFW/GLAD/GTest linking
- Create implementation plan document at docs/OpenGL测试实施计划.md
2026-03-17 12:26:21 +08:00
|
|
|
#include "OpenGLTestFixture.h"
|
|
|
|
|
|
|
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
|
|
2026-03-20 17:37:09 +08:00
|
|
|
static bool s_glfwInitialized = false;
|
|
|
|
|
static bool s_gladInitialized = false;
|
Add OpenGL test infrastructure - Phase 1: Device, Buffer, Fence tests (17 tests)
- Create test directory structure at tests/RHI/OpenGL/
- Implement OpenGLTestFixture with GLFW/GLAD initialization
- Add Device tests: CreateRenderWindow, InitializeWithExistingWindow, GetDeviceInfo, SwapBuffers, PollEvents
- Add Buffer tests: VertexBuffer, IndexBuffer, UniformBuffer, Dynamic, Bind/Unbind, Map/Unmap
- Add Fence tests: Initialize (signaled/unsignaled), Signal, Wait, IsSignaled, GetStatus
- Add CMakeLists.txt with proper GLFW/GLAD/GTest linking
- Create implementation plan document at docs/OpenGL测试实施计划.md
2026-03-17 12:26:21 +08:00
|
|
|
|
2026-03-20 17:37:09 +08:00
|
|
|
void OpenGLTestFixture::SetUp() {
|
|
|
|
|
if (!s_glfwInitialized) {
|
|
|
|
|
if (!glfwInit()) {
|
|
|
|
|
GTEST_SKIP() << "Failed to initialize GLFW";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
|
|
|
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
|
|
|
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
|
|
|
|
|
|
|
|
|
s_glfwInitialized = true;
|
Add OpenGL test infrastructure - Phase 1: Device, Buffer, Fence tests (17 tests)
- Create test directory structure at tests/RHI/OpenGL/
- Implement OpenGLTestFixture with GLFW/GLAD initialization
- Add Device tests: CreateRenderWindow, InitializeWithExistingWindow, GetDeviceInfo, SwapBuffers, PollEvents
- Add Buffer tests: VertexBuffer, IndexBuffer, UniformBuffer, Dynamic, Bind/Unbind, Map/Unmap
- Add Fence tests: Initialize (signaled/unsignaled), Signal, Wait, IsSignaled, GetStatus
- Add CMakeLists.txt with proper GLFW/GLAD/GTest linking
- Create implementation plan document at docs/OpenGL测试实施计划.md
2026-03-17 12:26:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_window = glfwCreateWindow(640, 480, "OpenGL Tests", nullptr, nullptr);
|
|
|
|
|
if (!m_window) {
|
|
|
|
|
GTEST_SKIP() << "Failed to create GLFW window";
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glfwMakeContextCurrent(m_window);
|
2026-03-20 17:37:09 +08:00
|
|
|
|
|
|
|
|
if (!s_gladInitialized) {
|
|
|
|
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
|
|
|
|
GTEST_SKIP() << "Failed to initialize GLAD";
|
|
|
|
|
glfwDestroyWindow(m_window);
|
|
|
|
|
m_window = nullptr;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
s_gladInitialized = true;
|
Add OpenGL test infrastructure - Phase 1: Device, Buffer, Fence tests (17 tests)
- Create test directory structure at tests/RHI/OpenGL/
- Implement OpenGLTestFixture with GLFW/GLAD initialization
- Add Device tests: CreateRenderWindow, InitializeWithExistingWindow, GetDeviceInfo, SwapBuffers, PollEvents
- Add Buffer tests: VertexBuffer, IndexBuffer, UniformBuffer, Dynamic, Bind/Unbind, Map/Unmap
- Add Fence tests: Initialize (signaled/unsignaled), Signal, Wait, IsSignaled, GetStatus
- Add CMakeLists.txt with proper GLFW/GLAD/GTest linking
- Create implementation plan document at docs/OpenGL测试实施计划.md
2026-03-17 12:26:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_device = new OpenGLDevice();
|
|
|
|
|
m_device->CreateRenderWindow(640, 480, "Test Window", false);
|
2026-03-20 17:37:09 +08:00
|
|
|
|
|
|
|
|
ClearGLErrors();
|
Add OpenGL test infrastructure - Phase 1: Device, Buffer, Fence tests (17 tests)
- Create test directory structure at tests/RHI/OpenGL/
- Implement OpenGLTestFixture with GLFW/GLAD initialization
- Add Device tests: CreateRenderWindow, InitializeWithExistingWindow, GetDeviceInfo, SwapBuffers, PollEvents
- Add Buffer tests: VertexBuffer, IndexBuffer, UniformBuffer, Dynamic, Bind/Unbind, Map/Unmap
- Add Fence tests: Initialize (signaled/unsignaled), Signal, Wait, IsSignaled, GetStatus
- Add CMakeLists.txt with proper GLFW/GLAD/GTest linking
- Create implementation plan document at docs/OpenGL测试实施计划.md
2026-03-17 12:26:21 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-20 17:37:09 +08:00
|
|
|
void OpenGLTestFixture::TearDown() {
|
|
|
|
|
ResetGLState();
|
|
|
|
|
|
Add OpenGL test infrastructure - Phase 1: Device, Buffer, Fence tests (17 tests)
- Create test directory structure at tests/RHI/OpenGL/
- Implement OpenGLTestFixture with GLFW/GLAD initialization
- Add Device tests: CreateRenderWindow, InitializeWithExistingWindow, GetDeviceInfo, SwapBuffers, PollEvents
- Add Buffer tests: VertexBuffer, IndexBuffer, UniformBuffer, Dynamic, Bind/Unbind, Map/Unmap
- Add Fence tests: Initialize (signaled/unsignaled), Signal, Wait, IsSignaled, GetStatus
- Add CMakeLists.txt with proper GLFW/GLAD/GTest linking
- Create implementation plan document at docs/OpenGL测试实施计划.md
2026-03-17 12:26:21 +08:00
|
|
|
if (m_device) {
|
|
|
|
|
delete m_device;
|
|
|
|
|
m_device = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_window) {
|
|
|
|
|
glfwDestroyWindow(m_window);
|
|
|
|
|
m_window = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLTestFixture::MakeContextCurrent() {
|
|
|
|
|
if (m_window) {
|
|
|
|
|
glfwMakeContextCurrent(m_window);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLTestFixture::DoneContextCurrent() {
|
|
|
|
|
glfwMakeContextCurrent(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLTestFixture::ClearGLErrors() {
|
|
|
|
|
while (glGetError() != GL_NO_ERROR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OpenGLTestFixture::CheckGLError(const char* file, int line) {
|
|
|
|
|
GLenum error = glGetError();
|
|
|
|
|
if (error != GL_NO_ERROR) {
|
|
|
|
|
ADD_FAILURE() << "OpenGL Error: " << error
|
|
|
|
|
<< " (" << GetGLErrorString(error) << ")"
|
|
|
|
|
<< " at " << file << ":" << line;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* OpenGLTestFixture::GetGLErrorString(GLenum error) {
|
|
|
|
|
switch (error) {
|
|
|
|
|
case GL_NO_ERROR: return "GL_NO_ERROR";
|
|
|
|
|
case GL_INVALID_ENUM: return "GL_INVALID_ENUM";
|
|
|
|
|
case GL_INVALID_VALUE: return "GL_INVALID_VALUE";
|
|
|
|
|
case GL_INVALID_OPERATION: return "GL_INVALID_OPERATION";
|
|
|
|
|
case GL_INVALID_FRAMEBUFFER_OPERATION: return "GL_INVALID_FRAMEBUFFER_OPERATION";
|
|
|
|
|
case GL_OUT_OF_MEMORY: return "GL_OUT_OF_MEMORY";
|
|
|
|
|
default: return "Unknown error";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLTestFixture::ResetGLState() {
|
|
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
|
|
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
|
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
|
|
|
|
|
|
|
|
|
glUseProgram(0);
|
|
|
|
|
|
|
|
|
|
glBindVertexArray(0);
|
|
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
|
|
|
|
|
|
|
|
|
glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
|
|
|
|
|
|
glDepthFunc(GL_LESS);
|
|
|
|
|
glStencilFunc(GL_ALWAYS, 0, 0xFF);
|
|
|
|
|
glBlendFunc(GL_ONE, GL_ZERO);
|
2026-03-20 17:37:09 +08:00
|
|
|
}
|