3d游戏引擎EngineTest的系统实现3

1.TestRenderer.h

#pragma once

#include "Test.h"

class engine_test : public test

{

public:

bool initialize() override;

void run() override;

void shutdown() override;

};

2.TestRenderer.cpp

#include "..\Platform\PlatformTypes.h"

#include "..\Platform\Platform.h"

#include "../Graphics/Renderer.h"

#include "TestRenderer.h"

#include "ShaderCompilation.h"

#if TEST_RENDERER

template <bool test,typename T = void>

struct enable_if {};

template <typename T>

struct enable_if<true, T> { using type = T; };

template <bool test, typename T = void>

using enable_if_t = typename enable_if<test, T>::type;

template<typename T>

using iterator_cat_t = typename std::iterator_traits<T>::iterator_category;

template<typename T>

using void_t = void;

template <typename T,typename=void>

constexpr bool is_iterator_v = false;

template<typename T>

constexpr bool is_iterator_v<T, void_t<iterator_cat_t<T>>> = true;

template<typename T, enable_if_t<is_iterator_v<T>, int> = 0>

void function(T t)

{

}

void function(int T)

{

}

using namespace primal;

graphics::render_surface _surfaces[4];

time_it timer{};

void destroy_render_surface(graphics::render_surface& surface);

LRESULT win_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)

{

function(1234);

function(&hwnd);

switch (msg)

{

case WM_DESTROY:

{

bool all_closed{ true };

for (u32 i{ 0 }; i < _countof(_surfaces); ++i) {

for (u32 i{ 0 }; i < _countof(_surfaces); ++i)

{

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, 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 = {};

//graphics::remove_surface(surface.surface.get_id());

//platform::remove_window(surface.window.get_id());

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()

{

while (!compile_shaders())

{

if (MessageBox(nullptr, L"Failed to compile engine shaders.", L"Shader Compilation Error", MB_RETRYCANCEL) != IDRETRY)

return false;

}

if (!graphics::initialize(graphics::graphics_platform::direct3d12)) return false;

//if (!result) return result;

platform::window_init_info info[]

{

{&win_proc,nullptr,L"RenderWindow 1",100 - 2000,100 - 700,400,800 },

{&win_proc,nullptr,L"RenderWindow 2",150 - 2000,150 - 700,800,400 },

{&win_proc,nullptr,L"RenderWindow 3",200 - 2000,200 - 700,400,400 },

{&win_proc,nullptr,L"RenderWindow 4",250 - 2000,250 - 700,800,600 },

};

static_assert(_countof(info) == _countof(_surfaces));

for (u32 i{ 0 }; i < _countof(_surfaces); ++i)

create_render_surface(_surfaces[i], info[i]);

return true;

}

void engine_test::run()

{

timer.begin();

std::this_thread::sleep_for(std::chrono::milliseconds(10));

//graphics::render();

for (u32 i{ 0 }; i < _countof(_surfaces); ++i)

{

if (_surfaces[i].surface.is_valid())

{

_surfaces[i].surface.render();

}

}

timer.end();

}

void engine_test::shutdown()

{

for (u32 i{ 0 }; i < _countof(_surfaces); ++i)

destroy_render_surface(_surfaces[i]);

graphics::shutdown();

}

#endif

相关推荐
程序猿零零漆几秒前
飞算JavaAI:革新Java开发的智能助手
java·飞算javaai
我是唐青枫11 分钟前
C#.NET serilog 详解
开发语言·c#·.net
万能小锦鲤12 分钟前
《Java EE与中间件》实验三 基于Spring Boot框架的购物车
java·spring boot·mysql·实验报告·购物车·文档资源·java ee与中间件
麦兜*25 分钟前
【Spring Boot】Spring Boot 4.0 的颠覆性AI特性全景解析,结合智能编码实战案例、底层架构革新及Prompt工程手册
java·人工智能·spring boot·后端·spring·架构
野犬寒鸦34 分钟前
MyBatis-Plus 中使用 Wrapper 自定义 SQL
java·数据库·后端·sql·mybatis
expect7g41 分钟前
Java的DNS缓存问题
java·后端
oioihoii41 分钟前
C++11中的std::minmax与std::minmax_element:原理解析与实战
java·开发语言·c++
超龄超能程序猿42 分钟前
使用 Python 对本地图片进行图像分类
开发语言·人工智能·python·机器学习·分类·数据挖掘·scipy
wkj0011 小时前
php中调用对象的方法可以使用array($object, ‘methodName‘)?
android·开发语言·php
karry01301 小时前
高并发导致重复key问题--org.springframework.dao.DuplicateKeyException
java·数据库·ide