- Simplify OpenGL integration test structure - Enable CTest registration for OpenGL tests - Refactor test fixtures and device enumeration - Minor code cleanup and improvements
54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include <windows.h>
|
|
#include <glad/glad.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLDevice.h"
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
class OpenGLTestFixture : public ::testing::Test {
|
|
protected:
|
|
void SetUp() override;
|
|
void TearDown() override;
|
|
|
|
HWND GetWindow() { return m_hwnd; }
|
|
HDC GetDC() { return m_hdc; }
|
|
HGLRC GetContext() { return m_hglrc; }
|
|
void MakeContextCurrent();
|
|
void DoneContextCurrent();
|
|
|
|
void ClearGLErrors();
|
|
bool CheckGLError(const char* file, int line);
|
|
const char* GetGLErrorString(GLenum error);
|
|
void ResetGLState();
|
|
|
|
private:
|
|
HWND m_hwnd = nullptr;
|
|
HDC m_hdc = nullptr;
|
|
HGLRC m_hglrc = nullptr;
|
|
OpenGLDevice* m_device = nullptr;
|
|
bool m_ownsWindow = false;
|
|
};
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|
|
|
|
#define GL_CLEAR_ERRORS() \
|
|
do { while (glGetError() != GL_NO_ERROR); } while(0)
|
|
|
|
#define GL_CHECK(call) \
|
|
do { \
|
|
call; \
|
|
ASSERT_TRUE(XCEngine::RHI::OpenGLTestFixture::CheckGLError(__FILE__, __LINE__)) \
|
|
<< "GL error after " << #call; \
|
|
} while(0)
|
|
|
|
#define GL_EXPECT_SUCCESS(call) \
|
|
do { \
|
|
call; \
|
|
EXPECT_EQ(glGetError(), GL_NO_ERROR) \
|
|
<< "GL error after " << #call; \
|
|
} while(0) |