refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLDevice.h"
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLSwapChain.h"
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLCommandList.h"
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLBuffer.h"
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLVertexArray.h"
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLShader.h"
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLPipelineState.h"
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLTexture.h"
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLSampler.h"
|
|
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLScreenshot.h"
|
|
|
|
|
#include "XCEngine/Debug/Logger.h"
|
|
|
|
|
#include "XCEngine/Debug/ConsoleLogSink.h"
|
2026-03-23 20:25:53 +08:00
|
|
|
#include "XCEngine/Debug/RenderDocCapture.h"
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
#include "XCEngine/Containers/String.h"
|
|
|
|
|
|
|
|
|
|
#pragma comment(lib, "opengl32.lib")
|
|
|
|
|
|
2026-03-23 01:42:48 +08:00
|
|
|
#include <GL/gl.h>
|
|
|
|
|
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
using namespace XCEngine::RHI;
|
|
|
|
|
using namespace XCEngine::Debug;
|
|
|
|
|
using namespace XCEngine::Containers;
|
|
|
|
|
|
|
|
|
|
static const int gWidth = 1280;
|
|
|
|
|
static const int gHeight = 720;
|
|
|
|
|
|
|
|
|
|
void Log(const char* format, ...) {
|
|
|
|
|
char buffer[1024];
|
|
|
|
|
va_list args;
|
|
|
|
|
va_start(args, format);
|
|
|
|
|
vsnprintf(buffer, sizeof(buffer), format, args);
|
|
|
|
|
va_end(args);
|
|
|
|
|
Logger::Get().Debug(LogCategory::Rendering, String(buffer));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
|
switch (msg) {
|
|
|
|
|
case WM_CLOSE:
|
|
|
|
|
PostQuitMessage(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return DefWindowProc(hwnd, msg, wParam, lParam);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IdentityMatrix(float* m) {
|
|
|
|
|
memset(m, 0, 16 * sizeof(float));
|
|
|
|
|
m[0] = m[5] = m[10] = m[15] = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TranslationMatrix(float* m, float x, float y, float z) {
|
|
|
|
|
memset(m, 0, 16 * sizeof(float));
|
|
|
|
|
m[0] = 1.0f; m[12] = x;
|
|
|
|
|
m[5] = 1.0f; m[13] = y;
|
|
|
|
|
m[10] = 1.0f; m[14] = z;
|
|
|
|
|
m[15] = 1.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PerspectiveMatrix(float* m, float fov, float aspect, float nearZ, float farZ) {
|
|
|
|
|
memset(m, 0, 16 * sizeof(float));
|
|
|
|
|
float tanHalfFov = tanf(fov / 2.0f);
|
2026-03-23 01:42:48 +08:00
|
|
|
m[0] = 1.0f / (aspect * tanHalfFov); // m[0][0]
|
|
|
|
|
m[5] = 1.0f / tanHalfFov; // m[1][1]
|
|
|
|
|
m[10] = -(farZ + nearZ) / (farZ - nearZ); // m[2][2]
|
|
|
|
|
m[14] = -(2.0f * farZ * nearZ) / (farZ - nearZ); // m[2][3]
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
m[15] = 0.0f;
|
2026-03-23 01:42:48 +08:00
|
|
|
m[11] = -1.0f; // m[3][2] = -1 for OpenGL clip space
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Vertex {
|
|
|
|
|
float pos[4];
|
|
|
|
|
float texcoord[2];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void GenerateSphere(std::vector<Vertex>& vertices, std::vector<uint32_t>& indices, float radius, int segments) {
|
|
|
|
|
vertices.clear();
|
|
|
|
|
indices.clear();
|
|
|
|
|
|
|
|
|
|
segments = (segments < 3) ? 3 : segments;
|
|
|
|
|
|
|
|
|
|
for (int lat = 0; lat <= segments; ++lat) {
|
|
|
|
|
float phi = static_cast<float>(3.14159265f) * lat / segments;
|
|
|
|
|
float sinPhi = sinf(phi);
|
|
|
|
|
float cosPhi = cosf(phi);
|
|
|
|
|
|
|
|
|
|
for (int lon = 0; lon <= segments; ++lon) {
|
|
|
|
|
float theta = static_cast<float>(2 * 3.14159265f) * lon / segments;
|
|
|
|
|
float sinTheta = sinf(theta);
|
|
|
|
|
float cosTheta = cosf(theta);
|
|
|
|
|
|
|
|
|
|
Vertex v;
|
|
|
|
|
v.pos[0] = radius * sinPhi * cosTheta;
|
|
|
|
|
v.pos[1] = radius * cosPhi;
|
|
|
|
|
v.pos[2] = radius * sinPhi * sinTheta;
|
|
|
|
|
v.pos[3] = 1.0f;
|
|
|
|
|
|
|
|
|
|
v.texcoord[0] = static_cast<float>(lon) / segments;
|
|
|
|
|
v.texcoord[1] = static_cast<float>(lat) / segments;
|
|
|
|
|
|
|
|
|
|
vertices.push_back(v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int lat = 0; lat < segments; ++lat) {
|
|
|
|
|
for (int lon = 0; lon < segments; ++lon) {
|
|
|
|
|
uint32_t topLeft = lat * (segments + 1) + lon;
|
|
|
|
|
uint32_t topRight = topLeft + 1;
|
|
|
|
|
uint32_t bottomLeft = (lat + 1) * (segments + 1) + lon;
|
|
|
|
|
uint32_t bottomRight = bottomLeft + 1;
|
|
|
|
|
|
|
|
|
|
indices.push_back(topLeft);
|
|
|
|
|
indices.push_back(bottomLeft);
|
|
|
|
|
indices.push_back(topRight);
|
|
|
|
|
|
|
|
|
|
indices.push_back(topRight);
|
|
|
|
|
indices.push_back(bottomLeft);
|
|
|
|
|
indices.push_back(bottomRight);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
|
|
|
|
|
Logger::Get().Initialize();
|
|
|
|
|
Logger::Get().AddSink(std::make_unique<ConsoleLogSink>());
|
|
|
|
|
Logger::Get().SetMinimumLevel(LogLevel::Debug);
|
|
|
|
|
|
|
|
|
|
Log("[INFO] OpenGL Sphere Test Starting");
|
|
|
|
|
|
|
|
|
|
WNDCLASSEXW wc = {};
|
|
|
|
|
wc.cbSize = sizeof(WNDCLASSEXW);
|
|
|
|
|
wc.style = CS_HREDRAW | CS_VREDRAW;
|
|
|
|
|
wc.lpfnWndProc = WindowProc;
|
|
|
|
|
wc.hInstance = hInstance;
|
|
|
|
|
wc.lpszClassName = L"XCEngine_OpenGL_Sphere";
|
|
|
|
|
|
|
|
|
|
if (!RegisterClassExW(&wc)) {
|
|
|
|
|
Log("[ERROR] Failed to register window class");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RECT rect = { 0, 0, gWidth, gHeight };
|
|
|
|
|
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
|
|
|
|
|
|
|
|
|
|
HWND hwnd = CreateWindowExW(
|
|
|
|
|
0,
|
|
|
|
|
L"XCEngine_OpenGL_Sphere",
|
|
|
|
|
L"OpenGL Sphere Test",
|
|
|
|
|
WS_OVERLAPPEDWINDOW,
|
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
|
rect.right - rect.left, rect.bottom - rect.top,
|
|
|
|
|
NULL, NULL, hInstance, NULL
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!hwnd) {
|
|
|
|
|
Log("[ERROR] Failed to create window");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 20:25:53 +08:00
|
|
|
RenderDocCapture::Get().Initialize(nullptr, hwnd);
|
|
|
|
|
RenderDocCapture::Get().SetCaptureFilePath(".\\sphere_frame30");
|
|
|
|
|
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
OpenGLDevice device;
|
2026-03-23 21:48:46 +08:00
|
|
|
RHIDeviceDesc desc = {};
|
|
|
|
|
desc.windowHandle = hwnd;
|
|
|
|
|
desc.width = gWidth;
|
|
|
|
|
desc.height = gHeight;
|
|
|
|
|
desc.appName = L"OpenGL_Sphere_Test";
|
|
|
|
|
desc.enableDebugLayer = true;
|
|
|
|
|
if (!device.Initialize(desc)) {
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
Log("[ERROR] Failed to initialize OpenGL device");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 21:48:46 +08:00
|
|
|
RenderDocCapture::Get().SetDevice(device.GetGLContext());
|
2026-03-23 20:25:53 +08:00
|
|
|
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
ShowWindow(hwnd, nShowCmd);
|
|
|
|
|
UpdateWindow(hwnd);
|
|
|
|
|
|
|
|
|
|
Log("[INFO] OpenGL Device: %S", device.GetDeviceInfo().renderer.c_str());
|
|
|
|
|
Log("[INFO] OpenGL Version: %S", device.GetDeviceInfo().version.c_str());
|
|
|
|
|
|
|
|
|
|
OpenGLSwapChain swapChain;
|
2026-03-23 21:48:46 +08:00
|
|
|
swapChain.Initialize(&device, hwnd, gWidth, gHeight);
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
|
|
|
|
|
OpenGLCommandList commandList;
|
|
|
|
|
|
|
|
|
|
std::vector<Vertex> vertices;
|
|
|
|
|
std::vector<uint32_t> indices;
|
|
|
|
|
GenerateSphere(vertices, indices, 1.0f, 32);
|
|
|
|
|
Log("[INFO] Generated %d vertices, %d indices", (int)vertices.size(), (int)indices.size());
|
|
|
|
|
|
|
|
|
|
OpenGLBuffer vertexBuffer;
|
|
|
|
|
if (!vertexBuffer.InitializeVertexBuffer(vertices.data(), (uint32_t)(sizeof(Vertex) * vertices.size()))) {
|
|
|
|
|
Log("[ERROR] Failed to initialize vertex buffer");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
vertexBuffer.SetStride(sizeof(Vertex));
|
|
|
|
|
|
|
|
|
|
OpenGLBuffer indexBuffer;
|
|
|
|
|
if (!indexBuffer.InitializeIndexBuffer(indices.data(), (uint32_t)(sizeof(uint32_t) * indices.size()))) {
|
|
|
|
|
Log("[ERROR] Failed to initialize index buffer");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenGLVertexArray vertexArray;
|
|
|
|
|
vertexArray.Initialize();
|
|
|
|
|
|
|
|
|
|
VertexAttribute posAttr = {};
|
|
|
|
|
posAttr.index = 0;
|
|
|
|
|
posAttr.count = 4;
|
|
|
|
|
posAttr.type = VertexAttributeType::Float;
|
|
|
|
|
posAttr.normalized = VertexAttributeNormalized::False;
|
|
|
|
|
posAttr.stride = sizeof(Vertex);
|
|
|
|
|
posAttr.offset = 0;
|
|
|
|
|
vertexArray.AddVertexBuffer(vertexBuffer.GetID(), posAttr);
|
|
|
|
|
|
|
|
|
|
VertexAttribute texAttr = {};
|
|
|
|
|
texAttr.index = 1;
|
|
|
|
|
texAttr.count = 2;
|
|
|
|
|
texAttr.type = VertexAttributeType::Float;
|
|
|
|
|
texAttr.normalized = VertexAttributeNormalized::False;
|
|
|
|
|
texAttr.stride = sizeof(Vertex);
|
|
|
|
|
texAttr.offset = sizeof(float) * 4;
|
|
|
|
|
vertexArray.AddVertexBuffer(vertexBuffer.GetID(), texAttr);
|
|
|
|
|
|
|
|
|
|
vertexArray.SetIndexBuffer(indexBuffer.GetID(), 0);
|
|
|
|
|
|
|
|
|
|
OpenGLShader shader;
|
|
|
|
|
if (!shader.CompileFromFile("Res/Shader/sphere.vert", "Res/Shader/sphere.frag")) {
|
|
|
|
|
Log("[ERROR] Failed to compile shaders");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
Log("[INFO] Shaders compiled successfully");
|
|
|
|
|
|
|
|
|
|
float modelMatrix[16];
|
|
|
|
|
float viewMatrix[16];
|
|
|
|
|
float projectionMatrix[16];
|
|
|
|
|
|
|
|
|
|
IdentityMatrix(viewMatrix);
|
|
|
|
|
TranslationMatrix(modelMatrix, 0.0f, 0.0f, -5.0f);
|
|
|
|
|
float aspect = 1280.0f / 720.0f;
|
|
|
|
|
PerspectiveMatrix(projectionMatrix, 45.0f * 3.14159265f / 180.0f, aspect, 0.1f, 1000.0f);
|
|
|
|
|
|
2026-03-23 01:42:48 +08:00
|
|
|
Log("[DEBUG] ProjectionMatrix:");
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
|
Log("[DEBUG] row%d: %.4f %.4f %.4f %.4f", i,
|
|
|
|
|
projectionMatrix[i*4], projectionMatrix[i*4+1], projectionMatrix[i*4+2], projectionMatrix[i*4+3]);
|
|
|
|
|
}
|
|
|
|
|
Log("[DEBUG] ModelMatrix:");
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
|
Log("[DEBUG] row%d: %.4f %.4f %.4f %.4f", i,
|
|
|
|
|
modelMatrix[i*4], modelMatrix[i*4+1], modelMatrix[i*4+2], modelMatrix[i*4+3]);
|
|
|
|
|
}
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
|
|
|
|
|
OpenGLPipelineState pipelineState;
|
|
|
|
|
OpenGLRasterizerState rasterizerState;
|
|
|
|
|
rasterizerState.cullFaceEnable = false;
|
|
|
|
|
pipelineState.SetRasterizerState(rasterizerState);
|
|
|
|
|
|
|
|
|
|
OpenGLDepthStencilState depthStencilState;
|
2026-03-23 01:42:48 +08:00
|
|
|
depthStencilState.depthTestEnable = true;
|
|
|
|
|
depthStencilState.depthWriteEnable = true;
|
|
|
|
|
depthStencilState.depthFunc = ComparisonFunc::Less;
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
pipelineState.SetDepthStencilState(depthStencilState);
|
|
|
|
|
|
|
|
|
|
ViewportState viewportState = { 0.0f, 0.0f, (float)gWidth, (float)gHeight, 0.0f, 1.0f };
|
|
|
|
|
pipelineState.SetViewport(viewportState);
|
|
|
|
|
|
|
|
|
|
pipelineState.AttachShader(shader.GetID());
|
|
|
|
|
pipelineState.Apply();
|
|
|
|
|
|
2026-03-23 01:42:48 +08:00
|
|
|
Log("[DEBUG] Shader program ID: %u", shader.GetID());
|
|
|
|
|
int modelLoc = shader.GetUniformLocation("gModelMatrix");
|
|
|
|
|
int viewLoc = shader.GetUniformLocation("gViewMatrix");
|
|
|
|
|
int projLoc = shader.GetUniformLocation("gProjectionMatrix");
|
|
|
|
|
Log("[DEBUG] Uniform locations - gModelMatrix: %d, gViewMatrix: %d, gProjectionMatrix: %d", modelLoc, viewLoc, projLoc);
|
|
|
|
|
shader.SetMat4("gModelMatrix", modelMatrix);
|
|
|
|
|
shader.SetMat4("gViewMatrix", viewMatrix);
|
|
|
|
|
shader.SetMat4("gProjectionMatrix", projectionMatrix);
|
|
|
|
|
shader.SetInt("uTexture", 0);
|
|
|
|
|
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
OpenGLTexture texture;
|
|
|
|
|
if (!texture.LoadFromFile("Res/Image/earth.png", true)) {
|
|
|
|
|
Log("[ERROR] Failed to load texture");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
Log("[INFO] Texture loaded successfully");
|
|
|
|
|
|
|
|
|
|
OpenGLSampler sampler;
|
|
|
|
|
OpenGLSamplerDesc samplerDesc = {};
|
|
|
|
|
samplerDesc.minFilter = SamplerFilter::Linear;
|
|
|
|
|
samplerDesc.magFilter = SamplerFilter::Linear;
|
|
|
|
|
samplerDesc.wrapS = SamplerWrapMode::ClampToEdge;
|
|
|
|
|
samplerDesc.wrapT = SamplerWrapMode::ClampToEdge;
|
|
|
|
|
sampler.Initialize(samplerDesc);
|
|
|
|
|
|
|
|
|
|
MSG msg = {};
|
|
|
|
|
int frameCount = 0;
|
2026-03-23 21:48:46 +08:00
|
|
|
const int captureStartFrame = 25;
|
|
|
|
|
const int captureEndFrame = 35;
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
|
2026-03-23 01:42:48 +08:00
|
|
|
int renderCount = 0;
|
2026-03-23 21:48:46 +08:00
|
|
|
while (frameCount < captureEndFrame) {
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
if (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) {
|
|
|
|
|
if (msg.message == WM_QUIT) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
|
DispatchMessageW(&msg);
|
|
|
|
|
} else {
|
2026-03-23 21:48:46 +08:00
|
|
|
wglMakeCurrent(device.GetPresentationDC(), device.GetGLContext());
|
|
|
|
|
|
2026-03-23 01:42:48 +08:00
|
|
|
renderCount++;
|
|
|
|
|
GLenum err = glGetError();
|
|
|
|
|
if (err != GL_NO_ERROR) Log("[DEBUG] GL error before clear: 0x%x", err);
|
|
|
|
|
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
commandList.SetViewport(0, 0, gWidth, gHeight);
|
2026-03-23 01:42:48 +08:00
|
|
|
commandList.Clear(0.0f, 0.0f, 1.0f, 1.0f, 1 | 2); // COLOR_BUFFER | DEPTH_BUFFER
|
|
|
|
|
|
|
|
|
|
err = glGetError();
|
|
|
|
|
if (err != GL_NO_ERROR) Log("[DEBUG] GL error after clear: 0x%x", err);
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
|
|
|
|
|
pipelineState.Bind();
|
|
|
|
|
|
2026-03-23 01:42:48 +08:00
|
|
|
err = glGetError();
|
|
|
|
|
if (err != GL_NO_ERROR) Log("[DEBUG] GL error after pipeline bind: 0x%x", err);
|
|
|
|
|
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
indexBuffer.Bind();
|
|
|
|
|
vertexArray.Bind();
|
|
|
|
|
|
|
|
|
|
texture.Bind(0);
|
|
|
|
|
sampler.Bind(0);
|
|
|
|
|
|
2026-03-23 01:42:48 +08:00
|
|
|
err = glGetError();
|
|
|
|
|
if (err != GL_NO_ERROR) Log("[DEBUG] GL error before draw: 0x%x", err);
|
|
|
|
|
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
commandList.DrawIndexed(PrimitiveType::Triangles, (uint32_t)indices.size(), 0, 0);
|
|
|
|
|
|
|
|
|
|
swapChain.Present(0, 0);
|
|
|
|
|
frameCount++;
|
2026-03-23 20:25:53 +08:00
|
|
|
|
2026-03-23 21:48:46 +08:00
|
|
|
if (frameCount == captureStartFrame) {
|
|
|
|
|
RenderDocCapture::Get().BeginCapture("OpenGL_Sphere_Test");
|
|
|
|
|
Log("[INFO] RenderDoc capture started at frame %d", frameCount);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (frameCount == captureEndFrame) {
|
|
|
|
|
RenderDocCapture::Get().EndCapture();
|
|
|
|
|
Log("[INFO] RenderDoc capture ended at frame %d", frameCount);
|
|
|
|
|
break;
|
2026-03-23 20:25:53 +08:00
|
|
|
}
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-23 21:48:46 +08:00
|
|
|
Log("[INFO] Rendered %d frames (capture was %d-%d)", renderCount, captureStartFrame, captureEndFrame);
|
|
|
|
|
Log("[INFO] Capture complete - taking screenshot!");
|
2026-03-23 01:42:48 +08:00
|
|
|
|
|
|
|
|
char exePath[MAX_PATH];
|
|
|
|
|
GetModuleFileNameA(NULL, exePath, MAX_PATH);
|
|
|
|
|
char* lastSlash = strrchr(exePath, '\\');
|
|
|
|
|
if (lastSlash) *lastSlash = '\0';
|
|
|
|
|
strcat_s(exePath, "\\sphere.ppm");
|
|
|
|
|
OpenGLScreenshot::Capture(device, swapChain, exePath);
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
|
|
|
|
|
sampler.Shutdown();
|
|
|
|
|
texture.Shutdown();
|
|
|
|
|
indexBuffer.Shutdown();
|
|
|
|
|
vertexArray.Shutdown();
|
|
|
|
|
vertexBuffer.Shutdown();
|
|
|
|
|
shader.Shutdown();
|
|
|
|
|
pipelineState.Shutdown();
|
|
|
|
|
|
|
|
|
|
swapChain.Shutdown();
|
|
|
|
|
device.Shutdown();
|
2026-03-23 20:25:53 +08:00
|
|
|
|
|
|
|
|
RenderDocCapture::Get().Shutdown();
|
refactor: improve test infrastructure and fix OpenGL GLAD initialization
- Rename D3D12Enum.h to D3D12Enums.h for naming consistency
- Fix OpenGL unit test GLAD initialization by using gladLoadGL()
instead of gladLoadGLLoader(wglGetProcAddress) for fallback support
- Migrate remaining tests to use gtest_discover_tests for granular
test discovery (math, core, containers, memory, threading, debug,
components, scene, resources, input, opengl)
- Remove obsolete TEST_RESOURCES_DIR and copy_directory commands
from OpenGL unit test CMakeLists (minimal/Res doesn't exist)
- Update TEST_SPEC.md with performance metrics and per-module
build/test commands for faster development workflow
- Update CMake path references to use lowercase paths
2026-03-23 00:43:02 +08:00
|
|
|
Logger::Get().Shutdown();
|
|
|
|
|
|
|
|
|
|
Log("[INFO] OpenGL Sphere Test Finished");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|