Files
DX12/EngineTest/TestRenderer.cpp
SpecialX 80cb696a3c fix(d3d12): 修复 Surface 重复释放问题,完善容器文档
- 改用 utl::free_list 管理 surface,避免 vector 扩容导致的资源重复释放
- 为 d3d12_surface 添加移动语义,禁用拷贝构造
- 添加撕裂检测支持(DXGI_PRESENT_ALLOW_TEARING)
- 为 FreeList.h 和 Vector.h 添加完整的 Doxygen 中文注释
- 更新 D3D12 学习 Wiki,添加 free_list 章节
2026-03-31 16:49:25 +08:00

137 lines
2.8 KiB
C++

/**
* @file TestRenderer.cpp
* @brief 渲染功能综合测试实现。
*/
#include "Test.h"
#include "TestRenderer.h"
#include "Graphics/Renderer.h"
#include "Platform/Platform.h"
#include "Platform/PlatformTypes.h"
#include <filesystem>
#include <fstream>
#ifdef TEST_RENDERER
using namespace XEngine;
time_it timer{};
graphics::render_surface _surfaces[4];
void destroy_render_surface(graphics::render_surface& surface);
LRESULT win_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
bool toggle_fullscreen{ false };
switch (msg)
{
case WM_DESTROY:
{
bool all_closed{ true };
for (u32 i{ 0 }; i < _countof(_surfaces); ++i)
{
if(_surfaces[i].window.is_valid()){
if(_surfaces[i].window.is_closed())
{
destroy_render_surface(_surfaces[i]);
}
else
{
all_closed = false;
}
}
}
if (all_closed)
{
PostQuitMessage(0);
return 0;
}
break;
}
case WM_SYSCHAR:
{
if(wparam == VK_RETURN && (HIWORD(lparam) & KF_ALTDOWN))
{
platform::window win{ platform::window_id{(id::id_type)GetWindowLongPtr(hwnd, GWLP_USERDATA)} };
win.set_fullscreen(!win.is_fullscreen());
return 0;
}
break;
}
case WM_KEYDOWN:
if(wparam == VK_ESCAPE)
{
PostMessage(hwnd,WM_CLOSE,0,0);
return 0;
}
}
return DefWindowProc(hwnd, msg, wparam, lparam);
}
void
create_render_surface(graphics::render_surface& surface, const platform::window_init_info info)
{
surface.window = platform::create_window(&info);
surface.surface = graphics::create_surface(surface.window);
}
void
destroy_render_surface(graphics::render_surface& surface)
{
graphics::render_surface temp{surface};
surface = {};
if(temp.surface.is_valid())graphics::remove_surface(temp.surface.get_id());
if(temp.window.is_valid())platform::remove_window(temp.window.get_id());
}
bool
engine_test::initialize()
{
bool result{ graphics::initialize(graphics::graphics_platform::direct3d12) };
if (!result)
{
return result;
}
platform::window_init_info info[]
{
{&win_proc, nullptr, L"Test Window 1", 200, 100,400,400},
{&win_proc, nullptr, L"Test Window 2", 700, 100,400,400},
{&win_proc, nullptr, L"Test Window 2", 700, 100,400,400},
{&win_proc, nullptr, L"Test Window 3", 1200,100,400,400},
};
static_assert(_countof(info) == _countof(_surfaces));
for (u32 i{ 0 }; i < _countof(_surfaces); ++i)
{
create_render_surface(_surfaces[i], info[i]);
}
return result;
}
void
engine_test::run()
{
timer.begin();
//std::this_thread::sleep_for(std::chrono::milliseconds(10));
for (u32 i{ 0 }; i < _countof(_surfaces); ++i)
{
if(_surfaces[i].surface.is_valid())
{
_surfaces[i].surface.render();
}
}
timer.end();
}
bool
engine_test::shutdown()
{
for (u32 i{ 0 }; i < _countof(_surfaces); ++i)
{
destroy_render_surface(_surfaces[i]);
}
graphics::shutdown();
return true;
}
#endif // TEST_RENDERER