diff --git a/CMakeLists.txt b/CMakeLists.txt index e0cc4f09..010b3fd9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,6 @@ include(cmake/import/all.cmake) include(cmake/build/all.cmake) add_subdirectory(external) include(cmake/packages.lua.cmake) -include(LuaSTG/shaders.cmake) add_subdirectory(imgui) add_subdirectory(engine) diff --git a/LuaSTG/CMakeLists.txt b/LuaSTG/CMakeLists.txt index 53929c30..21a92fde 100644 --- a/LuaSTG/CMakeLists.txt +++ b/LuaSTG/CMakeLists.txt @@ -1,8 +1,5 @@ # LuaSTG configurer -add_subdirectory(Shader) -include(Platform.cmake) -include(Core.cmake) add_subdirectory(Configurer) # LuaSTG Engine @@ -35,6 +32,8 @@ set(LUASTG_ENGINE_SOURCES LuaSTG/Debugger/ImGuiExtension.h LuaSTG/Debugger/Logger.cpp LuaSTG/Debugger/Logger.hpp + LuaSTG/Debugger/FrameQuery.hpp + LuaSTG/Debugger/FrameQuery.cpp LuaSTG/GameObject/GameObject.cpp LuaSTG/GameObject/GameObject.hpp @@ -210,10 +209,9 @@ target_link_libraries(LuaSTG PRIVATE utility utf8 win32 - PlatformAPI + beautiful_win32_api DirectX::ToolKitMini Microsoft::DirectXTexMini - Core xmath lua51_static lua_plus @@ -235,6 +233,8 @@ target_link_libraries(LuaSTG PRIVATE Core.Clipboard Core.ShellIntegration Core.Audio + Core.WindowSystem + Core.Graphics LuaSTG.InternalLuaScriptsFileSystem ) diff --git a/LuaSTG/Configurer/CMakeLists.txt b/LuaSTG/Configurer/CMakeLists.txt index 24bfc619..05ffe76b 100644 --- a/LuaSTG/Configurer/CMakeLists.txt +++ b/LuaSTG/Configurer/CMakeLists.txt @@ -18,12 +18,12 @@ target_link_libraries(Setting PRIVATE dxgi.lib spdlog utf8 + win32 beautiful_win32_api imgui imgui_impl_win32 imgui_impl_dx11 nlohmann_json - PlatformAPI ) set(LUASTG_SETTING_BUILD_OUTPUT_DIR ${CMAKE_BINARY_DIR}/bin) diff --git a/LuaSTG/Configurer/Main.cpp b/LuaSTG/Configurer/Main.cpp index 610c0c72..02798168 100644 --- a/LuaSTG/Configurer/Main.cpp +++ b/LuaSTG/Configurer/Main.cpp @@ -1,6 +1,6 @@ #include "win32/win32.hpp" #include "win32/abi.hpp" -#include "Platform/WindowTheme.hpp" +#include "windows/WindowTheme.hpp" #include "imgui.h" #include "imgui_stdlib.h" #include "imgui_freetype.h" @@ -601,8 +601,8 @@ struct Window } void LayoutWindowTab() { if (show_advance) { - showTextFieldEdit(config_json, "/window/title"_json_pointer, "config-window-title"sv, LUASTG_INFO ""s); - showCheckBoxEdit(config_json, "/window/cursor_visible"_json_pointer, "config-window-cursor-visible"sv, true); + showTextFieldEdit(config_json, "/window/title"_json_pointer, "config-window-title"sv, LUASTG_INFO ""s); + showCheckBoxEdit(config_json, "/window/cursor_visible"_json_pointer, "config-window-cursor-visible"sv, true); } showCheckBoxEdit(config_json, "/window/allow_window_corner"_json_pointer, "config-window-allow-window-corner"sv, true); } @@ -612,7 +612,7 @@ struct Window ImGui::TextUnformatted(i18n_c_str("config-graphics-system-preferred-device-name"sv)); ImGui::PushID(i18n_c_str("config-graphics-system-preferred-device-name"sv)); ImGui::SetNextItemWidth(-FLT_MIN); - if (ImGui::BeginCombo("##", !preferred_device_name.empty() ? preferred_device_name.c_str() : i18n_c_str("common-default2"sv))) { + if (ImGui::BeginCombo("##", !preferred_device_name.empty() ? preferred_device_name.c_str() : i18n_c_str("common-default2"sv))) { if (ImGui::Selectable(i18n_c_str("common-default2"sv), preferred_device_name.empty())) { config_json["/graphics_system/preferred_device_name"_json_pointer] = ""sv; } @@ -726,10 +726,7 @@ struct Window { throw std::runtime_error("CreateDXGIFactory1 failed."); } - if (FAILED(dxgi_factory->EnumAdapters1(0, &dxgi_adapter))) - { - throw std::runtime_error("IDXGIFactory1::EnumAdapters1 failed."); - } + dxgi_factory->EnumAdapters1(0, &dxgi_adapter); dxgi_adapter_list.clear(); Microsoft::WRL::ComPtr dxgi_factory6; @@ -759,10 +756,34 @@ struct Window D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, }; - hr = D3D11CreateDevice( - dxgi_adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, NULL, - D3D11_CREATE_DEVICE_BGRA_SUPPORT, target_levels, 3, D3D11_SDK_VERSION, - &d3d11_device, &d3d11_feature_level, &d3d11_devctx); + hr = E_FAIL; + if (dxgi_adapter) { + hr = D3D11CreateDevice( + dxgi_adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, NULL, + D3D11_CREATE_DEVICE_BGRA_SUPPORT, target_levels, 3, D3D11_SDK_VERSION, + &d3d11_device, &d3d11_feature_level, &d3d11_devctx); + } + if (FAILED(hr)) + { + hr = D3D11CreateDevice( + nullptr, D3D_DRIVER_TYPE_WARP, NULL, + D3D11_CREATE_DEVICE_BGRA_SUPPORT, target_levels, 3, D3D11_SDK_VERSION, + &d3d11_device, &d3d11_feature_level, &d3d11_devctx); + } + if (FAILED(hr)) + { + hr = D3D11CreateDevice( + nullptr, D3D_DRIVER_TYPE_SOFTWARE, NULL, + D3D11_CREATE_DEVICE_BGRA_SUPPORT, target_levels, 3, D3D11_SDK_VERSION, + &d3d11_device, &d3d11_feature_level, &d3d11_devctx); + } + if (FAILED(hr)) + { + hr = D3D11CreateDevice( + nullptr, D3D_DRIVER_TYPE_REFERENCE, NULL, + D3D11_CREATE_DEVICE_BGRA_SUPPORT, target_levels, 3, D3D11_SDK_VERSION, + &d3d11_device, &d3d11_feature_level, &d3d11_devctx); + } if (FAILED(hr)) { throw std::runtime_error("D3D11CreateDevice failed."); diff --git a/LuaSTG/Core.cmake b/LuaSTG/Core.cmake deleted file mode 100644 index c0a72ac5..00000000 --- a/LuaSTG/Core.cmake +++ /dev/null @@ -1,127 +0,0 @@ -# Core - -add_library(Core STATIC) - -luastg_target_common_options(Core) -luastg_target_more_warning(Core) -target_compile_definitions(Core PRIVATE - LUASTG_CORE_USING_IMGUI -) -target_include_directories(Core PUBLIC - . -) - -set(Core_SRC - Core/i18n.hpp - Core/i18n.cpp - Core/framework.hpp - Core/framework.cpp - - Core/Graphics/Window.hpp - Core/Graphics/Window_Win32.hpp - Core/Graphics/Window_Win32.cpp - Core/Graphics/Format.hpp - Core/Graphics/Device.hpp - Core/Graphics/SwapChain.hpp - Core/Graphics/SwapChain_D3D11.hpp - Core/Graphics/SwapChain_D3D11.cpp - Core/Graphics/Renderer.hpp - Core/Graphics/Renderer_D3D11.hpp - Core/Graphics/Renderer_D3D11.cpp - Core/Graphics/Renderer_Shader_D3D11.cpp - Core/Graphics/Model_D3D11.hpp - Core/Graphics/Model_D3D11.cpp - Core/Graphics/Model_Shader_D3D11.cpp - Core/Graphics/Sprite.hpp - Core/Graphics/Font.hpp - Core/Graphics/Mesh.hpp - - Core/Graphics/Common/Sprite.hpp - Core/Graphics/Common/Sprite.cpp - Core/Graphics/Common/SpriteRenderer.hpp - Core/Graphics/Common/SpriteRenderer.cpp - Core/Graphics/Common/FreeTypeGlyphManager.hpp - Core/Graphics/Common/FreeTypeGlyphManager.cpp - Core/Graphics/Common/TextRenderer.hpp - Core/Graphics/Common/TextRenderer.cpp - Core/Graphics/Common/TextRenderer2.hpp - Core/Graphics/Common/TextRenderer2.cpp - - Core/Graphics/Direct3D11/Constants.hpp - Core/Graphics/Direct3D11/Buffer.hpp - Core/Graphics/Direct3D11/Buffer.cpp - Core/Graphics/Direct3D11/Texture2D.hpp - Core/Graphics/Direct3D11/Texture2D.cpp - Core/Graphics/Direct3D11/SamplerState.hpp - Core/Graphics/Direct3D11/SamplerState.cpp - Core/Graphics/Direct3D11/RenderTarget.hpp - Core/Graphics/Direct3D11/RenderTarget.cpp - Core/Graphics/Direct3D11/DepthStencilBuffer.hpp - Core/Graphics/Direct3D11/DepthStencilBuffer.cpp - Core/Graphics/Direct3D11/Device.hpp - Core/Graphics/Direct3D11/Device.cpp - Core/Graphics/Direct3D11/Mesh.hpp - Core/Graphics/Direct3D11/Mesh.cpp - Core/Graphics/Direct3D11/MeshRenderer.hpp - Core/Graphics/Direct3D11/MeshRenderer.cpp - Core/Graphics/Direct3D11/LetterBoxingRenderer.hpp - Core/Graphics/Direct3D11/LetterBoxingRenderer.cpp - - Core/ApplicationModel.hpp - Core/ApplicationModel_Win32.hpp - Core/ApplicationModel_Win32.cpp -) -source_group(TREE ${CMAKE_CURRENT_LIST_DIR} FILES ${Core_SRC}) -target_precompile_headers(Core PRIVATE - Core/framework.hpp -) -target_sources(Core PRIVATE - ${Core_SRC} -) - -target_link_libraries(Core PUBLIC - # debug - spdlog - TracyAPI - imgui - # util - utility - utf8 - simdutf::simdutf - PlatformAPI - beautiful_win32_api - GeneratedShaderHeaders - # win32 - winmm.lib - imm32.lib - # dx - dxguid.lib - dxgi.lib - d3d11.lib - #Microsoft.XAudio2.Redist - Microsoft.Windows.ImplementationLibrary - Microsoft::DirectXTexMini - libqoi - # math - xmath - # text - Freetype::Freetype - # model - tinygltf - # audio - dr_libs - Ogg::ogg - Vorbis::vorbis - Vorbis::vorbisfile - FLAC::FLAC - # database - nlohmann_json - Core.Math - Core.String - Core.Configuration - Core.ReferenceCounted - Core.FileSystem - Core.Image - Core.Font - win32 -) diff --git a/LuaSTG/Core/ApplicationModel.hpp b/LuaSTG/Core/ApplicationModel.hpp deleted file mode 100644 index b2abcb77..00000000 --- a/LuaSTG/Core/ApplicationModel.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once -#include "Core/Graphics/Window.hpp" -#include "Core/Graphics/Device.hpp" -#include "Core/Graphics/SwapChain.hpp" -#include "Core/Graphics/Renderer.hpp" -#include "core/ReferenceCounted.hpp" - -namespace core -{ - struct IFrameRateController - { - virtual double update() = 0; - virtual uint32_t getTargetFPS() = 0; - virtual void setTargetFPS(uint32_t target_FPS) = 0; - virtual double getFPS() = 0; - virtual uint64_t getTotalFrame() = 0; - virtual double getTotalTime() = 0; - virtual double getAvgFPS() = 0; - virtual double getMinFPS() = 0; - virtual double getMaxFPS() = 0; - }; - - struct IApplicationEventListener - { - // [工作线程] - virtual bool onUpdate() { return true; } - // [工作线程] - virtual bool onRender() { return true; } - }; - - struct FrameStatistics - { - double total_time{}; - double wait_time{}; - double update_time{}; - double render_time{}; - double present_time{}; - }; - - struct FrameRenderStatistics - { - double render_time{}; - }; - - struct IApplicationModel : public IReferenceCounted - { - // [工作线程] - virtual IFrameRateController* getFrameRateController() = 0; - // [主线程|工作线程] - virtual Graphics::IWindow* getWindow() = 0; - // [工作线程] - virtual Graphics::IDevice* getDevice() = 0; - // [工作线程] - virtual Graphics::ISwapChain* getSwapChain() = 0; - // [工作线程] - virtual Graphics::IRenderer* getRenderer() = 0; - // [工作线程] - virtual FrameStatistics getFrameStatistics() = 0; - // [工作线程] - virtual FrameRenderStatistics getFrameRenderStatistics() = 0; - - // [主线程|工作线程] - virtual void requestExit() = 0; - // [主线程] - virtual bool run() = 0; - - static bool create(IApplicationEventListener* p_app, IApplicationModel** pp_model); - }; - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IApplicationModel - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("42313368-4b16-511f-895f-ee43f0e10713"); } -} diff --git a/LuaSTG/Core/ApplicationModel_Win32.cpp b/LuaSTG/Core/ApplicationModel_Win32.cpp deleted file mode 100644 index e2c12e64..00000000 --- a/LuaSTG/Core/ApplicationModel_Win32.cpp +++ /dev/null @@ -1,703 +0,0 @@ -#include "Core/ApplicationModel_Win32.hpp" -#include "Core/i18n.hpp" -#include "core/Configuration.hpp" -#include "Platform/WindowsVersion.hpp" -#include "Platform/ProcessorInfo.hpp" - -namespace core -{ - double FrameRateController::indexFPS(size_t idx) - { - return fps_[(fps_index_ + std::size(fps_) - 1 - idx) % std::size(fps_)]; - } - - double FrameRateController::udateData(int64_t curr) - { - // 更新各项数值 - double const fps = (double)freq_ / (double)(curr - last_); - double const s = 1.0 / fps; - total_frame_ += 1; - total_time_ += s; - fps_[fps_index_] = fps; - fps_index_ = (fps_index_ + 1) % std::size(fps_); - last_ = curr; - - // 更新统计数据 - fps_min_ = DBL_MAX; - fps_max_ = -DBL_MAX; - size_t const total_history = total_frame_ < std::size(fps_) ? (size_t)total_frame_ : std::size(fps_); - if (total_history > 0) - { - double total_fps = 0.0; - double total_time = 0.0; - size_t history_count = 0; - for (size_t i = 0; i < total_history; i += 1) - { - double const fps_history = indexFPS(i); - total_fps += fps_history; - fps_min_ = std::min(fps_min_, fps_history); - fps_max_ = std::max(fps_max_, fps_history); - total_time += 1.0 / fps_history; - history_count += 1; - if (total_time >= 0.25) - { - break; - } - } - fps_avg_ = total_fps / (double)history_count; - } - else - { - fps_avg_ = 0.0; - fps_min_ = 0.0; - fps_max_ = 0.0; - } - - return s; - } - bool FrameRateController::arrive() - { - // 先获取当前计数器 - LARGE_INTEGER curr_{}; - QueryPerformanceCounter(&curr_); - // 判断 - if ((curr_.QuadPart - last_) < wait_) - { - return false; - } - else - { - udateData(curr_.QuadPart); - return true; - } - } - double FrameRateController::update() - { - // 先获取当前计数器 - LARGE_INTEGER curr_{}; - QueryPerformanceCounter(&curr_); - - // 当设备运行时间足够长后,即使是 int64 也会溢出 - if (curr_.QuadPart < last_) - { - total_frame_ += 1; - total_time_ += 1.0 / indexFPS(0); - last_ = curr_.QuadPart; - return indexFPS(0); - } - - // 在启用了高精度计时器的情况下,可以用 Sleep 等待,不需要占用太多 CPU - LONGLONG const sleep_ms = (((wait_ - (curr_.QuadPart - last_)) - _2ms_) * 1000ll) / freq_; - if (sleep_ms > 0) - { - Sleep((DWORD)sleep_ms); - } - - // 轮询等待 - do - { - QueryPerformanceCounter(&curr_); - } while ((curr_.QuadPart - last_) < wait_); - - return udateData(curr_.QuadPart); - } - - uint32_t FrameRateController::getTargetFPS() - { - return (uint32_t)target_fps_; - } - void FrameRateController::setTargetFPS(uint32_t target_FPS) - { - target_fps_ = (double)(target_FPS > 0 ? target_FPS : 1); - LARGE_INTEGER lli{}; - QueryPerformanceFrequency(&lli); - freq_ = lli.QuadPart; - wait_ = (LONGLONG)((double)freq_ / target_fps_); - _2ms_ = (2ll * freq_) / 1000ll; - } - double FrameRateController::getFPS() - { - return indexFPS(0); - } - uint64_t FrameRateController::getTotalFrame() - { - return total_frame_; - } - double FrameRateController::getTotalTime() - { - return total_time_; - } - double FrameRateController::getAvgFPS() - { - return fps_avg_; - } - double FrameRateController::getMinFPS() - { - return fps_min_; - } - double FrameRateController::getMaxFPS() - { - return fps_max_; - } - - FrameRateController::FrameRateController(uint32_t target_FPS) - { - timeBeginPeriod(1); - setTargetFPS(target_FPS); - LARGE_INTEGER lli{}; - QueryPerformanceCounter(&lli); - last_ = lli.QuadPart; - } - FrameRateController::~FrameRateController() - { - timeEndPeriod(1); - } -} - -namespace core -{ - // 基于时间戳的帧率控制器 - // 当帧率有波动时,追赶或者等待更长时间 - - inline int64_t winQPC() - { - LARGE_INTEGER ll = {}; - QueryPerformanceCounter(&ll); - return ll.QuadPart; - } - inline int64_t winQPF() - { - LARGE_INTEGER ll = {}; - QueryPerformanceFrequency(&ll); - return ll.QuadPart; - } - - bool TimeStampFrameRateController::arrive() - { - // 计算下一个要到达的时间戳 - int64_t const target_pc_ = begin_pc_ + (frame_count_ + 1) * clock_pcpf_; - int64_t cur_pc_ = winQPC(); - return cur_pc_ >= target_pc_; - } - double TimeStampFrameRateController::update() - { - // 计算下一个要到达的时间戳 - int64_t const target_pc_ = begin_pc_ + (frame_count_ + 1) * clock_pcpf_; - int64_t cur_pc_ = winQPC(); - if (cur_pc_ > target_pc_) - { - // 已经超过 - if ((cur_pc_ - target_pc_) >= (clock_pcpf_ * 10)) - { - // 落后超过 10 帧,放弃追赶,并设置新的基准点 - begin_pc_ = cur_pc_; - frame_count_ = 0; - } - else - { - // 立即推进 1 帧 - frame_count_ += 1; - } - } - else - { - // 当需要等待的时间 Tms 大于 2ms 时,用Sleep 等待 (T - 2)ms - int64_t const err_pc_ = clock_freq_ * 2 / 1000; - int64_t const ddt_pc_ = target_pc_ - cur_pc_; - if (ddt_pc_ > err_pc_) - { - DWORD const ms_ = (DWORD)((ddt_pc_ - err_pc_) / (err_pc_ / 2)); - Sleep(ms_); - } - // 精确的轮询等待 - for (;;) - { - cur_pc_ = winQPC(); - if (cur_pc_ >= target_pc_) - { - break; - } - } - // 推进 1 帧 - frame_count_ += 1; - } - // 刷新数值 - int64_t const delta_pc_ = cur_pc_ - last_pc_; - delta_time_ = (double)delta_pc_ / (double)clock_freq_; - last_pc_ = cur_pc_; - return delta_time_; - } - - uint32_t TimeStampFrameRateController::getTargetFPS() - { - return (uint32_t)target_fps_; - } - void TimeStampFrameRateController::setTargetFPS(uint32_t target_FPS) - { - if (std::abs(target_fps_ - (double)target_FPS) < 0.01) - { - return; - } - - target_fps_ = (double)target_FPS; - target_spf_ = 1.0 / target_fps_; - - clock_freq_ = winQPF(); - clock_pcpf_ = (int64_t)(target_spf_ * (double)clock_freq_); - - begin_pc_ = winQPC(); - last_pc_ = begin_pc_; - frame_count_ = 0; - } - double TimeStampFrameRateController::getFPS() { return 1.0 / delta_time_; } - uint64_t TimeStampFrameRateController::getTotalFrame() { return 0; } - double TimeStampFrameRateController::getTotalTime() { return 0.0; } - double TimeStampFrameRateController::getAvgFPS() { return getFPS(); } - double TimeStampFrameRateController::getMinFPS() { return getFPS(); } - double TimeStampFrameRateController::getMaxFPS() { return getFPS(); } - - TimeStampFrameRateController::TimeStampFrameRateController(uint32_t target_FPS) - { - timeBeginPeriod(1); - setTargetFPS(target_FPS); - } - TimeStampFrameRateController::~TimeStampFrameRateController() - { - timeEndPeriod(1); - } -} - -namespace core -{ - static std::string bytes_count_to_string(DWORDLONG size) - { - int count = 0; - char buffer[64] = {}; - if (size < 1024llu) // B - { - count = std::snprintf(buffer, 64, "%u B", (unsigned int)size); - } - else if (size < (1024llu * 1024llu)) // KB - { - count = std::snprintf(buffer, 64, "%.2f KiB", (double)size / 1024.0); - } - else if (size < (1024llu * 1024llu * 1024llu)) // MB - { - count = std::snprintf(buffer, 64, "%.2f MiB", (double)size / 1048576.0); - } - else // GB - { - count = std::snprintf(buffer, 64, "%.2f GiB", (double)size / 1073741824.0); - } - return std::string(buffer, count); - } - static void get_system_memory_status() - { - MEMORYSTATUSEX info = { sizeof(MEMORYSTATUSEX) }; - if (GlobalMemoryStatusEx(&info)) - { - spdlog::info("[core] 系统内存使用情况:\n" - " 使用百分比:{}%\n" - " 总物理内存:{}\n" - " 剩余物理内存:{}\n" - " 当前进程可提交内存限制:{}\n" - " 当前进程剩余的可提交内存:{}\n" - " 当前进程用户模式内存空间限制*1:{}\n" - " 当前进程剩余的用户模式内存空间:{}\n" - " *1 此项反映此程序实际上能用的最大内存,在 32 位应用程序上此项一般为 2 GB,修改 Windows 操作系统注册表后可能为 1 到 3 GB" - , info.dwMemoryLoad - , bytes_count_to_string(info.ullTotalPhys) - , bytes_count_to_string(info.ullAvailPhys) - , bytes_count_to_string(info.ullTotalPageFile) - , bytes_count_to_string(info.ullAvailPageFile) - , bytes_count_to_string(info.ullTotalVirtual) - , bytes_count_to_string(info.ullAvailVirtual) - ); - } - else - { - spdlog::error("[core] 无法获取系统内存使用情况"); - } - } - - struct ScopeTimer - { - LARGE_INTEGER freq{}; - LARGE_INTEGER last{}; - double& t; - ScopeTimer(double& v_ref) : t(v_ref) - { - QueryPerformanceFrequency(&freq); - QueryPerformanceCounter(&last); - } - ~ScopeTimer() - { - LARGE_INTEGER curr{}; - QueryPerformanceCounter(&curr); - t = (double)(curr.QuadPart - last.QuadPart) / (double)freq.QuadPart; - } - }; - - DWORD WINAPI ApplicationModel_Win32::win32_thread_worker_entry(LPVOID lpThreadParameter) - { - static_cast(lpThreadParameter)->worker(); - return 0; - } - void ApplicationModel_Win32::worker() - { - // 设置线程优先级为最高,并尽量让它运行在同一个 CPU 核心上,降低切换开销 - SetThreadAffinityMask(GetCurrentThread(), 1); - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); - - // 更新、渲染循环 - TracyD3D11Collect(m_device->GetTracyContext()); - FrameMark; - { - tracy_zone_scoped_with_name("OnInitWait"); - m_swapchain->waitFrameLatency(); - m_p_frame_rate_controller->update(); - } - while (true) - { - size_t const i = (m_framestate_index + 1) % 2; - FrameStatistics& d = m_framestate[i]; - ScopeTimer gt(d.total_time); - - bool update_result = false; - - // 更新 - { - tracy_zone_scoped_with_name("OnUpdate"); - ScopeTimer t(d.update_time); - // 如果需要退出 - if (WAIT_OBJECT_0 == WaitForSingleObjectEx(win32_event_exit.Get(), 0, TRUE)) - { - break; - } - update_result = m_listener->onUpdate(); - } - - bool render_result = false; - - // 渲染 - if (update_result) - { - tracy_zone_scoped_with_name("OnRender"); - tracy_d3d11_context_zone(m_device->GetTracyContext(), "OnRender"); - ScopeTimer t(d.render_time); - m_swapchain->applyRenderAttachment(); - m_swapchain->clearRenderAttachment(); - render_result = m_listener->onRender(); - } - - // 呈现 - if (render_result) - { - tracy_zone_scoped_with_name("OnPresent"); - ScopeTimer t(d.present_time); - m_swapchain->present(); - TracyD3D11Collect(m_device->GetTracyContext()); - } - - // 等待下一帧 - { - tracy_zone_scoped_with_name("OnWait"); - ScopeTimer t(d.wait_time); - m_swapchain->waitFrameLatency(); - m_p_frame_rate_controller->update(); - } - - m_framestate_index = i; - FrameMark; - } - } - - bool ApplicationModel_Win32::runSingleThread() - { - // 设置线程优先级为高,并尽量让它运行在同一个 CPU 核心上,降低切换开销 - SetThreadAffinityMask(GetCurrentThread(), 1); - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_HIGHEST); - - // 初次收集诊断信息 - TracyD3D11Collect(m_device->GetTracyContext()); - FrameMark; - { - tracy_zone_scoped_with_name("OnInitWait"); - m_swapchain->waitFrameLatency(); - m_p_frame_rate_controller->update(); - } - - // 游戏循环 - MSG msg{}; - while (!m_exit_flag) - { - // 提取消息 - while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) - { - if (msg.message == WM_QUIT) - { - m_exit_flag = true; // 应该结束循环 - } - else - { - TranslateMessage(&msg); - DispatchMessageW(&msg); - } - } - - // 更新并渲染 - if (m_exit_flag) - { - break; - } - runFrame(); - } - - return true; - } - bool ApplicationModel_Win32::runDoubleThread() - { - // 设置线程优先级为稍高,并尽量让它运行在同一个 CPU 核心上,降低切换开销 - //SetThreadAffinityMask(GetCurrentThread(), 1); - SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL); - // 创建退出用的事件 - win32_event_exit.Attach(CreateEventExW(NULL, NULL, CREATE_EVENT_MANUAL_RESET, EVENT_ALL_ACCESS)); - if (!win32_event_exit.IsValid()) - { - return false; - } - // 创建更新、渲染线程 - Microsoft::WRL::Wrappers::ThreadHandle win32_thread_worker; - win32_thread_worker.Attach(CreateThread(NULL, 0, &win32_thread_worker_entry, this, 0, NULL)); - if (!win32_thread_worker.IsValid()) - { - return false; - } - // 消息循环 - MSG msg = {}; - BOOL running = TRUE; - HANDLE win32_events[1] = { win32_event_exit.Get() }; - while (running) - { - if (win32_events[0]) - { - // 监控退出事件和消息队列 - // MsgWaitForMultipleObjectsEx 在不带 MWMO_INPUTAVAILABLE 调用时,只会注意到“新”消息 - // 如果某些地方 PeekMessageW 不带 PM_REMOVE 调用,那么这个消息仍然存在于消息队列中,但是已经成为“老”消息 - // 为了防止这种情况卡住 MsgWaitForMultipleObjectsEx 造成无限等待: - // 1、调用 MsgWaitForMultipleObjectsEx 时带上 MWMO_INPUTAVAILABLE - // 2、使用 while 循环带 PM_REMOVE 调用 PeekMessageW 直到返回 FALSE - switch (MsgWaitForMultipleObjectsEx(1, win32_events, INFINITE, QS_ALLINPUT, MWMO_INPUTAVAILABLE)) - { - case (WAIT_OBJECT_0): - // 退出信号不是由窗口触发的,而是由工作线程触发的 - PostQuitMessage(EXIT_SUCCESS); - win32_events[0] = NULL; // 不再需要监控退出事件 - break; - case (WAIT_OBJECT_0 + 1): - while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) - { - if (msg.message == WM_QUIT) - { - running = FALSE; // 应该结束循环 - } - else - { - TranslateMessage(&msg); - DispatchMessageW(&msg); - } - } - break; - case WAIT_TIMEOUT: - i18n_core_system_call_report_error("MsgWaitForMultipleObjectsEx => WAIT_TIMEOUT"); - break; - case WAIT_FAILED: - gHRLastError; - i18n_core_system_call_report_error("MsgWaitForMultipleObjectsEx"); - running = FALSE; // 应该结束循环 - break; - } - } - else - { - // 监控消息队列 - BOOL const result = GetMessageW(&msg, NULL, 0, 0); - if (result >= TRUE) - { - TranslateMessage(&msg); - DispatchMessageW(&msg); - } - else if (result == FALSE) - { - running = FALSE; // 应该结束循环 - } - else - { - gHRLastError; - i18n_core_system_call_report_error("GetMessageW"); - running = FALSE; // 应该结束循环 - } - } - } - // 让工作线程退出 - requestExit(); - //WaitForSingleObjectEx(win32_thread_worker.Get(), INFINITE, TRUE); - auto wait_worker = [&]() - { - for (;;) - { - switch (WaitForSingleObjectEx(win32_thread_worker.Get(), USER_TIMER_MINIMUM, TRUE)) - { - case WAIT_OBJECT_0: - return; // ok - case WAIT_TIMEOUT: - break; // msg - case WAIT_FAILED: - gHRLastError; - return; // failed - } - // 你妈的,是不是还有消息没处理 - if (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE)) - { - if (msg.message == WM_QUIT) - { - // NOOP - } - else - { - TranslateMessage(&msg); - DispatchMessageW(&msg); - } - } - } - }; - wait_worker(); - return true; - } - void ApplicationModel_Win32::runFrame() - { - size_t const i = (m_framestate_index + 1) % 2; - FrameStatistics& d = m_framestate[i]; - ScopeTimer gt(d.total_time); - size_t const next_frame_query_index = (m_frame_query_index + 1) % m_frame_query_list.size(); - FrameQuery& frame_query = m_frame_query_list[next_frame_query_index]; - - bool update_result = false; - - // 更新 - { - tracy_zone_scoped_with_name("OnUpdate"); - ScopeTimer t(d.update_time); - update_result = m_listener->onUpdate(); - } - - bool render_result = false; - - - - // 渲染 - if (update_result) - { - tracy_zone_scoped_with_name("OnRender"); - tracy_d3d11_context_zone(m_device->GetTracyContext(), "OnRender"); - ScopeTimer t(d.render_time); - frame_query.begin(); // TODO: enable/disable by configuration - m_swapchain->applyRenderAttachment(); - m_swapchain->clearRenderAttachment(); - render_result = m_listener->onRender(); - frame_query.end(); // TODO: enable/disable by configuration - } - - // 呈现 - if (render_result) - { - tracy_zone_scoped_with_name("OnPresent"); - ScopeTimer t(d.present_time); - m_swapchain->present(); - TracyD3D11Collect(m_device->GetTracyContext()); - } - - // 等待下一帧 - { - tracy_zone_scoped_with_name("OnWait"); - ScopeTimer t(d.wait_time); - m_swapchain->waitFrameLatency(); - m_p_frame_rate_controller->update(); - } - - m_framestate_index = i; - m_frame_query_index = next_frame_query_index; - FrameMark; - } - - FrameStatistics ApplicationModel_Win32::getFrameStatistics() - { - return m_framestate[m_framestate_index]; - } - FrameRenderStatistics ApplicationModel_Win32::getFrameRenderStatistics() - { - FrameQuery& frame_query = m_frame_query_list[m_frame_query_index]; - FrameRenderStatistics statistics{}; - statistics.render_time = frame_query.getTime(); - return statistics; - } - - void ApplicationModel_Win32::requestExit() - { - SetEvent(win32_event_exit.Get()); - m_exit_flag = true; - } - bool ApplicationModel_Win32::run() - { - return runSingleThread(); - } - - ApplicationModel_Win32::ApplicationModel_Win32(IApplicationEventListener* p_listener) - : m_listener(p_listener) - { - assert(m_listener); - spdlog::info("[core] System: {}", Platform::WindowsVersion::GetName()); - spdlog::info("[core] Kernel: {}", Platform::WindowsVersion::GetKernelVersionString()); - spdlog::info("[core] CPU: {}", Platform::ProcessorInfo::name()); - if (m_steady_frame_rate_controller.available()) { - spdlog::info("[core] High Resolution Waitable Timer available, enable SteadyFrameRateController"); - m_p_frame_rate_controller = &m_steady_frame_rate_controller; - } - else { - m_p_frame_rate_controller = &m_frame_rate_controller; - } - get_system_memory_status(); - if (!Graphics::Window_Win32::create(m_window.put())) - throw std::runtime_error("Graphics::Window_Win32::create"); - m_window->implSetApplicationModel(this); - auto const& gpu = core::ConfigurationLoader::getInstance().getGraphicsSystem().getPreferredDeviceName(); - if (!Graphics::Direct3D11::Device::create(gpu, m_device.put())) - throw std::runtime_error("Graphics::Direct3D11::Device::create"); - if (!Graphics::SwapChain_D3D11::create(*m_window, *m_device, m_swapchain.put())) - throw std::runtime_error("Graphics::SwapChain_D3D11::create"); - if (!Graphics::Renderer_D3D11::create(*m_device, m_renderer.put())) - throw std::runtime_error("Graphics::Renderer_D3D11::create"); - m_frame_query_list.reserve(2); - for (int i = 0; i < 2; i += 1) { - m_frame_query_list.emplace_back(m_device.get()); - } - } - ApplicationModel_Win32::~ApplicationModel_Win32() - { - std::ignore = 0; - } - - bool IApplicationModel::create(IApplicationEventListener* p_app, IApplicationModel** pp_model) - { - try - { - *pp_model = new ApplicationModel_Win32(p_app); - return true; - } - catch (...) - { - *pp_model = nullptr; - return false; - } - } -} diff --git a/LuaSTG/Core/ApplicationModel_Win32.hpp b/LuaSTG/Core/ApplicationModel_Win32.hpp deleted file mode 100644 index e6984e35..00000000 --- a/LuaSTG/Core/ApplicationModel_Win32.hpp +++ /dev/null @@ -1,415 +0,0 @@ -#pragma once -#include "core/implement/ReferenceCounted.hpp" -#include "Core/ApplicationModel.hpp" -#include "Core/Graphics/Window_Win32.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "Core/Graphics/SwapChain_D3D11.hpp" -#include "Core/Graphics/Renderer_D3D11.hpp" - -namespace core -{ - class FrameRateController : public IFrameRateController - { - private: - int64_t freq_{}; - int64_t last_{}; - int64_t wait_{}; - int64_t _2ms_{}; - uint64_t total_frame_{}; - double total_time_{}; - double target_fps_{ 60.0 }; - double fps_[256]{}; - double fps_avg_{}; - double fps_min_{}; - double fps_max_{}; - size_t fps_index_{}; - private: - double indexFPS(size_t idx); - public: - double udateData(int64_t curr); - bool arrive(); - double update(); - public: - uint32_t getTargetFPS(); - void setTargetFPS(uint32_t target_FPS); - double getFPS(); - uint64_t getTotalFrame(); - double getTotalTime(); - double getAvgFPS(); - double getMinFPS(); - double getMaxFPS(); - public: - FrameRateController(uint32_t target_FPS = 60); - ~FrameRateController(); - }; - - class TimeStampFrameRateController : public IFrameRateController - { - private: - double target_fps_{ 0.0 }; - double target_spf_{ 0.0 }; - int64_t clock_freq_{ 0 }; - int64_t clock_pcpf_{ 0 }; - double delta_time_{ 0.0 }; - int64_t begin_pc_{ 0 }; - int64_t last_pc_{ 0 }; - int64_t frame_count_{ 0 }; - public: - bool arrive(); - double update(); - public: - uint32_t getTargetFPS(); - void setTargetFPS(uint32_t target_FPS); - double getFPS(); - uint64_t getTotalFrame(); - double getTotalTime(); - double getAvgFPS(); - double getMinFPS(); - double getMaxFPS(); - public: - TimeStampFrameRateController(uint32_t target_FPS = 60); - ~TimeStampFrameRateController(); - }; - - // Windows 10 1803+ 开始可用的高精度帧率控制方法 - class SteadyFrameRateController : public IFrameRateController - { - private: - uint32_t const m_max_error{ 10 }; // 相差超过 10 帧就不应该再追帧了 - double const m_update_avg_fps_delta{ 0.25 }; // 每 0.25s 更新一次平均帧率 - wil::unique_event_nothrow m_event; - LARGE_INTEGER m_freq{}; - LARGE_INTEGER m_last{}; - LARGE_INTEGER m_target_time{}; // 下一个期望的时间戳 - LARGE_INTEGER m_target_delta{}; // 期望的时间戳间隔 - uint32_t m_target_frame_rate{}; // 期望的帧率 - double m_last_fps{}; - double m_last_max_fps{}; - double m_last_min_fps{}; - uint64_t m_total_frame{}; - double m_total_time{}; - std::array m_time_history{}; - size_t m_time_history_index{}; - double m_last_avg_fps{}; - double m_update_avg_fps_timer{}; - private: - double updateTime() - { - LARGE_INTEGER v_curr{}; - QueryPerformanceCounter(&v_curr); - double delta_s = double(v_curr.QuadPart - m_last.QuadPart) / double(m_freq.QuadPart); - - m_last_fps = 1.0 / delta_s; - m_total_frame += 1; - m_total_time += delta_s; - m_time_history[m_time_history_index] = delta_s; - m_time_history_index = (m_time_history_index + 1) % m_time_history.size(); - - m_last_min_fps = std::numeric_limits::max(); - m_last_max_fps = std::numeric_limits::lowest(); - double total_s{}; - for (size_t i = 0; i < m_time_history.size(); i += 1) { - size_t idx = (m_time_history_index + m_time_history.size() - 1 - i) % m_time_history.size(); - double fps = 1.0 / m_time_history[idx]; - m_last_min_fps = std::min(m_last_min_fps, fps); - m_last_max_fps = std::max(m_last_max_fps, fps); - total_s += m_time_history[idx]; - } - - // 每 0.25s 更新一次平均帧率 - m_update_avg_fps_timer -= delta_s; - if (m_update_avg_fps_timer <= 0.0) { - m_update_avg_fps_timer = m_update_avg_fps_delta; - m_last_avg_fps = double(m_time_history.size()) / total_s; - } - - m_last = v_curr; - return delta_s; - } - bool recreateResource() - { - m_event.reset(CreateWaitableTimerExW(NULL, NULL, CREATE_WAITABLE_TIMER_HIGH_RESOLUTION, TIMER_ALL_ACCESS)); - if (!m_event) { - spdlog::error("[core] [SteadyFrameRateController] CreateWaitableTimerExW failed (LastError={})", GetLastError()); - } - return !!m_event; - } - public: - bool arrive() { return true; } - double update() - { - FILETIME file_time{}; - GetSystemTimeAsFileTime(&file_time); - LARGE_INTEGER current_time{}; - current_time.LowPart = file_time.dwLowDateTime; - current_time.HighPart = static_cast(file_time.dwHighDateTime); - - // 如果相差太大,就不应该追帧了 - if (std::abs(current_time.QuadPart - (m_target_time.QuadPart + m_target_delta.QuadPart)) >= (m_target_delta.QuadPart * 10)) - { - m_target_time.QuadPart = current_time.QuadPart; - return updateTime(); // 立即放弃等待,尽快追上 - } - - // 等待到下个时间戳 - m_target_time.QuadPart += m_target_delta.QuadPart; - if (!SetWaitableTimerEx(m_event.get(), &m_target_time, 0, NULL, NULL, NULL, 0)) - { - spdlog::error("[core] [SteadyFrameRateController] SetWaitableTimerEx failed (LastError={})", GetLastError()); - recreateResource(); // 尝试重新创建资源 - return updateTime(); - } - if (WAIT_FAILED == WaitForSingleObject(m_event.get(), INFINITE)) - { - spdlog::error("[core] [SteadyFrameRateController] WaitForSingleObject failed (LastError={})", GetLastError()); - recreateResource(); // 尝试重新创建资源 - return updateTime(); - } - - return updateTime(); - } - public: - uint32_t getTargetFPS() { return m_target_frame_rate; } - void setTargetFPS(uint32_t target_frame_rate) - { - if (target_frame_rate == m_target_frame_rate) { - return; - } - m_target_frame_rate = std::max(1, target_frame_rate); // 保护措施 - - double const delta_s = 1.0 / double(target_frame_rate); - m_target_delta.QuadPart = LONGLONG(delta_s * 10000000.0); - - FILETIME file_time{}; - GetSystemTimeAsFileTime(&file_time); - m_target_time.LowPart = file_time.dwLowDateTime; - m_target_time.HighPart = static_cast(file_time.dwHighDateTime); - } - double getFPS() { return m_last_fps; } - uint64_t getTotalFrame() { return m_total_frame; } - double getTotalTime() { return m_total_time; } - double getAvgFPS() { return m_last_avg_fps; } - double getMinFPS() { return m_last_min_fps; } - double getMaxFPS() { return m_last_max_fps; } - public: - bool available() { return !!m_event; } - public: - SteadyFrameRateController() - { - QueryPerformanceFrequency(&m_freq); - QueryPerformanceCounter(&m_last); - recreateResource(); - setTargetFPS(60); - } - ~SteadyFrameRateController() = default; - }; - - class FrameQuery : public Graphics::IDeviceEventListener - { - private: - - SmartReference m_device; - win32::com_ptr d3d11_device; - win32::com_ptr d3d11_device_context; - win32::com_ptr d3d11_query_freq; - win32::com_ptr d3d11_query_time_begin; - win32::com_ptr d3d11_query_time_end; - win32::com_ptr d3d11_query_statistics; - D3D11_QUERY_DATA_TIMESTAMP_DISJOINT freq{}; - UINT64 time_begin{}; - UINT64 time_end{}; - D3D11_QUERY_DATA_PIPELINE_STATISTICS statistics{}; - bool is_flying{}; - bool is_scope{}; - - void onDeviceCreate() override { - createResources(static_cast(m_device->getNativeHandle())); - } - void onDeviceDestroy() override { - destroyResources(); - } - - public: - - bool createResources(ID3D11Device* device) - { - assert(device); - d3d11_device = device; - d3d11_device->GetImmediateContext(d3d11_device_context.put()); - D3D11_QUERY_DESC d3d11_query_info{}; - d3d11_query_info.Query = D3D11_QUERY_TIMESTAMP_DISJOINT; - if (S_OK != d3d11_device->CreateQuery(&d3d11_query_info, d3d11_query_freq.put())) { - return false; - } - d3d11_query_info.Query = D3D11_QUERY_TIMESTAMP; - if (S_OK != d3d11_device->CreateQuery(&d3d11_query_info, d3d11_query_time_begin.put())) { - return false; - } - if (S_OK != d3d11_device->CreateQuery(&d3d11_query_info, d3d11_query_time_end.put())) { - return false; - } - d3d11_query_info.Query = D3D11_QUERY_PIPELINE_STATISTICS; - if (S_OK != d3d11_device->CreateQuery(&d3d11_query_info, d3d11_query_statistics.put())) { - return false; - } - is_flying = false; - is_scope = false; - return true; - } - void destroyResources() - { - d3d11_query_freq = nullptr; - d3d11_query_time_begin = nullptr; - d3d11_query_time_end = nullptr; - d3d11_query_statistics = nullptr; - is_flying = false; - is_scope = false; - } - void fetchData() - { - assert(d3d11_device_context); - assert(d3d11_query_freq); - assert(d3d11_query_time_begin); - assert(d3d11_query_time_end); - assert(d3d11_query_statistics); - if (!is_flying) { - return; - } - if (d3d11_query_freq) { - while (S_OK != d3d11_device_context->GetData(d3d11_query_freq.get(), &freq, sizeof(freq), 0)) { - ; - } - } - if (d3d11_query_time_begin) { - while (S_OK != d3d11_device_context->GetData(d3d11_query_time_begin.get(), &time_begin, sizeof(time_begin), 0)) { - ; - } - } - if (d3d11_query_time_end) { - while (S_OK != d3d11_device_context->GetData(d3d11_query_time_end.get(), &time_end, sizeof(time_end), 0)) { - ; - } - } - if (d3d11_query_statistics) { - while (S_OK != d3d11_device_context->GetData(d3d11_query_statistics.get(), &statistics, sizeof(statistics), 0)) { - ; - } - } - is_flying = false; - } - double getTime() - { - if (freq.Frequency == 0) { - return 0.0; - } - return double(time_end - time_begin) / double(freq.Frequency); - } - void begin() - { - if (is_flying) { - fetchData(); - } - assert(!is_flying); - assert(!is_scope); - is_scope = true; - assert(d3d11_device_context); - assert(d3d11_query_freq); - assert(d3d11_query_time_begin); - assert(d3d11_query_statistics); - if (d3d11_query_freq) { - d3d11_device_context->Begin(d3d11_query_freq.get()); - } - if (d3d11_query_time_begin) { - d3d11_device_context->End(d3d11_query_time_begin.get()); // timestamp End only - } - if (d3d11_query_statistics) { - d3d11_device_context->Begin(d3d11_query_statistics.get()); - } - } - void end() - { - assert(d3d11_device_context); - assert(d3d11_query_freq); - assert(d3d11_query_time_end); - assert(d3d11_query_statistics); - assert(is_scope); - if (d3d11_query_freq) { - d3d11_device_context->End(d3d11_query_freq.get()); - } - if (d3d11_query_time_end) { - d3d11_device_context->End(d3d11_query_time_end.get()); // timestamp End only - } - if (d3d11_query_statistics) { - d3d11_device_context->End(d3d11_query_statistics.get()); - } - is_scope = false; - is_flying = true; - } - - FrameQuery(Graphics::IDevice* p_device) : m_device(p_device) { - createResources(static_cast(m_device->getNativeHandle())); - m_device->addEventListener(this); - } - ~FrameQuery() { - m_device->removeEventListener(this); - } - }; - - class ApplicationModel_Win32 : public implement::ReferenceCounted - { - private: - // 多个线程共享 - - SmartReference m_window; - Microsoft::WRL::Wrappers::Event win32_event_exit; - bool m_exit_flag{}; - - // 仅限工作线程 - - SmartReference m_device; - SmartReference m_swapchain; - SmartReference m_renderer; - IFrameRateController* m_p_frame_rate_controller{}; - FrameRateController m_frame_rate_controller; - SteadyFrameRateController m_steady_frame_rate_controller; - IApplicationEventListener* m_listener{ nullptr }; - size_t m_framestate_index{ 0 }; - FrameStatistics m_framestate[2]{}; - std::vector m_frame_query_list; - size_t m_frame_query_index{}; - - static DWORD WINAPI win32_thread_worker_entry(LPVOID lpThreadParameter); - void worker(); - - bool runSingleThread(); - bool runDoubleThread(); - - public: - // 内部公开 - - void runFrame(); - - public: - // 多个线程共享 - - Graphics::IWindow* getWindow() { return *m_window; } - void requestExit(); - - // 仅限工作线程 - - IFrameRateController* getFrameRateController() { return m_p_frame_rate_controller; }; - Graphics::IDevice* getDevice() { return *m_device; } - Graphics::ISwapChain* getSwapChain() { return *m_swapchain; } - Graphics::IRenderer* getRenderer() { return *m_renderer; } - FrameStatistics getFrameStatistics(); - FrameRenderStatistics getFrameRenderStatistics(); - - // 仅限主线程 - - bool run(); - - public: - ApplicationModel_Win32(IApplicationEventListener* p_listener); - ~ApplicationModel_Win32(); - }; -} diff --git a/LuaSTG/Core/Graphics/Device.hpp b/LuaSTG/Core/Graphics/Device.hpp deleted file mode 100644 index ec02d07c..00000000 --- a/LuaSTG/Core/Graphics/Device.hpp +++ /dev/null @@ -1,206 +0,0 @@ -#pragma once -#include "core/Vector2.hpp" -#include "core/Rect.hpp" -#include "core/ReferenceCounted.hpp" -#include "core/Data.hpp" -#include "core/ImmutableString.hpp" -#include "core/Image.hpp" - -#define LUASTG_ENABLE_DIRECT2D - -namespace core::Graphics -{ - struct IDeviceEventListener - { - virtual void onDeviceCreate() = 0; - virtual void onDeviceDestroy() = 0; - }; - - struct DeviceMemoryUsageStatistics - { - struct DeviceMemoryUsage - { - uint64_t budget; - uint64_t current_usage; - uint64_t available_for_reservation; - uint64_t current_reservation; - }; - DeviceMemoryUsage local{}; - DeviceMemoryUsage non_local{}; - }; - - enum class Filter - { - Point, - PointMinLinear, - PointMagLinear, - PointMipLinear, - LinearMinPoint, - LinearMagPoint, - LinearMipPoint, - Linear, - Anisotropic, - }; - - enum class TextureAddressMode - { - Wrap, - Mirror, - Clamp, - Border, - MirrorOnce, - }; - - enum class BorderColor - { - Black, - OpaqueBlack, - TransparentWhite, - White, - }; - - struct SamplerState - { - Filter filer; - TextureAddressMode address_u; - TextureAddressMode address_v; - TextureAddressMode address_w; - float mip_lod_bias; - uint32_t max_anisotropy; - float min_lod; - float max_lod; - BorderColor border_color; - SamplerState() - : filer(Filter::Linear) - , address_u(TextureAddressMode::Clamp) - , address_v(TextureAddressMode::Clamp) - , address_w(TextureAddressMode::Clamp) - , mip_lod_bias(0.0f) - , max_anisotropy(1u) - , min_lod(-FLT_MAX) - , max_lod(FLT_MAX) - , border_color(BorderColor::Black) - {} - SamplerState(Filter filter_, TextureAddressMode address_) - : filer(filter_) - , address_u(address_) - , address_v(address_) - , address_w(address_) - , mip_lod_bias(0.0f) - , max_anisotropy(1u) - , min_lod(-FLT_MAX) - , max_lod(FLT_MAX) - , border_color(BorderColor::Black) - {} - }; - - struct ISamplerState : IReferenceCounted - { - }; - - struct ITexture2D : IReferenceCounted - { - virtual void* getNativeHandle() const noexcept = 0; - - virtual bool isDynamic() const noexcept = 0; - virtual bool isPremultipliedAlpha() const noexcept = 0; - virtual void setPremultipliedAlpha(bool v) = 0; - virtual Vector2U getSize() const noexcept = 0; - virtual bool setSize(Vector2U size) = 0; - - virtual bool uploadPixelData(RectU rc, void const* data, uint32_t pitch) = 0; - virtual void setImage(IImage* image) = 0; - - virtual bool saveToFile(StringView path) = 0; - - virtual void setSamplerState(ISamplerState* p_sampler) = 0; - // Might be nullptr - virtual ISamplerState* getSamplerState() const noexcept = 0; - }; - - struct IRenderTarget : IReferenceCounted - { - virtual void* getNativeHandle() const noexcept = 0; - virtual void* getNativeBitmapHandle() const noexcept = 0; - - virtual bool setSize(Vector2U size) = 0; - virtual ITexture2D* getTexture() const noexcept = 0; - }; - - struct IDepthStencilBuffer : IReferenceCounted - { - virtual void* getNativeHandle() const noexcept = 0; - - virtual bool setSize(Vector2U size) = 0; - virtual Vector2U getSize() const noexcept = 0; - }; - - struct IBuffer : IReferenceCounted { - virtual bool map(uint32_t size_in_bytes, bool discard, void** out_pointer) = 0; - virtual bool unmap() = 0; - }; - - struct IDevice : IReferenceCounted - { - virtual void addEventListener(IDeviceEventListener* e) = 0; - virtual void removeEventListener(IDeviceEventListener* e) = 0; - - virtual DeviceMemoryUsageStatistics getMemoryUsageStatistics() = 0; - - virtual bool recreate() = 0; - virtual void setPreferenceGpu(StringView preferred_gpu) = 0; - virtual uint32_t getGpuCount() = 0; - virtual StringView getGpuName(uint32_t index) = 0; - virtual StringView getCurrentGpuName() const noexcept = 0; - - virtual void* getNativeHandle() = 0; - virtual void* getNativeRendererHandle() = 0; - - virtual bool createVertexBuffer(uint32_t size_in_bytes, IBuffer** output) = 0; - virtual bool createIndexBuffer(uint32_t size_in_bytes, IBuffer** output) = 0; - virtual bool createConstantBuffer(uint32_t size_in_bytes, IBuffer** output) = 0; - - virtual bool createTextureFromFile(StringView path, bool mipmap, ITexture2D** pp_texture) = 0; - virtual bool createTextureFromImage(IImage* image, bool mipmap, ITexture2D** pp_texture) = 0; - virtual bool createTexture(Vector2U size, ITexture2D** pp_texture) = 0; - - virtual bool createRenderTarget(Vector2U size, IRenderTarget** pp_rt) = 0; - virtual bool createDepthStencilBuffer(Vector2U size, IDepthStencilBuffer** pp_ds) = 0; - - virtual bool createSamplerState(SamplerState const& info, ISamplerState** pp_sampler) = 0; - - static bool create(StringView preferred_gpu, IDevice** p_device); - }; -} - -namespace core { - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.ISamplerState - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("e3d354b2-5ba5-5ead-8e63-0d3516b45c05"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.ITexture2D - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("5477054a-61c9-5071-9339-a9959e538a21"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IRenderTarget - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("2753f336-07b6-5e69-95b1-46f1125531fa"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IDepthStencilBuffer - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("2c92426c-9703-57aa-88e6-073957b0d92c"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IBuffer - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("089911ec-bd44-519e-a1e6-41a0e8e4626c"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IDevice - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("f6b65f2d-4307-597e-bc16-f3504ef89def"); } -} diff --git a/LuaSTG/Core/Graphics/Direct3D11/Buffer.cpp b/LuaSTG/Core/Graphics/Direct3D11/Buffer.cpp deleted file mode 100644 index 896cb01b..00000000 --- a/LuaSTG/Core/Graphics/Direct3D11/Buffer.cpp +++ /dev/null @@ -1,132 +0,0 @@ -#include "Core/Graphics/Direct3D11/Buffer.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "Core/i18n.hpp" - -#define HRNew HRESULT hr = S_OK; -#define HRGet hr = gHR -#define HRCheckCallReport(x) if (FAILED(hr)) { i18n_core_system_call_report_error(x); } -#define HRCheckCallReturnBool(x) if (FAILED(hr)) { i18n_core_system_call_report_error(x); assert(false); return false; } -#define HRCheckCallNoAssertReturnBool(x) if (FAILED(hr)) { i18n_core_system_call_report_error(x); return false; } - -namespace { - uint32_t alignTo16 (uint32_t const size) { - return ((size + 15u) / 16u) * 16; - } -} - -// Buffer -namespace core::Graphics::Direct3D11 { - void Buffer::onDeviceCreate() { - if (m_initialized) { - createResources(); - } - } - void Buffer::onDeviceDestroy() { - m_buffer.reset(); - } - - bool Buffer::map(uint32_t const size_in_bytes, bool const discard, void** const out_pointer) { - if (size_in_bytes > m_size_in_bytes) { - assert(false); return false; - } - HRNew; - auto const ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - assert(m_buffer); - D3D11_MAPPED_SUBRESOURCE mapped{}; - HRGet = ctx->Map(m_buffer.get(), 0, discard ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped); - HRCheckCallReturnBool("ID3D11DeviceContext::Map"); - *out_pointer = mapped.pData; - return true; - } - bool Buffer::unmap() { - auto const ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - assert(m_buffer); - ctx->Unmap(m_buffer.get(), 0); - return true; - } - - Buffer::Buffer() = default; - Buffer::~Buffer() { - if (m_initialized && m_device) { - m_device->removeEventListener(this); - } - } - - bool Buffer::initialize(Device* const device, uint8_t const type, uint32_t const size_in_bytes) { - assert(device); - assert(type == type_vertex_buffer || type == type_index_buffer || type == type_constant_buffer); - assert(size_in_bytes > 0); - m_device = device; - m_size_in_bytes = size_in_bytes; - m_type = type; - if (!createResources()) { - return false; - } - m_initialized = true; - m_device->addEventListener(this); - return true; - } - bool Buffer::createResources() { - HRNew; - auto const device = m_device->GetD3D11Device(); - assert(device); - D3D11_BUFFER_DESC info{}; - info.ByteWidth = m_size_in_bytes; - info.Usage = D3D11_USAGE_DYNAMIC; - switch (m_type) { - case type_vertex_buffer: - info.BindFlags = D3D11_BIND_VERTEX_BUFFER; - break; - case type_index_buffer: - info.BindFlags = D3D11_BIND_INDEX_BUFFER; - break; - case type_constant_buffer: - // For a constant buffer (BindFlags of D3D11_BUFFER_DESC set to D3D11_BIND_CONSTANT_BUFFER), - // you must set the ByteWidth value of D3D11_BUFFER_DESC in multiples of 16, and less than or equal to D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT. - // https://learn.microsoft.com/en-us/windows/win32/api/D3D11/nf-d3d11-id3d11device-createbuffer - info.ByteWidth = alignTo16(info.ByteWidth); - info.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - break; - default: - assert(false); return false; - } - info.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - HRGet = device->CreateBuffer(&info, nullptr, m_buffer.put()); - HRCheckCallReturnBool("ID3D11Device::CreateBuffer"); - return true; - } -} -namespace core::Graphics::Direct3D11 { - bool Device::createVertexBuffer(uint32_t const size_in_bytes, IBuffer** const output) { - *output = nullptr; - SmartReference buffer; - buffer.attach(new Buffer); - if (!buffer->initialize(this, Buffer::type_vertex_buffer, size_in_bytes)) { - return false; - } - *output = buffer.detach(); - return true; - } - bool Device::createIndexBuffer(uint32_t const size_in_bytes, IBuffer** const output) { - *output = nullptr; - SmartReference buffer; - buffer.attach(new Buffer); - if (!buffer->initialize(this, Buffer::type_index_buffer, size_in_bytes)) { - return false; - } - *output = buffer.detach(); - return true; - } - bool Device::createConstantBuffer(uint32_t const size_in_bytes, IBuffer** const output) { - *output = nullptr; - SmartReference buffer; - buffer.attach(new Buffer); - if (!buffer->initialize(this, Buffer::type_constant_buffer, size_in_bytes)) { - return false; - } - *output = buffer.detach(); - return true; - } -} diff --git a/LuaSTG/Core/Graphics/Direct3D11/Buffer.hpp b/LuaSTG/Core/Graphics/Direct3D11/Buffer.hpp deleted file mode 100644 index a5cabf38..00000000 --- a/LuaSTG/Core/Graphics/Direct3D11/Buffer.hpp +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once -#include "core/SmartReference.hpp" -#include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Device.hpp" - -// Buffer -namespace core::Graphics::Direct3D11 { - class Device; - - class Buffer final - : public implement::ReferenceCounted - , public IDeviceEventListener { - public: - // IDeviceEventListener - - void onDeviceCreate() override; - void onDeviceDestroy() override; - - // IBuffer - - bool map(uint32_t size_in_bytes, bool discard, void** out_pointer) override; - bool unmap() override; - - // Buffer - - Buffer(); - Buffer(Buffer const&) = delete; - Buffer(Buffer&&) = delete; - Buffer& operator=(Buffer const&) = delete; - Buffer& operator=(Buffer&&) = delete; - ~Buffer(); - - [[nodiscard]] ID3D11Buffer* getNativeBuffer() const noexcept { return m_buffer.get(); } - - static constexpr uint8_t type_vertex_buffer{ 1 }; - static constexpr uint8_t type_index_buffer{ 2 }; - static constexpr uint8_t type_constant_buffer{ 3 }; - - bool initialize(Device* device, uint8_t type, uint32_t size_in_bytes); - bool createResources(); - - private: - SmartReference m_device; - wil::com_ptr_nothrow m_buffer; - uint32_t m_size_in_bytes{}; - uint8_t m_type{}; - bool m_initialized{ false }; - }; -} diff --git a/LuaSTG/Core/Graphics/Direct3D11/DepthStencilBuffer.cpp b/LuaSTG/Core/Graphics/Direct3D11/DepthStencilBuffer.cpp deleted file mode 100644 index 2e777bee..00000000 --- a/LuaSTG/Core/Graphics/Direct3D11/DepthStencilBuffer.cpp +++ /dev/null @@ -1,96 +0,0 @@ -#include "Core/Graphics/Direct3D11/DepthStencilBuffer.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "Core/i18n.hpp" - -// DepthStencilBuffer -namespace core::Graphics::Direct3D11 { - void DepthStencilBuffer::onDeviceCreate() { - if (m_initialized) { - createResource(); - } - } - void DepthStencilBuffer::onDeviceDestroy() { - m_texture.Reset(); - m_view.Reset(); - } - - bool DepthStencilBuffer::setSize(Vector2U const size) { - m_texture.Reset(); - m_view.Reset(); - m_size = size; - return createResource(); - } - - DepthStencilBuffer::DepthStencilBuffer() = default; - DepthStencilBuffer::~DepthStencilBuffer() { - if (m_initialized && m_device) { - m_device->removeEventListener(this); - } - } - - bool DepthStencilBuffer::initialize(Device* const device, Vector2U const size) { - assert(device); - assert(size.x > 0 && size.y > 0); - m_device = device; - m_size = size; - if (!createResource()) { - return false; - } - m_initialized = true; - m_device->addEventListener(this); - return true; - } - bool DepthStencilBuffer::createResource() { - HRESULT hr = S_OK; - - auto* d3d11_device = m_device->GetD3D11Device(); - auto* d3d11_devctx = m_device->GetD3D11DeviceContext(); - if (!d3d11_device || !d3d11_devctx) - return false; - - D3D11_TEXTURE2D_DESC tex2ddef = { - .Width = m_size.x, - .Height = m_size.y, - .MipLevels = 1, - .ArraySize = 1, - .Format = DXGI_FORMAT_D24_UNORM_S8_UINT, - .SampleDesc = DXGI_SAMPLE_DESC{.Count = 1,.Quality = 0,}, - .Usage = D3D11_USAGE_DEFAULT, - .BindFlags = D3D11_BIND_DEPTH_STENCIL, - .CPUAccessFlags = 0, - .MiscFlags = 0, - }; - hr = gHR = d3d11_device->CreateTexture2D(&tex2ddef, nullptr, &m_texture); - if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateTexture2D"); - return false; - } - M_D3D_SET_DEBUG_NAME(m_texture.Get(), "DepthStencilBuffer_D3D11::d3d11_texture2d"); - - D3D11_DEPTH_STENCIL_VIEW_DESC dsvdef = { - .Format = tex2ddef.Format, - .ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D, - .Texture2D = D3D11_TEX2D_DSV{.MipSlice = 0,}, - }; - hr = gHR = d3d11_device->CreateDepthStencilView(m_texture.Get(), &dsvdef, &m_view); - if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateDepthStencilView"); - return false; - } - M_D3D_SET_DEBUG_NAME(m_view.Get(), "DepthStencilBuffer_D3D11::d3d11_dsv"); - - return true; - } -} -namespace core::Graphics::Direct3D11 { - bool Device::createDepthStencilBuffer(Vector2U const size, IDepthStencilBuffer** const pp_ds) { - *pp_ds = nullptr; - SmartReference buffer; - buffer.attach(new DepthStencilBuffer); - if (!buffer->initialize(this, size)) { - return false; - } - *pp_ds = buffer.detach(); - return true; - } -} diff --git a/LuaSTG/Core/Graphics/Direct3D11/DepthStencilBuffer.hpp b/LuaSTG/Core/Graphics/Direct3D11/DepthStencilBuffer.hpp deleted file mode 100644 index 7c176c4c..00000000 --- a/LuaSTG/Core/Graphics/Direct3D11/DepthStencilBuffer.hpp +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once -#include "core/SmartReference.hpp" -#include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Device.hpp" - -// DepthStencilBuffer -namespace core::Graphics::Direct3D11 { - class Device; - - class DepthStencilBuffer final - : public implement::ReferenceCounted - , public IDeviceEventListener { - public: - // IDeviceEventListener - - void onDeviceCreate() override; - void onDeviceDestroy() override; - - // IDepthStencilBuffer - - [[nodiscard]] void* getNativeHandle() const noexcept override { return m_view.Get(); } - bool setSize(Vector2U size) override; - [[nodiscard]] Vector2U getSize() const noexcept override { return m_size; } - - // DepthStencilBuffer - - DepthStencilBuffer(); - DepthStencilBuffer(DepthStencilBuffer const&) = delete; - DepthStencilBuffer(DepthStencilBuffer&&) = delete; - DepthStencilBuffer& operator=(DepthStencilBuffer const&) = delete; - DepthStencilBuffer& operator=(DepthStencilBuffer&&) = delete; - ~DepthStencilBuffer(); - - [[nodiscard]] ID3D11Texture2D* GetResource() const noexcept { return m_texture.Get(); } - [[nodiscard]] ID3D11DepthStencilView* GetView() const noexcept { return m_view.Get(); } - - bool initialize(Device* device, Vector2U size); - bool createResource(); - - private: - SmartReference m_device; - Microsoft::WRL::ComPtr m_texture; - Microsoft::WRL::ComPtr m_view; - Vector2U m_size{}; - bool m_initialized{ false }; - }; -} diff --git a/LuaSTG/Core/Graphics/Direct3D11/Device.cpp b/LuaSTG/Core/Graphics/Direct3D11/Device.cpp deleted file mode 100644 index bb7ac892..00000000 --- a/LuaSTG/Core/Graphics/Direct3D11/Device.cpp +++ /dev/null @@ -1,1087 +0,0 @@ -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "core/Configuration.hpp" -#include "Core/i18n.hpp" -#include "Platform/WindowsVersion.hpp" -#include "Platform/AdapterPolicy.hpp" -#include "Platform/Direct3D11.hpp" -#include "utf8.hpp" - -namespace { - std::string bytes_count_to_string(DWORDLONG size) { - int count = 0; - char buffer[64] = {}; - if (size < 1024llu) // B - { - count = std::snprintf(buffer, 64, "%u B", (unsigned int)size); - } - else if (size < (1024llu * 1024llu)) // KB - { - count = std::snprintf(buffer, 64, "%.2f KiB", (double)size / 1024.0); - } - else if (size < (1024llu * 1024llu * 1024llu)) // MB - { - count = std::snprintf(buffer, 64, "%.2f MiB", (double)size / (1024.0 * 1024.0)); - } - else // GB - { - count = std::snprintf(buffer, 64, "%.2f GiB", (double)size / (1024.0 * 1024.0 * 1024.0)); - } - return std::string(buffer, count); - } - std::string_view adapter_flags_to_string(UINT const flags) { - if ((flags & DXGI_ADAPTER_FLAG_REMOTE)) { - if (flags & DXGI_ADAPTER_FLAG_SOFTWARE) { - return i18n("DXGI_adapter_type_software_remote"); - } - else { - return i18n("DXGI_adapter_type_hardware_remote"); - } - } - else { - if (flags & DXGI_ADAPTER_FLAG_SOFTWARE) { - return i18n("DXGI_adapter_type_software"); - } - else { - return i18n("DXGI_adapter_type_hardware"); - } - } - } - std::string_view d3d_feature_level_to_string(D3D_FEATURE_LEVEL level) { - switch (level) { - case D3D_FEATURE_LEVEL_12_2: return "12.2"; - case D3D_FEATURE_LEVEL_12_1: return "12.1"; - case D3D_FEATURE_LEVEL_12_0: return "12.0"; - case D3D_FEATURE_LEVEL_11_1: return "11.1"; - case D3D_FEATURE_LEVEL_11_0: return "11.0"; - case D3D_FEATURE_LEVEL_10_1: return "10.1"; - case D3D_FEATURE_LEVEL_10_0: return "10.0"; - case D3D_FEATURE_LEVEL_9_3: return "9.3"; - case D3D_FEATURE_LEVEL_9_2: return "9.2"; - case D3D_FEATURE_LEVEL_9_1: return "9.1"; - default: return i18n("unknown"); - } - } - std::string multi_plane_overlay_flags_to_string(UINT const flags) { - std::string buffer; - if (flags & DXGI_OVERLAY_SUPPORT_FLAG_DIRECT) { - buffer.append("直接呈现"); - } - if (flags & DXGI_OVERLAY_SUPPORT_FLAG_SCALING) { - if (!buffer.empty()) buffer.append("、"); - buffer.append("缩放呈现"); - } - if (buffer.empty()) { - buffer.append("无"); - } - return buffer; - }; - std::string hardware_composition_flags_to_string(UINT const flags) { - std::string buffer; - if (flags & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_FULLSCREEN) { - buffer.append("全屏"); - } - if (flags & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_WINDOWED) { - if (!buffer.empty()) buffer.append("、"); - buffer.append("窗口"); - } - if (flags & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_CURSOR_STRETCHED) { - if (!buffer.empty()) buffer.append("、"); - buffer.append("鼠标指针缩放"); - } - if (buffer.empty()) { - buffer.append("无"); - } - return buffer; - }; - std::string_view rotation_to_string(DXGI_MODE_ROTATION const rot) { - switch (rot) { - default: - case DXGI_MODE_ROTATION_UNSPECIFIED: return "未知"; - case DXGI_MODE_ROTATION_IDENTITY: return "无"; - case DXGI_MODE_ROTATION_ROTATE90: return "90 度"; - case DXGI_MODE_ROTATION_ROTATE180: return "180 度"; - case DXGI_MODE_ROTATION_ROTATE270: return "270 度"; - } - }; - std::string_view threading_feature_to_string(D3D11_FEATURE_DATA_THREADING const v) { - if (v.DriverConcurrentCreates) { - if (v.DriverCommandLists) { - return "异步资源创建、多线程命令队列"; - } - else { - return "异步资源创建"; - } - } - else { - if (v.DriverCommandLists) { - return "多线程命令队列"; - } - else { - return "不支持"; - } - } - }; - std::string_view d3d_feature_level_to_maximum_texture2d_size_string(D3D_FEATURE_LEVEL const level) { - switch (level) { - case D3D_FEATURE_LEVEL_12_2: - case D3D_FEATURE_LEVEL_12_1: - case D3D_FEATURE_LEVEL_12_0: - case D3D_FEATURE_LEVEL_11_1: - case D3D_FEATURE_LEVEL_11_0: - return "16384x16384"; - case D3D_FEATURE_LEVEL_10_1: - case D3D_FEATURE_LEVEL_10_0: - return "8192x8192"; - case D3D_FEATURE_LEVEL_9_3: - return "4096x4096"; - case D3D_FEATURE_LEVEL_9_2: - case D3D_FEATURE_LEVEL_9_1: - default: - return "2048x2048"; - } - } - std::string_view renderer_architecture_to_string(BOOL const TileBasedDeferredRenderer) { - if (TileBasedDeferredRenderer) - return "Tile Based Deferred Renderer (TBDR)"; - else - return "Immediate Mode Rendering (IMR)"; - } -} - -// Device -namespace core::Graphics::Direct3D11 { - Device::Device(std::string_view const& preferred_gpu) - : preferred_adapter_name(preferred_gpu) { - // 创建图形组件 - - i18n_log_info("[core].Device_D3D11.start_creating_graphic_components"); - - testAdapterPolicy(); - if (!createDXGI()) - throw std::runtime_error("create basic DXGI components failed"); - if (!createD3D11()) - throw std::runtime_error("create basic D3D11 components failed"); - if (!createWIC()) - throw std::runtime_error("create basic WIC components failed"); -#ifdef LUASTG_ENABLE_DIRECT2D - if (!createD2D1()) - throw std::runtime_error("create basic D2D1 components failed"); -#endif - if (!createDWrite()) - throw std::runtime_error("create basic DWrite components failed"); - - i18n_log_info("[core].Device_D3D11.created_graphic_components"); - } - Device::~Device() { - // 清理对象 - destroyDWrite(); // 长生存期 -#ifdef LUASTG_ENABLE_DIRECT2D - destroyD2D1(); -#endif - destroyWIC(); // 长生存期 - destroyD3D11(); - destroyDXGI(); - assert(m_eventobj.size() == 0); - assert(m_eventobj_late.size() == 0); - } - - bool Device::createDXGIFactory() { - HRESULT hr = S_OK; - - // 创建 1.2 的组件,强制要求平台更新 - hr = gHR = dxgi_loader.CreateFactory(IID_PPV_ARGS(&dxgi_factory)); - if (FAILED(hr)) { - i18n_core_system_call_report_error("CreateDXGIFactory2 -> IDXGIFactory2"); - assert(false); return false; - } - - return true; - } - void Device::destroyDXGIFactory() { - dxgi_factory.Reset(); - } - bool Device::selectAdapter() { - HRESULT hr = S_OK; - - // 枚举所有图形设备 - - i18n_log_info("[core].Device_D3D11.enum_all_adapters"); - - struct AdapterCandidate { - Microsoft::WRL::ComPtr adapter; - std::string adapter_name; - DXGI_ADAPTER_DESC1 adapter_info; - D3D_FEATURE_LEVEL feature_level; - BOOL link_to_output; - }; - std::vector adapter_candidate; - - Microsoft::WRL::ComPtr dxgi_adapter_temp; - for (UINT idx = 0; bHR = dxgi_factory->EnumAdapters1(idx, &dxgi_adapter_temp); idx += 1) { - // 检查此设备是否支持 Direct3D 11 并获取特性级别 - bool supported_d3d11 = false; - D3D_FEATURE_LEVEL level_info = D3D_FEATURE_LEVEL_10_0; - hr = gHR = d3d11_loader.CreateDeviceFromAdapter( - dxgi_adapter_temp.Get(), - D3D11_CREATE_DEVICE_BGRA_SUPPORT, - D3D_FEATURE_LEVEL_10_0, - NULL, - &level_info, - NULL); - if (SUCCEEDED(hr)) { - supported_d3d11 = true; - } - - // 获取图形设备信息 - std::string dev_name = ""; - DXGI_ADAPTER_DESC1 desc_ = {}; - if (bHR = gHR = dxgi_adapter_temp->GetDesc1(&desc_)) { - bool soft_dev_type = (desc_.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) || (desc_.Flags & DXGI_ADAPTER_FLAG_REMOTE); - dev_name = utf8::to_string(desc_.Description); - i18n_log_info_fmt("[core].Device_D3D11.DXGI_adapter_detail_fmt" - , idx - , dev_name - , d3d_feature_level_to_string(level_info) - , adapter_flags_to_string(desc_.Flags) - , soft_dev_type ? i18n("DXGI_adapter_type_software_warning") : "" - , bytes_count_to_string(desc_.DedicatedVideoMemory) - , bytes_count_to_string(desc_.DedicatedSystemMemory) - , bytes_count_to_string(desc_.SharedSystemMemory) - , desc_.VendorId - , desc_.DeviceId - , desc_.SubSysId - , desc_.Revision - , static_cast(desc_.AdapterLuid.HighPart), desc_.AdapterLuid.LowPart - ); - if (soft_dev_type) { - supported_d3d11 = false; // 排除软件或远程设备 - } - } - else { - i18n_core_system_call_report_error("IDXGIAdapter1::GetDesc1"); - i18n_log_error_fmt("[core].Device_D3D11.DXGI_adapter_detail_error_fmt", idx); - supported_d3d11 = false; // 排除未知错误 - } - - // 枚举显示输出 - bool has_linked_output = false; - Microsoft::WRL::ComPtr dxgi_output_temp; - for (UINT odx = 0; bHR = dxgi_adapter_temp->EnumOutputs(odx, &dxgi_output_temp); odx += 1) { - Microsoft::WRL::ComPtr dxgi_output_temp6; - hr = gHR = dxgi_output_temp.As(&dxgi_output_temp6); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIOutput::QueryInterface -> IDXGIOutput6"); - // 不是严重错误 - } - - DXGI_OUTPUT_DESC1 o_desc = {}; - bool read_o_desc = false; - UINT comp_sp_flags = 0; - - if (dxgi_output_temp6) { - if (!(bHR = gHR = dxgi_output_temp6->CheckHardwareCompositionSupport(&comp_sp_flags))) { - comp_sp_flags = 0; - i18n_core_system_call_report_error("IDXGIOutput6::CheckHardwareCompositionSupport"); - } - if (bHR = gHR = dxgi_output_temp6->GetDesc1(&o_desc)) { - read_o_desc = true; - } - else { - i18n_core_system_call_report_error("IDXGIOutput6::GetDesc1"); - } - } - if (!read_o_desc) { - DXGI_OUTPUT_DESC desc_0_ = {}; - if (bHR = gHR = dxgi_output_temp->GetDesc(&desc_0_)) { - std::memcpy(o_desc.DeviceName, desc_0_.DeviceName, sizeof(o_desc.DeviceName)); - o_desc.DesktopCoordinates = desc_0_.DesktopCoordinates; - o_desc.AttachedToDesktop = desc_0_.AttachedToDesktop; - o_desc.Rotation = desc_0_.Rotation; - o_desc.Monitor = desc_0_.Monitor; - read_o_desc = true; - } - else { - i18n_core_system_call_report_error("IDXGIOutput::GetDesc"); - } - } - - if (read_o_desc) { - i18n_log_info_fmt("[core].Device_D3D11.DXGI_output_detail_fmt" - , idx, odx - , o_desc.AttachedToDesktop ? i18n("DXGI_output_connected") : i18n("DXGI_output_not_connect") - , o_desc.DesktopCoordinates.left - , o_desc.DesktopCoordinates.top - , o_desc.DesktopCoordinates.right - o_desc.DesktopCoordinates.left - , o_desc.DesktopCoordinates.bottom - o_desc.DesktopCoordinates.top - , rotation_to_string(o_desc.Rotation) - , hardware_composition_flags_to_string(comp_sp_flags) - ); - has_linked_output = true; - } - else { - i18n_log_error_fmt("[core].Device_D3D11.DXGI_output_detail_error_fmt", idx, odx); - } - } - dxgi_output_temp.Reset(); - - // 加入候选列表 - if (supported_d3d11) { - adapter_candidate.emplace_back(AdapterCandidate{ - .adapter = dxgi_adapter_temp, - .adapter_name = std::move(dev_name), - .adapter_info = desc_, - .feature_level = level_info, - .link_to_output = has_linked_output, - }); - } - } - dxgi_adapter_temp.Reset(); - - // 选择图形设备 - - BOOL link_to_output = false; - for (auto& v : adapter_candidate) { - if (v.adapter_name == preferred_adapter_name) { - dxgi_adapter = v.adapter; - dxgi_adapter_name = v.adapter_name; - link_to_output = v.link_to_output; - break; - } - } - if (!dxgi_adapter && !adapter_candidate.empty()) { - auto& v = adapter_candidate[0]; - dxgi_adapter = v.adapter; - dxgi_adapter_name = v.adapter_name; - link_to_output = v.link_to_output; - } - dxgi_adapter_name_list.clear(); - for (auto& v : adapter_candidate) { - dxgi_adapter_name_list.emplace_back(std::move(v.adapter_name)); - } - adapter_candidate.clear(); - - // 获取图形设备 - - if (dxgi_adapter) { - M_D3D_SET_DEBUG_NAME(dxgi_adapter.Get(), "Device_D3D11::dxgi_adapter"); - i18n_log_info_fmt("[core].Device_D3D11.select_DXGI_adapter_fmt", dxgi_adapter_name); - if (!link_to_output) { - i18n_log_warn_fmt("[core].Device_D3D11.DXGI_adapter_no_output_warning_fmt", dxgi_adapter_name); - } - } - else { - i18n_log_critical("[core].Device_D3D11.no_available_DXGI_adapter"); - return false; - } - - return true; - } - bool Device::createDXGI() { - HRESULT hr = S_OK; - - i18n_log_info("[core].Device_D3D11.start_creating_basic_DXGI_components"); - - // 创建工厂 - - if (!createDXGIFactory()) return false; - - // 检测特性支持情况 - - Microsoft::WRL::ComPtr dxgi_factory3; - hr = gHR = dxgi_factory.As(&dxgi_factory3); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIFactory1::QueryInterface -> IDXGIFactory3"); - // 不是严重错误 - } - - Microsoft::WRL::ComPtr dxgi_factory4; - hr = gHR = dxgi_factory.As(&dxgi_factory4); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIFactory1::QueryInterface -> IDXGIFactory4"); - // 不是严重错误 - } - - Microsoft::WRL::ComPtr dxgi_factory5; - hr = gHR = dxgi_factory.As(&dxgi_factory5); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIFactory1::QueryInterface -> IDXGIFactory5"); - // 不是严重错误 - } - - Microsoft::WRL::ComPtr dxgi_factory6; - hr = gHR = dxgi_factory.As(&dxgi_factory6); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIFactory1::QueryInterface -> IDXGIFactory6"); - // 不是严重错误 - } - - Microsoft::WRL::ComPtr dxgi_factory7; - hr = gHR = dxgi_factory.As(&dxgi_factory7); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIFactory1::QueryInterface -> IDXGIFactory7"); - // 不是严重错误 - } - - if (dxgi_factory5) { - BOOL value = FALSE; - hr = gHR = dxgi_factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &value, sizeof(value)); - if (SUCCEEDED(hr)) { - dxgi_support_tearing = value; - } - else { - i18n_core_system_call_report_error("IDXGIFactory5::CheckFeatureSupport -> DXGI_FEATURE_PRESENT_ALLOW_TEARING"); - // 不是严重错误 - } - } - - // 打印特性支持情况 - i18n_log_info_fmt("[core].Device_D3D11.DXGI_detail_fmt" - , dxgi_support_tearing ? i18n("support") : i18n("not_support.requires_Windows_10_and_hardware") - ); - - // 获取适配器 - - if (!selectAdapter()) { - if (!core::ConfigurationLoader::getInstance().getGraphicsSystem().isAllowSoftwareDevice()) { - return false; - } - } - - // 检查适配器支持 - - if (dxgi_adapter) { - Microsoft::WRL::ComPtr dxgi_adapter2; - hr = gHR = dxgi_adapter.As(&dxgi_adapter2); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIAdapter1::QueryInterface -> IDXGIAdapter2"); - // 不是严重错误 - } - - Microsoft::WRL::ComPtr dxgi_adapter3; - hr = gHR = dxgi_adapter.As(&dxgi_adapter3); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIAdapter1::QueryInterface -> IDXGIAdapter3"); - // 不是严重错误 - } - - Microsoft::WRL::ComPtr dxgi_adapter4; - hr = gHR = dxgi_adapter.As(&dxgi_adapter4); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIAdapter1::QueryInterface -> IDXGIAdapter4"); - // 不是严重错误 - } - - i18n_log_info("[core].Device_D3D11.created_basic_DXGI_components"); - } - - return true; - } - void Device::destroyDXGI() { - destroyDXGIFactory(); - dxgi_adapter.Reset(); - - dxgi_adapter_name.clear(); - dxgi_adapter_name_list.clear(); - - dxgi_support_tearing = FALSE; - } - bool Device::createD3D11() { - HRESULT hr = S_OK; - - // 创建 - - i18n_log_info("[core].Device_D3D11.start_creating_basic_D3D11_components"); - - if (dxgi_adapter) { - hr = gHR = d3d11_loader.CreateDeviceFromAdapter( - dxgi_adapter.Get(), - D3D11_CREATE_DEVICE_BGRA_SUPPORT, - D3D_FEATURE_LEVEL_10_0, - &d3d11_device, - &d3d_feature_level, - &d3d11_devctx); - } - else if (core::ConfigurationLoader::getInstance().getGraphicsSystem().isAllowSoftwareDevice()) { - D3D_DRIVER_TYPE d3d_driver_type = D3D_DRIVER_TYPE_UNKNOWN; - hr = gHR = d3d11_loader.CreateDeviceFromSoftAdapter( - D3D11_CREATE_DEVICE_BGRA_SUPPORT, - D3D_FEATURE_LEVEL_10_0, - &d3d11_device, - &d3d_feature_level, - &d3d11_devctx, - &d3d_driver_type); - if (SUCCEEDED(hr)) { - switch (d3d_driver_type) { - case D3D_DRIVER_TYPE_REFERENCE: - spdlog::info("[core] 设备类型:参考光栅化设备"); - break; - case D3D_DRIVER_TYPE_SOFTWARE: - spdlog::info("[core] 设备类型:软件光栅化设备"); - break; - case D3D_DRIVER_TYPE_WARP: - spdlog::info("[core] 设备类型:Windows 高级光栅化平台(WARP)"); - break; - } - } - } - if (!d3d11_device) { - i18n_core_system_call_report_error("D3D11CreateDevice"); - return false; - } - M_D3D_SET_DEBUG_NAME(d3d11_device.Get(), "Device_D3D11::d3d11_device"); - M_D3D_SET_DEBUG_NAME(d3d11_devctx.Get(), "Device_D3D11::d3d11_devctx"); - if (!dxgi_adapter) { - hr = gHR = Platform::Direct3D11::GetDeviceAdater(d3d11_device.Get(), &dxgi_adapter); - if (FAILED(hr)) { - i18n_core_system_call_report_error("Platform::Direct3D11::GetDeviceAdater"); - return false; - } - } - - // 特性检查 - - hr = gHR = d3d11_device.As(&d3d11_device1); - if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::QueryInterface -> ID3D11Device1"); - // 不是严重错误 - } - hr = gHR = d3d11_devctx.As(&d3d11_devctx1); - if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11DeviceContext::QueryInterface -> ID3D11DeviceContext1"); - // 不是严重错误 - } - - struct D3DX11_FEATURE_DATA_FORMAT_SUPPORT { - DXGI_FORMAT InFormat; - UINT OutFormatSupport; - UINT OutFormatSupport2; - }; - auto check_format_support = [&](DXGI_FORMAT const format, std::string_view const& name) ->D3DX11_FEATURE_DATA_FORMAT_SUPPORT { - std::string name1("ID3D11Device::CheckFeatureSupport -> D3D11_FEATURE_FORMAT_SUPPORT ("); name1.append(name); name1.append(")"); - std::string name2("ID3D11Device::CheckFeatureSupport -> D3D11_FEATURE_FORMAT_SUPPORT2 ("); name2.append(name); name2.append(")"); - - D3D11_FEATURE_DATA_FORMAT_SUPPORT data1 = { .InFormat = format }; - HRESULT const hr1 = gHR = d3d11_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data1, sizeof(D3D11_FEATURE_DATA_FORMAT_SUPPORT)); - if (FAILED(hr1)) i18n_core_system_call_report_error(name1); - - D3D11_FEATURE_DATA_FORMAT_SUPPORT2 data2 = { .InFormat = format }; - HRESULT const hr2 = gHR = d3d11_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &data2, sizeof(D3D11_FEATURE_DATA_FORMAT_SUPPORT2)); - if (FAILED(hr2)) i18n_core_system_call_report_error(name2); - - return D3DX11_FEATURE_DATA_FORMAT_SUPPORT{ .InFormat = format, .OutFormatSupport = data1.OutFormatSupport, .OutFormatSupport2 = data2.OutFormatSupport2 }; - }; - auto check_format_support_1 = [&](DXGI_FORMAT const format, std::string_view const& name) ->D3DX11_FEATURE_DATA_FORMAT_SUPPORT { - std::string name1("ID3D11Device::CheckFeatureSupport -> D3D11_FEATURE_FORMAT_SUPPORT ("); name1.append(name); name1.append(")"); - - D3D11_FEATURE_DATA_FORMAT_SUPPORT data1 = { .InFormat = format }; - HRESULT const hr1 = gHR = d3d11_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &data1, sizeof(D3D11_FEATURE_DATA_FORMAT_SUPPORT)); - if (FAILED(hr1)) i18n_core_system_call_report_error(name1); - - D3D11_FEATURE_DATA_FORMAT_SUPPORT2 data2 = { .InFormat = format }; - d3d11_device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &data2, sizeof(D3D11_FEATURE_DATA_FORMAT_SUPPORT2)); - - return D3DX11_FEATURE_DATA_FORMAT_SUPPORT{ .InFormat = format, .OutFormatSupport = data1.OutFormatSupport, .OutFormatSupport2 = data2.OutFormatSupport2 }; - }; - - #define _CHECK_FORMAT_SUPPORT(_NAME, _FORMAT) \ - D3DX11_FEATURE_DATA_FORMAT_SUPPORT d3d11_feature_format_##_NAME = check_format_support(_FORMAT, #_FORMAT); - #define _CHECK_FORMAT_SUPPORT_1(_NAME, _FORMAT) \ - D3DX11_FEATURE_DATA_FORMAT_SUPPORT d3d11_feature_format_##_NAME = check_format_support_1(_FORMAT, #_FORMAT); - - _CHECK_FORMAT_SUPPORT(rgba32, DXGI_FORMAT_R8G8B8A8_UNORM); - _CHECK_FORMAT_SUPPORT(rgba32_srgb, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB); - _CHECK_FORMAT_SUPPORT(bgra32, DXGI_FORMAT_B8G8R8A8_UNORM); - _CHECK_FORMAT_SUPPORT(bgra32_srgb, DXGI_FORMAT_B8G8R8A8_UNORM_SRGB); - _CHECK_FORMAT_SUPPORT_1(d24_s8, DXGI_FORMAT_D24_UNORM_S8_UINT); - - #undef _CHECK_FORMAT_SUPPORT - - D3D11_FEATURE_DATA_THREADING d3d11_feature_mt = {}; - HRESULT hr_mt = d3d11_device->CheckFeatureSupport(D3D11_FEATURE_THREADING, &d3d11_feature_mt, sizeof(d3d11_feature_mt)); - if (FAILED(hr_mt)) { - i18n_core_system_call_report_error("ID3D11Device::CheckFeatureSupport -> D3D11_FEATURE_THREADING"); - // 不是严重错误 - } - - D3D11_FEATURE_DATA_ARCHITECTURE_INFO d3d11_feature_arch = {}; - HRESULT hr_arch = d3d11_device->CheckFeatureSupport(D3D11_FEATURE_ARCHITECTURE_INFO, &d3d11_feature_arch, sizeof(d3d11_feature_arch)); - if (FAILED(hr_arch)) { - i18n_core_system_call_report_error("ID3D11Device::CheckFeatureSupport -> D3D11_FEATURE_ARCHITECTURE_INFO"); - // 不是严重错误 - } - - D3D11_FEATURE_DATA_D3D11_OPTIONS2 d3d11_feature_o2 = {}; - HRESULT hr_o2 = d3d11_device->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS2, &d3d11_feature_o2, sizeof(d3d11_feature_o2)); - if (FAILED(hr_o2)) { - i18n_core_system_call_report_error("ID3D11Device::CheckFeatureSupport -> D3D11_FEATURE_D3D11_OPTIONS2"); - // 不是严重错误 - } - - #define _FORMAT_INFO_STRING_FMT3 \ - " 用于顶点缓冲区:{}\n"\ - " 创建二维纹理:{}\n"\ - " 创建立方体纹理:{}\n"\ - " 着色器采样:{}\n"\ - " 创建多级渐进纹理:{}\n"\ - " 自动生成多级渐进纹理:{}\n"\ - " 绑定为渲染目标:{}\n"\ - " 像素颜色混合操作:{}\n"\ - " 绑定为深度、模板缓冲区:{}\n"\ - " 被 CPU 锁定、读取:{}\n"\ - " 解析多重采样:{}\n"\ - " 用于显示输出:{}\n"\ - " 创建多重采样渲染目标:{}\n"\ - " 像素颜色逻辑混合操作:{}\n"\ - " 资源可分块:{}\n"\ - " 资源可共享:{}\n"\ - " 多平面叠加:{}\n" - - #define _FORMAT_MAKE_SUPPORT i18n("support") : i18n("not_support") - - #define _FORMAT_INFO_STRING_ARG3(_NAME) \ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_TEXTURE2D ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_TEXTURECUBE ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_MIP ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_BLENDABLE ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_CPU_LOCKABLE ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_DISPLAY ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_OUTPUT_MERGER_LOGIC_OP) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_TILED ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_SHAREABLE ) ? _FORMAT_MAKE_SUPPORT\ - , (d3d11_feature_format_##_NAME.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_MULTIPLANE_OVERLAY ) ? _FORMAT_MAKE_SUPPORT - - spdlog::info("[core] Direct3D 11 设备功能支持:\n" - " Direct3D 功能级别:{}\n" - " R8G8B8A8 格式:\n" - _FORMAT_INFO_STRING_FMT3 - " R8G8B8A8 sRGB 格式:\n" - _FORMAT_INFO_STRING_FMT3 - " B8G8R8A8 格式:\n" - _FORMAT_INFO_STRING_FMT3 - " B8G8R8A8 sRGB 格式:\n" - _FORMAT_INFO_STRING_FMT3 - " D24 S8 格式:\n" - _FORMAT_INFO_STRING_FMT3 - " 最大二维纹理尺寸:{}\n" - " 多线程架构:{}\n" - " 渲染架构:{}\n" - " 统一内存架构(UMA):{}" - , d3d_feature_level_to_string(d3d_feature_level) - _FORMAT_INFO_STRING_ARG3(rgba32) - _FORMAT_INFO_STRING_ARG3(rgba32_srgb) - _FORMAT_INFO_STRING_ARG3(bgra32) - _FORMAT_INFO_STRING_ARG3(bgra32_srgb) - _FORMAT_INFO_STRING_ARG3(d24_s8) - , d3d_feature_level_to_maximum_texture2d_size_string(d3d_feature_level) - , threading_feature_to_string(d3d11_feature_mt) - , renderer_architecture_to_string(d3d11_feature_arch.TileBasedDeferredRenderer) - , d3d11_feature_o2.UnifiedMemoryArchitecture ? _FORMAT_MAKE_SUPPORT - ); - - #undef _FORMAT_INFO_STRING_ARG3 - #undef _FORMAT_MAKE_SUPPORT - #undef _FORMAT_INFO_STRING_FMT3 - - if ( - (d3d11_feature_format_bgra32.OutFormatSupport & D3D11_FORMAT_SUPPORT_TEXTURE2D) - && (d3d11_feature_format_bgra32.OutFormatSupport & D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER) - && (d3d11_feature_format_bgra32.OutFormatSupport & D3D11_FORMAT_SUPPORT_MIP) - && (d3d11_feature_format_bgra32.OutFormatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET) - && (d3d11_feature_format_bgra32.OutFormatSupport & D3D11_FORMAT_SUPPORT_BLENDABLE) - && (d3d11_feature_format_bgra32.OutFormatSupport & D3D11_FORMAT_SUPPORT_DISPLAY) - ) { - // 确实支持 - } - else { - spdlog::warn("[core] 此设备没有完整的 B8G8R8A8 格式支持,程序可能无法正常运行"); - } - - testMultiPlaneOverlay(); - - i18n_log_info("[core].Device_D3D11.created_basic_D3D11_components"); - - tracy_context = tracy_d3d11_context_create(d3d11_device.Get(), d3d11_devctx.Get()); - - return true; - } - void Device::destroyD3D11() { - tracy_d3d11_context_destroy(tracy_context); - tracy_context = nullptr; - - d3d_feature_level = D3D_FEATURE_LEVEL_10_0; - - d3d11_device.Reset(); - d3d11_device1.Reset(); - d3d11_devctx.Reset(); - d3d11_devctx1.Reset(); - } - bool Device::createWIC() { - HRESULT hr = S_OK; - - hr = gHR = CoCreateInstance(CLSID_WICImagingFactory2, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&wic_factory2)); - if (SUCCEEDED(hr)) { - hr = gHR = wic_factory2.As(&wic_factory); - assert(SUCCEEDED(hr)); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IWICImagingFactory2::QueryInterface -> IWICImagingFactory"); - return false; - } - } - else { - i18n_core_system_call_report_error("CoCreateInstance -> IWICImagingFactory2"); - // 没有那么严重,来再一次 - hr = gHR = CoCreateInstance(CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&wic_factory)); - assert(SUCCEEDED(hr)); - if (FAILED(hr)) { - i18n_core_system_call_report_error("CoCreateInstance -> IWICImagingFactory"); - return false; - } - } - - return true; - } - void Device::destroyWIC() { - wic_factory.Reset(); - wic_factory2.Reset(); - } -#ifdef LUASTG_ENABLE_DIRECT2D - bool Device::createD2D1() { - HRESULT hr = S_OK; - - hr = gHR = d2d1_loader.CreateFactory( - D2D1_FACTORY_TYPE_MULTI_THREADED, - IID_PPV_ARGS(&d2d1_factory)); - if (FAILED(hr)) { - i18n_core_system_call_report_error("D2D1CreateFactory -> ID2D1Factory1"); - assert(false); return false; - } - - Microsoft::WRL::ComPtr dxgi_device; - hr = gHR = d3d11_device.As(&dxgi_device); - if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::QueryInterface -> IDXGIDevice"); - assert(false); return false; - } - - hr = gHR = d2d1_factory->CreateDevice(dxgi_device.Get(), &d2d1_device); - if (FAILED(hr)) { - i18n_core_system_call_report_error("ID2D1Factory1::CreateDevice"); - assert(false); return false; - } - - hr = gHR = d2d1_device->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &d2d1_devctx); - if (FAILED(hr)) { - i18n_core_system_call_report_error("ID2D1Device::CreateDeviceContext"); - assert(false); return false; - } - - return true; - } - void Device::destroyD2D1() { - d2d1_factory.Reset(); - d2d1_device.Reset(); - d2d1_devctx.Reset(); - } -#endif - bool Device::createDWrite() { - HRESULT hr = S_OK; - - hr = gHR = dwrite_loader.CreateFactory(DWRITE_FACTORY_TYPE_SHARED, IID_PPV_ARGS(&dwrite_factory)); - if (FAILED(hr)) { - i18n_core_system_call_report_error("DWriteCreateFactory -> DWRITE_FACTORY_TYPE_SHARED"); - return false; - } - - return true; - } - void Device::destroyDWrite() { - dwrite_factory.Reset(); - } - bool Device::doDestroyAndCreate() { - dispatchEvent(EventType::DeviceDestroy); - - //destroyDWrite(); // 长生存期 -#ifdef LUASTG_ENABLE_DIRECT2D - destroyD2D1(); -#endif - //destroyWIC(); // 长生存期 - destroyD3D11(); - destroyDXGI(); - - testAdapterPolicy(); - - if (!createDXGI()) return false; - if (!createD3D11()) return false; - //if (!createWIC()) return false; // 长生存期 -#ifdef LUASTG_ENABLE_DIRECT2D - if (!createD2D1()) return false; -#endif - //if (!createDWrite()) return false; // 长生存期 - - dispatchEvent(EventType::DeviceCreate); - - return true; - } - bool Device::testAdapterPolicy() { - if (preferred_adapter_name.empty()) return true; // default GPU - - auto testAdapterName = [&]() -> bool { - HRESULT hr = S_OK; - Microsoft::WRL::ComPtr dxgi_adapter; - hr = gHR = dxgi_factory->EnumAdapters1(0, &dxgi_adapter); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIFactory1::EnumAdapters1 -> #0"); - assert(false); return false; - } - DXGI_ADAPTER_DESC1 desc = {}; - hr = gHR = dxgi_adapter->GetDesc1(&desc); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIAdapter1::GetDesc1"); - assert(false); return false; - } - std::string gpu_name(utf8::to_string(desc.Description)); - return preferred_adapter_name == gpu_name; - }; - auto testStage = [&](bool nv, bool amd) -> bool { - Platform::AdapterPolicy::setNVIDIA(nv); - Platform::AdapterPolicy::setAMD(amd); - - if (!createDXGIFactory()) return false; - - bool const result = testAdapterName(); - - destroyDXGIFactory(); - - return result; - }; - - // Stage 1 - Disable and test - if (testStage(false, false)) return true; - // Stage 2 - Enable and test - if (testStage(true, true)) return true; - // Stage 3 - NVIDIA and test - if (testStage(true, false)) return true; - // Stage 4 - AMD and test - if (testStage(false, true)) return true; - // Stage 5 - Disable and failed - Platform::AdapterPolicy::setAll(false); - - return false; - } - bool Device::testMultiPlaneOverlay() { - HRESULT hr = S_OK; - - Microsoft::WRL::ComPtr adapter_; - for (UINT i = 0; bHR = dxgi_factory->EnumAdapters1(i, &adapter_); i += 1) { - Microsoft::WRL::ComPtr output_; - for (UINT j = 0; bHR = adapter_->EnumOutputs(j, &output_); j += 1) { - DXGI_OUTPUT_DESC desc = {}; - hr = gHR = output_->GetDesc(&desc); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIOutput3::CheckOverlaySupport -> DXGI_FORMAT_B8G8R8A8_UNORM"); - assert(false); return false; - } - - BOOL overlay_ = FALSE; - Microsoft::WRL::ComPtr output2_; - if (bHR = output_.As(&output2_)) { - overlay_ = output2_->SupportsOverlays(); - } - - UINT overlay_flags = 0; - Microsoft::WRL::ComPtr output3_; - if (bHR = output_.As(&output3_)) { - hr = gHR = output3_->CheckOverlaySupport( - DXGI_FORMAT_B8G8R8A8_UNORM, - d3d11_device.Get(), - &overlay_flags); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIOutput3::CheckOverlaySupport -> DXGI_FORMAT_B8G8R8A8_UNORM"); - } - } - - UINT composition_flags = 0; - Microsoft::WRL::ComPtr output6_; - if (bHR = output_.As(&output6_)) { - hr = gHR = output6_->CheckHardwareCompositionSupport(&composition_flags); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIOutput6::CheckHardwareCompositionSupport"); - } - } - - i18n_log_info_fmt("[core].Device_D3D11.DXGI_output_detail_fmt2" - , i, j - , desc.AttachedToDesktop ? i18n("DXGI_output_connected") : i18n("DXGI_output_not_connect") - , desc.DesktopCoordinates.left - , desc.DesktopCoordinates.top - , desc.DesktopCoordinates.right - desc.DesktopCoordinates.left - , desc.DesktopCoordinates.bottom - desc.DesktopCoordinates.top - , rotation_to_string(desc.Rotation) - , overlay_ ? i18n("support") : i18n("not_support") - , multi_plane_overlay_flags_to_string(overlay_flags) - , hardware_composition_flags_to_string(composition_flags) - ); - } - } - - return true; - } - - bool Device::handleDeviceLost() { - if (d3d11_device) { - gHR = d3d11_device->GetDeviceRemovedReason(); - } - return doDestroyAndCreate(); - } - bool Device::validateDXGIFactory() { - if (!dxgi_factory->IsCurrent()) { - HRESULT hr = S_OK; - - dxgi_factory.Reset(); - dxgi_adapter.Reset(); - - Microsoft::WRL::ComPtr dxgi_device; - hr = gHR = d3d11_device.As(&dxgi_device); - if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::QueryInterface -> IDXGIDevice"); - return false; - } - - Microsoft::WRL::ComPtr dxgi_adapter_tmp; - hr = gHR = dxgi_device->GetAdapter(&dxgi_adapter_tmp); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIDevice::GetAdapter"); - return false; - } - - hr = gHR = dxgi_adapter_tmp.As(&dxgi_adapter); - if (FAILED(hr)) { - i18n_core_system_call_report_error("IDXGIAdapter::QueryInterface -> IDXGIAdapter1"); - return false; - } - - //hr = gHR = dxgi_adapter->GetParent(IID_PPV_ARGS(&dxgi_factory)); - //if (FAILED(hr)) - //{ - // i18n_core_system_call_report_error("IDXGIAdapter1::GetParent -> IDXGIFactory2"); - // return false; - //} - - // 创建 1.2 的组件,强制要求平台更新 - hr = gHR = dxgi_loader.CreateFactory(IID_PPV_ARGS(&dxgi_factory)); - if (FAILED(hr)) { - i18n_core_system_call_report_error("CreateDXGIFactory2 -> IDXGIFactory2"); - assert(false); return false; - } - - assert(dxgi_factory->IsCurrent()); - } - return true; - } - - void Device::dispatchEvent(EventType t) { - // 回调 - m_is_dispatch_event = true; - switch (t) { - case EventType::DeviceCreate: - for (auto& v : m_eventobj) { - if (v) v->onDeviceCreate(); - } - break; - case EventType::DeviceDestroy: - for (auto& v : m_eventobj) { - if (v) v->onDeviceDestroy(); - } - break; - } - m_is_dispatch_event = false; - // 处理那些延迟的对象 - removeEventListener(nullptr); - for (auto& v : m_eventobj_late) { - m_eventobj.emplace_back(v); - } - m_eventobj_late.clear(); - } - - void Device::addEventListener(IDeviceEventListener* e) { - removeEventListener(e); - if (m_is_dispatch_event) { - m_eventobj_late.emplace_back(e); - } - else { - m_eventobj.emplace_back(e); - } - } - void Device::removeEventListener(IDeviceEventListener* e) { - if (m_is_dispatch_event) { - for (auto& v : m_eventobj) { - if (v == e) { - v = nullptr; // 不破坏遍历过程 - } - } - } - else { - for (auto it = m_eventobj.begin(); it != m_eventobj.end();) { - if (*it == e) - it = m_eventobj.erase(it); - else - it++; - } - } - } - - DeviceMemoryUsageStatistics Device::getMemoryUsageStatistics() { - DeviceMemoryUsageStatistics data = {}; - Microsoft::WRL::ComPtr adapter; - if (bHR = dxgi_adapter.As(&adapter)) { - DXGI_QUERY_VIDEO_MEMORY_INFO info = {}; - if (bHR = gHR = adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info)) { - data.local.budget = info.Budget; - data.local.current_usage = info.CurrentUsage; - data.local.available_for_reservation = info.AvailableForReservation; - data.local.current_reservation = info.CurrentReservation; - } - if (bHR = gHR = adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &info)) { - data.non_local.budget = info.Budget; - data.non_local.current_usage = info.CurrentUsage; - data.non_local.available_for_reservation = info.AvailableForReservation; - data.non_local.current_reservation = info.CurrentReservation; - } - } - return data; - } - - bool Device::recreate() { - return doDestroyAndCreate(); - } - - bool Device::create(StringView preferred_gpu, Device** p_device) { - try { - *p_device = new Device(preferred_gpu); - return true; - } - catch (...) { - *p_device = nullptr; - return false; - } - } -} -namespace core::Graphics { - bool IDevice::create(StringView preferred_gpu, IDevice** p_device) { - try { - *p_device = new Direct3D11::Device(preferred_gpu); - return true; - } - catch (...) { - *p_device = nullptr; - return false; - } - } -} diff --git a/LuaSTG/Core/Graphics/Direct3D11/Device.hpp b/LuaSTG/Core/Graphics/Direct3D11/Device.hpp deleted file mode 100644 index 00d06339..00000000 --- a/LuaSTG/Core/Graphics/Direct3D11/Device.hpp +++ /dev/null @@ -1,161 +0,0 @@ -#pragma once -#include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Device.hpp" -#include "Platform/RuntimeLoader/DXGI.hpp" -#include "Platform/RuntimeLoader/Direct3D11.hpp" -#include "Platform/RuntimeLoader/Direct2D1.hpp" -#include "Platform/RuntimeLoader/DirectWrite.hpp" - -// Device -namespace core::Graphics::Direct3D11 { - class Device final - : public implement::ReferenceCounted { - private: - // DXGI - - Platform::RuntimeLoader::DXGI dxgi_loader; - Microsoft::WRL::ComPtr dxgi_factory; - Microsoft::WRL::ComPtr dxgi_adapter; - - std::string preferred_adapter_name; - - std::string dxgi_adapter_name; - std::vector dxgi_adapter_name_list; - - BOOL dxgi_support_tearing{ FALSE }; - - // Direct3D - - D3D_FEATURE_LEVEL d3d_feature_level{ D3D_FEATURE_LEVEL_10_0 }; - - // Direct3D 11 - - Platform::RuntimeLoader::Direct3D11 d3d11_loader; - Microsoft::WRL::ComPtr d3d11_device; - Microsoft::WRL::ComPtr d3d11_device1; - Microsoft::WRL::ComPtr d3d11_devctx; - Microsoft::WRL::ComPtr d3d11_devctx1; - - // Window Image Component - - Microsoft::WRL::ComPtr wic_factory; - Microsoft::WRL::ComPtr wic_factory2; - - // Direct2D 1 - -#ifdef LUASTG_ENABLE_DIRECT2D - Platform::RuntimeLoader::Direct2D1 d2d1_loader; - Microsoft::WRL::ComPtr d2d1_factory; - Microsoft::WRL::ComPtr d2d1_device; - Microsoft::WRL::ComPtr d2d1_devctx; -#endif - - // DirectWrite - - Platform::RuntimeLoader::DirectWrite dwrite_loader; - Microsoft::WRL::ComPtr dwrite_factory; - - // Debug - - tracy_d3d11_context_t tracy_context{}; - - public: - // Get API - - inline IDXGIFactory2* GetDXGIFactory2() const noexcept { return dxgi_factory.Get(); } - inline IDXGIAdapter1* GetDXGIAdapter1() const noexcept { return dxgi_adapter.Get(); } - - inline std::string_view GetAdapterName() const noexcept { return dxgi_adapter_name; } - inline std::vector& GetAdapterNameArray() { return dxgi_adapter_name_list; } - - inline D3D_FEATURE_LEVEL GetD3DFeatureLevel() const noexcept { return d3d_feature_level; } - - inline ID3D11Device* GetD3D11Device() const noexcept { return d3d11_device.Get(); } - inline ID3D11Device1* GetD3D11Device1() const noexcept { return d3d11_device1.Get(); } - inline ID3D11DeviceContext* GetD3D11DeviceContext() const noexcept { return d3d11_devctx.Get(); } - inline ID3D11DeviceContext1* GetD3D11DeviceContext1() const noexcept { return d3d11_devctx1.Get(); } - -#ifdef LUASTG_ENABLE_DIRECT2D - inline ID2D1Device* GetD2D1Device() const noexcept { return d2d1_device.Get(); } - inline ID2D1DeviceContext* GetD2D1DeviceContext() const noexcept { return d2d1_devctx.Get(); } -#endif - - inline IWICImagingFactory* GetWICImagingFactory() const noexcept { return wic_factory.Get(); } - - inline BOOL IsTearingSupport() const noexcept { return dxgi_support_tearing; } - - inline tracy_d3d11_context_t GetTracyContext() const noexcept { return tracy_context; } - - private: - bool createDXGIFactory(); - void destroyDXGIFactory(); - bool selectAdapter(); - bool createDXGI(); - void destroyDXGI(); - bool createD3D11(); - void destroyD3D11(); - bool createWIC(); - void destroyWIC(); -#ifdef LUASTG_ENABLE_DIRECT2D - bool createD2D1(); - void destroyD2D1(); -#endif - bool createDWrite(); - void destroyDWrite(); - bool doDestroyAndCreate(); - bool testAdapterPolicy(); - bool testMultiPlaneOverlay(); - - public: - bool handleDeviceLost(); - bool validateDXGIFactory(); - - private: - enum class EventType { - DeviceCreate, - DeviceDestroy, - }; - bool m_is_dispatch_event{ false }; - std::vector m_eventobj; - std::vector m_eventobj_late; - private: - void dispatchEvent(EventType t); - public: - void addEventListener(IDeviceEventListener* e); - void removeEventListener(IDeviceEventListener* e); - - DeviceMemoryUsageStatistics getMemoryUsageStatistics(); - - bool recreate(); - void setPreferenceGpu(StringView preferred_gpu) { preferred_adapter_name = preferred_gpu; } - uint32_t getGpuCount() { return static_cast(dxgi_adapter_name_list.size()); } - StringView getGpuName(uint32_t index) { return dxgi_adapter_name_list[index]; } - StringView getCurrentGpuName() const noexcept { return dxgi_adapter_name; } - - void* getNativeHandle() { return d3d11_device.Get(); } -#ifdef LUASTG_ENABLE_DIRECT2D - void* getNativeRendererHandle() { return d2d1_devctx.Get(); } -#else - void* getNativeRendererHandle() { return nullptr; } -#endif - - bool createVertexBuffer(uint32_t size_in_bytes, IBuffer** output) override; - bool createIndexBuffer(uint32_t size_in_bytes, IBuffer** output) override; - bool createConstantBuffer(uint32_t size_in_bytes, IBuffer** output) override; - - bool createTextureFromFile(StringView path, bool mipmap, ITexture2D** pp_texture); - bool createTexture(Vector2U size, ITexture2D** pp_texture); - bool createTextureFromImage(IImage* image, bool mipmap, ITexture2D** pp_texture); - bool createRenderTarget(Vector2U size, IRenderTarget** pp_rt); - bool createDepthStencilBuffer(Vector2U size, IDepthStencilBuffer** pp_ds); - - bool createSamplerState(core::Graphics::SamplerState const& info, ISamplerState** pp_sampler); - - public: - Device(std::string_view const& preferred_gpu = ""); - ~Device(); - - public: - static bool create(StringView preferred_gpu, Device** p_device); - }; -} diff --git a/LuaSTG/Core/Graphics/Direct3D11/SamplerState.cpp b/LuaSTG/Core/Graphics/Direct3D11/SamplerState.cpp deleted file mode 100644 index 9638c4dc..00000000 --- a/LuaSTG/Core/Graphics/Direct3D11/SamplerState.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include "Core/Graphics/Direct3D11/SamplerState.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "Core/i18n.hpp" - -// SamplerState -namespace core::Graphics::Direct3D11 { - void SamplerState::onDeviceCreate() { - if (m_initialized) { - createResource(); - } - } - void SamplerState::onDeviceDestroy() { - m_sampler.Reset(); - } - - SamplerState::SamplerState() = default; - SamplerState::~SamplerState() { - if (m_initialized && m_device) { - m_device->removeEventListener(this); - } - } - - bool SamplerState::initialize(Device* const device, core::Graphics::SamplerState const& info) { - assert(device); - m_device = device; - m_info = info; - if (!createResource()) { - return false; - } - m_initialized = true; - m_device->addEventListener(this); - return true; - } - bool SamplerState::createResource() { - HRESULT hr = S_OK; - - D3D11_SAMPLER_DESC desc = {}; - - switch (m_info.filer) { - default: assert(false); return false; - case Filter::Point: desc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; break; - case Filter::PointMinLinear: desc.Filter = D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; break; - case Filter::PointMagLinear: desc.Filter = D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; break; - case Filter::PointMipLinear: desc.Filter = D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR; break; - case Filter::LinearMinPoint: desc.Filter = D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; break; - case Filter::LinearMagPoint: desc.Filter = D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; break; - case Filter::LinearMipPoint: desc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; break; - case Filter::Linear: desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; break; - case Filter::Anisotropic: desc.Filter = D3D11_FILTER_ANISOTROPIC; break; - } - - auto mapAddressMode_ = [](TextureAddressMode mode) -> D3D11_TEXTURE_ADDRESS_MODE { - switch (mode) { - default: return (D3D11_TEXTURE_ADDRESS_MODE)0; - case TextureAddressMode::Wrap: return D3D11_TEXTURE_ADDRESS_WRAP; - case TextureAddressMode::Mirror: return D3D11_TEXTURE_ADDRESS_MIRROR; - case TextureAddressMode::Clamp: return D3D11_TEXTURE_ADDRESS_CLAMP; - case TextureAddressMode::Border: return D3D11_TEXTURE_ADDRESS_BORDER; - case TextureAddressMode::MirrorOnce: return D3D11_TEXTURE_ADDRESS_MIRROR_ONCE; - } - }; - - #define mapAddressMode(_X, _Y) \ - desc._Y = mapAddressMode_(m_info._X);\ - if (desc._Y == (D3D11_TEXTURE_ADDRESS_MODE)0) { assert(false); return false; } - - mapAddressMode(address_u, AddressU); - mapAddressMode(address_v, AddressV); - mapAddressMode(address_w, AddressW); - - #undef mapAddressMode - - desc.MipLODBias = m_info.mip_lod_bias; - - desc.MaxAnisotropy = m_info.max_anisotropy; - - desc.ComparisonFunc = D3D11_COMPARISON_NEVER; - - desc.MinLOD = m_info.min_lod; - desc.MaxLOD = m_info.max_lod; - - #define makeColor(r, g, b, a) \ - desc.BorderColor[0] = r;\ - desc.BorderColor[1] = g;\ - desc.BorderColor[2] = b;\ - desc.BorderColor[3] = a; - - switch (m_info.border_color) { - default: assert(false); return false; - case BorderColor::Black: - makeColor(0.0f, 0.0f, 0.0f, 0.0f); - break; - case BorderColor::OpaqueBlack: - makeColor(0.0f, 0.0f, 0.0f, 1.0f); - break; - case BorderColor::TransparentWhite: - makeColor(1.0f, 1.0f, 1.0f, 0.0f); - break; - case BorderColor::White: - makeColor(1.0f, 1.0f, 1.0f, 1.0f); - break; - } - - #undef makeColor - - hr = gHR = m_device->GetD3D11Device()->CreateSamplerState(&desc, &m_sampler); - if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateSamplerState"); - return false; - } - M_D3D_SET_DEBUG_NAME(m_sampler.Get(), "SamplerState_D3D11::d3d11_sampler"); - - return true; - } -} -namespace core::Graphics::Direct3D11 { - bool Device::createSamplerState(core::Graphics::SamplerState const& info, ISamplerState** pp_sampler) { - *pp_sampler = nullptr; - SmartReference buffer; - buffer.attach(new SamplerState); - if (!buffer->initialize(this, info)) { - return false; - } - *pp_sampler = buffer.detach(); - return true; - } -} \ No newline at end of file diff --git a/LuaSTG/Core/Graphics/Direct3D11/SamplerState.hpp b/LuaSTG/Core/Graphics/Direct3D11/SamplerState.hpp deleted file mode 100644 index a17a57a0..00000000 --- a/LuaSTG/Core/Graphics/Direct3D11/SamplerState.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -#include "core/SmartReference.hpp" -#include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Device.hpp" - -// SamplerState -namespace core::Graphics::Direct3D11 { - class Device; - - class SamplerState final - : public implement::ReferenceCounted - , public IDeviceEventListener { - - public: - // IDeviceEventListener - - void onDeviceCreate() override; - void onDeviceDestroy() override; - - // ISamplerState - - // SamplerState - - SamplerState(); - SamplerState(SamplerState const&) = delete; - SamplerState(SamplerState&&) = delete; - SamplerState& operator=(SamplerState const&) = delete; - SamplerState& operator=(SamplerState&&) = delete; - ~SamplerState(); - - [[nodiscard]] ID3D11SamplerState* GetState() const noexcept { return m_sampler.Get(); } - - bool initialize(Device* device, core::Graphics::SamplerState const& info); - bool createResource(); - - private: - SmartReference m_device; - Microsoft::WRL::ComPtr m_sampler; - core::Graphics::SamplerState m_info{}; - bool m_initialized{ false }; - }; -} \ No newline at end of file diff --git a/LuaSTG/Core/Graphics/Model_D3D11.hpp b/LuaSTG/Core/Graphics/Model_D3D11.hpp deleted file mode 100644 index 14a5e237..00000000 --- a/LuaSTG/Core/Graphics/Model_D3D11.hpp +++ /dev/null @@ -1,190 +0,0 @@ -#pragma once -#include "core/SmartReference.hpp" -#include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Renderer.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "tiny_gltf.h" - -#define IDX(x) (size_t)static_cast(x) - -namespace core::Graphics -{ - class ModelSharedComponent_D3D11 - : public implement::ReferenceCounted - , public IDeviceEventListener - { - friend class Model_D3D11; - private: - SmartReference m_device; - - Microsoft::WRL::ComPtr default_image; - Microsoft::WRL::ComPtr default_sampler; - - Microsoft::WRL::ComPtr input_layout; - Microsoft::WRL::ComPtr input_layout_vc; - Microsoft::WRL::ComPtr shader_vertex; - Microsoft::WRL::ComPtr shader_vertex_vc; - Microsoft::WRL::ComPtr shader_pixel[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_alpha[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_inv_alpha[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_nt[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_alpha_nt[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_inv_alpha_nt[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_vc[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_alpha_vc[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_inv_alpha_vc[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_nt_vc[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_alpha_nt_vc[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_inv_alpha_nt_vc[IDX(IRenderer::FogState::MAX_COUNT)]; - - Microsoft::WRL::ComPtr shader_pixel_sd[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_sd_nt[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_sd_vc[IDX(IRenderer::FogState::MAX_COUNT)]; - Microsoft::WRL::ComPtr shader_pixel_sd_nt_vc[IDX(IRenderer::FogState::MAX_COUNT)]; - - Microsoft::WRL::ComPtr state_rs_cull_none; - Microsoft::WRL::ComPtr state_rs_cull_back; - Microsoft::WRL::ComPtr state_ds_disable; - Microsoft::WRL::ComPtr state_ds; - Microsoft::WRL::ComPtr state_ds_no_write; - Microsoft::WRL::ComPtr state_ds_dl; - Microsoft::WRL::ComPtr state_blend; - Microsoft::WRL::ComPtr state_blend_alpha; - - Microsoft::WRL::ComPtr cbo_mvp; - Microsoft::WRL::ComPtr cbo_mlw; - Microsoft::WRL::ComPtr cbo_caminfo; - Microsoft::WRL::ComPtr cbo_alpha; - Microsoft::WRL::ComPtr cbo_light; - - private: - bool createImage(); - bool createSampler(); - bool createShader(); - bool createConstantBuffer(); - bool createState(); - - bool createResources(); - void onDeviceCreate(); - void onDeviceDestroy(); - - public: - ModelSharedComponent_D3D11(Direct3D11::Device* p_device); - ~ModelSharedComponent_D3D11(); - }; - - class Model_D3D11 - : public implement::ReferenceCounted - , public IDeviceEventListener - { - private: - SmartReference m_device; - SmartReference shared_; - - DirectX::XMMATRIX t_scale_; - DirectX::XMMATRIX t_trans_; - DirectX::XMMATRIX t_mbrot_; - - std::string gltf_path; - - struct ModelBlock - { - Microsoft::WRL::ComPtr vertex_buffer; - Microsoft::WRL::ComPtr uv_buffer; - Microsoft::WRL::ComPtr normal_buffer; - Microsoft::WRL::ComPtr color_buffer; - Microsoft::WRL::ComPtr index_buffer; - Microsoft::WRL::ComPtr sampler; - Microsoft::WRL::ComPtr image; - DirectX::XMFLOAT4X4 local_matrix; - DirectX::XMFLOAT4X4 local_matrix_normal; // notice: pair with local_matrix - DirectX::XMFLOAT4 base_color; - BOOL double_side = FALSE; - BOOL alpha_blend = FALSE; - BOOL alpha_mask = FALSE; - FLOAT alpha = 0.5f; - UINT draw_count = 0; - DXGI_FORMAT index_format = DXGI_FORMAT_R16_UINT; - D3D11_PRIMITIVE_TOPOLOGY primitive_topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST; - ModelBlock() - { - DirectX::XMStoreFloat4x4(&local_matrix, DirectX::XMMatrixIdentity()); - DirectX::XMStoreFloat4x4(&local_matrix_normal, DirectX::XMMatrixIdentity()); - base_color = DirectX::XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); - } - }; - struct Sunshine - { - DirectX::XMFLOAT4 ambient; - DirectX::XMFLOAT4 pos; - DirectX::XMFLOAT4 dir; - DirectX::XMFLOAT4 color; - - void setDir(float dir_deg, float upd_deg) - { - DirectX::XMFLOAT3 slfrom(1.0f, 0.0f, 0.0f); - auto rotate_vec2 = [](float& x, float& y, float r) - { - float sin_v = std::sinf(r); - float cos_v = std::cosf(r); - float xx = x * cos_v - y * sin_v; - float yy = x * sin_v + y * cos_v; - x = xx; - y = yy; - }; - // up and down - rotate_vec2(slfrom.x, slfrom.y, DirectX::XMConvertToRadians(upd_deg)); - // direction - rotate_vec2(slfrom.x, slfrom.z, DirectX::XMConvertToRadians(dir_deg)); - // inverse - dir.x = -slfrom.x; - dir.y = -slfrom.y; - dir.z = -slfrom.z; - dir.w = 0.0f; - } - - Sunshine() - { - ambient = DirectX::XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); // full ambient light - pos = DirectX::XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); - dir = DirectX::XMFLOAT4(0.0f, -1.0f, 0.0f, 0.0f); - color = DirectX::XMFLOAT4(1.0f, 1.0f, 1.0f, 0.0f); // no directional light - } - }; - - std::vector> image; - std::vector> sampler; - - std::vector model_block; - - Sunshine sunshine; - - std::vector mTRS_stack; - - bool processNode(tinygltf::Model& model, tinygltf::Node& node); - bool createImage(tinygltf::Model& model); - bool createSampler(tinygltf::Model& model); - bool createModelBlock(tinygltf::Model& model); - - bool createResources(); - void onDeviceCreate(); - void onDeviceDestroy(); - - public: - - void setAmbient(Vector3F const& color, float brightness); - void setDirectionalLight(Vector3F const& direction, Vector3F const& color, float brightness); - void setScaling(Vector3F const& scale); - void setPosition(Vector3F const& pos); - void setRotationRollPitchYaw(float roll, float pitch, float yaw); - void setRotationQuaternion(Vector4F const& quat); - - void draw(IRenderer::FogState fog); - - public: - Model_D3D11(Direct3D11::Device* p_device, ModelSharedComponent_D3D11* p_model_shared, StringView path); - ~Model_D3D11(); - }; -} - -#undef IDX diff --git a/LuaSTG/Core/Graphics/Window_Win32.cpp b/LuaSTG/Core/Graphics/Window_Win32.cpp deleted file mode 100644 index f2beec90..00000000 --- a/LuaSTG/Core/Graphics/Window_Win32.cpp +++ /dev/null @@ -1,1420 +0,0 @@ -#include "Core/Graphics/Window_Win32.hpp" -#include "Core/ApplicationModel_Win32.hpp" -#include "Core/i18n.hpp" -#include "core/Configuration.hpp" -#include "win32/win32.hpp" -#include "win32/abi.hpp" -#include "Platform/WindowsVersion.hpp" -#include "Platform/WindowTheme.hpp" -#include "Platform/RuntimeLoader/DesktopWindowManager.hpp" -#include "utf8.hpp" -#include "simdutf.h" -#include -#include - -static constexpr int LUASTG_WM_UPDAE_TITLE = WM_APP + __LINE__; -static constexpr int LUASTG_WM_RECREATE = WM_APP + __LINE__; -static constexpr int LUASTG_WM_SET_WINDOW_MODE = WM_APP + __LINE__; -static constexpr int LUASTG_WM_SET_FULLSCREEN_MODE = WM_APP + __LINE__; - -namespace { - Platform::RuntimeLoader::DesktopWindowManager dwmapi_loader; - - template - T getMonitorInfo(HMONITOR const monitor) { - static_assert(std::is_same_v || std::is_same_v); - assert(monitor); - T info{}; - info.cbSize = sizeof(info); - [[maybe_unused]] auto const result = GetMonitorInfoW(monitor, &info); - assert(result); - return info; - } - - void clearWindowBackground(HWND const window) { - PAINTSTRUCT ps{}; - if (auto const dc = BeginPaint(window, &ps); dc != nullptr) { - RECT rc{}; - GetClientRect(window, &rc); - auto const brush = static_cast(GetStockObject(BLACK_BRUSH)); - FillRect(dc, &rc, brush); - EndPaint(window, &ps); - } - } - - void setAllowWindowCorner(HWND const window, bool const allow) { - DWM_WINDOW_CORNER_PREFERENCE const attr = allow ? DWMWCP_DEFAULT : DWMWCP_DONOTROUND; - HRESULT const hr = gHR = dwmapi_loader.SetWindowAttribute(window, DWMWA_WINDOW_CORNER_PREFERENCE, &attr, sizeof(attr)); - if (FAILED(hr)) { - std::string msg; - msg.reserve(64); - msg.append("DwmSetWindowAttribute -> "); - msg.append(allow ? "DWMWCP_DEFAULT" : "DWMWCP_DONOTROUND"); - i18n_core_system_call_report_error(msg); - } - } -} - -namespace core::Graphics -{ - void* Display_Win32::getNativeHandle() { - return win32_monitor; - } - void Display_Win32::getFriendlyName(IImmutableString** const output) { - auto const info = getMonitorInfo(win32_monitor); - - UINT path_count{}; - UINT mode_count{}; - if (ERROR_SUCCESS == GetDisplayConfigBufferSizes(QDC_DATABASE_CURRENT, &path_count, &mode_count)) { - std::vector path_list(path_count); - std::vector mode_list(mode_count); - DISPLAYCONFIG_TOPOLOGY_ID topology_id{}; - if (ERROR_SUCCESS == QueryDisplayConfig(QDC_DATABASE_CURRENT, &path_count, path_list.data(), &mode_count, mode_list.data(), &topology_id)) { - for (auto const& path : path_list) { - DISPLAYCONFIG_SOURCE_DEVICE_NAME source_device_name{}; - source_device_name.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME; - source_device_name.header.size = sizeof(source_device_name); - source_device_name.header.adapterId = path.sourceInfo.adapterId; - source_device_name.header.id = path.sourceInfo.id; - if (ERROR_SUCCESS == DisplayConfigGetDeviceInfo(&source_device_name.header)) { - if (std::wstring_view(info.szDevice) == std::wstring_view(source_device_name.viewGdiDeviceName)) { - DISPLAYCONFIG_TARGET_DEVICE_NAME target_device_name{}; - target_device_name.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME; - target_device_name.header.size = sizeof(target_device_name); - target_device_name.header.adapterId = path.targetInfo.adapterId; - target_device_name.header.id = path.targetInfo.id; - if (ERROR_SUCCESS == DisplayConfigGetDeviceInfo(&target_device_name.header)) { - std::string buffer; - if (target_device_name.flags.edidIdsValid) { - auto const manufacture_id = ((target_device_name.edidManufactureId & 0xff) << 8) | ((target_device_name.edidManufactureId & 0xff00) >> 8); - auto const letter1 = ((manufacture_id & 0x7c00) >> 10) - 1; - auto const letter2 = ((manufacture_id & 0x3e0) >> 5) - 1; - auto const letter3 = (manufacture_id & 0x1f) - 1; - buffer.push_back('A' + static_cast(letter1)); - buffer.push_back('A' + static_cast(letter2)); - buffer.push_back('A' + static_cast(letter3)); - } - if (!std::wstring_view(target_device_name.monitorFriendlyDeviceName).empty()) { - if (!buffer.empty()) { - buffer.push_back(' '); - } - buffer.append(utf8::to_string(target_device_name.monitorFriendlyDeviceName)); - } - else if (target_device_name.flags.edidIdsValid) { - buffer.append(std::format("{:04X}", target_device_name.edidProductCodeId)); - } - IImmutableString::create(buffer, output); - return; - } - } - } - } - } - } - - IImmutableString::create(utf8::to_string(info.szDevice), output); - } - Vector2U Display_Win32::getSize() { - auto const info = getMonitorInfo(win32_monitor); - auto const& rc = info.rcMonitor; - return Vector2U(static_cast(rc.right - rc.left), static_cast(rc.bottom - rc.top)); - } - Vector2I Display_Win32::getPosition() { - auto const info = getMonitorInfo(win32_monitor); - auto const& rc = info.rcMonitor; - return Vector2I(rc.left, rc.top); - } - RectI Display_Win32::getRect() { - auto const info = getMonitorInfo(win32_monitor); - auto const& rc = info.rcMonitor; - return RectI(rc.left, rc.top, rc.right, rc.bottom); - } - Vector2U Display_Win32::getWorkAreaSize() { - auto const info = getMonitorInfo(win32_monitor); - auto const& rc = info.rcWork; - return Vector2U(static_cast(rc.right - rc.left), static_cast(rc.bottom - rc.top)); - } - Vector2I Display_Win32::getWorkAreaPosition() { - auto const info = getMonitorInfo(win32_monitor); - auto const& rc = info.rcWork; - return Vector2I(rc.left, rc.top); - } - RectI Display_Win32::getWorkAreaRect() { - auto const info = getMonitorInfo(win32_monitor); - auto const& rc = info.rcWork; - return RectI(rc.left, rc.top, rc.right, rc.bottom); - } - bool Display_Win32::isPrimary() { - auto const info = getMonitorInfo(win32_monitor); - return !!(info.dwFlags & MONITORINFOF_PRIMARY); - } - float Display_Win32::getDisplayScale() { - return win32::getDpiScalingForMonitor(win32_monitor); - } - - Display_Win32::Display_Win32(HMONITOR const monitor) : win32_monitor(monitor) { - } - Display_Win32::~Display_Win32() = default; - - bool IDisplay::getAll(size_t* const count, IDisplay** const output) { - assert(count != nullptr); - assert(*count == 0 || (*count > 0 && output != nullptr)); - struct Context { - std::vector list; - static BOOL CALLBACK callback(HMONITOR const monitor, HDC, LPRECT, LPARAM const data) { - auto const context = reinterpret_cast(data); - context->list.emplace_back(monitor); - return TRUE; - } - }; - Context context{}; - if (!EnumDisplayMonitors(nullptr, nullptr, &Context::callback, reinterpret_cast(&context))) { - return false; - } - *count = context.list.size(); - if (output) { - for (size_t i = 0; i < context.list.size(); i += 1) { - output[i] = new Display_Win32(context.list.at(i)); - } - } - return true; - } - bool IDisplay::getPrimary(IDisplay** const output) { - assert(output != nullptr); - struct Context { - HMONITOR primary{}; - static BOOL CALLBACK callback(HMONITOR const monitor, HDC, LPRECT, LPARAM const data) { - auto const context = reinterpret_cast(data); - if (auto const info = getMonitorInfo(monitor); info.dwFlags & MONITORINFOF_PRIMARY) { - context->primary = monitor; - } - return TRUE; - }; - }; - Context context{}; - if (!EnumDisplayMonitors(nullptr, nullptr, &Context::callback, reinterpret_cast(&context))) { - return false; - } - *output = new Display_Win32(context.primary); - return true; - } - bool IDisplay::getNearestFromWindow(IWindow* const window, IDisplay** const output) { - assert(window != nullptr); - assert(output != nullptr); - auto const monitor = MonitorFromWindow(static_cast(window->getNativeHandle()), MONITOR_DEFAULTTOPRIMARY); - if (!monitor) { - return false; - } - *output = new Display_Win32(monitor); - return true; - } -} - -namespace core::Graphics -{ - void Window_Win32::textInput_updateBuffer() { - auto const& s32 = m_text_input_buffer; - auto& s8 = m_text_input_buffer_u8; - s8.resize(simdutf::utf8_length_from_utf32(s32.data(), s32.size())); - simdutf::convert_valid_utf32_to_utf8(s32.data(), s32.size(), reinterpret_cast(s8.data())); - } - void Window_Win32::textInput_addChar32(char32_t const code) { - m_text_input_buffer.insert(m_text_input_buffer.begin() + m_text_input_cursor, code); - m_text_input_cursor += 1; - textInput_updateBuffer(); - } - void Window_Win32::textInput_handleChar32(char32_t const code) { - if (code == U'\t' || code == U'\n' /* || code == U'\r' */ || (code >= 0x20 && code <= 0x7e) || code >= 0x80) { - textInput_addChar32(code); - } - } - void Window_Win32::textInput_handleChar16(char16_t const code) { - if (IS_HIGH_SURROGATE(code)) { - m_text_input_last_high_surrogate = code; - } - else if (IS_LOW_SURROGATE(code)) { - if (IS_SURROGATE_PAIR(m_text_input_last_high_surrogate, code)) { - char16_t const str[3]{ m_text_input_last_high_surrogate, code ,0 }; - char32_t buf[2]{}; - simdutf::convert_valid_utf16le_to_utf32(str, 2, buf); - textInput_handleChar32(buf[0]); - } - m_text_input_last_high_surrogate = {}; - } - else { - textInput_handleChar32(static_cast(code)); - } - } - - bool Window_Win32::textInput_isEnabled() { - return m_text_input_enabled; - } - void Window_Win32::textInput_setEnabled(bool const enabled) { - m_text_input_enabled = enabled; - } - StringView Window_Win32::textInput_getBuffer() { - return { reinterpret_cast(m_text_input_buffer_u8.data()), m_text_input_buffer_u8.size() }; - } - void Window_Win32::textInput_clearBuffer() { - m_text_input_buffer.clear(); - m_text_input_buffer_u8.clear(); - m_text_input_cursor = 0; - } - uint32_t Window_Win32::textInput_getCursorPosition() { - return m_text_input_cursor; - } - void Window_Win32::textInput_setCursorPosition(uint32_t const code_point_index) { - m_text_input_cursor = std::min(code_point_index, static_cast(m_text_input_buffer.size())); - } - void Window_Win32::textInput_addCursorPosition(int32_t const offset_by_code_point) { - if (offset_by_code_point == 0) { - return; - } - if (offset_by_code_point > 0) { - if ((static_cast(m_text_input_cursor) + offset_by_code_point) <= m_text_input_buffer.size()) { - m_text_input_cursor += offset_by_code_point; - } - else { - m_text_input_cursor = static_cast(m_text_input_buffer.size()); - } - } - else { - if ((static_cast(m_text_input_cursor) + offset_by_code_point) >= 0) { - m_text_input_cursor += offset_by_code_point; - } - else { - m_text_input_cursor = 0; - } - } - } - void Window_Win32::textInput_removeBufferRange(uint32_t const code_point_index, uint32_t const code_point_count) { - auto& s32 = m_text_input_buffer; - if (code_point_index >= s32.size()) { - return; - } - auto const right = static_cast(s32.size()) - code_point_index; - auto const count = std::min(code_point_count, right); - s32.erase(code_point_index, count); - m_text_input_cursor = std::min(m_text_input_cursor, static_cast(s32.size())); - textInput_updateBuffer(); - } - void Window_Win32::textInput_insertBufferRange(uint32_t const code_point_index, StringView const str) { - if (!simdutf::validate_utf8(str.data(), str.size())) { - return; - } - std::u32string buf; - buf.resize(simdutf::utf32_length_from_utf8(str.data(), str.size())); - simdutf::convert_valid_utf8_to_utf32(str.data(), str.size(), buf.data()); - if (code_point_index < m_text_input_buffer.size()) { - m_text_input_buffer.insert(code_point_index, buf); - } - else { - m_text_input_buffer.append(buf); - } - m_text_input_cursor += static_cast(str.size()); - textInput_updateBuffer(); - } - void Window_Win32::textInput_backspace(uint32_t const code_point_count) { - auto const count = std::min(m_text_input_cursor, code_point_count); - m_text_input_cursor -= count; - m_text_input_buffer.erase(m_text_input_cursor, count); - textInput_updateBuffer(); - } - - void Window_Win32::setInputMethodPosition(Vector2I position) { - if (!win32_window) { - return; - } - if (HIMC himc = ImmGetContext(win32_window); win32_window) { - COMPOSITIONFORM composition_form = {}; - composition_form.ptCurrentPos.x = position.x; - composition_form.ptCurrentPos.y = position.y; - composition_form.dwStyle = CFS_FORCE_POSITION; - ImmSetCompositionWindow(himc, &composition_form); - CANDIDATEFORM candidate_form = {}; - candidate_form.dwStyle = CFS_CANDIDATEPOS; - candidate_form.ptCurrentPos.x = position.x; - candidate_form.ptCurrentPos.y = position.y; - ImmSetCandidateWindow(himc, &candidate_form); - ImmReleaseContext(win32_window, himc); - } - } -} - -namespace core::Graphics -{ - static DWORD mapWindowStyle(WindowFrameStyle style, bool fullscreen) { - if (fullscreen) { - return WS_VISIBLE | WS_POPUP; - } - switch (style) - { - default: - assert(false); return WS_VISIBLE | WS_POPUP; - case WindowFrameStyle::None: - return WS_VISIBLE | WS_POPUP; - case WindowFrameStyle::Fixed: - return WS_VISIBLE | WS_OVERLAPPEDWINDOW ^ (WS_THICKFRAME | WS_MAXIMIZEBOX); - case WindowFrameStyle::Normal: - return WS_VISIBLE | WS_OVERLAPPEDWINDOW; - } - } - -#define APPMODEL ((ApplicationModel_Win32*)m_framework) - - LRESULT CALLBACK Window_Win32::win32_window_callback(HWND const window, UINT const message, WPARAM const arg1, LPARAM const arg2) { - if (auto const self = reinterpret_cast(GetWindowLongPtrW(window, GWLP_USERDATA))) { - return self->onMessage(window, message, arg1, arg2); - } - if (message == WM_NCCREATE) { - win32::enableNonClientDpiScaling(window); - if (auto const params = reinterpret_cast(arg2); params->lpCreateParams) { - auto const self = static_cast(params->lpCreateParams); - - SetLastError(0); - SetWindowLongPtrW(window, GWLP_USERDATA, reinterpret_cast(self)); - if (auto const code = GetLastError(); code != 0) { - spdlog::error("[luastg] (LastError = {}) SetWindowLongPtrW -> #GWLP_USERDATA failed", code); - return FALSE; - } - - Platform::WindowTheme::UpdateColorMode(window, TRUE); - setAllowWindowCorner(window, self->m_allow_windows_11_window_corner); - } - } - return DefWindowProcW(window, message, arg1, arg2); - } - - LRESULT Window_Win32::onMessage(HWND window, UINT message, WPARAM arg1, LPARAM arg2) - { - if (enable_track_window_focus && win32_window_want_track_focus) - { - HWND focus_window = GetForegroundWindow(); - if (focus_window && focus_window != window) - { - win32_window_want_track_focus = FALSE; - std::array buffer1{}; - std::array buffer2{}; - LRESULT const length1 = SendMessageW(focus_window, WM_GETTEXT, 256, (LPARAM)buffer1.data()); - int const length2 = GetClassNameW(focus_window, buffer2.data(), 256); - spdlog::info("[core] 窗口焦点已改变,新的焦点窗口为:[{}] ({}) {}", (void*)focus_window, - utf8::to_string(std::wstring_view(buffer2.data(), (size_t)length2)), - utf8::to_string(std::wstring_view(buffer1.data(), (size_t)length1)) - ); - } - } - - // 文本输入 - if (m_text_input_enabled) { - switch (message) { - case WM_CHAR: - if (arg1 <= 0xFFFF) { - textInput_handleChar16(static_cast(arg1)); - } - break; - } - } - // 窗口挪动器 - if (auto const result = m_sizemove.handleSizeMove(window, message, arg1, arg2); result.bReturn) { - return result.lResult; - } - // 标题栏控制器 - if (auto const result = m_title_bar_controller.handleWindowMessage(window, message, arg1, arg2); result.returnResult) { - return result.result; - } - // 特殊 - for (auto& v : m_eventobj) - { - if (v) - { - auto r = v->onNativeWindowMessage(window, message, arg1, arg2); - if (r.should_return) - { - return r.result; - } - } - } - // 其他消息 - switch (message) - { - case WM_ACTIVATEAPP: - if (arg1 /* == TRUE */) - { - win32_window_want_track_focus = FALSE; - Platform::WindowTheme::UpdateColorMode(window, TRUE); - dispatchEvent(EventType::WindowActive); - } - else - { - win32_window_want_track_focus = TRUE; // 要开始抓内鬼了 - Platform::WindowTheme::UpdateColorMode(window, FALSE); - dispatchEvent(EventType::WindowInactive); - } - m_alt_down = FALSE; // 无论如何,清除该按键状态 - break; - case WM_SIZE: - if (!m_ignore_size_message) - { - EventData d = {}; - d.window_size = Vector2U(LOWORD(arg2), HIWORD(arg2)); - dispatchEvent(EventType::WindowSize, d); - } - break; - case WM_ENTERSIZEMOVE: - win32_window_is_sizemove = TRUE; - InvalidateRect(window, NULL, FALSE); // 标记窗口区域为需要重新绘制,以便产生 WM_PAINT 消息 - return 0; - case WM_EXITSIZEMOVE: - win32_window_is_sizemove = FALSE; - return 0; - case WM_ENTERMENULOOP: - win32_window_is_menu_loop = TRUE; - InvalidateRect(window, NULL, FALSE); // 标记窗口区域为需要重新绘制,以便产生 WM_PAINT 消息 - return 0; - case WM_EXITMENULOOP: - win32_window_is_menu_loop = FALSE; - return 0; - case WM_PAINT: - if (win32_window_is_sizemove || win32_window_is_menu_loop) { - APPMODEL->runFrame(); - } - else { - ValidateRect(window, nullptr); // no gdi painting - } - return 0; - case WM_SYSKEYDOWN: - case WM_KEYDOWN: - if (arg1 == VK_MENU) - { - m_alt_down = TRUE; - return 0; - } - if (m_alt_down && arg1 == VK_RETURN) - { - _toggleFullScreenMode(); - return 0; - } - break; - case WM_SYSKEYUP: - case WM_KEYUP: - if (arg1 == VK_MENU) - { - m_alt_down = FALSE; - return 0; - } - break; - case WM_GETMINMAXINFO: - { - MINMAXINFO* info = (MINMAXINFO*)arg2; - RECT rect_min = { 0, 0, 320, 240 }; - UINT const dpi = win32::getDpiForWindow(window); - if (m_title_bar_controller.adjustWindowRectExForDpi(&rect_min, win32_window_style, FALSE, win32_window_style_ex, dpi)) - { - info->ptMinTrackSize.x = rect_min.right - rect_min.left; - info->ptMinTrackSize.y = rect_min.bottom - rect_min.top; - } - } - return 0; - case WM_DPICHANGED: - if (getFrameStyle() != WindowFrameStyle::None) - { - RECT rc{}; - GetWindowRect(window, &rc); - setSize(getSize()); // 刷新一次尺寸(因为非客户区可能会变化) - SetWindowPos(window, NULL, rc.left, rc.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE); - dispatchEvent(EventType::WindowDpiChanged); - return 0; - } - dispatchEvent(EventType::WindowDpiChanged); // 仍然需要通知 - break; - case WM_SETTINGCHANGE: - case WM_THEMECHANGED: - Platform::WindowTheme::UpdateColorMode(window, TRUE); - break; - case WM_DEVICECHANGE: - if (arg1 == 0x0007 /* DBT_DEVNODES_CHANGED */) - { - dispatchEvent(EventType::DeviceChange); - } - break; - case WM_SETCURSOR: - if (LOWORD(arg2) == HTCLIENT) - { - SetCursor(win32_window_cursor); - return TRUE; - } - break; - case WM_MENUCHAR: - // 快捷键能不能死全家 - return MAKELRESULT(0, MNC_CLOSE); - case WM_SYSCOMMAND: - // 鼠标左键点击标题栏图标或者 Alt+Space 不会出现菜单 - switch (arg1 & 0xFFF0) - { - case SC_KEYMENU: - case SC_MOUSEMENU: - return 0; - } - break; - case WM_CLOSE: - dispatchEvent(EventType::WindowClose); - PostQuitMessage(EXIT_SUCCESS); - return 0; - case LUASTG_WM_UPDAE_TITLE: - SetWindowTextW(window, win32_window_text_w.data()); - return 0; - case LUASTG_WM_RECREATE: - _recreateWindow(); - return 0; - case LUASTG_WM_SET_WINDOW_MODE: - _setWindowMode(reinterpret_cast(arg1), arg2); - return 0; - case LUASTG_WM_SET_FULLSCREEN_MODE: - _setFullScreenMode(reinterpret_cast(arg2)); - return 0; - } - const auto result = DefWindowProcW(window, message, arg1, arg2); - if (!m_window_created) { - // 在 CreateWindow/CreateWindowEx 期间, - // 即使设置了窗口类的 hbrBackground 为黑色笔刷,窗口背景也会先绘制为白色,再转为黑色。 - // 只有不断追着窗口消息重绘背景,才能 **一定程度** 上避免白色背景(不保证 100% 有效)。 - // CreateWindow/CreateWindowEx 一般会产生以下窗口消息(按先后顺序): - // - WM_GETMINMAXINFO - // - WM_NCCREATE - // - WM_NCCALCSIZE - // - WM_CREATE - // - WM_SHOWWINDOW - // - WM_WINDOWPOSCHANGING - // - WM_NCPAINT - // - WM_GETICON - // - WM_ERASEBKGND - // - WM_GETICON - // - WM_ACTIVATEAPP - // - WM_NCACTIVATE - // - WM_ACTIVATE - // - WM_IME_SETCONTEXT - // - WM_IME_NOTIFY - // - WM_SETFOCUS - // - WM_WINDOWPOSCHANGED - // - WM_SIZE - // - WM_MOVE - // 经过测试,如果在以下三类消息之后重绘背景为黑色,能极大程度地减少看到白色背景的概率: - // - WM_NCPAINT - // - WM_GETICON - // - WM_ERASEBKGND - // 但仅处理以上三类消息,仍然会有一定概率出现白色背景, - // 因此,有理由猜测白色背景的绘制在窗口弹出动画期间都会持续执行(可能由桌面窗口管理器合成)。 - clearWindowBackground(window); - } - return result; - } - bool Window_Win32::createWindowClass() { - auto const instance_handle = GetModuleHandleW(nullptr); - if (instance_handle == nullptr) { - assert(false); // unlikely - return false; - } - - HICON icon{}; - if (win32_window_icon_id != 0) { - icon = LoadIcon(instance_handle, MAKEINTRESOURCE(win32_window_icon_id)); - } - - auto& cls = win32_window_class; - cls.style = CS_HREDRAW | CS_VREDRAW; - cls.lpfnWndProc = &win32_window_callback; - cls.hInstance = instance_handle; - cls.hIcon = icon; - cls.hCursor = LoadCursor(nullptr, IDC_ARROW); - cls.hbrBackground = static_cast(GetStockObject(BLACK_BRUSH)); - cls.lpszClassName = L"luastg::core::Window"; - cls.hIconSm = icon; - - win32_window_class_atom = RegisterClassExW(&cls); - - if (icon != nullptr) { - DestroyIcon(icon); - } - - if (win32_window_class_atom == 0) { - spdlog::error("[luastg] (LastError = {}) RegisterClassExW failed", GetLastError()); - return false; - } - - return true; - } - void Window_Win32::destroyWindowClass() - { - if (win32_window_class_atom != 0) - { - UnregisterClassW(win32_window_class.lpszClassName, win32_window_class.hInstance); - } - win32_window_class_atom = 0; - } - bool Window_Win32::createWindow() { - if (win32_window_class_atom == 0) { - return false; - } - - // 拿到原点位置的显示器信息 - SmartReference display; - if (!IDisplay::getPrimary(display.put())) { - return false; // 理论上 Windows 平台的主显示器都在原点 - } - auto const display_rect = display->getWorkAreaRect(); - auto const display_dpi = static_cast(display->getDisplayScale() * USER_DEFAULT_SCREEN_DPI); - - // 计算初始大小 - - RECT client{ 0, 0, static_cast(win32_window_width),static_cast(win32_window_height) }; - m_title_bar_controller.setEnable(auto_hide_title_bar); - m_title_bar_controller.adjustWindowRectExForDpi(&client, win32_window_style, FALSE, win32_window_style_ex, display_dpi); - - // 创建窗口 - - convertTitleText(); - win32_window = CreateWindowExW( - win32_window_style_ex, - win32_window_class.lpszClassName, - win32_window_text_w.data(), - win32_window_style, - (display_rect.a.x + display_rect.b.x) / 2 - (client.right - client.left) / 2, // x (left) - (display_rect.a.y + display_rect.b.y) / 2 - (client.bottom - client.top) / 2, // y (top) - client.right - client.left, - client.bottom - client.top, - nullptr, // parent - nullptr, // menu - win32_window_class.hInstance, - this - ); - if (win32_window == nullptr) { - spdlog::error("[luastg] (LastError = {}) CreateWindowExW failed", GetLastError()); - return false; - } - m_window_created = true; - - // 配置输入法 - - if (!win32_window_ime_enable) { - ImmAssociateContext(win32_window, nullptr); - } - - // 配置窗口挪动器 - - m_sizemove.setWindow(win32_window); - - return true; - } - void Window_Win32::destroyWindow() { - m_sizemove.setWindow(nullptr); - m_window_created = false; - if (win32_window) { - DestroyWindow(win32_window); - win32_window = nullptr; - } - } - bool Window_Win32::_recreateWindow() { - BOOL result{ FALSE }; - WINDOWPLACEMENT last_window_placement{}; - last_window_placement.length = sizeof(last_window_placement); - - assert(win32_window); - if (result = GetWindowPlacement(win32_window, &last_window_placement); !result) { - assert(result); - return false; - } - - destroyWindow(); - if (!createWindow()) { - return false; - } - - assert(win32_window); - if (result = SetWindowPlacement(win32_window, &last_window_placement); !result) { - assert(result); - return false; - } - - return true; - } - bool Window_Win32::recreateWindow() - { - dispatchEvent(EventType::WindowDestroy); - SendMessageW(win32_window, LUASTG_WM_RECREATE, 0, 0); - //if (!_recreateWindow()) { - // return false; - //} - dispatchEvent(EventType::WindowCreate); - return true; - } - void Window_Win32::_toggleFullScreenMode() - { - if (m_fullscreen_mode) { - SetWindowedModeParameters parameters{}; - parameters.size = Vector2U(win32_window_width, win32_window_height); - parameters.style = m_framestyle; - _setWindowMode(¶meters, true); - } - else { - _setFullScreenMode(nullptr); - } - } - void Window_Win32::_setWindowMode(SetWindowedModeParameters* parameters, bool ignore_size) - { - assert(parameters); - - m_title_bar_controller.setEnable(auto_hide_title_bar); - - HMONITOR win32_monitor{}; - if (parameters->display) { - win32_monitor = static_cast(parameters->display->getNativeHandle()); - } - else { - win32_monitor = MonitorFromWindow(win32_window, MONITOR_DEFAULTTONEAREST); - } - assert(win32_monitor); - MONITORINFO monitor_info = {}; - monitor_info.cbSize = sizeof(monitor_info); - BOOL const get_monitor_info_result = GetMonitorInfoW(win32_monitor, &monitor_info); - assert(get_monitor_info_result); (void)get_monitor_info_result; - assert(monitor_info.rcWork.right > monitor_info.rcWork.left); - assert(monitor_info.rcWork.bottom > monitor_info.rcWork.top); - - bool const new_fullsceen_mode = false; - m_framestyle = parameters->style; - DWORD new_win32_window_style = mapWindowStyle(m_framestyle, new_fullsceen_mode); - - RECT rect = { 0, 0, (int32_t)parameters->size.x, (int32_t)parameters->size.y }; - m_title_bar_controller.adjustWindowRectExForDpi( - &rect, new_win32_window_style, FALSE, 0, - win32::getDpiForWindow(win32_window)); - - //m_ignore_size_message = TRUE; - SetLastError(0); - SetWindowLongPtrW(win32_window, GWL_STYLE, new_win32_window_style); - DWORD const set_style_result = GetLastError(); - assert(set_style_result == 0); (void)set_style_result; - //SetLastError(0); - //SetWindowLongPtrW(win32_window, GWL_EXSTYLE, 0); - //DWORD const set_style_ex_result = GetLastError(); - //assert(set_style_ex_result == 0); (void)set_style_ex_result; - //m_ignore_size_message = FALSE; - - bool want_restore_placement = false; - - if (m_fullscreen_mode && ignore_size) - { - want_restore_placement = true; - } - else - { - BOOL const set_window_pos_result = SetWindowPos( - win32_window, - HWND_TOP, - (monitor_info.rcWork.right + monitor_info.rcWork.left) / 2 - (rect.right - rect.left) / 2, - (monitor_info.rcWork.bottom + monitor_info.rcWork.top) / 2 - (rect.bottom - rect.top) / 2, - rect.right - rect.left, - rect.bottom - rect.top, - SWP_FRAMECHANGED | SWP_SHOWWINDOW); - assert(set_window_pos_result); (void)set_window_pos_result; - } - - RECT client_rect = {}; - BOOL get_client_rect_result = GetClientRect(win32_window, &client_rect); - assert(get_client_rect_result); (void)get_client_rect_result; - - m_fullscreen_mode = new_fullsceen_mode; - win32_window_style = new_win32_window_style; - win32_window_width = UINT(client_rect.right - client_rect.left); - win32_window_height = UINT(client_rect.bottom - client_rect.top); - - EventData event_data{}; - event_data.window_fullscreen_state = false; - dispatchEvent(EventType::WindowFullscreenStateChange, event_data); - - if (want_restore_placement) - { - BOOL const set_placement_result = SetWindowPlacement(win32_window, &m_last_window_placement); - assert(set_placement_result); (void)set_placement_result; - } - } - void Window_Win32::_setFullScreenMode(IDisplay* display) - { - m_title_bar_controller.setEnable(false); - - if (!m_fullscreen_mode) - { - BOOL const get_placement_result = GetWindowPlacement(win32_window, &m_last_window_placement); - assert(get_placement_result); (void)get_placement_result; - } - - HMONITOR win32_monitor{}; - if (display) { - win32_monitor = static_cast(display->getNativeHandle()); - } - else { - win32_monitor = MonitorFromWindow(win32_window, MONITOR_DEFAULTTONEAREST); - } - assert(win32_monitor); - MONITORINFO monitor_info = {}; - monitor_info.cbSize = sizeof(monitor_info); - BOOL const get_monitor_info_result = GetMonitorInfoW(win32_monitor, &monitor_info); - assert(get_monitor_info_result); (void)get_monitor_info_result; - assert(monitor_info.rcMonitor.right > monitor_info.rcMonitor.left); - assert(monitor_info.rcMonitor.bottom > monitor_info.rcMonitor.top); - - bool const new_fullsceen_mode = true; - DWORD new_win32_window_style = mapWindowStyle(m_framestyle, new_fullsceen_mode); - - //m_ignore_size_message = TRUE; - SetLastError(0); - SetWindowLongPtrW(win32_window, GWL_STYLE, new_win32_window_style); - DWORD const set_style_result = GetLastError(); - assert(set_style_result == 0); (void)set_style_result; - //SetLastError(0); - //SetWindowLongPtrW(win32_window, GWL_EXSTYLE, 0); - //DWORD const set_style_ex_result = GetLastError(); - //assert(set_style_ex_result == 0); (void)set_style_ex_result; - //m_ignore_size_message = FALSE; - - BOOL const set_window_pos_result = SetWindowPos( - win32_window, - HWND_TOP, - monitor_info.rcMonitor.left, - monitor_info.rcMonitor.top, - monitor_info.rcMonitor.right - monitor_info.rcMonitor.left, - monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top, - SWP_FRAMECHANGED | SWP_SHOWWINDOW); - assert(set_window_pos_result); (void)set_window_pos_result; - - m_fullscreen_mode = new_fullsceen_mode; - win32_window_style = new_win32_window_style; - win32_window_width = UINT(monitor_info.rcMonitor.right - monitor_info.rcMonitor.left); - win32_window_height = UINT(monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top); - - EventData event_data{}; - event_data.window_fullscreen_state = true; - dispatchEvent(EventType::WindowFullscreenStateChange, event_data); - } - - void Window_Win32::convertTitleText() - { - win32_window_text_w[0] = L'\0'; - int const size = MultiByteToWideChar(CP_UTF8, 0, win32_window_text.data(), (int)win32_window_text.size(), NULL, 0); - if (size <= 0 || size > (int)(win32_window_text_w.size() - 1)) - { - assert(false); return; - } - win32_window_text_w[size] = L'\0'; - int const result = MultiByteToWideChar(CP_UTF8, 0, win32_window_text.data(), (int)win32_window_text.size(), win32_window_text_w.data(), size); - if (result <= 0 || result != size) - { - assert(false); return; - } - win32_window_text_w[result] = L'\0'; - } - - RectI Window_Win32::getRect() - { - RECT rc = {}; - GetWindowRect(win32_window, &rc); - return RectI(rc.left, rc.top, rc.right, rc.bottom); - } - bool Window_Win32::setRect(RectI v) - { - return SetWindowPos(win32_window, NULL, - v.a.x, v.a.y, - v.b.x - v.a.x, v.b.y - v.a.y, - SWP_NOZORDER) != FALSE; - } - RectI Window_Win32::getClientRect() - { - RECT rc = {}; - GetClientRect(win32_window, &rc); - return RectI(rc.left, rc.top, rc.right, rc.bottom); - } - bool Window_Win32::setClientRect(RectI v) - { - // 更新 DPI - win32_window_dpi = win32::getDpiForWindow(win32_window); - // 计算包括窗口框架的尺寸 - RECT rc = { v.a.x , v.a.y , v.b.x , v.b.y }; - m_title_bar_controller.adjustWindowRectExForDpi( - &rc, - win32_window_style, - FALSE, - win32_window_style_ex, - win32_window_dpi); - // 获取最近的显示器的位置 - if (HMONITOR monitor = MonitorFromWindow(win32_window, MONITOR_DEFAULTTONEAREST)) - { - MONITORINFO moninfo = { sizeof(MONITORINFO), {}, {}, 0 }; - if (GetMonitorInfoA(monitor, &moninfo)) - { - // 偏移到该显示器0点位置 - rc.left += moninfo.rcMonitor.left; - rc.right += moninfo.rcMonitor.left; - rc.top += moninfo.rcMonitor.top; - rc.bottom += moninfo.rcMonitor.top; - } - } - // 最后再应用 - return SetWindowPos(win32_window, NULL, - rc.left, - rc.top, - rc.right - rc.left, - rc.bottom - rc.top, - SWP_NOZORDER) != FALSE; - } - uint32_t Window_Win32::getDPI() - { - win32_window_dpi = win32::getDpiForWindow(win32_window); - return win32_window_dpi; - } - - void Window_Win32::dispatchEvent(EventType t, EventData d) - { - // 回调 - m_is_dispatch_event = true; - switch (t) - { - case EventType::WindowCreate: - for (auto& v : m_eventobj) - { - if (v) v->onWindowCreate(); - } - break; - case EventType::WindowDestroy: - for (auto& v : m_eventobj) - { - if (v) v->onWindowDestroy(); - } - break; - case EventType::WindowActive: - for (auto& v : m_eventobj) - { - if (v) v->onWindowActive(); - } - break; - case EventType::WindowInactive: - for (auto& v : m_eventobj) - { - if (v) v->onWindowInactive(); - } - break; - case EventType::WindowClose: - for (auto& v : m_eventobj) - { - if (v) v->onWindowClose(); - } - break; - case EventType::WindowSize: - for (auto& v : m_eventobj) - { - if (v) v->onWindowSize(d.window_size); - } - break; - case EventType::WindowFullscreenStateChange: - for (auto& v : m_eventobj) - { - if (v) v->onWindowFullscreenStateChange(d.window_fullscreen_state); - } - break; - case EventType::WindowDpiChanged: - for (auto& v : m_eventobj) - { - if (v) v->onWindowDpiChange(); - } - break; - case EventType::DeviceChange: - for (auto& v : m_eventobj) - { - if (v) v->onDeviceChange(); - } - break; - } - m_is_dispatch_event = false; - // 处理那些延迟的对象 - removeEventListener(nullptr); - for (auto& v : m_eventobj_late) - { - m_eventobj.emplace_back(v); - } - m_eventobj_late.clear(); - } - void Window_Win32::addEventListener(IWindowEventListener* e) - { - removeEventListener(e); - if (m_is_dispatch_event) - { - m_eventobj_late.emplace_back(e); - } - else - { - m_eventobj.emplace_back(e); - } - } - void Window_Win32::removeEventListener(IWindowEventListener* e) - { - if (m_is_dispatch_event) - { - for (auto& v : m_eventobj) - { - if (v == e) - { - v = nullptr; // 不破坏遍历过程 - } - } - } - else - { - for (auto it = m_eventobj.begin(); it != m_eventobj.end();) - { - if (*it == e) - it = m_eventobj.erase(it); - else - it++; - } - } - } - - void* Window_Win32::getNativeHandle() { return win32_window; } - - void Window_Win32::setIMEState(bool enable) - { - if (!win32_window_ime_enable && enable) { - #pragma warning(push) - #pragma warning(disable: 6387) - // See: https://learn.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immassociatecontextex - // If the application calls this function with IACE_DEFAULT, the operating system restores the default input method context for the window. - ImmAssociateContextEx(win32_window, nullptr /* In this case, the hIMC parameter is ignored. */, IACE_DEFAULT); - #pragma warning (pop) - } - else if (win32_window_ime_enable && !enable) { - ImmAssociateContext(win32_window, nullptr); - } - win32_window_ime_enable = enable; - } - bool Window_Win32::getIMEState() - { - return win32_window_ime_enable; - } - - void Window_Win32::setTitleText(StringView const str) { - win32_window_text = str; - m_title_bar_controller.setTitle(std::string(str)); - convertTitleText(); - if (win32_window) { - PostMessageW(win32_window, LUASTG_WM_UPDAE_TITLE, 0, 0); - } - } - StringView Window_Win32::getTitleText() { - return win32_window_text; - } - - bool Window_Win32::setFrameStyle(WindowFrameStyle style) - { - m_framestyle = style; - win32_window_style = mapWindowStyle(m_framestyle, m_fullscreen_mode); - SetWindowLongPtrW(win32_window, GWL_STYLE, win32_window_style); - //SetWindowLongPtrW(win32_window, GWL_EXSTYLE, win32_window_style_ex); - constexpr UINT flags = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW; - SetWindowPos(win32_window, nullptr, 0, 0, 0, 0, flags); - return true; - } - WindowFrameStyle Window_Win32::getFrameStyle() - { - return m_framestyle; - } - - Vector2U Window_Win32::getSize() - { - return { win32_window_width, win32_window_height }; - } - Vector2U Window_Win32::_getCurrentSize() { - RECT rc{}; - GetClientRect(win32_window, &rc); - return Vector2U(static_cast(rc.right - rc.left), static_cast(rc.bottom - rc.top)); - } - bool Window_Win32::setSize(Vector2U v) - { - win32_window_width = v.x; - win32_window_height = v.y; - return setClientRect(RectI(0, 0, (int)v.x, (int)v.y)); - } - bool Window_Win32::setLayer(WindowLayer const layer) { - HWND native_layer{}; - switch (layer) { - case WindowLayer::Bottom: - native_layer = HWND_BOTTOM; - break; - case WindowLayer::Normal: - native_layer = HWND_NOTOPMOST; - break; - case WindowLayer::Top: - native_layer = HWND_TOP; - break; - case WindowLayer::TopMost: - native_layer = HWND_TOPMOST; - break; - default: - assert(false); - return false; - } - return SetWindowPos(win32_window, native_layer, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW) != FALSE; - } - - float Window_Win32::getDPIScaling() - { - return win32::getScalingFromDpi(getDPI()); - } - - void Window_Win32::setWindowMode(Vector2U size, WindowFrameStyle style, IDisplay* display) - { - SetWindowedModeParameters parameters{}; - parameters.size = size; - parameters.style = style; - parameters.display = display; - SendMessageW(win32_window, LUASTG_WM_SET_WINDOW_MODE, reinterpret_cast(¶meters), FALSE); - } - void Window_Win32::setFullScreenMode(IDisplay* display) - { - SendMessageW(win32_window, LUASTG_WM_SET_FULLSCREEN_MODE, 0, reinterpret_cast(display)); - } - void Window_Win32::setCentered(bool show, IDisplay* display) { - core::SmartReference local_display; - if (!display) { - if (!IDisplay::getNearestFromWindow(this, local_display.put())) { - return; - } - display = local_display.get(); - } - RECT r{}; - [[maybe_unused]] auto const result1 = GetWindowRect(win32_window, &r); - assert(result1); - auto const& m = display->getWorkAreaRect(); - UINT flags = SWP_FRAMECHANGED; - if (show) { - flags |= SWP_SHOWWINDOW; - } - [[maybe_unused]] auto const result2 = SetWindowPos( - win32_window, - HWND_TOP, - (m.a.x + m.b.x) / 2 - (r.right - r.left) / 2, - (m.a.y + m.b.y) / 2 - (r.bottom - r.top) / 2, - r.right - r.left, - r.bottom - r.top, - flags); - assert(result2); - } - - void Window_Win32::setCustomSizeMoveEnable(bool v) - { - m_sizemove.setEnable(v ? TRUE : FALSE); - } - void Window_Win32::setCustomMinimizeButtonRect(RectI v) - { - m_sizemove.setMinimizeButtonRect(RECT{ - .left = v.a.x, - .top = v.a.y, - .right = v.b.x, - .bottom = v.b.y, - }); - } - void Window_Win32::setCustomCloseButtonRect(RectI v) - { - m_sizemove.setCloseButtonRect(RECT{ - .left = v.a.x, - .top = v.a.y, - .right = v.b.x, - .bottom = v.b.y, - }); - } - void Window_Win32::setCustomMoveButtonRect(RectI v) - { - m_sizemove.setTitleBarRect(RECT{ - .left = v.a.x, - .top = v.a.y, - .right = v.b.x, - .bottom = v.b.y, - }); - } - - bool Window_Win32::setCursor(WindowCursor type) - { - m_cursor = type; - switch (type) - { - default: - assert(false); return false; - - case WindowCursor::None: - win32_window_cursor = NULL; - break; - - case WindowCursor::Arrow: - win32_window_cursor = LoadCursor(NULL, IDC_ARROW); - break; - case WindowCursor::Hand: - win32_window_cursor = LoadCursor(NULL, IDC_HAND); - break; - - case WindowCursor::Cross: - win32_window_cursor = LoadCursor(NULL, IDC_CROSS); - break; - case WindowCursor::TextInput: - win32_window_cursor = LoadCursor(NULL, IDC_IBEAM); - break; - - case WindowCursor::Resize: - win32_window_cursor = LoadCursor(NULL, IDC_SIZEALL); - break; - case WindowCursor::ResizeEW: - win32_window_cursor = LoadCursor(NULL, IDC_SIZEWE); - break; - case WindowCursor::ResizeNS: - win32_window_cursor = LoadCursor(NULL, IDC_SIZENS); - break; - case WindowCursor::ResizeNESW: - win32_window_cursor = LoadCursor(NULL, IDC_SIZENESW); - break; - case WindowCursor::ResizeNWSE: - win32_window_cursor = LoadCursor(NULL, IDC_SIZENWSE); - break; - - case WindowCursor::NotAllowed: - win32_window_cursor = LoadCursor(NULL, IDC_NO); - break; - case WindowCursor::Wait: - win32_window_cursor = LoadCursor(NULL, IDC_WAIT); - break; - } - POINT pt = {}; - GetCursorPos(&pt); - SetCursorPos(pt.x, pt.y); - return true; - } - WindowCursor Window_Win32::getCursor() - { - return m_cursor; - } - - void Window_Win32::setWindowCornerPreference(bool const allow) { - m_allow_windows_11_window_corner = allow; - if (!Platform::WindowsVersion::Is11()) { - return; - } - assert(win32_window); - setAllowWindowCorner(win32_window, allow); - } - void Window_Win32::setTitleBarAutoHidePreference(bool const allow) { - auto_hide_title_bar = allow; - m_title_bar_controller.setEnable(auto_hide_title_bar && !m_fullscreen_mode); - if (!m_fullscreen_mode) { - WINDOWPLACEMENT placement{ .length{sizeof(WINDOWPLACEMENT)} }; - GetWindowPlacement(win32_window, &placement); - SetWindowPos(win32_window, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); - SetWindowPlacement(win32_window, &placement); - } - else { - SetWindowPos(win32_window, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_SHOWWINDOW); - } - } - - Window_Win32::Window_Win32() { - auto const& debug_config = ConfigurationLoader::getInstance().getDebug(); - enable_track_window_focus = debug_config.isTrackWindowFocus(); - - auto const& window_config = ConfigurationLoader::getInstance().getWindow(); - if (window_config.hasTitle()) { - win32_window_text = window_config.getTitle(); - } - m_cursor = window_config.isCursorVisible() ? WindowCursor::Arrow : WindowCursor::None; - m_allow_windows_11_window_corner = window_config.isAllowWindowCorner(); - auto_hide_title_bar = window_config.isAllowTitleBarAutoHide(); - - auto const& graphics_config = ConfigurationLoader::getInstance().getGraphicsSystem(); - win32_window_width = graphics_config.getWidth(); - win32_window_height = graphics_config.getHeight(); - - m_title_bar_controller.setTitle(win32_window_text); - convertTitleText(); - win32_window_dpi = win32::getUserDefaultScreenDpi(); - - if (!createWindowClass()) - throw std::runtime_error("createWindowClass failed"); - if (!createWindow()) - throw std::runtime_error("createWindow failed"); - } - Window_Win32::~Window_Win32() - { - destroyWindow(); - destroyWindowClass(); - } - - bool Window_Win32::create(Window_Win32** pp_window) - { - try - { - *pp_window = new Window_Win32(); - return true; - } - catch (...) - { - *pp_window = nullptr; - return false; - } - } - bool Window_Win32::create(Vector2U size, StringView title_text, WindowFrameStyle style, bool show, Window_Win32** pp_window) - { - try - { - auto* p = new Window_Win32(); - *pp_window = p; - p->setSize(size); - p->setTitleText(title_text); - p->setFrameStyle(style); - if (show) - p->setLayer(WindowLayer::Normal); - return true; - } - catch (...) - { - *pp_window = nullptr; - return false; - } - } - - bool IWindow::create(IWindow** pp_window) - { - try - { - *pp_window = new Window_Win32(); - return true; - } - catch (...) - { - *pp_window = nullptr; - return false; - } - } - bool IWindow::create(Vector2U size, StringView title_text, WindowFrameStyle style, bool show, IWindow** pp_window) - { - try - { - auto* p = new Window_Win32(); - *pp_window = p; - p->setSize(size); - p->setTitleText(title_text); - p->setFrameStyle(style); - if (show) - p->setLayer(WindowLayer::Normal); - return true; - } - catch (...) - { - *pp_window = nullptr; - return false; - } - } -} diff --git a/LuaSTG/Core/Graphics/Window_Win32.hpp b/LuaSTG/Core/Graphics/Window_Win32.hpp deleted file mode 100644 index ef2462a4..00000000 --- a/LuaSTG/Core/Graphics/Window_Win32.hpp +++ /dev/null @@ -1,222 +0,0 @@ -#pragma once -#include "core/implement/ReferenceCounted.hpp" -#include "Core/ApplicationModel.hpp" -#include "Core/Graphics/Window.hpp" -#include "Platform/WindowSizeMoveController.hpp" -#include "Platform/ImmersiveTitleBarController.hpp" - -namespace core::Graphics -{ - class Display_Win32 final : public implement::ReferenceCounted { - public: - // IDisplay - - void* getNativeHandle() override; - void getFriendlyName(IImmutableString** output) override; - Vector2U getSize() override; - Vector2I getPosition() override; - RectI getRect() override; - Vector2U getWorkAreaSize() override; - Vector2I getWorkAreaPosition() override; - RectI getWorkAreaRect() override; - bool isPrimary() override; - float getDisplayScale() override; - - // Display/Win32 - - explicit Display_Win32(HMONITOR monitor); - Display_Win32(Display_Win32 const&) = delete; - Display_Win32(Display_Win32&&) = delete; - ~Display_Win32() override; - - Display_Win32& operator=(Display_Win32 const&) = delete; - Display_Win32& operator=(Display_Win32&&) = delete; - - private: - HMONITOR win32_monitor{}; - }; - - struct SetWindowedModeParameters { - Vector2U size; - WindowFrameStyle style{ WindowFrameStyle::None }; - IDisplay* display{}; - }; - - class Window_Win32 : public implement::ReferenceCounted - { - private: - WNDCLASSEXW win32_window_class{ sizeof(WNDCLASSEXW) }; - ATOM win32_window_class_atom{ 0 }; - static LRESULT CALLBACK win32_window_callback(HWND window, UINT message, WPARAM arg1, LPARAM arg2); - - HWND win32_window{}; - bool m_window_created{ false }; - - BOOL win32_window_ime_enable{ FALSE }; - - UINT win32_window_width{ 640 }; - UINT win32_window_height{ 480 }; - UINT win32_window_dpi{ USER_DEFAULT_SCREEN_DPI }; - - INT_PTR win32_window_icon_id{ /* IDI_APPICON THIS IS A HACK */ 101 }; - - std::string win32_window_text{ "LuaSTG Sub" }; - std::array win32_window_text_w{}; - - WindowCursor m_cursor{ WindowCursor::Arrow }; - HCURSOR win32_window_cursor{}; - - WindowFrameStyle m_framestyle{ WindowFrameStyle::Normal }; - DWORD win32_window_style{ WS_VISIBLE | WS_OVERLAPPEDWINDOW ^ (WS_THICKFRAME | WS_MAXIMIZEBOX) }; - DWORD win32_window_style_ex{ 0 }; - WINDOWPLACEMENT m_last_window_placement{}; - BOOL m_alt_down{ FALSE }; - BOOL m_fullscreen_mode{ FALSE }; - BOOL m_ignore_size_message{ FALSE }; // 在 SetWindowLongPtr 修改窗口样式时,可以忽略 WM_SIZE - BOOL m_allow_windows_11_window_corner{ TRUE }; - - BOOL win32_window_is_sizemove{ FALSE }; - BOOL win32_window_is_menu_loop{ FALSE }; - BOOL win32_window_want_track_focus{ FALSE }; - bool enable_track_window_focus{ false }; - bool auto_hide_title_bar{ false }; - - Platform::WindowSizeMoveController m_sizemove; - platform::windows::ImmersiveTitleBarController m_title_bar_controller; - - LRESULT onMessage(HWND window, UINT message, WPARAM arg1, LPARAM arg2); - - bool createWindowClass(); - void destroyWindowClass(); - bool createWindow(); - void destroyWindow(); - - IApplicationModel* m_framework{}; - - public: - // 内部方法 - - HWND GetWindow() { return win32_window; } - platform::windows::ImmersiveTitleBarController& getTitleBarController() { return m_title_bar_controller; } - - void convertTitleText(); - - RectI getRect(); - bool setRect(RectI v); - RectI getClientRect(); - bool setClientRect(RectI v); - uint32_t getDPI(); - bool _recreateWindow(); - bool recreateWindow(); - void _toggleFullScreenMode(); - void _setWindowMode(SetWindowedModeParameters* parameters, bool ignore_size); - void _setFullScreenMode(IDisplay* display); - - void implSetApplicationModel(IApplicationModel* p_framework) { m_framework = p_framework; } - - private: - - enum class EventType - { - WindowCreate, - WindowDestroy, - - WindowActive, - WindowInactive, - - WindowClose, - - WindowSize, - WindowFullscreenStateChange, - WindowDpiChanged, - - NativeWindowMessage, - - DeviceChange, - }; - union EventData - { - Vector2U window_size; - bool window_fullscreen_state; - }; - bool m_is_dispatch_event{ false }; - std::vector m_eventobj; - std::vector m_eventobj_late; - void dispatchEvent(EventType t, EventData d = {}); - - public: - - void addEventListener(IWindowEventListener* e) override; - void removeEventListener(IWindowEventListener* e) override; - - private: - - std::u32string m_text_input_buffer; - std::u8string m_text_input_buffer_u8; - uint32_t m_text_input_cursor{}; - char16_t m_text_input_last_high_surrogate{}; - bool m_text_input_enabled{ false }; - - void textInput_updateBuffer(); - void textInput_addChar32(char32_t code); - void textInput_handleChar32(char32_t code); - void textInput_handleChar16(char16_t code); - - public: - - // IWindow - - bool textInput_isEnabled() override; - void textInput_setEnabled(bool enabled) override; - StringView textInput_getBuffer() override; - void textInput_clearBuffer() override; - uint32_t textInput_getCursorPosition() override; - void textInput_setCursorPosition(uint32_t code_point_index) override; - void textInput_addCursorPosition(int32_t offset_by_code_point) override; - void textInput_removeBufferRange(uint32_t code_point_index, uint32_t code_point_count) override; - void textInput_insertBufferRange(uint32_t code_point_index, StringView str) override; - void textInput_backspace(uint32_t code_point_count) override; - - void* getNativeHandle() override; - - void setIMEState(bool enable) override; - bool getIMEState() override; - void setInputMethodPosition(Vector2I position) override; - - void setTitleText(StringView str) override; - StringView getTitleText() override; - - bool setFrameStyle(WindowFrameStyle style) override; - WindowFrameStyle getFrameStyle() override; - - Vector2U getSize() override; - Vector2U _getCurrentSize() override; - bool setSize(Vector2U v) override; - bool setLayer(WindowLayer layer) override; - - float getDPIScaling() override; - - void setWindowMode(Vector2U size, WindowFrameStyle style, IDisplay* display) override; - void setFullScreenMode(IDisplay* display) override; - void setCentered(bool show, IDisplay* display) override; - - void setCustomSizeMoveEnable(bool v) override; - void setCustomMinimizeButtonRect(RectI v) override; - void setCustomCloseButtonRect(RectI v) override; - void setCustomMoveButtonRect(RectI v) override; - - bool setCursor(WindowCursor type) override; - WindowCursor getCursor() override; - - void setWindowCornerPreference(bool allow) override; // Windows 11 - void setTitleBarAutoHidePreference(bool allow) override; // Windows 11 - - // Window/Win32 - - Window_Win32(); - ~Window_Win32() override; - - static bool create(Window_Win32** pp_window); - static bool create(Vector2U size, StringView title_text, WindowFrameStyle style, bool show, Window_Win32** pp_window); - }; -} diff --git a/LuaSTG/Core/framework.cpp b/LuaSTG/Core/framework.cpp deleted file mode 100644 index 6741c535..00000000 --- a/LuaSTG/Core/framework.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Core/framework.hpp" diff --git a/LuaSTG/Core/framework.hpp b/LuaSTG/Core/framework.hpp deleted file mode 100644 index e5252707..00000000 --- a/LuaSTG/Core/framework.hpp +++ /dev/null @@ -1,106 +0,0 @@ -#pragma once - -#ifdef _WIN32_WINNT -#undef _WIN32_WINNT -#endif -#ifdef NTDDI_VERSION -#undef NTDDI_VERSION -#endif -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "spdlog/spdlog.h" - -#include "tracy/Tracy.hpp" -#include "tracy/TracyD3D11.hpp" -#include "tracy/TracyAPI.hpp" - -#include "Platform/HResultChecker.hpp" - -namespace Microsoft::WRL::Wrappers -{ - namespace HandleTraits - { - struct ThreadHandleTraits : HANDLENullTraits - { - }; - } - using ThreadHandle = HandleT; -} - -#ifdef _DEBUG -inline void F_D3D_SET_DEBUG_NAME(IDXGIObject* ptr, std::string_view file, int line, std::string_view name) -{ - if (ptr) - { - std::stringstream strstr; - strstr << "File: " << file << " "; - strstr << "Line: " << line << " "; - strstr << "DXGIObject: " << name; - std::string str = strstr.str(); - ptr->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)str.length(), str.c_str()); - } -} -inline void F_D3D_SET_DEBUG_NAME(ID3D11Device* ptr, std::string_view file, int line, std::string_view name) -{ - if (ptr) - { - std::stringstream strstr; - strstr << "File: " << file << " "; - strstr << "Line: " << line << " "; - strstr << "DXGIObject: " << name; - std::string str = strstr.str(); - ptr->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)str.length(), str.c_str()); - } -} -inline void F_D3D_SET_DEBUG_NAME(ID3D11DeviceChild* ptr, std::string_view file, int line, std::string_view name) -{ - if (ptr) - { - std::stringstream strstr; - strstr << "File: " << file << " "; - strstr << "Line: " << line << " "; - strstr << "DXGIObject: " << name; - std::string str = strstr.str(); - ptr->SetPrivateData(WKPDID_D3DDebugObjectName, (UINT)str.length(), str.c_str()); - } -} -#define M_D3D_SET_DEBUG_NAME(OBJ, STR) F_D3D_SET_DEBUG_NAME(OBJ, __FILE__, __LINE__, STR) -#define M_D3D_SET_DEBUG_NAME_SIMPLE(OBJ) M_D3D_SET_DEBUG_NAME(OBJ, #OBJ) -#else -#define M_D3D_SET_DEBUG_NAME(OBJ, STR) -#define M_D3D_SET_DEBUG_NAME_SIMPLE(OBJ) -#endif diff --git a/LuaSTG/Core/i18n.cpp b/LuaSTG/Core/i18n.cpp deleted file mode 100644 index 367e54f2..00000000 --- a/LuaSTG/Core/i18n.cpp +++ /dev/null @@ -1,375 +0,0 @@ -#include "Core/i18n.hpp" - -struct i18n_entry_t -{ - std::string_view const zh_cn; - std::string_view const en_us; -}; - -static i18n_lang_t g_i18n_lang = i18n_lang_t::zh_cn; -static std::unordered_map const g_i18n_map = { - {"[core].system_call_failed_f",{ - .zh_cn = "[core] {} 调用失败", - .en_us = "[core] {} failed", - }}, - {"[core].system_dll_load_failed_f",{ - .zh_cn = "[core] 无法加载 {} 模块", - .en_us = "[core] load module {} failed", - }}, - {"[core].system_dll_load_func_failed_f",{ - .zh_cn = "[core] 无法从模块 {0} 加载接口 {1}", - .en_us = "[core] load interface {1} from module {0} failed", - }}, - - {"Enable",{ - .zh_cn = "启用", - .en_us = "Enable", - }}, - {"Disable",{ - .zh_cn = "禁用", - .en_us = "Disable", - }}, - {"unknown",{ - .zh_cn = "未知", - .en_us = "unknown", - }}, - {"support",{ - .zh_cn = "支持", - .en_us = "support", - }}, - {"not_support",{ - .zh_cn = "不支持", - .en_us = "not support", - }}, - {"not_support.requires_Windows_8",{ - .zh_cn = "不支持(最低系统要求为 Windows 8)", - .en_us = "not support (requires Windows 8 or above)", - }}, - {"not_support.requires_Windows_8_point_1",{ - .zh_cn = "不支持(最低系统要求为 Windows 8.1)", - .en_us = "not support (requires Windows 8.1 or above)", - }}, - {"not_support.requires_Windows_10",{ - .zh_cn = "不支持(最低系统要求为 Windows 10)", - .en_us = "not support (requires Windows 10 or above)", - }}, - {"not_support.requires_Windows_10_and_hardware",{ - .zh_cn = "不支持(最低系统要求为 Windows 10,且硬件支持该功能)", - .en_us = "not support (requires Windows 10 or above, and hardware support)", - }}, - - {"[core].Device_D3D11.start_creating_graphic_components",{ - .zh_cn = "[core] 开始创建图形组件", - .en_us = "[core] Start creating graphic components", - }}, - {"[core].Device_D3D11.created_graphic_components",{ - .zh_cn = "[core] 已创建图形组件", - .en_us = "[core] Graphic components created", - }}, - {"[core].Device_D3D11.start_creating_basic_DXGI_components",{ - .zh_cn = "[core] 开始创建基本 DXGI 组件", - .en_us = "[core] Start creating basic DXGI components", - }}, - {"[core].Device_D3D11.created_basic_DXGI_components",{ - .zh_cn = "[core] 已创建基本 DXGI 组件", - .en_us = "[core] Basic DXGI components created", - }}, - - {"[core].Device_D3D11.enum_all_adapters",{ - .zh_cn = "[core] 枚举所有图形设备", - .en_us = "[core] Enumerate all graphics devices", - }}, - {"[core].Device_D3D11.DXGI_detail_fmt",{ - .zh_cn = "[core] DXGI 组件功能支持:\n" - " 立即刷新:{}" - , - .en_us = "[core] DXGI components feature support:\n" - " Present Allow Tearing: {}" - , - }}, - - {"DXGI_adapter_type_hardware",{ - .zh_cn = "硬件设备", - .en_us = "Hardware", - }}, - {"DXGI_adapter_type_software",{ - .zh_cn = "软件设备", - .en_us = "Software", - }}, - {"DXGI_adapter_type_hardware_remote",{ - .zh_cn = "远程硬件设备", - .en_us = "Remote Hardware", - }}, - {"DXGI_adapter_type_software_remote",{ - .zh_cn = "远程软件设备", - .en_us = "Remote Software", - }}, - {"DXGI_adapter_type_software_warning",{ - .zh_cn = "(警告:软件或远程设备性能不足流畅运行程序)", - .en_us = " (WARNING: The software or remote device does not have enough performance to run the program smoothly)", - }}, - - {"[core].Device_D3D11.DXGI_adapter_detail_fmt",{ - .zh_cn = "[core] 图形设备[{}]:\n" - " 设备名称:{}\n" - " Direct3D 功能级别:{}\n" - " 设备类型:{}{}\n" - " 专用显存:{}\n" - " 专用内存:{}\n" - " 共享内存:{}\n" - " 供应商 ID:0x{:08X}\n" - " 设备 ID:0x{:08X}\n" - " 子系统 ID:0x{:08X}\n" - " 修订号:0x{:08X}\n" - " 设备 LUID:{:08X}-{:08X}" - , - .en_us = "[core] Graphics Device[{}]:\n" - " Description: {}\n" - " Direct3D Feature Level: {}\n" - " Type: {}{}\n" - " Dedicated Video Memory: {}\n" - " Dedicated System Memory: {}\n" - " Shared System Memory: {}\n" - " Vendor ID: 0x{:08X}\n" - " Device ID: 0x{:08X}\n" - " SubSystem ID: 0x{:08X}\n" - " Revision: 0x{:08X}\n" - " Adapter LUID:{:08X}-{:08X}" - , - }}, - {"[core].Device_D3D11.DXGI_adapter_detail_error_fmt",{ - .zh_cn = "[core] 图形设备[{}]:<无法读取信息>", - .en_us = "[core] Graphics Device[{}]: ", - }}, - - {"[core].Device_D3D11.select_DXGI_adapter_fmt",{ - .zh_cn = "[core] 已选择图形设备:{}", - .en_us = "[core] Select Graphics Device: {}", - }}, - {"[core].Device_D3D11.no_available_DXGI_adapter",{ - .zh_cn = "[core] 没有可用的图形设备", - .en_us = "[core] No Graphics Device available", - }}, - {"[core].Device_D3D11.DXGI_adapter_no_output_warning_fmt",{ - .zh_cn = "[core] 图形设备 {} 似乎没有连接到任何显示输出,这可能导致:\n" - " 独占全屏时会通过 PCI-E 复制渲染缓冲区\n" - " 独占全屏时桌面窗口管理器接管画面合成\n" - " 性能下降、呈现延迟变高" - , - .en_us = "[core] Graphics Device {} doesn't appear to connect to any display output, which could result in:\n" - " Buffer is copied over PCI-E when in exclusive fullscreen\n" - " Desktop Window Manager takes over desktop composition when in exclusive fullscreen\n" - " Degraded performance and increased frame latency" - , - }}, - - {"DXGI_output_connected",{ - .zh_cn = "已连接", - .en_us = "True", - }}, - {"DXGI_output_not_connect",{ - .zh_cn = "未连接", - .en_us = "False", - }}, - - {"[core].Device_D3D11.DXGI_output_detail_fmt",{ - .zh_cn = "[core] 图形设备[{}] - 显示输出设备[{}]:\n" - " 连接状态:{}\n" - " 显示区域:({}, {}) ({} x {})\n" - " 旋转:{}\n" - " 硬件表面合成:{}" - , - .en_us = "[core] Graphics Device[{}] - Display Output[{}]:\n" - " Attached To Desktop: {}\n" - " Desktop Coordinates: ({}, {}) ({} x {})\n" - " Rotation: {}\n" - " Hardware Composition: {}" - , - }}, - {"[core].Device_D3D11.DXGI_output_detail_fmt2",{ - .zh_cn = "[core] 图形设备[{}] - 显示输出设备[{}]:\n" - " 连接状态:{}\n" - " 显示区域:({}, {}) ({} x {})\n" - " 旋转:{}\n" - " 多平面叠加:{}\n" - " 多平面叠加功能:{}\n" - " 硬件表面合成:{}" - , - .en_us = "[core] Graphics Device[{}] - Display Output[{}]:\n" - " Attached To Desktop: {}\n" - " Desktop Coordinates: ({}, {}) ({} x {})\n" - " Rotation: {}\n" - " Multi-Plane Overlay: {}\n" - " Multi-Plane Overlay Feature: {}\n" - " Hardware Composition: {}" - , - }}, - {"[core].Device_D3D11.DXGI_output_detail_error_fmt",{ - .zh_cn = "[core] 图形设备[{}] - 显示输出设备[{}]:<无法读取信息>", - .en_us = "[core] Graphics Device[{}] - Display Output[{}]: ", - }}, - - {"[core].Device_D3D11.start_creating_basic_D3D11_components",{ - .zh_cn = "[core] 开始创建基本 Direct3D 11 组件", - .en_us = "[core] Start creating basic Direct3D 11 components", - }}, - {"[core].Device_D3D11.created_basic_D3D11_components",{ - .zh_cn = "[core] 已创建基本 Direct3D 11 组件", - .en_us = "[core] Basic Direct3D 11 components created", - }}, - -#pragma warning(disable:4002) -#define ADD(KEY, V1, V2) {KEY,{V1,V2}} - - // Swapchain DXGI - ADD("DXGI.SwapChain.SwapEffect.Discard", - .zh_cn = "位块传输模式", - .en_us = "Discard", - ), - ADD("DXGI.SwapChain.SwapEffect.FlipSequential", - .zh_cn = "序列交换模式", - .en_us = "Flip Sequential", - ), - ADD("DXGI.SwapChain.SwapEffect.FlipDiscard", - .zh_cn = "快速交换模式", - .en_us = "Flip Discard", - ), - ADD("DXGI.DisplayMode.RefreshRate.Desktop", - .zh_cn = "桌面刷新率", - .en_us = "Desktop", - ), - // Swapchain - ADD("[core].SwapChain_D3D11.start_creating_swapchain", - .zh_cn = "[core] 开始创建 SwapChain", - .en_us = "[core] Start creating SwapChain", - ), - ADD("[core].SwapChain_D3D11.created_swapchain", - .zh_cn = "[core] 已创建 SwapChain", - .en_us = "[core] SwapChain created", - ), - ADD("[core].SwapChain_D3D11.created_swapchain_info_fmt", - .zh_cn = "[core] 已创建 SwapChain:\n" - " 显示模式:{}x{}@{}\n" - " 独占全屏:{}\n" - " 交换链模式:{}\n" - " 立即刷新:{}\n" - " 低延迟呈现:{}", - .en_us = "[core] SwapChain created:\n" - " Display Mode: {}x{}@{}\n" - " Exclusive Fullscreen:{}\n" - " SwapChain swap effect: {}\n" - " Present Allow Tearing: {}\n" - " Frame Latency Waitable Object: {}", - ), - ADD("[core].SwapChain_D3D11.create_swapchain_failed_null_window", - .zh_cn = "[core] 无法创建 SwapChain,窗口为空", - .en_us = "[core] Failed to create SwapChain, Window is null", - ), - ADD("[core].SwapChain_D3D11.create_swapchain_failed_null_DXGI", - .zh_cn = "[core] 无法创建 SwapChain,DXGI 组件为空", - .en_us = "[core] Failed to create SwapChain, DXGI components are null", - ), - ADD("[core].SwapChain_D3D11.create_swapchain_failed_null_device", - .zh_cn = "[core] 无法创建 SwapChain,图形设备为空", - .en_us = "[core] Failed to create SwapChain, Device is null", - ), - ADD("[core].SwapChain_D3D11.create_swapchain_failed_invalid_size_fmt", - .zh_cn = "[core] 无法创建大小为 ({}x{}) 的 SwapChain", - .en_us = "[core] Cannot create SwapChain with size ({}x{})", - ), - ADD("[core].SwapChain_D3D11.resize_swapchain_failed_invalid_size_fmt", - .zh_cn = "[core] 无法更改 SwapChain 的大小为 ({}x{})", - .en_us = "[core] Cannot resize SwapChain with size ({}x{})", - ), - ADD("[core].SwapChain_D3D11.resize_swapchain_failed_null_SwapChain", - .zh_cn = "[core] 无法更改 SwapChain 的大小,交换链为空", - .en_us = "[core] Failed to resize SwapChain, SwapChain is null", - ), - // Swapchain Exclusive Fullscreen - ADD("[core].SwapChain_D3D11.enter_exclusive_fullscreen", - .zh_cn = "[core] 尝试进入独占全屏", - .en_us = "[core] Try to enter exclusive fullscreen", - ), - ADD("[core].SwapChain_D3D11.leave_exclusive_fullscreen", - .zh_cn = "[core] 尝试退出独占全屏", - .en_us = "[core] Try to leave exclusive fullscreen", - ), - ADD("[core].SwapChain_D3D11.exclusive_fullscreen_unavailable", - .zh_cn = "[core] 独占全屏不可用", - .en_us = "[core] Exclusive fullscreen unavailable", - ), - // Swapchain DisplayMode - ADD("[core].SwapChain_D3D11.start_enumerating_DisplayMode", - .zh_cn = "[core] 开始枚举显示模式", - .en_us = "[core] Start enumerating DisplayMode", - ), - ADD("[core].SwapChain_D3D11.found_N_DisplayMode_fmt", - .zh_cn = "[core] 共找到 {} 个支持的显示模式:", - .en_us = "[core] Found {} supported DisplayMode:", - ), - ADD("[core].SwapChain_D3D11.enumerating_DisplayMode_failed", - .zh_cn = "[core] 找不到可用的显示模式", - .en_us = "[core] No DisplayMode available", - ), - ADD("[core].SwapChain_D3D11.match_DisplayMode_failed_invalid_size_fmt", - .zh_cn = "[core] 无法匹配大小为 ({}x{}) 的显示模式", - .en_us = "[core] Cannot match DisplayMode with size ({}x{})", - ), - ADD("[core].SwapChain_D3D11.match_DisplayMode_failed_null_SwapChain", - .zh_cn = "[core] 无法匹配显示模式,交换链为空", - .en_us = "[core] Failed to match DisplayMode, SwapChain is null" - ), - ADD("[core].SwapChain_D3D11.match_DisplayMode_failed_null_Device", - .zh_cn = "[core] 无法匹配显示模式,图形设备为空", - .en_us = "[core] Failed to match DisplayMode, Device is null" - ), - // Swapchain RenderAttachment - ADD("[core].SwapChain_D3D11.start_creating_RenderAttachment", - .zh_cn = "[core] 开始创建 RenderAttachment", - .en_us = "[core] Start creating RenderAttachment" - ), - ADD("[core].SwapChain_D3D11.created_RenderAttachment", - .zh_cn = "[core] 已创建 RenderAttachment", - .en_us = "[core] RenderAttachment created" - ), - ADD("[core].SwapChain_D3D11.create_RenderAttachment_failed_null_SwapChain", - .zh_cn = "[core] 无法创建 RenderAttachment,交换链为空", - .en_us = "[core] Failed to create RenderAttachment, SwapChain is null" - ), - ADD("[core].SwapChain_D3D11.create_RenderAttachment_failed_null_Device", - .zh_cn = "[core] 无法创建 RenderAttachment,图形设备为空", - .en_us = "[core] Failed to create RenderAttachment, Device is null" - ), - // Swapchain Canvas - ADD("[core].SwapChain_D3D11.resize_canvas_failed_invalid_size_fmt", - .zh_cn = "[core] 无法将 Canvas 的尺寸更改为 ({}x{})", - .en_us = "[core] Cannot resize SwapChain with size ({}x{})", - ), - -#pragma warning(default:4002) -}; - -void i18n_set_lang(i18n_lang_t lang) -{ - g_i18n_lang = lang; -} -std::string_view i18n(std::string_view const& key) -{ - assert(!key.empty()); - auto it = g_i18n_map.find(key); - assert(it != g_i18n_map.end()); - if (it != g_i18n_map.end()) - { - assert(!it->second.zh_cn.empty()); - assert(!it->second.en_us.empty()); - switch (g_i18n_lang) - { - default: - case i18n_lang_t::zh_cn: - return it->second.zh_cn; - case i18n_lang_t::en_us: - return it->second.en_us; - } - } - return key; -} diff --git a/LuaSTG/Core/i18n.hpp b/LuaSTG/Core/i18n.hpp deleted file mode 100644 index ebabe4f6..00000000 --- a/LuaSTG/Core/i18n.hpp +++ /dev/null @@ -1,54 +0,0 @@ -#pragma once -#include -#include -#include - -enum class i18n_lang_t -{ - zh_cn, - en_us, -}; - -void i18n_set_lang(i18n_lang_t lang); -std::string_view i18n(std::string_view const& key); - -#define i18n_log_info(STR) spdlog::info(i18n(STR)) -//#define i18n_log_info_fmt(FMT, ...) spdlog::info(fmt::runtime(i18n(FMT)), __VA_ARGS__) - -#define i18n_log_warn(STR) spdlog::warn(i18n(STR)) -//#define i18n_log_warn_fmt(FMT, ...) spdlog::warn(fmt::runtime(i18n(FMT)), __VA_ARGS__) - -#define i18n_log_error(STR) spdlog::error(i18n(STR)) -//#define i18n_log_error_fmt(FMT, ...) spdlog::error(fmt::runtime(i18n(FMT)), __VA_ARGS__) - -#define i18n_log_critical(STR) spdlog::critical(i18n(STR)) -//#define i18n_log_critical_fmt(FMT, ...) spdlog::critical(fmt::runtime(i18n(FMT)), __VA_ARGS__) - -template -inline void i18n_log_info_fmt(T&& fmt, A&&... args) -{ - spdlog::info(fmt::runtime(i18n(std::forward(fmt))), std::forward(args)...); -} - -template -inline void i18n_log_warn_fmt(T&& fmt, A&&... args) -{ - spdlog::warn(fmt::runtime(i18n(std::forward(fmt))), std::forward(args)...); -} - -template -inline void i18n_log_error_fmt(T&& fmt, A&&... args) -{ - spdlog::error(fmt::runtime(i18n(std::forward(fmt))), std::forward(args)...); -} - -template -inline void i18n_log_critical_fmt(T&& fmt, A&&... args) -{ - spdlog::critical(fmt::runtime(i18n(std::forward(fmt))), std::forward(args)...); -} - -inline void i18n_core_system_call_report_error(std::string_view message) -{ - spdlog::error(fmt::runtime(i18n("[core].system_call_failed_f")), message); -} diff --git a/LuaSTG/LuaSTG/AppFrame.cpp b/LuaSTG/LuaSTG/AppFrame.cpp index 0fb48c56..4cc914ca 100644 --- a/LuaSTG/LuaSTG/AppFrame.cpp +++ b/LuaSTG/LuaSTG/AppFrame.cpp @@ -1,7 +1,9 @@ #include "AppFrame.h" #include "ApplicationRestart.hpp" #include "core/FileSystem.hpp" -#include "Platform/XInput.hpp" +#include "windows/WindowsVersion.hpp" +#include "windows/ProcessorInfo.hpp" +#include "windows/XInput.hpp" #include "Utility/Utility.h" #include "Debugger/ImGuiExtension.h" #include "LuaBinding/LuaAppFrame.hpp" @@ -68,19 +70,17 @@ float AppFrame::GetBGMVolume() { return core::ConfigurationLoader::getInstance().getAudioSystem().getMusicVolume(); } } -void AppFrame::SetTitle(const char* v)noexcept -{ - if (m_pAppModel) { - m_pAppModel->getWindow()->setTitleText(v); +void AppFrame::SetTitle(const char* v) noexcept { + if (m_window) { + m_window->setTitleText(v); } else { auto& win = core::ConfigurationLoader::getInstance().getWindowRef(); win.setTitle(v); } } -void AppFrame::SetPreferenceGPU(const char* v) noexcept -{ - if (m_pAppModel) { +void AppFrame::SetPreferenceGPU(const char* v) noexcept { + if (m_graphics_device) { // TODO } else { @@ -88,10 +88,9 @@ void AppFrame::SetPreferenceGPU(const char* v) noexcept gs.setPreferredDeviceName(v); } } -void AppFrame::SetSplash(bool v)noexcept -{ - if (m_pAppModel) { - m_pAppModel->getWindow()->setCursor(v ? core::Graphics::WindowCursor::Arrow : core::Graphics::WindowCursor::None); +void AppFrame::SetSplash(bool v) noexcept { + if (m_window) { + m_window->setCursor(v ? core::WindowCursor::Arrow : core::WindowCursor::None); } else { auto& win = core::ConfigurationLoader::getInstance().getWindowRef(); @@ -197,11 +196,26 @@ bool AppFrame::Init()noexcept window_config.setTitle(LUASTG_INFO); } - if (!core::IApplicationModel::create(this, m_pAppModel.put())) + spdlog::info("[core] System: {}", Platform::WindowsVersion::GetName()); + spdlog::info("[core] Kernel: {}", Platform::WindowsVersion::GetKernelVersionString()); + spdlog::info("[core] CPU: {}", Platform::ProcessorInfo::name()); + //get_system_memory_status(); + if (!core::IWindow::create(m_window.put())) return false; - if (!core::IAudioEngine::create(m_audio_engine.put())) + auto const& gpu = core::ConfigurationLoader::getInstance().getGraphicsSystem().getPreferredDeviceName(); + if (!core::IGraphicsDevice::create(gpu, m_graphics_device.put())) return false; - if (!core::Graphics::ITextRenderer::create(m_pAppModel->getRenderer(), m_pTextRenderer.put())) + m_render_statistics.reserve(4); + for (int i = 0; i < 4; i += 1) { + m_render_statistics.emplace_back(m_graphics_device.get()); + } + if (!core::Graphics::ISwapChain::create(m_window.get(), m_graphics_device.get(), m_swap_chain.put())) + return false; + if (!core::Graphics::IRenderer::create(m_graphics_device.get(), m_renderer.put())) + return false; + if (!core::Graphics::ITextRenderer::create(m_renderer.get(), m_text_renderer.put())) + return false; + if (!core::IAudioEngine::create(m_audio_engine.put())) return false; if (!SharedSpriteRenderer::create()) return false; @@ -216,7 +230,7 @@ bool AppFrame::Init()noexcept // 创建手柄输入 try { - m_DirectInput = std::make_unique((ptrdiff_t)m_pAppModel->getWindow()->getNativeHandle()); + m_DirectInput = std::make_unique((ptrdiff_t)m_window->getNativeHandle()); { m_DirectInput->refresh(); // 这里因为窗口还没显示,所以应该会出现一个Aquire设备失败的错误信息,忽略即可 uint32_t cnt = m_DirectInput->count(); @@ -292,9 +306,13 @@ void AppFrame::Shutdown()noexcept CloseInput(); m_DirectInput = nullptr; - m_pTextRenderer = nullptr; - m_pAppModel = nullptr; - m_audio_engine = nullptr; + m_window.reset(); + m_graphics_device.reset(); + m_render_statistics.clear(); + m_swap_chain.reset(); + m_renderer.reset(); + m_text_renderer.reset(); + m_audio_engine.reset(); SharedSpriteRenderer::destroy(); m_iStatus = AppStatus::Destroyed; @@ -305,15 +323,15 @@ void AppFrame::Run()noexcept assert(m_iStatus == AppStatus::Initialized); spdlog::info("[luastg] 开始更新&渲染循环"); - m_pAppModel->getWindow()->addEventListener(this); + m_window->addEventListener(this); onSwapChainCreate(); // 手动触发一次,让自动尺寸的RenderTarget设置为正确的尺寸 - m_pAppModel->getSwapChain()->addEventListener(this); + m_swap_chain->addEventListener(this); - m_pAppModel->getFrameRateController()->setTargetFPS(m_target_fps); - m_pAppModel->run(); + m_frame_rate_controller->setFrameRate(m_target_fps); + core::ApplicationManager::run(this); - m_pAppModel->getSwapChain()->removeEventListener(this); - m_pAppModel->getWindow()->removeEventListener(this); + m_swap_chain->removeEventListener(this); + m_window->removeEventListener(this); spdlog::info("[luastg] 结束更新&渲染循环"); } @@ -325,7 +343,7 @@ void AppFrame::Run()noexcept void AppFrame::onWindowCreate() { OpenInput(); - m_DirectInput = std::make_unique((ptrdiff_t)m_pAppModel->getWindow()->getNativeHandle()); + m_DirectInput = std::make_unique((ptrdiff_t)m_window->getNativeHandle()); { m_DirectInput->refresh(); // 这里因为窗口还没显示,所以应该会出现一个Aquire设备失败的错误信息,忽略即可 uint32_t cnt = m_DirectInput->count(); @@ -364,17 +382,72 @@ void AppFrame::onDeviceChange() m_window_active_changed.fetch_or(0x4); } -bool AppFrame::onUpdate() -{ - m_fFPS = m_pAppModel->getFrameRateController()->getFPS(); - m_fAvgFPS = m_pAppModel->getFrameRateController()->getAvgFPS(); - m_pAppModel->getFrameRateController()->setTargetFPS(m_target_fps); +bool AppFrame::onCreate() { return true; } +void AppFrame::onBeforeUpdate() { + const auto frame_statistics_index = (m_frame_statistics_index + 1) % 2; + auto& d = m_frame_statistics[frame_statistics_index]; + + { + core::ScopeTimer t(&d.wait_time); + if (m_swap_chain) { + m_swap_chain->waitFrameLatency(); + } + m_frame_rate_controller->update(); + } + + m_fFPS = 1.0 / m_frame_rate_controller->getStatistics()->getDuration(0); + m_fAvgFPS = 1.0 / m_frame_rate_controller->getStatistics()->getAverage(10); + m_frame_rate_controller->setFrameRate(m_target_fps); + m_message_timer = core::ScopeTimer(&m_message_time); +} +bool AppFrame::onUpdate() { + m_message_timer = core::ScopeTimer(); + + const auto frame_statistics_index = (m_frame_statistics_index + 1) % 2; + auto& d = m_frame_statistics[frame_statistics_index]; + + const auto render_statistics_index = (m_render_statistics_index + 1) % m_render_statistics.size(); + auto& r = m_render_statistics[render_statistics_index]; + { + core::ScopeTimer t(&d.update_time); + if (!onUpdateInternal()) { + return false; + } + } + + { + core::ScopeTimer t(&d.render_time); + r.begin(); + m_swap_chain->applyRenderAttachment(); + m_swap_chain->clearRenderAttachment(); + const auto result = onRenderInternal(); + r.end(); + if (!result) { + return false; + } + } + + { + core::ScopeTimer t(&d.present_time); + m_swap_chain->present(); + } + + d.update_time += m_message_time; + d.total_time = d.wait_time + d.update_time + d.render_time + d.present_time; + m_frame_statistics_index = frame_statistics_index; // move next + m_render_statistics_index = render_statistics_index; + return true; +} +void AppFrame::onDestroy() {} + +bool AppFrame::onUpdateInternal() +{ bool result = true; // pre-check if (ApplicationRestart::hasRestart()) { - m_pAppModel->requestExit(); + core::ApplicationManager::requestExit(); result = false; } @@ -394,7 +467,7 @@ bool AppFrame::onUpdate() if (!SafeCallGlobalFunction(LuaEngine::G_CALLBACK_FocusLoseFunc)) { result = false; - m_pAppModel->requestExit(); + core::ApplicationManager::requestExit(); } } if (window_active_changed & 0x1) @@ -409,7 +482,7 @@ bool AppFrame::onUpdate() if (!SafeCallGlobalFunction(LuaEngine::G_CALLBACK_FocusGainFunc)) { result = false; - m_pAppModel->requestExit(); + core::ApplicationManager::requestExit(); } } if (window_active_changed & 0x4) @@ -435,24 +508,24 @@ bool AppFrame::onUpdate() if (!SafeCallGlobalFunction(LuaEngine::G_CALLBACK_EngineUpdate, 1)) { result = false; - m_pAppModel->requestExit(); + core::ApplicationManager::requestExit(); } bool tAbort = lua_toboolean(L, -1) != 0; lua_pop(L, 1); if (tAbort) - m_pAppModel->requestExit(); + core::ApplicationManager::requestExit(); m_ResourceMgr.UpdateSound(); } // check again after FrameFunc if (ApplicationRestart::hasRestart()) { - m_pAppModel->requestExit(); + core::ApplicationManager::requestExit(); result = false; } return result; } -bool AppFrame::onRender() +bool AppFrame::onRenderInternal() { m_bRenderStarted = true; @@ -461,7 +534,7 @@ bool AppFrame::onRender() // 执行渲染函数 bool result = SafeCallGlobalFunction(LuaEngine::G_CALLBACK_EngineDraw); if (!result) - m_pAppModel->requestExit(); + core::ApplicationManager::requestExit(); GetRenderTargetManager()->EndRenderTargetStack(); diff --git a/LuaSTG/LuaSTG/AppFrame.h b/LuaSTG/LuaSTG/AppFrame.h index c0c68417..e5d7b5f3 100644 --- a/LuaSTG/LuaSTG/AppFrame.h +++ b/LuaSTG/LuaSTG/AppFrame.h @@ -1,10 +1,18 @@ #pragma once -#include "Core/ApplicationModel.hpp" -#include "Core/Graphics/Font.hpp" +#include +#include +#include "core/Application.hpp" +#include "core/FrameRateController.hpp" +#include "core/Window.hpp" +#include "core/GraphicsDevice.hpp" +#include "core/Graphics/SwapChain.hpp" +#include "core/Graphics/Renderer.hpp" +#include "core/Graphics/Font.hpp" #include "core/AudioEngine.hpp" #include "GameResource/ResourceManager.h" #include "GameObject/GameObjectPool.h" -#include "Platform/DirectInput.hpp" +#include "windows/DirectInput.hpp" +#include "Debugger/FrameQuery.hpp" namespace luastg { /// @brief 应用程序状态 @@ -38,19 +46,48 @@ namespace luastg { /// @brief 应用程序框架 class AppFrame - : public core::IApplicationEventListener - , public core::Graphics::IWindowEventListener + : public core::IApplication + , public core::IWindowEventListener , public core::Graphics::ISwapChainEventListener , public IRenderTargetManager { + public: + // 统计数据 + + struct FrameStatistics { + double total_time{}; + double wait_time{}; + double update_time{}; + double render_time{}; + double present_time{}; + }; + + struct FrameRenderStatistics { + double render_time{}; + }; + private: AppStatus m_iStatus = AppStatus::NotInitialized; // 应用程序框架 - core::SmartReference m_pAppModel; - core::SmartReference m_pTextRenderer; + core::IFrameRateController* m_frame_rate_controller{ core::IFrameRateController::getInstance() }; + core::SmartReference m_window; + core::SmartReference m_graphics_device; + core::SmartReference m_swap_chain; + core::SmartReference m_renderer; + core::SmartReference m_text_renderer; core::SmartReference m_audio_engine; + // 统计数据 + size_t m_frame_statistics_index{}; + FrameStatistics m_frame_statistics[2]{}; + double m_message_time{}; + core::ScopeTimer m_message_timer; + + // 图形统计数据 + size_t m_render_statistics_index{}; + std::vector m_render_statistics; + // 资源管理器 ResourceMgr m_ResourceMgr; @@ -252,9 +289,19 @@ namespace luastg { Platform::DirectInput* GetDInput()noexcept { return m_DirectInput.get(); } - core::IApplicationModel* GetAppModel() { return m_pAppModel.get(); } - core::Graphics::IRenderer* GetRenderer2D() { return m_pAppModel->getRenderer(); } - core::IAudioEngine* getAudioEngine() { return m_audio_engine.get(); } + const FrameStatistics& getFrameStatistics() { return m_frame_statistics[m_frame_statistics_index]; } + const FrameRenderStatistics& getFrameRenderStatistics() { + // TODO: stupid implement + static FrameRenderStatistics s; + s.render_time = m_render_statistics[m_render_statistics_index].getTime(); + return s; + } + core::IWindow* getWindow() const noexcept { return m_window.get(); } + core::IGraphicsDevice* getGraphicsDevice() const noexcept { return m_graphics_device.get(); } + core::Graphics::ISwapChain* getSwapChain() const noexcept { return m_swap_chain.get(); } + core::Graphics::IRenderer* getRenderer2D() const noexcept { return m_renderer.get(); } + core::Graphics::ITextRenderer* getTextRenderer() const noexcept { return m_text_renderer.get(); } + core::IAudioEngine* getAudioEngine() const noexcept { return m_audio_engine.get(); } public: /// @brief 初始化框架 @@ -279,8 +326,17 @@ namespace luastg { void onWindowSize(core::Vector2U size) override; void onDeviceChange() override; + // IApplication + + bool onCreate() override; + void onBeforeUpdate() override; bool onUpdate() override; - bool onRender() override; + void onDestroy() override; + + // Application + + bool onUpdateInternal(); + bool onRenderInternal(); public: AppFrame()noexcept; ~AppFrame()noexcept; diff --git a/LuaSTG/LuaSTG/AppFrameDisplayMode.cpp b/LuaSTG/LuaSTG/AppFrameDisplayMode.cpp index 00631a90..f8f9af6c 100644 --- a/LuaSTG/LuaSTG/AppFrameDisplayMode.cpp +++ b/LuaSTG/LuaSTG/AppFrameDisplayMode.cpp @@ -6,13 +6,10 @@ namespace luastg { bool AppFrame::SetDisplayModeWindow(core::Vector2U window_size, bool vsync) { - auto* window = GetAppModel()->getWindow(); - auto* swapchain = GetAppModel()->getSwapChain(); + m_swap_chain->setVSync(vsync); + bool const result = m_swap_chain->setCanvasSize(window_size); - swapchain->setVSync(vsync); - bool const result = swapchain->setCanvasSize(window_size); - - window->setWindowMode(window_size); + m_window->setWindowMode(window_size); return result; } @@ -20,14 +17,11 @@ namespace luastg // TODO: 废弃 bool AppFrame::SetDisplayModeExclusiveFullscreen(core::Vector2U window_size, bool vsync, core::Rational) { - auto* window = GetAppModel()->getWindow(); - auto* swapchain = GetAppModel()->getSwapChain(); - - swapchain->setVSync(vsync); - bool const result = swapchain->setCanvasSize(window_size); + m_swap_chain->setVSync(vsync); + bool const result = m_swap_chain->setCanvasSize(window_size); - window->setWindowMode(window_size); - window->setFullScreenMode(); + m_window->setWindowMode(window_size); + m_window->setFullScreenMode(); return result; } @@ -43,9 +37,8 @@ namespace luastg { auto const& gs = core::ConfigurationLoader::getInstance().getGraphicsSystem(); auto const& win = core::ConfigurationLoader::getInstance().getWindow(); - auto* p_window = m_pAppModel->getWindow(); - p_window->setCursor(win.isCursorVisible() ? core::Graphics::WindowCursor::Arrow : core::Graphics::WindowCursor::None); - p_window->setWindowMode(core::Vector2U(gs.getWidth(), gs.getHeight())); + m_window->setCursor(win.isCursorVisible() ? core::WindowCursor::Arrow : core::WindowCursor::None); + m_window->setWindowMode(core::Vector2U(gs.getWidth(), gs.getHeight())); } return true; } @@ -53,16 +46,14 @@ namespace luastg bool AppFrame::InitializationApplySettingStage2() { auto const& gs = core::ConfigurationLoader::getInstance().getGraphicsSystem(); - auto* p_window = m_pAppModel->getWindow(); - auto* p_swapchain = GetAppModel()->getSwapChain(); // 初始化交换链 auto const canvas_size = core::Vector2U(gs.getWidth(), gs.getHeight()); - p_swapchain->setVSync(gs.isVsync()); - if (!p_swapchain->setWindowMode(canvas_size)) { + m_swap_chain->setVSync(gs.isVsync()); + if (!m_swap_chain->setWindowMode(canvas_size)) { return false; } if (gs.isFullscreen()) { - p_window->setFullScreenMode(); + m_window->setFullScreenMode(); } return true; } diff --git a/LuaSTG/LuaSTG/AppFrameFontRenderer.cpp b/LuaSTG/LuaSTG/AppFrameFontRenderer.cpp index 23378626..69a1245a 100644 --- a/LuaSTG/LuaSTG/AppFrameFontRenderer.cpp +++ b/LuaSTG/LuaSTG/AppFrameFontRenderer.cpp @@ -23,12 +23,12 @@ namespace luastg IGlyphManager* pGlyphManager = p->GetGlyphManager(); // 准备渲染字体 - m_pTextRenderer->setGlyphManager(pGlyphManager); - m_pTextRenderer->setScale(scale); + m_text_renderer->setGlyphManager(pGlyphManager); + m_text_renderer->setScale(scale); // 设置混合和颜色 updateGraph2DBlendMode(p->GetBlendMode()); - m_pTextRenderer->setColor(p->GetBlendColor()); + m_text_renderer->setColor(p->GetBlendColor()); // 第一次遍历计算要渲染多少行 const wchar_t* pText = strBuf; @@ -128,20 +128,20 @@ namespace luastg switch (halign) { case FontAlignHorizontal::Right: - m_pTextRenderer->drawText(u8_str, Vector2F( + m_text_renderer->drawText(u8_str, Vector2F( vRenderPos.x + std::abs(rect.a.x - rect.b.x) - fLineWidth, vRenderPos.y ), &ignore_); break; case FontAlignHorizontal::Center: - m_pTextRenderer->drawText(u8_str, Vector2F( + m_text_renderer->drawText(u8_str, Vector2F( vRenderPos.x + std::abs(rect.a.x - rect.b.x) / 2.f - fLineWidth / 2.f, vRenderPos.y ), &ignore_); break; case FontAlignHorizontal::Left: default: - m_pTextRenderer->drawText(u8_str, vRenderPos, &ignore_); + m_text_renderer->drawText(u8_str, vRenderPos, &ignore_); break; } @@ -309,48 +309,48 @@ namespace luastg spdlog::error("[luastg] SetFontProvider: 找不到字体资源'{}'", name); return false; } - m_pTextRenderer->setGlyphManager(p->GetGlyphManager()); + m_text_renderer->setGlyphManager(p->GetGlyphManager()); return true; } void AppFrame::FontRenderer_SetScale(core::Vector2F const& s) { - m_pTextRenderer->setScale(s); + m_text_renderer->setScale(s); } core::RectF AppFrame::FontRenderer_MeasureTextBoundary(const char* str, size_t len) { - return m_pTextRenderer->getTextBoundary(core::StringView(str, len)); + return m_text_renderer->getTextBoundary(core::StringView(str, len)); } core::Vector2F AppFrame::FontRenderer_MeasureTextAdvance(const char* str, size_t len) { - return m_pTextRenderer->getTextAdvance(core::StringView(str, len)); + return m_text_renderer->getTextAdvance(core::StringView(str, len)); } bool AppFrame::FontRenderer_RenderText(const char* str, size_t len, core::Vector2F& pos, const float z, const BlendMode blend, core::Color4B const& color) { - float const last_z = m_pTextRenderer->getZ(); + float const last_z = m_text_renderer->getZ(); updateGraph2DBlendMode(blend); - m_pTextRenderer->setZ(z); - m_pTextRenderer->setColor(color); + m_text_renderer->setZ(z); + m_text_renderer->setColor(color); core::Vector2F endpos; - const bool result = m_pTextRenderer->drawText(core::StringView(str, len), pos, &endpos); + const bool result = m_text_renderer->drawText(core::StringView(str, len), pos, &endpos); pos = endpos; - m_pTextRenderer->setZ(last_z); + m_text_renderer->setZ(last_z); return result; } bool AppFrame::FontRenderer_RenderTextInSpace(const char* str, size_t len, core::Vector3F& pos, core::Vector3F const& rvec, core::Vector3F const& dvec, const BlendMode blend, core::Color4B const& color) { updateGraph2DBlendMode(blend); - m_pTextRenderer->setColor(color); + m_text_renderer->setColor(color); core::Vector3F endpos; - const bool result = m_pTextRenderer->drawTextInSpace( + const bool result = m_text_renderer->drawTextInSpace( core::StringView(str, len), pos, rvec, @@ -363,21 +363,21 @@ namespace luastg float AppFrame::FontRenderer_GetFontLineHeight() { - auto* p = m_pTextRenderer->getGlyphManager(); + auto* p = m_text_renderer->getGlyphManager(); if (p) return p->getLineHeight(); return 0.0f; } float AppFrame::FontRenderer_GetFontAscender() { - auto* p = m_pTextRenderer->getGlyphManager(); + auto* p = m_text_renderer->getGlyphManager(); if (p) return p->getAscender(); return 0.0f; } float AppFrame::FontRenderer_GetFontDescender() { - auto* p = m_pTextRenderer->getGlyphManager(); + auto* p = m_text_renderer->getGlyphManager(); if (p) return p->getDescender(); return 0.0f; } diff --git a/LuaSTG/LuaSTG/AppFrameInput.cpp b/LuaSTG/LuaSTG/AppFrameInput.cpp index b350a440..9d40d3bc 100644 --- a/LuaSTG/LuaSTG/AppFrameInput.cpp +++ b/LuaSTG/LuaSTG/AppFrameInput.cpp @@ -4,14 +4,14 @@ #define NOMINMAX #include #include "Mouse.h" -#include "Platform/Keyboard.hpp" +#include "windows/Keyboard.hpp" namespace { Platform::Keyboard g_Keyboard; Platform::Keyboard::State g_KeyboardState; - struct InputEventListener : public core::Graphics::IWindowEventListener { + struct InputEventListener : public core::IWindowEventListener { NativeWindowMessageResult onNativeWindowMessage(void* window, uint32_t message, uintptr_t arg1, intptr_t arg2) { switch (message) { case WM_ACTIVATE: @@ -58,12 +58,12 @@ namespace luastg g_Keyboard.Reset(); Mouse = std::make_unique(); ZeroMemory(&MouseState, sizeof(MouseState)); - m_pAppModel->getWindow()->addEventListener(&g_InputEventListener); - Mouse->SetWindow((HWND)m_pAppModel->getWindow()->getNativeHandle()); + m_window->addEventListener(&g_InputEventListener); + Mouse->SetWindow((HWND)m_window->getNativeHandle()); } void AppFrame::CloseInput() { - m_pAppModel->getWindow()->removeEventListener(&g_InputEventListener); + m_window->removeEventListener(&g_InputEventListener); Mouse = nullptr; } void AppFrame::UpdateInput() @@ -152,7 +152,7 @@ namespace luastg } core::Vector2F AppFrame::GetMousePosition(bool no_flip)noexcept { - auto const c_size = GetAppModel()->getSwapChain()->getCanvasSize(); + auto const c_size = m_swap_chain->getCanvasSize(); auto const transform = GetMousePositionTransformF(); auto pos = core::Vector2F( ((float)MouseState.x + transform.x) * transform.z, @@ -166,7 +166,7 @@ namespace luastg if (m_win32_window_size.x == 0 || m_win32_window_size.y == 0) { RECT rc = {}; - GetClientRect((HWND)GetAppModel()->getWindow()->getNativeHandle(), &rc); + GetClientRect((HWND)m_window->getNativeHandle(), &rc); m_win32_window_size = core::Vector2U((uint32_t)(rc.right - rc.left), (uint32_t)(rc.bottom - rc.top)); } auto const w_size = m_win32_window_size; @@ -177,16 +177,16 @@ namespace luastg if (m_win32_window_size.x == 0 || m_win32_window_size.y == 0) { RECT rc = {}; - GetClientRect((HWND)GetAppModel()->getWindow()->getNativeHandle(), &rc); + GetClientRect((HWND)m_window->getNativeHandle(), &rc); m_win32_window_size = core::Vector2U((uint32_t)(rc.right - rc.left), (uint32_t)(rc.bottom - rc.top)); } auto const w_size = m_win32_window_size; - auto const c_size = GetAppModel()->getSwapChain()->getCanvasSize(); + auto const c_size = m_swap_chain->getCanvasSize(); float const hscale = (float)w_size.x / (float)c_size.x; float const vscale = (float)w_size.y / (float)c_size.y; - if (GetAppModel()->getSwapChain()->getScalingMode() == core::Graphics::SwapChainScalingMode::Stretch) + if (m_swap_chain->getScalingMode() == core::Graphics::SwapChainScalingMode::Stretch) { return core::Vector4F(0.0f, 0.0f, 1.0f / hscale, 1.0f / vscale); } diff --git a/LuaSTG/LuaSTG/AppFrameLua.cpp b/LuaSTG/LuaSTG/AppFrameLua.cpp index 4397e01b..64892c59 100644 --- a/LuaSTG/LuaSTG/AppFrameLua.cpp +++ b/LuaSTG/LuaSTG/AppFrameLua.cpp @@ -34,6 +34,13 @@ extern "C" { using std::string_view_literals::operator ""sv; namespace { + HWND getMainWindow(core::IWindow* const window) { + if (!window) { + return nullptr; + } + return static_cast(window->getNativeHandle()); + } + void registerCommandLineArguments(lua_State* const vm) { [[maybe_unused]] lua::stack_balancer_t const sb(vm); lua::stack_t const ctx(vm); @@ -97,7 +104,7 @@ namespace luastg { spdlog::error("[luajit] 编译'{}'失败:{}", desc, lua_tostring(L, -1)); MessageBoxW( - m_pAppModel ? (HWND)m_pAppModel->getWindow()->getNativeHandle() : NULL, + getMainWindow(m_window.get()), utf8::to_wstring( fmt::format("编译'{}'失败:{}", desc, lua_tostring(L, -1)) ).c_str(), @@ -122,7 +129,7 @@ namespace luastg } spdlog::error("[luajit] 运行'{}'时出错:{}", desc, errmsg); MessageBoxW( - m_pAppModel ? (HWND)m_pAppModel->getWindow()->getNativeHandle() : NULL, + getMainWindow(m_window.get()), utf8::to_wstring( fmt::format("运行'{}'时出错:\n{}", desc, errmsg) ).c_str(), @@ -167,7 +174,7 @@ namespace luastg } spdlog::error("[luajit] 调用全局函数'{}'时出错:{}", name, errmsg); MessageBoxW( - m_pAppModel ? (HWND)m_pAppModel->getWindow()->getNativeHandle() : NULL, + getMainWindow(m_window.get()), utf8::to_wstring( fmt::format("调用全局函数'{}'时出错:\n{}", name, errmsg) ).c_str(), @@ -202,7 +209,7 @@ namespace luastg spdlog::error("[luajit] 调用全局函数'{}'时出错:全局函数'{}'不存在", name, name); /* MessageBoxW( - m_pAppModel ? (HWND)m_pAppModel->getWindow()->getNativeHandle() : NULL, + getMainWindow(m_window.get()), tErrorInfo.c_str(), L"" LUASTG_INFO, MB_ICONERROR | MB_OK); @@ -228,7 +235,7 @@ namespace luastg { spdlog::error("[luajit] 调用全局函数'{}'时出错:{}", name, lua_tostring(L, -1)); MessageBoxW( - m_pAppModel ? (HWND)m_pAppModel->getWindow()->getNativeHandle() : NULL, + getMainWindow(m_window.get()), utf8::to_wstring( fmt::format("调用全局函数'{}'时出错:\n{}", name, lua_tostring(L, -1)) ).c_str(), diff --git a/LuaSTG/LuaSTG/AppFrameRender.cpp b/LuaSTG/LuaSTG/AppFrameRender.cpp index ddeecb4a..efee0fcb 100644 --- a/LuaSTG/LuaSTG/AppFrameRender.cpp +++ b/LuaSTG/LuaSTG/AppFrameRender.cpp @@ -4,9 +4,8 @@ namespace luastg { void AppFrame::updateGraph2DBlendMode(BlendMode const blend) { auto const [v, b] = translateLegacyBlendState(blend); - auto const renderer = m_pAppModel->getRenderer(); - renderer->setVertexColorBlendState(v); - renderer->setBlendState(b); + m_renderer->setVertexColorBlendState(v); + m_renderer->setBlendState(b); } bool AppFrame::Render(IParticlePool* p, float hscale, float vscale) noexcept { @@ -21,7 +20,7 @@ namespace luastg { } void AppFrame::SnapShot(const char* path) noexcept { - if (!GetAppModel()->getSwapChain()->saveSnapshotToFile(path)) { + if (!m_swap_chain->saveSnapshotToFile(path)) { spdlog::error("[luastg] SnapShot: 保存截图到文件'{}'失败", path); return; } diff --git a/LuaSTG/LuaSTG/AppFrameRenderEx.cpp b/LuaSTG/LuaSTG/AppFrameRenderEx.cpp index ea168d4b..111f0852 100644 --- a/LuaSTG/LuaSTG/AppFrameRenderEx.cpp +++ b/LuaSTG/LuaSTG/AppFrameRenderEx.cpp @@ -5,7 +5,7 @@ namespace luastg bool AppFrame::BeginRenderTargetStack() { m_stRenderTargetStack.clear(); - GetAppModel()->getSwapChain()->applyRenderAttachment(); + m_swap_chain->applyRenderAttachment(); return true; } bool AppFrame::EndRenderTargetStack() @@ -15,7 +15,7 @@ namespace luastg { spdlog::error("[luastg] 渲染结束时 RenderTarget 栈不为空,可能缺少对 lstg.PopRenderTarget 的调用"); m_stRenderTargetStack.clear(); - GetAppModel()->getSwapChain()->applyRenderAttachment(); + m_swap_chain->applyRenderAttachment(); } return true; } @@ -32,7 +32,7 @@ namespace luastg return false; } - GetRenderer2D()->setRenderAttachment( + getRenderer2D()->setRenderAttachment( rt->GetRenderTarget(), rt->GetDepthStencilBuffer() ); @@ -60,14 +60,14 @@ namespace luastg if (!m_stRenderTargetStack.empty()) { IResourceTexture* rt = *(m_stRenderTargetStack.back()); - GetRenderer2D()->setRenderAttachment( + getRenderer2D()->setRenderAttachment( rt->GetRenderTarget(), rt->GetDepthStencilBuffer() ); } else { - GetAppModel()->getSwapChain()->applyRenderAttachment(); + m_swap_chain->applyRenderAttachment(); } return true; @@ -91,7 +91,7 @@ namespace luastg } else { - return GetAppModel()->getSwapChain()->getCanvasSize(); + return m_swap_chain->getCanvasSize(); } } @@ -112,7 +112,7 @@ namespace luastg if (m_AutoSizeRenderTargetSize.x == 0 || m_AutoSizeRenderTargetSize.y == 0) { // 初始化 - m_AutoSizeRenderTargetSize = GetAppModel()->getSwapChain()->getCanvasSize(); + m_AutoSizeRenderTargetSize = m_swap_chain->getCanvasSize(); } return m_AutoSizeRenderTargetSize; } @@ -132,7 +132,7 @@ namespace luastg void AppFrame::onSwapChainCreate() { - ResizeAutoSizeRenderTarget(GetAppModel()->getSwapChain()->getCanvasSize()); + ResizeAutoSizeRenderTarget(m_swap_chain->getCanvasSize()); } void AppFrame::onSwapChainDestroy() {} @@ -147,7 +147,7 @@ namespace luastg void AppFrame::DebugSetGeometryRenderState() { using namespace core::Graphics; - auto* r2d = GetRenderer2D(); + auto* r2d = getRenderer2D(); r2d->setBlendState(IRenderer::BlendState::Alpha); r2d->setDepthState(IRenderer::DepthState::Disable); r2d->setFogState(IRenderer::FogState::Disable, {}, 0.0f, 0.0f); @@ -160,7 +160,7 @@ namespace luastg { using namespace core; using namespace core::Graphics; - auto* r2d = GetRenderer2D(); + auto* r2d = getRenderer2D(); // 分割 32 份,圆周上 32 个点以及中心点,共 32 个三角形,需要 32 * 3 个索引 IRenderer::DrawVertex* vert = nullptr; IRenderer::DrawIndex* vidx = nullptr; @@ -195,7 +195,7 @@ namespace luastg { using namespace core; using namespace core::Graphics; - auto* r2d = GetRenderer2D(); + auto* r2d = getRenderer2D(); // 计算出矩形的4个顶点 IRenderer::DrawVertex vert[4] = { IRenderer::DrawVertex(-a, -b, 0.5f, 0.0f, 0.0f, color.color()), @@ -223,7 +223,7 @@ namespace luastg { using namespace core; using namespace core::Graphics; - auto* r2d = GetRenderer2D(); + auto* r2d = getRenderer2D(); // 分割 36 份,椭圆周上 36 个点以及中心点,共 36 个三角形,需要 36 * 3 个索引 IRenderer::DrawVertex* vert = nullptr; IRenderer::DrawIndex* vidx = nullptr; diff --git a/LuaSTG/LuaSTG/Custom/AppFrameLuaEx.cpp b/LuaSTG/LuaSTG/Custom/AppFrameLuaEx.cpp index 7ca4d015..cea81589 100644 --- a/LuaSTG/LuaSTG/Custom/AppFrameLuaEx.cpp +++ b/LuaSTG/LuaSTG/Custom/AppFrameLuaEx.cpp @@ -6,12 +6,16 @@ #include #include -#include "Platform/HResultChecker.hpp" +namespace { + using std::string_view_literals::operator""sv; + using std::string_literals::operator""s; -using std::string_view_literals::operator""sv; -using std::string_literals::operator""s; + const std::string_view entry_scripts[3] = { + "core.lua"sv, + "main.lua"sv, + "src/main.lua"sv, + }; -namespace { constexpr bool not_space(const char c) { switch (c) { case '\t': case '\n': case '\v': case '\f': case '\r': case ' ': @@ -74,33 +78,20 @@ namespace luastg { #endif return true; }; - - bool AppFrame::OnLoadMainScriptAndFiles() - { - spdlog::info("[luastg] 加载入口点脚本"); - std::string_view entry_scripts[3] = { - "core.lua", - "main.lua", - "src/main.lua", - }; + + bool AppFrame::OnLoadMainScriptAndFiles() { + core::Logger::info("[luastg] loading main script"); core::SmartReference src; - bool is_load = false; - for (auto& v : entry_scripts) - { - if (core::FileSystemManager::readFile(v, src.put())) - { - if (SafeCallScript((char const*)src->data(), src->size(), v.data())) - { - spdlog::info("[luastg] 加载脚本'{}'", v); - is_load = true; - break; - } + for (const auto& path : entry_scripts) { + if (!core::FileSystemManager::readFile(path, src.put())) { + continue; + } + if (SafeCallScript(static_cast(src->data()), src->size(), path.data())) { + core::Logger::info("[luastg] main script '{}' loaded", path); + return true; } } - if (!is_load) - { - spdlog::error("[luastg] 找不到文件'{}'、'{}'或'{}'", entry_scripts[0], entry_scripts[1], entry_scripts[2]); - } - return true; + core::Logger::error("[luastg] main script not found"); + return false; } } diff --git a/LuaSTG/LuaSTG/Debugger/FrameQuery.cpp b/LuaSTG/LuaSTG/Debugger/FrameQuery.cpp new file mode 100644 index 00000000..f7af8c67 --- /dev/null +++ b/LuaSTG/LuaSTG/Debugger/FrameQuery.cpp @@ -0,0 +1,165 @@ +#include "Debugger/FrameQuery.hpp" +#include "core/SmartReference.hpp" +#include "win32/base.hpp" +#include +#include + +namespace luastg { + struct FrameQuery::Impl : public core::IGraphicsDeviceEventListener { + public: + // IGraphicsDeviceEventListener + + void onGraphicsDeviceCreate() override { + createResources(static_cast(m_device->getNativeHandle())); + } + void onGraphicsDeviceDestroy() override { + destroyResources(); + } + + // FrameQuery + + bool createResources(ID3D11Device* const device) { + assert(device); + d3d11_device = device; + d3d11_device->GetImmediateContext(d3d11_device_context.put()); + D3D11_QUERY_DESC d3d11_query_info{}; + d3d11_query_info.Query = D3D11_QUERY_TIMESTAMP_DISJOINT; + if (S_OK != d3d11_device->CreateQuery(&d3d11_query_info, d3d11_query_freq.put())) { + return false; + } + d3d11_query_info.Query = D3D11_QUERY_TIMESTAMP; + if (S_OK != d3d11_device->CreateQuery(&d3d11_query_info, d3d11_query_time_begin.put())) { + return false; + } + if (S_OK != d3d11_device->CreateQuery(&d3d11_query_info, d3d11_query_time_end.put())) { + return false; + } + d3d11_query_info.Query = D3D11_QUERY_PIPELINE_STATISTICS; + if (S_OK != d3d11_device->CreateQuery(&d3d11_query_info, d3d11_query_statistics.put())) { + return false; + } + is_flying = false; + is_scope = false; + return true; + } + void destroyResources() { + d3d11_query_freq.reset(); + d3d11_query_time_begin.reset(); + d3d11_query_time_end.reset(); + d3d11_query_statistics.reset(); + is_flying = false; + is_scope = false; + } + void fetchData() { + assert(d3d11_device_context); + assert(d3d11_query_freq); + assert(d3d11_query_time_begin); + assert(d3d11_query_time_end); + assert(d3d11_query_statistics); + if (!is_flying) { + return; + } + if (d3d11_query_freq) { + while (S_OK != d3d11_device_context->GetData(d3d11_query_freq.get(), &freq, sizeof(freq), 0)) { + ; + } + } + if (d3d11_query_time_begin) { + while (S_OK != d3d11_device_context->GetData(d3d11_query_time_begin.get(), &time_begin, sizeof(time_begin), 0)) { + ; + } + } + if (d3d11_query_time_end) { + while (S_OK != d3d11_device_context->GetData(d3d11_query_time_end.get(), &time_end, sizeof(time_end), 0)) { + ; + } + } + if (d3d11_query_statistics) { + while (S_OK != d3d11_device_context->GetData(d3d11_query_statistics.get(), &statistics, sizeof(statistics), 0)) { + ; + } + } + is_flying = false; + } + double getTime() { + if (freq.Frequency == 0) { + return 0.0; + } + return double(time_end - time_begin) / double(freq.Frequency); + } + void begin() { + if (is_flying) { + fetchData(); + } + assert(!is_flying); + assert(!is_scope); + is_scope = true; + assert(d3d11_device_context); + assert(d3d11_query_freq); + assert(d3d11_query_time_begin); + assert(d3d11_query_statistics); + if (d3d11_query_freq) { + d3d11_device_context->Begin(d3d11_query_freq.get()); + } + if (d3d11_query_time_begin) { + d3d11_device_context->End(d3d11_query_time_begin.get()); // timestamp End only + } + if (d3d11_query_statistics) { + d3d11_device_context->Begin(d3d11_query_statistics.get()); + } + } + void end() { + assert(d3d11_device_context); + assert(d3d11_query_freq); + assert(d3d11_query_time_end); + assert(d3d11_query_statistics); + assert(is_scope); + if (d3d11_query_freq) { + d3d11_device_context->End(d3d11_query_freq.get()); + } + if (d3d11_query_time_end) { + d3d11_device_context->End(d3d11_query_time_end.get()); // timestamp End only + } + if (d3d11_query_statistics) { + d3d11_device_context->End(d3d11_query_statistics.get()); + } + is_scope = false; + is_flying = true; + } + + Impl(core::IGraphicsDevice* device) : m_device(device) { + createResources(static_cast(m_device->getNativeHandle())); + m_device->addEventListener(this); + } + ~Impl() { + m_device->removeEventListener(this); + } + + private: + core::SmartReference m_device; + win32::com_ptr d3d11_device; + win32::com_ptr d3d11_device_context; + win32::com_ptr d3d11_query_freq; + win32::com_ptr d3d11_query_time_begin; + win32::com_ptr d3d11_query_time_end; + win32::com_ptr d3d11_query_statistics; + D3D11_QUERY_DATA_TIMESTAMP_DISJOINT freq{}; + UINT64 time_begin{}; + UINT64 time_end{}; + D3D11_QUERY_DATA_PIPELINE_STATISTICS statistics{}; + bool is_flying{}; + bool is_scope{}; + }; + + void FrameQuery::fetchData() { m_impl->fetchData(); } + double FrameQuery::getTime() { return m_impl->getTime(); } + void FrameQuery::begin() { m_impl->begin(); } + void FrameQuery::end() { m_impl->end(); } + + FrameQuery::FrameQuery(core::IGraphicsDevice* device) { + m_impl = new Impl(device); + } + FrameQuery::~FrameQuery() { + delete m_impl; + } +} diff --git a/LuaSTG/LuaSTG/Debugger/FrameQuery.hpp b/LuaSTG/LuaSTG/Debugger/FrameQuery.hpp new file mode 100644 index 00000000..cb8e8950 --- /dev/null +++ b/LuaSTG/LuaSTG/Debugger/FrameQuery.hpp @@ -0,0 +1,19 @@ +#pragma once +#include "core/GraphicsDevice.hpp" + +namespace luastg { + class FrameQuery { + public: + void fetchData(); + double getTime(); + void begin(); + void end(); + + FrameQuery(core::IGraphicsDevice* device); + ~FrameQuery(); + + private: + struct Impl; + Impl* m_impl{}; + }; +} diff --git a/LuaSTG/LuaSTG/Debugger/ImGuiExtension.cpp b/LuaSTG/LuaSTG/Debugger/ImGuiExtension.cpp index fdef8ca0..f45dcb64 100644 --- a/LuaSTG/LuaSTG/Debugger/ImGuiExtension.cpp +++ b/LuaSTG/LuaSTG/Debugger/ImGuiExtension.cpp @@ -16,7 +16,7 @@ #include "lua.hpp" #include "lua_imgui.hpp" -#include "Platform/XInput.hpp" +#include "windows/XInput.hpp" #include "core/Configuration.hpp" #include "utf8.hpp" @@ -135,7 +135,7 @@ namespace imgui { ImGui::Text("Lua Virtual Machine: %s", format_size(size)); } if (ImGui::CollapsingHeader("Graphics", ImGuiTreeNodeFlags_DefaultOpen)) { - auto const info = LAPP.GetAppModel()->getDevice()->getMemoryUsageStatistics(); + auto const info = LAPP.getGraphicsDevice()->getMemoryStatistics(); if (m_more_details) ImGui::Text("Local Budget: %s", format_size(info.local.budget)); ImGui::Text("Local Current Usage: %s", format_size(info.local.current_usage)); if (m_more_details) ImGui::Text("Local Available For Reservation: %s", format_size(info.local.available_for_reservation)); @@ -440,7 +440,7 @@ namespace { // frame time if (ImGui::CollapsingHeader("Frame Time")) { - auto info = LAPP.GetAppModel()->getFrameStatistics(); + auto info = LAPP.getFrameStatistics(); ImGui::Text("Wait : %.3fms", info.wait_time * 1000.0); ImGui::Text("Update : %.3fms", info.update_time * 1000.0); @@ -506,7 +506,7 @@ namespace { // gpu time if (ImGui::CollapsingHeader("GPU Time")) { - auto info = LAPP.GetAppModel()->getFrameRenderStatistics(); + auto info = LAPP.getFrameRenderStatistics(); ImGui::Text("Render : %.3fms", info.render_time * 1000.0); @@ -557,7 +557,7 @@ namespace { if (ImGui::CollapsingHeader("Memory Usage")) { MEMORYSTATUSEX mem_info = { sizeof(MEMORYSTATUSEX) }; GlobalMemoryStatusEx(&mem_info); - auto gpu_info = LAPP.GetAppModel()->getDevice()->getMemoryUsageStatistics(); + auto gpu_info = LAPP.getGraphicsDevice()->getMemoryStatistics(); lua_State* L_ = LAPP.GetLuaEngine(); int lua_infokb = lua_gc(L_, LUA_GCCOUNT, 0); int lua_infob = lua_gc(L_, LUA_GCCOUNTB, 0); @@ -727,18 +727,18 @@ namespace { namespace imgui { class ImGuiBackendEventListener - : public core::Graphics::IDeviceEventListener - , public core::Graphics::IWindowEventListener { + : public core::IGraphicsDeviceEventListener + , public core::IWindowEventListener { public: - // IDeviceEventListener + // IGraphicsDeviceEventListener - void onDeviceDestroy() override { + void onGraphicsDeviceDestroy() override { g_imgui_impl_dx11_initialized = false; ImGui_ImplDX11_Shutdown(); } - void onDeviceCreate() override { + void onGraphicsDeviceCreate() override { g_imgui_impl_dx11_initialized = false; - auto const device = static_cast(LAPP.GetAppModel()->getDevice()->getNativeHandle()); + auto const device = static_cast(LAPP.getGraphicsDevice()->getNativeHandle()); ID3D11DeviceContext* context{}; device->GetImmediateContext(&context); ImGui_ImplDX11_Init(device, context); @@ -748,7 +748,7 @@ namespace imgui { // IWindowEventListener void onWindowCreate() override { - ImGui_ImplWin32Ex_Init(LAPP.GetAppModel()->getWindow()->getNativeHandle()); + ImGui_ImplWin32Ex_Init(LAPP.getWindow()->getNativeHandle()); } void onWindowDestroy() override { ImGui_ImplWin32Ex_Shutdown(); @@ -834,10 +834,8 @@ namespace { style.FrameBorderSize = 1.0f; style.TabBorderSize = 1.0f; - if (auto const framework = LAPP.GetAppModel()) { - style.FontScaleDpi = framework->getWindow()->getDPIScaling(); - style.ScaleAllSizes(framework->getWindow()->getDPIScaling()); - } + style.FontScaleDpi = LAPP.getWindow()->getDPIScaling(); + style.ScaleAllSizes(LAPP.getWindow()->getDPIScaling()); ImGui::GetStyle() = style; } @@ -858,11 +856,11 @@ namespace imgui { applyStyle(); g_imgui_backend_event_listener.onWindowCreate(); - auto const window = LAPP.GetAppModel()->getWindow(); + auto const window = LAPP.getWindow(); window->addEventListener(&g_imgui_backend_event_listener); - g_imgui_backend_event_listener.onDeviceCreate(); - auto const device = LAPP.GetAppModel()->getDevice(); + g_imgui_backend_event_listener.onGraphicsDeviceCreate(); + auto const device = LAPP.getGraphicsDevice(); device->addEventListener(&g_imgui_backend_event_listener); auto const vm = LAPP.GetLuaEngine(); @@ -873,17 +871,19 @@ namespace imgui { g_imgui_initialized = true; } void unbindEngine() { - if (LAPP.GetAppModel()) { - auto const device = LAPP.GetAppModel()->getDevice(); + if (const auto device = LAPP.getGraphicsDevice(); device != nullptr) { device->removeEventListener(&g_imgui_backend_event_listener); - g_imgui_backend_event_listener.onDeviceDestroy(); + g_imgui_backend_event_listener.onGraphicsDeviceDestroy(); + } + else { + g_imgui_backend_event_listener.onGraphicsDeviceDestroy(); + } - auto const window = LAPP.GetAppModel()->getWindow(); + if (const auto window = LAPP.getWindow(); window != nullptr) { window->removeEventListener(&g_imgui_backend_event_listener); g_imgui_backend_event_listener.onWindowDestroy(); } else { - g_imgui_backend_event_listener.onDeviceDestroy(); g_imgui_backend_event_listener.onWindowDestroy(); } @@ -919,7 +919,7 @@ namespace imgui { { tracy_zone_scoped_with_name("imgui.backend.NewFrame-WIN32"); - auto const ws = LAPP.GetAppModel()->getSwapChain()->getCanvasSize(); + auto const ws = LAPP.getSwapChain()->getCanvasSize(); auto const mt = LAPP.GetMousePositionTransformF(); ImGui_ImplWin32Ex_FrameData dt; dt.view_size.x = static_cast(ws.x); @@ -940,9 +940,9 @@ namespace imgui { } void drawEngine() { if (g_imgui_initialized && g_imgui_impl_dx11_initialized) { - LAPP.GetAppModel()->getRenderer()->endBatch(); + LAPP.getRenderer2D()->endBatch(); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); - LAPP.GetAppModel()->getRenderer()->beginBatch(); // restore + LAPP.getRenderer2D()->beginBatch(); // restore } } diff --git a/LuaSTG/LuaSTG/Debugger/Logger.cpp b/LuaSTG/LuaSTG/Debugger/Logger.cpp index e91372ca..2b53487e 100644 --- a/LuaSTG/LuaSTG/Debugger/Logger.cpp +++ b/LuaSTG/LuaSTG/Debugger/Logger.cpp @@ -5,7 +5,7 @@ #include "spdlog/sinks/stdout_sinks.h" #include "spdlog/sinks/wincolor_sink.h" #include "spdlog/sinks/msvc_sink.h" -#include "Platform/HResultChecker.hpp" +#include "windows/HResultChecker.hpp" #include "core/Configuration.hpp" #include "utf8.hpp" #include "win32/base.hpp" @@ -187,7 +187,7 @@ namespace luastg { }; #include -#include "Platform/CleanWindows.hpp" +#include "windows/CleanWindows.hpp" namespace { bool redirectStdOut() { diff --git a/LuaSTG/LuaSTG/GameObject/GameObject.hpp b/LuaSTG/LuaSTG/GameObject/GameObject.hpp index 16a497e6..7d1f3509 100644 --- a/LuaSTG/LuaSTG/GameObject/GameObject.hpp +++ b/LuaSTG/LuaSTG/GameObject/GameObject.hpp @@ -39,7 +39,7 @@ namespace luastg { struct GameObject; // 游戏对象回调函数集和调用链 - struct CORE_NO_VIRTUAL_TABLE IGameObjectCallbacks { + CORE_INTERFACE IGameObjectCallbacks { // 获取当前回调函数集的名称 virtual std::string_view getCallbacksName(GameObject* self) const noexcept = 0; // 被标记为删除状态时调用 diff --git a/LuaSTG/LuaSTG/GameObject/GameObjectBentLaser.cpp b/LuaSTG/LuaSTG/GameObject/GameObjectBentLaser.cpp index 05ec7a3b..703e5a44 100644 --- a/LuaSTG/LuaSTG/GameObject/GameObjectBentLaser.cpp +++ b/LuaSTG/LuaSTG/GameObject/GameObjectBentLaser.cpp @@ -453,9 +453,9 @@ bool GameObjectBentLaser::Render(const char* tex_name, BlendMode blend, core::Co } // 设置纹理、混合模式等 - auto* p_renderer = LAPP.GetAppModel()->getRenderer(); + const auto renderer = LAPP.getRenderer2D(); LAPP.updateGraph2DBlendMode(blend); - p_renderer->setTexture(pTex->GetTexture()); + renderer->setTexture(pTex->GetTexture()); // 分配顶点和索引 // 顶点总共需要:节点数 * 2 @@ -465,7 +465,7 @@ bool GameObjectBentLaser::Render(const char* tex_name, BlendMode blend, core::Co IRenderer::DrawVertex* p_vertex = nullptr; IRenderer::DrawIndex* p_index = nullptr; uint16_t index_offset = 0; - if (!p_renderer->drawRequest( + if (!renderer->drawRequest( node_count * 2, (node_count - 1) * 6, &p_vertex, diff --git a/LuaSTG/LuaSTG/GameObject/GameObjectPool.h b/LuaSTG/LuaSTG/GameObject/GameObjectPool.h index ff3bea86..89a53c92 100644 --- a/LuaSTG/LuaSTG/GameObject/GameObjectPool.h +++ b/LuaSTG/LuaSTG/GameObject/GameObjectPool.h @@ -120,7 +120,7 @@ namespace luastg using GameObjectDetectLinkedList = GameObjectLinkedList; // 游戏对象管理器回调函数集 - struct CORE_NO_VIRTUAL_TABLE IGameObjectManagerCallbacks { + CORE_INTERFACE IGameObjectManagerCallbacks { // 获取当前回调函数集的名称 [[nodiscard]] virtual std::string_view getCallbacksName() const noexcept = 0; // 对象管理器分配对象 diff --git a/LuaSTG/LuaSTG/GameResource/Implement/ResourceAnimationImpl.cpp b/LuaSTG/LuaSTG/GameResource/Implement/ResourceAnimationImpl.cpp index aacb1697..5f3f5f79 100644 --- a/LuaSTG/LuaSTG/GameResource/Implement/ResourceAnimationImpl.cpp +++ b/LuaSTG/LuaSTG/GameResource/Implement/ResourceAnimationImpl.cpp @@ -96,7 +96,7 @@ namespace luastg renderer->setLegacyBlendState(blend.vertex_color_blend_state, blend.blend_state); renderer->setColor(m_vertex_color[0], m_vertex_color[1], m_vertex_color[2], m_vertex_color[3]); - renderer->draw(LAPP.GetRenderer2D()); + renderer->draw(LAPP.getRenderer2D()); renderer->setSprite(nullptr); } @@ -112,7 +112,7 @@ namespace luastg renderer->setLegacyBlendState(blend.vertex_color_blend_state, blend.blend_state); renderer->setColor(color); - renderer->draw(LAPP.GetRenderer2D()); + renderer->draw(LAPP.getRenderer2D()); renderer->setSprite(nullptr); } diff --git a/LuaSTG/LuaSTG/GameResource/Implement/ResourceFontImpl.cpp b/LuaSTG/LuaSTG/GameResource/Implement/ResourceFontImpl.cpp index 7853fc14..e2937e20 100644 --- a/LuaSTG/LuaSTG/GameResource/Implement/ResourceFontImpl.cpp +++ b/LuaSTG/LuaSTG/GameResource/Implement/ResourceFontImpl.cpp @@ -309,7 +309,7 @@ namespace luastg // 加载纹理 if (core::FileSystemManager::hasFile(texture)) { - if (!LAPP.GetAppModel()->getDevice()->createTextureFromFile(texture, mipmap, m_texture.put())) + if (!LAPP.getGraphicsDevice()->createTextureFromFile(texture, mipmap, m_texture.put())) { spdlog::error("[luastg] 加载 HGE 纹理字体失败,无法加载纹理 '{}'", texture); throw std::runtime_error("hgeFont::hgeFont"); @@ -322,7 +322,7 @@ namespace luastg wide_path.remove_filename(); wide_path /= utf8::to_wstring(texture); std::string texture_path(utf8::to_string(wide_path.wstring())); - if (!LAPP.GetAppModel()->getDevice()->createTextureFromFile(texture_path, mipmap, m_texture.put())) + if (!LAPP.getGraphicsDevice()->createTextureFromFile(texture_path, mipmap, m_texture.put())) { spdlog::error("[luastg] 加载 HGE 纹理字体失败,无法加载纹理 '{}'", texture_path); throw std::runtime_error("hgeFont::hgeFont"); @@ -472,7 +472,7 @@ namespace luastg // 加载纹理 if (core::FileSystemManager::hasFile(raw_texture_path)) { - if (!LAPP.GetAppModel()->getDevice()->createTextureFromFile(raw_texture_path, mipmap, m_texture.put())) + if (!LAPP.getGraphicsDevice()->createTextureFromFile(raw_texture_path, mipmap, m_texture.put())) { spdlog::error("[luastg] 加载 fancy2d 纹理字体失败,无法加载纹理 '{}'", raw_texture_path); throw std::runtime_error("f2dFont::f2dFont"); @@ -485,7 +485,7 @@ namespace luastg wide_path.remove_filename(); wide_path /= utf8::to_wstring(raw_texture_path); std::string texture_path(utf8::to_string(wide_path.wstring())); - if (!LAPP.GetAppModel()->getDevice()->createTextureFromFile(texture_path, mipmap, m_texture.put())) + if (!LAPP.getGraphicsDevice()->createTextureFromFile(texture_path, mipmap, m_texture.put())) { spdlog::error("[luastg] 加载 fancy2d 纹理字体失败,无法加载纹理 '{}'", texture_path); throw std::runtime_error("f2dFont::f2dFont"); diff --git a/LuaSTG/LuaSTG/GameResource/Implement/ResourceModelImpl.cpp b/LuaSTG/LuaSTG/GameResource/Implement/ResourceModelImpl.cpp index eab30345..bd9c5dd4 100644 --- a/LuaSTG/LuaSTG/GameResource/Implement/ResourceModelImpl.cpp +++ b/LuaSTG/LuaSTG/GameResource/Implement/ResourceModelImpl.cpp @@ -6,7 +6,7 @@ namespace luastg ResourceModelImpl::ResourceModelImpl(const char* name, const char* path) : ResourceBaseImpl(ResourceType::Model, name) { - if (!LAPP.GetAppModel()->getRenderer()->createModel(path, model_.put())) + if (!LAPP.getRenderer2D()->createModel(path, model_.put())) throw std::runtime_error("ResourceModelImpl::ResourceModelImpl"); } } diff --git a/LuaSTG/LuaSTG/GameResource/Implement/ResourceParticleImpl.cpp b/LuaSTG/LuaSTG/GameResource/Implement/ResourceParticleImpl.cpp index 6eeaa9dd..d6922364 100644 --- a/LuaSTG/LuaSTG/GameResource/Implement/ResourceParticleImpl.cpp +++ b/LuaSTG/LuaSTG/GameResource/Implement/ResourceParticleImpl.cpp @@ -263,7 +263,7 @@ namespace luastg core::Color4B const tVertexColor = GetVertexColor(); const auto sprite = m_Info.pSprite.get(); const auto renderer = SharedSpriteRenderer::getInstance(); - const auto command_list = LAPP.GetRenderer2D(); + const auto command_list = LAPP.getRenderer2D(); const auto blend = luastg::translateLegacyBlendState(m_Info.eBlendMode); renderer->setSprite(sprite); diff --git a/LuaSTG/LuaSTG/GameResource/Implement/ResourceParticleImpl.hpp b/LuaSTG/LuaSTG/GameResource/Implement/ResourceParticleImpl.hpp index 1f3c0d75..66d96fc7 100644 --- a/LuaSTG/LuaSTG/GameResource/Implement/ResourceParticleImpl.hpp +++ b/LuaSTG/LuaSTG/GameResource/Implement/ResourceParticleImpl.hpp @@ -2,7 +2,7 @@ #include "core/SmartReference.hpp" #include "GameResource/ResourceParticle.hpp" #include "GameResource/Implement/ResourceBaseImpl.hpp" -#include "Core/Graphics/Sprite.hpp" +#include "core/Graphics/Sprite.hpp" #include "Utility/xorshift.hpp" #define LPARTICLE_MAXCNT 500 // 单个粒子池最多有500个粒子,这是HGE粒子特效的实现,不应该修改 diff --git a/LuaSTG/LuaSTG/GameResource/Implement/ResourcePostEffectShaderImpl.cpp b/LuaSTG/LuaSTG/GameResource/Implement/ResourcePostEffectShaderImpl.cpp index c9fe8fd6..6783bad0 100644 --- a/LuaSTG/LuaSTG/GameResource/Implement/ResourcePostEffectShaderImpl.cpp +++ b/LuaSTG/LuaSTG/GameResource/Implement/ResourcePostEffectShaderImpl.cpp @@ -6,6 +6,6 @@ namespace luastg ResourcePostEffectShaderImpl::ResourcePostEffectShaderImpl(const char* name, const char* path) : ResourceBaseImpl(ResourceType::FX, name) { - LAPP.GetAppModel()->getRenderer()->createPostEffectShader(path, m_shader.put()); + LAPP.getRenderer2D()->createPostEffectShader(path, m_shader.put()); } } diff --git a/LuaSTG/LuaSTG/GameResource/Implement/ResourceSpriteImpl.cpp b/LuaSTG/LuaSTG/GameResource/Implement/ResourceSpriteImpl.cpp index 24b1d11a..3ef99cc2 100644 --- a/LuaSTG/LuaSTG/GameResource/Implement/ResourceSpriteImpl.cpp +++ b/LuaSTG/LuaSTG/GameResource/Implement/ResourceSpriteImpl.cpp @@ -25,7 +25,7 @@ namespace luastg renderer->setLegacyBlendState(blend.vertex_color_blend_state, blend.blend_state); renderer->setColor(m_color[0], m_color[1], m_color[2], m_color[3]); - renderer->draw(LAPP.GetRenderer2D()); + renderer->draw(LAPP.getRenderer2D()); renderer->setSprite(nullptr); } @@ -40,7 +40,7 @@ namespace luastg renderer->setLegacyBlendState(blend.vertex_color_blend_state, blend.blend_state); renderer->setColor(m_color[0], m_color[1], m_color[2], m_color[3]); - renderer->draw(LAPP.GetRenderer2D()); + renderer->draw(LAPP.getRenderer2D()); renderer->setSprite(nullptr); } @@ -55,7 +55,7 @@ namespace luastg renderer->setLegacyBlendState(blend.vertex_color_blend_state, blend.blend_state); renderer->setColor(color); - renderer->draw(LAPP.GetRenderer2D()); + renderer->draw(LAPP.getRenderer2D()); renderer->setSprite(nullptr); } @@ -74,7 +74,7 @@ namespace luastg renderer->setLegacyBlendState(blend.vertex_color_blend_state, blend.blend_state); renderer->setColor(m_color[0], m_color[1], m_color[2], m_color[3]); - renderer->draw(LAPP.GetRenderer2D()); + renderer->draw(LAPP.getRenderer2D()); renderer->setSprite(nullptr); } diff --git a/LuaSTG/LuaSTG/GameResource/Implement/ResourceTextureImpl.cpp b/LuaSTG/LuaSTG/GameResource/Implement/ResourceTextureImpl.cpp index b98fde39..21e1799d 100644 --- a/LuaSTG/LuaSTG/GameResource/Implement/ResourceTextureImpl.cpp +++ b/LuaSTG/LuaSTG/GameResource/Implement/ResourceTextureImpl.cpp @@ -7,7 +7,7 @@ namespace luastg { if (!m_rt) { - if (!LAPP.GetAppModel()->getDevice()->createRenderTarget(size, m_rt.put())) + if (!LAPP.getGraphicsDevice()->createRenderTarget(size, m_rt.put())) { return false; } @@ -25,7 +25,7 @@ namespace luastg { if (!m_ds) { - if (!LAPP.GetAppModel()->getDevice()->createDepthStencilBuffer(size, m_ds.put())) + if (!LAPP.getGraphicsDevice()->createDepthStencilBuffer(size, m_ds.put())) { return false; } @@ -84,7 +84,7 @@ namespace luastg } namespace luastg { - RenderTargetStackResourceTextureImpl::RenderTargetStackResourceTextureImpl(core::Graphics::IRenderTarget* const rt, core::Graphics::IDepthStencilBuffer* const ds) : m_rt(rt), m_ds(ds) { + RenderTargetStackResourceTextureImpl::RenderTargetStackResourceTextureImpl(core::Graphics::IRenderTarget* const rt, core::IDepthStencilBuffer* const ds) : m_rt(rt), m_ds(ds) { } RenderTargetStackResourceTextureImpl::~RenderTargetStackResourceTextureImpl() = default; } diff --git a/LuaSTG/LuaSTG/GameResource/Implement/ResourceTextureImpl.hpp b/LuaSTG/LuaSTG/GameResource/Implement/ResourceTextureImpl.hpp index 6153e040..c068abdf 100644 --- a/LuaSTG/LuaSTG/GameResource/Implement/ResourceTextureImpl.hpp +++ b/LuaSTG/LuaSTG/GameResource/Implement/ResourceTextureImpl.hpp @@ -10,7 +10,7 @@ namespace luastg private: core::SmartReference m_texture; core::SmartReference m_rt; - core::SmartReference m_ds; + core::SmartReference m_ds; bool m_is_rendertarget{ false }; bool m_is_auto_resize{ false }; bool m_enable_depthbuffer{ false }; @@ -19,7 +19,7 @@ namespace luastg public: core::Graphics::ITexture2D* GetTexture() { return m_texture.get(); } core::Graphics::IRenderTarget* GetRenderTarget() { return m_rt.get(); } - core::Graphics::IDepthStencilBuffer* GetDepthStencilBuffer() { return m_ds.get(); } + core::IDepthStencilBuffer* GetDepthStencilBuffer() { return m_ds.get(); } bool IsRenderTarget() { return m_is_rendertarget; } bool HasDepthStencilBuffer() { return m_enable_depthbuffer; } public: @@ -45,13 +45,13 @@ namespace luastg core::Graphics::ITexture2D* GetTexture() override { return m_rt->getTexture(); } core::Graphics::IRenderTarget* GetRenderTarget() override { return m_rt.get(); } - core::Graphics::IDepthStencilBuffer* GetDepthStencilBuffer() override { return m_ds.get(); } + core::IDepthStencilBuffer* GetDepthStencilBuffer() override { return m_ds.get(); } bool IsRenderTarget() override { return true; } bool HasDepthStencilBuffer() override { return !!m_ds; } // RenderTargetStackResourceTextureImpl - RenderTargetStackResourceTextureImpl(core::Graphics::IRenderTarget* rt, core::Graphics::IDepthStencilBuffer* ds); + RenderTargetStackResourceTextureImpl(core::Graphics::IRenderTarget* rt, core::IDepthStencilBuffer* ds); RenderTargetStackResourceTextureImpl(RenderTargetStackResourceTextureImpl const&) = delete; RenderTargetStackResourceTextureImpl(RenderTargetStackResourceTextureImpl&&) = delete; ~RenderTargetStackResourceTextureImpl(); @@ -60,6 +60,6 @@ namespace luastg RenderTargetStackResourceTextureImpl& operator=(RenderTargetStackResourceTextureImpl&&) = delete; private: core::SmartReference m_rt; - core::SmartReference m_ds; + core::SmartReference m_ds; }; } diff --git a/LuaSTG/LuaSTG/GameResource/LegacyBlendStateHelper.hpp b/LuaSTG/LuaSTG/GameResource/LegacyBlendStateHelper.hpp index 906c4117..f89aa347 100644 --- a/LuaSTG/LuaSTG/GameResource/LegacyBlendStateHelper.hpp +++ b/LuaSTG/LuaSTG/GameResource/LegacyBlendStateHelper.hpp @@ -1,5 +1,5 @@ #pragma once -#include "Core/Graphics/Renderer.hpp" +#include "core/Graphics/Renderer.hpp" #include "GameResource/ResourceBase.hpp" namespace luastg { diff --git a/LuaSTG/LuaSTG/GameResource/ResourceAnimation.hpp b/LuaSTG/LuaSTG/GameResource/ResourceAnimation.hpp index a9e430a1..acdcf122 100644 --- a/LuaSTG/LuaSTG/GameResource/ResourceAnimation.hpp +++ b/LuaSTG/LuaSTG/GameResource/ResourceAnimation.hpp @@ -1,7 +1,7 @@ #pragma once #include "GameResource/ResourceBase.hpp" #include "GameResource/ResourceSprite.hpp" -#include "Core/Graphics/Sprite.hpp" +#include "core/Graphics/Sprite.hpp" namespace luastg { diff --git a/LuaSTG/LuaSTG/GameResource/ResourceFont.hpp b/LuaSTG/LuaSTG/GameResource/ResourceFont.hpp index 03cbb350..61f6be0d 100644 --- a/LuaSTG/LuaSTG/GameResource/ResourceFont.hpp +++ b/LuaSTG/LuaSTG/GameResource/ResourceFont.hpp @@ -1,6 +1,6 @@ #pragma once #include "GameResource/ResourceBase.hpp" -#include "Core/Graphics/Font.hpp" +#include "core/Graphics/Font.hpp" namespace luastg { diff --git a/LuaSTG/LuaSTG/GameResource/ResourceModel.hpp b/LuaSTG/LuaSTG/GameResource/ResourceModel.hpp index 463d36aa..00978a87 100644 --- a/LuaSTG/LuaSTG/GameResource/ResourceModel.hpp +++ b/LuaSTG/LuaSTG/GameResource/ResourceModel.hpp @@ -1,6 +1,6 @@ #pragma once #include "GameResource/ResourceBase.hpp" -#include "Core/Graphics/Renderer.hpp" +#include "core/Graphics/Renderer.hpp" namespace luastg { diff --git a/LuaSTG/LuaSTG/GameResource/ResourcePool.cpp b/LuaSTG/LuaSTG/GameResource/ResourcePool.cpp index 506f7c73..53ca657d 100644 --- a/LuaSTG/LuaSTG/GameResource/ResourcePool.cpp +++ b/LuaSTG/LuaSTG/GameResource/ResourcePool.cpp @@ -201,7 +201,7 @@ namespace luastg } core::SmartReference p_texture; - if (!LAPP.GetAppModel()->getDevice()->createTextureFromFile(path, mipmaps, p_texture.put())) + if (!LAPP.getGraphicsDevice()->createTextureFromFile(path, mipmaps, p_texture.put())) { spdlog::error("[luastg] 从 '{}' 创建纹理 '{}' 失败", path, name); return false; @@ -239,7 +239,7 @@ namespace luastg } core::SmartReference p_texture; - if (!LAPP.GetAppModel()->getDevice()->createTexture(core::Vector2U((uint32_t)width, (uint32_t)height), p_texture.put())) + if (!LAPP.getGraphicsDevice()->createTexture(core::Vector2U((uint32_t)width, (uint32_t)height), p_texture.put())) { spdlog::error("[luastg] 创建纹理 '{}' ({}x{}) 失败", name, width, height); return false; @@ -751,7 +751,7 @@ namespace luastg .is_force_to_file = false, .is_buffer = false, }; - if (!core::Graphics::IGlyphManager::create(LAPP.GetAppModel()->getDevice(), &create_info, 1, p_glyphmgr.put())) + if (!core::Graphics::IGlyphManager::create(LAPP.getGraphicsDevice(), &create_info, 1, p_glyphmgr.put())) { spdlog::error("[luastg] LoadTTFFont: 加载矢量字体 '{}' 失败", name); return false; @@ -790,7 +790,7 @@ namespace luastg } core::SmartReference p_glyphmgr; - if (!core::Graphics::IGlyphManager::create(LAPP.GetAppModel()->getDevice(), fonts, count, p_glyphmgr.put())) + if (!core::Graphics::IGlyphManager::create(LAPP.getGraphicsDevice(), fonts, count, p_glyphmgr.put())) { spdlog::error("[luastg] LoadTrueTypeFont: 加载矢量字体组 '{}' 失败", name); return false; diff --git a/LuaSTG/LuaSTG/GameResource/ResourcePostEffectShader.hpp b/LuaSTG/LuaSTG/GameResource/ResourcePostEffectShader.hpp index 62e76f1c..4e56b206 100644 --- a/LuaSTG/LuaSTG/GameResource/ResourcePostEffectShader.hpp +++ b/LuaSTG/LuaSTG/GameResource/ResourcePostEffectShader.hpp @@ -1,6 +1,6 @@ #pragma once #include "GameResource/ResourceBase.hpp" -#include "Core/Graphics/Renderer.hpp" +#include "core/Graphics/Renderer.hpp" namespace luastg { diff --git a/LuaSTG/LuaSTG/GameResource/ResourceSprite.hpp b/LuaSTG/LuaSTG/GameResource/ResourceSprite.hpp index 61750792..734305b5 100644 --- a/LuaSTG/LuaSTG/GameResource/ResourceSprite.hpp +++ b/LuaSTG/LuaSTG/GameResource/ResourceSprite.hpp @@ -1,6 +1,6 @@ #pragma once #include "GameResource/ResourceBase.hpp" -#include "Core/Graphics/Sprite.hpp" +#include "core/Graphics/Sprite.hpp" namespace luastg { diff --git a/LuaSTG/LuaSTG/GameResource/ResourceTexture.hpp b/LuaSTG/LuaSTG/GameResource/ResourceTexture.hpp index 3eebcb01..b2f6557c 100644 --- a/LuaSTG/LuaSTG/GameResource/ResourceTexture.hpp +++ b/LuaSTG/LuaSTG/GameResource/ResourceTexture.hpp @@ -1,6 +1,6 @@ #pragma once #include "GameResource/ResourceBase.hpp" -#include "Core/Graphics/Device.hpp" +#include "core/GraphicsDevice.hpp" namespace luastg { @@ -10,7 +10,7 @@ namespace luastg virtual core::Graphics::ITexture2D* GetTexture() = 0; virtual core::Graphics::IRenderTarget* GetRenderTarget() = 0; - virtual core::Graphics::IDepthStencilBuffer* GetDepthStencilBuffer() = 0; + virtual core::IDepthStencilBuffer* GetDepthStencilBuffer() = 0; virtual bool IsRenderTarget() = 0; virtual bool HasDepthStencilBuffer() = 0; }; diff --git a/LuaSTG/LuaSTG/LuaBinding/LW_Input.cpp b/LuaSTG/LuaSTG/LuaBinding/LW_Input.cpp index c91430f6..6e57a7e4 100644 --- a/LuaSTG/LuaSTG/LuaBinding/LW_Input.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/LW_Input.cpp @@ -1,7 +1,7 @@ #include "LuaBinding/LuaWrapper.hpp" #include "AppFrame.h" #include "Keyboard.h" -#include "Platform/Keyboard.hpp" +#include "windows/Keyboard.hpp" #include "Mouse.h" static int register_keyboard(lua_State* L) diff --git a/LuaSTG/LuaSTG/LuaBinding/LW_LuaSTG.cpp b/LuaSTG/LuaSTG/LuaBinding/LW_LuaSTG.cpp index 6727aa8e..ce5457dc 100644 --- a/LuaSTG/LuaSTG/LuaBinding/LW_LuaSTG.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/LW_LuaSTG.cpp @@ -164,54 +164,49 @@ void luastg::binding::BuiltInFunction::Register(lua_State* L)noexcept } static int EnumGPUs(lua_State* L) { lua::stack_t S(L); - if (LAPP.GetAppModel()) - { - auto* p_device = LAPP.GetAppModel()->getDevice(); - auto count = p_device->getGpuCount(); + if (const auto device = LAPP.getGraphicsDevice(); device != nullptr) { + auto count = device->getGpuCount(); lua_createtable(L, count, 0); // t - for (int index = 0; index < (int)count; index += 1) - { - S.push_value(p_device->getGpuName((uint32_t)index)); // t name + for (int index = 0; index < (int)count; index += 1) { + S.push_value(device->getGpuName((uint32_t)index)); // t name lua_rawseti(L, -2, index + 1); // t } return 1; } - else - { + else { return luaL_error(L, "render device is not avilable."); } } static int ChangeGPU(lua_State* L) { lua::stack_t S(L); - if (LAPP.GetAppModel()) - { + if (const auto device = LAPP.getGraphicsDevice(); device != nullptr) { auto const gpu = S.get_value(1); - auto* p_device = LAPP.GetAppModel()->getDevice(); - p_device->setPreferenceGpu(gpu); - if (!p_device->recreate()) + device->setPreferenceGpu(gpu); + if (!device->recreate()) return luaL_error(L, "ChangeGPU failed."); return 0; } - else - { + else { return luaL_error(L, "render device is not avilable."); } } static int GetCurrentGpuName(lua_State* L) { - if (!LAPP.GetAppModel()->getDevice()) - { + if (const auto device = LAPP.getGraphicsDevice(); device != nullptr) { + lua::stack_t S(L); + auto const name = device->getCurrentGpuName(); + S.push_value(name); + return 1; + } + else { return luaL_error(L, "render device is not avilable."); } - lua::stack_t S(L); - auto const name = LAPP.GetAppModel()->getDevice()->getCurrentGpuName(); - S.push_value(name); - return 1; } static int SetSwapChainScalingMode(lua_State* L)noexcept { - LAPP.GetAppModel()->getSwapChain()->setScalingMode( - (core::Graphics::SwapChainScalingMode)luaL_checkinteger(L, 1)); + const lua::stack_t ctx(L); + const auto scaling_mode = ctx.get_value(1); + LAPP.getSwapChain()->setScalingMode(scaling_mode); return 0; } #pragma endregion diff --git a/LuaSTG/LuaSTG/LuaBinding/LW_Platform.cpp b/LuaSTG/LuaSTG/LuaBinding/LW_Platform.cpp index 28d5249f..d99b5dd8 100644 --- a/LuaSTG/LuaSTG/LuaBinding/LW_Platform.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/LW_Platform.cpp @@ -1,13 +1,22 @@ #include "LuaBinding/LuaWrapper.hpp" #include "lua/plus.hpp" #include "ApplicationRestart.hpp" -#include "Platform/KnownDirectory.hpp" +#include "windows/KnownDirectory.hpp" #define WIN32_LEAN_AND_MEAN #define NOMINMAX #include #include #include "utf8.hpp" +namespace { + HWND getMainWindow(core::IWindow* const window) { + if (window == nullptr) { + return nullptr; + } + return static_cast(window->getNativeHandle()); + } +} + void luastg::binding::Platform::Register(lua_State* L) noexcept { struct Wrapper @@ -130,7 +139,7 @@ void luastg::binding::Platform::Register(lua_State* L) noexcept char const* text = luaL_checkstring(L, 2); UINT flags = (UINT)luaL_checkinteger(L, 3); int result = MessageBoxW( - (LAPP.GetAppModel() && LAPP.GetAppModel()->getWindow()) ? (HWND)LAPP.GetAppModel()->getWindow()->getNativeHandle() : NULL, + getMainWindow(LAPP.getWindow()), utf8::to_wstring(text).c_str(), utf8::to_wstring(title).c_str(), flags); diff --git a/LuaSTG/LuaSTG/LuaBinding/LW_Renderer.cpp b/LuaSTG/LuaSTG/LuaBinding/LW_Renderer.cpp index 13a3c207..851d1c52 100644 --- a/LuaSTG/LuaSTG/LuaBinding/LW_Renderer.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/LW_Renderer.cpp @@ -11,7 +11,7 @@ #include "GameResource/LegacyBlendStateHelper.hpp" namespace luastg { - inline core::Graphics::IRenderer* LR2D() { return LAPP.GetAppModel()->getRenderer(); } + inline core::Graphics::IRenderer* LR2D() { return LAPP.getRenderer2D(); } inline ResourceMgr& LRESMGR() { return LAPP.GetResourceMgr(); } #ifndef NDEBUG diff --git a/LuaSTG/LuaSTG/LuaBinding/LW_ResourceMgr.cpp b/LuaSTG/LuaSTG/LuaBinding/LW_ResourceMgr.cpp index 1d930840..cc00bf11 100644 --- a/LuaSTG/LuaSTG/LuaBinding/LW_ResourceMgr.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/LW_ResourceMgr.cpp @@ -432,7 +432,7 @@ void luastg::binding::ResourceManager::Register(lua_State* L) noexcept else return luaL_error(L, "unknown sampler state '%s'", sampler_name.data()); // 设置 - core::Graphics::ISamplerState* p_sampler = LAPP.GetRenderer2D()->getKnownSamplerState(state); + core::IGraphicsSampler* p_sampler = LAPP.getRenderer2D()->getKnownSamplerState(state); p->GetTexture()->setSamplerState(p_sampler); return 0; diff --git a/LuaSTG/LuaSTG/LuaBinding/LW_StopWatch.cpp b/LuaSTG/LuaSTG/LuaBinding/LW_StopWatch.cpp index b84ebf5c..0c597054 100644 --- a/LuaSTG/LuaSTG/LuaBinding/LW_StopWatch.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/LW_StopWatch.cpp @@ -1,5 +1,5 @@ #include "LuaBinding/LuaWrapper.hpp" -#include "Platform/CleanWindows.hpp" +#include "windows/CleanWindows.hpp" //////////////////////////////////////////////////////////////////////////////// /// @brief 高精度停表类 diff --git a/LuaSTG/LuaSTG/LuaBinding/PostEffectShader.cpp b/LuaSTG/LuaSTG/LuaBinding/PostEffectShader.cpp index 9261c92e..39f2298d 100644 --- a/LuaSTG/LuaSTG/LuaBinding/PostEffectShader.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/PostEffectShader.cpp @@ -106,7 +106,7 @@ namespace luastg::binding lua::stack_t S(L); auto const file_path = S.get_value(1); core::SmartReference shader; - if (!LAPP.GetRenderer2D()->createPostEffectShader(file_path, shader.put())) + if (!LAPP.getRenderer2D()->createPostEffectShader(file_path, shader.put())) { return luaL_error(L, "lstg.CreatePostEffectShader failed, see log file for more detail"); } diff --git a/LuaSTG/LuaSTG/LuaBinding/PostEffectShader.hpp b/LuaSTG/LuaSTG/LuaBinding/PostEffectShader.hpp index 7ab0d604..5aa37ed2 100644 --- a/LuaSTG/LuaSTG/LuaBinding/PostEffectShader.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/PostEffectShader.hpp @@ -1,5 +1,5 @@ #pragma once -#include "Core/Graphics/Renderer.hpp" +#include "core/Graphics/Renderer.hpp" #include "lua.hpp" namespace luastg::binding diff --git a/LuaSTG/LuaSTG/LuaBinding/external/lua_dwrite.cpp b/LuaSTG/LuaSTG/LuaBinding/external/lua_dwrite.cpp index e4ec24f3..27535d34 100644 --- a/LuaSTG/LuaSTG/LuaBinding/external/lua_dwrite.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/external/lua_dwrite.cpp @@ -9,7 +9,7 @@ #include #include -#include "Platform/HResultChecker.hpp" +#include "windows/HResultChecker.hpp" #include "core/FileSystem.hpp" #include "backend/WicImage.hpp" #include "AppFrame.h" @@ -101,61 +101,51 @@ namespace DirectWrite // DirectWrite helper - void printFontCollectionInfo(IDWriteFontCollection* dwrite_font_collection, std::stringstream& string_buffer) - { - for (UINT32 ff_idx = 0; ff_idx < dwrite_font_collection->GetFontFamilyCount(); ff_idx += 1) - { + void printFontCollectionInfo(IDWriteLocalizedStrings* const names, const std::string_view indent, std::stringstream& string_buffer) { + for (UINT32 name_idx = 0; name_idx < names->GetCount(); name_idx += 1) { + UINT32 str_len = 0; + + if (FAILED(names->GetStringLength(name_idx, &str_len))) continue; + std::wstring name(str_len + 1, L'\0'); + if (FAILED(names->GetString(name_idx, name.data(), str_len + 1))) continue; + if (name.back() == L'\0') name.pop_back(); + + if (FAILED(names->GetLocaleNameLength(name_idx, &str_len))) continue; + std::wstring locale_name(str_len + 1, L'\0'); + if (FAILED(names->GetLocaleName(name_idx, locale_name.data(), str_len + 1))) continue; + if (locale_name.back() == L'\0') locale_name.pop_back(); + + string_buffer << indent << "[" << name_idx << "] (" << utf8::to_string(locale_name) << ") " << utf8::to_string(name) << '\n'; + } + } + void printFontCollectionInfo(IDWriteFontCollection* dwrite_font_collection, std::stringstream& string_buffer) { + for (UINT32 ff_idx = 0; ff_idx < dwrite_font_collection->GetFontFamilyCount(); ff_idx += 1) { string_buffer << '[' << ff_idx << "] Font Family\n"; Microsoft::WRL::ComPtr dwrite_font_family; - gHR = dwrite_font_collection->GetFontFamily(ff_idx, &dwrite_font_family); + if (FAILED(dwrite_font_collection->GetFontFamily(ff_idx, &dwrite_font_family))) { + continue; + } string_buffer << " Name:\n"; Microsoft::WRL::ComPtr dwrite_font_family_names; - gHR = dwrite_font_family->GetFamilyNames(&dwrite_font_family_names); - for (UINT32 name_idx = 0; name_idx < dwrite_font_family_names->GetCount(); name_idx += 1) - { - UINT32 str_len = 0; - - gHR = dwrite_font_family_names->GetStringLength(name_idx, &str_len); - std::wstring name(str_len + 1, L'\0'); - gHR = dwrite_font_family_names->GetString(name_idx, name.data(), str_len + 1); - if (name.back() == L'\0') name.pop_back(); - - gHR = dwrite_font_family_names->GetLocaleNameLength(name_idx, &str_len); - std::wstring locale_name(str_len + 1, L'\0'); - gHR = dwrite_font_family_names->GetLocaleName(name_idx, locale_name.data(), str_len + 1); - if (locale_name.back() == L'\0') locale_name.pop_back(); - - string_buffer << " [" << name_idx << "] (" << utf8::to_string(locale_name) << ") " << utf8::to_string(name) << '\n'; + if (SUCCEEDED(dwrite_font_family->GetFamilyNames(&dwrite_font_family_names))) { + printFontCollectionInfo(dwrite_font_family_names.Get(), " ", string_buffer); } string_buffer << " Font:\n"; - for (UINT32 font_idx = 0; font_idx < dwrite_font_family->GetFontCount(); font_idx += 1) - { + for (UINT32 font_idx = 0; font_idx < dwrite_font_family->GetFontCount(); font_idx += 1) { string_buffer << " [" << font_idx << "] Font\n"; Microsoft::WRL::ComPtr dwrite_font; - gHR = dwrite_font_family->GetFont(font_idx, &dwrite_font); + if (FAILED(dwrite_font_family->GetFont(font_idx, &dwrite_font))) { + continue; + } string_buffer << " Name:\n"; Microsoft::WRL::ComPtr dwrite_font_face_names; - gHR = dwrite_font->GetFaceNames(&dwrite_font_face_names); - for (UINT32 name_idx = 0; name_idx < dwrite_font_face_names->GetCount(); name_idx += 1) - { - UINT32 str_len = 0; - - gHR = dwrite_font_face_names->GetStringLength(name_idx, &str_len); - std::wstring name(str_len + 1, L'\0'); - gHR = dwrite_font_face_names->GetString(name_idx, name.data(), str_len + 1); - if (name.back() == L'\0') name.pop_back(); - - gHR = dwrite_font_face_names->GetLocaleNameLength(name_idx, &str_len); - std::wstring locale_name(str_len + 1, L'\0'); - gHR = dwrite_font_face_names->GetLocaleName(name_idx, locale_name.data(), str_len + 1); - if (locale_name.back() == L'\0') locale_name.pop_back(); - - string_buffer << " [" << name_idx << "] (" << utf8::to_string(locale_name) << ") " << utf8::to_string(name) << '\n'; + if (SUCCEEDED(dwrite_font->GetFaceNames(&dwrite_font_face_names))) { + printFontCollectionInfo(dwrite_font_face_names.Get(), " ", string_buffer); } /* @@ -2143,7 +2133,7 @@ namespace DirectWrite HRESULT hr = S_OK; Microsoft::WRL::ComPtr d2d1_device_context; - d2d1_device_context = (ID2D1DeviceContext*)LAPP.GetAppModel()->getDevice()->getNativeRendererHandle(); + d2d1_device_context = (ID2D1DeviceContext*)LAPP.getGraphicsDevice()->getNativeRendererHandle(); assert(d2d1_device_context); Microsoft::WRL::ComPtr d2d1_bitmap_target; @@ -2583,6 +2573,7 @@ namespace DirectWrite canvas_image_description.size.y = static_cast(texture_canvas_height); canvas_image_description.format = core::ImageFormat::b8g8r8a8_normalized; canvas_image_description.color_space = core::ImageColorSpace::srgb_gamma_2_2; + canvas_image_description.alpha_mode = core::ImageAlphaMode::premultiplied; core::SmartReference canvas_image; if (!core::ImageFactory::create(canvas_image_description, canvas_image.put())) { diff --git a/LuaSTG/LuaSTG/LuaBinding/external/lua_xinput.cpp b/LuaSTG/LuaSTG/LuaBinding/external/lua_xinput.cpp index dee39d9e..6a88b1df 100644 --- a/LuaSTG/LuaSTG/LuaBinding/external/lua_xinput.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/external/lua_xinput.cpp @@ -1,5 +1,5 @@ #include "lua_xinput.hpp" -#include "Platform/XInput.hpp" +#include "windows/XInput.hpp" #include #include diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/DepthStencilBuffer.cpp b/LuaSTG/LuaSTG/LuaBinding/modern/DepthStencilBuffer.cpp index a9923043..18199904 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/DepthStencilBuffer.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/DepthStencilBuffer.cpp @@ -59,8 +59,8 @@ namespace luastg::binding { lua::stack_t const ctx(vm); auto const width = ctx.get_value(1); auto const height = ctx.get_value(2); - core::SmartReference buffer; - if (!LAPP.GetAppModel()->getDevice()->createDepthStencilBuffer(core::Vector2U(width, height), buffer.put())) { + core::SmartReference buffer; + if (!LAPP.getGraphicsDevice()->createDepthStencilBuffer(core::Vector2U(width, height), buffer.put())) { auto const error_message = std::format( "create DepthStencilBuffer ({}x{}) failed", width, height); return luaL_error(vm, error_message.c_str()); diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/DepthStencilBuffer.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/DepthStencilBuffer.hpp index 3e892e97..1d2f24dc 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/DepthStencilBuffer.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/DepthStencilBuffer.hpp @@ -1,12 +1,12 @@ #pragma once #include "lua.hpp" -#include "Core/Graphics/Device.hpp" +#include "core/DepthStencilBuffer.hpp" namespace luastg::binding { struct DepthStencilBuffer { static std::string_view class_name; - [[maybe_unused]] core::Graphics::IDepthStencilBuffer* data{}; + [[maybe_unused]] core::IDepthStencilBuffer* data{}; static bool is(lua_State* vm, int index); static DepthStencilBuffer* as(lua_State* vm, int index); diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/Display.cpp b/LuaSTG/LuaSTG/LuaBinding/modern/Display.cpp index c0e042b7..ee9d1fab 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/Display.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/Display.cpp @@ -136,11 +136,11 @@ namespace luastg::binding { lua::stack_t S(L); size_t count{}; - if (!core::Graphics::IDisplay::getAll(&count, nullptr)) { + if (!core::IDisplay::getAll(&count, nullptr)) { return luaL_error(L, "lstg.Display.getAll failed"); } - std::vector list(count); + std::vector list(count); [[maybe_unused]] auto release_list = wil::scope_exit([&]() -> void { for (auto ptr : list) { if (ptr) { @@ -148,7 +148,7 @@ namespace luastg::binding { } } }); - if (!core::Graphics::IDisplay::getAll(&count, list.data())) { + if (!core::IDisplay::getAll(&count, list.data())) { return luaL_error(L, "lstg.Display.getAll failed"); } @@ -168,7 +168,7 @@ namespace luastg::binding { static int getPrimary(lua_State* L) { lua::stack_t S(L); auto self = create(L); - if (!core::Graphics::IDisplay::getPrimary(&self->data)) { + if (!core::IDisplay::getPrimary(&self->data)) { return luaL_error(L, "lstg.Display.getPrimary failed"); } return 1; diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/Display.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/Display.hpp index 8fe1bc01..f709adb3 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/Display.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/Display.hpp @@ -1,7 +1,7 @@ #pragma once #include #include "lua.hpp" -#include "Core/Graphics/Window.hpp" +#include "core/Display.hpp" namespace luastg::binding { @@ -9,7 +9,7 @@ namespace luastg::binding { static std::string_view class_name; - [[maybe_unused]] core::Graphics::IDisplay* data{}; + [[maybe_unused]] core::IDisplay* data{}; static bool is(lua_State* L, int index); diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/Mesh.cpp b/LuaSTG/LuaSTG/LuaBinding/modern/Mesh.cpp index 6ec95f47..dc750b9e 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/Mesh.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/Mesh.cpp @@ -444,7 +444,7 @@ namespace luastg::binding { } ctx.pop_value(); - auto const device = LAPP.GetAppModel()->getDevice(); + auto const device = LAPP.getGraphicsDevice(); auto const self = Mesh::create(vm); if (!core::Graphics::IMesh::create(device, options, &self->data)) { return luaL_error(vm, "create Mesh failed."); diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/Mesh.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/Mesh.hpp index 18de16e6..63d5dc0e 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/Mesh.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/Mesh.hpp @@ -1,6 +1,6 @@ #pragma once #include "lua.hpp" -#include "Core/Graphics/Mesh.hpp" +#include "core/Graphics/Mesh.hpp" namespace luastg::binding { struct Mesh { diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/MeshRenderer.cpp b/LuaSTG/LuaSTG/LuaBinding/modern/MeshRenderer.cpp index 39ebfc6e..6593430f 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/MeshRenderer.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/MeshRenderer.cpp @@ -155,7 +155,7 @@ namespace luastg::binding { lua::stack_t const ctx(vm); auto const self = as(vm, 1); - auto const renderer = LAPP.GetAppModel()->getRenderer(); + auto const renderer = LAPP.getRenderer2D(); self->data->draw(renderer); ctx.push_value(lua::stack_index_t(1)); // return self @@ -166,7 +166,7 @@ namespace luastg::binding { static int create(lua_State* vm) { lua::stack_t const ctx(vm); - auto const device = LAPP.GetAppModel()->getDevice(); + auto const device = LAPP.getGraphicsDevice(); if (ctx.index_of_top() >= 2) { auto const mesh = Mesh::as(vm, 1); auto const texture = Texture2D::as(vm, 2); diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/MeshRenderer.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/MeshRenderer.hpp index 03f07dc4..1f8e2742 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/MeshRenderer.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/MeshRenderer.hpp @@ -1,6 +1,6 @@ #pragma once #include "lua.hpp" -#include "Core/Graphics/Mesh.hpp" +#include "core/Graphics/Mesh.hpp" namespace luastg::binding { struct MeshRenderer { diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/RenderTarget.cpp b/LuaSTG/LuaSTG/LuaBinding/modern/RenderTarget.cpp index 2703fb7e..2bf592a2 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/RenderTarget.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/RenderTarget.cpp @@ -72,7 +72,7 @@ namespace luastg::binding { auto const width = ctx.get_value(1); auto const height = ctx.get_value(2); core::SmartReference render_target; - if (!LAPP.GetAppModel()->getDevice()->createRenderTarget(core::Vector2U(width, height), render_target.put())) { + if (!LAPP.getGraphicsDevice()->createRenderTarget(core::Vector2U(width, height), render_target.put())) { auto const error_message = std::format( "create RenderTarget ({}x{}) failed", width, height); return luaL_error(vm, error_message.c_str()); diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/RenderTarget.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/RenderTarget.hpp index f3ce5a11..7c30da25 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/RenderTarget.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/RenderTarget.hpp @@ -1,6 +1,6 @@ #pragma once #include "lua.hpp" -#include "Core/Graphics/Device.hpp" +#include "core/Graphics/Device.hpp" namespace luastg::binding { struct RenderTarget { diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/Sprite.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/Sprite.hpp index ebe4c2d7..23931dd1 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/Sprite.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/Sprite.hpp @@ -1,6 +1,6 @@ #pragma once #include "lua.hpp" -#include "Core/Graphics/Sprite.hpp" +#include "core/Graphics/Sprite.hpp" namespace luastg::binding { struct Sprite { diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/SpriteRenderer.cpp b/LuaSTG/LuaSTG/LuaBinding/modern/SpriteRenderer.cpp index 417d7e31..cc465a2c 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/SpriteRenderer.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/SpriteRenderer.cpp @@ -124,7 +124,7 @@ namespace luastg::binding { self->data->setTransform(self->position, self->scale, self->rotation); // TODO: TBD self->data->setZ(0.5); // TODO: allow custom } - self->data->draw(LAPP.GetAppModel()->getRenderer()); + self->data->draw(LAPP.getRenderer2D()); return 0; } @@ -277,7 +277,7 @@ namespace luastg::binding { } static int draw(lua_State* vm) { auto const self = as(vm, 1); - self->data->draw(LAPP.GetAppModel()->getRenderer()); + self->data->draw(LAPP.getRenderer2D()); return 0; } @@ -459,7 +459,7 @@ namespace luastg::binding { } static int draw(lua_State* vm) { auto const self = as(vm, 1); - self->data->draw(LAPP.GetAppModel()->getRenderer()); + self->data->draw(LAPP.getRenderer2D()); return 0; } diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/SpriteRenderer.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/SpriteRenderer.hpp index 3159442e..719bf7f7 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/SpriteRenderer.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/SpriteRenderer.hpp @@ -1,6 +1,6 @@ #pragma once #include "lua.hpp" -#include "Core/Graphics/Sprite.hpp" +#include "core/Graphics/Sprite.hpp" namespace luastg::binding { struct SpriteRenderer { diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/SwapChain.cpp b/LuaSTG/LuaSTG/LuaBinding/modern/SwapChain.cpp index cbdf2d5c..2f75c963 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/SwapChain.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/SwapChain.cpp @@ -114,7 +114,7 @@ namespace luastg::binding { static int getMain(lua_State* L) { lua::stack_t S(L); auto self = create(L); - self->data = LAPP.GetAppModel()->getSwapChain(); + self->data = LAPP.getSwapChain(); self->data->retain(); return 1; } diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/SwapChain.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/SwapChain.hpp index 39e9a5ef..95416710 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/SwapChain.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/SwapChain.hpp @@ -1,7 +1,7 @@ #pragma once #include #include "lua.hpp" -#include "Core/Graphics/SwapChain.hpp" +#include "core/Graphics/SwapChain.hpp" namespace luastg::binding { diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/TextRenderer.cpp b/LuaSTG/LuaSTG/LuaBinding/modern/TextRenderer.cpp index 9c9fe1c9..36e6ef0a 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/TextRenderer.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/TextRenderer.cpp @@ -141,7 +141,7 @@ namespace luastg::binding { self->data->setTransform(self->position, self->scale, self->rotation); // TODO: TBD self->data->setZ(0.5); // TODO: allow custom } - self->data->draw(LAPP.GetAppModel()->getRenderer()); + self->data->draw(LAPP.getRenderer2D()); return 0; } @@ -151,14 +151,14 @@ namespace luastg::binding { if (lua::stack_t const ctx(vm); ctx.index_of_top() >= 1) { auto const text_layout = TextLayout::as(vm, 1); auto const self = TextRenderer::create(vm); - if (!core::Graphics::ITextRenderer2::create(LAPP.GetAppModel()->getDevice(), &self->data)) { + if (!core::Graphics::ITextRenderer2::create(LAPP.getGraphicsDevice(), &self->data)) { return luaL_error(vm, "create TextRenderer failed"); } self->data->setTextLayout(text_layout->data); } else { auto const self = TextRenderer::create(vm); - if (!core::Graphics::ITextRenderer2::create(LAPP.GetAppModel()->getDevice(), &self->data)) { + if (!core::Graphics::ITextRenderer2::create(LAPP.getGraphicsDevice(), &self->data)) { return luaL_error(vm, "create TextRenderer failed"); } } diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/TextRenderer.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/TextRenderer.hpp index 4563c773..75ce0023 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/TextRenderer.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/TextRenderer.hpp @@ -1,6 +1,6 @@ #pragma once #include "lua.hpp" -#include "Core/Graphics/Font.hpp" +#include "core/Graphics/Font.hpp" namespace luastg::binding { struct TextRenderer { diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/Texture2D.cpp b/LuaSTG/LuaSTG/LuaBinding/modern/Texture2D.cpp index 923ac546..3a7597b1 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/Texture2D.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/Texture2D.cpp @@ -59,7 +59,7 @@ namespace luastg::binding { auto const path = ctx.get_value(1); auto const mipmap_levels = ctx.get_value(2, 1ui32); core::SmartReference texture; - if (!LAPP.GetAppModel()->getDevice()->createTextureFromFile(path, mipmap_levels != 1, texture.put())) { + if (!LAPP.getGraphicsDevice()->createTextureFromFile(path, mipmap_levels != 1, texture.put())) { auto const error_message = std::format( "create Texture2D from file '{}' failed", path); return luaL_error(vm, error_message.c_str()); diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/Texture2D.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/Texture2D.hpp index d62f2c10..82f1f80b 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/Texture2D.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/Texture2D.hpp @@ -1,6 +1,6 @@ #pragma once #include "lua.hpp" -#include "Core/Graphics/Device.hpp" +#include "core/Graphics/Device.hpp" namespace luastg::binding { struct Texture2D { diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/Window.cpp b/LuaSTG/LuaSTG/LuaBinding/modern/Window.cpp index 652fd86d..c4638d01 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/Window.cpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/Window.cpp @@ -2,7 +2,7 @@ #include "Window.hpp" #include "lua/plus.hpp" #include "AppFrame.h" -#include "Platform/WindowsVersion.hpp" +#include "windows/WindowsVersion.hpp" static void pushSize(lua_State* L, lua_Number const width, lua_Number const height) { lua::stack_t S(L); @@ -99,7 +99,7 @@ namespace luastg::binding { auto const size = core::Vector2U(width, height); auto style = self->data->getFrameStyle(); if (S.is_number(4)) { - style = static_cast(S.get_value(4)); + style = static_cast(S.get_value(4)); } if (Display::is(L, 5)) { auto display = Display::as(L, 5); @@ -127,7 +127,7 @@ namespace luastg::binding { static int getCursorVisibility(lua_State* L) { auto self = as(L, 1); lua::stack_t S(L); - S.push_value(self->data->getCursor() != core::Graphics::WindowCursor::None); + S.push_value(self->data->getCursor() != core::WindowCursor::None); return 1; } @@ -135,7 +135,7 @@ namespace luastg::binding { auto self = as(L, 1); lua::stack_t S(L); auto const visible = S.get_value(2); - self->data->setCursor(visible ? core::Graphics::WindowCursor::Arrow : core::Graphics::WindowCursor::None); + self->data->setCursor(visible ? core::WindowCursor::Arrow : core::WindowCursor::None); return 0; } @@ -174,7 +174,7 @@ namespace luastg::binding { static int getMain(lua_State* L) { lua::stack_t S(L); auto self = create(L); - self->data = LAPP.GetAppModel()->getWindow(); + self->data = LAPP.getWindow(); self->data->retain(); return 1; } @@ -206,9 +206,9 @@ namespace luastg::binding { { auto const e = S.create_module("lstg.Window.FrameStyle"); - S.set_map_value(e, "borderless", static_cast(core::Graphics::WindowFrameStyle::None)); - S.set_map_value(e, "fixed", static_cast(core::Graphics::WindowFrameStyle::Fixed)); - S.set_map_value(e, "normal", static_cast(core::Graphics::WindowFrameStyle::Normal)); + S.set_map_value(e, "borderless", static_cast(core::WindowFrameStyle::None)); + S.set_map_value(e, "fixed", static_cast(core::WindowFrameStyle::Fixed)); + S.set_map_value(e, "normal", static_cast(core::WindowFrameStyle::Normal)); } // method diff --git a/LuaSTG/LuaSTG/LuaBinding/modern/Window.hpp b/LuaSTG/LuaSTG/LuaBinding/modern/Window.hpp index 897ea64b..cace4533 100644 --- a/LuaSTG/LuaSTG/LuaBinding/modern/Window.hpp +++ b/LuaSTG/LuaSTG/LuaBinding/modern/Window.hpp @@ -1,7 +1,7 @@ #pragma once #include #include "lua.hpp" -#include "Core/Graphics/Window.hpp" +#include "core/Window.hpp" namespace luastg::binding { @@ -9,7 +9,7 @@ namespace luastg::binding { static std::string_view class_name; - [[maybe_unused]] core::Graphics::IWindow* data{}; + [[maybe_unused]] core::IWindow* data{}; static bool is(lua_State* L, int index); @@ -25,7 +25,7 @@ namespace luastg::binding { static std::string_view class_name; - [[maybe_unused]] core::Graphics::IWindow* data{}; + [[maybe_unused]] core::IWindow* data{}; static bool is(lua_State* L, int index); @@ -41,7 +41,7 @@ namespace luastg::binding { static std::string_view class_name; - [[maybe_unused]] core::Graphics::IWindow* data{}; + [[maybe_unused]] core::IWindow* data{}; static bool is(lua_State* L, int index); @@ -57,7 +57,7 @@ namespace luastg::binding { static std::string_view class_name; - [[maybe_unused]] core::Graphics::IWindow* data{}; + [[maybe_unused]] core::IWindow* data{}; static bool is(lua_State* L, int index); diff --git a/LuaSTG/LuaSTG/Main.cpp b/LuaSTG/LuaSTG/Main.cpp index 86de0988..e94ca8fe 100644 --- a/LuaSTG/LuaSTG/Main.cpp +++ b/LuaSTG/LuaSTG/Main.cpp @@ -1,8 +1,8 @@ #include "luastg_config_generated.h" #include "Main.h" #include "core/implement/ReferenceCountedDebugger.hpp" -#include "Platform/MessageBox.hpp" -#include "Platform/ApplicationSingleInstance.hpp" +#include "windows/MessageBox.hpp" +#include "windows/ApplicationSingleInstance.hpp" #include "Debugger/Logger.hpp" #include "SteamAPI/SteamAPI.hpp" #include "Utility/Utility.h" diff --git a/LuaSTG/LuaSTG/RuntimeCheck.cpp b/LuaSTG/LuaSTG/RuntimeCheck.cpp index 51406939..b19f4ae9 100644 --- a/LuaSTG/LuaSTG/RuntimeCheck.cpp +++ b/LuaSTG/LuaSTG/RuntimeCheck.cpp @@ -1,12 +1,13 @@ #include "RuntimeCheck.hpp" #include "core/Configuration.hpp" -#include "Platform/MessageBox.hpp" -#include "Platform/WindowsVersion.hpp" -#include "Platform/CleanWindows.hpp" -#include "Platform/ModuleLoader.hpp" +#include "core/GraphicsDeviceManager.hpp" +#include "windows/MessageBox.hpp" +#include "windows/WindowsVersion.hpp" +#include "windows/CleanWindows.hpp" +#include "windows/ModuleLoader.hpp" #include #include -#include "Platform/Direct3D11.hpp" +#include "windows/Direct3D11.hpp" #include namespace luastg @@ -274,24 +275,27 @@ namespace luastg return is_all_satisfied; } - bool checkEngineRuntimeRequirement() - { - if (!CheckSystem()) return false; - bool const chinese_simplified = is_chinese_simplified(); - auto const title = make_message_box_title(chinese_simplified); - if (!Platform::Direct3D11::HasDevice(D3D11_CREATE_DEVICE_BGRA_SUPPORT, D3D_FEATURE_LEVEL_10_0)) - { + bool checkEngineRuntimeRequirement() { + if (!CheckSystem()) { + return false; + } + + const auto chinese_simplified = is_chinese_simplified(); + const auto title = make_message_box_title(chinese_simplified); + + core::GraphicsDeviceManager::refresh(); + const auto physical_device_count = core::GraphicsDeviceManager::getPhysicalDeviceCount(); + + if (physical_device_count == 0) { std::string_view text; - if (chinese_simplified) - { + if (chinese_simplified) { text = "找不到可用的显卡:\n" "1、显卡驱动程序可能未安装或未正确安装\n" "2、显卡驱动程序可能未正常工作\n" "3、显卡可能过于老旧,无法被识别\n" "4、虚拟机或者云电脑可能不支持或未安装显卡\n"; } - else - { + else { text = "No available Graphics Card found: \n" "1. Graphics Driver may not be installed or installed incorrectly\n" "2. Graphics Driver might not working correctly\n" @@ -303,6 +307,7 @@ namespace luastg return false; } } + return true; } } diff --git a/LuaSTG/Platform.cmake b/LuaSTG/Platform.cmake deleted file mode 100644 index 3d140a14..00000000 --- a/LuaSTG/Platform.cmake +++ /dev/null @@ -1,66 +0,0 @@ -# Windows Platform - -set(PLATFORM_SOURCES - Platform/Shared.hpp - Platform/RuntimeLoader/DXGI.hpp - Platform/RuntimeLoader/D3DKMT.hpp - Platform/RuntimeLoader/D3DKMT.cpp - Platform/RuntimeLoader/Direct3D11.hpp - Platform/RuntimeLoader/Direct2D1.hpp - Platform/RuntimeLoader/Direct3DCompiler.hpp - Platform/RuntimeLoader/DirectComposition.hpp - Platform/RuntimeLoader/DirectWrite.hpp - Platform/RuntimeLoader/DesktopWindowManager.hpp - Platform/RuntimeLoader/XAudio2.hpp - Platform/RuntimeLoader/All.cpp - Platform/DesktopWindowManager.hpp - Platform/Direct3D11.hpp - Platform/DXGI.hpp - Platform/ModuleLoader.hpp - Platform/All.cpp - Platform/ApplicationSingleInstance.hpp - - Platform/CleanWindows.hpp - Platform/KnownDirectory.hpp - Platform/KnownDirectory.cpp - Platform/WindowSizeMoveController.hpp - Platform/WindowSizeMoveController.cpp - Platform/DirectInput.hpp - Platform/DirectInput.cpp - Platform/WindowsVersion.hpp - Platform/WindowsVersion.cpp - Platform/WindowTheme.hpp - Platform/WindowTheme.cpp - Platform/Keyboard.hpp - Platform/Keyboard.cpp - Platform/HResultChecker.hpp - Platform/HResultChecker.cpp - #Platform/DetectCPU.hpp - #Platform/DetectCPU.cpp - Platform/ProcessorInfo.hpp - Platform/ProcessorInfo.cpp - Platform/XInput.hpp - Platform/XInput.cpp - Platform/AdapterPolicy.hpp - Platform/AdapterPolicy.cpp - Platform/MessageBox.hpp - Platform/MessageBox.cpp - Platform/ImmersiveTitleBarController.hpp - Platform/ImmersiveTitleBarController.cpp -) -source_group(TREE ${CMAKE_CURRENT_LIST_DIR} FILES ${PLATFORM_SOURCES}) - -add_library(PlatformAPI STATIC) -luastg_target_common_options(PlatformAPI) -luastg_target_more_warning(PlatformAPI) -target_include_directories(PlatformAPI PUBLIC - . -) -target_sources(PlatformAPI PRIVATE - ${PLATFORM_SOURCES} -) -target_link_libraries(PlatformAPI PRIVATE - Microsoft.Windows.ImplementationLibrary - utf8 - beautiful_win32_api -) diff --git a/LuaSTG/Shader/CMakeLists.txt b/LuaSTG/Shader/CMakeLists.txt deleted file mode 100644 index dc8c8823..00000000 --- a/LuaSTG/Shader/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -add_executable(ShaderCompiler) -set_target_properties(ShaderCompiler PROPERTIES - C_STANDARD 17 - C_STANDARD_REQUIRED ON - CXX_STANDARD 20 - CXX_STANDARD_REQUIRED ON -) -target_compile_options(ShaderCompiler -PRIVATE - "/utf-8" - "/W4" # 更多警告 -) -#target_link_options(ShaderCompiler -#PRIVATE -# "/DEPENDENTLOADFLAG:0x800" # Windows 10 1607+ 强制 DLL 搜索目录为系统目录 -#) -target_compile_definitions(ShaderCompiler -PRIVATE - _UNICODE - UNICODE - HREADER_OUTPUT_DIRECTORY=\"${CMAKE_CURRENT_LIST_DIR}/generated\" - HREADER_INPUT_DIRECTORY=\"${CMAKE_CURRENT_LIST_DIR}\" -) -target_include_directories(ShaderCompiler -PRIVATE - ${CMAKE_CURRENT_LIST_DIR} -) -target_sources(ShaderCompiler -PRIVATE - ShaderCompiler.cpp -) -target_link_libraries(ShaderCompiler -PRIVATE - d3dcompiler.lib -) diff --git a/LuaSTG/Shader/ShaderCompiler.cpp b/LuaSTG/Shader/ShaderCompiler.cpp deleted file mode 100644 index 32371b21..00000000 --- a/LuaSTG/Shader/ShaderCompiler.cpp +++ /dev/null @@ -1,626 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#include -#include -#include - -static const std::string_view source_root(HREADER_INPUT_DIRECTORY); -static const std::string_view generated_root(HREADER_OUTPUT_DIRECTORY); - -namespace std -{ - inline wstring to_wstring(string_view str) - { - wstring wstr; - int const count = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), nullptr, 0); - assert(count >= 0); - wstr.resize(static_cast(count)); - [[maybe_unused]] - int const result = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), wstr.data(), count); - assert(count == result); - return wstr; - } - - namespace files - { - template - requires same_as - bool read_file(string_view path, T& storage) - { - ifstream file(to_wstring(path), ios::in | ios::binary); - if (!file.is_open()) - { - assert(false); - return false; - } - file.seekg(0, ios::end); - streampos const file_end = file.tellg(); - file.seekg(0, ios::beg); - streampos const file_begin = file.tellg(); - assert(file_end >= file_begin); - streamoff const file_size = file_end - file_begin; - - array buffer{}; - size_t size_to_read = static_cast(file_size); - while (size_to_read > 0) - { - if (size_to_read > buffer.size()) - { - file.read(static_cast(buffer.data()), 64); - for (size_t i = 0; i < 64; i += 1) - { - storage.push_back(buffer[i]); - } - size_to_read -= 64; - } - else - { - file.read(static_cast(buffer.data()), static_cast(size_to_read)); - for (size_t i = 0; i < size_to_read; i += 1) - { - storage.push_back(buffer[i]); - } - size_to_read -= size_to_read; - } - } - - return true; - } - } -} - -struct output_config_t -{ - std::string_view namespace_name; - std::string_view value_name; - std::string file_path; -}; - -bool write_blob_to_file(winrt::com_ptr blob, output_config_t const& config, std::ofstream& file) -{ - assert(blob); - assert(blob->GetBufferSize() % 4 == 0); - - file << "// This is a file generated by the compiler, DO NOT directly modify this file\n"; - file << "#pragma once\n"; - file << "namespace " << config.namespace_name << "\n"; - file << "{\n"; - file << " static unsigned char const " << config.value_name << "[] = {\n"; - - std::span const bytes(static_cast(blob->GetBufferPointer()), blob->GetBufferSize()); - - for (size_t index = 0; index < bytes.size(); index += 4) - { - std::span const view = bytes.subspan(index, 4); - std::format_to(std::ostreambuf_iterator(file), - " {:#04x}, {:#04x}, {:#04x}, {:#04x},\n", - view[0], view[1], view[2], view[3]); - } - - file << " };\n"; - file << "}\n"; - - return true; -} - -bool write_blob_to_file(winrt::com_ptr blob, output_config_t const& config) -{ - std::filesystem::path path(std::to_wstring(std::string(generated_root) + "/" + config.file_path)); - std::filesystem::create_directories(path.parent_path()); - std::ofstream file(path, std::ios::out | std::ios::binary | std::ios::trunc); - if (!file.is_open()) - { - assert(false); - return false; - } - return write_blob_to_file(blob, config, file); -} - -enum class optimization_level : uint8_t -{ - unspecified = 255u, - level0 = 0u, - level1 = 1u, - level2 = 2u, - level3 = 3u, -}; - -enum class shader_type : uint8_t -{ - invalid, - vertex_shader, - pixel_shader, -}; - -struct compile_profile_t -{ - // Directs the compiler to insert debug file/line/type/symbol information into the output code. - uint8_t debug : 1; - - // Directs the compiler not to validate the generated code against known capabilities and constraints. We recommend that you use this constant only with shaders that have been successfully compiled in the past. DirectX always validates shaders before it sets them to a device. - uint8_t skip_validation : 1; - - // Directs the compiler to skip optimization steps during code generation. We recommend that you set this constant for debug purposes only. - uint8_t skip_optimization : 1; - - // Directs the compiler to pack matrices in row-major order on input and output from the shader. - uint8_t pack_matrix_row_major : 1; - - // Directs the compiler to pack matrices in column-major order on input and output from the shader. This type of packing is generally more efficient because a series of dot-products can then perform vector-matrix multiplication. - uint8_t pack_matrix_column_major : 1; - - // Directs the compiler to perform all computations with partial precision. If you set this constant, the compiled code might run faster on some hardware. - uint8_t partial_precision : 1; - - // Directs the compiler to not use flow-control constructs where possible. - uint8_t avoid_control_flow : 1; - - // Forces strict compile, which might not allow for legacy syntax. By default, the compiler disables strictness on deprecated syntax. - uint8_t strictness : 1; - - // Forces the IEEE strict compile which avoids optimizations that may break IEEE rules. - uint8_t ieee_strictness : 1; - - // Directs the compiler to treat all warnings as errors when it compiles the shader code. We recommend that you use this constant for new shader code, so that you can resolve all warnings and lower the number of hard-to-find code defects. - uint8_t warnings_are_errors : 1; - - // Directs the compiler to use different optimization level. - optimization_level optimization_level; - - inline uint32_t to_flags() const - { - uint32_t flags = 0; - if (debug) flags |= D3DCOMPILE_DEBUG; - if (skip_validation) flags |= D3DCOMPILE_SKIP_VALIDATION; - if (skip_optimization) flags |= D3DCOMPILE_SKIP_OPTIMIZATION; - if (pack_matrix_row_major) flags |= D3DCOMPILE_PACK_MATRIX_ROW_MAJOR; - if (pack_matrix_column_major) flags |= D3DCOMPILE_PACK_MATRIX_COLUMN_MAJOR; - if (partial_precision) flags |= D3DCOMPILE_PARTIAL_PRECISION; - if (avoid_control_flow) flags |= D3DCOMPILE_AVOID_FLOW_CONTROL; - if (strictness) flags |= D3DCOMPILE_ENABLE_STRICTNESS; - if (ieee_strictness) flags |= D3DCOMPILE_IEEE_STRICTNESS; - if (warnings_are_errors) flags |= D3DCOMPILE_WARNINGS_ARE_ERRORS; - switch (optimization_level) - { - case optimization_level::level0: flags |= D3DCOMPILE_OPTIMIZATION_LEVEL0; break; - case optimization_level::level1: flags |= D3DCOMPILE_OPTIMIZATION_LEVEL1; break; - case optimization_level::level2: flags |= D3DCOMPILE_OPTIMIZATION_LEVEL2; break; - case optimization_level::level3: flags |= D3DCOMPILE_OPTIMIZATION_LEVEL3; break; - default: break; - } - return flags; - } - - static inline compile_profile_t standard_debug() - { - return compile_profile_t{ - .debug = true, - .skip_validation = false, - .skip_optimization = true, - .pack_matrix_row_major = false, - .pack_matrix_column_major = false, // 我们也禁用该选项,保留默认行为 - .partial_precision = false, - .avoid_control_flow = false, - .strictness = true, // 避免使用 Direct3D9 时期的语法 - .ieee_strictness = false, // 不需要严格 IEEE 浮点,确保调试模式和发布模式下表现一致 - .warnings_are_errors = true, // 不润许一切警告 - .optimization_level = optimization_level::unspecified, - }; - } - - static inline compile_profile_t standard_release() - { - return compile_profile_t{ - .debug = false, - .skip_validation = false, - .skip_optimization = false, - .pack_matrix_row_major = false, - .pack_matrix_column_major = false, // 我们也禁用该选项,保留默认行为 - .partial_precision = false, - .avoid_control_flow = true, - .strictness = true, // 避免使用 Direct3D9 时期的语法 - .ieee_strictness = false, // 不需要严格 IEEE 浮点,确保调试模式和发布模式下表现一致 - .warnings_are_errors = true, // 不润许一切警告 - .optimization_level = optimization_level::level3, - }; - } -}; - -struct compile_config_t -{ - compile_profile_t compile_profile; - shader_type shader_type; - std::vector definitions; - std::string file_path; -}; - -bool compile_shader(compile_config_t const& config, winrt::com_ptr& blob) -{ - std::vector source; - if (!std::files::read_file(std::string(source_root) + "/" + config.file_path, source)) - { - return false; - } - winrt::com_ptr error_message; - std::string_view target_type = ""; - switch (config.shader_type) - { - case shader_type::vertex_shader: target_type = "vs_4_0"; break; - case shader_type::pixel_shader: target_type = "ps_4_0"; break; - default: assert(false); return false; - } - std::vector definitions; - for (auto const& v : config.definitions) - { - D3D_SHADER_MACRO e = { - .Name = v.c_str(), - .Definition = "1", - }; - definitions.push_back(e); - } - definitions.push_back({}); // { NULL, NULL } - winrt::hresult hr = D3DCompile( - source.data(), - source.size(), - config.file_path.data(), - definitions.data(), - D3D_COMPILE_STANDARD_FILE_INCLUDE, - "main", - target_type.data(), - config.compile_profile.to_flags(), - 0, - blob.put(), - error_message.put()); - if (error_message && error_message->GetBufferSize() > 0) - { - std::cout << std::string_view(static_cast(error_message->GetBufferPointer()), error_message->GetBufferSize()) << std::endl; - } - if (FAILED(hr)) - { - return false; - } - return true; -} - -bool process_shader(compile_config_t const& compile_config, output_config_t const& output_config) -{ - winrt::com_ptr blob; - if (!compile_shader(compile_config, blob)) - { - return false; - } - return write_blob_to_file(blob, output_config); -} - -void process_imgui_shader() -{ - // imgui::backend::d3d11 - - /* vertex shader */ { - compile_config_t iconfig = { - .compile_profile = compile_profile_t::standard_release(), - .shader_type = shader_type::vertex_shader, - .file_path = "imgui/backend/d3d11/vertex_shader.hlsl", - }; - output_config_t oconfig = { - .namespace_name = "imgui::backend::d3d11", - .value_name = "vertex_shader", - .file_path = "imgui/backend/d3d11/vertex_shader.hpp", - }; - if (!process_shader(iconfig, oconfig)) - { - std::exit(1); - } - } - - /* pixel shader */ { - compile_config_t iconfig = { - .compile_profile = compile_profile_t::standard_release(), - .shader_type = shader_type::pixel_shader, - .file_path = "imgui/backend/d3d11/pixel_shader.hlsl", - }; - output_config_t oconfig = { - .namespace_name = "imgui::backend::d3d11", - .value_name = "pixel_shader", - .file_path = "imgui/backend/d3d11/pixel_shader.hpp", - }; - if (!process_shader(iconfig, oconfig)) - { - std::exit(1); - } - } -} - -void process_luastg_shader() -{ - auto process_vertex_shader_ = [](std::vector const& defs, std::string_view name) - { - compile_config_t iconfig = { - .compile_profile = compile_profile_t::standard_release(), - .shader_type = shader_type::vertex_shader, - .file_path = "luastg/sub/renderer/vertex_shader.hlsl", - }; - iconfig.definitions = defs; - std::string value_name = "vertex_shader_" + std::string(name); - output_config_t oconfig = { - .namespace_name = "luastg::sub::renderer", - .value_name = value_name, - .file_path = "luastg/sub/renderer/" + value_name + ".hpp", - }; - if (!process_shader(iconfig, oconfig)) - { - std::exit(1); - } - }; - -#define process_vertex_shader(X) process_vertex_shader_(X, #X) - - std::vector def_none = { - }; - std::vector def_fog = { - "FOG_ENABLE", - }; - - process_vertex_shader(def_none); - process_vertex_shader(def_fog); - -#undef process_vertex_shader - - auto process_pixel_shader_ = [](std::vector const& defs, std::string_view name) - { - compile_config_t iconfig = { - .compile_profile = compile_profile_t::standard_release(), - .shader_type = shader_type::pixel_shader, - .file_path = "luastg/sub/renderer/pixel_shader.hlsl", - }; - iconfig.definitions = defs; - std::string value_name = "pixel_shader_" + std::string(name); - output_config_t oconfig = { - .namespace_name = "luastg::sub::renderer", - .value_name = value_name, - .file_path = "luastg/sub/renderer/" + value_name + ".hpp", - }; - if (!process_shader(iconfig, oconfig)) - { - std::exit(1); - } - }; - -#define process_pixel_shader(X) process_pixel_shader_(X, #X) - - auto pass1 = [&]() - { - std::vector def_zero_none_normal = { - "VERTEX_COLOR_BLEND_ZERO", - }; - std::vector def_one_none_normal = { - "VERTEX_COLOR_BLEND_ONE", - }; - std::vector def_add_none_normal = { - "VERTEX_COLOR_BLEND_ADD", - }; - std::vector def_mul_none_normal = { - "VERTEX_COLOR_BLEND_MUL", - }; - - process_pixel_shader(def_zero_none_normal); - process_pixel_shader(def_one_none_normal); - process_pixel_shader(def_add_none_normal); - process_pixel_shader(def_mul_none_normal); - - std::vector def_zero_linear_normal = { - "VERTEX_COLOR_BLEND_ZERO", - "FOG_ENABLE", - "FOG_LINEAR", - }; - std::vector def_one_linear_normal = { - "VERTEX_COLOR_BLEND_ONE", - "FOG_ENABLE", - "FOG_LINEAR", - }; - std::vector def_add_linear_normal = { - "VERTEX_COLOR_BLEND_ADD", - "FOG_ENABLE", - "FOG_LINEAR", - }; - std::vector def_mul_linear_normal = { - "VERTEX_COLOR_BLEND_MUL", - "FOG_ENABLE", - "FOG_LINEAR", - }; - - process_pixel_shader(def_zero_linear_normal); - process_pixel_shader(def_one_linear_normal); - process_pixel_shader(def_add_linear_normal); - process_pixel_shader(def_mul_linear_normal); - - std::vector def_zero_exp_normal = { - "VERTEX_COLOR_BLEND_ZERO", - "FOG_ENABLE", - "FOG_EXP", - }; - std::vector def_one_exp_normal = { - "VERTEX_COLOR_BLEND_ONE", - "FOG_ENABLE", - "FOG_EXP", - }; - std::vector def_add_exp_normal = { - "VERTEX_COLOR_BLEND_ADD", - "FOG_ENABLE", - "FOG_EXP", - }; - std::vector def_mul_exp_normal = { - "VERTEX_COLOR_BLEND_MUL", - "FOG_ENABLE", - "FOG_EXP", - }; - - process_pixel_shader(def_zero_exp_normal); - process_pixel_shader(def_one_exp_normal); - process_pixel_shader(def_add_exp_normal); - process_pixel_shader(def_mul_exp_normal); - - std::vector def_zero_exp2_normal = { - "VERTEX_COLOR_BLEND_ZERO", - "FOG_ENABLE", - "FOG_EXP2", - }; - std::vector def_one_exp2_normal = { - "VERTEX_COLOR_BLEND_ONE", - "FOG_ENABLE", - "FOG_EXP2", - }; - std::vector def_add_exp2_normal = { - "VERTEX_COLOR_BLEND_ADD", - "FOG_ENABLE", - "FOG_EXP2", - }; - std::vector def_mul_exp2_normal = { - "VERTEX_COLOR_BLEND_MUL", - "FOG_ENABLE", - "FOG_EXP2", - }; - - process_pixel_shader(def_zero_exp2_normal); - process_pixel_shader(def_one_exp2_normal); - process_pixel_shader(def_add_exp2_normal); - process_pixel_shader(def_mul_exp2_normal); - }; - - auto pass2 = [&]() - { - std::vector def_zero_none_premul = { - "VERTEX_COLOR_BLEND_ZERO", - "PREMUL_ALPHA", - }; - std::vector def_one_none_premul = { - "VERTEX_COLOR_BLEND_ONE", - "PREMUL_ALPHA", - }; - std::vector def_add_none_premul = { - "VERTEX_COLOR_BLEND_ADD", - "PREMUL_ALPHA", - }; - std::vector def_mul_none_premul = { - "VERTEX_COLOR_BLEND_MUL", - "PREMUL_ALPHA", - }; - - process_pixel_shader(def_zero_none_premul); - process_pixel_shader(def_one_none_premul); - process_pixel_shader(def_add_none_premul); - process_pixel_shader(def_mul_none_premul); - - std::vector def_zero_linear_premul = { - "VERTEX_COLOR_BLEND_ZERO", - "FOG_ENABLE", - "FOG_LINEAR", - "PREMUL_ALPHA", - }; - std::vector def_one_linear_premul = { - "VERTEX_COLOR_BLEND_ONE", - "FOG_ENABLE", - "FOG_LINEAR", - "PREMUL_ALPHA", - }; - std::vector def_add_linear_premul = { - "VERTEX_COLOR_BLEND_ADD", - "FOG_ENABLE", - "FOG_LINEAR", - "PREMUL_ALPHA", - }; - std::vector def_mul_linear_premul = { - "VERTEX_COLOR_BLEND_MUL", - "FOG_ENABLE", - "FOG_LINEAR", - "PREMUL_ALPHA", - }; - - process_pixel_shader(def_zero_linear_premul); - process_pixel_shader(def_one_linear_premul); - process_pixel_shader(def_add_linear_premul); - process_pixel_shader(def_mul_linear_premul); - - std::vector def_zero_exp_premul = { - "VERTEX_COLOR_BLEND_ZERO", - "FOG_ENABLE", - "FOG_EXP", - "PREMUL_ALPHA", - }; - std::vector def_one_exp_premul = { - "VERTEX_COLOR_BLEND_ONE", - "FOG_ENABLE", - "FOG_EXP", - "PREMUL_ALPHA", - }; - std::vector def_add_exp_premul = { - "VERTEX_COLOR_BLEND_ADD", - "FOG_ENABLE", - "FOG_EXP", - "PREMUL_ALPHA", - }; - std::vector def_mul_exp_premul = { - "VERTEX_COLOR_BLEND_MUL", - "FOG_ENABLE", - "FOG_EXP", - "PREMUL_ALPHA", - }; - - process_pixel_shader(def_zero_exp_premul); - process_pixel_shader(def_one_exp_premul); - process_pixel_shader(def_add_exp_premul); - process_pixel_shader(def_mul_exp_premul); - - std::vector def_zero_exp2_premul = { - "VERTEX_COLOR_BLEND_ZERO", - "FOG_ENABLE", - "FOG_EXP2", - "PREMUL_ALPHA", - }; - std::vector def_one_exp2_premul = { - "VERTEX_COLOR_BLEND_ONE", - "FOG_ENABLE", - "FOG_EXP2", - "PREMUL_ALPHA", - }; - std::vector def_add_exp2_premul = { - "VERTEX_COLOR_BLEND_ADD", - "FOG_ENABLE", - "FOG_EXP2", - "PREMUL_ALPHA", - }; - std::vector def_mul_exp2_premul = { - "VERTEX_COLOR_BLEND_MUL", - "FOG_ENABLE", - "FOG_EXP2", - "PREMUL_ALPHA", - }; - - process_pixel_shader(def_zero_exp2_premul); - process_pixel_shader(def_one_exp2_premul); - process_pixel_shader(def_add_exp2_premul); - process_pixel_shader(def_mul_exp2_premul); - }; - -#undef process_pixel_shader - - pass1(); - pass2(); -} - -int main(int, char**) -{ - process_imgui_shader(); - process_luastg_shader(); - return 0; -} diff --git a/LuaSTG/Shader/generated/imgui/backend/d3d11/pixel_shader.hpp b/LuaSTG/Shader/generated/imgui/backend/d3d11/pixel_shader.hpp deleted file mode 100644 index a180d940..00000000 --- a/LuaSTG/Shader/generated/imgui/backend/d3d11/pixel_shader.hpp +++ /dev/null @@ -1,172 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace imgui::backend::d3d11 -{ - static unsigned char const pixel_shader[] = { - 0x44, 0x58, 0x42, 0x43, - 0x0d, 0x7e, 0x4b, 0x70, - 0x1a, 0x93, 0xd5, 0x4f, - 0x43, 0xee, 0xde, 0x02, - 0xb4, 0x52, 0x03, 0x5e, - 0x01, 0x00, 0x00, 0x00, - 0x94, 0x02, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd4, 0x00, 0x00, 0x00, - 0x48, 0x01, 0x00, 0x00, - 0x7c, 0x01, 0x00, 0x00, - 0x18, 0x02, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x98, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6e, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x4d, 0x69, - 0x63, 0x72, 0x6f, 0x73, - 0x6f, 0x66, 0x74, 0x20, - 0x28, 0x52, 0x29, 0x20, - 0x48, 0x4c, 0x53, 0x4c, - 0x20, 0x53, 0x68, 0x61, - 0x64, 0x65, 0x72, 0x20, - 0x43, 0x6f, 0x6d, 0x70, - 0x69, 0x6c, 0x65, 0x72, - 0x20, 0x31, 0x30, 0x2e, - 0x31, 0x00, 0xab, 0xab, - 0x49, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x62, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x43, 0x4f, 0x4c, 0x4f, - 0x52, 0x00, 0x54, 0x45, - 0x58, 0x43, 0x4f, 0x4f, - 0x52, 0x44, 0x00, 0xab, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x61, 0x72, 0x67, 0x65, - 0x74, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x94, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x25, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/imgui/backend/d3d11/vertex_shader.hpp b/LuaSTG/Shader/generated/imgui/backend/d3d11/vertex_shader.hpp deleted file mode 100644 index d6213074..00000000 --- a/LuaSTG/Shader/generated/imgui/backend/d3d11/vertex_shader.hpp +++ /dev/null @@ -1,226 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace imgui::backend::d3d11 -{ - static unsigned char const vertex_shader[] = { - 0x44, 0x58, 0x42, 0x43, - 0x87, 0x84, 0x02, 0xfd, - 0x99, 0x4a, 0xa5, 0x05, - 0x6c, 0xa4, 0xa1, 0x2b, - 0x5c, 0x26, 0x4b, 0x35, - 0x01, 0x00, 0x00, 0x00, - 0x6c, 0x03, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x04, 0x01, 0x00, 0x00, - 0x74, 0x01, 0x00, 0x00, - 0xe8, 0x01, 0x00, 0x00, - 0xf0, 0x02, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0xc8, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x4c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xfe, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0xa0, 0x00, 0x00, 0x00, - 0x3c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x76, 0x65, 0x72, 0x74, - 0x65, 0x78, 0x42, 0x75, - 0x66, 0x66, 0x65, 0x72, - 0x00, 0xab, 0xab, 0xab, - 0x3c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x64, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x90, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x50, 0x72, 0x6f, 0x6a, - 0x65, 0x63, 0x74, 0x69, - 0x6f, 0x6e, 0x4d, 0x61, - 0x74, 0x72, 0x69, 0x78, - 0x00, 0xab, 0xab, 0xab, - 0x03, 0x00, 0x03, 0x00, - 0x04, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x68, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x43, 0x4f, 0x4c, - 0x4f, 0x52, 0x00, 0x54, - 0x45, 0x58, 0x43, 0x4f, - 0x4f, 0x52, 0x44, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x62, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x0c, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x43, 0x4f, 0x4c, 0x4f, - 0x52, 0x00, 0x54, 0x45, - 0x58, 0x43, 0x4f, 0x4f, - 0x52, 0x44, 0x00, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x00, 0x01, 0x00, 0x00, - 0x40, 0x00, 0x01, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x67, 0x00, 0x00, 0x04, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0x32, 0x20, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x56, 0x15, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0xf2, 0x20, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x32, 0x20, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp2_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp2_normal.hpp deleted file mode 100644 index ae266951..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp2_normal.hpp +++ /dev/null @@ -1,412 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_add_exp2_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0x1f, 0xbb, 0x20, 0x05, - 0xbf, 0xff, 0xb1, 0xcb, - 0xc9, 0x1b, 0x7d, 0xe1, - 0x50, 0xc8, 0xdb, 0x19, - 0x01, 0x00, 0x00, 0x00, - 0x54, 0x06, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0xd8, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x38, 0x03, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xce, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x33, 0x00, 0x00, 0x0a, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x15, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp2_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp2_premul.hpp deleted file mode 100644 index 42c77d3f..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp2_premul.hpp +++ /dev/null @@ -1,429 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_add_exp2_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x9f, 0x88, 0xba, 0x19, - 0x0d, 0xaa, 0x4b, 0x6a, - 0x1a, 0xf3, 0x77, 0x35, - 0x2a, 0x77, 0x1e, 0x20, - 0x01, 0x00, 0x00, 0x00, - 0x98, 0x06, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x1c, 0x06, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x7c, 0x03, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xdf, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x31, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x81, 0x80, 0x80, 0x3b, - 0x0d, 0x00, 0x04, 0x03, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x33, 0x00, 0x00, 0x0a, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x42, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x22, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xd2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x06, 0x89, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x56, 0x05, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x86, 0x03, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x1b, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x17, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp_normal.hpp deleted file mode 100644 index b96ea829..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp_normal.hpp +++ /dev/null @@ -1,412 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_add_exp_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0xdd, 0x61, 0x1a, 0x3d, - 0x42, 0xab, 0x03, 0x3b, - 0xe8, 0x29, 0xd8, 0x95, - 0x36, 0x30, 0x93, 0x3e, - 0x01, 0x00, 0x00, 0x00, - 0x54, 0x06, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0xd8, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x38, 0x03, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xce, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x34, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x33, 0x00, 0x00, 0x0a, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x15, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp_premul.hpp deleted file mode 100644 index 91eab2bd..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_exp_premul.hpp +++ /dev/null @@ -1,429 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_add_exp_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x5a, 0x9c, 0x62, 0x8b, - 0xac, 0xb7, 0x9e, 0xa7, - 0x02, 0x3d, 0x0c, 0xa6, - 0xa8, 0x4a, 0x9f, 0xc3, - 0x01, 0x00, 0x00, 0x00, - 0x98, 0x06, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x1c, 0x06, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x7c, 0x03, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xdf, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x31, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x81, 0x80, 0x80, 0x3b, - 0x0d, 0x00, 0x04, 0x03, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x33, 0x00, 0x00, 0x0a, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x34, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x42, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x22, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xd2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x06, 0x89, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x56, 0x05, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x86, 0x03, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x1b, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x17, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_linear_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_linear_normal.hpp deleted file mode 100644 index 914b3ac3..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_linear_normal.hpp +++ /dev/null @@ -1,394 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_add_linear_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0x99, 0x36, 0x5d, 0x99, - 0x3b, 0x21, 0x55, 0xc6, - 0x69, 0xdc, 0x8f, 0x3f, - 0xe7, 0x2c, 0x31, 0x6a, - 0x01, 0x00, 0x00, 0x00, - 0x0c, 0x06, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x90, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xf0, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xbc, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x20, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x33, 0x00, 0x00, 0x0a, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x15, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_linear_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_linear_premul.hpp deleted file mode 100644 index 05478f40..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_linear_premul.hpp +++ /dev/null @@ -1,411 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_add_linear_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x61, 0x5c, 0x0e, 0x87, - 0x7e, 0xba, 0x07, 0xcf, - 0xe3, 0xb0, 0xa2, 0xaf, - 0xcb, 0x01, 0x7e, 0x78, - 0x01, 0x00, 0x00, 0x00, - 0x50, 0x06, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0xd4, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x34, 0x03, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xcd, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x31, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x81, 0x80, 0x80, 0x3b, - 0x0d, 0x00, 0x04, 0x03, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x33, 0x00, 0x00, 0x0a, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x20, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x42, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x22, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xd2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x06, 0x89, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x56, 0x05, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x86, 0x03, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x18, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_none_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_none_normal.hpp deleted file mode 100644 index 606e7ac2..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_none_normal.hpp +++ /dev/null @@ -1,201 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_add_none_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0x04, 0xef, 0x07, 0xca, - 0x42, 0x64, 0x28, 0x25, - 0x57, 0x17, 0x18, 0x2d, - 0x8f, 0xa0, 0xc0, 0xca, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x03, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd4, 0x00, 0x00, 0x00, - 0x48, 0x01, 0x00, 0x00, - 0x7c, 0x01, 0x00, 0x00, - 0x8c, 0x02, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x98, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6e, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x4d, 0x69, - 0x63, 0x72, 0x6f, 0x73, - 0x6f, 0x66, 0x74, 0x20, - 0x28, 0x52, 0x29, 0x20, - 0x48, 0x4c, 0x53, 0x4c, - 0x20, 0x53, 0x68, 0x61, - 0x64, 0x65, 0x72, 0x20, - 0x43, 0x6f, 0x6d, 0x70, - 0x69, 0x6c, 0x65, 0x72, - 0x20, 0x31, 0x30, 0x2e, - 0x31, 0x00, 0xab, 0xab, - 0x49, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x54, 0x45, 0x58, 0x43, - 0x4f, 0x4f, 0x52, 0x44, - 0x00, 0x43, 0x4f, 0x4c, - 0x4f, 0x52, 0x00, 0xab, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x08, 0x01, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x42, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x33, 0x00, 0x00, 0x0a, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x07, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_none_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_none_premul.hpp deleted file mode 100644 index d7ce47f8..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_add_none_premul.hpp +++ /dev/null @@ -1,218 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_add_none_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x40, 0xda, 0xc5, 0x6f, - 0x9f, 0xde, 0x22, 0x39, - 0x37, 0xb8, 0x04, 0xb1, - 0xfc, 0x82, 0xa0, 0x55, - 0x01, 0x00, 0x00, 0x00, - 0x4c, 0x03, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd4, 0x00, 0x00, 0x00, - 0x48, 0x01, 0x00, 0x00, - 0x7c, 0x01, 0x00, 0x00, - 0xd0, 0x02, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x98, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6e, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x4d, 0x69, - 0x63, 0x72, 0x6f, 0x73, - 0x6f, 0x66, 0x74, 0x20, - 0x28, 0x52, 0x29, 0x20, - 0x48, 0x4c, 0x53, 0x4c, - 0x20, 0x53, 0x68, 0x61, - 0x64, 0x65, 0x72, 0x20, - 0x43, 0x6f, 0x6d, 0x70, - 0x69, 0x6c, 0x65, 0x72, - 0x20, 0x31, 0x30, 0x2e, - 0x31, 0x00, 0xab, 0xab, - 0x49, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x54, 0x45, 0x58, 0x43, - 0x4f, 0x4f, 0x52, 0x44, - 0x00, 0x43, 0x4f, 0x4c, - 0x4f, 0x52, 0x00, 0xab, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x4c, 0x01, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x53, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x31, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x81, 0x80, 0x80, 0x3b, - 0x0d, 0x00, 0x04, 0x03, - 0x0a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x33, 0x00, 0x00, 0x0a, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp2_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp2_normal.hpp deleted file mode 100644 index 051b9b4d..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp2_normal.hpp +++ /dev/null @@ -1,395 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_mul_exp2_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0x66, 0x02, 0xc5, 0x7e, - 0xfc, 0x56, 0xca, 0x2a, - 0x6e, 0xae, 0x8c, 0x24, - 0x55, 0x06, 0xac, 0x92, - 0x01, 0x00, 0x00, 0x00, - 0x10, 0x06, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x94, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xf4, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xbd, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x16, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x13, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp2_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp2_premul.hpp deleted file mode 100644 index 69485de3..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp2_premul.hpp +++ /dev/null @@ -1,395 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_mul_exp2_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x3e, 0xd5, 0xd1, 0xf9, - 0x33, 0x97, 0x66, 0x94, - 0x38, 0x3e, 0x56, 0x4b, - 0xee, 0xc4, 0x43, 0x41, - 0x01, 0x00, 0x00, 0x00, - 0x10, 0x06, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x94, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xf4, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xbd, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x1f, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x16, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x13, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp_normal.hpp deleted file mode 100644 index 97208ad9..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp_normal.hpp +++ /dev/null @@ -1,395 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_mul_exp_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0xe9, 0xd1, 0xcd, 0x3a, - 0xdf, 0xcd, 0x2a, 0x96, - 0x8c, 0x49, 0x5f, 0x00, - 0x1b, 0x2e, 0xf4, 0xc8, - 0x01, 0x00, 0x00, 0x00, - 0x10, 0x06, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x94, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xf4, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xbd, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x34, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x16, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x13, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp_premul.hpp deleted file mode 100644 index ed3a7317..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_exp_premul.hpp +++ /dev/null @@ -1,395 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_mul_exp_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x57, 0xdb, 0xaf, 0x26, - 0x96, 0x38, 0x8c, 0xee, - 0x02, 0x0a, 0xbb, 0x81, - 0xec, 0x22, 0x1c, 0x7c, - 0x01, 0x00, 0x00, 0x00, - 0x10, 0x06, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x94, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xf4, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xbd, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x34, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x1f, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x16, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x13, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_linear_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_linear_normal.hpp deleted file mode 100644 index cfa07011..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_linear_normal.hpp +++ /dev/null @@ -1,377 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_mul_linear_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0x10, 0xb6, 0x4c, 0x82, - 0x65, 0x40, 0xd3, 0x18, - 0x8f, 0x0d, 0x0e, 0x25, - 0xb5, 0x0b, 0x9f, 0xd3, - 0x01, 0x00, 0x00, 0x00, - 0xc8, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x4c, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xac, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xab, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x20, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xe2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x89, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x96, 0x07, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x13, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_linear_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_linear_premul.hpp deleted file mode 100644 index 00a3dd90..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_linear_premul.hpp +++ /dev/null @@ -1,377 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_mul_linear_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x86, 0x83, 0x6e, 0xfd, - 0x06, 0xc9, 0x88, 0x36, - 0xe7, 0xea, 0xf2, 0x0f, - 0x4f, 0xf5, 0xa7, 0x55, - 0x01, 0x00, 0x00, 0x00, - 0xc8, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x4c, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xac, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xab, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x20, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x1f, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xe2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x89, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x96, 0x07, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x13, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_none_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_none_normal.hpp deleted file mode 100644 index 0d9d9670..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_none_normal.hpp +++ /dev/null @@ -1,184 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_mul_none_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0xc2, 0x90, 0xf7, 0xaf, - 0xe4, 0x37, 0x4d, 0xc6, - 0x48, 0xb6, 0x8e, 0xd6, - 0x75, 0x27, 0x4e, 0xf6, - 0x01, 0x00, 0x00, 0x00, - 0xc4, 0x02, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd4, 0x00, 0x00, 0x00, - 0x48, 0x01, 0x00, 0x00, - 0x7c, 0x01, 0x00, 0x00, - 0x48, 0x02, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x98, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6e, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x4d, 0x69, - 0x63, 0x72, 0x6f, 0x73, - 0x6f, 0x66, 0x74, 0x20, - 0x28, 0x52, 0x29, 0x20, - 0x48, 0x4c, 0x53, 0x4c, - 0x20, 0x53, 0x68, 0x61, - 0x64, 0x65, 0x72, 0x20, - 0x43, 0x6f, 0x6d, 0x70, - 0x69, 0x6c, 0x65, 0x72, - 0x20, 0x31, 0x30, 0x2e, - 0x31, 0x00, 0xab, 0xab, - 0x49, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x54, 0x45, 0x58, 0x43, - 0x4f, 0x4f, 0x52, 0x44, - 0x00, 0x43, 0x4f, 0x4c, - 0x4f, 0x52, 0x00, 0xab, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xc4, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x31, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_none_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_none_premul.hpp deleted file mode 100644 index 377a28d6..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_mul_none_premul.hpp +++ /dev/null @@ -1,184 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_mul_none_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x35, 0x1f, 0x16, 0x48, - 0xf4, 0x4a, 0xf4, 0x9b, - 0x5c, 0x2c, 0x75, 0x37, - 0xae, 0xd3, 0x29, 0x83, - 0x01, 0x00, 0x00, 0x00, - 0xc4, 0x02, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd4, 0x00, 0x00, 0x00, - 0x48, 0x01, 0x00, 0x00, - 0x7c, 0x01, 0x00, 0x00, - 0x48, 0x02, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x98, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6e, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x4d, 0x69, - 0x63, 0x72, 0x6f, 0x73, - 0x6f, 0x66, 0x74, 0x20, - 0x28, 0x52, 0x29, 0x20, - 0x48, 0x4c, 0x53, 0x4c, - 0x20, 0x53, 0x68, 0x61, - 0x64, 0x65, 0x72, 0x20, - 0x43, 0x6f, 0x6d, 0x70, - 0x69, 0x6c, 0x65, 0x72, - 0x20, 0x31, 0x30, 0x2e, - 0x31, 0x00, 0xab, 0xab, - 0x49, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x54, 0x45, 0x58, 0x43, - 0x4f, 0x4f, 0x52, 0x44, - 0x00, 0x43, 0x4f, 0x4c, - 0x4f, 0x52, 0x00, 0xab, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xc4, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x31, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x1f, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp2_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp2_normal.hpp deleted file mode 100644 index 1575902e..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp2_normal.hpp +++ /dev/null @@ -1,349 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_one_exp2_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0xcb, 0xdf, 0xea, 0x97, - 0x7c, 0x4a, 0x57, 0x8c, - 0xe0, 0x6b, 0x7c, 0x3c, - 0xac, 0x09, 0xe5, 0xf3, - 0x01, 0x00, 0x00, 0x00, - 0x58, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x80, 0x01, 0x00, 0x00, - 0x14, 0x02, 0x00, 0x00, - 0x48, 0x02, 0x00, 0x00, - 0xdc, 0x04, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x44, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x1c, 0x01, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x64, - 0x61, 0x74, 0x61, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x64, 0x61, 0x74, 0x61, - 0x00, 0xab, 0xab, 0xab, - 0x5c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xd8, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xbc, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x08, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x12, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x8c, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xa3, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x1f, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp2_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp2_premul.hpp deleted file mode 100644 index 6d2b0b2f..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp2_premul.hpp +++ /dev/null @@ -1,342 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_one_exp2_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0xc1, 0x1a, 0x4a, 0xca, - 0x10, 0xbc, 0xc5, 0x2d, - 0x5a, 0x42, 0x6c, 0x0d, - 0x1f, 0x57, 0x75, 0xcf, - 0x01, 0x00, 0x00, 0x00, - 0x3c, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x80, 0x01, 0x00, 0x00, - 0x14, 0x02, 0x00, 0x00, - 0x48, 0x02, 0x00, 0x00, - 0xc0, 0x04, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x44, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x1c, 0x01, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x64, - 0x61, 0x74, 0x61, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x64, 0x61, 0x74, 0x61, - 0x00, 0xab, 0xab, 0xab, - 0x5c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xd8, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xbc, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x08, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x12, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x70, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x13, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp_normal.hpp deleted file mode 100644 index a5649fbe..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp_normal.hpp +++ /dev/null @@ -1,349 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_one_exp_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0x49, 0x1f, 0x93, 0x6e, - 0x7b, 0x4d, 0x1f, 0x6d, - 0x22, 0xea, 0x8d, 0x4c, - 0xb8, 0x89, 0x3d, 0x82, - 0x01, 0x00, 0x00, 0x00, - 0x58, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x80, 0x01, 0x00, 0x00, - 0x14, 0x02, 0x00, 0x00, - 0x48, 0x02, 0x00, 0x00, - 0xdc, 0x04, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x44, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x1c, 0x01, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x64, - 0x61, 0x74, 0x61, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x64, 0x61, 0x74, 0x61, - 0x00, 0xab, 0xab, 0xab, - 0x5c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xd8, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xbc, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x08, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x12, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x8c, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xa3, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x34, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x1f, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp_premul.hpp deleted file mode 100644 index efbee9b8..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_exp_premul.hpp +++ /dev/null @@ -1,342 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_one_exp_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x56, 0x9b, 0x31, 0xf7, - 0x00, 0xcd, 0xd7, 0xeb, - 0xae, 0x23, 0xd9, 0x53, - 0x57, 0x52, 0x22, 0x46, - 0x01, 0x00, 0x00, 0x00, - 0x3c, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x80, 0x01, 0x00, 0x00, - 0x14, 0x02, 0x00, 0x00, - 0x48, 0x02, 0x00, 0x00, - 0xc0, 0x04, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x44, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x1c, 0x01, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x64, - 0x61, 0x74, 0x61, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x64, 0x61, 0x74, 0x61, - 0x00, 0xab, 0xab, 0xab, - 0x5c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xd8, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xbc, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x08, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x12, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x70, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x34, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x13, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_linear_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_linear_normal.hpp deleted file mode 100644 index f5a66ce2..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_linear_normal.hpp +++ /dev/null @@ -1,331 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_one_linear_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0x0d, 0x6f, 0x9f, 0xfd, - 0x6c, 0x18, 0x12, 0x3b, - 0xc2, 0xb4, 0x33, 0xe0, - 0xd1, 0x91, 0xf0, 0x9c, - 0x01, 0x00, 0x00, 0x00, - 0x10, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x80, 0x01, 0x00, 0x00, - 0x14, 0x02, 0x00, 0x00, - 0x48, 0x02, 0x00, 0x00, - 0x94, 0x04, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x44, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x1c, 0x01, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x64, - 0x61, 0x74, 0x61, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x64, 0x61, 0x74, 0x61, - 0x00, 0xab, 0xab, 0xab, - 0x5c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xd8, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xbc, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x08, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x12, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x44, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x91, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x20, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xe2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x89, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x1f, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x96, 0x07, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_linear_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_linear_premul.hpp deleted file mode 100644 index 728c717b..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_linear_premul.hpp +++ /dev/null @@ -1,324 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_one_linear_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x2b, 0xc8, 0x30, 0x28, - 0x8a, 0xae, 0x6f, 0x94, - 0x1a, 0x8f, 0x9a, 0xe7, - 0x8a, 0x09, 0x09, 0x62, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x04, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x80, 0x01, 0x00, 0x00, - 0x14, 0x02, 0x00, 0x00, - 0x48, 0x02, 0x00, 0x00, - 0x78, 0x04, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x44, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x1c, 0x01, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x64, - 0x61, 0x74, 0x61, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x64, 0x61, 0x74, 0x61, - 0x00, 0xab, 0xab, 0xab, - 0x5c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xd8, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xbc, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x08, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x12, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc8, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x28, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x8a, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x20, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xe2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x89, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x96, 0x07, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_none_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_none_normal.hpp deleted file mode 100644 index e43e5f97..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_none_normal.hpp +++ /dev/null @@ -1,135 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_one_none_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0xbe, 0x4b, 0x68, 0x9d, - 0x41, 0xe0, 0x11, 0xa2, - 0x4a, 0xee, 0x3a, 0x4a, - 0x86, 0xb7, 0x87, 0xca, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x02, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x84, 0x01, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x44, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x54, 0x45, 0x58, 0x43, - 0x4f, 0x4f, 0x52, 0x44, - 0x00, 0x43, 0x4f, 0x4c, - 0x4f, 0x52, 0x00, 0xab, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x54, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x15, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x1f, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_none_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_none_premul.hpp deleted file mode 100644 index 05a9b66e..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_one_none_premul.hpp +++ /dev/null @@ -1,128 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_one_none_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x71, 0x1a, 0xf0, 0x9c, - 0xa8, 0xaf, 0x88, 0x9a, - 0x01, 0xa3, 0xf5, 0xb4, - 0xe3, 0x57, 0x73, 0xc5, - 0x01, 0x00, 0x00, 0x00, - 0xe4, 0x01, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x68, 0x01, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x44, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x54, 0x45, 0x58, 0x43, - 0x4f, 0x4f, 0x52, 0x44, - 0x00, 0x43, 0x4f, 0x4c, - 0x4f, 0x52, 0x00, 0xab, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x38, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp2_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp2_normal.hpp deleted file mode 100644 index 31b02f4e..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp2_normal.hpp +++ /dev/null @@ -1,385 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_zero_exp2_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0xa2, 0x0e, 0xa3, 0xc3, - 0x3a, 0x2d, 0x9c, 0xbc, - 0x23, 0x4e, 0x38, 0x9e, - 0xdb, 0x2d, 0x9c, 0x19, - 0x01, 0x00, 0x00, 0x00, - 0xe8, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x6c, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xcc, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xb3, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x15, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp2_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp2_premul.hpp deleted file mode 100644 index b839b6dc..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp2_premul.hpp +++ /dev/null @@ -1,378 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_zero_exp2_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x0f, 0x18, 0xbc, 0xc7, - 0x31, 0x43, 0x97, 0x29, - 0x90, 0x0d, 0xfe, 0xcb, - 0xd3, 0xc0, 0x59, 0x2f, - 0x01, 0x00, 0x00, 0x00, - 0xcc, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x50, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xb0, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xac, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp_normal.hpp deleted file mode 100644 index e5a6f2a3..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp_normal.hpp +++ /dev/null @@ -1,385 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_zero_exp_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0x2d, 0xaa, 0xa4, 0xb4, - 0xb9, 0x7c, 0x9b, 0x82, - 0xa2, 0x94, 0x98, 0x2d, - 0xbd, 0x99, 0x51, 0xfa, - 0x01, 0x00, 0x00, 0x00, - 0xe8, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x6c, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xcc, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xb3, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x34, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x15, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp_premul.hpp deleted file mode 100644 index dc7170c6..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_exp_premul.hpp +++ /dev/null @@ -1,378 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_zero_exp_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x46, 0x1e, 0xbf, 0xc4, - 0x3e, 0x53, 0xd2, 0x39, - 0x93, 0x19, 0x3f, 0x98, - 0x78, 0x41, 0xd7, 0xbe, - 0x01, 0x00, 0x00, 0x00, - 0xcc, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x50, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0xb0, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xac, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x3b, 0xaa, 0xb8, 0xbf, - 0x19, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x34, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x14, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_linear_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_linear_normal.hpp deleted file mode 100644 index ffc8e0c2..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_linear_normal.hpp +++ /dev/null @@ -1,367 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_zero_linear_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0x81, 0x54, 0x11, 0xac, - 0x9d, 0x7a, 0xec, 0xdf, - 0x13, 0x64, 0xde, 0x6c, - 0x12, 0x4e, 0xdd, 0x08, - 0x01, 0x00, 0x00, 0x00, - 0xa0, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x24, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x84, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0xa1, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x20, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x12, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_linear_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_linear_premul.hpp deleted file mode 100644 index 9a3292c9..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_linear_premul.hpp +++ /dev/null @@ -1,360 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_zero_linear_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0x95, 0x09, 0x7e, 0x70, - 0xe4, 0x05, 0x52, 0x67, - 0x1c, 0xfe, 0x8f, 0xff, - 0xa7, 0x63, 0xfb, 0xe0, - 0x01, 0x00, 0x00, 0x00, - 0x84, 0x05, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd0, 0x01, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x98, 0x02, 0x00, 0x00, - 0x08, 0x05, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x94, 0x01, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xc4, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6c, 0x01, 0x00, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xa5, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0xae, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x63, 0x61, - 0x6d, 0x65, 0x72, 0x61, - 0x5f, 0x64, 0x61, 0x74, - 0x61, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x64, 0x61, - 0x74, 0x61, 0x00, 0xab, - 0xae, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0xf4, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xba, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x28, 0x01, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0c, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x63, 0x61, 0x6d, 0x65, - 0x72, 0x61, 0x5f, 0x70, - 0x6f, 0x73, 0x00, 0xab, - 0x01, 0x00, 0x03, 0x00, - 0x01, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x62, 0x01, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x18, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x66, 0x6f, 0x67, 0x5f, - 0x63, 0x6f, 0x6c, 0x6f, - 0x72, 0x00, 0x66, 0x6f, - 0x67, 0x5f, 0x72, 0x61, - 0x6e, 0x67, 0x65, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x07, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x68, 0x02, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x9a, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x72, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x82, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x10, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4b, 0x00, 0x00, 0x05, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x09, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x80, 0x20, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0e, 0x20, 0x00, 0x08, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x80, - 0x41, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x32, 0x00, 0x00, 0x0a, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x42, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x2a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0x82, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x80, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x22, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x12, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x1a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xb2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x88, 0x20, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x09, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xa6, 0x0a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x03, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x11, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0e, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_none_normal.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_none_normal.hpp deleted file mode 100644 index 5ffb8cea..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_none_normal.hpp +++ /dev/null @@ -1,174 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_zero_none_normal[] = { - 0x44, 0x58, 0x42, 0x43, - 0x84, 0x62, 0xa5, 0x68, - 0x68, 0x83, 0x58, 0xb2, - 0x51, 0xae, 0x4e, 0x2a, - 0x1c, 0x99, 0x39, 0xfa, - 0x01, 0x00, 0x00, 0x00, - 0x9c, 0x02, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd4, 0x00, 0x00, 0x00, - 0x48, 0x01, 0x00, 0x00, - 0x7c, 0x01, 0x00, 0x00, - 0x20, 0x02, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x98, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6e, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x4d, 0x69, - 0x63, 0x72, 0x6f, 0x73, - 0x6f, 0x66, 0x74, 0x20, - 0x28, 0x52, 0x29, 0x20, - 0x48, 0x4c, 0x53, 0x4c, - 0x20, 0x53, 0x68, 0x61, - 0x64, 0x65, 0x72, 0x20, - 0x43, 0x6f, 0x6d, 0x70, - 0x69, 0x6c, 0x65, 0x72, - 0x20, 0x31, 0x30, 0x2e, - 0x31, 0x00, 0xab, 0xab, - 0x49, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x54, 0x45, 0x58, 0x43, - 0x4f, 0x4f, 0x52, 0x44, - 0x00, 0x43, 0x4f, 0x4c, - 0x4f, 0x52, 0x00, 0xab, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x9c, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x27, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x07, - 0x72, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0xf6, 0x0f, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x02, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3a, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_none_premul.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_none_premul.hpp deleted file mode 100644 index 1df5dc6c..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/pixel_shader_def_zero_none_premul.hpp +++ /dev/null @@ -1,160 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const pixel_shader_def_zero_none_premul[] = { - 0x44, 0x58, 0x42, 0x43, - 0xc9, 0x71, 0x19, 0x2e, - 0xfc, 0x41, 0x0b, 0x4f, - 0x82, 0xf6, 0x08, 0xe6, - 0x89, 0x5d, 0xd2, 0x57, - 0x01, 0x00, 0x00, 0x00, - 0x64, 0x02, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0xd4, 0x00, 0x00, 0x00, - 0x48, 0x01, 0x00, 0x00, - 0x7c, 0x01, 0x00, 0x00, - 0xe8, 0x01, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0x98, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xff, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x6e, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, - 0x73, 0x61, 0x6d, 0x70, - 0x6c, 0x65, 0x72, 0x30, - 0x00, 0x74, 0x65, 0x78, - 0x74, 0x75, 0x72, 0x65, - 0x30, 0x00, 0x4d, 0x69, - 0x63, 0x72, 0x6f, 0x73, - 0x6f, 0x66, 0x74, 0x20, - 0x28, 0x52, 0x29, 0x20, - 0x48, 0x4c, 0x53, 0x4c, - 0x20, 0x53, 0x68, 0x61, - 0x64, 0x65, 0x72, 0x20, - 0x43, 0x6f, 0x6d, 0x70, - 0x69, 0x6c, 0x65, 0x72, - 0x20, 0x31, 0x30, 0x2e, - 0x31, 0x00, 0xab, 0xab, - 0x49, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x54, 0x45, 0x58, 0x43, - 0x4f, 0x4f, 0x52, 0x44, - 0x00, 0x43, 0x4f, 0x4c, - 0x4f, 0x52, 0x00, 0xab, - 0x4f, 0x53, 0x47, 0x4e, - 0x2c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x20, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x54, - 0x41, 0x52, 0x47, 0x45, - 0x54, 0x00, 0xab, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x64, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x19, 0x00, 0x00, 0x00, - 0x5a, 0x00, 0x00, 0x03, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x58, 0x18, 0x00, 0x04, - 0x00, 0x70, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x55, 0x55, 0x00, 0x00, - 0x62, 0x10, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x45, 0x00, 0x00, 0x09, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x7e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x60, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/vertex_shader_def_fog.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/vertex_shader_def_fog.hpp deleted file mode 100644 index 547a49ec..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/vertex_shader_def_fog.hpp +++ /dev/null @@ -1,256 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const vertex_shader_def_fog[] = { - 0x44, 0x58, 0x42, 0x43, - 0xc8, 0x2c, 0x34, 0x50, - 0x63, 0x09, 0xb3, 0x49, - 0xf8, 0x07, 0x20, 0x94, - 0xd0, 0xf5, 0x3d, 0x3b, - 0x01, 0x00, 0x00, 0x00, - 0xe4, 0x03, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, - 0x70, 0x01, 0x00, 0x00, - 0x04, 0x02, 0x00, 0x00, - 0x68, 0x03, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0xc4, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xfe, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x3c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x76, 0x69, 0x65, 0x77, - 0x5f, 0x70, 0x72, 0x6f, - 0x6a, 0x5f, 0x62, 0x75, - 0x66, 0x66, 0x65, 0x72, - 0x00, 0xab, 0xab, 0xab, - 0x3c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x8c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x76, 0x69, 0x65, 0x77, - 0x5f, 0x70, 0x72, 0x6f, - 0x6a, 0x00, 0xab, 0xab, - 0x03, 0x00, 0x03, 0x00, - 0x04, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x68, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x07, 0x07, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x62, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x8c, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x74, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x7d, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x03, 0x0c, 0x00, 0x00, - 0x86, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x53, 0x48, 0x44, 0x52, - 0x5c, 0x01, 0x00, 0x00, - 0x40, 0x00, 0x01, 0x00, - 0x57, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x67, 0x00, 0x00, 0x04, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0x32, 0x20, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x56, 0x15, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xa6, 0x1a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x72, 0x20, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x12, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x82, 0x20, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x40, 0x00, 0x00, - 0x00, 0x00, 0x80, 0x3f, - 0x36, 0x00, 0x00, 0x05, - 0x32, 0x20, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0xf2, 0x20, 0x10, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x07, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/Shader/generated/luastg/sub/renderer/vertex_shader_def_none.hpp b/LuaSTG/Shader/generated/luastg/sub/renderer/vertex_shader_def_none.hpp deleted file mode 100644 index 2970252f..00000000 --- a/LuaSTG/Shader/generated/luastg/sub/renderer/vertex_shader_def_none.hpp +++ /dev/null @@ -1,235 +0,0 @@ -// This is a file generated by the compiler, DO NOT directly modify this file -#pragma once -namespace luastg::sub::renderer -{ - static unsigned char const vertex_shader_def_none[] = { - 0x44, 0x58, 0x42, 0x43, - 0xd5, 0x13, 0x36, 0x38, - 0x7a, 0x06, 0x96, 0x22, - 0x4c, 0x6a, 0x8f, 0xa5, - 0x20, 0x80, 0x69, 0x0e, - 0x01, 0x00, 0x00, 0x00, - 0x90, 0x03, 0x00, 0x00, - 0x05, 0x00, 0x00, 0x00, - 0x34, 0x00, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, - 0x70, 0x01, 0x00, 0x00, - 0xe4, 0x01, 0x00, 0x00, - 0x14, 0x03, 0x00, 0x00, - 0x52, 0x44, 0x45, 0x46, - 0xc4, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x1c, 0x00, 0x00, 0x00, - 0x00, 0x04, 0xfe, 0xff, - 0x00, 0x8b, 0x04, 0x00, - 0x9c, 0x00, 0x00, 0x00, - 0x3c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x76, 0x69, 0x65, 0x77, - 0x5f, 0x70, 0x72, 0x6f, - 0x6a, 0x5f, 0x62, 0x75, - 0x66, 0x66, 0x65, 0x72, - 0x00, 0xab, 0xab, 0xab, - 0x3c, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x80, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x8c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x76, 0x69, 0x65, 0x77, - 0x5f, 0x70, 0x72, 0x6f, - 0x6a, 0x00, 0xab, 0xab, - 0x03, 0x00, 0x03, 0x00, - 0x04, 0x00, 0x04, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x4d, 0x69, 0x63, 0x72, - 0x6f, 0x73, 0x6f, 0x66, - 0x74, 0x20, 0x28, 0x52, - 0x29, 0x20, 0x48, 0x4c, - 0x53, 0x4c, 0x20, 0x53, - 0x68, 0x61, 0x64, 0x65, - 0x72, 0x20, 0x43, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, - 0x65, 0x72, 0x20, 0x31, - 0x30, 0x2e, 0x31, 0x00, - 0x49, 0x53, 0x47, 0x4e, - 0x68, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x07, 0x07, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x03, 0x00, 0x00, - 0x62, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x0f, 0x00, 0x00, - 0x50, 0x4f, 0x53, 0x49, - 0x54, 0x49, 0x4f, 0x4e, - 0x00, 0x54, 0x45, 0x58, - 0x43, 0x4f, 0x4f, 0x52, - 0x44, 0x00, 0x43, 0x4f, - 0x4c, 0x4f, 0x52, 0x00, - 0x4f, 0x53, 0x47, 0x4e, - 0x6c, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x08, 0x00, 0x00, 0x00, - 0x50, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x5c, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x03, 0x0c, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x0f, 0x00, 0x00, 0x00, - 0x53, 0x56, 0x5f, 0x50, - 0x4f, 0x53, 0x49, 0x54, - 0x49, 0x4f, 0x4e, 0x00, - 0x54, 0x45, 0x58, 0x43, - 0x4f, 0x4f, 0x52, 0x44, - 0x00, 0x43, 0x4f, 0x4c, - 0x4f, 0x52, 0x00, 0xab, - 0x53, 0x48, 0x44, 0x52, - 0x28, 0x01, 0x00, 0x00, - 0x40, 0x00, 0x01, 0x00, - 0x4a, 0x00, 0x00, 0x00, - 0x59, 0x00, 0x00, 0x04, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x03, - 0x72, 0x10, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x03, - 0x32, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x5f, 0x00, 0x00, 0x03, - 0xf2, 0x10, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x67, 0x00, 0x00, 0x04, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0x32, 0x20, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x65, 0x00, 0x00, 0x03, - 0xf2, 0x20, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x68, 0x00, 0x00, 0x02, - 0x01, 0x00, 0x00, 0x00, - 0x38, 0x00, 0x00, 0x08, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x56, 0x15, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x10, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x32, 0x00, 0x00, 0x0a, - 0xf2, 0x00, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0xa6, 0x1a, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x08, - 0xf2, 0x20, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x0e, 0x10, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x46, 0x8e, 0x20, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0x32, 0x20, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x46, 0x10, 0x10, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x36, 0x00, 0x00, 0x05, - 0xf2, 0x20, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x46, 0x1e, 0x10, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x00, 0x01, - 0x53, 0x54, 0x41, 0x54, - 0x74, 0x00, 0x00, 0x00, - 0x07, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x06, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x01, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x02, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - }; -} diff --git a/LuaSTG/shaders.cmake b/LuaSTG/shaders.cmake deleted file mode 100644 index 8cf5207a..00000000 --- a/LuaSTG/shaders.cmake +++ /dev/null @@ -1,5 +0,0 @@ -add_library(GeneratedShaderHeaders INTERFACE) -target_include_directories(GeneratedShaderHeaders -INTERFACE - ${CMAKE_CURRENT_LIST_DIR}/Shader/generated -) diff --git a/cmake/luastg_options.cmake b/cmake/luastg_options.cmake index df4741d4..b40386a1 100644 --- a/cmake/luastg_options.cmake +++ b/cmake/luastg_options.cmake @@ -131,6 +131,15 @@ luastg_cmake_option( unset(use_wic) unset(image_library_enable) +# LuaSTG - Graphics + +luastg_cmake_option( + NAME LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE + TYPE BOOL + HELP "LuaSTG: Graphics: Enable debug layer" + VALUE TRUE +) + # LuaSTG - Steam API luastg_cmake_option( diff --git a/engine/CMakeLists.txt b/engine/CMakeLists.txt index c36c17d6..017682f1 100644 --- a/engine/CMakeLists.txt +++ b/engine/CMakeLists.txt @@ -16,3 +16,5 @@ add_subdirectory(shell-integration) add_subdirectory(audio) add_subdirectory(image) add_subdirectory(font) +add_subdirectory(window-system) +add_subdirectory(graphics) diff --git a/engine/audio/core/AudioDecoder.hpp b/engine/audio/core/AudioDecoder.hpp index 4f19333b..d3bded5f 100644 --- a/engine/audio/core/AudioDecoder.hpp +++ b/engine/audio/core/AudioDecoder.hpp @@ -3,7 +3,7 @@ #include "core/Data.hpp" namespace core { - struct CORE_NO_VIRTUAL_TABLE IAudioDecoder : IReferenceCounted { + CORE_INTERFACE IAudioDecoder : IReferenceCounted { [[nodiscard]] virtual uint16_t getSampleSize() const noexcept = 0; // 1byte(8bit) 2bytes(16bits) 3byte(24bits) 4byte(32bits) [[nodiscard]] virtual uint16_t getChannelCount() const noexcept = 0; // 1channel 2channels [[nodiscard]] virtual uint16_t getFrameSize() const noexcept = 0; // = getChannelCount() * getSampleSize() diff --git a/engine/audio/core/AudioEngine.hpp b/engine/audio/core/AudioEngine.hpp index d8e81627..f56600af 100644 --- a/engine/audio/core/AudioEngine.hpp +++ b/engine/audio/core/AudioEngine.hpp @@ -12,12 +12,12 @@ namespace core { count = 3, }; - struct CORE_NO_VIRTUAL_TABLE IAudioEngineEventListener { + CORE_INTERFACE IAudioEngineEventListener { virtual void onAudioEngineCreate() = 0; virtual void onAudioEngineDestroy() = 0; }; - struct CORE_NO_VIRTUAL_TABLE IAudioEngine : IReferenceCounted { + CORE_INTERFACE IAudioEngine : IReferenceCounted { virtual void addEventListener(IAudioEngineEventListener* listener) = 0; virtual void removeEventListener(IAudioEngineEventListener* listener) = 0; diff --git a/engine/audio/core/AudioPlayer.hpp b/engine/audio/core/AudioPlayer.hpp index f030a9f4..55829985 100644 --- a/engine/audio/core/AudioPlayer.hpp +++ b/engine/audio/core/AudioPlayer.hpp @@ -14,7 +14,7 @@ namespace core { paused = 2, }; - struct CORE_NO_VIRTUAL_TABLE IAudioPlayer : IReferenceCounted { + CORE_INTERFACE IAudioPlayer : IReferenceCounted { virtual bool play(double seconds) = 0; virtual bool pause() = 0; virtual bool resume() = 0; diff --git a/engine/embedded-file-system/luastg/EmbeddedFileSystem.hpp b/engine/embedded-file-system/luastg/EmbeddedFileSystem.hpp index 0aaedd0a..57c10c8e 100644 --- a/engine/embedded-file-system/luastg/EmbeddedFileSystem.hpp +++ b/engine/embedded-file-system/luastg/EmbeddedFileSystem.hpp @@ -2,7 +2,7 @@ #include "core/FileSystem.hpp" namespace luastg { - struct CORE_NO_VIRTUAL_TABLE IEmbeddedFileSystem : core::IFileSystem { + CORE_INTERFACE IEmbeddedFileSystem : core::IFileSystem { static IEmbeddedFileSystem* getInstance(); }; } diff --git a/engine/file-system/core/Data.hpp b/engine/file-system/core/Data.hpp index 41d72818..3a6e221f 100644 --- a/engine/file-system/core/Data.hpp +++ b/engine/file-system/core/Data.hpp @@ -2,7 +2,7 @@ #include "core/ReferenceCounted.hpp" namespace core { - struct CORE_NO_VIRTUAL_TABLE IData : IReferenceCounted { + CORE_INTERFACE IData : IReferenceCounted { virtual void* data() = 0; virtual size_t size() = 0; diff --git a/engine/file-system/core/FileSystem.hpp b/engine/file-system/core/FileSystem.hpp index 23a8f71c..6d2f8fd6 100644 --- a/engine/file-system/core/FileSystem.hpp +++ b/engine/file-system/core/FileSystem.hpp @@ -9,7 +9,7 @@ namespace core { directory, }; - struct CORE_NO_VIRTUAL_TABLE IFileSystemEnumerator : IReferenceCounted { + CORE_INTERFACE IFileSystemEnumerator : IReferenceCounted { virtual bool next() = 0; virtual std::string_view getName() = 0; virtual FileSystemNodeType getNodeType() = 0; @@ -22,7 +22,7 @@ namespace core { // https://www.luastg-sub.com/core.IFileSystemEnumerator template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("49e754fe-15af-58ac-9632-d9ed06b3f0d4"); } - struct CORE_NO_VIRTUAL_TABLE IFileSystem : IReferenceCounted { + CORE_INTERFACE IFileSystem : IReferenceCounted { virtual bool hasNode(std::string_view const& name) = 0; virtual FileSystemNodeType getNodeType(std::string_view const& name) = 0; virtual bool hasFile(std::string_view const& name) = 0; @@ -38,7 +38,7 @@ namespace core { // https://www.luastg-sub.com/core.IFileSystem template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("61c1bc5e-6e1e-5fe2-958c-527e85138010"); } - struct CORE_NO_VIRTUAL_TABLE IFileSystemOS : IFileSystem { + CORE_INTERFACE IFileSystemOS : IFileSystem { static IFileSystemOS* getInstance(); }; @@ -47,7 +47,7 @@ namespace core { // https://www.luastg-sub.com/core.IFileSystemOS template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("f21693cb-e71a-5877-9786-7815d4af4ffd"); } - struct CORE_NO_VIRTUAL_TABLE IFileSystemArchive : IFileSystem { + CORE_INTERFACE IFileSystemArchive : IFileSystem { virtual std::string_view getArchivePath() = 0; virtual bool setPassword(std::string_view const& password) = 0; @@ -59,7 +59,7 @@ namespace core { // https://www.luastg-sub.com/core.IFileSystemArchive template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("a36e930b-4fb8-5061-b88b-127e5200474e"); } - struct CORE_NO_VIRTUAL_TABLE IFileSystemFileSystemEnumerator : IReferenceCounted { + CORE_INTERFACE IFileSystemFileSystemEnumerator : IReferenceCounted { virtual bool next(IFileSystem** output) = 0; }; diff --git a/engine/file-system/core/FileSystemWatcher.hpp b/engine/file-system/core/FileSystemWatcher.hpp index c9305bad..5d0b7a74 100644 --- a/engine/file-system/core/FileSystemWatcher.hpp +++ b/engine/file-system/core/FileSystemWatcher.hpp @@ -69,7 +69,7 @@ namespace core { } }; - struct CORE_NO_VIRTUAL_TABLE IMessageQueueBasedFileSystemWatcher : IReferenceCounted { + CORE_INTERFACE IMessageQueueBasedFileSystemWatcher : IReferenceCounted { virtual bool next(FileNotifyInformation* info) = 0; static bool create(std::string_view const& path, IMessageQueueBasedFileSystemWatcher** object); diff --git a/engine/font/CMakeLists.txt b/engine/font/CMakeLists.txt index c585a404..f9591905 100644 --- a/engine/font/CMakeLists.txt +++ b/engine/font/CMakeLists.txt @@ -15,6 +15,9 @@ source_group(TREE ${CMAKE_CURRENT_LIST_DIR} FILES ${lib_src}) add_library(${lib_name}) luastg_target_common_options(${lib_name}) luastg_target_more_warning(${lib_name}) +if (LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE) + target_compile_definitions(${lib_name} PRIVATE LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE) +endif () target_include_directories(${lib_name} PUBLIC .) target_sources(${lib_name} PRIVATE ${lib_src}) target_link_libraries(${lib_name} PRIVATE options_compile_utf8) diff --git a/engine/font/backend/DirectWriteTextLayout.cpp b/engine/font/backend/DirectWriteTextLayout.cpp index 9d119fb6..c920868b 100644 --- a/engine/font/backend/DirectWriteTextLayout.cpp +++ b/engine/font/backend/DirectWriteTextLayout.cpp @@ -42,10 +42,10 @@ namespace { ID2D1Factory* getRendererFactory() { if (!s_d2d1_factory) { constexpr D2D1_FACTORY_OPTIONS options{ - #ifdef NDEBUG - .debugLevel = D2D1_DEBUG_LEVEL_NONE, - #else + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) .debugLevel = D2D1_DEBUG_LEVEL_INFORMATION, + #else + .debugLevel = D2D1_DEBUG_LEVEL_NONE, #endif }; win32::check_hresult_throw_if_failed( @@ -234,6 +234,7 @@ namespace core { } image_description.format = ImageFormat::b8g8r8a8_normalized; image_description.color_space = ImageColorSpace::srgb_gamma_2_2; + image_description.alpha_mode = ImageAlphaMode::premultiplied; if (!m_image || m_image->getDescription()->size != image_description.size) { if (!ImageFactory::create(image_description, m_image.put())) { diff --git a/engine/graphics/CMakeLists.txt b/engine/graphics/CMakeLists.txt new file mode 100644 index 00000000..bd56540c --- /dev/null +++ b/engine/graphics/CMakeLists.txt @@ -0,0 +1,69 @@ +# Graphics + +set(lib_name "Core.Graphics") + +file(GLOB_RECURSE lib_src RELATIVE ${CMAKE_CURRENT_LIST_DIR} + core/*.hpp + core/*.cpp + d3d11/*.hpp + d3d11/*.cpp +) +source_group(TREE ${CMAKE_CURRENT_LIST_DIR} FILES ${lib_src}) + +add_library(${lib_name} STATIC) +luastg_target_common_options(${lib_name}) +luastg_target_more_warning(${lib_name}) +if (LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE) + target_compile_definitions(${lib_name} PRIVATE LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE) +endif () +target_include_directories(${lib_name} PUBLIC .) +target_sources(${lib_name} PRIVATE ${lib_src}) +target_precompile_headers(${lib_name} PRIVATE + d3d11/pch.h +) +target_link_libraries(${lib_name} PRIVATE options_compile_utf8) +target_link_libraries(${lib_name} PUBLIC + # Core + Core.ReferenceCounted + Core.Configuration + Core.FileSystem + Core.Logging + Core.Math + Core.Image + win32 + # debug + TracyAPI + # util + utility + utf8 + simdutf::simdutf + # win32 + winmm.lib + imm32.lib + # dx + dxguid.lib + dxgi.lib + d3d11.lib + Microsoft.Windows.ImplementationLibrary + Microsoft::DirectXTexMini + libqoi + # math + xmath + # text + Freetype::Freetype + # model + tinygltf + # engine + Core.Math + Core.String + Core.Configuration + Core.ReferenceCounted + Core.FileSystem + Core.Image + Core.Font + Core.WindowSystem + win32 + beautiful_win32_api +) + +set_target_properties(${lib_name} PROPERTIES FOLDER engine) diff --git a/engine/graphics/core/DepthStencilBuffer.hpp b/engine/graphics/core/DepthStencilBuffer.hpp new file mode 100644 index 00000000..2b0885ff --- /dev/null +++ b/engine/graphics/core/DepthStencilBuffer.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "core/ReferenceCounted.hpp" +#include "core/Vector2.hpp" + +namespace core { + CORE_INTERFACE IDepthStencilBuffer : IReferenceCounted { + virtual void* getNativeResource() const noexcept = 0; + virtual void* getNativeView() const noexcept = 0; + + virtual Vector2U getSize() const noexcept = 0; + virtual bool setSize(Vector2U size) = 0; + }; + + CORE_INTERFACE_ID(IDepthStencilBuffer, "2c92426c-9703-57aa-88e6-073957b0d92c"); +} diff --git a/LuaSTG/Core/Graphics/Common/FreeTypeGlyphManager.cpp b/engine/graphics/core/Graphics/Common/FreeTypeGlyphManager.cpp similarity index 96% rename from LuaSTG/Core/Graphics/Common/FreeTypeGlyphManager.cpp rename to engine/graphics/core/Graphics/Common/FreeTypeGlyphManager.cpp index a1a5a654..4adbb307 100644 --- a/LuaSTG/Core/Graphics/Common/FreeTypeGlyphManager.cpp +++ b/engine/graphics/core/Graphics/Common/FreeTypeGlyphManager.cpp @@ -1,4 +1,4 @@ -#include "Core/Graphics/Common/FreeTypeGlyphManager.hpp" +#include "core/Graphics/Common/FreeTypeGlyphManager.hpp" #include "core/FileSystem.hpp" #include "utility/utf.hpp" #include "utf8.hpp" @@ -85,12 +85,12 @@ namespace core::Graphics::Common { } } namespace core::Graphics::Common { - // IDeviceEventListener + // IGraphicsDeviceEventListener - void FreeTypeGlyphManager::onDeviceCreate() { + void FreeTypeGlyphManager::onGraphicsDeviceCreate() { // 等一个幸运儿调用 flush } - void FreeTypeGlyphManager::onDeviceDestroy() { + void FreeTypeGlyphManager::onGraphicsDeviceDestroy() { // 全标记为脏 for (auto& t : m_tex) { t.dirty_l = 0; @@ -179,7 +179,7 @@ namespace core::Graphics::Common { // FreeTypeGlyphManager - FreeTypeGlyphManager::FreeTypeGlyphManager(IDevice* const p_device, TrueTypeFontInfo const* const p_arr_info, size_t const info_count) + FreeTypeGlyphManager::FreeTypeGlyphManager(IGraphicsDevice* const p_device, TrueTypeFontInfo const* const p_arr_info, size_t const info_count) : m_device(p_device) { if (!openFonts(p_arr_info, info_count)) { throw std::runtime_error("FreeTypeGlyphManager::FreeTypeGlyphManager (openFonts)"); @@ -437,7 +437,7 @@ namespace core::Graphics::Common { } } namespace core::Graphics { - bool IGlyphManager::create(IDevice* const p_device, TrueTypeFontInfo const* const p_arr_info, size_t const info_count, IGlyphManager** const output) { + bool IGlyphManager::create(IGraphicsDevice* const p_device, TrueTypeFontInfo const* const p_arr_info, size_t const info_count, IGlyphManager** const output) { try { *output = new Common::FreeTypeGlyphManager(p_device, p_arr_info, info_count); return true; diff --git a/LuaSTG/Core/Graphics/Common/FreeTypeGlyphManager.hpp b/engine/graphics/core/Graphics/Common/FreeTypeGlyphManager.hpp similarity index 89% rename from LuaSTG/Core/Graphics/Common/FreeTypeGlyphManager.hpp rename to engine/graphics/core/Graphics/Common/FreeTypeGlyphManager.hpp index 1466d6eb..3ee142ef 100644 --- a/LuaSTG/Core/Graphics/Common/FreeTypeGlyphManager.hpp +++ b/engine/graphics/core/Graphics/Common/FreeTypeGlyphManager.hpp @@ -1,7 +1,7 @@ #pragma once #include "core/SmartReference.hpp" #include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Font.hpp" +#include "core/Graphics/Font.hpp" #include "ft2build.h" #include FT_FREETYPE_H @@ -62,12 +62,12 @@ namespace core::Graphics::Common { class FreeTypeGlyphManager final : public implement::ReferenceCounted - , public IDeviceEventListener { + , public IGraphicsDeviceEventListener { public: - // IDeviceEventListener + // IGraphicsDeviceEventListener - void onDeviceCreate() override; - void onDeviceDestroy() override; + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; // IGlyphManager @@ -86,7 +86,7 @@ namespace core::Graphics::Common { // FreeTypeGlyphManager - FreeTypeGlyphManager(IDevice* p_device, TrueTypeFontInfo const* p_arr_info, size_t info_count); + FreeTypeGlyphManager(IGraphicsDevice* p_device, TrueTypeFontInfo const* p_arr_info, size_t info_count); FreeTypeGlyphManager(FreeTypeGlyphManager const&) = delete; FreeTypeGlyphManager(FreeTypeGlyphManager&&) = delete; ~FreeTypeGlyphManager(); @@ -103,7 +103,7 @@ namespace core::Graphics::Common { GlyphCacheInfo* getGlyphCacheInfo(uint32_t codepoint); bool renderCache(uint32_t codepoint); - SmartReference m_device; + SmartReference m_device; FreeTypeFontCommonInfo m_common_info; std::vector m_font; std::vector m_tex; diff --git a/LuaSTG/Core/Graphics/Common/Sprite.cpp b/engine/graphics/core/Graphics/Common/Sprite.cpp similarity index 95% rename from LuaSTG/Core/Graphics/Common/Sprite.cpp rename to engine/graphics/core/Graphics/Common/Sprite.cpp index 3e7dc7c5..316e65fc 100644 --- a/LuaSTG/Core/Graphics/Common/Sprite.cpp +++ b/engine/graphics/core/Graphics/Common/Sprite.cpp @@ -1,4 +1,4 @@ -#include "Core/Graphics/Common/Sprite.hpp" +#include "core/Graphics/Common/Sprite.hpp" namespace core::Graphics::Common { void Sprite::setTextureRect(RectF const& rc) { diff --git a/LuaSTG/Core/Graphics/Common/Sprite.hpp b/engine/graphics/core/Graphics/Common/Sprite.hpp similarity index 97% rename from LuaSTG/Core/Graphics/Common/Sprite.hpp rename to engine/graphics/core/Graphics/Common/Sprite.hpp index 9d40c73b..c0efbd0c 100644 --- a/LuaSTG/Core/Graphics/Common/Sprite.hpp +++ b/engine/graphics/core/Graphics/Common/Sprite.hpp @@ -1,7 +1,7 @@ #pragma once #include "core/SmartReference.hpp" #include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Sprite.hpp" +#include "core/Graphics/Sprite.hpp" namespace core::Graphics::Common { class Sprite final : public implement::ReferenceCounted { diff --git a/LuaSTG/Core/Graphics/Common/SpriteRenderer.cpp b/engine/graphics/core/Graphics/Common/SpriteRenderer.cpp similarity index 98% rename from LuaSTG/Core/Graphics/Common/SpriteRenderer.cpp rename to engine/graphics/core/Graphics/Common/SpriteRenderer.cpp index 24dd561a..cf870752 100644 --- a/LuaSTG/Core/Graphics/Common/SpriteRenderer.cpp +++ b/engine/graphics/core/Graphics/Common/SpriteRenderer.cpp @@ -1,4 +1,4 @@ -#include "Core/Graphics/Common/SpriteRenderer.hpp" +#include "core/Graphics/Common/SpriteRenderer.hpp" #include namespace core::Graphics::Common { @@ -89,7 +89,7 @@ namespace core::Graphics::Common { m_vertex[3].y += position.y; } void SpriteRenderer::setSprite(ISprite* const sprite) { - assert(sprite); + //assert(sprite); m_sprite = sprite; if (m_sprite) { auto const rect = m_sprite->getTextureRect(); diff --git a/LuaSTG/Core/Graphics/Common/SpriteRenderer.hpp b/engine/graphics/core/Graphics/Common/SpriteRenderer.hpp similarity index 97% rename from LuaSTG/Core/Graphics/Common/SpriteRenderer.hpp rename to engine/graphics/core/Graphics/Common/SpriteRenderer.hpp index f6a196ad..6da264f8 100644 --- a/LuaSTG/Core/Graphics/Common/SpriteRenderer.hpp +++ b/engine/graphics/core/Graphics/Common/SpriteRenderer.hpp @@ -1,7 +1,7 @@ #pragma once #include "core/SmartReference.hpp" #include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Sprite.hpp" +#include "core/Graphics/Sprite.hpp" namespace core::Graphics::Common { class SpriteRenderer final diff --git a/LuaSTG/Core/Graphics/Common/TextLayout-TextRenderer.md b/engine/graphics/core/Graphics/Common/TextLayout-TextRenderer.md similarity index 100% rename from LuaSTG/Core/Graphics/Common/TextLayout-TextRenderer.md rename to engine/graphics/core/Graphics/Common/TextLayout-TextRenderer.md diff --git a/LuaSTG/Core/Graphics/Common/TextRenderer.cpp b/engine/graphics/core/Graphics/Common/TextRenderer.cpp similarity index 99% rename from LuaSTG/Core/Graphics/Common/TextRenderer.cpp rename to engine/graphics/core/Graphics/Common/TextRenderer.cpp index 042564f1..7a008e44 100644 --- a/LuaSTG/Core/Graphics/Common/TextRenderer.cpp +++ b/engine/graphics/core/Graphics/Common/TextRenderer.cpp @@ -1,4 +1,4 @@ -#include "Core/Graphics/Common/TextRenderer.hpp" +#include "core/Graphics/Common/TextRenderer.hpp" #include "utility/utf.hpp" namespace core::Graphics::Common { diff --git a/LuaSTG/Core/Graphics/Common/TextRenderer.hpp b/engine/graphics/core/Graphics/Common/TextRenderer.hpp similarity index 98% rename from LuaSTG/Core/Graphics/Common/TextRenderer.hpp rename to engine/graphics/core/Graphics/Common/TextRenderer.hpp index 43c2d6d0..ceac2ed3 100644 --- a/LuaSTG/Core/Graphics/Common/TextRenderer.hpp +++ b/engine/graphics/core/Graphics/Common/TextRenderer.hpp @@ -1,7 +1,7 @@ #pragma once #include "core/SmartReference.hpp" #include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Font.hpp" +#include "core/Graphics/Font.hpp" namespace core::Graphics::Common { diff --git a/LuaSTG/Core/Graphics/Common/TextRenderer2.cpp b/engine/graphics/core/Graphics/Common/TextRenderer2.cpp similarity index 94% rename from LuaSTG/Core/Graphics/Common/TextRenderer2.cpp rename to engine/graphics/core/Graphics/Common/TextRenderer2.cpp index c1ffc469..8921b988 100644 --- a/LuaSTG/Core/Graphics/Common/TextRenderer2.cpp +++ b/engine/graphics/core/Graphics/Common/TextRenderer2.cpp @@ -1,4 +1,4 @@ -#include "Core/Graphics/Common/TextRenderer2.hpp" +#include "core/Graphics/Common/TextRenderer2.hpp" #include namespace core::Graphics { @@ -56,7 +56,7 @@ namespace core::Graphics { // TextRenderer2 - bool TextRenderer2::initialize(IDevice* const device) { + bool TextRenderer2::initialize(IGraphicsDevice* const device) { assert(device != nullptr); m_device = device; if (!ISpriteRenderer::create(m_sprite_renderer.put())) { @@ -116,7 +116,7 @@ namespace core::Graphics { } namespace core::Graphics { - bool ITextRenderer2::create(IDevice* const device, ITextRenderer2** const output) { + bool ITextRenderer2::create(IGraphicsDevice* const device, ITextRenderer2** const output) { if (device == nullptr || output == nullptr) { assert(false); return false; diff --git a/LuaSTG/Core/Graphics/Common/TextRenderer2.hpp b/engine/graphics/core/Graphics/Common/TextRenderer2.hpp similarity index 89% rename from LuaSTG/Core/Graphics/Common/TextRenderer2.hpp rename to engine/graphics/core/Graphics/Common/TextRenderer2.hpp index 6891bd30..b0aa519b 100644 --- a/LuaSTG/Core/Graphics/Common/TextRenderer2.hpp +++ b/engine/graphics/core/Graphics/Common/TextRenderer2.hpp @@ -1,6 +1,6 @@ #pragma once -#include "Core/Graphics/Font.hpp" -#include "Core/Graphics/Sprite.hpp" +#include "core/Graphics/Font.hpp" +#include "core/Graphics/Sprite.hpp" #include "core/SmartReference.hpp" #include "core/implement/ReferenceCounted.hpp" #include "core/TextLayout.hpp" @@ -24,12 +24,12 @@ namespace core::Graphics { // TextRenderer2 - bool initialize(IDevice* device); + bool initialize(IGraphicsDevice* device); bool update(); private: SmartReference m_text_layout; - SmartReference m_device; + SmartReference m_device; SmartReference m_texture; SmartReference m_sprite; SmartReference m_sprite_renderer; diff --git a/engine/graphics/core/Graphics/Device.hpp b/engine/graphics/core/Graphics/Device.hpp new file mode 100644 index 00000000..bf0c3c06 --- /dev/null +++ b/engine/graphics/core/Graphics/Device.hpp @@ -0,0 +1,54 @@ +#pragma once +#include "core/Vector2.hpp" +#include "core/Rect.hpp" +#include "core/ReferenceCounted.hpp" +#include "core/Data.hpp" +#include "core/ImmutableString.hpp" +#include "core/Image.hpp" +#include "core/GraphicsSampler.hpp" + +#define LUASTG_ENABLE_DIRECT2D + +namespace core::Graphics +{ + struct ITexture2D : IReferenceCounted + { + virtual void* getNativeHandle() const noexcept = 0; + + virtual bool isDynamic() const noexcept = 0; + virtual bool isPremultipliedAlpha() const noexcept = 0; + virtual void setPremultipliedAlpha(bool v) = 0; + virtual Vector2U getSize() const noexcept = 0; + virtual bool setSize(Vector2U size) = 0; + + virtual bool uploadPixelData(RectU rc, void const* data, uint32_t pitch) = 0; + virtual void setImage(IImage* image) = 0; + + virtual bool saveToFile(StringView path) = 0; + + virtual void setSamplerState(IGraphicsSampler* p_sampler) = 0; + // Might be nullptr + virtual IGraphicsSampler* getSamplerState() const noexcept = 0; + }; + + struct IRenderTarget : IReferenceCounted + { + virtual void* getNativeHandle() const noexcept = 0; + virtual void* getNativeBitmapHandle() const noexcept = 0; + + virtual bool setSize(Vector2U size) = 0; + virtual ITexture2D* getTexture() const noexcept = 0; + }; +} + +namespace core { + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.ITexture2D + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("5477054a-61c9-5071-9339-a9959e538a21"); } + + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.IRenderTarget + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("2753f336-07b6-5e69-95b1-46f1125531fa"); } +} diff --git a/LuaSTG/Core/Graphics/Direct3D11/Constants.hpp b/engine/graphics/core/Graphics/Direct3D11/Constants.hpp similarity index 100% rename from LuaSTG/Core/Graphics/Direct3D11/Constants.hpp rename to engine/graphics/core/Graphics/Direct3D11/Constants.hpp diff --git a/LuaSTG/Core/Graphics/Direct3D11/LetterBoxingRenderer.cpp b/engine/graphics/core/Graphics/Direct3D11/LetterBoxingRenderer.cpp similarity index 84% rename from LuaSTG/Core/Graphics/Direct3D11/LetterBoxingRenderer.cpp rename to engine/graphics/core/Graphics/Direct3D11/LetterBoxingRenderer.cpp index f490c8a3..45b136fb 100644 --- a/LuaSTG/Core/Graphics/Direct3D11/LetterBoxingRenderer.cpp +++ b/engine/graphics/core/Graphics/Direct3D11/LetterBoxingRenderer.cpp @@ -1,423 +1,423 @@ -#include "Core/Graphics/Direct3D11/LetterBoxingRenderer.hpp" -#include "Core/i18n.hpp" - -#define HRNew HRESULT hr = S_OK; -#define HRGet hr = gHR -#define HRCheckCallReturnBool(x) if (FAILED(hr)) { i18n_core_system_call_report_error(x); return false; } - -namespace core::Graphics::Direct3D11 -{ - bool LetterBoxingRenderer::CreateResource() - { - assert(d3d11_device); - assert(d3d11_device_context); - - HRNew; - - /* - cbuffer TransformBuffer : register(b0) - { - float4x4 mvp; - }; - - struct ShaderInput - { - float2 pos : POSITION; - float2 uv : TEXCOORD; - }; - - struct ShaderOutput - { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD; - }; - - ShaderOutput main(ShaderInput input) - { - ShaderOutput output; - output.pos = mul(float4(input.pos, 0.0f, 1.0f), mvp); - output.uv = input.uv; - return output; - } - */ - static unsigned char const vertex_shader[] = { 68, 88, 66, 67, 59, 64, 214, 227, 106, 29, 100, 169, 229, 180, 69, 232, 69, 58, 239, 19, 1, 0, 0, 0, 56, 3, 0, 0, 5, 0, 0, 0, 52, 0, 0, 0, 244, 0, 0, 0, 72, 1, 0, 0, 160, 1, 0, 0, 188, 2, 0, 0, 82, 68, 69, 70, 184, 0, 0, 0, 1, 0, 0, 0, 76, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 0, 4, 254, 255, 0, 1, 0, 0, 144, 0, 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 84, 114, 97, 110, 115, 102, 111, 114, 109, 66, 117, 102, 102, 101, 114, 0, 60, 0, 0, 0, 1, 0, 0, 0, 100, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 124, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 2, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 109, 118, 112, 0, 3, 0, 3, 0, 4, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 73, 83, 71, 78, 76, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 3, 0, 0, 80, 79, 83, 73, 84, 73, 79, 78, 0, 84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 79, 83, 71, 78, 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 12, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0, 84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 171, 83, 72, 68, 82, 20, 1, 0, 0, 64, 0, 1, 0, 69, 0, 0, 0, 89, 0, 0, 4, 70, 142, 32, 0, 0, 0, 0, 0, 4, 0, 0, 0, 95, 0, 0, 3, 50, 16, 16, 0, 0, 0, 0, 0, 95, 0, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0, 103, 0, 0, 4, 242, 32, 16, 0, 0, 0, 0, 0, 1, 0, 0, 0, 101, 0, 0, 3, 50, 32, 16, 0, 1, 0, 0, 0, 104, 0, 0, 2, 1, 0, 0, 0, 54, 0, 0, 5, 50, 0, 16, 0, 0, 0, 0, 0, 70, 16, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, 66, 0, 16, 0, 0, 0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 16, 0, 0, 8, 18, 32, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, 70, 131, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 8, 34, 32, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, 70, 131, 32, 0, 0, 0, 0, 0, 1, 0, 0, 0, 16, 0, 0, 8, 66, 32, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, 70, 131, 32, 0, 0, 0, 0, 0, 2, 0, 0, 0, 16, 0, 0, 8, 130, 32, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, 70, 131, 32, 0, 0, 0, 0, 0, 3, 0, 0, 0, 54, 0, 0, 5, 50, 32, 16, 0, 1, 0, 0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 62, 0, 0, 1, 83, 84, 65, 84, 116, 0, 0, 0, 8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - /* - SamplerState sampler0 : register(s0); - Texture2D texture0 : register(t0); - - struct ShaderInput - { - float4 pos : SV_POSITION; - float2 uv : TEXCOORD; - }; - - struct ShaderOutput - { - float4 col : SV_TARGET; - }; - - ShaderOutput main(ShaderInput input) - { - ShaderOutput output; - output.col = texture0.Sample(sampler0, input.uv); - return output; - } - */ - static unsigned char const pixel_shader[] = { 68, 88, 66, 67, 73, 50, 79, 193, 221, 29, 6, 76, 161, 213, 6, 101, 254, 234, 249, 59, 1, 0, 0, 0, 72, 2, 0, 0, 5, 0, 0, 0, 52, 0, 0, 0, 212, 0, 0, 0, 44, 1, 0, 0, 96, 1, 0, 0, 204, 1, 0, 0, 82, 68, 69, 70, 152, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 28, 0, 0, 0, 0, 4, 255, 255, 0, 1, 0, 0, 110, 0, 0, 0, 92, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 101, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 4, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 13, 0, 0, 0, 115, 97, 109, 112, 108, 101, 114, 48, 0, 116, 101, 120, 116, 117, 114, 101, 48, 0, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 171, 171, 73, 83, 71, 78, 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 3, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0, 84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 171, 79, 83, 71, 78, 44, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 71, 69, 84, 0, 171, 171, 83, 72, 68, 82, 100, 0, 0, 0, 64, 0, 0, 0, 25, 0, 0, 0, 90, 0, 0, 3, 0, 96, 16, 0, 0, 0, 0, 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, 0, 0, 85, 85, 0, 0, 98, 16, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0, 101, 0, 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 69, 0, 0, 9, 242, 32, 16, 0, 0, 0, 0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, 0, 96, 16, 0, 0, 0, 0, 0, 62, 0, 0, 1, 83, 84, 65, 84, 116, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - - /* input layout */ { - D3D11_INPUT_ELEMENT_DESC input_layout_p2f_t2f[] = { - { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - }; - HRGet = d3d11_device->CreateInputLayout(input_layout_p2f_t2f, 2, vertex_shader, sizeof(vertex_shader), &d3d11_input_layout); - HRCheckCallReturnBool("ID3D11Device::CreateInputLayout"); - } - - /* vertex buffer */ { - D3D11_BUFFER_DESC vertex_buffer_info = {}; - vertex_buffer_info.ByteWidth = 4 * sizeof(Vertex); - vertex_buffer_info.Usage = D3D11_USAGE_DYNAMIC; - vertex_buffer_info.BindFlags = D3D11_BIND_VERTEX_BUFFER; - vertex_buffer_info.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - HRGet = d3d11_device->CreateBuffer(&vertex_buffer_info, NULL, &d3d11_vertex_buffer); - HRCheckCallReturnBool("ID3D11Device::CreateBuffer"); - } - - /* index buffer */ { - D3D11_BUFFER_DESC index_buffer_info = {}; - index_buffer_info.ByteWidth = 6 * sizeof(Index); - index_buffer_info.Usage = D3D11_USAGE_DEFAULT; - index_buffer_info.BindFlags = D3D11_BIND_INDEX_BUFFER; - Index index_buffer_data[6] = { 0, 1, 2, 0, 2, 3 }; - D3D11_SUBRESOURCE_DATA index_buffer_data_info = {}; - index_buffer_data_info.pSysMem = index_buffer_data; - HRGet = d3d11_device->CreateBuffer(&index_buffer_info, &index_buffer_data_info, &d3d11_index_buffer); - HRCheckCallReturnBool("ID3D11Device::CreateBuffer"); - } - - /* constant buffer */ { - D3D11_BUFFER_DESC constant_buffer_info = {}; - constant_buffer_info.ByteWidth = sizeof(TransformBuffer); - constant_buffer_info.Usage = D3D11_USAGE_DYNAMIC; - constant_buffer_info.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - constant_buffer_info.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - HRGet = d3d11_device->CreateBuffer(&constant_buffer_info, NULL, &d3d11_constant_buffer); - HRCheckCallReturnBool("ID3D11Device::CreateBuffer"); - } - - /* vertex shader */ { - HRGet = d3d11_device->CreateVertexShader(vertex_shader, sizeof(vertex_shader), NULL, &d3d11_vertex_shader); - HRCheckCallReturnBool("ID3D11Device::CreateVertexShader"); - } - - /* rasterizer state */ { - D3D11_RASTERIZER_DESC state_info = {}; - state_info.FillMode = D3D11_FILL_SOLID; - state_info.CullMode = D3D11_CULL_NONE; - HRGet = d3d11_device->CreateRasterizerState(&state_info, &d3d11_rasterizer_state); - HRCheckCallReturnBool("ID3D11Device::CreateRasterizerState"); - } - - /* sampler state */ { - D3D11_SAMPLER_DESC state_info = {}; - state_info.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; - state_info.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - state_info.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - state_info.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - state_info.MaxAnisotropy = 1; - state_info.ComparisonFunc = D3D11_COMPARISON_NEVER; - state_info.MinLOD = -FLT_MAX; - state_info.MaxLOD = FLT_MAX; - HRGet = d3d11_device->CreateSamplerState(&state_info, &d3d11_sampler_state_linear); - HRCheckCallReturnBool("ID3D11Device::CreateSamplerState"); - - state_info.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - HRGet = d3d11_device->CreateSamplerState(&state_info, &d3d11_sampler_state_point); - HRCheckCallReturnBool("ID3D11Device::CreateSamplerState"); - } - - /* pixel shader */ { - HRGet = d3d11_device->CreatePixelShader(pixel_shader, sizeof(pixel_shader), NULL, &d3d11_pixel_shader); - HRCheckCallReturnBool("ID3D11Device::CreatePixelShader"); - } - - /* depth stencil state */ { - D3D11_DEPTH_STENCILOP_DESC state_op_info = { - .StencilFailOp = D3D11_STENCIL_OP_KEEP, - .StencilDepthFailOp = D3D11_STENCIL_OP_KEEP, - .StencilPassOp = D3D11_STENCIL_OP_KEEP, - .StencilFunc = D3D11_COMPARISON_ALWAYS, - }; - D3D11_DEPTH_STENCIL_DESC state_info = { - .DepthEnable = FALSE, - .DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL, - .DepthFunc = D3D11_COMPARISON_LESS, - .StencilEnable = FALSE, - .StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK, - .StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK, - .FrontFace = state_op_info, - .BackFace = state_op_info, - }; - HRGet = d3d11_device->CreateDepthStencilState(&state_info, &d3d11_depth_stencil_state); - HRCheckCallReturnBool("ID3D11Device::CreateDepthStencilState"); - } - - /* blend state */ { - D3D11_RENDER_TARGET_BLEND_DESC blend_state_info = { - .BlendEnable = FALSE, - .SrcBlend = D3D11_BLEND_ONE, - .DestBlend = D3D11_BLEND_ZERO, - .BlendOp = D3D11_BLEND_OP_ADD, - .SrcBlendAlpha = D3D11_BLEND_ONE, - .DestBlendAlpha = D3D11_BLEND_ZERO, - .BlendOpAlpha = D3D11_BLEND_OP_ADD, - .RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL, - }; - D3D11_BLEND_DESC state_info = { - .AlphaToCoverageEnable = FALSE, - .IndependentBlendEnable = FALSE, - .RenderTarget = { - blend_state_info, - blend_state_info, - blend_state_info, - blend_state_info, - blend_state_info, - blend_state_info, - blend_state_info, - blend_state_info, - }, - }; - HRGet = d3d11_device->CreateBlendState(&state_info, &d3d11_blend_state); - HRCheckCallReturnBool("ID3D11Device::CreateBlendState"); - } - - return true; - } - void LetterBoxingRenderer::DestroyResource() - { - d3d11_input_layout.Reset(); - d3d11_vertex_buffer.Reset(); - d3d11_index_buffer.Reset(); - d3d11_constant_buffer.Reset(); - d3d11_vertex_shader.Reset(); - d3d11_rasterizer_state.Reset(); - d3d11_sampler_state_linear.Reset(); - d3d11_sampler_state_point.Reset(); - d3d11_pixel_shader.Reset(); - d3d11_depth_stencil_state.Reset(); - d3d11_blend_state.Reset(); - } - - inline bool GetTexture2DInfoFromView(ID3D11View* view, D3D11_TEXTURE2D_DESC& info) - { - assert(view); - HRNew; - Microsoft::WRL::ComPtr resource; - view->GetResource(resource.ReleaseAndGetAddressOf()); - Microsoft::WRL::ComPtr texture; - HRGet = resource.As(&texture); - HRCheckCallReturnBool("ID3D11Resource::QueryInterface -> ID3D11Texture2D"); - texture->GetDesc(&info); - return true; - } - - bool LetterBoxingRenderer::AttachDevice(ID3D11Device* device) - { - assert(device); - d3d11_device = device; - d3d11_device->GetImmediateContext(&d3d11_device_context); - return CreateResource(); - } - void LetterBoxingRenderer::DetachDevice() - { - DestroyResource(); - d3d11_device.Reset(); - d3d11_device_context.Reset(); - } - bool LetterBoxingRenderer::UpdateTransform(ID3D11ShaderResourceView* srv, ID3D11RenderTargetView* rtv, bool stretch) - { - assert(srv); - assert(rtv); - assert(d3d11_device_context); - assert(d3d11_vertex_buffer); - assert(d3d11_constant_buffer); - - HRNew; - - // info - - D3D11_TEXTURE2D_DESC srv_res_tex_info{}; - if (!GetTexture2DInfoFromView(srv, srv_res_tex_info)) return false; - D3D11_TEXTURE2D_DESC rtv_res_tex_info = {}; - if (!GetTexture2DInfoFromView(rtv, rtv_res_tex_info)) return false; - - // vertex buffer - - float const window_w = float(rtv_res_tex_info.Width); - float const window_h = float(rtv_res_tex_info.Height); - - if (stretch) - { - // stretch - - float const _ = 0.0f; - - vertex_buffer[0] = { 0.0f + _, window_h, 0.0f, 0.0f }; - vertex_buffer[1] = { window_w, window_h, 1.0f, 0.0f }; - vertex_buffer[2] = { window_w, 0.0f + _, 1.0f, 1.0f }; - vertex_buffer[3] = { 0.0f + _, 0.0f + _, 0.0f, 1.0f }; - } - else - { - // letter boxing - - float const ______ = 0.0f; - - float const canvas_w = float(srv_res_tex_info.Width); - float const canvas_h = float(srv_res_tex_info.Height); - - float const scale_w = window_w / canvas_w; - float const scale_h = window_h / canvas_h; - float const scale = std::min(scale_w, scale_h); - - float const draw_w = canvas_w * scale; - float const draw_h = canvas_h * scale; - float const draw_x = (window_w - draw_w) * 0.5f; - float const draw_y = (window_h - draw_h) * 0.5f; - - vertex_buffer[0] = { draw_x + ______, draw_y + draw_h, 0.0f, 0.0f }; - vertex_buffer[1] = { draw_x + draw_w, draw_y + draw_h, 1.0f, 0.0f }; - vertex_buffer[2] = { draw_x + draw_w, draw_y + ______, 1.0f, 1.0f }; - vertex_buffer[3] = { draw_x + ______, draw_y + ______, 0.0f, 1.0f }; - } - - D3D11_MAPPED_SUBRESOURCE vertex_data_range = {}; - HRGet = d3d11_device_context->Map(d3d11_vertex_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &vertex_data_range); - HRCheckCallReturnBool("ID3D11DeviceContext::Map"); - memcpy(vertex_data_range.pData, vertex_buffer, sizeof(vertex_buffer)); - d3d11_device_context->Unmap(d3d11_vertex_buffer.Get(), 0); - - // constant buffer - - DirectX::XMStoreFloat4x4( - &transform_buffer.mvp, - DirectX::XMMatrixTranspose( - DirectX::XMMatrixOrthographicOffCenterLH( - 0.0f, window_w, 0.0f, window_h, 0.0f, 1.0f - ) - ) - ); - - D3D11_MAPPED_SUBRESOURCE constant_data_range = {}; - HRGet = d3d11_device_context->Map(d3d11_constant_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &constant_data_range); - HRCheckCallReturnBool("ID3D11DeviceContext::Map"); - memcpy(constant_data_range.pData, &transform_buffer, sizeof(transform_buffer)); - d3d11_device_context->Unmap(d3d11_constant_buffer.Get(), 0); - - // state - - d3d11_viewport = { 0.0f, 0.0f, window_w , window_h ,0.0f, 1.0f }; - d3d11_scissor_rect = { 0, 0, static_cast(rtv_res_tex_info.Width), static_cast(rtv_res_tex_info.Height) }; - - return true; - } - bool LetterBoxingRenderer::Draw(ID3D11ShaderResourceView* srv, ID3D11RenderTargetView* rtv, bool clear_rtv) - { - assert(srv); - assert(rtv); - assert(d3d11_device_context); - - D3D11_TEXTURE2D_DESC srv_res_tex_info{}; - if (!GetTexture2DInfoFromView(srv, srv_res_tex_info)) return false; - D3D11_TEXTURE2D_DESC rtv_res_tex_info = {}; - if (!GetTexture2DInfoFromView(rtv, rtv_res_tex_info)) return false; - - bool const is_width_or_heigth_equal = false - || (srv_res_tex_info.Width == rtv_res_tex_info.Width && srv_res_tex_info.Height <= rtv_res_tex_info.Height) - || (srv_res_tex_info.Width <= rtv_res_tex_info.Width && srv_res_tex_info.Height == rtv_res_tex_info.Height); - bool const is_width_or_heigth_not_equal = false - || srv_res_tex_info.Width != rtv_res_tex_info.Width - || srv_res_tex_info.Height != rtv_res_tex_info.Height; - - if (is_width_or_heigth_equal) - { - if (is_width_or_heigth_not_equal && clear_rtv) - { - FLOAT const clear_color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; - d3d11_device_context->ClearRenderTargetView(rtv, clear_color); - } - Microsoft::WRL::ComPtr srv_res; - Microsoft::WRL::ComPtr rtv_res; - srv->GetResource(&srv_res); - rtv->GetResource(&rtv_res); - UINT const dx = (rtv_res_tex_info.Width - srv_res_tex_info.Width) / 2; - UINT const dy = (rtv_res_tex_info.Height - srv_res_tex_info.Height) / 2; - d3d11_device_context->CopySubresourceRegion( - rtv_res.Get(), 0, dx, dy, 0, - srv_res.Get(), 0, NULL); - return true; - } - - assert(d3d11_input_layout); - assert(d3d11_vertex_buffer); - assert(d3d11_index_buffer); - - d3d11_device_context->ClearState(); - - d3d11_device_context->IASetInputLayout(d3d11_input_layout.Get()); - d3d11_device_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - ID3D11Buffer* vertex_buffer_list[1] = { d3d11_vertex_buffer.Get() }; - UINT stride_list[1] = { (UINT)sizeof(Vertex) }; - UINT offset_list[1] = { 0 }; - d3d11_device_context->IASetVertexBuffers(0, 1, vertex_buffer_list, stride_list, offset_list); - d3d11_device_context->IASetIndexBuffer(d3d11_index_buffer.Get(), DXGI_FORMAT_R16_UINT, 0); - - assert(d3d11_constant_buffer); - assert(d3d11_vertex_shader); - - ID3D11Buffer* constant_buffer_list[1] = { d3d11_constant_buffer.Get() }; - d3d11_device_context->VSSetConstantBuffers(0, 1, constant_buffer_list); - d3d11_device_context->VSSetShader(d3d11_vertex_shader.Get(), NULL, 0); - - assert(d3d11_rasterizer_state); - - d3d11_device_context->RSSetState(d3d11_rasterizer_state.Get()); - d3d11_device_context->RSSetViewports(1, &d3d11_viewport); - d3d11_device_context->RSSetScissorRects(1, &d3d11_scissor_rect); - - assert(d3d11_sampler_state_linear); - assert(d3d11_sampler_state_point); - assert(srv); - assert(d3d11_pixel_shader); - - ID3D11SamplerState* sampler_state_list[1] = { d3d11_sampler_state_linear.Get() }; - d3d11_device_context->PSSetSamplers(0, 1, sampler_state_list); - ID3D11ShaderResourceView* shader_resource_view_list[1] = { srv }; - d3d11_device_context->PSSetShaderResources(0, 1, shader_resource_view_list); - d3d11_device_context->PSSetShader(d3d11_pixel_shader.Get(), NULL, 0); - - assert(d3d11_depth_stencil_state); - assert(d3d11_blend_state); - assert(rtv); - - d3d11_device_context->OMSetDepthStencilState(d3d11_depth_stencil_state.Get(), D3D11_DEFAULT_STENCIL_REFERENCE); - FLOAT const blend_factor[4]{}; - d3d11_device_context->OMSetBlendState(d3d11_blend_state.Get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); - ID3D11RenderTargetView* render_target_view_list[1] = { rtv }; - d3d11_device_context->OMSetRenderTargets(1, render_target_view_list, NULL); - - if (clear_rtv) - { - FLOAT const clear_color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; - d3d11_device_context->ClearRenderTargetView(rtv, clear_color); - } - d3d11_device_context->DrawIndexed(6, 0, 0); - - return true; - } - - LetterBoxingRenderer::LetterBoxingRenderer() = default; - LetterBoxingRenderer::~LetterBoxingRenderer() { DetachDevice(); } -} +#include "core/Graphics/Direct3D11/LetterBoxingRenderer.hpp" +#include "core/Logger.hpp" + +#define HRNew HRESULT hr = S_OK; +#define HRGet hr +#define HRCheckCallReturnBool(x) if (FAILED(hr)) { Logger::error("Windows API failed: " x); return false; } + +namespace core::Graphics::Direct3D11 +{ + bool LetterBoxingRenderer::CreateResource() + { + assert(d3d11_device); + assert(d3d11_device_context); + + HRNew; + + /* + cbuffer TransformBuffer : register(b0) + { + float4x4 mvp; + }; + + struct ShaderInput + { + float2 pos : POSITION; + float2 uv : TEXCOORD; + }; + + struct ShaderOutput + { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD; + }; + + ShaderOutput main(ShaderInput input) + { + ShaderOutput output; + output.pos = mul(float4(input.pos, 0.0f, 1.0f), mvp); + output.uv = input.uv; + return output; + } + */ + static unsigned char const vertex_shader[] = { 68, 88, 66, 67, 59, 64, 214, 227, 106, 29, 100, 169, 229, 180, 69, 232, 69, 58, 239, 19, 1, 0, 0, 0, 56, 3, 0, 0, 5, 0, 0, 0, 52, 0, 0, 0, 244, 0, 0, 0, 72, 1, 0, 0, 160, 1, 0, 0, 188, 2, 0, 0, 82, 68, 69, 70, 184, 0, 0, 0, 1, 0, 0, 0, 76, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 0, 4, 254, 255, 0, 1, 0, 0, 144, 0, 0, 0, 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 84, 114, 97, 110, 115, 102, 111, 114, 109, 66, 117, 102, 102, 101, 114, 0, 60, 0, 0, 0, 1, 0, 0, 0, 100, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 124, 0, 0, 0, 0, 0, 0, 0, 64, 0, 0, 0, 2, 0, 0, 0, 128, 0, 0, 0, 0, 0, 0, 0, 109, 118, 112, 0, 3, 0, 3, 0, 4, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 73, 83, 71, 78, 76, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 65, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 3, 0, 0, 80, 79, 83, 73, 84, 73, 79, 78, 0, 84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 79, 83, 71, 78, 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 12, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0, 84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 171, 83, 72, 68, 82, 20, 1, 0, 0, 64, 0, 1, 0, 69, 0, 0, 0, 89, 0, 0, 4, 70, 142, 32, 0, 0, 0, 0, 0, 4, 0, 0, 0, 95, 0, 0, 3, 50, 16, 16, 0, 0, 0, 0, 0, 95, 0, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0, 103, 0, 0, 4, 242, 32, 16, 0, 0, 0, 0, 0, 1, 0, 0, 0, 101, 0, 0, 3, 50, 32, 16, 0, 1, 0, 0, 0, 104, 0, 0, 2, 1, 0, 0, 0, 54, 0, 0, 5, 50, 0, 16, 0, 0, 0, 0, 0, 70, 16, 16, 0, 0, 0, 0, 0, 54, 0, 0, 5, 66, 0, 16, 0, 0, 0, 0, 0, 1, 64, 0, 0, 0, 0, 128, 63, 16, 0, 0, 8, 18, 32, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, 70, 131, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 8, 34, 32, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, 70, 131, 32, 0, 0, 0, 0, 0, 1, 0, 0, 0, 16, 0, 0, 8, 66, 32, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, 70, 131, 32, 0, 0, 0, 0, 0, 2, 0, 0, 0, 16, 0, 0, 8, 130, 32, 16, 0, 0, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, 70, 131, 32, 0, 0, 0, 0, 0, 3, 0, 0, 0, 54, 0, 0, 5, 50, 32, 16, 0, 1, 0, 0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 62, 0, 0, 1, 83, 84, 65, 84, 116, 0, 0, 0, 8, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + /* + SamplerState sampler0 : register(s0); + Texture2D texture0 : register(t0); + + struct ShaderInput + { + float4 pos : SV_POSITION; + float2 uv : TEXCOORD; + }; + + struct ShaderOutput + { + float4 col : SV_TARGET; + }; + + ShaderOutput main(ShaderInput input) + { + ShaderOutput output; + output.col = texture0.Sample(sampler0, input.uv); + return output; + } + */ + static unsigned char const pixel_shader[] = { 68, 88, 66, 67, 73, 50, 79, 193, 221, 29, 6, 76, 161, 213, 6, 101, 254, 234, 249, 59, 1, 0, 0, 0, 72, 2, 0, 0, 5, 0, 0, 0, 52, 0, 0, 0, 212, 0, 0, 0, 44, 1, 0, 0, 96, 1, 0, 0, 204, 1, 0, 0, 82, 68, 69, 70, 152, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 28, 0, 0, 0, 0, 4, 255, 255, 0, 1, 0, 0, 110, 0, 0, 0, 92, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 101, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 4, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, 13, 0, 0, 0, 115, 97, 109, 112, 108, 101, 114, 48, 0, 116, 101, 120, 116, 117, 114, 101, 48, 0, 77, 105, 99, 114, 111, 115, 111, 102, 116, 32, 40, 82, 41, 32, 72, 76, 83, 76, 32, 83, 104, 97, 100, 101, 114, 32, 67, 111, 109, 112, 105, 108, 101, 114, 32, 49, 48, 46, 49, 0, 171, 171, 73, 83, 71, 78, 80, 0, 0, 0, 2, 0, 0, 0, 8, 0, 0, 0, 56, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 3, 3, 0, 0, 83, 86, 95, 80, 79, 83, 73, 84, 73, 79, 78, 0, 84, 69, 88, 67, 79, 79, 82, 68, 0, 171, 171, 171, 79, 83, 71, 78, 44, 0, 0, 0, 1, 0, 0, 0, 8, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 83, 86, 95, 84, 65, 82, 71, 69, 84, 0, 171, 171, 83, 72, 68, 82, 100, 0, 0, 0, 64, 0, 0, 0, 25, 0, 0, 0, 90, 0, 0, 3, 0, 96, 16, 0, 0, 0, 0, 0, 88, 24, 0, 4, 0, 112, 16, 0, 0, 0, 0, 0, 85, 85, 0, 0, 98, 16, 0, 3, 50, 16, 16, 0, 1, 0, 0, 0, 101, 0, 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 69, 0, 0, 9, 242, 32, 16, 0, 0, 0, 0, 0, 70, 16, 16, 0, 1, 0, 0, 0, 70, 126, 16, 0, 0, 0, 0, 0, 0, 96, 16, 0, 0, 0, 0, 0, 62, 0, 0, 1, 83, 84, 65, 84, 116, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + + /* input layout */ { + D3D11_INPUT_ELEMENT_DESC input_layout_p2f_t2f[] = { + { "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + }; + HRGet = d3d11_device->CreateInputLayout(input_layout_p2f_t2f, 2, vertex_shader, sizeof(vertex_shader), d3d11_input_layout.put()); + HRCheckCallReturnBool("ID3D11Device::CreateInputLayout"); + } + + /* vertex buffer */ { + D3D11_BUFFER_DESC vertex_buffer_info = {}; + vertex_buffer_info.ByteWidth = 4 * sizeof(Vertex); + vertex_buffer_info.Usage = D3D11_USAGE_DYNAMIC; + vertex_buffer_info.BindFlags = D3D11_BIND_VERTEX_BUFFER; + vertex_buffer_info.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + HRGet = d3d11_device->CreateBuffer(&vertex_buffer_info, NULL, d3d11_vertex_buffer.put()); + HRCheckCallReturnBool("ID3D11Device::CreateBuffer"); + } + + /* index buffer */ { + D3D11_BUFFER_DESC index_buffer_info = {}; + index_buffer_info.ByteWidth = 6 * sizeof(Index); + index_buffer_info.Usage = D3D11_USAGE_DEFAULT; + index_buffer_info.BindFlags = D3D11_BIND_INDEX_BUFFER; + Index index_buffer_data[6] = { 0, 1, 2, 0, 2, 3 }; + D3D11_SUBRESOURCE_DATA index_buffer_data_info = {}; + index_buffer_data_info.pSysMem = index_buffer_data; + HRGet = d3d11_device->CreateBuffer(&index_buffer_info, &index_buffer_data_info, d3d11_index_buffer.put()); + HRCheckCallReturnBool("ID3D11Device::CreateBuffer"); + } + + /* constant buffer */ { + D3D11_BUFFER_DESC constant_buffer_info = {}; + constant_buffer_info.ByteWidth = sizeof(TransformBuffer); + constant_buffer_info.Usage = D3D11_USAGE_DYNAMIC; + constant_buffer_info.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + constant_buffer_info.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + HRGet = d3d11_device->CreateBuffer(&constant_buffer_info, NULL, d3d11_constant_buffer.put()); + HRCheckCallReturnBool("ID3D11Device::CreateBuffer"); + } + + /* vertex shader */ { + HRGet = d3d11_device->CreateVertexShader(vertex_shader, sizeof(vertex_shader), NULL, d3d11_vertex_shader.put()); + HRCheckCallReturnBool("ID3D11Device::CreateVertexShader"); + } + + /* rasterizer state */ { + D3D11_RASTERIZER_DESC state_info = {}; + state_info.FillMode = D3D11_FILL_SOLID; + state_info.CullMode = D3D11_CULL_NONE; + HRGet = d3d11_device->CreateRasterizerState(&state_info, d3d11_rasterizer_state.put()); + HRCheckCallReturnBool("ID3D11Device::CreateRasterizerState"); + } + + /* sampler state */ { + D3D11_SAMPLER_DESC state_info = {}; + state_info.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; + state_info.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; + state_info.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; + state_info.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + state_info.MaxAnisotropy = 1; + state_info.ComparisonFunc = D3D11_COMPARISON_NEVER; + state_info.MinLOD = -FLT_MAX; + state_info.MaxLOD = FLT_MAX; + HRGet = d3d11_device->CreateSamplerState(&state_info, d3d11_sampler_state_linear.put()); + HRCheckCallReturnBool("ID3D11Device::CreateSamplerState"); + + state_info.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + HRGet = d3d11_device->CreateSamplerState(&state_info, d3d11_sampler_state_point.put()); + HRCheckCallReturnBool("ID3D11Device::CreateSamplerState"); + } + + /* pixel shader */ { + HRGet = d3d11_device->CreatePixelShader(pixel_shader, sizeof(pixel_shader), NULL, d3d11_pixel_shader.put()); + HRCheckCallReturnBool("ID3D11Device::CreatePixelShader"); + } + + /* depth stencil state */ { + D3D11_DEPTH_STENCILOP_DESC state_op_info = { + .StencilFailOp = D3D11_STENCIL_OP_KEEP, + .StencilDepthFailOp = D3D11_STENCIL_OP_KEEP, + .StencilPassOp = D3D11_STENCIL_OP_KEEP, + .StencilFunc = D3D11_COMPARISON_ALWAYS, + }; + D3D11_DEPTH_STENCIL_DESC state_info = { + .DepthEnable = FALSE, + .DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL, + .DepthFunc = D3D11_COMPARISON_LESS, + .StencilEnable = FALSE, + .StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK, + .StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK, + .FrontFace = state_op_info, + .BackFace = state_op_info, + }; + HRGet = d3d11_device->CreateDepthStencilState(&state_info, d3d11_depth_stencil_state.put()); + HRCheckCallReturnBool("ID3D11Device::CreateDepthStencilState"); + } + + /* blend state */ { + D3D11_RENDER_TARGET_BLEND_DESC blend_state_info = { + .BlendEnable = FALSE, + .SrcBlend = D3D11_BLEND_ONE, + .DestBlend = D3D11_BLEND_ZERO, + .BlendOp = D3D11_BLEND_OP_ADD, + .SrcBlendAlpha = D3D11_BLEND_ONE, + .DestBlendAlpha = D3D11_BLEND_ZERO, + .BlendOpAlpha = D3D11_BLEND_OP_ADD, + .RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL, + }; + D3D11_BLEND_DESC state_info = { + .AlphaToCoverageEnable = FALSE, + .IndependentBlendEnable = FALSE, + .RenderTarget = { + blend_state_info, + blend_state_info, + blend_state_info, + blend_state_info, + blend_state_info, + blend_state_info, + blend_state_info, + blend_state_info, + }, + }; + HRGet = d3d11_device->CreateBlendState(&state_info, d3d11_blend_state.put()); + HRCheckCallReturnBool("ID3D11Device::CreateBlendState"); + } + + return true; + } + void LetterBoxingRenderer::DestroyResource() + { + d3d11_input_layout.reset(); + d3d11_vertex_buffer.reset(); + d3d11_index_buffer.reset(); + d3d11_constant_buffer.reset(); + d3d11_vertex_shader.reset(); + d3d11_rasterizer_state.reset(); + d3d11_sampler_state_linear.reset(); + d3d11_sampler_state_point.reset(); + d3d11_pixel_shader.reset(); + d3d11_depth_stencil_state.reset(); + d3d11_blend_state.reset(); + } + + inline bool GetTexture2DInfoFromView(ID3D11View* view, D3D11_TEXTURE2D_DESC& info) + { + assert(view); + HRNew; + win32::com_ptr resource; + view->GetResource(resource.put()); + win32::com_ptr texture; + HRGet = resource->QueryInterface(texture.put()); + HRCheckCallReturnBool("ID3D11Resource::QueryInterface -> ID3D11Texture2D"); + texture->GetDesc(&info); + return true; + } + + bool LetterBoxingRenderer::AttachDevice(ID3D11Device* device) + { + assert(device); + d3d11_device = device; + d3d11_device->GetImmediateContext(d3d11_device_context.put()); + return CreateResource(); + } + void LetterBoxingRenderer::DetachDevice() + { + DestroyResource(); + d3d11_device.reset(); + d3d11_device_context.reset(); + } + bool LetterBoxingRenderer::UpdateTransform(ID3D11ShaderResourceView* srv, ID3D11RenderTargetView* rtv, bool stretch) + { + assert(srv); + assert(rtv); + assert(d3d11_device_context); + assert(d3d11_vertex_buffer); + assert(d3d11_constant_buffer); + + HRNew; + + // info + + D3D11_TEXTURE2D_DESC srv_res_tex_info{}; + if (!GetTexture2DInfoFromView(srv, srv_res_tex_info)) return false; + D3D11_TEXTURE2D_DESC rtv_res_tex_info = {}; + if (!GetTexture2DInfoFromView(rtv, rtv_res_tex_info)) return false; + + // vertex buffer + + float const window_w = float(rtv_res_tex_info.Width); + float const window_h = float(rtv_res_tex_info.Height); + + if (stretch) + { + // stretch + + float const _ = 0.0f; + + vertex_buffer[0] = { 0.0f + _, window_h, 0.0f, 0.0f }; + vertex_buffer[1] = { window_w, window_h, 1.0f, 0.0f }; + vertex_buffer[2] = { window_w, 0.0f + _, 1.0f, 1.0f }; + vertex_buffer[3] = { 0.0f + _, 0.0f + _, 0.0f, 1.0f }; + } + else + { + // letter boxing + + float const ______ = 0.0f; + + float const canvas_w = float(srv_res_tex_info.Width); + float const canvas_h = float(srv_res_tex_info.Height); + + float const scale_w = window_w / canvas_w; + float const scale_h = window_h / canvas_h; + float const scale = std::min(scale_w, scale_h); + + float const draw_w = canvas_w * scale; + float const draw_h = canvas_h * scale; + float const draw_x = (window_w - draw_w) * 0.5f; + float const draw_y = (window_h - draw_h) * 0.5f; + + vertex_buffer[0] = { draw_x + ______, draw_y + draw_h, 0.0f, 0.0f }; + vertex_buffer[1] = { draw_x + draw_w, draw_y + draw_h, 1.0f, 0.0f }; + vertex_buffer[2] = { draw_x + draw_w, draw_y + ______, 1.0f, 1.0f }; + vertex_buffer[3] = { draw_x + ______, draw_y + ______, 0.0f, 1.0f }; + } + + D3D11_MAPPED_SUBRESOURCE vertex_data_range = {}; + HRGet = d3d11_device_context->Map(d3d11_vertex_buffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &vertex_data_range); + HRCheckCallReturnBool("ID3D11DeviceContext::Map"); + memcpy(vertex_data_range.pData, vertex_buffer, sizeof(vertex_buffer)); + d3d11_device_context->Unmap(d3d11_vertex_buffer.get(), 0); + + // constant buffer + + DirectX::XMStoreFloat4x4( + &transform_buffer.mvp, + DirectX::XMMatrixTranspose( + DirectX::XMMatrixOrthographicOffCenterLH( + 0.0f, window_w, 0.0f, window_h, 0.0f, 1.0f + ) + ) + ); + + D3D11_MAPPED_SUBRESOURCE constant_data_range = {}; + HRGet = d3d11_device_context->Map(d3d11_constant_buffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &constant_data_range); + HRCheckCallReturnBool("ID3D11DeviceContext::Map"); + memcpy(constant_data_range.pData, &transform_buffer, sizeof(transform_buffer)); + d3d11_device_context->Unmap(d3d11_constant_buffer.get(), 0); + + // state + + d3d11_viewport = { 0.0f, 0.0f, window_w , window_h ,0.0f, 1.0f }; + d3d11_scissor_rect = { 0, 0, static_cast(rtv_res_tex_info.Width), static_cast(rtv_res_tex_info.Height) }; + + return true; + } + bool LetterBoxingRenderer::Draw(ID3D11ShaderResourceView* srv, ID3D11RenderTargetView* rtv, bool clear_rtv) + { + assert(srv); + assert(rtv); + assert(d3d11_device_context); + + D3D11_TEXTURE2D_DESC srv_res_tex_info{}; + if (!GetTexture2DInfoFromView(srv, srv_res_tex_info)) return false; + D3D11_TEXTURE2D_DESC rtv_res_tex_info = {}; + if (!GetTexture2DInfoFromView(rtv, rtv_res_tex_info)) return false; + + bool const is_width_or_heigth_equal = false + || (srv_res_tex_info.Width == rtv_res_tex_info.Width && srv_res_tex_info.Height <= rtv_res_tex_info.Height) + || (srv_res_tex_info.Width <= rtv_res_tex_info.Width && srv_res_tex_info.Height == rtv_res_tex_info.Height); + bool const is_width_or_heigth_not_equal = false + || srv_res_tex_info.Width != rtv_res_tex_info.Width + || srv_res_tex_info.Height != rtv_res_tex_info.Height; + + if (is_width_or_heigth_equal) + { + if (is_width_or_heigth_not_equal && clear_rtv) + { + FLOAT const clear_color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; + d3d11_device_context->ClearRenderTargetView(rtv, clear_color); + } + win32::com_ptr srv_res; + win32::com_ptr rtv_res; + srv->GetResource(srv_res.put()); + rtv->GetResource(rtv_res.put()); + UINT const dx = (rtv_res_tex_info.Width - srv_res_tex_info.Width) / 2; + UINT const dy = (rtv_res_tex_info.Height - srv_res_tex_info.Height) / 2; + d3d11_device_context->CopySubresourceRegion( + rtv_res.get(), 0, dx, dy, 0, + srv_res.get(), 0, NULL); + return true; + } + + assert(d3d11_input_layout); + assert(d3d11_vertex_buffer); + assert(d3d11_index_buffer); + + d3d11_device_context->ClearState(); + + d3d11_device_context->IASetInputLayout(d3d11_input_layout.get()); + d3d11_device_context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D11Buffer* vertex_buffer_list[1] = { d3d11_vertex_buffer.get() }; + UINT stride_list[1] = { (UINT)sizeof(Vertex) }; + UINT offset_list[1] = { 0 }; + d3d11_device_context->IASetVertexBuffers(0, 1, vertex_buffer_list, stride_list, offset_list); + d3d11_device_context->IASetIndexBuffer(d3d11_index_buffer.get(), DXGI_FORMAT_R16_UINT, 0); + + assert(d3d11_constant_buffer); + assert(d3d11_vertex_shader); + + ID3D11Buffer* constant_buffer_list[1] = { d3d11_constant_buffer.get() }; + d3d11_device_context->VSSetConstantBuffers(0, 1, constant_buffer_list); + d3d11_device_context->VSSetShader(d3d11_vertex_shader.get(), NULL, 0); + + assert(d3d11_rasterizer_state); + + d3d11_device_context->RSSetState(d3d11_rasterizer_state.get()); + d3d11_device_context->RSSetViewports(1, &d3d11_viewport); + d3d11_device_context->RSSetScissorRects(1, &d3d11_scissor_rect); + + assert(d3d11_sampler_state_linear); + assert(d3d11_sampler_state_point); + assert(srv); + assert(d3d11_pixel_shader); + + ID3D11SamplerState* sampler_state_list[1] = { d3d11_sampler_state_linear.get() }; + d3d11_device_context->PSSetSamplers(0, 1, sampler_state_list); + ID3D11ShaderResourceView* shader_resource_view_list[1] = { srv }; + d3d11_device_context->PSSetShaderResources(0, 1, shader_resource_view_list); + d3d11_device_context->PSSetShader(d3d11_pixel_shader.get(), NULL, 0); + + assert(d3d11_depth_stencil_state); + assert(d3d11_blend_state); + assert(rtv); + + d3d11_device_context->OMSetDepthStencilState(d3d11_depth_stencil_state.get(), D3D11_DEFAULT_STENCIL_REFERENCE); + FLOAT const blend_factor[4]{}; + d3d11_device_context->OMSetBlendState(d3d11_blend_state.get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + ID3D11RenderTargetView* render_target_view_list[1] = { rtv }; + d3d11_device_context->OMSetRenderTargets(1, render_target_view_list, NULL); + + if (clear_rtv) + { + FLOAT const clear_color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; + d3d11_device_context->ClearRenderTargetView(rtv, clear_color); + } + d3d11_device_context->DrawIndexed(6, 0, 0); + + return true; + } + + LetterBoxingRenderer::LetterBoxingRenderer() = default; + LetterBoxingRenderer::~LetterBoxingRenderer() { DetachDevice(); } +} diff --git a/LuaSTG/Core/Graphics/Direct3D11/LetterBoxingRenderer.hpp b/engine/graphics/core/Graphics/Direct3D11/LetterBoxingRenderer.hpp similarity index 50% rename from LuaSTG/Core/Graphics/Direct3D11/LetterBoxingRenderer.hpp rename to engine/graphics/core/Graphics/Direct3D11/LetterBoxingRenderer.hpp index 441ec402..857308b5 100644 --- a/LuaSTG/Core/Graphics/Direct3D11/LetterBoxingRenderer.hpp +++ b/engine/graphics/core/Graphics/Direct3D11/LetterBoxingRenderer.hpp @@ -1,51 +1,51 @@ -#pragma once - -namespace core::Graphics::Direct3D11 -{ - class LetterBoxingRenderer - { - private: - struct Vertex - { - DirectX::XMFLOAT2 pos; - DirectX::XMFLOAT2 uv; - inline Vertex() = default; - inline Vertex(float x, float y, float u, float v) : pos(x, y), uv(u, v) {} - }; - using Index = uint16_t; - struct TransformBuffer - { - DirectX::XMFLOAT4X4 mvp; - }; - private: - Microsoft::WRL::ComPtr d3d11_device; - Microsoft::WRL::ComPtr d3d11_device_context; - private: - Microsoft::WRL::ComPtr d3d11_input_layout; - Vertex vertex_buffer[4]{}; - Microsoft::WRL::ComPtr d3d11_vertex_buffer; - Microsoft::WRL::ComPtr d3d11_index_buffer; - TransformBuffer transform_buffer{}; - Microsoft::WRL::ComPtr d3d11_constant_buffer; - Microsoft::WRL::ComPtr d3d11_vertex_shader; - D3D11_VIEWPORT d3d11_viewport{}; - D3D11_RECT d3d11_scissor_rect{}; - Microsoft::WRL::ComPtr d3d11_rasterizer_state; - Microsoft::WRL::ComPtr d3d11_sampler_state_linear; - Microsoft::WRL::ComPtr d3d11_sampler_state_point; - Microsoft::WRL::ComPtr d3d11_pixel_shader; - Microsoft::WRL::ComPtr d3d11_depth_stencil_state; - Microsoft::WRL::ComPtr d3d11_blend_state; - private: - bool CreateResource(); - void DestroyResource(); - public: - bool AttachDevice(ID3D11Device* device); - void DetachDevice(); - bool UpdateTransform(ID3D11ShaderResourceView* srv, ID3D11RenderTargetView* rtv, bool stretch = false); - bool Draw(ID3D11ShaderResourceView* srv, ID3D11RenderTargetView* rtv, bool clear_rtv); - public: - LetterBoxingRenderer(); - ~LetterBoxingRenderer(); - }; -} +#pragma once + +namespace core::Graphics::Direct3D11 +{ + class LetterBoxingRenderer + { + private: + struct Vertex + { + DirectX::XMFLOAT2 pos; + DirectX::XMFLOAT2 uv; + inline Vertex() = default; + inline Vertex(float x, float y, float u, float v) : pos(x, y), uv(u, v) {} + }; + using Index = uint16_t; + struct TransformBuffer + { + DirectX::XMFLOAT4X4 mvp; + }; + private: + win32::com_ptr d3d11_device; + win32::com_ptr d3d11_device_context; + private: + win32::com_ptr d3d11_input_layout; + Vertex vertex_buffer[4]{}; + win32::com_ptr d3d11_vertex_buffer; + win32::com_ptr d3d11_index_buffer; + TransformBuffer transform_buffer{}; + win32::com_ptr d3d11_constant_buffer; + win32::com_ptr d3d11_vertex_shader; + D3D11_VIEWPORT d3d11_viewport{}; + D3D11_RECT d3d11_scissor_rect{}; + win32::com_ptr d3d11_rasterizer_state; + win32::com_ptr d3d11_sampler_state_linear; + win32::com_ptr d3d11_sampler_state_point; + win32::com_ptr d3d11_pixel_shader; + win32::com_ptr d3d11_depth_stencil_state; + win32::com_ptr d3d11_blend_state; + private: + bool CreateResource(); + void DestroyResource(); + public: + bool AttachDevice(ID3D11Device* device); + void DetachDevice(); + bool UpdateTransform(ID3D11ShaderResourceView* srv, ID3D11RenderTargetView* rtv, bool stretch = false); + bool Draw(ID3D11ShaderResourceView* srv, ID3D11RenderTargetView* rtv, bool clear_rtv); + public: + LetterBoxingRenderer(); + ~LetterBoxingRenderer(); + }; +} diff --git a/LuaSTG/Core/Graphics/Direct3D11/Mesh.cpp b/engine/graphics/core/Graphics/Direct3D11/Mesh.cpp similarity index 91% rename from LuaSTG/Core/Graphics/Direct3D11/Mesh.cpp rename to engine/graphics/core/Graphics/Direct3D11/Mesh.cpp index 361185d2..08ce8c41 100644 --- a/LuaSTG/Core/Graphics/Direct3D11/Mesh.cpp +++ b/engine/graphics/core/Graphics/Direct3D11/Mesh.cpp @@ -1,20 +1,19 @@ // ReSharper disable CppTooWideScopeInitStatement -#include "Core/Graphics/Direct3D11/Mesh.hpp" -#include "Core/Graphics/Direct3D11/Buffer.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "Platform/RuntimeLoader/Direct3DCompiler.hpp" -#include "Core/i18n.hpp" +#include "core/Graphics/Direct3D11/Mesh.hpp" +#include "core/Logger.hpp" +#include "d3d11/GraphicsDevice.hpp" +#include "windows/RuntimeLoader/Direct3DCompiler.hpp" using std::string_view_literals::operator ""sv; namespace { Platform::RuntimeLoader::Direct3DCompiler d3d_compiler; void reportReadOnly() { - spdlog::error("[core] Mesh: read-only"); + core::Logger::error("[core] [Mesh] read-only mesh"); } void reportIndexOutOfBounds() { - spdlog::error("[core] Mesh: index out of bounds"); + core::Logger::error("[core] [Mesh] index out of bounds"); } std::string generateVertexShader(core::Graphics::MeshOptions const& options, bool const fog) { // ReSharper disable StringLiteralTypo @@ -91,12 +90,12 @@ namespace { nullptr, nullptr, "main", "vs_4_0", flags, 0, vertex_shader_blob.put(), error_message_blob.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("D3DCompile"); + core::Logger::error("Windows API failed: D3DCompile"); if (error_message_blob) { std::string_view const error_message(static_cast(error_message_blob->GetBufferPointer())); - spdlog::error("compiler error message:\n{}", error_message); + core::Logger::error("[core] [Mesh] compiler error message:\n{}", error_message); } - spdlog::error("generated vertex shader:\n{}", source); + core::Logger::error("[core] [Mesh] generated vertex shader:\n{}", source); return false; } *output = vertex_shader_blob.detach(); @@ -113,14 +112,14 @@ namespace { #define REPORT_READ_ONLY_RETURN_BOOL if (m_validation && m_read_only) { reportReadOnly(); assert(false); return false; } namespace core::Graphics::Direct3D11 { - void Mesh::onDeviceCreate() { + void Mesh::onGraphicsDeviceCreate() { if (m_initialized) { createResources(); // TODO: 如何确保回调顺序?我们希望 VertexBuffer 和 IndexBuffer 先重建 commit(); } } - void Mesh::onDeviceDestroy() { + void Mesh::onGraphicsDeviceDestroy() { m_vertex_shader.reset(); m_vertex_shader_fog.reset(); m_input_layout.reset(); @@ -234,7 +233,7 @@ namespace core::Graphics::Direct3D11 { REPORT_READ_ONLY_RETURN_BOOL; if (m_options.vertex_count > 0) { void* pointer{}; - if (!m_vertex_buffer->map(static_cast(m_vertex_data.size()), true, &pointer)) { + if (!m_vertex_buffer->map(&pointer, true)) { return false; } std::memcpy(pointer, m_vertex_data.data(), m_vertex_data.size()); @@ -244,7 +243,7 @@ namespace core::Graphics::Direct3D11 { } if (m_options.index_count > 0) { void* pointer{}; - if (!m_index_buffer->map(static_cast(m_index_data.size()), true, &pointer)) { + if (!m_index_buffer->map(&pointer, true)) { return false; } std::memcpy(pointer, m_index_data.data(), m_index_data.size()); @@ -270,11 +269,11 @@ namespace core::Graphics::Direct3D11 { // Stage: IA - ID3D11Buffer* const vbs[]{ static_cast(m_vertex_buffer.get())->getNativeBuffer() }; + ID3D11Buffer* const vbs[]{ static_cast(m_vertex_buffer->getNativeResource()) }; constexpr UINT offset{}; ctx->IASetVertexBuffers(0, 1, vbs, &m_vertex_metadata.stride, &offset); if (m_index_buffer) { - ID3D11Buffer* const ib{ static_cast(m_index_buffer.get())->getNativeBuffer() }; + ID3D11Buffer* const ib{ static_cast(m_index_buffer->getNativeResource()) }; ctx->IASetIndexBuffer(ib, m_options.vertex_index_compression ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT, 0); } ctx->IASetPrimitiveTopology(m_options.primitive_topology == PrimitiveTopology::triangle_list @@ -296,7 +295,7 @@ namespace core::Graphics::Direct3D11 { } } - bool Mesh::initialize(IDevice* const device, MeshOptions const& options) { + bool Mesh::initialize(IGraphicsDevice* const device, MeshOptions const& options) { assert(device); m_device = device; m_options = options; @@ -313,8 +312,8 @@ namespace core::Graphics::Direct3D11 { m_index_metadata.stride = m_options.vertex_index_compression ? sizeof(uint16_t) : sizeof(uint32_t); #ifndef NDEBUG - spdlog::info( - "[core] Mesh metadata:\n" + Logger::info( + "[core] [Mesh] metadata:\n" " vertex metadata:\n" " position offset: {} (bytes)\n" " position size : {} (bytes)\n" @@ -361,7 +360,7 @@ namespace core::Graphics::Direct3D11 { } bool Mesh::createResources() { HRESULT hr{}; - auto const device = static_cast(m_device.get())->GetD3D11Device(); + auto const device = static_cast(m_device.get())->GetD3D11Device(); assert(device); D3D11_INPUT_ELEMENT_DESC elements[3]{}; @@ -393,19 +392,19 @@ namespace core::Graphics::Direct3D11 { hr = gHR = device->CreateVertexShader(m_vertex_shader_byte_code->GetBufferPointer(), m_vertex_shader_byte_code->GetBufferSize(), nullptr, m_vertex_shader.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateVertexShader"); + Logger::error("Windows API failed: ID3D11Device::CreateVertexShader"); return false; } hr = gHR = device->CreateVertexShader(m_vertex_shader_byte_code_fog->GetBufferPointer(), m_vertex_shader_byte_code_fog->GetBufferSize(), nullptr, m_vertex_shader_fog.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateVertexShader"); + Logger::error("Windows API failed: ID3D11Device::CreateVertexShader"); return false; } // vertex shader input elements are compatible hr = gHR = device->CreateInputLayout(elements, 3, m_vertex_shader_byte_code->GetBufferPointer(), m_vertex_shader_byte_code->GetBufferSize(), m_input_layout.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateInputLayout"); + Logger::error("Windows API failed: ID3D11Device::CreateInputLayout"); return false; } @@ -413,7 +412,7 @@ namespace core::Graphics::Direct3D11 { } } namespace core::Graphics { - bool IMesh::create(IDevice* device, MeshOptions const& options, IMesh** output) { + bool IMesh::create(IGraphicsDevice* device, MeshOptions const& options, IMesh** output) { *output = nullptr; SmartReference buffer; buffer.attach(new Direct3D11::Mesh); diff --git a/LuaSTG/Core/Graphics/Direct3D11/Mesh.hpp b/engine/graphics/core/Graphics/Direct3D11/Mesh.hpp similarity index 80% rename from LuaSTG/Core/Graphics/Direct3D11/Mesh.hpp rename to engine/graphics/core/Graphics/Direct3D11/Mesh.hpp index 6452f2e2..e887c9f3 100644 --- a/LuaSTG/Core/Graphics/Direct3D11/Mesh.hpp +++ b/engine/graphics/core/Graphics/Direct3D11/Mesh.hpp @@ -1,18 +1,18 @@ #pragma once #include "core/SmartReference.hpp" #include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Mesh.hpp" +#include "core/Graphics/Mesh.hpp" namespace core::Graphics::Direct3D11 { class Mesh final : public implement::ReferenceCounted - , public IDeviceEventListener + , public IGraphicsDeviceEventListener { public: - // IDeviceEventListener + // IGraphicsDeviceEventListener - void onDeviceCreate() override; - void onDeviceDestroy() override; + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; // IMesh @@ -55,18 +55,18 @@ namespace core::Graphics::Direct3D11 { void applyNative(ID3D11DeviceContext* ctx, bool fog = false); void drawNative(ID3D11DeviceContext* ctx) const; - bool initialize(IDevice* device, MeshOptions const& options); + bool initialize(IGraphicsDevice* device, MeshOptions const& options); bool createResources(); private: - SmartReference m_device; - SmartReference m_vertex_buffer; - SmartReference m_index_buffer; - wil::com_ptr_nothrow m_vertex_shader_byte_code; - wil::com_ptr_nothrow m_vertex_shader_byte_code_fog; - wil::com_ptr_nothrow m_vertex_shader; - wil::com_ptr_nothrow m_vertex_shader_fog; - wil::com_ptr_nothrow m_input_layout; + SmartReference m_device; + SmartReference m_vertex_buffer; + SmartReference m_index_buffer; + win32::com_ptr m_vertex_shader_byte_code; + win32::com_ptr m_vertex_shader_byte_code_fog; + win32::com_ptr m_vertex_shader; + win32::com_ptr m_vertex_shader_fog; + win32::com_ptr m_input_layout; std::vector m_vertex_data; std::vector m_index_data; struct VertexMetadata { diff --git a/LuaSTG/Core/Graphics/Direct3D11/MeshRenderer.cpp b/engine/graphics/core/Graphics/Direct3D11/MeshRenderer.cpp similarity index 79% rename from LuaSTG/Core/Graphics/Direct3D11/MeshRenderer.cpp rename to engine/graphics/core/Graphics/Direct3D11/MeshRenderer.cpp index 0ce06755..54b3dbd1 100644 --- a/LuaSTG/Core/Graphics/Direct3D11/MeshRenderer.cpp +++ b/engine/graphics/core/Graphics/Direct3D11/MeshRenderer.cpp @@ -1,16 +1,14 @@ -#include "Core/Graphics/Direct3D11/MeshRenderer.hpp" -#include "Core/Graphics/Direct3D11/Constants.hpp" -#include "Core/Graphics/Direct3D11/Buffer.hpp" -#include "Core/Graphics/Direct3D11/Texture2D.hpp" -#include "Core/Graphics/Direct3D11/SamplerState.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "Core/Graphics/Direct3D11/Mesh.hpp" -#include "Core/Graphics/Renderer_D3D11.hpp" +#include "core/Graphics/Direct3D11/MeshRenderer.hpp" +#include "core/Graphics/Direct3D11/Constants.hpp" +#include "core/Graphics/Direct3D11/Texture2D.hpp" +#include "core/Graphics/Direct3D11/Mesh.hpp" +#include "d3d11/GraphicsDevice.hpp" +#include "core/Graphics/Renderer_D3D11.hpp" namespace core::Graphics::Direct3D11 { - void MeshRenderer::onDeviceCreate() { + void MeshRenderer::onGraphicsDeviceCreate() { } - void MeshRenderer::onDeviceDestroy() { + void MeshRenderer::onGraphicsDeviceDestroy() { m_transform_dirty = true; } @@ -44,7 +42,7 @@ namespace core::Graphics::Direct3D11 { return; } - auto const ctx = static_cast(m_device.get())->GetD3D11DeviceContext(); + auto const ctx = static_cast(m_device.get())->GetD3D11DeviceContext(); assert(ctx); // Mesh setup: @@ -67,7 +65,7 @@ namespace core::Graphics::Direct3D11 { // VS stage constant buffer setup by MeshRenderer // * constant buffer (world matrix) - ID3D11Buffer* const world_matrix[1]{ static_cast(m_constant_buffer.get())->getNativeBuffer() }; + ID3D11Buffer* const world_matrix[1]{ static_cast(m_constant_buffer->getNativeResource()) }; ctx->VSSetConstantBuffers(Constants::vertex_shader_stage_constant_buffer_slot_world_matrix, 1, world_matrix); // RS stage setup by Renderer: @@ -88,10 +86,10 @@ namespace core::Graphics::Direct3D11 { ID3D11SamplerState* sampler_state[1]{}; if (m_texture->getSamplerState()) { - sampler_state[0] = static_cast(m_texture->getSamplerState())->GetState(); + sampler_state[0] = static_cast(m_texture->getSamplerState()->getNativeHandle()); } else { auto const ss = renderer->getKnownSamplerState(IRenderer::SamplerState::LinearWrap); - sampler_state[0] = static_cast(ss)->GetState(); + sampler_state[0] = static_cast(ss->getNativeHandle()); } ctx->PSSetSamplers(0, 1, sampler_state); @@ -122,7 +120,7 @@ namespace core::Graphics::Direct3D11 { return true; } void* ptr{}; - if (!m_constant_buffer->map(sizeof(m_transform), true, &ptr)) { + if (!m_constant_buffer->map(&ptr, true)) { return false; } //auto const original = DirectX::XMLoadFloat4x4(reinterpret_cast(&m_transform)); @@ -136,7 +134,7 @@ namespace core::Graphics::Direct3D11 { } return true; } - bool MeshRenderer::initialize(IDevice* const device) { + bool MeshRenderer::initialize(IGraphicsDevice* const device) { assert(device); m_device = device; if (!m_device->createConstantBuffer(sizeof(m_transform), m_constant_buffer.put())) { @@ -146,7 +144,7 @@ namespace core::Graphics::Direct3D11 { } } namespace core::Graphics { - bool IMeshRenderer::create(IDevice* const device, IMeshRenderer** const output) { + bool IMeshRenderer::create(IGraphicsDevice* const device, IMeshRenderer** const output) { assert(device); assert(output); *output = nullptr; diff --git a/LuaSTG/Core/Graphics/Direct3D11/MeshRenderer.hpp b/engine/graphics/core/Graphics/Direct3D11/MeshRenderer.hpp similarity index 77% rename from LuaSTG/Core/Graphics/Direct3D11/MeshRenderer.hpp rename to engine/graphics/core/Graphics/Direct3D11/MeshRenderer.hpp index 3e3a424b..7e3a9085 100644 --- a/LuaSTG/Core/Graphics/Direct3D11/MeshRenderer.hpp +++ b/engine/graphics/core/Graphics/Direct3D11/MeshRenderer.hpp @@ -1,17 +1,17 @@ #pragma once #include "core/SmartReference.hpp" #include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Mesh.hpp" +#include "core/Graphics/Mesh.hpp" namespace core::Graphics::Direct3D11 { class MeshRenderer final : public implement::ReferenceCounted - , public IDeviceEventListener { + , public IGraphicsDeviceEventListener { public: - // IDeviceEventListener + // IGraphicsDeviceEventListener - void onDeviceCreate() override; - void onDeviceDestroy() override; + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; // IMeshRenderer @@ -32,13 +32,13 @@ namespace core::Graphics::Direct3D11 { MeshRenderer& operator=(MeshRenderer&&) = delete; bool uploadConstantBuffer(); - bool initialize(IDevice* device); + bool initialize(IGraphicsDevice* device); private: - SmartReference m_device; + SmartReference m_device; SmartReference m_texture; SmartReference m_mesh; - SmartReference m_constant_buffer; + SmartReference m_constant_buffer; Matrix4F m_transform{ Matrix4F::identity() }; IRenderer::VertexColorBlendState m_vertex_color_blend_state{ IRenderer::VertexColorBlendState::Mul }; IRenderer::BlendState m_blend_state{ IRenderer::BlendState::Alpha }; diff --git a/LuaSTG/Core/Graphics/Direct3D11/RenderTarget.cpp b/engine/graphics/core/Graphics/Direct3D11/RenderTarget.cpp similarity index 59% rename from LuaSTG/Core/Graphics/Direct3D11/RenderTarget.cpp rename to engine/graphics/core/Graphics/Direct3D11/RenderTarget.cpp index 6aae44ba..b4b01e4f 100644 --- a/LuaSTG/Core/Graphics/Direct3D11/RenderTarget.cpp +++ b/engine/graphics/core/Graphics/Direct3D11/RenderTarget.cpp @@ -1,11 +1,10 @@ -#include "Core/Graphics/Direct3D11/RenderTarget.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "Core/Graphics/Direct3D11/Texture2D.hpp" -#include "Core/i18n.hpp" +#include "core/Graphics/Direct3D11/RenderTarget.hpp" +#include "core/Logger.hpp" +#include "core/Graphics/Direct3D11/Texture2D.hpp" // RenderTarget namespace core::Graphics::Direct3D11 { - void RenderTarget::onDeviceCreate() { + void RenderTarget::onGraphicsDeviceCreate() { if (m_initialized) { // 这里不能直接调用 texture 的 onDeviceCreate,因为要判断创建是否成功 if (m_texture->createResource()) { @@ -13,12 +12,12 @@ namespace core::Graphics::Direct3D11 { } } } - void RenderTarget::onDeviceDestroy() { - m_view.Reset(); + void RenderTarget::onGraphicsDeviceDestroy() { + m_view.reset(); #ifdef LUASTG_ENABLE_DIRECT2D - m_bitmap.Reset(); + m_bitmap.reset(); #endif - m_texture->onDeviceDestroy(); + m_texture->onGraphicsDeviceDestroy(); } ITexture2D* RenderTarget::getTexture() const noexcept { return m_texture.get(); } @@ -31,9 +30,9 @@ namespace core::Graphics::Direct3D11 { } bool RenderTarget::setSize(Vector2U const size) { - m_view.Reset(); + m_view.reset(); #ifdef LUASTG_ENABLE_DIRECT2D - m_bitmap.Reset(); + m_bitmap.reset(); #endif if (!m_texture->setSize(size)) { return false; @@ -41,7 +40,7 @@ namespace core::Graphics::Direct3D11 { return createResource(); } - bool RenderTarget::initialize(Device* const device, Vector2U const size) { + bool RenderTarget::initialize(IGraphicsDevice* const device, Vector2U const size) { assert(device); assert(size.x > 0 && size.y > 0); m_device = device; @@ -59,12 +58,15 @@ namespace core::Graphics::Direct3D11 { bool RenderTarget::createResource() { HRESULT hr = S_OK; - auto* d3d11_device = m_device->GetD3D11Device(); - auto* d3d11_devctx = m_device->GetD3D11DeviceContext(); - if (!d3d11_device || !d3d11_devctx) + const auto d3d11_device = static_cast(m_device->getNativeHandle()); + if (!d3d11_device) + return false; + win32::com_ptr d3d11_devctx; + d3d11_device->GetImmediateContext(d3d11_devctx.put()); + if (!d3d11_devctx) return false; #ifdef LUASTG_ENABLE_DIRECT2D - auto* d2d1_device_context = m_device->GetD2D1DeviceContext(); + const auto d2d1_device_context = static_cast(m_device->getNativeRendererHandle()); if (!d2d1_device_context) return false; #endif @@ -83,19 +85,19 @@ namespace core::Graphics::Direct3D11 { .ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D, .Texture2D = D3D11_TEX2D_RTV{.MipSlice = 0,}, }; - hr = gHR = d3d11_device->CreateRenderTargetView(m_texture->GetResource(), &rtvdef, &m_view); + hr = gHR = d3d11_device->CreateRenderTargetView(m_texture->GetResource(), &rtvdef, m_view.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateRenderTargetView"); + Logger::error("Windows API failed: ID3D11Device::CreateRenderTargetView"); return false; } - M_D3D_SET_DEBUG_NAME(m_view.Get(), "RenderTarget_D3D11::d3d11_rtv"); + M_D3D_SET_DEBUG_NAME(m_view.get(), "RenderTarget_D3D11::d3d11_rtv"); // 创建D2D1位图 - Microsoft::WRL::ComPtr dxgi_surface; - hr = gHR = m_texture->GetResource()->QueryInterface(IID_PPV_ARGS(&dxgi_surface)); + win32::com_ptr dxgi_surface; + hr = gHR = m_texture->GetResource()->QueryInterface(dxgi_surface.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Texture2D::QueryInterface -> IDXGISurface"); + Logger::error("Windows API failed: ID3D11Texture2D::QueryInterface -> IDXGISurface"); return false; } @@ -110,9 +112,9 @@ namespace core::Graphics::Direct3D11 { .bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET, .colorContext = nullptr, }; - hr = gHR = d2d1_device_context->CreateBitmapFromDxgiSurface(dxgi_surface.Get(), &bitmap_info, &m_bitmap); + hr = gHR = d2d1_device_context->CreateBitmapFromDxgiSurface(dxgi_surface.get(), &bitmap_info, m_bitmap.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11DeviceContext::CreateBitmapFromDxgiSurface"); + Logger::error("Windows API failed: ID3D11DeviceContext::CreateBitmapFromDxgiSurface"); return false; } #endif @@ -120,11 +122,14 @@ namespace core::Graphics::Direct3D11 { return true; } } -namespace core::Graphics::Direct3D11 { - bool Device::createRenderTarget(Vector2U const size, IRenderTarget** const pp_rt) { + +#include "d3d11/GraphicsDevice.hpp" + +namespace core { + bool GraphicsDevice::createRenderTarget(Vector2U const size, Graphics::IRenderTarget** const pp_rt) { *pp_rt = nullptr; - SmartReference buffer; - buffer.attach(new RenderTarget); + SmartReference buffer; + buffer.attach(new Graphics::Direct3D11::RenderTarget); if (!buffer->initialize(this, size)) { return false; } diff --git a/LuaSTG/Core/Graphics/Direct3D11/RenderTarget.hpp b/engine/graphics/core/Graphics/Direct3D11/RenderTarget.hpp similarity index 69% rename from LuaSTG/Core/Graphics/Direct3D11/RenderTarget.hpp rename to engine/graphics/core/Graphics/Direct3D11/RenderTarget.hpp index 5cfa6bdf..8444fe40 100644 --- a/LuaSTG/Core/Graphics/Direct3D11/RenderTarget.hpp +++ b/engine/graphics/core/Graphics/Direct3D11/RenderTarget.hpp @@ -1,27 +1,26 @@ #pragma once #include "core/SmartReference.hpp" #include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Device.hpp" +#include "core/GraphicsDevice.hpp" // RenderTarget namespace core::Graphics::Direct3D11 { - class Device; class Texture2D; class RenderTarget final : public implement::ReferenceCounted - , public IDeviceEventListener { + , public IGraphicsDeviceEventListener { public: - // IDeviceEventListener + // IGraphicsDeviceEventListener - void onDeviceCreate() override; - void onDeviceDestroy() override; + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; // IRenderTarget - [[nodiscard]] void* getNativeHandle() const noexcept override { return m_view.Get(); } + [[nodiscard]] void* getNativeHandle() const noexcept override { return m_view.get(); } #ifdef LUASTG_ENABLE_DIRECT2D - [[nodiscard]] void* getNativeBitmapHandle() const noexcept override { return m_bitmap.Get(); } + [[nodiscard]] void* getNativeBitmapHandle() const noexcept override { return m_bitmap.get(); } #else [[nodiscard]] void* getNativeBitmapHandle() const noexcept override { return nullptr; } #endif @@ -37,17 +36,17 @@ namespace core::Graphics::Direct3D11 { RenderTarget& operator=(RenderTarget&&) = delete; ~RenderTarget(); - [[nodiscard]] ID3D11RenderTargetView* GetView() const noexcept { return m_view.Get(); } + [[nodiscard]] ID3D11RenderTargetView* GetView() const noexcept { return m_view.get(); } - bool initialize(Device* device, Vector2U size); + bool initialize(IGraphicsDevice* device, Vector2U size); bool createResource(); private: - SmartReference m_device; + SmartReference m_device; SmartReference m_texture; - Microsoft::WRL::ComPtr m_view; + win32::com_ptr m_view; #ifdef LUASTG_ENABLE_DIRECT2D - Microsoft::WRL::ComPtr m_bitmap; + win32::com_ptr m_bitmap; #endif bool m_initialized{ false }; }; diff --git a/LuaSTG/Core/Graphics/Direct3D11/Texture2D.cpp b/engine/graphics/core/Graphics/Direct3D11/Texture2D.cpp similarity index 63% rename from LuaSTG/Core/Graphics/Direct3D11/Texture2D.cpp rename to engine/graphics/core/Graphics/Direct3D11/Texture2D.cpp index f2f6b3f4..9d907847 100644 --- a/LuaSTG/Core/Graphics/Direct3D11/Texture2D.cpp +++ b/engine/graphics/core/Graphics/Direct3D11/Texture2D.cpp @@ -1,45 +1,49 @@ -#include "Core/Graphics/Direct3D11/Texture2D.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" +#include "core/Graphics/Direct3D11/Texture2D.hpp" +#include "core/Logger.hpp" #include "core/FileSystem.hpp" -#include "Core/i18n.hpp" #include "utf8.hpp" #include "WICTextureLoader11.h" #include "DDSTextureLoader11.h" #include "QOITextureLoader11.h" #include "ScreenGrab11.h" +namespace { + IWICImagingFactory* getWIC(core::IGraphicsDevice* device); +} + // Texture2D namespace core::Graphics::Direct3D11 { - void Texture2D::onDeviceCreate() { + void Texture2D::onGraphicsDeviceCreate() { if (m_initialized) { createResource(); } } - void Texture2D::onDeviceDestroy() { - m_texture.Reset(); - m_view.Reset(); + void Texture2D::onGraphicsDeviceDestroy() { + m_texture.reset(); + m_view.reset(); } bool Texture2D::setSize(Vector2U const size) { if (!m_dynamic) { - spdlog::error("[core] 不能修改静态纹理的大小"); + Logger::error("[core] [Texture2D] read-only texture cannot be resized"); assert(false); return false; } if (!m_is_render_target) { - spdlog::error("[core] 此纹理由 RenderTarget 托管,禁止直接 setSize"); + Logger::error("[core] [Texture2D] this texture is managed by RenderTarget and cannot be resized"); assert(false); return false; } - onDeviceDestroy(); + onGraphicsDeviceDestroy(); m_size = size; return createResource(); } bool Texture2D::uploadPixelData(RectU const rc, void const* const data, uint32_t const pitch) { if (!m_dynamic) { - spdlog::error("[core] 不能修改静态纹理的内容"); + Logger::error("[core] [Texture2D] read-only texture cannot by modified"); assert(false); return false; } - auto const ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); + assert(m_device->getNativeHandle()); + win32::com_ptr ctx; + static_cast(m_device->getNativeHandle())->GetImmediateContext(ctx.put()); assert(m_texture); if (!ctx || !m_texture) { return false; @@ -52,15 +56,19 @@ namespace core::Graphics::Direct3D11 { .bottom = rc.b.y, .back = 1, }; - ctx->UpdateSubresource(m_texture.Get(), 0, &box, data, pitch, 0); + ctx->UpdateSubresource(m_texture.get(), 0, &box, data, pitch, 0); return true; } bool Texture2D::saveToFile(StringView const path) { + assert(m_device->getNativeHandle()); + win32::com_ptr ctx; + static_cast(m_device->getNativeHandle())->GetImmediateContext(ctx.put()); + std::wstring const wide_path(utf8::to_wstring(path)); HRESULT hr = S_OK; hr = gHR = DirectX::SaveWICTextureToFile( - m_device->GetD3D11DeviceContext(), - m_texture.Get(), + ctx.get(), + m_texture.get(), GUID_ContainerFormatJpeg, wide_path.c_str(), &GUID_WICPixelFormat24bppBGR); @@ -74,7 +82,7 @@ namespace core::Graphics::Direct3D11 { } } - bool Texture2D::initialize(Device* const device, StringView const path, bool const mipmap) { + bool Texture2D::initialize(IGraphicsDevice* const device, StringView const path, bool const mipmap) { assert(device); assert(!path.empty()); m_device = device; @@ -87,7 +95,7 @@ namespace core::Graphics::Direct3D11 { m_device->addEventListener(this); return true; } - bool Texture2D::initialize(Device* const device, IImage* const image, bool const mipmap) { + bool Texture2D::initialize(IGraphicsDevice* const device, IImage* const image, bool const mipmap) { // TODO: image must be read-only assert(device); assert(image); @@ -102,7 +110,7 @@ namespace core::Graphics::Direct3D11 { m_device->addEventListener(this); return true; } - bool Texture2D::initialize(Device* const device, Vector2U const size, bool const is_render_target) { + bool Texture2D::initialize(IGraphicsDevice* const device, Vector2U const size, bool const is_render_target) { assert(device); assert(size.x > 0 && size.y > 0); m_device = device; @@ -124,9 +132,12 @@ namespace core::Graphics::Direct3D11 { bool Texture2D::createResource() { HRESULT hr = S_OK; - auto* d3d11_device = m_device->GetD3D11Device(); - auto* d3d11_devctx = m_device->GetD3D11DeviceContext(); - if (!d3d11_device || !d3d11_devctx) + const auto d3d11_device = static_cast(m_device->getNativeHandle()); + if (!d3d11_device) + return false; + win32::com_ptr d3d11_devctx; + d3d11_device->GetImmediateContext(d3d11_devctx.put()); + if (!d3d11_devctx) return false; if (m_image) { @@ -174,12 +185,12 @@ namespace core::Graphics::Direct3D11 { .SysMemSlicePitch = buffer.size, }; - hr = gHR = d3d11_device->CreateTexture2D(&tex2d_desc, &subres_data, &m_texture); + hr = gHR = d3d11_device->CreateTexture2D(&tex2d_desc, &subres_data, m_texture.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateTexture2D"); + Logger::error("Windows API failed: ID3D11Device::CreateTexture2D"); return false; } - M_D3D_SET_DEBUG_NAME(m_texture.Get(), "Texture2D_D3D11::d3d11_texture2d"); + M_D3D_SET_DEBUG_NAME(m_texture.get(), "Texture2D_D3D11::d3d11_texture2d"); D3D11_SHADER_RESOURCE_VIEW_DESC view_desc = { .Format = tex2d_desc.Format, @@ -189,62 +200,62 @@ namespace core::Graphics::Direct3D11 { .MipLevels = 1, }, }; - hr = gHR = d3d11_device->CreateShaderResourceView(m_texture.Get(), &view_desc, &m_view); + hr = gHR = d3d11_device->CreateShaderResourceView(m_texture.get(), &view_desc, m_view.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateShaderResourceView"); + Logger::error("Windows API failed: ID3D11Device::CreateShaderResourceView"); return false; } - M_D3D_SET_DEBUG_NAME(m_view.Get(), "Texture2D_D3D11::d3d11_srv"); + M_D3D_SET_DEBUG_NAME(m_view.get(), "Texture2D_D3D11::d3d11_srv"); } else if (!m_source_path.empty()) { SmartReference src; if (!FileSystemManager::readFile(m_source_path, src.put())) { - spdlog::error("[core] 无法加载文件 '{}'", m_source_path); + Logger::error("[core] [Texture2D] read file '{}' failed", m_source_path); return false; } // 加载图片 - Microsoft::WRL::ComPtr res; + win32::com_ptr res; // 先尝试以 DDS 格式加载 DirectX::DDS_ALPHA_MODE dds_alpha_mode = DirectX::DDS_ALPHA_MODE_UNKNOWN; HRESULT const hr1 = DirectX::CreateDDSTextureFromMemoryEx( - d3d11_device, m_mipmap ? d3d11_devctx : nullptr, + d3d11_device, m_mipmap ? d3d11_devctx.get() : nullptr, static_cast(src->data()), src->size(), 0, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, DirectX::DDS_LOADER_IGNORE_SRGB, // TODO: 这里也同样忽略了 sRGB,看以后渲染管线颜色空间怎么改 - &res, &m_view, + res.put(), m_view.put(), &dds_alpha_mode); if (FAILED(hr1)) { // 尝试以普通图片格式加载 HRESULT const hr2 = DirectX::CreateWICTextureFromMemoryEx( - d3d11_device, m_mipmap ? d3d11_devctx : nullptr, + d3d11_device, m_mipmap ? d3d11_devctx.get() : nullptr, static_cast(src->data()), src->size(), 0, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, DirectX::WIC_LOADER_DEFAULT | DirectX::WIC_LOADER_IGNORE_SRGB, // TODO: 渲染管线目前是在 sRGB 下计算的,也就是心理视觉色彩,将错就错吧…… //DirectX::WIC_LOADER_DEFAULT | DirectX::WIC_LOADER_SRGB_DEFAULT, - &res, &m_view); + res.put(), m_view.put()); if (FAILED(hr2)) { // 尝试以 QOI 图片格式加载 HRESULT const hr3 = DirectX::CreateQOITextureFromMemoryEx( - d3d11_device, m_mipmap ? d3d11_devctx : nullptr, m_device->GetWICImagingFactory(), + d3d11_device, m_mipmap ? d3d11_devctx.get() : nullptr, getWIC(m_device.get()), static_cast(src->data()), src->size(), 0, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, 0, DirectX::QOI_LOADER_DEFAULT | DirectX::QOI_LOADER_IGNORE_SRGB, // TODO: 渲染管线目前是在 sRGB 下计算的,也就是心理视觉色彩,将错就错吧…… //DirectX::QOI_LOADER_DEFAULT | DirectX::QOI_LOADER_SRGB_DEFAULT, - &res, &m_view); + res.put(), m_view.put()); if (FAILED(hr3)) { // 在这里一起报告,不然 log 文件里遍地都是 error gHR = hr1; - i18n_core_system_call_report_error("DirectX::CreateDDSTextureFromMemoryEx"); + Logger::error("Windows API failed: DirectX::CreateDDSTextureFromMemoryEx"); gHR = hr2; - i18n_core_system_call_report_error("DirectX::CreateWICTextureFromMemoryEx"); + Logger::error("Windows API failed: DirectX::CreateWICTextureFromMemoryEx"); gHR = hr3; - i18n_core_system_call_report_error("DirectX::CreateQOITextureFromMemoryEx"); + Logger::error("Windows API failed: DirectX::CreateQOITextureFromMemoryEx"); return false; } } @@ -252,15 +263,15 @@ namespace core::Graphics::Direct3D11 { if (dds_alpha_mode == DirectX::DDS_ALPHA_MODE_PREMULTIPLIED) { m_pre_mul_alpha = true; // 您小子预乘了 alpha 通道是吧,行 } - M_D3D_SET_DEBUG_NAME(m_view.Get(), "Texture2D_D3D11::d3d11_srv"); + M_D3D_SET_DEBUG_NAME(m_view.get(), "Texture2D_D3D11::d3d11_srv"); // 转换类型 - hr = gHR = res.As(&m_texture); + hr = gHR = res->QueryInterface(m_texture.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Resource::QueryInterface -> ID3D11Texture2D"); + Logger::error("Windows API failed: ID3D11Resource::QueryInterface -> ID3D11Texture2D"); return false; } - M_D3D_SET_DEBUG_NAME(m_texture.Get(), "Texture2D_D3D11::d3d11_texture2d"); + M_D3D_SET_DEBUG_NAME(m_texture.get(), "Texture2D_D3D11::d3d11_texture2d"); // 获取图片尺寸 D3D11_TEXTURE2D_DESC texture_info{}; @@ -281,61 +292,70 @@ namespace core::Graphics::Direct3D11 { .CPUAccessFlags = 0, .MiscFlags = 0, }; - hr = gHR = d3d11_device->CreateTexture2D(&texdef, nullptr, &m_texture); + hr = gHR = d3d11_device->CreateTexture2D(&texdef, nullptr, m_texture.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateTexture2D"); + Logger::error("Windows API failed: ID3D11Device::CreateTexture2D"); return false; } - M_D3D_SET_DEBUG_NAME(m_texture.Get(), "Texture2D_D3D11::d3d11_texture2d"); + M_D3D_SET_DEBUG_NAME(m_texture.get(), "Texture2D_D3D11::d3d11_texture2d"); D3D11_SHADER_RESOURCE_VIEW_DESC viewdef = { .Format = texdef.Format, .ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D, .Texture2D = D3D11_TEX2D_SRV{.MostDetailedMip = 0,.MipLevels = 1,}, }; - hr = gHR = d3d11_device->CreateShaderResourceView(m_texture.Get(), &viewdef, &m_view); + hr = gHR = d3d11_device->CreateShaderResourceView(m_texture.get(), &viewdef, m_view.put()); if (FAILED(hr)) { - i18n_core_system_call_report_error("ID3D11Device::CreateShaderResourceView"); + Logger::error("Windows API failed: ID3D11Device::CreateShaderResourceView"); return false; } - M_D3D_SET_DEBUG_NAME(m_view.Get(), "Texture2D_D3D11::d3d11_srv"); + M_D3D_SET_DEBUG_NAME(m_view.get(), "Texture2D_D3D11::d3d11_srv"); } return true; } } -namespace core::Graphics::Direct3D11 { - bool Device::createTextureFromFile(StringView const path, bool const mipmap, ITexture2D** const pp_texture) { + +#include "d3d11/GraphicsDevice.hpp" + +namespace { + IWICImagingFactory* getWIC(core::IGraphicsDevice* const device) { + return static_cast(device)->GetWICImagingFactory(); + } +} + +namespace core { + bool GraphicsDevice::createTextureFromFile(StringView const path, bool const mipmap, Graphics::ITexture2D** const pp_texture) { *pp_texture = nullptr; - SmartReference buffer; - buffer.attach(new Texture2D); + SmartReference buffer; + buffer.attach(new Graphics::Direct3D11::Texture2D); if (!buffer->initialize(this, path, mipmap)) { return false; } *pp_texture = buffer.detach(); return true; } - bool Device::createTextureFromImage(IImage* const image, bool const mipmap, ITexture2D** const pp_texture) { + bool GraphicsDevice::createTextureFromImage(IImage* const image, bool const mipmap, Graphics::ITexture2D** const pp_texture) { *pp_texture = nullptr; if (image == nullptr) { return false; } - SmartReference buffer; - buffer.attach(new Texture2D); + SmartReference buffer; + buffer.attach(new Graphics::Direct3D11::Texture2D); if (!buffer->initialize(this, image, mipmap)) { return false; } *pp_texture = buffer.detach(); return true; } - bool Device::createTexture(Vector2U const size, ITexture2D** const pp_texture) { + bool GraphicsDevice::createTexture(Vector2U const size, Graphics::ITexture2D** const pp_texture) { *pp_texture = nullptr; - SmartReference buffer; - buffer.attach(new Texture2D); + SmartReference buffer; + buffer.attach(new Graphics::Direct3D11::Texture2D); if (!buffer->initialize(this, size, false)) { return false; } *pp_texture = buffer.detach(); return true; } -} \ No newline at end of file +} diff --git a/LuaSTG/Core/Graphics/Direct3D11/Texture2D.hpp b/engine/graphics/core/Graphics/Direct3D11/Texture2D.hpp similarity index 63% rename from LuaSTG/Core/Graphics/Direct3D11/Texture2D.hpp rename to engine/graphics/core/Graphics/Direct3D11/Texture2D.hpp index 2f9c457c..4841841e 100644 --- a/LuaSTG/Core/Graphics/Direct3D11/Texture2D.hpp +++ b/engine/graphics/core/Graphics/Direct3D11/Texture2D.hpp @@ -1,24 +1,22 @@ #pragma once #include "core/SmartReference.hpp" #include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Device.hpp" +#include "core/GraphicsDevice.hpp" // Texture2D namespace core::Graphics::Direct3D11 { - class Device; - class Texture2D final : public implement::ReferenceCounted - , public IDeviceEventListener { + , public IGraphicsDeviceEventListener { public: - // IDeviceEventListener + // IGraphicsDeviceEventListener - void onDeviceCreate() override; - void onDeviceDestroy() override; + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; // ITexture2D - [[nodiscard]] void* getNativeHandle() const noexcept override { return m_view.Get(); } + [[nodiscard]] void* getNativeHandle() const noexcept override { return m_view.get(); } [[nodiscard]] bool isDynamic() const noexcept override { return m_dynamic; } [[nodiscard]] bool isPremultipliedAlpha() const noexcept override { return m_pre_mul_alpha; } @@ -31,8 +29,8 @@ namespace core::Graphics::Direct3D11 { bool saveToFile(StringView path) override; - void setSamplerState(ISamplerState* p_sampler) override { m_sampler = p_sampler; } - [[nodiscard]] ISamplerState* getSamplerState() const noexcept override { return m_sampler.get(); } + void setSamplerState(IGraphicsSampler* p_sampler) override { m_sampler = p_sampler; } + [[nodiscard]] IGraphicsSampler* getSamplerState() const noexcept override { return m_sampler.get(); } // Texture2D @@ -43,21 +41,21 @@ namespace core::Graphics::Direct3D11 { Texture2D& operator=(Texture2D&&) = delete; ~Texture2D(); - [[nodiscard]] ID3D11Texture2D* GetResource() const noexcept { return m_texture.Get(); } - [[nodiscard]] ID3D11ShaderResourceView* GetView() const noexcept { return m_view.Get(); } + [[nodiscard]] ID3D11Texture2D* GetResource() const noexcept { return m_texture.get(); } + [[nodiscard]] ID3D11ShaderResourceView* GetView() const noexcept { return m_view.get(); } - bool initialize(Device* device, StringView path, bool mipmap); - bool initialize(Device* device, IImage* image, bool mipmap); - bool initialize(Device* device, Vector2U size, bool is_render_target); + bool initialize(IGraphicsDevice* device, StringView path, bool mipmap); + bool initialize(IGraphicsDevice* device, IImage* image, bool mipmap); + bool initialize(IGraphicsDevice* device, Vector2U size, bool is_render_target); bool createResource(); private: - SmartReference m_device; - SmartReference m_sampler; + SmartReference m_device; + SmartReference m_sampler; SmartReference m_image; std::string m_source_path; - Microsoft::WRL::ComPtr m_texture; - Microsoft::WRL::ComPtr m_view; + win32::com_ptr m_texture; + win32::com_ptr m_view; Vector2U m_size{}; bool m_dynamic{ false }; bool m_pre_mul_alpha{ false }; diff --git a/LuaSTG/Core/Graphics/Font.hpp b/engine/graphics/core/Graphics/Font.hpp similarity index 91% rename from LuaSTG/Core/Graphics/Font.hpp rename to engine/graphics/core/Graphics/Font.hpp index 819af68d..68f9e26d 100644 --- a/LuaSTG/Core/Graphics/Font.hpp +++ b/engine/graphics/core/Graphics/Font.hpp @@ -1,102 +1,102 @@ -#pragma once -#include "Core/Graphics/Device.hpp" -#include "Core/Graphics/Renderer.hpp" -#include "core/ReferenceCounted.hpp" -#include "core/TextLayout.hpp" - -namespace core::Graphics -{ - struct GlyphInfo - { - uint32_t texture_index = 0; // 字形在哪个纹理上 - RectF texture_rect; // 字形在纹理上的uv坐标 - Vector2F size; // 字形大小 - Vector2F position; // 笔触距离字形左上角坐标 - Vector2F advance; // 前进量 - }; - - struct TrueTypeFontInfo - { - StringView source; - uint32_t font_face; // 字面索引,一个字体文件中有多个字面 - Vector2F font_size; // 像素大小 - bool is_force_to_file; // source 参数代表文件路径,且强制以文件的方式打开,不读取进内存,当 is_buffer = true 时忽略该选项 - bool is_buffer; // source 参数代表二进制数据,而不是文件路径 - }; - - struct IGlyphManager : public IReferenceCounted - { - virtual float getLineHeight() = 0; - virtual float getAscender() = 0; - virtual float getDescender() = 0; - - virtual uint32_t getTextureCount() = 0; - virtual ITexture2D* getTexture(uint32_t index) = 0; - - virtual bool cacheGlyph(uint32_t codepoint) = 0; - virtual bool cacheString(StringView str) = 0; - virtual bool flush() = 0; - - virtual bool getGlyph(uint32_t codepoint, GlyphInfo* p_ref_info, bool no_render) = 0; - - static bool create(IDevice* p_device, TrueTypeFontInfo const* p_arr_info, size_t info_count, IGlyphManager** output); - }; - - struct ITextRenderer : public IReferenceCounted - { - virtual void setScale(Vector2F const& scale) = 0; - virtual Vector2F getScale() = 0; - virtual void setColor(Color4B const color) = 0; - virtual Color4B getColor() = 0; - virtual void setZ(float const z) = 0; - virtual float getZ() = 0; - virtual void setGlyphManager(IGlyphManager* p_mgr) = 0; - virtual IGlyphManager* getGlyphManager() = 0; - - // 测量一个字符串绘制的精确包围盒大小(受到 setScale 影响) - virtual RectF getTextBoundary(StringView str) = 0; - // 测量一个字符串绘制的前进量(受到 setScale 影响) - virtual Vector2F getTextAdvance(StringView str) = 0; - // 绘制文字,y 轴朝上(受到 setScale 影响) - virtual bool drawText(StringView str, Vector2F const& start, Vector2F* end_output) = 0; - // 绘制文字,提供 3D 的移动向量,以便在空间中绘制(受到 setScale 影响) - virtual bool drawTextInSpace(StringView str, - Vector3F const& start, Vector3F const& right_vec, Vector3F const& down_vec, - Vector3F* end_output) = 0; - - static bool create(IRenderer* p_renderer, ITextRenderer** output); - }; - - struct ITextRenderer2 : public IReferenceCounted { - virtual void setTransform(RectF const& rect) = 0; - virtual void setTransform(Vector2F const& p1, Vector2F const& p2, Vector2F const& p3, Vector2F const& p4) = 0; - virtual void setTransform(Vector3F const& p1, Vector3F const& p2, Vector3F const& p3, Vector3F const& p4) = 0; - virtual void setTransform(Vector2F const& position, Vector2F const& scale, float rotation) = 0; - virtual void setTextLayout(ITextLayout* text_layout) = 0; - virtual void setColor(Color4B color) = 0; - virtual void setColor(Color4B c1, Color4B c2, Color4B c3, Color4B c4) = 0; - virtual void setAnchor(Vector2F anchor) = 0; - virtual void setZ(float z) = 0; - virtual void setLegacyBlendState(IRenderer::VertexColorBlendState vertex_color_blend_state, IRenderer::BlendState blend_state) = 0; - virtual void draw(IRenderer* renderer) = 0; - - static bool create(IDevice* device, ITextRenderer2** output); - }; -} - -namespace core { - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IGlyphManager - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("2c719bf6-dbf1-5d51-86c6-8ea3c1d5a7f0"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.ITextRenderer - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("23c381e5-4769-5caf-9623-5f050c0f9aba"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.ITextRenderer2 - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("3308ba67-afc6-54ef-938b-7aeb006876a0"); } -} +#pragma once +#include "core/GraphicsDevice.hpp" +#include "core/Graphics/Renderer.hpp" +#include "core/ReferenceCounted.hpp" +#include "core/TextLayout.hpp" + +namespace core::Graphics +{ + struct GlyphInfo + { + uint32_t texture_index = 0; // 字形在哪个纹理上 + RectF texture_rect; // 字形在纹理上的uv坐标 + Vector2F size; // 字形大小 + Vector2F position; // 笔触距离字形左上角坐标 + Vector2F advance; // 前进量 + }; + + struct TrueTypeFontInfo + { + StringView source; + uint32_t font_face; // 字面索引,一个字体文件中有多个字面 + Vector2F font_size; // 像素大小 + bool is_force_to_file; // source 参数代表文件路径,且强制以文件的方式打开,不读取进内存,当 is_buffer = true 时忽略该选项 + bool is_buffer; // source 参数代表二进制数据,而不是文件路径 + }; + + struct IGlyphManager : public IReferenceCounted + { + virtual float getLineHeight() = 0; + virtual float getAscender() = 0; + virtual float getDescender() = 0; + + virtual uint32_t getTextureCount() = 0; + virtual ITexture2D* getTexture(uint32_t index) = 0; + + virtual bool cacheGlyph(uint32_t codepoint) = 0; + virtual bool cacheString(StringView str) = 0; + virtual bool flush() = 0; + + virtual bool getGlyph(uint32_t codepoint, GlyphInfo* p_ref_info, bool no_render) = 0; + + static bool create(IGraphicsDevice* p_device, TrueTypeFontInfo const* p_arr_info, size_t info_count, IGlyphManager** output); + }; + + struct ITextRenderer : public IReferenceCounted + { + virtual void setScale(Vector2F const& scale) = 0; + virtual Vector2F getScale() = 0; + virtual void setColor(Color4B const color) = 0; + virtual Color4B getColor() = 0; + virtual void setZ(float const z) = 0; + virtual float getZ() = 0; + virtual void setGlyphManager(IGlyphManager* p_mgr) = 0; + virtual IGlyphManager* getGlyphManager() = 0; + + // 测量一个字符串绘制的精确包围盒大小(受到 setScale 影响) + virtual RectF getTextBoundary(StringView str) = 0; + // 测量一个字符串绘制的前进量(受到 setScale 影响) + virtual Vector2F getTextAdvance(StringView str) = 0; + // 绘制文字,y 轴朝上(受到 setScale 影响) + virtual bool drawText(StringView str, Vector2F const& start, Vector2F* end_output) = 0; + // 绘制文字,提供 3D 的移动向量,以便在空间中绘制(受到 setScale 影响) + virtual bool drawTextInSpace(StringView str, + Vector3F const& start, Vector3F const& right_vec, Vector3F const& down_vec, + Vector3F* end_output) = 0; + + static bool create(IRenderer* p_renderer, ITextRenderer** output); + }; + + struct ITextRenderer2 : public IReferenceCounted { + virtual void setTransform(RectF const& rect) = 0; + virtual void setTransform(Vector2F const& p1, Vector2F const& p2, Vector2F const& p3, Vector2F const& p4) = 0; + virtual void setTransform(Vector3F const& p1, Vector3F const& p2, Vector3F const& p3, Vector3F const& p4) = 0; + virtual void setTransform(Vector2F const& position, Vector2F const& scale, float rotation) = 0; + virtual void setTextLayout(ITextLayout* text_layout) = 0; + virtual void setColor(Color4B color) = 0; + virtual void setColor(Color4B c1, Color4B c2, Color4B c3, Color4B c4) = 0; + virtual void setAnchor(Vector2F anchor) = 0; + virtual void setZ(float z) = 0; + virtual void setLegacyBlendState(IRenderer::VertexColorBlendState vertex_color_blend_state, IRenderer::BlendState blend_state) = 0; + virtual void draw(IRenderer* renderer) = 0; + + static bool create(IGraphicsDevice* device, ITextRenderer2** output); + }; +} + +namespace core { + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.IGlyphManager + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("2c719bf6-dbf1-5d51-86c6-8ea3c1d5a7f0"); } + + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.ITextRenderer + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("23c381e5-4769-5caf-9623-5f050c0f9aba"); } + + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.ITextRenderer2 + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("3308ba67-afc6-54ef-938b-7aeb006876a0"); } +} diff --git a/LuaSTG/Core/Graphics/Format.hpp b/engine/graphics/core/Graphics/Format.hpp similarity index 92% rename from LuaSTG/Core/Graphics/Format.hpp rename to engine/graphics/core/Graphics/Format.hpp index 76d25e06..5e57fb15 100644 --- a/LuaSTG/Core/Graphics/Format.hpp +++ b/engine/graphics/core/Graphics/Format.hpp @@ -1,12 +1,12 @@ -#pragma once -#include - -namespace core::Graphics -{ - enum class Format : uint32_t - { - Unknown, - R8G8B8A8_UNORM, - B8G8R8A8_UNORM, - }; -} +#pragma once +#include + +namespace core::Graphics +{ + enum class Format : uint32_t + { + Unknown, + R8G8B8A8_UNORM, + B8G8R8A8_UNORM, + }; +} diff --git a/LuaSTG/Core/Graphics/Mesh.hpp b/engine/graphics/core/Graphics/Mesh.hpp similarity index 92% rename from LuaSTG/Core/Graphics/Mesh.hpp rename to engine/graphics/core/Graphics/Mesh.hpp index 1961b119..5928b86c 100644 --- a/LuaSTG/Core/Graphics/Mesh.hpp +++ b/engine/graphics/core/Graphics/Mesh.hpp @@ -1,7 +1,7 @@ #pragma once #include "core/Matrix4x4.hpp" -#include "Core/Graphics/Device.hpp" -#include "Core/Graphics/Renderer.hpp" +#include "core/GraphicsDevice.hpp" +#include "core/Graphics/Renderer.hpp" #include "core/ReferenceCounted.hpp" namespace core::Graphics { @@ -55,7 +55,7 @@ namespace core::Graphics { virtual bool commit() = 0; virtual void setReadOnly() = 0; - static bool create(IDevice* device, MeshOptions const& options, IMesh** output); + static bool create(IGraphicsDevice* device, MeshOptions const& options, IMesh** output); }; struct IMeshRenderer : IReferenceCounted { @@ -65,7 +65,7 @@ namespace core::Graphics { virtual void setLegacyBlendState(IRenderer::VertexColorBlendState vertex_color_blend_state, IRenderer::BlendState blend_state) = 0; virtual void draw(IRenderer* renderer) = 0; - static bool create(IDevice* device, IMeshRenderer** output); + static bool create(IGraphicsDevice* device, IMeshRenderer** output); }; } diff --git a/LuaSTG/Core/Graphics/Model_D3D11.cpp b/engine/graphics/core/Graphics/Model_D3D11.cpp similarity index 88% rename from LuaSTG/Core/Graphics/Model_D3D11.cpp rename to engine/graphics/core/Graphics/Model_D3D11.cpp index 2953f7e0..a8fd1ddb 100644 --- a/LuaSTG/Core/Graphics/Model_D3D11.cpp +++ b/engine/graphics/core/Graphics/Model_D3D11.cpp @@ -1,4 +1,5 @@ -#include "Core/Graphics/Model_D3D11.hpp" +#include "core/Graphics/Model_D3D11.hpp" +#include "core/Logger.hpp" #include "core/FileSystem.hpp" #define IDX(x) (size_t)static_cast(x) @@ -86,8 +87,8 @@ namespace core::Graphics .SysMemPitch = 64 * 4, .SysMemSlicePitch = 0, }; - Microsoft::WRL::ComPtr def_texture2d; - hr = device->CreateTexture2D(&def_tex_def, &def_dat_def, &def_texture2d); + win32::com_ptr def_texture2d; + hr = device->CreateTexture2D(&def_tex_def, &def_dat_def, def_texture2d.put()); if (FAILED(hr)) { assert(false); @@ -101,7 +102,7 @@ namespace core::Graphics .MipLevels = def_tex_def.MipLevels, }, }; - hr = device->CreateShaderResourceView(def_texture2d.Get(), &def_srv_def, &default_image); + hr = device->CreateShaderResourceView(def_texture2d.get(), &def_srv_def, default_image.put()); if (FAILED(hr)) { assert(false); @@ -131,7 +132,7 @@ namespace core::Graphics .MinLOD = 0.0f, .MaxLOD = D3D11_FLOAT32_MAX, }; - hr = device->CreateSamplerState(&def_samp_def, &default_sampler); + hr = device->CreateSamplerState(&def_samp_def, default_sampler.put()); if (FAILED(hr)) { assert(false); @@ -157,7 +158,7 @@ namespace core::Graphics .MiscFlags = 0, .StructureByteStride = 0, }; - hr = device->CreateBuffer(&cbo_def, NULL, &cbo_mvp); + hr = device->CreateBuffer(&cbo_def, NULL, cbo_mvp.put()); if (FAILED(hr)) { assert(false); @@ -167,7 +168,7 @@ namespace core::Graphics // built-in: local-world matrix cbo_def.ByteWidth = 2 * sizeof(DirectX::XMFLOAT4X4); - hr = device->CreateBuffer(&cbo_def, NULL, &cbo_mlw); + hr = device->CreateBuffer(&cbo_def, NULL, cbo_mlw.put()); if (FAILED(hr)) { assert(false); @@ -177,7 +178,7 @@ namespace core::Graphics // built-in: camera info cbo_def.ByteWidth = 2 * sizeof(DirectX::XMFLOAT4X4); - hr = device->CreateBuffer(&cbo_def, NULL, &cbo_caminfo); + hr = device->CreateBuffer(&cbo_def, NULL, cbo_caminfo.put()); if (FAILED(hr)) { assert(false); @@ -187,7 +188,7 @@ namespace core::Graphics // // built-in: alpha mask cbo_def.ByteWidth = 2 * sizeof(DirectX::XMFLOAT4); - hr = device->CreateBuffer(&cbo_def, NULL, &cbo_alpha); + hr = device->CreateBuffer(&cbo_def, NULL, cbo_alpha.put()); if (FAILED(hr)) { assert(false); @@ -197,7 +198,7 @@ namespace core::Graphics // // built-in: light cbo_def.ByteWidth = 4 * sizeof(DirectX::XMFLOAT4); - hr = device->CreateBuffer(&cbo_def, NULL, &cbo_light); + hr = device->CreateBuffer(&cbo_def, NULL, cbo_light.put()); if (FAILED(hr)) { assert(false); @@ -229,7 +230,7 @@ namespace core::Graphics .MultisampleEnable = FALSE, .AntialiasedLineEnable = FALSE, }; - hr = device->CreateRasterizerState(&rs_def, &state_rs_cull_none); + hr = device->CreateRasterizerState(&rs_def, state_rs_cull_none.put()); if (FAILED(hr)) { assert(false); @@ -240,7 +241,7 @@ namespace core::Graphics rs_def.CullMode = D3D11_CULL_BACK; rs_def.FrontCounterClockwise = TRUE; - hr = device->CreateRasterizerState(&rs_def, &state_rs_cull_back); + hr = device->CreateRasterizerState(&rs_def, state_rs_cull_back.put()); if (FAILED(hr)) { assert(false); @@ -271,7 +272,7 @@ namespace core::Graphics .StencilFunc = D3D11_COMPARISON_ALWAYS, }, }; - hr = device->CreateDepthStencilState(&ds_def, &state_ds); + hr = device->CreateDepthStencilState(&ds_def, state_ds.put()); if (FAILED(hr)) { assert(false); @@ -282,7 +283,7 @@ namespace core::Graphics ds_def.DepthFunc = D3D11_COMPARISON_LESS; - hr = device->CreateDepthStencilState(&ds_def, &state_ds_dl); + hr = device->CreateDepthStencilState(&ds_def, state_ds_dl.put()); if (FAILED(hr)) { assert(false); @@ -293,7 +294,7 @@ namespace core::Graphics ds_def.DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ZERO; - hr = device->CreateDepthStencilState(&ds_def, &state_ds_no_write); + hr = device->CreateDepthStencilState(&ds_def, state_ds_no_write.put()); if (FAILED(hr)) { assert(false); @@ -305,7 +306,7 @@ namespace core::Graphics ds_def.DepthEnable = FALSE; ds_def.DepthFunc = D3D11_COMPARISON_ALWAYS; - hr = device->CreateDepthStencilState(&ds_def, &state_ds_disable); + hr = device->CreateDepthStencilState(&ds_def, state_ds_disable.put()); if (FAILED(hr)) { assert(false); @@ -335,7 +336,7 @@ namespace core::Graphics { rt_blend = rt_blend_def; } - hr = device->CreateBlendState(&blend_def, &state_blend); + hr = device->CreateBlendState(&blend_def, state_blend.put()); if (FAILED(hr)) { assert(false); @@ -350,7 +351,7 @@ namespace core::Graphics { rt_blend = rt_blend_def; } - hr = device->CreateBlendState(&blend_def, &state_blend_alpha); + hr = device->CreateBlendState(&blend_def, state_blend_alpha.put()); if (FAILED(hr)) { assert(false); @@ -384,42 +385,42 @@ namespace core::Graphics return true; } - void ModelSharedComponent_D3D11::onDeviceCreate() + void ModelSharedComponent_D3D11::onGraphicsDeviceCreate() { createResources(); } - void ModelSharedComponent_D3D11::onDeviceDestroy() + void ModelSharedComponent_D3D11::onGraphicsDeviceDestroy() { - default_image.Reset(); - default_sampler.Reset(); - - input_layout.Reset(); - input_layout_vc.Reset(); - shader_vertex.Reset(); - shader_vertex_vc.Reset(); - for (auto& v : shader_pixel) v.Reset(); - for (auto& v : shader_pixel_alpha) v.Reset(); - for (auto& v : shader_pixel_nt) v.Reset(); - for (auto& v : shader_pixel_alpha_nt) v.Reset(); - for (auto& v : shader_pixel_vc) v.Reset(); - for (auto& v : shader_pixel_alpha_vc) v.Reset(); - for (auto& v : shader_pixel_nt_vc) v.Reset(); - for (auto& v : shader_pixel_alpha_nt_vc) v.Reset(); - - state_rs_cull_none.Reset(); - state_rs_cull_back.Reset(); - state_ds.Reset(); - state_blend.Reset(); - state_blend_alpha.Reset(); - - cbo_mvp.Reset(); - cbo_mlw.Reset(); - cbo_caminfo.Reset(); - cbo_alpha.Reset(); - cbo_light.Reset(); + default_image.reset(); + default_sampler.reset(); + + input_layout.reset(); + input_layout_vc.reset(); + shader_vertex.reset(); + shader_vertex_vc.reset(); + for (auto& v : shader_pixel) v.reset(); + for (auto& v : shader_pixel_alpha) v.reset(); + for (auto& v : shader_pixel_nt) v.reset(); + for (auto& v : shader_pixel_alpha_nt) v.reset(); + for (auto& v : shader_pixel_vc) v.reset(); + for (auto& v : shader_pixel_alpha_vc) v.reset(); + for (auto& v : shader_pixel_nt_vc) v.reset(); + for (auto& v : shader_pixel_alpha_nt_vc) v.reset(); + + state_rs_cull_none.reset(); + state_rs_cull_back.reset(); + state_ds.reset(); + state_blend.reset(); + state_blend_alpha.reset(); + + cbo_mvp.reset(); + cbo_mlw.reset(); + cbo_caminfo.reset(); + cbo_alpha.reset(); + cbo_light.reset(); } - ModelSharedComponent_D3D11::ModelSharedComponent_D3D11(Direct3D11::Device* p_device) + ModelSharedComponent_D3D11::ModelSharedComponent_D3D11(GraphicsDevice* p_device) : m_device(p_device) { if (!createResources()) @@ -603,8 +604,8 @@ namespace core::Graphics ) { // buffer view if (accessor.bufferView < 0 || accessor.bufferView >= model.bufferViews.size()) { - spdlog::error( - "[core] gltf 2.0 loader -- accessor (index = {}) buffer view index out of bound (value = {})", + Logger::error( + "[core] [Model] gltf 2.0 loader -- accessor (index = {}) buffer view index out of bound (value = {})", &accessor - model.accessors.data(), accessor.bufferView ); @@ -612,8 +613,8 @@ namespace core::Graphics const auto& buffer_view = model.bufferViews[accessor.bufferView]; // buffer if (buffer_view.buffer < 0 || buffer_view.buffer >= model.buffers.size()) { - spdlog::error( - "[core] gltf 2.0 loader -- buffer view (index = {}) buffer index out of bound (value = {})", + Logger::error( + "[core] [Model] gltf 2.0 loader -- buffer view (index = {}) buffer index out of bound (value = {})", &buffer_view - model.bufferViews.data(), buffer_view.buffer ); @@ -621,16 +622,16 @@ namespace core::Graphics const auto& buffer = model.buffers[buffer_view.buffer]; // total size if (tinygltf::GetComponentSizeInBytes(accessor.componentType) < 0) { - spdlog::error( - "[core] gltf 2.0 loader -- unknown accessor (index = {}) component type (value = {})", + Logger::error( + "[core] [Model] gltf 2.0 loader -- unknown accessor (index = {}) component type (value = {})", &accessor - model.accessors.data(), accessor.componentType ); return false; } if (tinygltf::GetNumComponentsInType(accessor.type) < 0) { - spdlog::error( - "[core] gltf 2.0 loader -- unknown accessor (index = {}) type (value = {})", + Logger::error( + "[core] [Model] gltf 2.0 loader -- unknown accessor (index = {}) type (value = {})", &accessor - model.accessors.data(), accessor.type ); @@ -705,7 +706,7 @@ namespace core::Graphics if (img.width <= 0 || img.height <= 0) { image[idx] = shared_->default_image; // 兄啊,你这纹理好怪哦 - spdlog::error("[core] 加载纹理 '{}' 失败", img.name); + Logger::error("[core] [Model] load texture '{}' failed", img.name); continue; } @@ -730,8 +731,8 @@ namespace core::Graphics .SysMemPitch = (UINT)(img.width * img.component * img.bits) / 8, .SysMemSlicePitch = (UINT)img.image.size(), }; - Microsoft::WRL::ComPtr texture2d; - hr = device->CreateTexture2D(&tex_def, mipmap ? NULL : &dat_def, &texture2d); + win32::com_ptr texture2d; + hr = device->CreateTexture2D(&tex_def, mipmap ? NULL : &dat_def, texture2d.put()); if (FAILED(hr)) { assert(false); @@ -745,7 +746,7 @@ namespace core::Graphics .MipLevels = mipmap ? UINT(-1) : tex_def.MipLevels, }, }; - hr = device->CreateShaderResourceView(texture2d.Get(), &srv_def, &image[idx]); + hr = device->CreateShaderResourceView(texture2d.get(), &srv_def, image[idx].put()); if (FAILED(hr)) { assert(false); @@ -753,8 +754,8 @@ namespace core::Graphics } if (mipmap) { - context->UpdateSubresource(texture2d.Get(), 0, NULL, dat_def.pSysMem, dat_def.SysMemPitch, dat_def.SysMemSlicePitch); - context->GenerateMips(image[idx].Get()); + context->UpdateSubresource(texture2d.get(), 0, NULL, dat_def.pSysMem, dat_def.SysMemPitch, dat_def.SysMemSlicePitch); + context->GenerateMips(image[idx].get()); } } @@ -786,7 +787,7 @@ namespace core::Graphics }; map_sampler_to_d3d11(samp, samp_def); samp_def.Filter = D3D11_FILTER_ANISOTROPIC; // TODO: better? - hr = device->CreateSamplerState(&samp_def, &sampler[idx]); + hr = device->CreateSamplerState(&samp_def, sampler[idx].put()); if (FAILED(hr)) { assert(false); @@ -840,7 +841,7 @@ namespace core::Graphics .SysMemPitch = 0, .SysMemSlicePitch = 0, }; - hr = device->CreateBuffer(&vbo_def, &dat_def, &mblock.vertex_buffer); + hr = device->CreateBuffer(&vbo_def, &dat_def, mblock.vertex_buffer.put()); if (FAILED(hr)) { assert(false); @@ -871,7 +872,7 @@ namespace core::Graphics .SysMemPitch = 0, .SysMemSlicePitch = 0, }; - hr = device->CreateBuffer(&vbo_def, &dat_def, &mblock.normal_buffer); + hr = device->CreateBuffer(&vbo_def, &dat_def, mblock.normal_buffer.put()); if (FAILED(hr)) { assert(false); @@ -900,7 +901,7 @@ namespace core::Graphics .SysMemPitch = 0, .SysMemSlicePitch = 0, }; - hr = device->CreateBuffer(&vbo_def, &dat_def, &mblock.color_buffer); + hr = device->CreateBuffer(&vbo_def, &dat_def, mblock.color_buffer.put()); if (FAILED(hr)) { assert(false); @@ -929,7 +930,7 @@ namespace core::Graphics .SysMemPitch = 0, .SysMemSlicePitch = 0, }; - hr = device->CreateBuffer(&vbo_def, &dat_def, &mblock.uv_buffer); + hr = device->CreateBuffer(&vbo_def, &dat_def, mblock.uv_buffer.put()); if (FAILED(hr)) { assert(false); @@ -976,7 +977,7 @@ namespace core::Graphics assert(index_size == 2 || index_size == 4); mblock.index_format = index_size == 2 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; - hr = device->CreateBuffer(&ibo_def, &dat_def, &mblock.index_buffer); + hr = device->CreateBuffer(&ibo_def, &dat_def, mblock.index_buffer.put()); if (FAILED(hr)) { assert(false); @@ -1116,11 +1117,11 @@ namespace core::Graphics } if (!warn.empty()) { - spdlog::warn("[core] gltf model warning: {}", warn); + Logger::warn("[core] [Model] gltf model warning: {}", warn); } if (!err.empty()) { - spdlog::error("[core] gltf model error: {}", err); + Logger::error("[core] [Model] gltf model error: {}", err); } if (!ret) { @@ -1141,11 +1142,11 @@ namespace core::Graphics return true; } - void Model_D3D11::onDeviceCreate() + void Model_D3D11::onGraphicsDeviceCreate() { createResources(); } - void Model_D3D11::onDeviceDestroy() + void Model_D3D11::onGraphicsDeviceDestroy() { image.clear(); sampler.clear(); @@ -1159,7 +1160,7 @@ namespace core::Graphics // common data - context->UpdateSubresource(shared_->cbo_light.Get(), 0, NULL, &sunshine, 0, 0); + context->UpdateSubresource(shared_->cbo_light.get(), 0, NULL, &sunshine, 0, 0); DirectX::XMMATRIX const t_locwo_ = DirectX::XMMatrixMultiply(DirectX::XMMatrixMultiply(t_scale_, t_mbrot_), t_trans_); auto set_state_matrix_from_block = [&](ModelBlock& mblock) @@ -1167,16 +1168,16 @@ namespace core::Graphics // IA if (mblock.color_buffer) - context->IASetInputLayout(shared_->input_layout_vc.Get()); + context->IASetInputLayout(shared_->input_layout_vc.get()); else - context->IASetInputLayout(shared_->input_layout.Get()); + context->IASetInputLayout(shared_->input_layout.get()); // VS if (mblock.color_buffer) - context->VSSetShader(shared_->shader_vertex_vc.Get(), NULL, 0); + context->VSSetShader(shared_->shader_vertex_vc.get(), NULL, 0); else - context->VSSetShader(shared_->shader_vertex.Get(), NULL, 0); + context->VSSetShader(shared_->shader_vertex.get(), NULL, 0); // PS @@ -1185,16 +1186,16 @@ namespace core::Graphics if (mblock.image) { if (mblock.color_buffer) - context->PSSetShader(shared_->shader_pixel_vc[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_vc[IDX(fog)].get(), NULL, 0); else - context->PSSetShader(shared_->shader_pixel[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel[IDX(fog)].get(), NULL, 0); } else { if (mblock.color_buffer) - context->PSSetShader(shared_->shader_pixel_nt_vc[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_nt_vc[IDX(fog)].get(), NULL, 0); else - context->PSSetShader(shared_->shader_pixel_nt[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_nt[IDX(fog)].get(), NULL, 0); } } else @@ -1202,16 +1203,16 @@ namespace core::Graphics if (mblock.image) { if (mblock.color_buffer) - context->PSSetShader(shared_->shader_pixel_alpha_vc[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_alpha_vc[IDX(fog)].get(), NULL, 0); else - context->PSSetShader(shared_->shader_pixel_alpha[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_alpha[IDX(fog)].get(), NULL, 0); } else { if (mblock.color_buffer) - context->PSSetShader(shared_->shader_pixel_alpha_nt_vc[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_alpha_nt_vc[IDX(fog)].get(), NULL, 0); else - context->PSSetShader(shared_->shader_pixel_alpha_nt[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_alpha_nt[IDX(fog)].get(), NULL, 0); } } }; @@ -1225,7 +1226,7 @@ namespace core::Graphics DirectX::XMMATRIX const t_total_ = DirectX::XMMatrixMultiply(DirectX::XMLoadFloat4x4(&mblock.local_matrix), t_locwo_); DirectX::XMStoreFloat4x4(&v.v1, t_total_); DirectX::XMStoreFloat4x4(&v.v2, DirectX::XMMatrixInverseTranspose(t_total_)); - context->UpdateSubresource(shared_->cbo_mlw.Get(), 0, NULL, &v, 0, 0); + context->UpdateSubresource(shared_->cbo_mlw.get(), 0, NULL, &v, 0, 0); }; auto set_alpha_mode_opaque = [&](ModelBlock& mblock) { @@ -1235,17 +1236,17 @@ namespace core::Graphics mblock.base_color.x, mblock.base_color.y, mblock.base_color.z, mblock.base_color.w, 0.5f, 0.0f, 0.0f, 0.0f, }; - context->UpdateSubresource(shared_->cbo_alpha.Get(), 0, NULL, alpha, 0, 0); + context->UpdateSubresource(shared_->cbo_alpha.get(), 0, NULL, alpha, 0, 0); ID3D11Buffer* ps_cbo[2] = { // camera position and look to vector are setup by Renderer at register(b0) - shared_->cbo_alpha.Get(), - shared_->cbo_light.Get(), + shared_->cbo_alpha.get(), + shared_->cbo_light.get(), }; context->PSSetConstantBuffers(2, 2, ps_cbo); // OM FLOAT const blend_factor[4]{}; - context->OMSetBlendState(shared_->state_blend.Get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + context->OMSetBlendState(shared_->state_blend.get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); }; auto set_alpha_mode_mask = [&](ModelBlock& mblock) { @@ -1255,17 +1256,17 @@ namespace core::Graphics mblock.base_color.x, mblock.base_color.y, mblock.base_color.z, mblock.base_color.w, mblock.alpha, 0.0f, 0.0f, 0.0f, }; - context->UpdateSubresource(shared_->cbo_alpha.Get(), 0, NULL, alpha, 0, 0); + context->UpdateSubresource(shared_->cbo_alpha.get(), 0, NULL, alpha, 0, 0); ID3D11Buffer* ps_cbo[2] = { // camera position and look to vector are setup by Renderer at register(b0) - shared_->cbo_alpha.Get(), - shared_->cbo_light.Get(), + shared_->cbo_alpha.get(), + shared_->cbo_light.get(), }; context->PSSetConstantBuffers(2, 2, ps_cbo); // OM FLOAT const blend_factor[4]{}; - context->OMSetBlendState(shared_->state_blend.Get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + context->OMSetBlendState(shared_->state_blend.get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); }; auto set_alpha_mode_mask_custom = [&](ModelBlock& mblock, float const value) { @@ -1275,31 +1276,31 @@ namespace core::Graphics mblock.base_color.x, mblock.base_color.y, mblock.base_color.z, mblock.base_color.w, value, 0.0f, 0.0f, 0.0f, }; - context->UpdateSubresource(shared_->cbo_alpha.Get(), 0, NULL, alpha, 0, 0); + context->UpdateSubresource(shared_->cbo_alpha.get(), 0, NULL, alpha, 0, 0); ID3D11Buffer* ps_cbo[2] = { // camera position and look to vector are setup by Renderer at register(b0) - shared_->cbo_alpha.Get(), - shared_->cbo_light.Get(), + shared_->cbo_alpha.get(), + shared_->cbo_light.get(), }; context->PSSetConstantBuffers(2, 2, ps_cbo); if (mblock.image) { if (mblock.color_buffer) - context->PSSetShader(shared_->shader_pixel_alpha_vc[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_alpha_vc[IDX(fog)].get(), NULL, 0); else - context->PSSetShader(shared_->shader_pixel_alpha[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_alpha[IDX(fog)].get(), NULL, 0); } else { if (mblock.color_buffer) - context->PSSetShader(shared_->shader_pixel_alpha_nt_vc[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_alpha_nt_vc[IDX(fog)].get(), NULL, 0); else - context->PSSetShader(shared_->shader_pixel_alpha_nt[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_alpha_nt[IDX(fog)].get(), NULL, 0); } // OM FLOAT const blend_factor[4]{}; - context->OMSetBlendState(shared_->state_blend.Get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + context->OMSetBlendState(shared_->state_blend.get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); }; auto set_alpha_mode_blend = [&](ModelBlock& mblock) { @@ -1309,17 +1310,17 @@ namespace core::Graphics mblock.base_color.x, mblock.base_color.y, mblock.base_color.z, mblock.base_color.w, 0.5f, 0.0f, 0.0f, 0.0f, }; - context->UpdateSubresource(shared_->cbo_alpha.Get(), 0, NULL, alpha, 0, 0); + context->UpdateSubresource(shared_->cbo_alpha.get(), 0, NULL, alpha, 0, 0); ID3D11Buffer* ps_cbo[2] = { // camera position and look to vector are setup by Renderer at register(b0) - shared_->cbo_alpha.Get(), - shared_->cbo_light.Get(), + shared_->cbo_alpha.get(), + shared_->cbo_light.get(), }; context->PSSetConstantBuffers(2, 2, ps_cbo); // OM FLOAT const blend_factor[4]{}; - context->OMSetBlendState(shared_->state_blend_alpha.Get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + context->OMSetBlendState(shared_->state_blend_alpha.get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); }; auto set_alpha_mode_blend_overlay = [&](ModelBlock& mblock, float const exclude_value) { @@ -1329,32 +1330,32 @@ namespace core::Graphics mblock.base_color.x, mblock.base_color.y, mblock.base_color.z, mblock.base_color.w, exclude_value, 0.0f, 0.0f, 0.0f, }; - context->UpdateSubresource(shared_->cbo_alpha.Get(), 0, NULL, alpha, 0, 0); + context->UpdateSubresource(shared_->cbo_alpha.get(), 0, NULL, alpha, 0, 0); ID3D11Buffer* ps_cbo[2] = { // camera position and look to vector are setup by Renderer at register(b0) - shared_->cbo_alpha.Get(), - shared_->cbo_light.Get(), + shared_->cbo_alpha.get(), + shared_->cbo_light.get(), }; context->PSSetConstantBuffers(2, 2, ps_cbo); if (mblock.image) { if (mblock.color_buffer) - context->PSSetShader(shared_->shader_pixel_inv_alpha_vc[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_inv_alpha_vc[IDX(fog)].get(), NULL, 0); else - context->PSSetShader(shared_->shader_pixel_inv_alpha[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_inv_alpha[IDX(fog)].get(), NULL, 0); } else { if (mblock.color_buffer) - context->PSSetShader(shared_->shader_pixel_inv_alpha_nt_vc[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_inv_alpha_nt_vc[IDX(fog)].get(), NULL, 0); else - context->PSSetShader(shared_->shader_pixel_inv_alpha_nt[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_inv_alpha_nt[IDX(fog)].get(), NULL, 0); } // OM - context->OMSetDepthStencilState(shared_->state_ds.Get(), D3D11_DEFAULT_STENCIL_REFERENCE); + context->OMSetDepthStencilState(shared_->state_ds.get(), D3D11_DEFAULT_STENCIL_REFERENCE); FLOAT const blend_factor[4]{}; - context->OMSetBlendState(shared_->state_blend_alpha.Get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + context->OMSetBlendState(shared_->state_blend_alpha.get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); }; auto set_alpha_mode_screen_door = [&](ModelBlock& mblock) { @@ -1364,32 +1365,32 @@ namespace core::Graphics mblock.base_color.x, mblock.base_color.y, mblock.base_color.z, mblock.base_color.w, 0.5f, 0.0f, 0.0f, 0.0f, }; - context->UpdateSubresource(shared_->cbo_alpha.Get(), 0, NULL, alpha, 0, 0); + context->UpdateSubresource(shared_->cbo_alpha.get(), 0, NULL, alpha, 0, 0); ID3D11Buffer* ps_cbo[2] = { // camera position and look to vector are setup by Renderer at register(b0) - shared_->cbo_alpha.Get(), - shared_->cbo_light.Get(), + shared_->cbo_alpha.get(), + shared_->cbo_light.get(), }; context->PSSetConstantBuffers(2, 2, ps_cbo); if (mblock.image) { if (mblock.color_buffer) - context->PSSetShader(shared_->shader_pixel_sd_vc[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_sd_vc[IDX(fog)].get(), NULL, 0); else - context->PSSetShader(shared_->shader_pixel_sd[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_sd[IDX(fog)].get(), NULL, 0); } else { if (mblock.color_buffer) - context->PSSetShader(shared_->shader_pixel_sd_nt_vc[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_sd_nt_vc[IDX(fog)].get(), NULL, 0); else - context->PSSetShader(shared_->shader_pixel_sd_nt[IDX(fog)].Get(), NULL, 0); + context->PSSetShader(shared_->shader_pixel_sd_nt[IDX(fog)].get(), NULL, 0); } // OM - context->OMSetDepthStencilState(shared_->state_ds.Get(), D3D11_DEFAULT_STENCIL_REFERENCE); + context->OMSetDepthStencilState(shared_->state_ds.get(), D3D11_DEFAULT_STENCIL_REFERENCE); FLOAT const blend_factor[4]{}; - context->OMSetBlendState(shared_->state_blend.Get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + context->OMSetBlendState(shared_->state_blend.get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); }; auto set_state_from_block = [&](ModelBlock& mblock) { @@ -1398,18 +1399,18 @@ namespace core::Graphics // IA context->IASetPrimitiveTopology(mblock.primitive_topology); - ID3D11Buffer* vbo[4] = { mblock.vertex_buffer.Get(), mblock.normal_buffer.Get(), mblock.uv_buffer.Get(), mblock.color_buffer.Get() }; + ID3D11Buffer* vbo[4] = { mblock.vertex_buffer.get(), mblock.normal_buffer.get(), mblock.uv_buffer.get(), mblock.color_buffer.get() }; UINT stride[4] = { 3 * sizeof(float), 3 * sizeof(float), 2 * sizeof(float), 3 * sizeof(float) }; UINT offset[4] = { 0, 0, 0, 0 }; context->IASetVertexBuffers(0, 4, vbo, stride, offset); - context->IASetIndexBuffer(mblock.index_buffer.Get(), mblock.index_format, 0); + context->IASetIndexBuffer(mblock.index_buffer.get(), mblock.index_format, 0); // VS upload_local_world_matrix(mblock); ID3D11Buffer* vs_cbo[1] = { // view-projection matrix setup by Renderer at register(b0) - shared_->cbo_mlw.Get(), + shared_->cbo_mlw.get(), }; context->VSSetConstantBuffers(1, 1, vs_cbo); @@ -1417,23 +1418,23 @@ namespace core::Graphics if (mblock.double_side) { - context->RSSetState(shared_->state_rs_cull_none.Get()); + context->RSSetState(shared_->state_rs_cull_none.get()); } else { - context->RSSetState(shared_->state_rs_cull_back.Get()); + context->RSSetState(shared_->state_rs_cull_back.get()); } // PS - ID3D11SamplerState* ps_samp[1] = { mblock.sampler.Get() }; + ID3D11SamplerState* ps_samp[1] = { mblock.sampler.get() }; context->PSSetSamplers(0, 1, ps_samp); - ID3D11ShaderResourceView* ps_srv[1] = { mblock.image.Get() }; + ID3D11ShaderResourceView* ps_srv[1] = { mblock.image.get() }; context->PSSetShaderResources(0, 1, ps_srv); // OM - context->OMSetDepthStencilState(shared_->state_ds.Get(), D3D11_DEFAULT_STENCIL_REFERENCE); + context->OMSetDepthStencilState(shared_->state_ds.get(), D3D11_DEFAULT_STENCIL_REFERENCE); // other if (mblock.alpha_blend) { @@ -1517,7 +1518,7 @@ namespace core::Graphics clear_state(); } - Model_D3D11::Model_D3D11(Direct3D11::Device* p_device, ModelSharedComponent_D3D11* p_model_shared, StringView path) + Model_D3D11::Model_D3D11(GraphicsDevice* p_device, ModelSharedComponent_D3D11* p_model_shared, StringView path) : m_device(p_device) , shared_(p_model_shared) , gltf_path(path) diff --git a/engine/graphics/core/Graphics/Model_D3D11.hpp b/engine/graphics/core/Graphics/Model_D3D11.hpp new file mode 100644 index 00000000..dc4d7a8e --- /dev/null +++ b/engine/graphics/core/Graphics/Model_D3D11.hpp @@ -0,0 +1,190 @@ +#pragma once +#include "core/SmartReference.hpp" +#include "core/implement/ReferenceCounted.hpp" +#include "core/Graphics/Renderer.hpp" +#include "d3d11/GraphicsDevice.hpp" +#include "tiny_gltf.h" + +#define IDX(x) (size_t)static_cast(x) + +namespace core::Graphics +{ + class ModelSharedComponent_D3D11 + : public implement::ReferenceCounted + , public IGraphicsDeviceEventListener + { + friend class Model_D3D11; + private: + SmartReference m_device; + + win32::com_ptr default_image; + win32::com_ptr default_sampler; + + win32::com_ptr input_layout; + win32::com_ptr input_layout_vc; + win32::com_ptr shader_vertex; + win32::com_ptr shader_vertex_vc; + win32::com_ptr shader_pixel[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_alpha[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_inv_alpha[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_nt[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_alpha_nt[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_inv_alpha_nt[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_vc[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_alpha_vc[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_inv_alpha_vc[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_nt_vc[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_alpha_nt_vc[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_inv_alpha_nt_vc[IDX(IRenderer::FogState::MAX_COUNT)]; + + win32::com_ptr shader_pixel_sd[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_sd_nt[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_sd_vc[IDX(IRenderer::FogState::MAX_COUNT)]; + win32::com_ptr shader_pixel_sd_nt_vc[IDX(IRenderer::FogState::MAX_COUNT)]; + + win32::com_ptr state_rs_cull_none; + win32::com_ptr state_rs_cull_back; + win32::com_ptr state_ds_disable; + win32::com_ptr state_ds; + win32::com_ptr state_ds_no_write; + win32::com_ptr state_ds_dl; + win32::com_ptr state_blend; + win32::com_ptr state_blend_alpha; + + win32::com_ptr cbo_mvp; + win32::com_ptr cbo_mlw; + win32::com_ptr cbo_caminfo; + win32::com_ptr cbo_alpha; + win32::com_ptr cbo_light; + + private: + bool createImage(); + bool createSampler(); + bool createShader(); + bool createConstantBuffer(); + bool createState(); + + bool createResources(); + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; + + public: + ModelSharedComponent_D3D11(GraphicsDevice* p_device); + ~ModelSharedComponent_D3D11(); + }; + + class Model_D3D11 + : public implement::ReferenceCounted + , public IGraphicsDeviceEventListener + { + private: + SmartReference m_device; + SmartReference shared_; + + DirectX::XMMATRIX t_scale_; + DirectX::XMMATRIX t_trans_; + DirectX::XMMATRIX t_mbrot_; + + std::string gltf_path; + + struct ModelBlock + { + win32::com_ptr vertex_buffer; + win32::com_ptr uv_buffer; + win32::com_ptr normal_buffer; + win32::com_ptr color_buffer; + win32::com_ptr index_buffer; + win32::com_ptr sampler; + win32::com_ptr image; + DirectX::XMFLOAT4X4 local_matrix; + DirectX::XMFLOAT4X4 local_matrix_normal; // notice: pair with local_matrix + DirectX::XMFLOAT4 base_color; + BOOL double_side = FALSE; + BOOL alpha_blend = FALSE; + BOOL alpha_mask = FALSE; + FLOAT alpha = 0.5f; + UINT draw_count = 0; + DXGI_FORMAT index_format = DXGI_FORMAT_R16_UINT; + D3D11_PRIMITIVE_TOPOLOGY primitive_topology = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST; + ModelBlock() + { + DirectX::XMStoreFloat4x4(&local_matrix, DirectX::XMMatrixIdentity()); + DirectX::XMStoreFloat4x4(&local_matrix_normal, DirectX::XMMatrixIdentity()); + base_color = DirectX::XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); + } + }; + struct Sunshine + { + DirectX::XMFLOAT4 ambient; + DirectX::XMFLOAT4 pos; + DirectX::XMFLOAT4 dir; + DirectX::XMFLOAT4 color; + + void setDir(float dir_deg, float upd_deg) + { + DirectX::XMFLOAT3 slfrom(1.0f, 0.0f, 0.0f); + auto rotate_vec2 = [](float& x, float& y, float r) + { + float sin_v = std::sinf(r); + float cos_v = std::cosf(r); + float xx = x * cos_v - y * sin_v; + float yy = x * sin_v + y * cos_v; + x = xx; + y = yy; + }; + // up and down + rotate_vec2(slfrom.x, slfrom.y, DirectX::XMConvertToRadians(upd_deg)); + // direction + rotate_vec2(slfrom.x, slfrom.z, DirectX::XMConvertToRadians(dir_deg)); + // inverse + dir.x = -slfrom.x; + dir.y = -slfrom.y; + dir.z = -slfrom.z; + dir.w = 0.0f; + } + + Sunshine() + { + ambient = DirectX::XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f); // full ambient light + pos = DirectX::XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f); + dir = DirectX::XMFLOAT4(0.0f, -1.0f, 0.0f, 0.0f); + color = DirectX::XMFLOAT4(1.0f, 1.0f, 1.0f, 0.0f); // no directional light + } + }; + + std::vector> image; + std::vector> sampler; + + std::vector model_block; + + Sunshine sunshine; + + std::vector mTRS_stack; + + bool processNode(tinygltf::Model& model, tinygltf::Node& node); + bool createImage(tinygltf::Model& model); + bool createSampler(tinygltf::Model& model); + bool createModelBlock(tinygltf::Model& model); + + bool createResources(); + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; + + public: + + void setAmbient(Vector3F const& color, float brightness); + void setDirectionalLight(Vector3F const& direction, Vector3F const& color, float brightness); + void setScaling(Vector3F const& scale); + void setPosition(Vector3F const& pos); + void setRotationRollPitchYaw(float roll, float pitch, float yaw); + void setRotationQuaternion(Vector4F const& quat); + + void draw(IRenderer::FogState fog); + + public: + Model_D3D11(GraphicsDevice* p_device, ModelSharedComponent_D3D11* p_model_shared, StringView path); + ~Model_D3D11(); + }; +} + +#undef IDX diff --git a/LuaSTG/Core/Graphics/Model_Shader_D3D11.cpp b/engine/graphics/core/Graphics/Model_Shader_D3D11.cpp similarity index 91% rename from LuaSTG/Core/Graphics/Model_Shader_D3D11.cpp rename to engine/graphics/core/Graphics/Model_Shader_D3D11.cpp index 6d326748..d779fe33 100644 --- a/LuaSTG/Core/Graphics/Model_Shader_D3D11.cpp +++ b/engine/graphics/core/Graphics/Model_Shader_D3D11.cpp @@ -1,5 +1,6 @@ -#include "Core/Graphics/Model_D3D11.hpp" -#include "Platform/RuntimeLoader/Direct3DCompiler.hpp" +#include "core/Graphics/Model_D3D11.hpp" +#include "core/Logger.hpp" +#include "windows/RuntimeLoader/Direct3DCompiler.hpp" static std::string_view const built_in_shader(R"( // pipeline data flow @@ -464,35 +465,34 @@ namespace core::Graphics // built-in: compile shader - Microsoft::WRL::ComPtr vs; - Microsoft::WRL::ComPtr vs_vc; + win32::com_ptr vs; + win32::com_ptr vs_vc; auto fxc = [&](std::string_view const& name, D3D_SHADER_MACRO const* macro, std::string_view const& entry, int type, ID3DBlob** blob) -> bool { - Microsoft::WRL::ComPtr err; + win32::com_ptr err; UINT compile_flags = D3DCOMPILE_ENABLE_STRICTNESS; #ifdef _DEBUG compile_flags |= (D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION); #endif hr = gHR = g_d3dcompiler_loader.Compile( built_in_shader.data(), built_in_shader.size(), name.data(), - macro, NULL, entry.data(), type ? "ps_4_0" : "vs_4_0", compile_flags, 0, blob, &err); + macro, NULL, entry.data(), type ? "ps_4_0" : "vs_4_0", compile_flags, 0, blob, err.put()); if (FAILED(hr)) { - spdlog::error("[core] D3DCompile 调用失败"); - spdlog::error("[core] 编译着色器 '{}' 失败:{}", name, (char*)err->GetBufferPointer()); + Logger::error("[core] [Model] compile shader '{}' failed: {}", name, (char*)err->GetBufferPointer()); assert(false); return false; } return true; }; - if (!fxc("model-vs", NULL, "VS_Main", 0, &vs)) return false; - if (!fxc("model-vs-vertex-color", NULL, "VS_Main_VertexColor", 0, &vs_vc)) return false; + if (!fxc("model-vs", NULL, "VS_Main", 0, vs.put())) return false; + if (!fxc("model-vs-vertex-color", NULL, "VS_Main_VertexColor", 0, vs_vc.put())) return false; - hr = gHR = device->CreateVertexShader(vs->GetBufferPointer(), vs->GetBufferSize(), NULL, &shader_vertex); + hr = gHR = device->CreateVertexShader(vs->GetBufferPointer(), vs->GetBufferSize(), NULL, shader_vertex.put()); if (FAILED(hr)) return false; - hr = gHR = device->CreateVertexShader(vs_vc->GetBufferPointer(), vs_vc->GetBufferSize(), NULL, &shader_vertex_vc); + hr = gHR = device->CreateVertexShader(vs_vc->GetBufferPointer(), vs_vc->GetBufferSize(), NULL, shader_vertex_vc.put()); if (FAILED(hr)) return false; const D3D_SHADER_MACRO fog_none[] = { @@ -514,24 +514,24 @@ namespace core::Graphics { NULL, NULL }, }; - auto fxc_ps = [&](std::string_view const& name, std::string_view const& entry, Microsoft::WRL::ComPtr ps[IDX(IRenderer::FogState::MAX_COUNT)]) -> bool + auto fxc_ps = [&](std::string_view const& name, std::string_view const& entry, win32::com_ptr ps[IDX(IRenderer::FogState::MAX_COUNT)]) -> bool { - Microsoft::WRL::ComPtr ps_bc; + win32::com_ptr ps_bc; - if (!fxc(name, fog_none, entry, 1, &ps_bc)) return false; - hr = gHR = device->CreatePixelShader(ps_bc->GetBufferPointer(), ps_bc->GetBufferSize(), NULL, &ps[IDX(IRenderer::FogState::Disable)]); + if (!fxc(name, fog_none, entry, 1, ps_bc.put())) return false; + hr = gHR = device->CreatePixelShader(ps_bc->GetBufferPointer(), ps_bc->GetBufferSize(), NULL, ps[IDX(IRenderer::FogState::Disable)].put()); if (FAILED(hr)) return false; - if (!fxc(name, fog_line, entry, 1, &ps_bc)) return false; - hr = gHR = device->CreatePixelShader(ps_bc->GetBufferPointer(), ps_bc->GetBufferSize(), NULL, &ps[IDX(IRenderer::FogState::Linear)]); + if (!fxc(name, fog_line, entry, 1, ps_bc.put())) return false; + hr = gHR = device->CreatePixelShader(ps_bc->GetBufferPointer(), ps_bc->GetBufferSize(), NULL, ps[IDX(IRenderer::FogState::Linear)].put()); if (FAILED(hr)) return false; - if (!fxc(name, fog_exp1, entry, 1, &ps_bc)) return false; - hr = gHR = device->CreatePixelShader(ps_bc->GetBufferPointer(), ps_bc->GetBufferSize(), NULL, &ps[IDX(IRenderer::FogState::Exp)]); + if (!fxc(name, fog_exp1, entry, 1, ps_bc.put())) return false; + hr = gHR = device->CreatePixelShader(ps_bc->GetBufferPointer(), ps_bc->GetBufferSize(), NULL, ps[IDX(IRenderer::FogState::Exp)].put()); if (FAILED(hr)) return false; - if (!fxc(name, fog_exp2, entry, 1, &ps_bc)) return false; - hr = gHR = device->CreatePixelShader(ps_bc->GetBufferPointer(), ps_bc->GetBufferSize(), NULL, &ps[IDX(IRenderer::FogState::Exp2)]); + if (!fxc(name, fog_exp2, entry, 1, ps_bc.put())) return false; + hr = gHR = device->CreatePixelShader(ps_bc->GetBufferPointer(), ps_bc->GetBufferSize(), NULL, ps[IDX(IRenderer::FogState::Exp2)].put()); if (FAILED(hr)) return false; return true; @@ -564,7 +564,7 @@ namespace core::Graphics { "NORMAL" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 1, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT , 2, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; - hr = gHR = device->CreateInputLayout(ia_layout, 3, vs->GetBufferPointer(), vs->GetBufferSize(), &input_layout); + hr = gHR = device->CreateInputLayout(ia_layout, 3, vs->GetBufferPointer(), vs->GetBufferSize(), input_layout.put()); if (FAILED(hr)) { assert(false); @@ -577,7 +577,7 @@ namespace core::Graphics { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT , 2, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR" , 0, DXGI_FORMAT_R32G32B32_FLOAT, 3, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; - hr = gHR = device->CreateInputLayout(ia_layout_vc, 4, vs_vc->GetBufferPointer(), vs_vc->GetBufferSize(), &input_layout_vc); + hr = gHR = device->CreateInputLayout(ia_layout_vc, 4, vs_vc->GetBufferPointer(), vs_vc->GetBufferSize(), input_layout_vc.put()); if (FAILED(hr)) { assert(false); diff --git a/LuaSTG/Core/Graphics/Renderer.hpp b/engine/graphics/core/Graphics/Renderer.hpp similarity index 92% rename from LuaSTG/Core/Graphics/Renderer.hpp rename to engine/graphics/core/Graphics/Renderer.hpp index 891e68b3..06811311 100644 --- a/LuaSTG/Core/Graphics/Renderer.hpp +++ b/engine/graphics/core/Graphics/Renderer.hpp @@ -1,196 +1,192 @@ -#pragma once -#include "core/Vector2.hpp" -#include "core/Vector3.hpp" -#include "core/Vector4.hpp" -#include "core/Color.hpp" -#include "core/Box.hpp" -#include "core/ReferenceCounted.hpp" -#include "Core/Graphics/Device.hpp" - -namespace core::Graphics -{ - struct IRenderer; - - struct IPostEffectShader : public IReferenceCounted - { - virtual bool setFloat(StringView name, float value) = 0; - virtual bool setFloat2(StringView name, Vector2F value) = 0; - virtual bool setFloat3(StringView name, Vector3F value) = 0; - virtual bool setFloat4(StringView name, Vector4F value) = 0; - virtual bool setTexture2D(StringView name, ITexture2D* p_texture) = 0; - virtual bool apply(IRenderer* p_renderer) = 0; - }; - - struct IModel : public IReferenceCounted - { - virtual void setAmbient(Vector3F const& color, float brightness) = 0; - virtual void setDirectionalLight(Vector3F const& direction, Vector3F const& color, float brightness) = 0; - - virtual void setScaling(Vector3F const& scale) = 0; - virtual void setPosition(Vector3F const& pos) = 0; - virtual void setRotationRollPitchYaw(float roll, float pitch, float yaw) = 0; - virtual void setRotationQuaternion(Vector4F const& quat) = 0; - }; - - struct IRenderer : public IReferenceCounted - { - enum class VertexColorBlendState : uint8_t - { - MIN_INDEX = 0, - - Zero = MIN_INDEX, - One, - Add, - Mul, - - MAX_INDEX = Mul, - MAX_COUNT, - }; - enum class FogState : uint8_t - { - MIN_INDEX = 0, - - Disable = MIN_INDEX, - Linear, - Exp, - Exp2, - - MAX_INDEX = Exp2, - MAX_COUNT, - }; - enum class DepthState : uint8_t - { - MIN_INDEX = 0, - - Disable = MIN_INDEX, - Enable, - - MAX_INDEX = Enable, - MAX_COUNT, - }; - enum class BlendState : uint8_t - { - MIN_INDEX = 0, - - Disable = MIN_INDEX, - Alpha, - One, - Min, - Max, - Mul, - Screen, - Add, - Sub, - RevSub, - Inv, - - MAX_INDEX = Inv, - MAX_COUNT, - }; - enum class SamplerState : uint8_t - { - MIN_INDEX = 0, - - PointWrap = MIN_INDEX, - PointClamp, - PointBorderBlack, - PointBorderWhite, - LinearWrap, - LinearClamp, - LinearBorderBlack, - LinearBorderWhite, - - MAX_INDEX = LinearBorderWhite, - MAX_COUNT, - }; - enum class TextureAlphaType : uint8_t - { - MIN_INDEX = 0, - - Normal = MIN_INDEX, - PremulAlpha, - - MAX_INDEX = PremulAlpha, - MAX_COUNT, - }; - - struct DrawVertex - { - float x, y, z; - uint32_t color; - float u, v; - - DrawVertex() : x(0.0f), y(0.0f), z(0.0f), u(0.0f), v(0.0f), color(0u) {} - DrawVertex(float const x_, float const y_, float const z_, float const u_, float const v_, uint32_t const c_) - : x(x_), y(y_), z(z_), u(u_), v(v_), color(c_) {} - DrawVertex(float const x_, float const y_, float const z_, float const u_, float const v_) - : x(x_), y(y_), z(z_), u(u_), v(v_), color(0xFFFFFFFFu) {} - DrawVertex(float const x_, float const y_, float const u_, float const v_) - : x(x_), y(y_), z(0.5f), u(u_), v(v_), color(0xFFFFFFFFu) {} // TODO: z = 0.0f or z = 0.5f ? - }; - using DrawIndex = uint16_t; - - virtual bool beginBatch() = 0; - virtual bool endBatch() = 0; - virtual bool isBatchScope() = 0; - virtual bool flush() = 0; - - virtual void clearRenderTarget(Color4B const& color) = 0; - virtual void clearDepthBuffer(float zvalue) = 0; - virtual void setRenderAttachment(IRenderTarget* p_rt, IDepthStencilBuffer* p_ds) = 0; - - virtual void setOrtho(BoxF const& box) = 0; - virtual void setPerspective(Vector3F const& eye, Vector3F const& lookat, Vector3F const& headup, float fov, float aspect, float znear, float zfar) = 0; - - virtual BoxF getViewport() = 0; // 应该严格限制该方法的用途 - virtual void setViewport(BoxF const& box) = 0; - virtual void setScissorRect(RectF const& rect) = 0; - virtual void setViewportAndScissorRect() = 0; - - virtual void setVertexColorBlendState(VertexColorBlendState state) = 0; - virtual void setFogState(FogState state, Color4B const& color, float density_or_znear, float zfar) = 0; - virtual void setDepthState(DepthState state) = 0; - virtual void setBlendState(BlendState state) = 0; - virtual void setTexture(ITexture2D* texture) = 0; - - virtual bool drawTriangle(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3) = 0; - virtual bool drawTriangle(DrawVertex const* pvert) = 0; - virtual bool drawQuad(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3, DrawVertex const& v4) = 0; - virtual bool drawQuad(DrawVertex const* pvert) = 0; - virtual bool drawRaw(DrawVertex const* pvert, uint16_t nvert, DrawIndex const* pidx, uint16_t nidx) = 0; - virtual bool drawRequest(uint16_t nvert, uint16_t nidx, DrawVertex** ppvert, DrawIndex** ppidx, uint16_t* idxoffset) = 0; - - virtual bool createPostEffectShader(StringView path, IPostEffectShader** pp_effect) = 0; - virtual bool drawPostEffect( - IPostEffectShader* p_effect, - BlendState blend, - ITexture2D* p_tex, SamplerState rtsv, - Vector4F const* cv, size_t cv_n, - ITexture2D* const* p_tex_arr, SamplerState const* sv, size_t tv_sv_n) = 0; - virtual bool drawPostEffect(IPostEffectShader* p_effect, BlendState blend) = 0; - - virtual bool createModel(StringView path, IModel** pp_model) = 0; - virtual bool drawModel(IModel* p_model) = 0; - - virtual ISamplerState* getKnownSamplerState(SamplerState state) = 0; - - static bool create(IDevice* p_device, IRenderer** pp_renderer); - }; -} - -namespace core { - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IPostEffectShader - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("d9bbdce5-bb1a-50fe-af44-0149e7e3f1b4"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IModel - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("31d5322d-0165-56e4-bda6-914e131eccf9"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IRenderer - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("0ebdb9dc-847f-5827-bf0a-a902494b84bc"); } -} +#pragma once +#include "core/Vector2.hpp" +#include "core/Vector3.hpp" +#include "core/Vector4.hpp" +#include "core/Color.hpp" +#include "core/Box.hpp" +#include "core/ReferenceCounted.hpp" +#include "core/GraphicsDevice.hpp" + +namespace core::Graphics +{ + struct IRenderer; + + struct IPostEffectShader : public IReferenceCounted + { + virtual bool setFloat(StringView name, float value) = 0; + virtual bool setFloat2(StringView name, Vector2F value) = 0; + virtual bool setFloat3(StringView name, Vector3F value) = 0; + virtual bool setFloat4(StringView name, Vector4F value) = 0; + virtual bool setTexture2D(StringView name, ITexture2D* p_texture) = 0; + virtual bool apply(IRenderer* p_renderer) = 0; + }; + + struct IModel : public IReferenceCounted + { + virtual void setAmbient(Vector3F const& color, float brightness) = 0; + virtual void setDirectionalLight(Vector3F const& direction, Vector3F const& color, float brightness) = 0; + + virtual void setScaling(Vector3F const& scale) = 0; + virtual void setPosition(Vector3F const& pos) = 0; + virtual void setRotationRollPitchYaw(float roll, float pitch, float yaw) = 0; + virtual void setRotationQuaternion(Vector4F const& quat) = 0; + }; + + struct IRenderer : public IReferenceCounted + { + enum class VertexColorBlendState : uint8_t + { + MIN_INDEX = 0, + + Zero = MIN_INDEX, + One, + Add, + Mul, + + MAX_INDEX = Mul, + MAX_COUNT, + }; + enum class FogState : uint8_t + { + MIN_INDEX = 0, + + Disable = MIN_INDEX, + Linear, + Exp, + Exp2, + + MAX_INDEX = Exp2, + MAX_COUNT, + }; + enum class DepthState : uint8_t + { + MIN_INDEX = 0, + + Disable = MIN_INDEX, + Enable, + + MAX_INDEX = Enable, + MAX_COUNT, + }; + enum class BlendState : uint8_t + { + MIN_INDEX = 0, + + Disable = MIN_INDEX, + Alpha, + One, + Min, + Max, + Mul, + Screen, + Add, + Sub, + RevSub, + Inv, + + MAX_INDEX = Inv, + MAX_COUNT, + }; + enum class SamplerState : uint8_t + { + MIN_INDEX = 0, + + PointWrap = MIN_INDEX, + PointClamp, + LinearWrap, + LinearClamp, + + MAX_INDEX = LinearClamp, + MAX_COUNT, + }; + enum class TextureAlphaType : uint8_t + { + MIN_INDEX = 0, + + Normal = MIN_INDEX, + PremulAlpha, + + MAX_INDEX = PremulAlpha, + MAX_COUNT, + }; + + struct DrawVertex + { + float x, y, z; + uint32_t color; + float u, v; + + DrawVertex() : x(0.0f), y(0.0f), z(0.0f), u(0.0f), v(0.0f), color(0u) {} + DrawVertex(float const x_, float const y_, float const z_, float const u_, float const v_, uint32_t const c_) + : x(x_), y(y_), z(z_), u(u_), v(v_), color(c_) {} + DrawVertex(float const x_, float const y_, float const z_, float const u_, float const v_) + : x(x_), y(y_), z(z_), u(u_), v(v_), color(0xFFFFFFFFu) {} + DrawVertex(float const x_, float const y_, float const u_, float const v_) + : x(x_), y(y_), z(0.5f), u(u_), v(v_), color(0xFFFFFFFFu) {} // TODO: z = 0.0f or z = 0.5f ? + }; + using DrawIndex = uint16_t; + + virtual bool beginBatch() = 0; + virtual bool endBatch() = 0; + virtual bool isBatchScope() = 0; + virtual bool flush() = 0; + + virtual void clearRenderTarget(Color4B const& color) = 0; + virtual void clearDepthBuffer(float zvalue) = 0; + virtual void setRenderAttachment(IRenderTarget* p_rt, IDepthStencilBuffer* p_ds) = 0; + + virtual void setOrtho(BoxF const& box) = 0; + virtual void setPerspective(Vector3F const& eye, Vector3F const& lookat, Vector3F const& headup, float fov, float aspect, float znear, float zfar) = 0; + + virtual BoxF getViewport() = 0; // 应该严格限制该方法的用途 + virtual void setViewport(BoxF const& box) = 0; + virtual void setScissorRect(RectF const& rect) = 0; + virtual void setViewportAndScissorRect() = 0; + + virtual void setVertexColorBlendState(VertexColorBlendState state) = 0; + virtual void setFogState(FogState state, Color4B const& color, float density_or_znear, float zfar) = 0; + virtual void setDepthState(DepthState state) = 0; + virtual void setBlendState(BlendState state) = 0; + virtual void setTexture(ITexture2D* texture) = 0; + + virtual bool drawTriangle(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3) = 0; + virtual bool drawTriangle(DrawVertex const* pvert) = 0; + virtual bool drawQuad(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3, DrawVertex const& v4) = 0; + virtual bool drawQuad(DrawVertex const* pvert) = 0; + virtual bool drawRaw(DrawVertex const* pvert, uint16_t nvert, DrawIndex const* pidx, uint16_t nidx) = 0; + virtual bool drawRequest(uint16_t nvert, uint16_t nidx, DrawVertex** ppvert, DrawIndex** ppidx, uint16_t* idxoffset) = 0; + + virtual bool createPostEffectShader(StringView path, IPostEffectShader** pp_effect) = 0; + virtual bool drawPostEffect( + IPostEffectShader* p_effect, + BlendState blend, + ITexture2D* p_tex, SamplerState rtsv, + Vector4F const* cv, size_t cv_n, + ITexture2D* const* p_tex_arr, SamplerState const* sv, size_t tv_sv_n) = 0; + virtual bool drawPostEffect(IPostEffectShader* p_effect, BlendState blend) = 0; + + virtual bool createModel(StringView path, IModel** pp_model) = 0; + virtual bool drawModel(IModel* p_model) = 0; + + virtual IGraphicsSampler* getKnownSamplerState(SamplerState state) = 0; + + static bool create(IGraphicsDevice* p_device, IRenderer** pp_renderer); + }; +} + +namespace core { + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.IPostEffectShader + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("d9bbdce5-bb1a-50fe-af44-0149e7e3f1b4"); } + + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.IModel + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("31d5322d-0165-56e4-bda6-914e131eccf9"); } + + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.IRenderer + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("0ebdb9dc-847f-5827-bf0a-a902494b84bc"); } +} diff --git a/LuaSTG/Core/Graphics/Renderer_D3D11.cpp b/engine/graphics/core/Graphics/Renderer_D3D11.cpp similarity index 60% rename from LuaSTG/Core/Graphics/Renderer_D3D11.cpp rename to engine/graphics/core/Graphics/Renderer_D3D11.cpp index 4ba81d77..9830802e 100644 --- a/LuaSTG/Core/Graphics/Renderer_D3D11.cpp +++ b/engine/graphics/core/Graphics/Renderer_D3D11.cpp @@ -1,1732 +1,1537 @@ -#include "Core/Graphics/Renderer_D3D11.hpp" -#include "Core/Graphics/Model_D3D11.hpp" -#include "Core/Graphics/Direct3D11/Constants.hpp" -#include "Core/Graphics/Direct3D11/SamplerState.hpp" -#include "Core/Graphics/Direct3D11/RenderTarget.hpp" -#include "Core/Graphics/Direct3D11/DepthStencilBuffer.hpp" - -#define IDX(x) (size_t)static_cast(x) - -namespace core::Graphics -{ - inline ID3D11ShaderResourceView* get_view(Direct3D11::Texture2D* p) - { - return p ? p->GetView() : NULL; - } - inline ID3D11ShaderResourceView* get_view(ITexture2D* p) - { - return get_view(static_cast(p)); - } - inline ID3D11ShaderResourceView* get_view(SmartReference& p) - { - return get_view(p.get()); - } - inline ID3D11ShaderResourceView* get_view(SmartReference& p) - { - return get_view(static_cast(p.get())); - } - - inline ID3D11SamplerState* get_sampler(ISamplerState* p_sampler) - { - return static_cast(p_sampler)->GetState(); - } - inline ID3D11SamplerState* get_sampler(SmartReference& p_sampler) - { - return static_cast(p_sampler.get())->GetState(); - } -} - -namespace core::Graphics -{ - void PostEffectShader_D3D11::onDeviceCreate() - { - createResources(); - } - void PostEffectShader_D3D11::onDeviceDestroy() - { - d3d11_ps.Reset(); - for (auto& v : m_buffer_map) - { - v.second.d3d11_buffer.Reset(); - } - } - - bool PostEffectShader_D3D11::findVariable(StringView name, LocalConstantBuffer*& buf, LocalVariable*& val) - { - std::string name_s(name); - for (auto& b : m_buffer_map) - { - auto it = b.second.variable.find(name_s); - if (it != b.second.variable.end()) - { - buf = &b.second; - val = &it->second; - return true; - } - } - return false; - } - bool PostEffectShader_D3D11::setFloat(StringView name, float value) - { - LocalConstantBuffer* b{}; - LocalVariable* v{}; - if (!findVariable(name, b, v)) { return false; } - if (v->size != sizeof(value)) { assert(false); return false; } - memcpy(b->buffer.data() + v->offset, &value, v->size); - return true; - } - bool PostEffectShader_D3D11::setFloat2(StringView name, Vector2F value) - { - LocalConstantBuffer* b{}; - LocalVariable* v{}; - if (!findVariable(name, b, v)) { return false; } - if (v->size != sizeof(value)) { assert(false); return false; } - memcpy(b->buffer.data() + v->offset, &value, v->size); - return true; - } - bool PostEffectShader_D3D11::setFloat3(StringView name, Vector3F value) - { - LocalConstantBuffer* b{}; - LocalVariable* v{}; - if (!findVariable(name, b, v)) { return false; } - if (v->size != sizeof(value)) { assert(false); return false; } - memcpy(b->buffer.data() + v->offset, &value, v->size); - return true; - } - bool PostEffectShader_D3D11::setFloat4(StringView name, Vector4F value) - { - LocalConstantBuffer* b{}; - LocalVariable* v{}; - if (!findVariable(name, b, v)) { return false; } - if (v->size != sizeof(value)) { assert(false); return false; } - memcpy(b->buffer.data() + v->offset, &value, v->size); - return true; - } - bool PostEffectShader_D3D11::setTexture2D(StringView name, ITexture2D* p_texture) - { - std::string name_s(name); - auto it = m_texture2d_map.find(name_s); - if (it == m_texture2d_map.end()) { return false; } - it->second.texture = dynamic_cast(p_texture); - if (!it->second.texture) { assert(false); return false; } - return true; - } - bool PostEffectShader_D3D11::apply(IRenderer* p_renderer) - { - assert(p_renderer); - - auto* ctx = m_device->GetD3D11DeviceContext(); - if (!ctx) { assert(false); return false; } - - auto* p_sampler = p_renderer->getKnownSamplerState(IRenderer::SamplerState::LinearClamp); - - for (auto& v : m_buffer_map) - { - D3D11_MAPPED_SUBRESOURCE res{}; - HRESULT hr = gHR = ctx->Map(v.second.d3d11_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res); - if (FAILED(hr)) { assert(false); return false; } - memcpy(res.pData, v.second.buffer.data(), v.second.buffer.size()); - ctx->Unmap(v.second.d3d11_buffer.Get(), 0); - - ID3D11Buffer* b[1] = { v.second.d3d11_buffer.Get() }; - ctx->PSSetConstantBuffers(v.second.index, 1, b); - } - - for (auto& v : m_texture2d_map) - { - ID3D11ShaderResourceView* t[1] = { get_view(v.second.texture) }; - ctx->PSSetShaderResources(v.second.index, 1, t); - auto* p_custom = v.second.texture->getSamplerState(); - ID3D11SamplerState* s[1] = { p_custom ? get_sampler(p_custom) : get_sampler(p_sampler) }; - ctx->PSSetSamplers(v.second.index, 1, s); - } - - return true; - } - - PostEffectShader_D3D11::PostEffectShader_D3D11(Direct3D11::Device* p_device, StringView path, bool is_path_) - : m_device(p_device) - , source(path) - , is_path(is_path_) - { - if (!createResources()) - throw std::runtime_error("PostEffectShader_D3D11::PostEffectShader_D3D11"); - m_device->addEventListener(this); - } - PostEffectShader_D3D11::~PostEffectShader_D3D11() - { - m_device->removeEventListener(this); - } -} - -namespace core::Graphics -{ - void Renderer_D3D11::setVertexIndexBuffer(size_t index) - { - assert(m_device->GetD3D11DeviceContext()); - - auto& vi = _vi_buffer[(index == 0xFFFFFFFFu) ? _vi_buffer_index : index]; - ID3D11Buffer* vbo[1] = { vi.vertex_buffer.Get() }; - UINT stride[1] = { sizeof(IRenderer::DrawVertex) }; - UINT offset[1] = { 0 }; - m_device->GetD3D11DeviceContext()->IASetVertexBuffers(0, 1, vbo, stride, offset); - - constexpr DXGI_FORMAT format = sizeof(DrawIndex) < 4 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; - m_device->GetD3D11DeviceContext()->IASetIndexBuffer(vi.index_buffer.Get(), format, 0); - } - bool Renderer_D3D11::uploadVertexIndexBuffer(bool discard) - { - assert(m_device->GetD3D11DeviceContext()); - tracy_zone_scoped; - tracy_d3d11_context_zone(m_device->GetTracyContext(), "UploadVertexIndexBuffer"); - HRESULT hr = 0; - auto& vi_ = _vi_buffer[_vi_buffer_index]; - const D3D11_MAP map_type_ = discard ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE; - // copy vertex data - if (_draw_list.vertex.size > 0) - { - D3D11_MAPPED_SUBRESOURCE res_ = {}; - hr = gHR = m_device->GetD3D11DeviceContext()->Map(vi_.vertex_buffer.Get(), 0, map_type_, 0, &res_); - if (FAILED(hr)) - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #vertex_buffer[{}] 调用失败,无法上传顶点", _vi_buffer_index); - return false; - } - std::memcpy((DrawVertex*)res_.pData + vi_.vertex_offset, _draw_list.vertex.data, _draw_list.vertex.size * sizeof(DrawVertex)); - m_device->GetD3D11DeviceContext()->Unmap(vi_.vertex_buffer.Get(), 0); - } - // copy index data - if (_draw_list.index.size > 0) - { - D3D11_MAPPED_SUBRESOURCE res_ = {}; - hr = gHR = m_device->GetD3D11DeviceContext()->Map(vi_.index_buffer.Get(), 0, map_type_, 0, &res_); - if (FAILED(hr)) - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #index_buffer[{}] 调用失败,无法上传顶点索引", _vi_buffer_index); - return false; - } - std::memcpy((DrawIndex*)res_.pData + vi_.index_offset, _draw_list.index.data, _draw_list.index.size * sizeof(DrawIndex)); - m_device->GetD3D11DeviceContext()->Unmap(vi_.index_buffer.Get(), 0); - } - return true; - } - void Renderer_D3D11::clearDrawList() - { - for (size_t j_ = 0; j_ < _draw_list.command.size; j_ += 1) - { - _draw_list.command.data[j_].texture.reset(); - } - _draw_list.vertex.size = 0; - _draw_list.index.size = 0; - _draw_list.command.size = 0; - } - - bool Renderer_D3D11::createBuffers() - { - assert(m_device->GetD3D11Device()); - - HRESULT hr = 0; - - { - { - D3D11_BUFFER_DESC desc_ = { - .ByteWidth = 4 * sizeof(DrawVertex), - .Usage = D3D11_USAGE_DYNAMIC, - .BindFlags = D3D11_BIND_VERTEX_BUFFER, - .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE, - .MiscFlags = 0, - .StructureByteStride = 0, - }; - hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, NULL, &_fx_vbuffer); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_fx_vbuffer.Get()); - } - { - DrawIndex const idx_[6] = { 0, 1, 2, 0, 2, 3 }; - D3D11_BUFFER_DESC desc_ = { - .ByteWidth = 6 * sizeof(DrawIndex), - .Usage = D3D11_USAGE_DEFAULT, - .BindFlags = D3D11_BIND_INDEX_BUFFER, - .CPUAccessFlags = 0, - .MiscFlags = 0, - .StructureByteStride = 0, - }; - D3D11_SUBRESOURCE_DATA data_ = { - .pSysMem = &idx_, - .SysMemPitch = desc_.ByteWidth, - .SysMemSlicePitch = desc_.ByteWidth, - }; - hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, &data_, &_fx_ibuffer); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_fx_ibuffer.Get()); - } - } - - for (auto& vi_ : _vi_buffer) - { - { - D3D11_BUFFER_DESC desc_ = { - .ByteWidth = sizeof(_draw_list.vertex.data), - .Usage = D3D11_USAGE_DYNAMIC, - .BindFlags = D3D11_BIND_VERTEX_BUFFER, - .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE, - .MiscFlags = 0, - .StructureByteStride = 0, - }; - hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, NULL, &vi_.vertex_buffer); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(vi_.vertex_buffer.Get()); - } - - { - D3D11_BUFFER_DESC desc_ = { - .ByteWidth = sizeof(_draw_list.index.data), - .Usage = D3D11_USAGE_DYNAMIC, - .BindFlags = D3D11_BIND_INDEX_BUFFER, - .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE, - .MiscFlags = 0, - .StructureByteStride = 0, - }; - hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, NULL, &vi_.index_buffer); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(vi_.index_buffer.Get()); - } - } - - { - D3D11_BUFFER_DESC desc_ = { - .ByteWidth = sizeof(DirectX::XMFLOAT4X4), - .Usage = D3D11_USAGE_DYNAMIC, - .BindFlags = D3D11_BIND_CONSTANT_BUFFER, - .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE, - .MiscFlags = 0, - .StructureByteStride = 0, - }; - hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, NULL, &_vp_matrix_buffer); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_vp_matrix_buffer.Get()); - - hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, NULL, &_world_matrix_buffer); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_world_matrix_buffer.Get()); - - desc_.ByteWidth = 2 * sizeof(DirectX::XMFLOAT4); - hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, NULL, &_camera_pos_buffer); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_camera_pos_buffer.Get()); - - desc_.ByteWidth = 2 * sizeof(DirectX::XMFLOAT4); - hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, NULL, &_fog_data_buffer); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_fog_data_buffer.Get()); - - desc_.ByteWidth = 8 * sizeof(DirectX::XMFLOAT4); // 用户最多可用 8 个 float4 - hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, NULL, &_user_float_buffer); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_user_float_buffer.Get()); - } - - return true; - } - bool Renderer_D3D11::createStates() - { - assert(m_device->GetD3D11Device()); - - HRESULT hr = 0; - - { - D3D11_RASTERIZER_DESC desc_ = { - .FillMode = D3D11_FILL_SOLID, - .CullMode = D3D11_CULL_NONE, // 2D 图片精灵可能有负缩放 - .FrontCounterClockwise = FALSE, - .DepthBias = D3D11_DEFAULT_DEPTH_BIAS, - .DepthBiasClamp = D3D11_DEFAULT_DEPTH_BIAS_CLAMP, - .SlopeScaledDepthBias = D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS, - .DepthClipEnable = TRUE, - .ScissorEnable = TRUE, - .MultisampleEnable = FALSE, - .AntialiasedLineEnable = FALSE, - }; - hr = gHR = m_device->GetD3D11Device()->CreateRasterizerState(&desc_, &_raster_state); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_raster_state.Get()); - } - - { - Graphics::SamplerState sampler_state; - - // point - - sampler_state.filer = Filter::Point; - sampler_state.address_u = TextureAddressMode::Wrap; - sampler_state.address_v = TextureAddressMode::Wrap; - sampler_state.address_w = TextureAddressMode::Wrap; - if (!m_device->createSamplerState(sampler_state, _sampler_state[IDX(SamplerState::PointWrap)].put())) - return false; - - sampler_state.filer = Filter::Point; - sampler_state.address_u = TextureAddressMode::Clamp; - sampler_state.address_v = TextureAddressMode::Clamp; - sampler_state.address_w = TextureAddressMode::Clamp; - if (!m_device->createSamplerState(sampler_state, _sampler_state[IDX(SamplerState::PointClamp)].put())) - return false; - - sampler_state.filer = Filter::Point; - sampler_state.address_u = TextureAddressMode::Border; - sampler_state.address_v = TextureAddressMode::Border; - sampler_state.address_w = TextureAddressMode::Border; - sampler_state.border_color = BorderColor::Black; - if (!m_device->createSamplerState(sampler_state, _sampler_state[IDX(SamplerState::PointBorderBlack)].put())) - return false; - - sampler_state.filer = Filter::Point; - sampler_state.address_u = TextureAddressMode::Border; - sampler_state.address_v = TextureAddressMode::Border; - sampler_state.address_w = TextureAddressMode::Border; - sampler_state.border_color = BorderColor::White; - if (!m_device->createSamplerState(sampler_state, _sampler_state[IDX(SamplerState::PointBorderWhite)].put())) - return false; - - // linear - - sampler_state.filer = Filter::Linear; - sampler_state.address_u = TextureAddressMode::Wrap; - sampler_state.address_v = TextureAddressMode::Wrap; - sampler_state.address_w = TextureAddressMode::Wrap; - if (!m_device->createSamplerState(sampler_state, _sampler_state[IDX(SamplerState::LinearWrap)].put())) - return false; - - sampler_state.filer = Filter::Linear; - sampler_state.address_u = TextureAddressMode::Clamp; - sampler_state.address_v = TextureAddressMode::Clamp; - sampler_state.address_w = TextureAddressMode::Clamp; - if (!m_device->createSamplerState(sampler_state, _sampler_state[IDX(SamplerState::LinearClamp)].put())) - return false; - - sampler_state.filer = Filter::Linear; - sampler_state.address_u = TextureAddressMode::Border; - sampler_state.address_v = TextureAddressMode::Border; - sampler_state.address_w = TextureAddressMode::Border; - sampler_state.border_color = BorderColor::Black; - if (!m_device->createSamplerState(sampler_state, _sampler_state[IDX(SamplerState::LinearBorderBlack)].put())) - return false; - - sampler_state.filer = Filter::Linear; - sampler_state.address_u = TextureAddressMode::Border; - sampler_state.address_v = TextureAddressMode::Border; - sampler_state.address_w = TextureAddressMode::Border; - sampler_state.border_color = BorderColor::White; - if (!m_device->createSamplerState(sampler_state, _sampler_state[IDX(SamplerState::LinearBorderWhite)].put())) - return false; - } - - { - D3D11_DEPTH_STENCIL_DESC desc_ = { - .DepthEnable = FALSE, - .DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL, - .DepthFunc = D3D11_COMPARISON_LESS_EQUAL, - .StencilEnable = FALSE, - .StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK, - .StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK, - .FrontFace = D3D11_DEPTH_STENCILOP_DESC{ - .StencilFailOp = D3D11_STENCIL_OP_KEEP, - .StencilDepthFailOp = D3D11_STENCIL_OP_KEEP, - .StencilPassOp = D3D11_STENCIL_OP_KEEP, - .StencilFunc = D3D11_COMPARISON_ALWAYS, - }, - .BackFace = D3D11_DEPTH_STENCILOP_DESC{ - .StencilFailOp = D3D11_STENCIL_OP_KEEP, - .StencilDepthFailOp = D3D11_STENCIL_OP_KEEP, - .StencilPassOp = D3D11_STENCIL_OP_KEEP, - .StencilFunc = D3D11_COMPARISON_ALWAYS, - }, - }; - hr = gHR = m_device->GetD3D11Device()->CreateDepthStencilState(&desc_, &_depth_state[IDX(DepthState::Disable)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_depth_state[IDX(DepthState::Disable)].Get()); - - desc_.DepthEnable = TRUE; - hr = gHR = m_device->GetD3D11Device()->CreateDepthStencilState(&desc_, &_depth_state[IDX(DepthState::Enable)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_depth_state[IDX(DepthState::Enable)].Get()); - } - - { - D3D11_BLEND_DESC desc_ = { - .AlphaToCoverageEnable = FALSE, - .IndependentBlendEnable = FALSE, - .RenderTarget = {}, - }; - D3D11_RENDER_TARGET_BLEND_DESC blendt_ = { - .BlendEnable = FALSE, - .SrcBlend = D3D11_BLEND_ZERO, - .DestBlend = D3D11_BLEND_ONE, - .BlendOp = D3D11_BLEND_OP_ADD, - .SrcBlendAlpha = D3D11_BLEND_ZERO, - .DestBlendAlpha = D3D11_BLEND_ONE, - .BlendOpAlpha = D3D11_BLEND_OP_ADD, - .RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL, - }; - auto copy_ = [&]() -> void - { - for (auto& v : desc_.RenderTarget) - { - v = blendt_; - } - }; - copy_(); - - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::Disable)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Disable)].Get()); - - blendt_.BlendEnable = TRUE; - - blendt_.BlendOp = D3D11_BLEND_OP_ADD; - blendt_.SrcBlend = D3D11_BLEND_ONE; - blendt_.DestBlend = D3D11_BLEND_INV_SRC_ALPHA; - blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; - blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; - blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - copy_(); - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::Alpha)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Alpha)].Get()); - - blendt_.BlendOp = D3D11_BLEND_OP_ADD; - blendt_.SrcBlend = D3D11_BLEND_ONE; - blendt_.DestBlend = D3D11_BLEND_ZERO; - blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; - blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; - blendt_.DestBlendAlpha = D3D11_BLEND_ZERO; - copy_(); - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::One)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::One)].Get()); - - blendt_.BlendOp = D3D11_BLEND_OP_MIN; - blendt_.SrcBlend = D3D11_BLEND_ONE; - blendt_.DestBlend = D3D11_BLEND_ONE; - blendt_.BlendOpAlpha = D3D11_BLEND_OP_MIN; - blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; - blendt_.DestBlendAlpha = D3D11_BLEND_ONE; - copy_(); - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::Min)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Min)].Get()); - - blendt_.BlendOp = D3D11_BLEND_OP_MAX; - blendt_.SrcBlend = D3D11_BLEND_ONE; - blendt_.DestBlend = D3D11_BLEND_ONE; - blendt_.BlendOpAlpha = D3D11_BLEND_OP_MAX; - blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; - blendt_.DestBlendAlpha = D3D11_BLEND_ONE; - copy_(); - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::Max)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Max)].Get()); - - blendt_.BlendOp = D3D11_BLEND_OP_ADD; - blendt_.SrcBlend = D3D11_BLEND_DEST_COLOR; - blendt_.DestBlend = D3D11_BLEND_ZERO; - blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; - blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; - blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - copy_(); - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::Mul)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Mul)].Get()); - - blendt_.BlendOp = D3D11_BLEND_OP_ADD; - blendt_.SrcBlend = D3D11_BLEND_ONE; - blendt_.DestBlend = D3D11_BLEND_INV_SRC_COLOR; - blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; - blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; - blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - copy_(); - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::Screen)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Screen)].Get()); - - blendt_.BlendOp = D3D11_BLEND_OP_ADD; - blendt_.SrcBlend = D3D11_BLEND_ONE; - blendt_.DestBlend = D3D11_BLEND_ONE; - blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; - blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; - blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - copy_(); - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::Add)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Add)].Get()); - - blendt_.BlendOp = D3D11_BLEND_OP_SUBTRACT; - blendt_.SrcBlend = D3D11_BLEND_ONE; - blendt_.DestBlend = D3D11_BLEND_ONE; - blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; - blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; - blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - copy_(); - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::Sub)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Sub)].Get()); - - blendt_.BlendOp = D3D11_BLEND_OP_REV_SUBTRACT; - blendt_.SrcBlend = D3D11_BLEND_ONE; - blendt_.DestBlend = D3D11_BLEND_ONE; - blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; - blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; - blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; - copy_(); - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::RevSub)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::RevSub)].Get()); - - blendt_.BlendOp = D3D11_BLEND_OP_ADD; - blendt_.SrcBlend = D3D11_BLEND_INV_DEST_COLOR; - blendt_.DestBlend = D3D11_BLEND_INV_SRC_COLOR; - blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; - blendt_.SrcBlendAlpha = D3D11_BLEND_ZERO; - blendt_.DestBlendAlpha = D3D11_BLEND_ONE; - copy_(); - hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, &_blend_state[IDX(BlendState::Inv)]); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Inv)].Get()); - } - - return true; - } - void Renderer_D3D11::initState() - { - _state_dirty = true; - - if (!_camera_state_set.is_3D) - { - setOrtho(_camera_state_set.ortho); - } - else - { - setPerspective(_camera_state_set.eye, _camera_state_set.lookat, _camera_state_set.headup, _camera_state_set.fov, _camera_state_set.aspect, _camera_state_set.znear, _camera_state_set.zfar); - } - - setViewport(_state_set.viewport); - setScissorRect(_state_set.scissor_rect); - - setVertexColorBlendState(_state_set.vertex_color_blend_state); - setSamplerState(_state_set.sampler_state, 0); - setFogState(_state_set.fog_state, _state_set.fog_color, _state_set.fog_near_or_density, _state_set.fog_far); - setDepthState(_state_set.depth_state); - setBlendState(_state_set.blend_state); - setTexture(_state_texture.get()); - bindTextureAlphaType(_state_texture.get()); - - _state_dirty = false; - } - void Renderer_D3D11::setSamplerState(SamplerState state, UINT index) - { - ID3D11SamplerState* d3d11_sampler = static_cast(_sampler_state[IDX(state)].get())->GetState(); - m_device->GetD3D11DeviceContext()->PSSetSamplers(index, 1, &d3d11_sampler); - } - bool Renderer_D3D11::uploadVertexIndexBufferFromDrawList() - { - // upload data - if ((_draw_list.vertex.capacity - _vi_buffer[_vi_buffer_index].vertex_offset) < _draw_list.vertex.size - || (_draw_list.index.capacity - _vi_buffer[_vi_buffer_index].index_offset) < _draw_list.index.size) - { - // next buffer - _vi_buffer_index = (_vi_buffer_index + 1) % _vi_buffer_count; - _vi_buffer[_vi_buffer_index].vertex_offset = 0; - _vi_buffer[_vi_buffer_index].index_offset = 0; - // discard and copy - if (!uploadVertexIndexBuffer(true)) - { - clearDrawList(); - return false; - } - // bind buffer - if (_vi_buffer_count > 1) - { - setVertexIndexBuffer(); // need to switch v/i buffers - } - } - else - { - // copy no overwrite - if (!uploadVertexIndexBuffer(false)) - { - clearDrawList(); - return false; - } - } - return true; - } - void Renderer_D3D11::bindTextureSamplerState(ITexture2D* texture) - { - ISamplerState* sampler_from_texture = texture ? texture->getSamplerState() : nullptr; - ISamplerState* sampler = sampler_from_texture ? sampler_from_texture : _sampler_state[IDX(_state_set.sampler_state)].get(); - ID3D11SamplerState* d3d11_sampler = static_cast(sampler)->GetState(); - m_device->GetD3D11DeviceContext()->PSSetSamplers(0, 1, &d3d11_sampler); - } - void Renderer_D3D11::bindTextureAlphaType(ITexture2D* texture) - { - TextureAlphaType const state = (texture ? texture->isPremultipliedAlpha() : false) ? TextureAlphaType::PremulAlpha : TextureAlphaType::Normal; - if (_state_dirty || _state_set.texture_alpha_type != state) - { - _state_set.texture_alpha_type = state; - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - ctx->PSSetShader(_pixel_shader[IDX(_state_set.vertex_color_blend_state)][IDX(_state_set.fog_state)][IDX(state)].Get(), NULL, 0); - } - } - bool Renderer_D3D11::batchFlush(bool discard) - { - tracy_zone_scoped; - if (!discard) - { - tracy_d3d11_context_zone(m_device->GetTracyContext(), "BatchFlush"); - // upload data - if (!uploadVertexIndexBufferFromDrawList()) return false; - // draw - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - if (_draw_list.command.size > 0) - { - VertexIndexBuffer& vi_ = _vi_buffer[_vi_buffer_index]; - for (size_t j_ = 0; j_ < _draw_list.command.size; j_ += 1) - { - DrawCommand& cmd_ = _draw_list.command.data[j_]; - if (cmd_.vertex_count > 0 && cmd_.index_count > 0) - { - ID3D11ShaderResourceView* srv[1] = { get_view(cmd_.texture) }; - ctx->PSSetShaderResources(0, 1, srv); - bindTextureSamplerState(cmd_.texture.get()); - bindTextureAlphaType(cmd_.texture.get()); - ctx->DrawIndexed(cmd_.index_count, vi_.index_offset, vi_.vertex_offset); - } - vi_.vertex_offset += cmd_.vertex_count; - vi_.index_offset += cmd_.index_count; - } - } - // unbound: solve some debug warning - ID3D11ShaderResourceView* null_srv[1] = { NULL }; - ctx->PSSetShaderResources(0, 1, null_srv); - } - // clear - clearDrawList(); - setTexture(_state_texture.get()); - return true; - } - - bool Renderer_D3D11::createResources() - { - assert(m_device->GetD3D11Device()); - - spdlog::info("[core] 开始创建渲染器"); - - if (!createBuffers()) - { - spdlog::error("[core] 无法创建渲染器所需的顶点、索引缓冲区和着色器常量缓冲区"); - return false; - } - if (!createStates()) - { - spdlog::error("[core] 无法创建渲染器所需的渲染状态"); - return false; - } - if (!createShaders()) - { - spdlog::error("[core] 无法创建渲染器所需的内置着色器"); - return false; - } - - spdlog::info("[core] 已创建渲染器"); - - return true; - } - void Renderer_D3D11::onDeviceCreate() - { - createResources(); - } - void Renderer_D3D11::onDeviceDestroy() - { - batchFlush(true); - - _state_texture.reset(); - - _fx_vbuffer.Reset(); - _fx_ibuffer.Reset(); - for (auto& v : _vi_buffer) - { - v.vertex_buffer.Reset(); - v.index_buffer.Reset(); - v.vertex_offset = 0; - v.index_offset = 0; - } - _vi_buffer_index = 0; - - _vp_matrix_buffer.Reset(); - _world_matrix_buffer.Reset(); - _camera_pos_buffer.Reset(); - _fog_data_buffer.Reset(); - _user_float_buffer.Reset(); - - _input_layout.Reset(); - for (auto& v : _vertex_shader) - { - v.Reset(); - } - for (auto& i : _pixel_shader) - { - for (auto& j : i) - { - for (auto& v : j) - { - v.Reset(); - } - } - } - _raster_state.Reset(); - for (auto& v : _sampler_state) - { - v.reset(); - } - for (auto& v : _depth_state) - { - v.Reset(); - } - for (auto& v : _blend_state) - { - v.Reset(); - } - - spdlog::info("[core] 已关闭渲染器"); - } - - bool Renderer_D3D11::beginBatch() - { - auto const ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - - // [IA Stage] - - ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - ctx->IASetInputLayout(_input_layout.Get()); - setVertexIndexBuffer(); - - // [VS State] - - ID3D11Buffer* const view_projection_matrix = _vp_matrix_buffer.Get(); - ctx->VSSetConstantBuffers(Direct3D11::Constants::vertex_shader_stage_constant_buffer_slot_view_projection_matrix, 1, &view_projection_matrix); - ID3D11Buffer* const world_matrix = _world_matrix_buffer.Get(); - ctx->VSSetConstantBuffers(Direct3D11::Constants::vertex_shader_stage_constant_buffer_slot_world_matrix, 1, &world_matrix); - - // [RS Stage] - - ctx->RSSetState(_raster_state.Get()); - - // [PS State] - - ID3D11Buffer* const camera_position = _camera_pos_buffer.Get(); - ctx->PSSetConstantBuffers(Direct3D11::Constants::pixel_shader_stage_constant_buffer_slot_camera_position, 1, &camera_position); - ID3D11Buffer* const fog_parameter = _fog_data_buffer.Get(); - ctx->PSSetConstantBuffers(Direct3D11::Constants::pixel_shader_stage_constant_buffer_slot_fog_parameter, 1, &fog_parameter); - - // [OM Stage] - - // [Internal State] - - initState(); - - _batch_scope = true; - return true; - } - bool Renderer_D3D11::endBatch() - { - _batch_scope = false; - if (!batchFlush()) - return false; - _state_texture.reset(); - return true; - } - bool Renderer_D3D11::flush() - { - return batchFlush(); - } - - void Renderer_D3D11::clearRenderTarget(Color4B const& color) - { - batchFlush(); - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - ID3D11RenderTargetView* rtv = NULL; - ctx->OMGetRenderTargets(1, &rtv, NULL); - if (rtv) - { - FLOAT const clear_color[4] = { - (float)color.r / 255.0f, - (float)color.g / 255.0f, - (float)color.b / 255.0f, - (float)color.a / 255.0f, - }; - ctx->ClearRenderTargetView(rtv, clear_color); - rtv->Release(); - } - } - void Renderer_D3D11::clearDepthBuffer(float zvalue) - { - batchFlush(); - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - ID3D11DepthStencilView* dsv = NULL; - ctx->OMGetRenderTargets(1, NULL, &dsv); - if (dsv) - { - ctx->ClearDepthStencilView(dsv, D3D11_CLEAR_DEPTH, zvalue, D3D11_DEFAULT_STENCIL_REFERENCE); - dsv->Release(); - } - } - void Renderer_D3D11::setRenderAttachment(IRenderTarget* p_rt, IDepthStencilBuffer* p_ds) - { - batchFlush(); - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - ID3D11RenderTargetView* rtv[1] = { p_rt ? static_cast(p_rt)->GetView() : nullptr }; - ID3D11DepthStencilView* dsv = p_ds ? static_cast(p_ds)->GetView() : nullptr; - ctx->OMSetRenderTargets(1, rtv, dsv); - } - - void Renderer_D3D11::setOrtho(BoxF const& box) - { - if (_state_dirty || !_camera_state_set.isEqual(box)) - { - batchFlush(); - _camera_state_set.ortho = box; - _camera_state_set.is_3D = false; - DirectX::XMFLOAT4X4 f4x4; - DirectX::XMStoreFloat4x4(&f4x4, DirectX::XMMatrixOrthographicOffCenterLH(box.a.x, box.b.x, box.b.y, box.a.y, box.a.z, box.b.z)); - /* upload vp matrix */ { - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - D3D11_MAPPED_SUBRESOURCE res_ = {}; - HRESULT hr = gHR = ctx->Map(_vp_matrix_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res_); - if (SUCCEEDED(hr)) - { - std::memcpy(res_.pData, &f4x4, sizeof(f4x4)); - ctx->Unmap(_vp_matrix_buffer.Get(), 0); - } - else - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #view_projection_matrix_buffer 调用失败,无法上传摄像机变换矩阵"); - } - } - } - } - void Renderer_D3D11::setPerspective(Vector3F const& eye, Vector3F const& lookat, Vector3F const& headup, float fov, float aspect, float znear, float zfar) - { - if (_state_dirty || !_camera_state_set.isEqual(eye, lookat, headup, fov, aspect, znear, zfar)) - { - batchFlush(); - _camera_state_set.eye = eye; - _camera_state_set.lookat = lookat; - _camera_state_set.headup = headup; - _camera_state_set.fov = fov; - _camera_state_set.aspect = aspect; - _camera_state_set.znear = znear; - _camera_state_set.zfar = zfar; - _camera_state_set.is_3D = true; - DirectX::XMFLOAT3 const eyef3(eye.x, eye.y, eye.z); - DirectX::XMFLOAT3 const lookatf3(lookat.x, lookat.y, lookat.z); - DirectX::XMFLOAT3 const headupf3(headup.x, headup.y, headup.z); - DirectX::XMFLOAT4X4 f4x4; - DirectX::XMStoreFloat4x4(&f4x4, - DirectX::XMMatrixMultiply( - DirectX::XMMatrixLookAtLH(DirectX::XMLoadFloat3(&eyef3), DirectX::XMLoadFloat3(&lookatf3), DirectX::XMLoadFloat3(&headupf3)), - DirectX::XMMatrixPerspectiveFovLH(fov, aspect, znear, zfar))); - float const camera_pos[8] = { - eye.x, eye.y, eye.z, 0.0f, - lookatf3.x - eyef3.x, lookatf3.y - eyef3.y, lookatf3.z - eyef3.z, 0.0f, - }; - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - /* upload vp matrix */ { - D3D11_MAPPED_SUBRESOURCE res_ = {}; - HRESULT hr = gHR = ctx->Map(_vp_matrix_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res_); - if (SUCCEEDED(hr)) - { - std::memcpy(res_.pData, &f4x4, sizeof(f4x4)); - ctx->Unmap(_vp_matrix_buffer.Get(), 0); - } - else - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #view_projection_matrix_buffer 调用失败,无法上传摄像机变换矩阵"); - } - } - /* upload camera pos */ { - D3D11_MAPPED_SUBRESOURCE res_ = {}; - HRESULT hr = gHR = ctx->Map(_camera_pos_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res_); - if (SUCCEEDED(hr)) - { - std::memcpy(res_.pData, camera_pos, sizeof(camera_pos)); - ctx->Unmap(_camera_pos_buffer.Get(), 0); - } - else - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #camera_position_buffer 调用失败,无法上传摄像机位置"); - } - } - } - } - - void Renderer_D3D11::setViewport(BoxF const& box) - { - if (_state_dirty || _state_set.viewport != box) - { - batchFlush(); - _state_set.viewport = box; - D3D11_VIEWPORT const vp = { - .TopLeftX = box.a.x, - .TopLeftY = box.a.y, - .Width = box.b.x - box.a.x, - .Height = box.b.y - box.a.y, - .MinDepth = box.a.z, - .MaxDepth = box.b.z, - }; - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - ctx->RSSetViewports(1, &vp); - } - } - void Renderer_D3D11::setScissorRect(RectF const& rect) - { - if (_state_dirty || _state_set.scissor_rect != rect) - { - batchFlush(); - _state_set.scissor_rect = rect; - D3D11_RECT const rc = { - .left = (LONG)rect.a.x, - .top = (LONG)rect.a.y, - .right = (LONG)rect.b.x, - .bottom = (LONG)rect.b.y, - }; - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - ctx->RSSetScissorRects(1, &rc); - } - } - void Renderer_D3D11::setViewportAndScissorRect() - { - _state_dirty = true; - setViewport(_state_set.viewport); - setScissorRect(_state_set.scissor_rect); - _state_dirty = false; - } - - void Renderer_D3D11::setVertexColorBlendState(VertexColorBlendState state) - { - if (_state_dirty || _state_set.vertex_color_blend_state != state) - { - batchFlush(); - _state_set.vertex_color_blend_state = state; - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - ctx->PSSetShader(_pixel_shader[IDX(state)][IDX(_state_set.fog_state)][IDX(_state_set.texture_alpha_type)].Get(), NULL, 0); - } - } - void Renderer_D3D11::setFogState(FogState state, Color4B const& color, float density_or_znear, float zfar) - { - if (_state_dirty || _state_set.fog_state != state || _state_set.fog_color != color || _state_set.fog_near_or_density != density_or_znear || _state_set.fog_far != zfar) - { - batchFlush(); - _state_set.fog_state = state; - _state_set.fog_color = color; - _state_set.fog_near_or_density = density_or_znear; - _state_set.fog_far = zfar; - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - ctx->VSSetShader(_vertex_shader[IDX(state)].Get(), NULL, 0); - float const fog_color_and_range[8] = { - (float)color.r / 255.0f, - (float)color.g / 255.0f, - (float)color.b / 255.0f, - (float)color.a / 255.0f, - density_or_znear, zfar, 0.0f, zfar - density_or_znear, - }; - /* upload */ { - D3D11_MAPPED_SUBRESOURCE res_ = {}; - HRESULT hr = gHR = ctx->Map(_fog_data_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res_); - if (SUCCEEDED(hr)) - { - std::memcpy(res_.pData, fog_color_and_range, sizeof(fog_color_and_range)); - ctx->Unmap(_fog_data_buffer.Get(), 0); - } - else - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #fog_data_buffer 调用失败,无法上传雾颜色、范围和密度信息"); - } - } - ctx->PSSetShader(_pixel_shader[IDX(_state_set.vertex_color_blend_state)][IDX(state)][IDX(_state_set.texture_alpha_type)].Get(), NULL, 0); - } - } - void Renderer_D3D11::setDepthState(DepthState state) - { - if (_state_dirty || _state_set.depth_state != state) - { - batchFlush(); - _state_set.depth_state = state; - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - ctx->OMSetDepthStencilState(_depth_state[IDX(state)].Get(), D3D11_DEFAULT_STENCIL_REFERENCE); - } - } - void Renderer_D3D11::setBlendState(BlendState state) - { - if (_state_dirty || _state_set.blend_state != state) - { - batchFlush(); - _state_set.blend_state = state; - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - FLOAT const factor[4] = {}; - ctx->OMSetBlendState(_blend_state[IDX(state)].Get(), factor, D3D11_DEFAULT_SAMPLE_MASK); - } - } - - inline bool is_same(Direct3D11::Texture2D* a, ITexture2D* b) - { - if (a && b) - return a->GetView() == static_cast(b)->GetView(); - else if (!a && !b) - return true; - else - return false; - } - inline bool is_same(SmartReference& a, ITexture2D* b) - { - return is_same(*a, b); - } - - void Renderer_D3D11::setTexture(ITexture2D* texture) - { - if (_draw_list.command.size > 0 && is_same(_draw_list.command.data[_draw_list.command.size - 1].texture, texture)) - { - // 可以合并 - } - else - { - // 新的渲染命令 - if ((_draw_list.command.capacity - _draw_list.command.size) < 1) - { - batchFlush(); // 需要腾出空间 - } - _draw_list.command.size += 1; - DrawCommand& cmd_ = _draw_list.command.data[_draw_list.command.size - 1]; - cmd_.texture = static_cast(texture); - cmd_.vertex_count = 0; - cmd_.index_count = 0; - } - // 更新当前状态的纹理 - if (!is_same(_state_texture, texture)) - { - _state_texture = static_cast(texture); - } - } - - bool Renderer_D3D11::drawTriangle(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3) - { - if ((_draw_list.vertex.capacity - _draw_list.vertex.size) < 3 || (_draw_list.index.capacity - _draw_list.index.size) < 3) - { - if (!batchFlush()) return false; - } - assert(_draw_list.command.size > 0); - DrawCommand& cmd_ = _draw_list.command.data[_draw_list.command.size - 1]; - DrawVertex* vbuf_ = _draw_list.vertex.data + _draw_list.vertex.size; - vbuf_[0] = v1; - vbuf_[1] = v2; - vbuf_[2] = v3; - _draw_list.vertex.size += 3; - DrawIndex* ibuf_ = _draw_list.index.data + _draw_list.index.size; - ibuf_[0] = cmd_.vertex_count; - ibuf_[1] = cmd_.vertex_count + 1; - ibuf_[2] = cmd_.vertex_count + 2; - _draw_list.index.size += 3; - cmd_.vertex_count += 3; - cmd_.index_count += 3; - return true; - } - bool Renderer_D3D11::drawTriangle(DrawVertex const* pvert) - { - return drawTriangle(pvert[0], pvert[1], pvert[2]); - } - bool Renderer_D3D11::drawQuad(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3, DrawVertex const& v4) - { - if ((_draw_list.vertex.capacity - _draw_list.vertex.size) < 4 || (_draw_list.index.capacity - _draw_list.index.size) < 6) - { - if (!batchFlush()) return false; - } - assert(_draw_list.command.size > 0); - DrawCommand& cmd_ = _draw_list.command.data[_draw_list.command.size - 1]; - DrawVertex* vbuf_ = _draw_list.vertex.data + _draw_list.vertex.size; - vbuf_[0] = v1; - vbuf_[1] = v2; - vbuf_[2] = v3; - vbuf_[3] = v4; - _draw_list.vertex.size += 4; - DrawIndex* ibuf_ = _draw_list.index.data + _draw_list.index.size; - ibuf_[0] = cmd_.vertex_count; - ibuf_[1] = cmd_.vertex_count + 1; - ibuf_[2] = cmd_.vertex_count + 2; - ibuf_[3] = cmd_.vertex_count; - ibuf_[4] = cmd_.vertex_count + 2; - ibuf_[5] = cmd_.vertex_count + 3; - _draw_list.index.size += 6; - cmd_.vertex_count += 4; - cmd_.index_count += 6; - return true; - } - bool Renderer_D3D11::drawQuad(DrawVertex const* pvert) - { - return drawQuad(pvert[0], pvert[1], pvert[2], pvert[3]); - } - bool Renderer_D3D11::drawRaw(DrawVertex const* pvert, uint16_t nvert, DrawIndex const* pidx, uint16_t nidx) - { - if (nvert > _draw_list.vertex.capacity || nidx > _draw_list.index.capacity) - { - assert(false); return false; - } - - if ((_draw_list.vertex.capacity - _draw_list.vertex.size) < nvert || (_draw_list.index.capacity - _draw_list.index.size) < nidx) - { - if (!batchFlush()) return false; - } - - assert(_draw_list.command.size > 0); - DrawCommand& cmd_ = _draw_list.command.data[_draw_list.command.size - 1]; - - DrawVertex* vbuf_ = _draw_list.vertex.data + _draw_list.vertex.size; - std::memcpy(vbuf_, pvert, nvert * sizeof(DrawVertex)); - _draw_list.vertex.size += nvert; - - DrawIndex* ibuf_ = _draw_list.index.data + _draw_list.index.size; - for (size_t idx_ = 0; idx_ < nidx; idx_ += 1) - { - ibuf_[idx_] = cmd_.vertex_count + pidx[idx_]; - } - _draw_list.index.size += nidx; - - cmd_.vertex_count += nvert; - cmd_.index_count += nidx; - - return true; - } - bool Renderer_D3D11::drawRequest(uint16_t nvert, uint16_t nidx, DrawVertex** ppvert, DrawIndex** ppidx, uint16_t* idxoffset) - { - if (nvert > _draw_list.vertex.capacity || nidx > _draw_list.index.capacity) - { - assert(false); return false; - } - - if ((_draw_list.vertex.capacity - _draw_list.vertex.size) < nvert || (_draw_list.index.capacity - _draw_list.index.size) < nidx) - { - if (!batchFlush()) return false; - } - - assert(_draw_list.command.size > 0); - DrawCommand& cmd_ = _draw_list.command.data[_draw_list.command.size - 1]; - - *ppvert = _draw_list.vertex.data + _draw_list.vertex.size; - _draw_list.vertex.size += nvert; - - *ppidx = _draw_list.index.data + _draw_list.index.size; - _draw_list.index.size += nidx; - - *idxoffset = cmd_.vertex_count; // 输出顶点索引偏移 - cmd_.vertex_count += nvert; - cmd_.index_count += nidx; - - return true; - } - - bool Renderer_D3D11::createPostEffectShader(StringView path, IPostEffectShader** pp_effect) - { - try - { - *pp_effect = new PostEffectShader_D3D11(m_device.get(), path, true); - return true; - } - catch (...) - { - *pp_effect = nullptr; - return false; - } - } - bool Renderer_D3D11::drawPostEffect( - IPostEffectShader* p_effect, - BlendState blend, - ITexture2D* p_tex, SamplerState rtsv, - Vector4F const* cv, size_t cv_n, - ITexture2D* const* p_tex_arr, SamplerState const* sv, size_t tv_sv_n) - { - assert(p_effect); - assert((cv_n == 0) || (cv_n > 0 && cv)); - assert((tv_sv_n == 0) || (tv_sv_n > 0 && p_tex_arr && sv)); - - if (!endBatch()) return false; - - // PREPARE - - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - - Microsoft::WRL::ComPtr p_d3d11_rtv; - Microsoft::WRL::ComPtr p_d3d11_dsv; - - float sw_ = 0.0f; - float sh_ = 0.0f; - /* get current rendertarget size */ { - ID3D11RenderTargetView* rtv_ = NULL; - ID3D11DepthStencilView* dsv_ = NULL; - ctx->OMGetRenderTargets(1, &rtv_, &dsv_); - if (rtv_) - { - Microsoft::WRL::ComPtr res_; - rtv_->GetResource(&res_); - Microsoft::WRL::ComPtr tex2d_; - HRESULT hr = gHR = res_.As(&tex2d_); - if (SUCCEEDED(hr)) - { - D3D11_TEXTURE2D_DESC desc_ = {}; - tex2d_->GetDesc(&desc_); - sw_ = (float)desc_.Width; - sh_ = (float)desc_.Height; - } - else - { - spdlog::error("[core] ID3D11Resource::QueryInterface -> #ID3D11Texture2D 调用失败"); - return false; - } - p_d3d11_rtv = rtv_; - rtv_->Release(); - } - if (dsv_) - { - p_d3d11_dsv = dsv_; - dsv_->Release(); - } - } - if (sw_ < 1.0f || sh_ < 1.0f) - { - spdlog::warn("[core] LuaSTG::core::Renderer::postEffect 调用提前中止,当前渲染管线未绑定渲染目标"); - return false; - } - - ctx->ClearState(); - - // [Stage IA] - - /* upload vertex data */ { - D3D11_MAPPED_SUBRESOURCE res_ = {}; - HRESULT hr = gHR = m_device->GetD3D11DeviceContext()->Map(_fx_vbuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res_); - if (FAILED(hr)) - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #_fx_vbuffer 调用失败,无法上传顶点"); - return false; - } - DrawVertex const vertex_data[4] = { - DrawVertex(0.f, sh_, 0.0f, 0.0f), - DrawVertex(sw_, sh_, 1.0f, 0.0f), - DrawVertex(sw_, 0.f, 1.0f, 1.0f), - DrawVertex(0.f, 0.f, 0.0f, 1.0f), - }; - std::memcpy(res_.pData, vertex_data, sizeof(vertex_data)); - m_device->GetD3D11DeviceContext()->Unmap(_fx_vbuffer.Get(), 0); - } - - ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - ID3D11Buffer* p_d3d11_vbos[1] = { _fx_vbuffer.Get() }; - UINT const stride = sizeof(DrawVertex); - UINT const offset = 0; - ctx->IASetVertexBuffers(0, 1, p_d3d11_vbos, &stride, &offset); - ctx->IASetIndexBuffer(_fx_ibuffer.Get(), DXGI_FORMAT_R16_UINT, 0); - ctx->IASetInputLayout(_input_layout.Get()); - - // [Stage VS] - - /* upload vp matrix */ { - D3D11_MAPPED_SUBRESOURCE res_ = {}; - HRESULT hr = gHR = ctx->Map(_vp_matrix_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res_); - if (SUCCEEDED(hr)) - { - DirectX::XMFLOAT4X4 f4x4; - DirectX::XMStoreFloat4x4(&f4x4, DirectX::XMMatrixOrthographicOffCenterLH(0.0f, sw_, 0.0f, sh_, 0.0f, 1.0f)); - std::memcpy(res_.pData, &f4x4, sizeof(f4x4)); - ctx->Unmap(_vp_matrix_buffer.Get(), 0); - } - else - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #view_projection_matrix_buffer 调用失败,无法上传摄像机变换矩阵"); - } - } - - ctx->VSSetShader(_vertex_shader[IDX(FogState::Disable)].Get(), NULL, 0); - ID3D11Buffer* const view_projection_matrix = _vp_matrix_buffer.Get(); - ctx->VSSetConstantBuffers(Direct3D11::Constants::vertex_shader_stage_constant_buffer_slot_view_projection_matrix, 1, &view_projection_matrix); - - // [Stage RS] - - ctx->RSSetState(_raster_state.Get()); - D3D11_VIEWPORT viewport = { - .TopLeftX = 0.0f, - .TopLeftY = 0.0f, - .Width = sw_, - .Height = sh_, - .MinDepth = 0.0f, - .MaxDepth = 1.0f, - }; - ctx->RSSetViewports(1, &viewport); - D3D11_RECT scissor = { - .left = 0, - .top = 0, - .right = (LONG)sw_, - .bottom = (LONG)sh_, - }; - ctx->RSSetScissorRects(1, &scissor); - - // [Stage PS] - - /* upload built-in value */ if (cv_n > 0) { - D3D11_MAPPED_SUBRESOURCE res_ = {}; - HRESULT hr = gHR = ctx->Map(_user_float_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res_); - if (FAILED(hr)) - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #user_float_buffer 调用失败,上传数据失败,LuaSTG::core::Renderer::postEffect 调用提前中止"); - return false; - } - std::memcpy(res_.pData, cv, std::min((UINT)cv_n, 8) * sizeof(Vector4F)); - ctx->Unmap(_user_float_buffer.Get(), 0); - } - /* upload built-in value */ { - float ps_cbdata[8] = { - sw_, sh_, 0.0f, 0.0f, - _state_set.viewport.a.x, _state_set.viewport.a.y, _state_set.viewport.b.x, _state_set.viewport.b.y, - }; - D3D11_MAPPED_SUBRESOURCE res_ = {}; - HRESULT hr = gHR = ctx->Map(_fog_data_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res_); - if (FAILED(hr)) - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #engine_built_in_value_buffer 调用失败,无法上传渲染目标尺寸和视口信息,LuaSTG::core::Renderer::postEffect 调用提前中止"); - return false; - } - std::memcpy(res_.pData, ps_cbdata, sizeof(ps_cbdata)); - ctx->Unmap(_fog_data_buffer.Get(), 0); - } - ID3D11Buffer* const user_data = _user_float_buffer.Get(); - ctx->PSSetConstantBuffers(Direct3D11::Constants::pixel_shader_stage_constant_buffer_slot_user_data, 1, &user_data); - ID3D11Buffer* const fog_parameter = _fog_data_buffer.Get(); - ctx->PSSetConstantBuffers(Direct3D11::Constants::pixel_shader_stage_constant_buffer_slot_fog_parameter, 1, &fog_parameter); - - ctx->PSSetShader(static_cast(p_effect)->GetPS(), NULL, 0); - - ID3D11ShaderResourceView* p_srvs[5] = {}; - ID3D11SamplerState* p_samplers[5] = {}; - p_srvs[4] = get_view(p_tex); - p_samplers[4] = get_sampler(_sampler_state[IDX(rtsv)]); - for (DWORD stage = 0; stage < std::min((DWORD)tv_sv_n, 4); stage += 1) - { - p_srvs[stage] = get_view(p_tex_arr[stage]); - p_samplers[stage] = get_sampler(_sampler_state[IDX(sv[stage])]); - } - ctx->PSSetShaderResources(0, 5, p_srvs); - ctx->PSSetSamplers(0, 5, p_samplers); - - // [Stage OM] - - ctx->OMSetDepthStencilState(_depth_state[IDX(DepthState::Disable)].Get(), D3D11_DEFAULT_STENCIL_REFERENCE); - FLOAT blend_factor[4] = {}; - ctx->OMSetBlendState(_blend_state[IDX(blend)].Get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); - ID3D11RenderTargetView* p_d3d11_rtvs[1] = { p_d3d11_rtv.Get() }; - ctx->OMSetRenderTargets(1, p_d3d11_rtvs, p_d3d11_dsv.Get()); - - // DRAW - - ctx->DrawIndexed(6, 0, 0); - - // CLEAR - - ctx->ClearState(); - ctx->OMSetRenderTargets(1, p_d3d11_rtvs, p_d3d11_dsv.Get()); - - return beginBatch(); - } - bool Renderer_D3D11::drawPostEffect(IPostEffectShader* p_effect, BlendState blend) - { - assert(p_effect); - - if (!endBatch()) return false; - - // PREPARE - - auto* ctx = m_device->GetD3D11DeviceContext(); - assert(ctx); - - Microsoft::WRL::ComPtr p_d3d11_rtv; - Microsoft::WRL::ComPtr p_d3d11_dsv; - - float sw_ = 0.0f; - float sh_ = 0.0f; - /* get current rendertarget size */ { - ID3D11RenderTargetView* rtv_ = NULL; - ID3D11DepthStencilView* dsv_ = NULL; - ctx->OMGetRenderTargets(1, &rtv_, &dsv_); - if (rtv_) - { - Microsoft::WRL::ComPtr res_; - rtv_->GetResource(&res_); - Microsoft::WRL::ComPtr tex2d_; - HRESULT hr = gHR = res_.As(&tex2d_); - if (SUCCEEDED(hr)) - { - D3D11_TEXTURE2D_DESC desc_ = {}; - tex2d_->GetDesc(&desc_); - sw_ = (float)desc_.Width; - sh_ = (float)desc_.Height; - } - else - { - spdlog::error("[core] ID3D11Resource::QueryInterface -> #ID3D11Texture2D 调用失败"); - return false; - } - p_d3d11_rtv = rtv_; - rtv_->Release(); - } - if (dsv_) - { - p_d3d11_dsv = dsv_; - dsv_->Release(); - } - } - if (sw_ < 1.0f || sh_ < 1.0f) - { - spdlog::warn("[core] LuaSTG::core::Renderer::postEffect 调用提前中止,当前渲染管线未绑定渲染目标"); - return false; - } - - ctx->ClearState(); - - // [Stage IA] - - /* upload vertex data */ { - D3D11_MAPPED_SUBRESOURCE res_ = {}; - HRESULT hr = gHR = m_device->GetD3D11DeviceContext()->Map(_fx_vbuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res_); - if (FAILED(hr)) - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #_fx_vbuffer 调用失败,无法上传顶点"); - return false; - } - DrawVertex const vertex_data[4] = { - DrawVertex(0.f, sh_, 0.0f, 0.0f), - DrawVertex(sw_, sh_, 1.0f, 0.0f), - DrawVertex(sw_, 0.f, 1.0f, 1.0f), - DrawVertex(0.f, 0.f, 0.0f, 1.0f), - }; - std::memcpy(res_.pData, vertex_data, sizeof(vertex_data)); - m_device->GetD3D11DeviceContext()->Unmap(_fx_vbuffer.Get(), 0); - } - - ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); - ID3D11Buffer* p_d3d11_vbos[1] = { _fx_vbuffer.Get() }; - UINT const stride = sizeof(DrawVertex); - UINT const offset = 0; - ctx->IASetVertexBuffers(0, 1, p_d3d11_vbos, &stride, &offset); - ctx->IASetIndexBuffer(_fx_ibuffer.Get(), DXGI_FORMAT_R16_UINT, 0); - ctx->IASetInputLayout(_input_layout.Get()); - - // [Stage VS] - - /* upload vp matrix */ { - D3D11_MAPPED_SUBRESOURCE res_ = {}; - HRESULT hr = gHR = ctx->Map(_vp_matrix_buffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res_); - if (SUCCEEDED(hr)) - { - DirectX::XMFLOAT4X4 f4x4; - DirectX::XMStoreFloat4x4(&f4x4, DirectX::XMMatrixOrthographicOffCenterLH(0.0f, sw_, 0.0f, sh_, 0.0f, 1.0f)); - std::memcpy(res_.pData, &f4x4, sizeof(f4x4)); - ctx->Unmap(_vp_matrix_buffer.Get(), 0); - } - else - { - spdlog::error("[core] ID3D11DeviceContext::Map -> #view_projection_matrix_buffer 调用失败,无法上传摄像机变换矩阵"); - } - } - - ctx->VSSetShader(_vertex_shader[IDX(FogState::Disable)].Get(), NULL, 0); - ID3D11Buffer* const view_projection_matrix = _vp_matrix_buffer.Get(); - ctx->VSSetConstantBuffers(Direct3D11::Constants::vertex_shader_stage_constant_buffer_slot_view_projection_matrix, 1, &view_projection_matrix); - - // [Stage RS] - - ctx->RSSetState(_raster_state.Get()); - D3D11_VIEWPORT viewport = { - .TopLeftX = 0.0f, - .TopLeftY = 0.0f, - .Width = sw_, - .Height = sh_, - .MinDepth = 0.0f, - .MaxDepth = 1.0f, - }; - ctx->RSSetViewports(1, &viewport); - D3D11_RECT scissor = { - .left = 0, - .top = 0, - .right = (LONG)sw_, - .bottom = (LONG)sh_, - }; - ctx->RSSetScissorRects(1, &scissor); - - // [Stage PS] - - if (!p_effect->apply(this)) - { - spdlog::error("[core] 无法应用 PostEffectShader 变量"); - return false; - } - ctx->PSSetShader(static_cast(p_effect)->GetPS(), NULL, 0); - - // [Stage OM] - - ctx->OMSetDepthStencilState(_depth_state[IDX(DepthState::Disable)].Get(), D3D11_DEFAULT_STENCIL_REFERENCE); - FLOAT blend_factor[4] = {}; - ctx->OMSetBlendState(_blend_state[IDX(blend)].Get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); - ID3D11RenderTargetView* p_d3d11_rtvs[1] = { p_d3d11_rtv.Get() }; - ctx->OMSetRenderTargets(1, p_d3d11_rtvs, p_d3d11_dsv.Get()); - - // DRAW - - ctx->DrawIndexed(6, 0, 0); - - // CLEAR - - ctx->ClearState(); - ctx->OMSetRenderTargets(1, p_d3d11_rtvs, p_d3d11_dsv.Get()); - - return beginBatch(); - } - - bool Renderer_D3D11::createModel(StringView path, IModel** pp_model) - { - if (!m_model_shared) - { - spdlog::info("[core] 创建模型渲染器共享组件"); - try - { - *(m_model_shared.put()) = new ModelSharedComponent_D3D11(m_device.get()); - spdlog::info("[luastg] 已创建模型渲染器共享组件"); - } - catch (...) - { - spdlog::error("[core] 无法创建模型渲染器共享组件"); - return false; - } - } - - try - { - *pp_model = new Model_D3D11(m_device.get(), m_model_shared.get(), path); - return true; - } - catch (const std::exception&) - { - *pp_model = nullptr; - spdlog::error("[luastg] LuaSTG::core::Renderer::createModel 失败"); - return false; - } - } - bool Renderer_D3D11::drawModel(IModel* p_model) - { - if (!p_model) - { - assert(false); - return false; - } - - if (!endBatch()) - { - return false; - } - - static_cast(p_model)->draw(_state_set.fog_state); - - if (!beginBatch()) - { - return false; - } - - return true; - } - - ISamplerState* Renderer_D3D11::getKnownSamplerState(SamplerState state) - { - return _sampler_state[IDX(state)].get(); - } - - Renderer_D3D11::Renderer_D3D11(Direct3D11::Device* p_device) - : m_device(p_device) - { - if (!createResources()) - throw std::runtime_error("Renderer_D3D11::Renderer_D3D11"); - m_device->addEventListener(this); - } - Renderer_D3D11::~Renderer_D3D11() - { - m_device->removeEventListener(this); - } - - bool Renderer_D3D11::create(Direct3D11::Device* p_device, Renderer_D3D11** pp_renderer) - { - try - { - *pp_renderer = new Renderer_D3D11(p_device); - return true; - } - catch (...) - { - *pp_renderer = nullptr; - return false; - } - } - - bool IRenderer::create(IDevice* p_device, IRenderer** pp_renderer) - { - try - { - *pp_renderer = new Renderer_D3D11(static_cast(p_device)); - return true; - } - catch (...) - { - *pp_renderer = nullptr; - return false; - } - } -} +#include "core/Graphics/Renderer_D3D11.hpp" +#include "core/Logger.hpp" +#include "core/Graphics/Model_D3D11.hpp" +#include "core/Graphics/Direct3D11/Constants.hpp" +#include "core/Graphics/Direct3D11/RenderTarget.hpp" +#include "core//DepthStencilBuffer.hpp" + +#define IDX(x) (size_t)static_cast(x) + +namespace core::Graphics +{ + inline ID3D11ShaderResourceView* get_view(Direct3D11::Texture2D* p) + { + return p ? p->GetView() : NULL; + } + inline ID3D11ShaderResourceView* get_view(ITexture2D* p) + { + return get_view(static_cast(p)); + } + inline ID3D11ShaderResourceView* get_view(SmartReference& p) + { + return get_view(p.get()); + } + inline ID3D11ShaderResourceView* get_view(SmartReference& p) + { + return get_view(static_cast(p.get())); + } + + inline ID3D11SamplerState* get_sampler(IGraphicsSampler* p_sampler) + { + return p_sampler != nullptr ? static_cast(p_sampler->getNativeHandle()) : nullptr; + } + inline ID3D11SamplerState* get_sampler(SmartReference& p_sampler) + { + return p_sampler ? static_cast(p_sampler->getNativeHandle()) : nullptr; + } +} + +namespace core::Graphics +{ + void PostEffectShader_D3D11::onGraphicsDeviceCreate() + { + createResources(); + } + void PostEffectShader_D3D11::onGraphicsDeviceDestroy() + { + d3d11_ps.reset(); + for (auto& v : m_buffer_map) + { + v.second.d3d11_buffer.reset(); + } + } + + bool PostEffectShader_D3D11::findVariable(StringView name, LocalConstantBuffer*& buf, LocalVariable*& val) + { + std::string name_s(name); + for (auto& b : m_buffer_map) + { + auto it = b.second.variable.find(name_s); + if (it != b.second.variable.end()) + { + buf = &b.second; + val = &it->second; + return true; + } + } + return false; + } + bool PostEffectShader_D3D11::setFloat(StringView name, float value) + { + LocalConstantBuffer* b{}; + LocalVariable* v{}; + if (!findVariable(name, b, v)) { return false; } + if (v->size != sizeof(value)) { assert(false); return false; } + memcpy(b->buffer.data() + v->offset, &value, v->size); + return true; + } + bool PostEffectShader_D3D11::setFloat2(StringView name, Vector2F value) + { + LocalConstantBuffer* b{}; + LocalVariable* v{}; + if (!findVariable(name, b, v)) { return false; } + if (v->size != sizeof(value)) { assert(false); return false; } + memcpy(b->buffer.data() + v->offset, &value, v->size); + return true; + } + bool PostEffectShader_D3D11::setFloat3(StringView name, Vector3F value) + { + LocalConstantBuffer* b{}; + LocalVariable* v{}; + if (!findVariable(name, b, v)) { return false; } + if (v->size != sizeof(value)) { assert(false); return false; } + memcpy(b->buffer.data() + v->offset, &value, v->size); + return true; + } + bool PostEffectShader_D3D11::setFloat4(StringView name, Vector4F value) + { + LocalConstantBuffer* b{}; + LocalVariable* v{}; + if (!findVariable(name, b, v)) { return false; } + if (v->size != sizeof(value)) { assert(false); return false; } + memcpy(b->buffer.data() + v->offset, &value, v->size); + return true; + } + bool PostEffectShader_D3D11::setTexture2D(StringView name, ITexture2D* p_texture) + { + std::string name_s(name); + auto it = m_texture2d_map.find(name_s); + if (it == m_texture2d_map.end()) { return false; } + it->second.texture = dynamic_cast(p_texture); + if (!it->second.texture) { assert(false); return false; } + return true; + } + bool PostEffectShader_D3D11::apply(IRenderer* p_renderer) + { + assert(p_renderer); + + auto* ctx = m_device->GetD3D11DeviceContext(); + if (!ctx) { assert(false); return false; } + + auto* p_sampler = p_renderer->getKnownSamplerState(IRenderer::SamplerState::LinearClamp); + + for (auto& v : m_buffer_map) + { + D3D11_MAPPED_SUBRESOURCE res{}; + HRESULT hr = gHR = ctx->Map(v.second.d3d11_buffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &res); + if (FAILED(hr)) { assert(false); return false; } + memcpy(res.pData, v.second.buffer.data(), v.second.buffer.size()); + ctx->Unmap(v.second.d3d11_buffer.get(), 0); + + ID3D11Buffer* b[1] = { v.second.d3d11_buffer.get() }; + ctx->PSSetConstantBuffers(v.second.index, 1, b); + } + + for (auto& v : m_texture2d_map) + { + ID3D11ShaderResourceView* t[1] = { get_view(v.second.texture) }; + ctx->PSSetShaderResources(v.second.index, 1, t); + auto* p_custom = v.second.texture->getSamplerState(); + ID3D11SamplerState* s[1] = { p_custom ? get_sampler(p_custom) : get_sampler(p_sampler) }; + ctx->PSSetSamplers(v.second.index, 1, s); + } + + return true; + } + + PostEffectShader_D3D11::PostEffectShader_D3D11(GraphicsDevice* p_device, StringView path, bool is_path_) + : m_device(p_device) + , source(path) + , is_path(is_path_) + { + if (!createResources()) + throw std::runtime_error("PostEffectShader_D3D11::PostEffectShader_D3D11"); + m_device->addEventListener(this); + } + PostEffectShader_D3D11::~PostEffectShader_D3D11() + { + m_device->removeEventListener(this); + } +} + +namespace core::Graphics +{ + void Renderer_D3D11::setVertexIndexBuffer(const size_t index) { + assert(m_device->GetD3D11DeviceContext()); + + auto& vi = _vi_buffer[(index == 0xFFFFFFFFu) ? _vi_buffer_index : index]; + ID3D11Buffer* vbo[1] = { static_cast(vi.vertex_buffer->getNativeResource()) }; + UINT stride[1] = { sizeof(IRenderer::DrawVertex) }; + UINT offset[1] = { 0 }; + m_device->GetD3D11DeviceContext()->IASetVertexBuffers(0, 1, vbo, stride, offset); + + constexpr DXGI_FORMAT format = sizeof(DrawIndex) < 4 ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT; + m_device->GetD3D11DeviceContext()->IASetIndexBuffer(static_cast(vi.index_buffer->getNativeResource()), format, 0); + } + bool Renderer_D3D11::uploadVertexIndexBuffer(const bool discard) { + tracy_zone_scoped; + tracy_d3d11_context_zone(m_device->GetTracyContext(), "UploadVertexIndexBuffer"); + + const auto& current = _vi_buffer[_vi_buffer_index]; + + // copy vertex data + if (_draw_list.vertex.size > 0) { + DrawVertex* ptr{}; + if (!current.vertex_buffer->map(reinterpret_cast(&ptr), discard)) { + Logger::error("[core] [Renderer] upload vertex buffer failed (map)"); + return false; + } + std::memcpy(ptr + current.vertex_offset, _draw_list.vertex.data, _draw_list.vertex.size * sizeof(DrawVertex)); + if (!current.vertex_buffer->unmap()) { + Logger::error("[core] [Renderer] upload vertex buffer failed (unmap)"); + return false; + } + } + + // copy index data + if (_draw_list.index.size > 0) { + DrawIndex* ptr{}; + if (!current.index_buffer->map(reinterpret_cast(&ptr), discard)) { + Logger::error("[core] [Renderer] upload index buffer failed (map)"); + return false; + } + std::memcpy(ptr + current.index_offset, _draw_list.index.data, _draw_list.index.size * sizeof(DrawIndex)); + if (!current.index_buffer->unmap()) { + Logger::error("[core] [Renderer] upload index buffer failed (unmap)"); + return false; + } + } + + return true; + } + void Renderer_D3D11::clearDrawList() { + for (size_t i = 0; i < _draw_list.command.size; i += 1) { + _draw_list.command.data[i].texture.reset(); + } + _draw_list.vertex.size = 0; + _draw_list.index.size = 0; + _draw_list.command.size = 0; + } + + bool Renderer_D3D11::createBuffers() + { + assert(m_device->getNativeHandle() != nullptr); + + if (!m_device->createVertexBuffer(4 * sizeof(DrawVertex), _fx_vbuffer.put())) { + return false; + } + if (!m_device->createIndexBuffer(6 * sizeof(DrawIndex), _fx_ibuffer.put())) { + return false; + } + { + constexpr DrawIndex quad_index[6] = { 0, 1, 2, 0, 2, 3 }; + DrawIndex* ptr{}; + if (!_fx_ibuffer->map(reinterpret_cast(&ptr), false)) { + return false; + } + std::memcpy(ptr, quad_index, sizeof(quad_index)); + if (!_fx_ibuffer->unmap()) { + return false; + } + } + + for (auto& vi_ : _vi_buffer) { + if (!m_device->createVertexBuffer(sizeof(_draw_list.vertex.data), vi_.vertex_buffer.put())) { + return false; + } + if (!m_device->createIndexBuffer(sizeof(_draw_list.index.data), vi_.index_buffer.put())) { + return false; + } + } + + if (!m_device->createConstantBuffer(sizeof(DirectX::XMFLOAT4X4), _vp_matrix_buffer.put())) { + return false; + } + if (!m_device->createConstantBuffer(sizeof(DirectX::XMFLOAT4X4), _world_matrix_buffer.put())) { + return false; + } + if (!m_device->createConstantBuffer(2 * sizeof(DirectX::XMFLOAT4), _camera_pos_buffer.put())) { + return false; + } + if (!m_device->createConstantBuffer(2 * sizeof(DirectX::XMFLOAT4), _fog_data_buffer.put())) { + return false; + } + // 用户最多可用 8 个 float4 + if (!m_device->createConstantBuffer(8 * sizeof(DirectX::XMFLOAT4), _user_float_buffer.put())) { + return false; + } + + return true; + } + bool Renderer_D3D11::createStates(const bool is_recreating) + { + assert(m_device->GetD3D11Device()); + + HRESULT hr = 0; + + { + D3D11_RASTERIZER_DESC desc_ = { + .FillMode = D3D11_FILL_SOLID, + .CullMode = D3D11_CULL_NONE, // 2D 图片精灵可能有负缩放 + .FrontCounterClockwise = FALSE, + .DepthBias = D3D11_DEFAULT_DEPTH_BIAS, + .DepthBiasClamp = D3D11_DEFAULT_DEPTH_BIAS_CLAMP, + .SlopeScaledDepthBias = D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS, + .DepthClipEnable = TRUE, + .ScissorEnable = TRUE, + .MultisampleEnable = FALSE, + .AntialiasedLineEnable = FALSE, + }; + hr = gHR = m_device->GetD3D11Device()->CreateRasterizerState(&desc_, _raster_state.put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_raster_state.get()); + } + + if (!is_recreating) { + GraphicsSamplerInfo sampler_info{}; + + // point + + sampler_info.filter = GraphicsFilter::point; + sampler_info.address_u = GraphicsTextureAddressMode::wrap; + sampler_info.address_v = GraphicsTextureAddressMode::wrap; + sampler_info.address_w = GraphicsTextureAddressMode::wrap; + if (!m_device->createSampler(sampler_info, _sampler_state[IDX(SamplerState::PointWrap)].put())) + return false; + + sampler_info.filter = GraphicsFilter::point; + sampler_info.address_u = GraphicsTextureAddressMode::clamp; + sampler_info.address_v = GraphicsTextureAddressMode::clamp; + sampler_info.address_w = GraphicsTextureAddressMode::clamp; + if (!m_device->createSampler(sampler_info, _sampler_state[IDX(SamplerState::PointClamp)].put())) + return false; + + // linear + + sampler_info.filter = GraphicsFilter::linear; + sampler_info.address_u = GraphicsTextureAddressMode::wrap; + sampler_info.address_v = GraphicsTextureAddressMode::wrap; + sampler_info.address_w = GraphicsTextureAddressMode::wrap; + if (!m_device->createSampler(sampler_info, _sampler_state[IDX(SamplerState::LinearWrap)].put())) + return false; + + sampler_info.filter = GraphicsFilter::linear; + sampler_info.address_u = GraphicsTextureAddressMode::clamp; + sampler_info.address_v = GraphicsTextureAddressMode::clamp; + sampler_info.address_w = GraphicsTextureAddressMode::clamp; + if (!m_device->createSampler(sampler_info, _sampler_state[IDX(SamplerState::LinearClamp)].put())) + return false; + } + + { + D3D11_DEPTH_STENCIL_DESC desc_ = { + .DepthEnable = FALSE, + .DepthWriteMask = D3D11_DEPTH_WRITE_MASK_ALL, + .DepthFunc = D3D11_COMPARISON_LESS_EQUAL, + .StencilEnable = FALSE, + .StencilReadMask = D3D11_DEFAULT_STENCIL_READ_MASK, + .StencilWriteMask = D3D11_DEFAULT_STENCIL_WRITE_MASK, + .FrontFace = D3D11_DEPTH_STENCILOP_DESC{ + .StencilFailOp = D3D11_STENCIL_OP_KEEP, + .StencilDepthFailOp = D3D11_STENCIL_OP_KEEP, + .StencilPassOp = D3D11_STENCIL_OP_KEEP, + .StencilFunc = D3D11_COMPARISON_ALWAYS, + }, + .BackFace = D3D11_DEPTH_STENCILOP_DESC{ + .StencilFailOp = D3D11_STENCIL_OP_KEEP, + .StencilDepthFailOp = D3D11_STENCIL_OP_KEEP, + .StencilPassOp = D3D11_STENCIL_OP_KEEP, + .StencilFunc = D3D11_COMPARISON_ALWAYS, + }, + }; + hr = gHR = m_device->GetD3D11Device()->CreateDepthStencilState(&desc_, _depth_state[IDX(DepthState::Disable)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_depth_state[IDX(DepthState::Disable)].get()); + + desc_.DepthEnable = TRUE; + hr = gHR = m_device->GetD3D11Device()->CreateDepthStencilState(&desc_, _depth_state[IDX(DepthState::Enable)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_depth_state[IDX(DepthState::Enable)].get()); + } + + { + D3D11_BLEND_DESC desc_ = { + .AlphaToCoverageEnable = FALSE, + .IndependentBlendEnable = FALSE, + .RenderTarget = {}, + }; + D3D11_RENDER_TARGET_BLEND_DESC blendt_ = { + .BlendEnable = FALSE, + .SrcBlend = D3D11_BLEND_ZERO, + .DestBlend = D3D11_BLEND_ONE, + .BlendOp = D3D11_BLEND_OP_ADD, + .SrcBlendAlpha = D3D11_BLEND_ZERO, + .DestBlendAlpha = D3D11_BLEND_ONE, + .BlendOpAlpha = D3D11_BLEND_OP_ADD, + .RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL, + }; + auto copy_ = [&]() -> void + { + for (auto& v : desc_.RenderTarget) + { + v = blendt_; + } + }; + copy_(); + + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::Disable)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Disable)].get()); + + blendt_.BlendEnable = TRUE; + + blendt_.BlendOp = D3D11_BLEND_OP_ADD; + blendt_.SrcBlend = D3D11_BLEND_ONE; + blendt_.DestBlend = D3D11_BLEND_INV_SRC_ALPHA; + blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; + blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; + blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + copy_(); + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::Alpha)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Alpha)].get()); + + blendt_.BlendOp = D3D11_BLEND_OP_ADD; + blendt_.SrcBlend = D3D11_BLEND_ONE; + blendt_.DestBlend = D3D11_BLEND_ZERO; + blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; + blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; + blendt_.DestBlendAlpha = D3D11_BLEND_ZERO; + copy_(); + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::One)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::One)].get()); + + blendt_.BlendOp = D3D11_BLEND_OP_MIN; + blendt_.SrcBlend = D3D11_BLEND_ONE; + blendt_.DestBlend = D3D11_BLEND_ONE; + blendt_.BlendOpAlpha = D3D11_BLEND_OP_MIN; + blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; + blendt_.DestBlendAlpha = D3D11_BLEND_ONE; + copy_(); + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::Min)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Min)].get()); + + blendt_.BlendOp = D3D11_BLEND_OP_MAX; + blendt_.SrcBlend = D3D11_BLEND_ONE; + blendt_.DestBlend = D3D11_BLEND_ONE; + blendt_.BlendOpAlpha = D3D11_BLEND_OP_MAX; + blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; + blendt_.DestBlendAlpha = D3D11_BLEND_ONE; + copy_(); + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::Max)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Max)].get()); + + blendt_.BlendOp = D3D11_BLEND_OP_ADD; + blendt_.SrcBlend = D3D11_BLEND_DEST_COLOR; + blendt_.DestBlend = D3D11_BLEND_ZERO; + blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; + blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; + blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + copy_(); + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::Mul)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Mul)].get()); + + blendt_.BlendOp = D3D11_BLEND_OP_ADD; + blendt_.SrcBlend = D3D11_BLEND_ONE; + blendt_.DestBlend = D3D11_BLEND_INV_SRC_COLOR; + blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; + blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; + blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + copy_(); + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::Screen)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Screen)].get()); + + blendt_.BlendOp = D3D11_BLEND_OP_ADD; + blendt_.SrcBlend = D3D11_BLEND_ONE; + blendt_.DestBlend = D3D11_BLEND_ONE; + blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; + blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; + blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + copy_(); + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::Add)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Add)].get()); + + blendt_.BlendOp = D3D11_BLEND_OP_SUBTRACT; + blendt_.SrcBlend = D3D11_BLEND_ONE; + blendt_.DestBlend = D3D11_BLEND_ONE; + blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; + blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; + blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + copy_(); + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::Sub)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Sub)].get()); + + blendt_.BlendOp = D3D11_BLEND_OP_REV_SUBTRACT; + blendt_.SrcBlend = D3D11_BLEND_ONE; + blendt_.DestBlend = D3D11_BLEND_ONE; + blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; + blendt_.SrcBlendAlpha = D3D11_BLEND_ONE; + blendt_.DestBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; + copy_(); + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::RevSub)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::RevSub)].get()); + + blendt_.BlendOp = D3D11_BLEND_OP_ADD; + blendt_.SrcBlend = D3D11_BLEND_INV_DEST_COLOR; + blendt_.DestBlend = D3D11_BLEND_INV_SRC_COLOR; + blendt_.BlendOpAlpha = D3D11_BLEND_OP_ADD; + blendt_.SrcBlendAlpha = D3D11_BLEND_ZERO; + blendt_.DestBlendAlpha = D3D11_BLEND_ONE; + copy_(); + hr = gHR = m_device->GetD3D11Device()->CreateBlendState(&desc_, _blend_state[IDX(BlendState::Inv)].put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(_blend_state[IDX(BlendState::Inv)].get()); + } + + return true; + } + void Renderer_D3D11::initState() + { + _state_dirty = true; + + if (!_camera_state_set.is_3D) + { + setOrtho(_camera_state_set.ortho); + } + else + { + setPerspective(_camera_state_set.eye, _camera_state_set.lookat, _camera_state_set.headup, _camera_state_set.fov, _camera_state_set.aspect, _camera_state_set.znear, _camera_state_set.zfar); + } + + setViewport(_state_set.viewport); + setScissorRect(_state_set.scissor_rect); + + setVertexColorBlendState(_state_set.vertex_color_blend_state); + setSamplerState(_state_set.sampler_state, 0); + setFogState(_state_set.fog_state, _state_set.fog_color, _state_set.fog_near_or_density, _state_set.fog_far); + setDepthState(_state_set.depth_state); + setBlendState(_state_set.blend_state); + setTexture(_state_texture.get()); + bindTextureAlphaType(_state_texture.get()); + + _state_dirty = false; + } + void Renderer_D3D11::setSamplerState(SamplerState state, UINT index) + { + ID3D11SamplerState* d3d11_sampler = get_sampler(_sampler_state[IDX(state)]); + m_device->GetD3D11DeviceContext()->PSSetSamplers(index, 1, &d3d11_sampler); + } + bool Renderer_D3D11::uploadVertexIndexBufferFromDrawList() + { + // upload data + if ((_draw_list.vertex.capacity - _vi_buffer[_vi_buffer_index].vertex_offset) < _draw_list.vertex.size + || (_draw_list.index.capacity - _vi_buffer[_vi_buffer_index].index_offset) < _draw_list.index.size) + { + // next buffer + _vi_buffer_index = (_vi_buffer_index + 1) % _vi_buffer_count; + _vi_buffer[_vi_buffer_index].vertex_offset = 0; + _vi_buffer[_vi_buffer_index].index_offset = 0; + // discard and copy + if (!uploadVertexIndexBuffer(true)) + { + clearDrawList(); + return false; + } + // bind buffer + if (_vi_buffer_count > 1) + { + setVertexIndexBuffer(); // need to switch v/i buffers + } + } + else + { + // copy no overwrite + if (!uploadVertexIndexBuffer(false)) + { + clearDrawList(); + return false; + } + } + return true; + } + void Renderer_D3D11::bindTextureSamplerState(ITexture2D* texture) + { + IGraphicsSampler* sampler_from_texture = texture ? texture->getSamplerState() : nullptr; + IGraphicsSampler* sampler = sampler_from_texture ? sampler_from_texture : _sampler_state[IDX(_state_set.sampler_state)].get(); + ID3D11SamplerState* d3d11_sampler = get_sampler(sampler); + m_device->GetD3D11DeviceContext()->PSSetSamplers(0, 1, &d3d11_sampler); + } + void Renderer_D3D11::bindTextureAlphaType(ITexture2D* texture) + { + TextureAlphaType const state = (texture ? texture->isPremultipliedAlpha() : false) ? TextureAlphaType::PremulAlpha : TextureAlphaType::Normal; + if (_state_dirty || _state_set.texture_alpha_type != state) + { + _state_set.texture_alpha_type = state; + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + ctx->PSSetShader(_pixel_shader[IDX(_state_set.vertex_color_blend_state)][IDX(_state_set.fog_state)][IDX(state)].get(), NULL, 0); + } + } + bool Renderer_D3D11::batchFlush(bool discard) + { + tracy_zone_scoped; + if (!discard) + { + tracy_d3d11_context_zone(m_device->GetTracyContext(), "BatchFlush"); + // upload data + if (!uploadVertexIndexBufferFromDrawList()) return false; + // draw + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + if (_draw_list.command.size > 0) + { + VertexIndexBuffer& vi_ = _vi_buffer[_vi_buffer_index]; + for (size_t j_ = 0; j_ < _draw_list.command.size; j_ += 1) + { + DrawCommand& cmd_ = _draw_list.command.data[j_]; + if (cmd_.vertex_count > 0 && cmd_.index_count > 0) + { + ID3D11ShaderResourceView* srv[1] = { get_view(cmd_.texture) }; + ctx->PSSetShaderResources(0, 1, srv); + bindTextureSamplerState(cmd_.texture.get()); + bindTextureAlphaType(cmd_.texture.get()); + ctx->DrawIndexed(cmd_.index_count, vi_.index_offset, vi_.vertex_offset); + } + vi_.vertex_offset += cmd_.vertex_count; + vi_.index_offset += cmd_.index_count; + } + } + // unbound: solve some debug warning + ID3D11ShaderResourceView* null_srv[1] = { NULL }; + ctx->PSSetShaderResources(0, 1, null_srv); + } + // clear + clearDrawList(); + setTexture(_state_texture.get()); + return true; + } + + bool Renderer_D3D11::createResources(const bool is_recreating) { + assert(m_device->getNativeHandle()); + + Logger::info("[core] [Renderer] initializing..."); + + if (!is_recreating) { + if (!createBuffers()) { + Logger::error("[core] [Renderer] create Buffers failed"); + return false; + } + } + if (!createStates(is_recreating)) { + Logger::error("[core] [Renderer] create PipelineState objects failed"); + return false; + } + if (!createShaders()) { + Logger::error("[core] [Renderer] create Shaders failed"); + return false; + } + + Logger::info("[core] [Renderer] initialization complete"); + + return true; + } + void Renderer_D3D11::onGraphicsDeviceCreate() + { + createResources(true); + } + void Renderer_D3D11::onGraphicsDeviceDestroy() { + batchFlush(true); + + _state_texture.reset(); + + //_fx_vbuffer.reset(); + //_fx_ibuffer.reset(); + for (auto& v : _vi_buffer) { + //v.vertex_buffer.reset(); + //v.index_buffer.reset(); + v.vertex_offset = 0; + v.index_offset = 0; + } + _vi_buffer_index = 0; + + //_vp_matrix_buffer.reset(); + //_world_matrix_buffer.reset(); + //_camera_pos_buffer.reset(); + //_fog_data_buffer.reset(); + //_user_float_buffer.reset(); + + _input_layout.reset(); + for (auto& v : _vertex_shader) { + v.reset(); + } + for (auto& i : _pixel_shader) { + for (auto& j : i) { + for (auto& v : j) { + v.reset(); + } + } + } + _raster_state.reset(); + //for (auto& v : _sampler_state) { + // v.reset(); + //} + for (auto& v : _depth_state) { + v.reset(); + } + for (auto& v : _blend_state) { + v.reset(); + } + + Logger::info("[core] [Renderer] cleanup complete"); + } + + bool Renderer_D3D11::beginBatch() + { + auto const ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + + // [IA Stage] + + ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ctx->IASetInputLayout(_input_layout.get()); + setVertexIndexBuffer(); + + // [VS State] + + ID3D11Buffer* const view_projection_matrix = static_cast(_vp_matrix_buffer->getNativeResource()); + ctx->VSSetConstantBuffers(Direct3D11::Constants::vertex_shader_stage_constant_buffer_slot_view_projection_matrix, 1, &view_projection_matrix); + ID3D11Buffer* const world_matrix = static_cast(_world_matrix_buffer->getNativeResource()); + ctx->VSSetConstantBuffers(Direct3D11::Constants::vertex_shader_stage_constant_buffer_slot_world_matrix, 1, &world_matrix); + + // [RS Stage] + + ctx->RSSetState(_raster_state.get()); + + // [PS State] + + ID3D11Buffer* const camera_position = static_cast(_camera_pos_buffer->getNativeResource()); + ctx->PSSetConstantBuffers(Direct3D11::Constants::pixel_shader_stage_constant_buffer_slot_camera_position, 1, &camera_position); + ID3D11Buffer* const fog_parameter = static_cast(_fog_data_buffer->getNativeResource()); + ctx->PSSetConstantBuffers(Direct3D11::Constants::pixel_shader_stage_constant_buffer_slot_fog_parameter, 1, &fog_parameter); + + // [OM Stage] + + // [Internal State] + + initState(); + + _batch_scope = true; + return true; + } + bool Renderer_D3D11::endBatch() + { + _batch_scope = false; + if (!batchFlush()) + return false; + _state_texture.reset(); + return true; + } + bool Renderer_D3D11::flush() + { + return batchFlush(); + } + + void Renderer_D3D11::clearRenderTarget(Color4B const& color) + { + batchFlush(); + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + ID3D11RenderTargetView* rtv = NULL; + ctx->OMGetRenderTargets(1, &rtv, NULL); + if (rtv) + { + FLOAT const clear_color[4] = { + (float)color.r / 255.0f, + (float)color.g / 255.0f, + (float)color.b / 255.0f, + (float)color.a / 255.0f, + }; + ctx->ClearRenderTargetView(rtv, clear_color); + rtv->Release(); + } + } + void Renderer_D3D11::clearDepthBuffer(float zvalue) + { + batchFlush(); + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + ID3D11DepthStencilView* dsv = NULL; + ctx->OMGetRenderTargets(1, NULL, &dsv); + if (dsv) + { + ctx->ClearDepthStencilView(dsv, D3D11_CLEAR_DEPTH, zvalue, D3D11_DEFAULT_STENCIL_REFERENCE); + dsv->Release(); + } + } + void Renderer_D3D11::setRenderAttachment(IRenderTarget* p_rt, IDepthStencilBuffer* p_ds) + { + batchFlush(); + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + ID3D11RenderTargetView* rtv[1] = { p_rt ? static_cast(p_rt)->GetView() : nullptr }; + ID3D11DepthStencilView* dsv = p_ds ? static_cast(p_ds->getNativeView()) : nullptr; + ctx->OMSetRenderTargets(1, rtv, dsv); + } + + void Renderer_D3D11::setOrtho(BoxF const& box) + { + if (_state_dirty || !_camera_state_set.isEqual(box)) + { + batchFlush(); + _camera_state_set.ortho = box; + _camera_state_set.is_3D = false; + DirectX::XMFLOAT4X4 f4x4; + DirectX::XMStoreFloat4x4(&f4x4, DirectX::XMMatrixOrthographicOffCenterLH(box.a.x, box.b.x, box.b.y, box.a.y, box.a.z, box.b.z)); + if (!_vp_matrix_buffer->update(&f4x4, sizeof(f4x4), true)) { + Logger::error("[core] [Renderer] upload constant buffer failed (vp_matrix_buffer)"); + } + } + } + void Renderer_D3D11::setPerspective(Vector3F const& eye, Vector3F const& lookat, Vector3F const& headup, float fov, float aspect, float znear, float zfar) + { + if (_state_dirty || !_camera_state_set.isEqual(eye, lookat, headup, fov, aspect, znear, zfar)) + { + batchFlush(); + _camera_state_set.eye = eye; + _camera_state_set.lookat = lookat; + _camera_state_set.headup = headup; + _camera_state_set.fov = fov; + _camera_state_set.aspect = aspect; + _camera_state_set.znear = znear; + _camera_state_set.zfar = zfar; + _camera_state_set.is_3D = true; + DirectX::XMFLOAT3 const eyef3(eye.x, eye.y, eye.z); + DirectX::XMFLOAT3 const lookatf3(lookat.x, lookat.y, lookat.z); + DirectX::XMFLOAT3 const headupf3(headup.x, headup.y, headup.z); + DirectX::XMFLOAT4X4 f4x4; + DirectX::XMStoreFloat4x4(&f4x4, + DirectX::XMMatrixMultiply( + DirectX::XMMatrixLookAtLH(DirectX::XMLoadFloat3(&eyef3), DirectX::XMLoadFloat3(&lookatf3), DirectX::XMLoadFloat3(&headupf3)), + DirectX::XMMatrixPerspectiveFovLH(fov, aspect, znear, zfar))); + float const camera_pos[8] = { + eye.x, eye.y, eye.z, 0.0f, + lookatf3.x - eyef3.x, lookatf3.y - eyef3.y, lookatf3.z - eyef3.z, 0.0f, + }; + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + if (!_vp_matrix_buffer->update(&f4x4, sizeof(f4x4), true)) { + Logger::error("[core] [Renderer] upload constant buffer failed (vp_matrix_buffer)"); + } + if (!_camera_pos_buffer->update(camera_pos, sizeof(camera_pos), true)) { + Logger::error("[core] [Renderer] upload constant buffer failed (camera_pos_buffer)"); + } + } + } + + void Renderer_D3D11::setViewport(BoxF const& box) + { + if (_state_dirty || _state_set.viewport != box) + { + batchFlush(); + _state_set.viewport = box; + D3D11_VIEWPORT const vp = { + .TopLeftX = box.a.x, + .TopLeftY = box.a.y, + .Width = box.b.x - box.a.x, + .Height = box.b.y - box.a.y, + .MinDepth = box.a.z, + .MaxDepth = box.b.z, + }; + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + ctx->RSSetViewports(1, &vp); + } + } + void Renderer_D3D11::setScissorRect(RectF const& rect) + { + if (_state_dirty || _state_set.scissor_rect != rect) + { + batchFlush(); + _state_set.scissor_rect = rect; + D3D11_RECT const rc = { + .left = (LONG)rect.a.x, + .top = (LONG)rect.a.y, + .right = (LONG)rect.b.x, + .bottom = (LONG)rect.b.y, + }; + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + ctx->RSSetScissorRects(1, &rc); + } + } + void Renderer_D3D11::setViewportAndScissorRect() + { + _state_dirty = true; + setViewport(_state_set.viewport); + setScissorRect(_state_set.scissor_rect); + _state_dirty = false; + } + + void Renderer_D3D11::setVertexColorBlendState(VertexColorBlendState state) + { + if (_state_dirty || _state_set.vertex_color_blend_state != state) + { + batchFlush(); + _state_set.vertex_color_blend_state = state; + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + ctx->PSSetShader(_pixel_shader[IDX(state)][IDX(_state_set.fog_state)][IDX(_state_set.texture_alpha_type)].get(), NULL, 0); + } + } + void Renderer_D3D11::setFogState(FogState state, Color4B const& color, float density_or_znear, float zfar) + { + if (_state_dirty || _state_set.fog_state != state || _state_set.fog_color != color || _state_set.fog_near_or_density != density_or_znear || _state_set.fog_far != zfar) + { + batchFlush(); + _state_set.fog_state = state; + _state_set.fog_color = color; + _state_set.fog_near_or_density = density_or_znear; + _state_set.fog_far = zfar; + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + ctx->VSSetShader(_vertex_shader[IDX(state)].get(), NULL, 0); + float const fog_color_and_range[8] = { + (float)color.r / 255.0f, + (float)color.g / 255.0f, + (float)color.b / 255.0f, + (float)color.a / 255.0f, + density_or_znear, zfar, 0.0f, zfar - density_or_znear, + }; + if (!_fog_data_buffer->update(fog_color_and_range, sizeof(fog_color_and_range), true)) { + Logger::error("[core] [Renderer] upload constant buffer failed (fog_data_buffer)"); + } + ctx->PSSetShader(_pixel_shader[IDX(_state_set.vertex_color_blend_state)][IDX(state)][IDX(_state_set.texture_alpha_type)].get(), NULL, 0); + } + } + void Renderer_D3D11::setDepthState(DepthState state) + { + if (_state_dirty || _state_set.depth_state != state) + { + batchFlush(); + _state_set.depth_state = state; + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + ctx->OMSetDepthStencilState(_depth_state[IDX(state)].get(), D3D11_DEFAULT_STENCIL_REFERENCE); + } + } + void Renderer_D3D11::setBlendState(BlendState state) + { + if (_state_dirty || _state_set.blend_state != state) + { + batchFlush(); + _state_set.blend_state = state; + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + FLOAT const factor[4] = {}; + ctx->OMSetBlendState(_blend_state[IDX(state)].get(), factor, D3D11_DEFAULT_SAMPLE_MASK); + } + } + + inline bool is_same(Direct3D11::Texture2D* a, ITexture2D* b) + { + if (a && b) + return a->GetView() == static_cast(b)->GetView(); + else if (!a && !b) + return true; + else + return false; + } + inline bool is_same(SmartReference& a, ITexture2D* b) + { + return is_same(*a, b); + } + + void Renderer_D3D11::setTexture(ITexture2D* texture) + { + if (_draw_list.command.size > 0 && is_same(_draw_list.command.data[_draw_list.command.size - 1].texture, texture)) + { + // 可以合并 + } + else + { + // 新的渲染命令 + if ((_draw_list.command.capacity - _draw_list.command.size) < 1) + { + batchFlush(); // 需要腾出空间 + } + _draw_list.command.size += 1; + DrawCommand& cmd_ = _draw_list.command.data[_draw_list.command.size - 1]; + cmd_.texture = static_cast(texture); + cmd_.vertex_count = 0; + cmd_.index_count = 0; + } + // 更新当前状态的纹理 + if (!is_same(_state_texture, texture)) + { + _state_texture = static_cast(texture); + } + } + + bool Renderer_D3D11::drawTriangle(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3) + { + if ((_draw_list.vertex.capacity - _draw_list.vertex.size) < 3 || (_draw_list.index.capacity - _draw_list.index.size) < 3) + { + if (!batchFlush()) return false; + } + assert(_draw_list.command.size > 0); + DrawCommand& cmd_ = _draw_list.command.data[_draw_list.command.size - 1]; + DrawVertex* vbuf_ = _draw_list.vertex.data + _draw_list.vertex.size; + vbuf_[0] = v1; + vbuf_[1] = v2; + vbuf_[2] = v3; + _draw_list.vertex.size += 3; + DrawIndex* ibuf_ = _draw_list.index.data + _draw_list.index.size; + ibuf_[0] = cmd_.vertex_count; + ibuf_[1] = cmd_.vertex_count + 1; + ibuf_[2] = cmd_.vertex_count + 2; + _draw_list.index.size += 3; + cmd_.vertex_count += 3; + cmd_.index_count += 3; + return true; + } + bool Renderer_D3D11::drawTriangle(DrawVertex const* pvert) + { + return drawTriangle(pvert[0], pvert[1], pvert[2]); + } + bool Renderer_D3D11::drawQuad(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3, DrawVertex const& v4) + { + if ((_draw_list.vertex.capacity - _draw_list.vertex.size) < 4 || (_draw_list.index.capacity - _draw_list.index.size) < 6) + { + if (!batchFlush()) return false; + } + assert(_draw_list.command.size > 0); + DrawCommand& cmd_ = _draw_list.command.data[_draw_list.command.size - 1]; + DrawVertex* vbuf_ = _draw_list.vertex.data + _draw_list.vertex.size; + vbuf_[0] = v1; + vbuf_[1] = v2; + vbuf_[2] = v3; + vbuf_[3] = v4; + _draw_list.vertex.size += 4; + DrawIndex* ibuf_ = _draw_list.index.data + _draw_list.index.size; + ibuf_[0] = cmd_.vertex_count; + ibuf_[1] = cmd_.vertex_count + 1; + ibuf_[2] = cmd_.vertex_count + 2; + ibuf_[3] = cmd_.vertex_count; + ibuf_[4] = cmd_.vertex_count + 2; + ibuf_[5] = cmd_.vertex_count + 3; + _draw_list.index.size += 6; + cmd_.vertex_count += 4; + cmd_.index_count += 6; + return true; + } + bool Renderer_D3D11::drawQuad(DrawVertex const* pvert) + { + return drawQuad(pvert[0], pvert[1], pvert[2], pvert[3]); + } + bool Renderer_D3D11::drawRaw(DrawVertex const* pvert, uint16_t nvert, DrawIndex const* pidx, uint16_t nidx) + { + if (nvert > _draw_list.vertex.capacity || nidx > _draw_list.index.capacity) + { + assert(false); return false; + } + + if ((_draw_list.vertex.capacity - _draw_list.vertex.size) < nvert || (_draw_list.index.capacity - _draw_list.index.size) < nidx) + { + if (!batchFlush()) return false; + } + + assert(_draw_list.command.size > 0); + DrawCommand& cmd_ = _draw_list.command.data[_draw_list.command.size - 1]; + + DrawVertex* vbuf_ = _draw_list.vertex.data + _draw_list.vertex.size; + std::memcpy(vbuf_, pvert, nvert * sizeof(DrawVertex)); + _draw_list.vertex.size += nvert; + + DrawIndex* ibuf_ = _draw_list.index.data + _draw_list.index.size; + for (size_t idx_ = 0; idx_ < nidx; idx_ += 1) + { + ibuf_[idx_] = cmd_.vertex_count + pidx[idx_]; + } + _draw_list.index.size += nidx; + + cmd_.vertex_count += nvert; + cmd_.index_count += nidx; + + return true; + } + bool Renderer_D3D11::drawRequest(uint16_t nvert, uint16_t nidx, DrawVertex** ppvert, DrawIndex** ppidx, uint16_t* idxoffset) + { + if (nvert > _draw_list.vertex.capacity || nidx > _draw_list.index.capacity) + { + assert(false); return false; + } + + if ((_draw_list.vertex.capacity - _draw_list.vertex.size) < nvert || (_draw_list.index.capacity - _draw_list.index.size) < nidx) + { + if (!batchFlush()) return false; + } + + assert(_draw_list.command.size > 0); + DrawCommand& cmd_ = _draw_list.command.data[_draw_list.command.size - 1]; + + *ppvert = _draw_list.vertex.data + _draw_list.vertex.size; + _draw_list.vertex.size += nvert; + + *ppidx = _draw_list.index.data + _draw_list.index.size; + _draw_list.index.size += nidx; + + *idxoffset = cmd_.vertex_count; // 输出顶点索引偏移 + cmd_.vertex_count += nvert; + cmd_.index_count += nidx; + + return true; + } + + bool Renderer_D3D11::createPostEffectShader(StringView path, IPostEffectShader** pp_effect) + { + try + { + *pp_effect = new PostEffectShader_D3D11(m_device.get(), path, true); + return true; + } + catch (...) + { + *pp_effect = nullptr; + return false; + } + } + bool Renderer_D3D11::drawPostEffect( + IPostEffectShader* p_effect, + BlendState blend, + ITexture2D* p_tex, SamplerState rtsv, + Vector4F const* cv, size_t cv_n, + ITexture2D* const* p_tex_arr, SamplerState const* sv, size_t tv_sv_n) + { + assert(p_effect); + assert((cv_n == 0) || (cv_n > 0 && cv)); + assert((tv_sv_n == 0) || (tv_sv_n > 0 && p_tex_arr && sv)); + + if (!endBatch()) return false; + + // PREPARE + + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + + win32::com_ptr p_d3d11_rtv; + win32::com_ptr p_d3d11_dsv; + + float sw_ = 0.0f; + float sh_ = 0.0f; + /* get current rendertarget size */ { + ID3D11RenderTargetView* rtv_ = NULL; + ID3D11DepthStencilView* dsv_ = NULL; + ctx->OMGetRenderTargets(1, &rtv_, &dsv_); + if (rtv_) + { + win32::com_ptr res_; + rtv_->GetResource(res_.put()); + win32::com_ptr tex2d_; + HRESULT hr = gHR = res_->QueryInterface(tex2d_.put()); + if (SUCCEEDED(hr)) + { + D3D11_TEXTURE2D_DESC desc_ = {}; + tex2d_->GetDesc(&desc_); + sw_ = (float)desc_.Width; + sh_ = (float)desc_.Height; + } + else + { + Logger::error("[core] [Renderer] postEffect failed: ID3D11Resource::QueryInterface -> #ID3D11Texture2D failed"); + return false; + } + p_d3d11_rtv = rtv_; + rtv_->Release(); + } + if (dsv_) + { + p_d3d11_dsv = dsv_; + dsv_->Release(); + } + } + if (sw_ < 1.0f || sh_ < 1.0f) + { + Logger::error("[core] [Renderer] postEffect failed: no RenderTarget bound"); + return false; + } + + ctx->ClearState(); + + // [Stage IA] + + /* upload vertex data */ { + DrawVertex* ptr{}; + if (!_fx_vbuffer->map(reinterpret_cast(&ptr), true)) { + Logger::error("[core] [Renderer] upload vertex buffer failed (map)"); + return false; + } + const DrawVertex vertex_data[4] = { + DrawVertex(0.f, sh_, 0.0f, 0.0f), + DrawVertex(sw_, sh_, 1.0f, 0.0f), + DrawVertex(sw_, 0.f, 1.0f, 1.0f), + DrawVertex(0.f, 0.f, 0.0f, 1.0f), + }; + std::memcpy(ptr, vertex_data, sizeof(vertex_data)); + if (!_fx_vbuffer->unmap()) { + Logger::error("[core] [Renderer] upload vertex buffer failed (unmap)"); + return false; + } + } + + ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D11Buffer* p_d3d11_vbos[1] = { static_cast(_fx_vbuffer->getNativeResource()) }; + UINT const stride = sizeof(DrawVertex); + UINT const offset = 0; + ctx->IASetVertexBuffers(0, 1, p_d3d11_vbos, &stride, &offset); + ctx->IASetIndexBuffer(static_cast(_fx_ibuffer->getNativeResource()), DXGI_FORMAT_R16_UINT, 0); + ctx->IASetInputLayout(_input_layout.get()); + + // [Stage VS] + + DirectX::XMFLOAT4X4 vp_matrix; + DirectX::XMStoreFloat4x4(&vp_matrix, DirectX::XMMatrixOrthographicOffCenterLH(0.0f, sw_, 0.0f, sh_, 0.0f, 1.0f)); + if (!_vp_matrix_buffer->update(&vp_matrix, sizeof(vp_matrix), true)) { + Logger::error("[core] [Renderer] upload constant buffer failed (vp_matrix_buffer)"); + } + ctx->VSSetShader(_vertex_shader[IDX(FogState::Disable)].get(), NULL, 0); + ID3D11Buffer* const view_projection_matrix = static_cast(_vp_matrix_buffer->getNativeResource()); + ctx->VSSetConstantBuffers(Direct3D11::Constants::vertex_shader_stage_constant_buffer_slot_view_projection_matrix, 1, &view_projection_matrix); + + // [Stage RS] + + ctx->RSSetState(_raster_state.get()); + D3D11_VIEWPORT viewport = { + .TopLeftX = 0.0f, + .TopLeftY = 0.0f, + .Width = sw_, + .Height = sh_, + .MinDepth = 0.0f, + .MaxDepth = 1.0f, + }; + ctx->RSSetViewports(1, &viewport); + D3D11_RECT scissor = { + .left = 0, + .top = 0, + .right = (LONG)sw_, + .bottom = (LONG)sh_, + }; + ctx->RSSetScissorRects(1, &scissor); + + // [Stage PS] + + const auto cv_sz = static_cast(std::min(cv_n, 8) * sizeof(Vector4F)); + if (!_user_float_buffer->update(cv, cv_sz, true)) { + Logger::error("[core] [Renderer] upload constant buffer failed (user_float_buffer)"); + } + const float size_viewport[8] = { + sw_, sh_, 0.0f, 0.0f, + _state_set.viewport.a.x, _state_set.viewport.a.y, _state_set.viewport.b.x, _state_set.viewport.b.y, + }; + if (!_fog_data_buffer->update(size_viewport, sizeof(size_viewport), true)) { + Logger::error("[core] [Renderer] upload constant buffer failed (fog_data_buffer/size_viewport_buffer)"); + } + ID3D11Buffer* const user_data = static_cast(_user_float_buffer->getNativeResource()); + ctx->PSSetConstantBuffers(Direct3D11::Constants::pixel_shader_stage_constant_buffer_slot_user_data, 1, &user_data); + ID3D11Buffer* const fog_parameter = static_cast(_fog_data_buffer->getNativeResource()); + ctx->PSSetConstantBuffers(Direct3D11::Constants::pixel_shader_stage_constant_buffer_slot_fog_parameter, 1, &fog_parameter); + + ctx->PSSetShader(static_cast(p_effect)->GetPS(), NULL, 0); + + ID3D11ShaderResourceView* p_srvs[5] = {}; + ID3D11SamplerState* p_samplers[5] = {}; + p_srvs[4] = get_view(p_tex); + p_samplers[4] = get_sampler(_sampler_state[IDX(rtsv)]); + for (DWORD stage = 0; stage < std::min((DWORD)tv_sv_n, 4); stage += 1) + { + p_srvs[stage] = get_view(p_tex_arr[stage]); + p_samplers[stage] = get_sampler(_sampler_state[IDX(sv[stage])]); + } + ctx->PSSetShaderResources(0, 5, p_srvs); + ctx->PSSetSamplers(0, 5, p_samplers); + + // [Stage OM] + + ctx->OMSetDepthStencilState(_depth_state[IDX(DepthState::Disable)].get(), D3D11_DEFAULT_STENCIL_REFERENCE); + FLOAT blend_factor[4] = {}; + ctx->OMSetBlendState(_blend_state[IDX(blend)].get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + ID3D11RenderTargetView* p_d3d11_rtvs[1] = { p_d3d11_rtv.get() }; + ctx->OMSetRenderTargets(1, p_d3d11_rtvs, p_d3d11_dsv.get()); + + // DRAW + + ctx->DrawIndexed(6, 0, 0); + + // CLEAR + + ctx->ClearState(); + ctx->OMSetRenderTargets(1, p_d3d11_rtvs, p_d3d11_dsv.get()); + + return beginBatch(); + } + bool Renderer_D3D11::drawPostEffect(IPostEffectShader* p_effect, BlendState blend) + { + assert(p_effect); + + if (!endBatch()) return false; + + // PREPARE + + auto* ctx = m_device->GetD3D11DeviceContext(); + assert(ctx); + + win32::com_ptr p_d3d11_rtv; + win32::com_ptr p_d3d11_dsv; + + float sw_ = 0.0f; + float sh_ = 0.0f; + /* get current rendertarget size */ { + ID3D11RenderTargetView* rtv_ = NULL; + ID3D11DepthStencilView* dsv_ = NULL; + ctx->OMGetRenderTargets(1, &rtv_, &dsv_); + if (rtv_) + { + win32::com_ptr res_; + rtv_->GetResource(res_.put()); + win32::com_ptr tex2d_; + HRESULT hr = gHR = res_->QueryInterface(tex2d_.put()); + if (SUCCEEDED(hr)) + { + D3D11_TEXTURE2D_DESC desc_ = {}; + tex2d_->GetDesc(&desc_); + sw_ = (float)desc_.Width; + sh_ = (float)desc_.Height; + } + else + { + Logger::error("[core] [Renderer] postEffect failed: ID3D11Resource::QueryInterface -> #ID3D11Texture2D failed"); + return false; + } + p_d3d11_rtv = rtv_; + rtv_->Release(); + } + if (dsv_) + { + p_d3d11_dsv = dsv_; + dsv_->Release(); + } + } + if (sw_ < 1.0f || sh_ < 1.0f) + { + Logger::error("[core] [Renderer] postEffect failed: no RenderTarget bound"); + return false; + } + + ctx->ClearState(); + + // [Stage IA] + + /* upload vertex data */ { + DrawVertex* ptr{}; + if (!_fx_vbuffer->map(reinterpret_cast(&ptr), true)) { + Logger::error("[core] [Renderer] upload vertex buffer failed (map)"); + return false; + } + const DrawVertex vertex_data[4] = { + DrawVertex(0.f, sh_, 0.0f, 0.0f), + DrawVertex(sw_, sh_, 1.0f, 0.0f), + DrawVertex(sw_, 0.f, 1.0f, 1.0f), + DrawVertex(0.f, 0.f, 0.0f, 1.0f), + }; + std::memcpy(ptr, vertex_data, sizeof(vertex_data)); + if (!_fx_vbuffer->unmap()) { + Logger::error("[core] [Renderer] upload vertex buffer failed (unmap)"); + return false; + } + } + + ctx->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + ID3D11Buffer* p_d3d11_vbos[1] = { static_cast(_fx_vbuffer->getNativeResource()) }; + UINT const stride = sizeof(DrawVertex); + UINT const offset = 0; + ctx->IASetVertexBuffers(0, 1, p_d3d11_vbos, &stride, &offset); + ctx->IASetIndexBuffer(static_cast(_fx_ibuffer->getNativeResource()), DXGI_FORMAT_R16_UINT, 0); + ctx->IASetInputLayout(_input_layout.get()); + + // [Stage VS] + + DirectX::XMFLOAT4X4 vp_matrix; + DirectX::XMStoreFloat4x4(&vp_matrix, DirectX::XMMatrixOrthographicOffCenterLH(0.0f, sw_, 0.0f, sh_, 0.0f, 1.0f)); + if (!_vp_matrix_buffer->update(&vp_matrix, sizeof(vp_matrix), true)) { + Logger::error("[core] [Renderer] upload constant buffer failed (vp_matrix_buffer)"); + } + ctx->VSSetShader(_vertex_shader[IDX(FogState::Disable)].get(), NULL, 0); + ID3D11Buffer* const view_projection_matrix = static_cast(_vp_matrix_buffer->getNativeResource()); + ctx->VSSetConstantBuffers(Direct3D11::Constants::vertex_shader_stage_constant_buffer_slot_view_projection_matrix, 1, &view_projection_matrix); + + // [Stage RS] + + ctx->RSSetState(_raster_state.get()); + D3D11_VIEWPORT viewport = { + .TopLeftX = 0.0f, + .TopLeftY = 0.0f, + .Width = sw_, + .Height = sh_, + .MinDepth = 0.0f, + .MaxDepth = 1.0f, + }; + ctx->RSSetViewports(1, &viewport); + D3D11_RECT scissor = { + .left = 0, + .top = 0, + .right = (LONG)sw_, + .bottom = (LONG)sh_, + }; + ctx->RSSetScissorRects(1, &scissor); + + // [Stage PS] + + if (!p_effect->apply(this)) + { + Logger::error("[core] [Renderer] PostEffectShader apply failed"); + return false; + } + ctx->PSSetShader(static_cast(p_effect)->GetPS(), NULL, 0); + + // [Stage OM] + + ctx->OMSetDepthStencilState(_depth_state[IDX(DepthState::Disable)].get(), D3D11_DEFAULT_STENCIL_REFERENCE); + FLOAT blend_factor[4] = {}; + ctx->OMSetBlendState(_blend_state[IDX(blend)].get(), blend_factor, D3D11_DEFAULT_SAMPLE_MASK); + ID3D11RenderTargetView* p_d3d11_rtvs[1] = { p_d3d11_rtv.get() }; + ctx->OMSetRenderTargets(1, p_d3d11_rtvs, p_d3d11_dsv.get()); + + // DRAW + + ctx->DrawIndexed(6, 0, 0); + + // CLEAR + + ctx->ClearState(); + ctx->OMSetRenderTargets(1, p_d3d11_rtvs, p_d3d11_dsv.get()); + + return beginBatch(); + } + + bool Renderer_D3D11::createModel(StringView path, IModel** pp_model) { + if (!m_model_shared) { + Logger::info("[core] [Model] creating shared resources..."); + try { + *(m_model_shared.put()) = new ModelSharedComponent_D3D11(m_device.get()); + Logger::info("[core] [Model] shared resources created"); + } + catch (...) { + Logger::error("[core] [Model] create shared resources failed"); + return false; + } + } + + try { + *pp_model = new Model_D3D11(m_device.get(), m_model_shared.get(), path); + return true; + } + catch (const std::exception&) { + *pp_model = nullptr; + Logger::error("[core] [Model] create failed"); + return false; + } + } + bool Renderer_D3D11::drawModel(IModel* p_model) + { + if (!p_model) + { + assert(false); + return false; + } + + if (!endBatch()) + { + return false; + } + + static_cast(p_model)->draw(_state_set.fog_state); + + if (!beginBatch()) + { + return false; + } + + return true; + } + + IGraphicsSampler* Renderer_D3D11::getKnownSamplerState(SamplerState state) + { + return _sampler_state[IDX(state)].get(); + } + + Renderer_D3D11::Renderer_D3D11(GraphicsDevice* p_device) + : m_device(p_device) + { + if (!createResources()) + throw std::runtime_error("Renderer_D3D11::Renderer_D3D11"); + m_device->addEventListener(this); + } + Renderer_D3D11::~Renderer_D3D11() + { + m_device->removeEventListener(this); + } + + bool Renderer_D3D11::create(GraphicsDevice* p_device, Renderer_D3D11** pp_renderer) + { + try + { + *pp_renderer = new Renderer_D3D11(p_device); + return true; + } + catch (...) + { + *pp_renderer = nullptr; + return false; + } + } + + bool IRenderer::create(IGraphicsDevice* p_device, IRenderer** pp_renderer) + { + try + { + *pp_renderer = new Renderer_D3D11(static_cast(p_device)); + return true; + } + catch (...) + { + *pp_renderer = nullptr; + return false; + } + } +} diff --git a/LuaSTG/Core/Graphics/Renderer_D3D11.hpp b/engine/graphics/core/Graphics/Renderer_D3D11.hpp similarity index 68% rename from LuaSTG/Core/Graphics/Renderer_D3D11.hpp rename to engine/graphics/core/Graphics/Renderer_D3D11.hpp index fd6f12bd..22581c46 100644 --- a/LuaSTG/Core/Graphics/Renderer_D3D11.hpp +++ b/engine/graphics/core/Graphics/Renderer_D3D11.hpp @@ -1,258 +1,253 @@ -#pragma once -#include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/Renderer.hpp" -#include "Core/Graphics/Direct3D11/Texture2D.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "Core/Graphics/Model_D3D11.hpp" - -#define IDX(x) (size_t)static_cast(x) - -namespace core::Graphics -{ - struct RendererStateSet - { - BoxF viewport = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; - RectF scissor_rect = { 0.0f, 0.0f, 1.0f, 1.0f }; - float fog_near_or_density = 0.0f; - float fog_far = 0.0f; - Color4B fog_color; - IRenderer::VertexColorBlendState vertex_color_blend_state = IRenderer::VertexColorBlendState::Mul; - IRenderer::SamplerState sampler_state = IRenderer::SamplerState::LinearClamp; - IRenderer::FogState fog_state = IRenderer::FogState::Disable; - IRenderer::TextureAlphaType texture_alpha_type = IRenderer::TextureAlphaType::Normal; - IRenderer::DepthState depth_state = IRenderer::DepthState::Disable; - IRenderer::BlendState blend_state = IRenderer::BlendState::Alpha; - }; - - struct CameraStateSet - { - BoxF ortho = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; - Vector3F eye = { 0.0f, 0.0f, 0.0f }; - Vector3F lookat = { 0.0f, 0.0f, 1.0f }; - Vector3F headup = { 0.0f, 1.0f, 0.0f }; - float fov = 0.0f; - float aspect = 0.0f; - float znear = 0.0f; - float zfar = 0.0f; - bool is_3D = false; - - bool isEqual(BoxF const& box) - { - return !is_3D && ortho == box; - } - bool isEqual(Vector3F const& eye_, Vector3F const& lookat_, Vector3F const& headup_, float fov_, float aspect_, float znear_, float zfar_) - { - return is_3D - && eye == eye_ - && lookat == lookat_ - && headup == headup_ - && fov == fov_ - && aspect == aspect_ - && znear == znear_ - && zfar == zfar_; - } - }; - - struct VertexIndexBuffer - { - Microsoft::WRL::ComPtr vertex_buffer; - Microsoft::WRL::ComPtr index_buffer; - INT vertex_offset = 0; - UINT index_offset = 0; - }; - - struct DrawCommand - { - SmartReference texture; - uint16_t vertex_count = 0; - uint16_t index_count = 0; - }; - - struct DrawList - { - struct VertexBuffer - { - const size_t capacity = 32768; - size_t size = 0; - IRenderer::DrawVertex data[32768] = {}; - } vertex; - struct IndexBuffer - { - const size_t capacity = 32768; - size_t size = 0; - IRenderer::DrawIndex data[32768] = {}; - } index; - struct DrawCommandBuffer - { - const size_t capacity = 2048; - size_t size = 0; - DrawCommand data[2048] = {}; - } command; - }; - - class PostEffectShader_D3D11 - : public implement::ReferenceCounted - , IDeviceEventListener - { - private: - struct LocalVariable - { - UINT offset{}; - UINT size{}; - }; - struct LocalConstantBuffer - { - UINT index{}; - std::vector buffer; - Microsoft::WRL::ComPtr d3d11_buffer; - std::unordered_map variable; - }; - struct LocalTexture2D - { - UINT index{}; - SmartReference texture; - }; - private: - SmartReference m_device; - Microsoft::WRL::ComPtr d3d_ps_blob; - Microsoft::WRL::ComPtr d3d11_ps_reflect; - Microsoft::WRL::ComPtr d3d11_ps; - std::unordered_map m_buffer_map; - std::unordered_map m_texture2d_map; - std::string source; - bool is_path{ false }; - - bool createResources(); - void onDeviceCreate(); - void onDeviceDestroy(); - bool findVariable(StringView name, LocalConstantBuffer*& buf, LocalVariable*& val); - - public: - ID3D11PixelShader* GetPS() const noexcept { return d3d11_ps.Get(); } - - public: - bool setFloat(StringView name, float value); - bool setFloat2(StringView name, Vector2F value); - bool setFloat3(StringView name, Vector3F value); - bool setFloat4(StringView name, Vector4F value); - bool setTexture2D(StringView name, ITexture2D* p_texture); - bool apply(IRenderer* p_renderer); - - public: - PostEffectShader_D3D11(Direct3D11::Device* p_device, StringView path, bool is_path_); - ~PostEffectShader_D3D11(); - }; - - class Renderer_D3D11 - : public implement::ReferenceCounted - , IDeviceEventListener - { - private: - SmartReference m_device; - SmartReference m_model_shared; - - Microsoft::WRL::ComPtr _fx_vbuffer; - Microsoft::WRL::ComPtr _fx_ibuffer; - VertexIndexBuffer _vi_buffer[1]; - size_t _vi_buffer_index = 0; - const size_t _vi_buffer_count = 1; - DrawList _draw_list; - - void setVertexIndexBuffer(size_t index = 0xFFFFFFFFu); - bool uploadVertexIndexBuffer(bool discard); - void clearDrawList(); - - Microsoft::WRL::ComPtr _vp_matrix_buffer; - Microsoft::WRL::ComPtr _world_matrix_buffer; - Microsoft::WRL::ComPtr _camera_pos_buffer; // 在 postEffect 的时候被替换了 - Microsoft::WRL::ComPtr _fog_data_buffer; // 同时也用于储存 postEffect 的 纹理大小和视口范围 - Microsoft::WRL::ComPtr _user_float_buffer; // 在 postEffect 的时候用这个 - - Microsoft::WRL::ComPtr _input_layout; - Microsoft::WRL::ComPtr _vertex_shader[IDX(FogState::MAX_COUNT)]; // FogState - Microsoft::WRL::ComPtr _pixel_shader[IDX(VertexColorBlendState::MAX_COUNT)][IDX(FogState::MAX_COUNT)][IDX(TextureAlphaType::MAX_COUNT)]; // VertexColorBlendState, FogState, TextureAlphaType - Microsoft::WRL::ComPtr _raster_state; - SmartReference _sampler_state[IDX(SamplerState::MAX_COUNT)]; - Microsoft::WRL::ComPtr _depth_state[IDX(DepthState::MAX_COUNT)]; - Microsoft::WRL::ComPtr _blend_state[IDX(BlendState::MAX_COUNT)]; - - SmartReference _state_texture; - CameraStateSet _camera_state_set; - RendererStateSet _state_set; - bool _state_dirty = false; - bool _batch_scope = false; - - bool createBuffers(); - bool createStates(); - bool createShaders(); - void initState(); - void setSamplerState(SamplerState state, UINT index); - bool uploadVertexIndexBufferFromDrawList(); - bool batchFlush(bool discard = false); - - bool createResources(); - void onDeviceCreate(); - void onDeviceDestroy(); - - public: - // public to MeshRenderer - [[nodiscard]] bool isFogEnabled() const noexcept { return _state_set.fog_state != FogState::Disable; } - // public to MeshRenderer - void bindTextureSamplerState(ITexture2D* texture); - // public to MeshRenderer - void bindTextureAlphaType(ITexture2D* texture); - - bool beginBatch(); - bool endBatch(); - bool isBatchScope() { return _batch_scope; } - bool flush(); - - void clearRenderTarget(Color4B const& color); - void clearDepthBuffer(float zvalue); - void setRenderAttachment(IRenderTarget* p_rt, IDepthStencilBuffer* p_ds); - - void setOrtho(BoxF const& box); - void setPerspective(Vector3F const& eye, Vector3F const& lookat, Vector3F const& headup, float fov, float aspect, float znear, float zfar); - - inline BoxF getViewport() { return _state_set.viewport; } - void setViewport(BoxF const& box); - void setScissorRect(RectF const& rect); - void setViewportAndScissorRect(); - - void setVertexColorBlendState(VertexColorBlendState state); - void setFogState(FogState state, Color4B const& color, float density_or_znear, float zfar); - void setDepthState(DepthState state); - void setBlendState(BlendState state); - void setTexture(ITexture2D* texture); - - bool drawTriangle(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3); - bool drawTriangle(DrawVertex const* pvert); - bool drawQuad(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3, DrawVertex const& v4); - bool drawQuad(DrawVertex const* pvert); - bool drawRaw(DrawVertex const* pvert, uint16_t nvert, DrawIndex const* pidx, uint16_t nidx); - bool drawRequest(uint16_t nvert, uint16_t nidx, DrawVertex** ppvert, DrawIndex** ppidx, uint16_t* idxoffset); - - bool createPostEffectShader(StringView path, IPostEffectShader** pp_effect); - bool drawPostEffect( - IPostEffectShader* p_effect, - BlendState blend, - ITexture2D* p_tex, SamplerState rtsv, - Vector4F const* cv, size_t cv_n, - ITexture2D* const* p_tex_arr, SamplerState const* sv, size_t tv_sv_n); - bool drawPostEffect(IPostEffectShader* p_effect, BlendState blend); - - bool createModel(StringView path, IModel** pp_model); - bool drawModel(IModel* p_model); - - ISamplerState* getKnownSamplerState(SamplerState state); - - public: - Renderer_D3D11(Direct3D11::Device* p_device); - ~Renderer_D3D11(); - - public: - static bool create(Direct3D11::Device* p_device, Renderer_D3D11** pp_renderer); - }; -} - -#undef IDX +#pragma once +#include "core/implement/ReferenceCounted.hpp" +#include "core/Graphics/Renderer.hpp" +#include "core/Graphics/Direct3D11/Texture2D.hpp" +#include "d3d11/GraphicsDevice.hpp" +#include "core/Graphics/Model_D3D11.hpp" + +#define IDX(x) (size_t)static_cast(x) + +namespace core::Graphics +{ + struct RendererStateSet + { + BoxF viewport = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; + RectF scissor_rect = { 0.0f, 0.0f, 1.0f, 1.0f }; + float fog_near_or_density = 0.0f; + float fog_far = 0.0f; + Color4B fog_color; + IRenderer::VertexColorBlendState vertex_color_blend_state = IRenderer::VertexColorBlendState::Mul; + IRenderer::SamplerState sampler_state = IRenderer::SamplerState::LinearClamp; + IRenderer::FogState fog_state = IRenderer::FogState::Disable; + IRenderer::TextureAlphaType texture_alpha_type = IRenderer::TextureAlphaType::Normal; + IRenderer::DepthState depth_state = IRenderer::DepthState::Disable; + IRenderer::BlendState blend_state = IRenderer::BlendState::Alpha; + }; + + struct CameraStateSet + { + BoxF ortho = { 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f }; + Vector3F eye = { 0.0f, 0.0f, 0.0f }; + Vector3F lookat = { 0.0f, 0.0f, 1.0f }; + Vector3F headup = { 0.0f, 1.0f, 0.0f }; + float fov = 0.0f; + float aspect = 0.0f; + float znear = 0.0f; + float zfar = 0.0f; + bool is_3D = false; + + bool isEqual(BoxF const& box) + { + return !is_3D && ortho == box; + } + bool isEqual(Vector3F const& eye_, Vector3F const& lookat_, Vector3F const& headup_, float fov_, float aspect_, float znear_, float zfar_) + { + return is_3D + && eye == eye_ + && lookat == lookat_ + && headup == headup_ + && fov == fov_ + && aspect == aspect_ + && znear == znear_ + && zfar == zfar_; + } + }; + + struct VertexIndexBuffer { + SmartReference vertex_buffer; + SmartReference index_buffer; + INT vertex_offset = 0; + UINT index_offset = 0; + }; + + struct DrawCommand + { + SmartReference texture; + uint16_t vertex_count = 0; + uint16_t index_count = 0; + }; + + struct DrawList { + struct VertexBuffer { + const size_t capacity = 32768; + size_t size = 0; + IRenderer::DrawVertex data[32768] = {}; + } vertex; + struct IndexBuffer { + const size_t capacity = 32768; + size_t size = 0; + IRenderer::DrawIndex data[32768] = {}; + } index; + struct DrawCommandBuffer { + const size_t capacity = 2048; + size_t size = 0; + DrawCommand data[2048] = {}; + } command; + }; + + class PostEffectShader_D3D11 + : public implement::ReferenceCounted + , IGraphicsDeviceEventListener + { + private: + struct LocalVariable + { + UINT offset{}; + UINT size{}; + }; + struct LocalConstantBuffer + { + UINT index{}; + std::vector buffer; + win32::com_ptr d3d11_buffer; + std::unordered_map variable; + }; + struct LocalTexture2D + { + UINT index{}; + SmartReference texture; + }; + private: + SmartReference m_device; + win32::com_ptr d3d_ps_blob; + win32::com_ptr d3d11_ps_reflect; + win32::com_ptr d3d11_ps; + std::unordered_map m_buffer_map; + std::unordered_map m_texture2d_map; + std::string source; + bool is_path{ false }; + + bool createResources(); + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; + bool findVariable(StringView name, LocalConstantBuffer*& buf, LocalVariable*& val); + + public: + ID3D11PixelShader* GetPS() const noexcept { return d3d11_ps.get(); } + + public: + bool setFloat(StringView name, float value); + bool setFloat2(StringView name, Vector2F value); + bool setFloat3(StringView name, Vector3F value); + bool setFloat4(StringView name, Vector4F value); + bool setTexture2D(StringView name, ITexture2D* p_texture); + bool apply(IRenderer* p_renderer); + + public: + PostEffectShader_D3D11(GraphicsDevice* p_device, StringView path, bool is_path_); + ~PostEffectShader_D3D11(); + }; + + class Renderer_D3D11 + : public implement::ReferenceCounted + , IGraphicsDeviceEventListener + { + private: + SmartReference m_device; + SmartReference m_model_shared; + + SmartReference _fx_vbuffer; + SmartReference _fx_ibuffer; + std::array _vi_buffer; + size_t _vi_buffer_index = 0; + const size_t _vi_buffer_count = 1; + DrawList _draw_list; + + void setVertexIndexBuffer(size_t index = 0xFFFFFFFFu); + bool uploadVertexIndexBuffer(bool discard); + void clearDrawList(); + + SmartReference _vp_matrix_buffer; + SmartReference _world_matrix_buffer; + SmartReference _camera_pos_buffer; // 在 postEffect 的时候被替换了 + SmartReference _fog_data_buffer; // 同时也用于储存 postEffect 的 纹理大小和视口范围 + SmartReference _user_float_buffer; // 在 postEffect 的时候用这个 + + win32::com_ptr _input_layout; + win32::com_ptr _vertex_shader[IDX(FogState::MAX_COUNT)]; // FogState + win32::com_ptr _pixel_shader[IDX(VertexColorBlendState::MAX_COUNT)][IDX(FogState::MAX_COUNT)][IDX(TextureAlphaType::MAX_COUNT)]; // VertexColorBlendState, FogState, TextureAlphaType + win32::com_ptr _raster_state; + SmartReference _sampler_state[IDX(SamplerState::MAX_COUNT)]; + win32::com_ptr _depth_state[IDX(DepthState::MAX_COUNT)]; + win32::com_ptr _blend_state[IDX(BlendState::MAX_COUNT)]; + + SmartReference _state_texture; + CameraStateSet _camera_state_set; + RendererStateSet _state_set; + bool _state_dirty = false; + bool _batch_scope = false; + + bool createBuffers(); + bool createStates(bool is_recreating = false); + bool createShaders(); + void initState(); + void setSamplerState(SamplerState state, UINT index); + bool uploadVertexIndexBufferFromDrawList(); + bool batchFlush(bool discard = false); + + bool createResources(bool is_recreating = false); + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; + + public: + // public to MeshRenderer + [[nodiscard]] bool isFogEnabled() const noexcept { return _state_set.fog_state != FogState::Disable; } + // public to MeshRenderer + void bindTextureSamplerState(ITexture2D* texture); + // public to MeshRenderer + void bindTextureAlphaType(ITexture2D* texture); + + bool beginBatch(); + bool endBatch(); + bool isBatchScope() { return _batch_scope; } + bool flush(); + + void clearRenderTarget(Color4B const& color); + void clearDepthBuffer(float zvalue); + void setRenderAttachment(IRenderTarget* p_rt, IDepthStencilBuffer* p_ds); + + void setOrtho(BoxF const& box); + void setPerspective(Vector3F const& eye, Vector3F const& lookat, Vector3F const& headup, float fov, float aspect, float znear, float zfar); + + inline BoxF getViewport() { return _state_set.viewport; } + void setViewport(BoxF const& box); + void setScissorRect(RectF const& rect); + void setViewportAndScissorRect(); + + void setVertexColorBlendState(VertexColorBlendState state); + void setFogState(FogState state, Color4B const& color, float density_or_znear, float zfar); + void setDepthState(DepthState state); + void setBlendState(BlendState state); + void setTexture(ITexture2D* texture); + + bool drawTriangle(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3); + bool drawTriangle(DrawVertex const* pvert); + bool drawQuad(DrawVertex const& v1, DrawVertex const& v2, DrawVertex const& v3, DrawVertex const& v4); + bool drawQuad(DrawVertex const* pvert); + bool drawRaw(DrawVertex const* pvert, uint16_t nvert, DrawIndex const* pidx, uint16_t nidx); + bool drawRequest(uint16_t nvert, uint16_t nidx, DrawVertex** ppvert, DrawIndex** ppidx, uint16_t* idxoffset); + + bool createPostEffectShader(StringView path, IPostEffectShader** pp_effect); + bool drawPostEffect( + IPostEffectShader* p_effect, + BlendState blend, + ITexture2D* p_tex, SamplerState rtsv, + Vector4F const* cv, size_t cv_n, + ITexture2D* const* p_tex_arr, SamplerState const* sv, size_t tv_sv_n); + bool drawPostEffect(IPostEffectShader* p_effect, BlendState blend); + + bool createModel(StringView path, IModel** pp_model); + bool drawModel(IModel* p_model); + + IGraphicsSampler* getKnownSamplerState(SamplerState state); + + public: + Renderer_D3D11(GraphicsDevice* p_device); + ~Renderer_D3D11(); + + public: + static bool create(GraphicsDevice* p_device, Renderer_D3D11** pp_renderer); + }; +} + +#undef IDX diff --git a/LuaSTG/Core/Graphics/Renderer_Shader_D3D11.cpp b/engine/graphics/core/Graphics/Renderer_Shader_D3D11.cpp similarity index 62% rename from LuaSTG/Core/Graphics/Renderer_Shader_D3D11.cpp rename to engine/graphics/core/Graphics/Renderer_Shader_D3D11.cpp index 85161251..a2047848 100644 --- a/LuaSTG/Core/Graphics/Renderer_Shader_D3D11.cpp +++ b/engine/graphics/core/Graphics/Renderer_Shader_D3D11.cpp @@ -1,341 +1,334 @@ -#include "Core/Graphics/Renderer_D3D11.hpp" -#include "core/FileSystem.hpp" -#include "Platform/RuntimeLoader/Direct3DCompiler.hpp" - -#include "luastg/sub/renderer/vertex_shader_def_none.hpp" -#include "luastg/sub/renderer/vertex_shader_def_fog.hpp" - -#include "luastg/sub/renderer/pixel_shader_def_zero_none_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_one_none_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_add_none_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_mul_none_normal.hpp" - -#include "luastg/sub/renderer/pixel_shader_def_zero_linear_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_one_linear_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_add_linear_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_mul_linear_normal.hpp" - -#include "luastg/sub/renderer/pixel_shader_def_zero_exp_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_one_exp_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_add_exp_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_mul_exp_normal.hpp" - -#include "luastg/sub/renderer/pixel_shader_def_zero_exp2_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_one_exp2_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_add_exp2_normal.hpp" -#include "luastg/sub/renderer/pixel_shader_def_mul_exp2_normal.hpp" - -#include "luastg/sub/renderer/pixel_shader_def_zero_none_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_one_none_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_add_none_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_mul_none_premul.hpp" - -#include "luastg/sub/renderer/pixel_shader_def_zero_linear_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_one_linear_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_add_linear_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_mul_linear_premul.hpp" - -#include "luastg/sub/renderer/pixel_shader_def_zero_exp_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_one_exp_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_add_exp_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_mul_exp_premul.hpp" - -#include "luastg/sub/renderer/pixel_shader_def_zero_exp2_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_one_exp2_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_add_exp2_premul.hpp" -#include "luastg/sub/renderer/pixel_shader_def_mul_exp2_premul.hpp" - -#define IDX(x) (size_t)static_cast(x) - -class D3DIncludeImpl : public ID3DInclude -{ -public: - COM_DECLSPEC_NOTHROW HRESULT WINAPI Open(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes) - { - UNREFERENCED_PARAMETER(IncludeType); // 我们不关心它是从哪里包含的 - UNREFERENCED_PARAMETER(pParentData); - core::SmartReference data; - if (!core::FileSystemManager::readFile(pFileName, data.put())) - { - return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); - } - void* buffer = malloc(data->size()); - if (!buffer) return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); - // TODO: no copy x2 - memcpy(buffer, data->data(), data->size()); - *ppData = buffer; - *pBytes = static_cast(data->size()); - return S_OK; - } - COM_DECLSPEC_NOTHROW HRESULT WINAPI Close(LPCVOID pData) - { - assert(pData); - free(const_cast(pData)); - return S_OK; - } -}; - -static D3DIncludeImpl g_include_loader; -static Platform::RuntimeLoader::Direct3DCompiler g_d3dcompiler_loader; - -namespace core::Graphics -{ - static bool compileShaderMacro(char const* name, void const* data, size_t size, char const* target, const D3D_SHADER_MACRO* defs, ID3DBlob** ppBlob) - { - UINT flag_ = D3DCOMPILE_ENABLE_STRICTNESS; - #ifdef _DEBUG - flag_ |= D3DCOMPILE_DEBUG; - flag_ |= D3DCOMPILE_SKIP_OPTIMIZATION; - #endif - Microsoft::WRL::ComPtr errmsg_; - HRESULT hr = gHR = g_d3dcompiler_loader.Compile(data, size, name, defs, &g_include_loader, "main", target, flag_, 0, ppBlob, &errmsg_); - if (FAILED(hr)) - { - spdlog::error("[core] D3DCompile 调用失败"); - spdlog::error("[core] 编译着色器 '{}' 失败:{}", name, (char*)errmsg_->GetBufferPointer()); - return false; - } - return true; - } - static bool compileVertexShaderMacro11(char const* name, void const* data, size_t size, const D3D_SHADER_MACRO* defs, ID3DBlob** ppBlob) - { - return compileShaderMacro(name, data, size, "vs_4_0", defs, ppBlob); - } - static bool compilePixelShaderMacro11(char const* name, void const* data, size_t size, const D3D_SHADER_MACRO* defs, ID3DBlob** ppBlob) - { - return compileShaderMacro(name, data, size, "ps_4_0", defs, ppBlob); - } - - bool PostEffectShader_D3D11::createResources() - { - if (!d3d_ps_blob) - { - if (is_path) - { - SmartReference src; - if (!FileSystemManager::readFile(source, src.put())) - return false; - if (!compilePixelShaderMacro11(source.c_str(), src->data(), src->size(), nullptr, &d3d_ps_blob)) - return false; - } - else - { - if (!compilePixelShaderMacro11(source.c_str(), source.data(), source.size(), nullptr, &d3d_ps_blob)) - return false; - } - } - assert(m_device->GetD3D11Device()); - HRESULT hr = gHR = m_device->GetD3D11Device()->CreatePixelShader(d3d_ps_blob->GetBufferPointer(), d3d_ps_blob->GetBufferSize(), nullptr, &d3d11_ps); - if (FAILED(hr)) - return false; - M_D3D_SET_DEBUG_NAME_SIMPLE(d3d11_ps.Get()); - - // 着色器反射 - - if (!d3d11_ps_reflect) - { - hr = gHR = g_d3dcompiler_loader.Reflect(d3d_ps_blob->GetBufferPointer(), d3d_ps_blob->GetBufferSize(), IID_PPV_ARGS(&d3d11_ps_reflect)); - if (FAILED(hr)) return false; - - // 获得着色器信息 - - D3D11_SHADER_DESC shader_info{}; - hr = gHR = d3d11_ps_reflect->GetDesc(&shader_info); - if (FAILED(hr)) return false; - - // 常量缓冲区 - - m_buffer_map.reserve(shader_info.ConstantBuffers); - for (UINT i = 0; i < shader_info.ConstantBuffers; i += 1) - { - auto* constant_buffer = d3d11_ps_reflect->GetConstantBufferByIndex(i); - - D3D11_SHADER_BUFFER_DESC constant_buffer_info{}; - hr = gHR = constant_buffer->GetDesc(&constant_buffer_info); - if (FAILED(hr)) return false; - - D3D11_SHADER_INPUT_BIND_DESC bind_info{}; - hr = gHR = d3d11_ps_reflect->GetResourceBindingDescByName(constant_buffer_info.Name, &bind_info); - if (FAILED(hr)) return false; - - LocalConstantBuffer local_buffer; - local_buffer.index = bind_info.BindPoint; - local_buffer.buffer.resize(constant_buffer_info.Size); - local_buffer.variable.reserve(constant_buffer_info.Variables); - - for (UINT j = 0; j < constant_buffer_info.Variables; j += 1) - { - auto* variable = constant_buffer->GetVariableByIndex(j); - - D3D11_SHADER_VARIABLE_DESC variable_info{}; - hr = gHR = variable->GetDesc(&variable_info); - if (FAILED(hr)) return false; - - auto* variable_type = variable->GetType(); - - D3D11_SHADER_TYPE_DESC variable_type_info{}; - hr = gHR = variable_type->GetDesc(&variable_type_info); - if (FAILED(hr)) return false; - - LocalVariable local_variable; - local_variable.offset = variable_info.StartOffset; - local_variable.size = variable_info.Size; - - local_buffer.variable.emplace(variable_info.Name, std::move(local_variable)); - } - - m_buffer_map.emplace(constant_buffer_info.Name, std::move(local_buffer)); - } - - // 纹理 - - m_texture2d_map.reserve(shader_info.BoundResources - shader_info.ConstantBuffers); - for (UINT i = 0; i < shader_info.BoundResources; i += 1) - { - D3D11_SHADER_INPUT_BIND_DESC bind_info{}; - hr = gHR = d3d11_ps_reflect->GetResourceBindingDesc(i, &bind_info); - if (FAILED(hr)) return false; - - if (!(bind_info.Type == D3D_SIT_TEXTURE && bind_info.Dimension == D3D_SRV_DIMENSION_TEXTURE2D)) - { - continue; // 并非所需 - } - - LocalTexture2D local_texture2d; - local_texture2d.index = bind_info.BindPoint; - - m_texture2d_map.emplace(bind_info.Name, std::move(local_texture2d)); - } - } - - // 创建缓冲区 - - for (auto& v : m_buffer_map) - { - D3D11_BUFFER_DESC desc_ = { - .ByteWidth = static_cast(v.second.buffer.size()), - .Usage = D3D11_USAGE_DYNAMIC, - .BindFlags = D3D11_BIND_CONSTANT_BUFFER, - .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE, - .MiscFlags = 0, - .StructureByteStride = 0, - }; - hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, NULL, &v.second.d3d11_buffer); - if (FAILED(hr)) - return false; - } - - return true; - } - - bool Renderer_D3D11::createShaders() - { - assert(m_device->GetD3D11Device()); - - HRESULT hr = 0; - - // vertex shader - { - auto load_ = [&](FogState f, void const* data, size_t size) - { - hr = gHR = m_device->GetD3D11Device()->CreateVertexShader( - data, - size, - NULL, - & _vertex_shader[IDX(f)]); - }; - - #define load(f, name)\ - load_(f, luastg::sub::renderer::vertex_shader_##name, sizeof(luastg::sub::renderer::vertex_shader_##name));\ - if (FAILED(hr)) return false;\ - M_D3D_SET_DEBUG_NAME_SIMPLE(_vertex_shader[IDX(f)].Get()); - - load(FogState::Disable, def_none); - load(FogState::Linear, def_fog); - load(FogState::Exp, def_fog); - load(FogState::Exp2, def_fog); - - #undef load - } - - // input layout - { - D3D11_INPUT_ELEMENT_DESC layout_[] = - { - // DrawVertex2D - { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0 , D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "COLOR", 0, DXGI_FORMAT_B8G8R8A8_UNORM , 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT , 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 }, - }; - hr = gHR = m_device->GetD3D11Device()->CreateInputLayout( - layout_, 3, - luastg::sub::renderer::vertex_shader_def_none, - sizeof(luastg::sub::renderer::vertex_shader_def_none), - &_input_layout); - if (FAILED(hr)) - return false; - } - - // pixel shader - { - auto load_ = [&](VertexColorBlendState v, FogState f, TextureAlphaType t, void const* data, size_t size) - { - hr = gHR = m_device->GetD3D11Device()->CreatePixelShader( - data, - size, - NULL, - &_pixel_shader[IDX(v)][IDX(f)][IDX(t)] - ); - }; - - #define load(v, f, t, name)\ - load_(v, f, t, luastg::sub::renderer::pixel_shader_##name, sizeof(luastg::sub::renderer::pixel_shader_##name));\ - if (FAILED(hr)) return false;\ - M_D3D_SET_DEBUG_NAME_SIMPLE(_pixel_shader[IDX(v)][IDX(f)][IDX(t)].Get()); - - load(VertexColorBlendState::Zero, FogState::Disable, TextureAlphaType::Normal, def_zero_none_normal); - load(VertexColorBlendState::One, FogState::Disable, TextureAlphaType::Normal, def_one_none_normal); - load(VertexColorBlendState::Add, FogState::Disable, TextureAlphaType::Normal, def_add_none_normal); - load(VertexColorBlendState::Mul, FogState::Disable, TextureAlphaType::Normal, def_mul_none_normal); - - load(VertexColorBlendState::Zero, FogState::Linear, TextureAlphaType::Normal, def_zero_linear_normal); - load(VertexColorBlendState::One, FogState::Linear, TextureAlphaType::Normal, def_one_linear_normal); - load(VertexColorBlendState::Add, FogState::Linear, TextureAlphaType::Normal, def_add_linear_normal); - load(VertexColorBlendState::Mul, FogState::Linear, TextureAlphaType::Normal, def_mul_linear_normal); - - load(VertexColorBlendState::Zero, FogState::Exp, TextureAlphaType::Normal, def_zero_exp_normal); - load(VertexColorBlendState::One, FogState::Exp, TextureAlphaType::Normal, def_one_exp_normal); - load(VertexColorBlendState::Add, FogState::Exp, TextureAlphaType::Normal, def_add_exp_normal); - load(VertexColorBlendState::Mul, FogState::Exp, TextureAlphaType::Normal, def_mul_exp_normal); - - load(VertexColorBlendState::Zero, FogState::Exp2, TextureAlphaType::Normal, def_zero_exp2_normal); - load(VertexColorBlendState::One, FogState::Exp2, TextureAlphaType::Normal, def_one_exp2_normal); - load(VertexColorBlendState::Add, FogState::Exp2, TextureAlphaType::Normal, def_add_exp2_normal); - load(VertexColorBlendState::Mul, FogState::Exp2, TextureAlphaType::Normal, def_mul_exp2_normal); - - load(VertexColorBlendState::Zero, FogState::Disable, TextureAlphaType::PremulAlpha, def_zero_none_premul); - load(VertexColorBlendState::One, FogState::Disable, TextureAlphaType::PremulAlpha, def_one_none_premul); - load(VertexColorBlendState::Add, FogState::Disable, TextureAlphaType::PremulAlpha, def_add_none_premul); - load(VertexColorBlendState::Mul, FogState::Disable, TextureAlphaType::PremulAlpha, def_mul_none_premul); - - load(VertexColorBlendState::Zero, FogState::Linear, TextureAlphaType::PremulAlpha, def_zero_linear_premul); - load(VertexColorBlendState::One, FogState::Linear, TextureAlphaType::PremulAlpha, def_one_linear_premul); - load(VertexColorBlendState::Add, FogState::Linear, TextureAlphaType::PremulAlpha, def_add_linear_premul); - load(VertexColorBlendState::Mul, FogState::Linear, TextureAlphaType::PremulAlpha, def_mul_linear_premul); - - load(VertexColorBlendState::Zero, FogState::Exp, TextureAlphaType::PremulAlpha, def_zero_exp_premul); - load(VertexColorBlendState::One, FogState::Exp, TextureAlphaType::PremulAlpha, def_one_exp_premul); - load(VertexColorBlendState::Add, FogState::Exp, TextureAlphaType::PremulAlpha, def_add_exp_premul); - load(VertexColorBlendState::Mul, FogState::Exp, TextureAlphaType::PremulAlpha, def_mul_exp_premul); - - load(VertexColorBlendState::Zero, FogState::Exp2, TextureAlphaType::PremulAlpha, def_zero_exp2_premul); - load(VertexColorBlendState::One, FogState::Exp2, TextureAlphaType::PremulAlpha, def_one_exp2_premul); - load(VertexColorBlendState::Add, FogState::Exp2, TextureAlphaType::PremulAlpha, def_add_exp2_premul); - load(VertexColorBlendState::Mul, FogState::Exp2, TextureAlphaType::PremulAlpha, def_mul_exp2_premul); - - #undef load - } - - return true; - } -} +#include "core/Graphics/Renderer_D3D11.hpp" +#include "core/Logger.hpp" +#include "core/FileSystem.hpp" +#include "windows/RuntimeLoader/Direct3DCompiler.hpp" + +#include "d3d11/shader/renderer/vertex_shader_fog.h" +#include "d3d11/shader/renderer/vertex_shader_normal.h" + +#include "d3d11/shader/renderer/pixel_shader_add_exp2_premul.h" +#include "d3d11/shader/renderer/pixel_shader_add_exp2_straight.h" +#include "d3d11/shader/renderer/pixel_shader_add_exp_premul.h" +#include "d3d11/shader/renderer/pixel_shader_add_exp_straight.h" +#include "d3d11/shader/renderer/pixel_shader_add_linear_premul.h" +#include "d3d11/shader/renderer/pixel_shader_add_linear_straight.h" +#include "d3d11/shader/renderer/pixel_shader_add_none_premul.h" +#include "d3d11/shader/renderer/pixel_shader_add_none_straight.h" +#include "d3d11/shader/renderer/pixel_shader_mul_exp2_premul.h" +#include "d3d11/shader/renderer/pixel_shader_mul_exp2_straight.h" +#include "d3d11/shader/renderer/pixel_shader_mul_exp_premul.h" +#include "d3d11/shader/renderer/pixel_shader_mul_exp_straight.h" +#include "d3d11/shader/renderer/pixel_shader_mul_linear_premul.h" +#include "d3d11/shader/renderer/pixel_shader_mul_linear_straight.h" +#include "d3d11/shader/renderer/pixel_shader_mul_none_premul.h" +#include "d3d11/shader/renderer/pixel_shader_mul_none_straight.h" +#include "d3d11/shader/renderer/pixel_shader_one_exp2_premul.h" +#include "d3d11/shader/renderer/pixel_shader_one_exp2_straight.h" +#include "d3d11/shader/renderer/pixel_shader_one_exp_premul.h" +#include "d3d11/shader/renderer/pixel_shader_one_exp_straight.h" +#include "d3d11/shader/renderer/pixel_shader_one_linear_premul.h" +#include "d3d11/shader/renderer/pixel_shader_one_linear_straight.h" +#include "d3d11/shader/renderer/pixel_shader_one_none_premul.h" +#include "d3d11/shader/renderer/pixel_shader_one_none_straight.h" +#include "d3d11/shader/renderer/pixel_shader_zero_exp2_premul.h" +#include "d3d11/shader/renderer/pixel_shader_zero_exp2_straight.h" +#include "d3d11/shader/renderer/pixel_shader_zero_exp_premul.h" +#include "d3d11/shader/renderer/pixel_shader_zero_exp_straight.h" +#include "d3d11/shader/renderer/pixel_shader_zero_linear_premul.h" +#include "d3d11/shader/renderer/pixel_shader_zero_linear_straight.h" +#include "d3d11/shader/renderer/pixel_shader_zero_none_premul.h" +#include "d3d11/shader/renderer/pixel_shader_zero_none_straight.h" + +#define IDX(x) (size_t)static_cast(x) + +class D3DIncludeImpl : public ID3DInclude +{ +public: + COM_DECLSPEC_NOTHROW HRESULT WINAPI Open(D3D_INCLUDE_TYPE IncludeType, LPCSTR pFileName, LPCVOID pParentData, LPCVOID* ppData, UINT* pBytes) + { + UNREFERENCED_PARAMETER(IncludeType); // 我们不关心它是从哪里包含的 + UNREFERENCED_PARAMETER(pParentData); + core::SmartReference data; + if (!core::FileSystemManager::readFile(pFileName, data.put())) + { + return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND); + } + void* buffer = malloc(data->size()); + if (!buffer) return HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY); + // TODO: no copy x2 + memcpy(buffer, data->data(), data->size()); + *ppData = buffer; + *pBytes = static_cast(data->size()); + return S_OK; + } + COM_DECLSPEC_NOTHROW HRESULT WINAPI Close(LPCVOID pData) + { + assert(pData); + free(const_cast(pData)); + return S_OK; + } +}; + +static D3DIncludeImpl g_include_loader; +static Platform::RuntimeLoader::Direct3DCompiler g_d3dcompiler_loader; + +namespace core::Graphics +{ + static bool compileShaderMacro(char const* name, void const* data, size_t size, char const* target, const D3D_SHADER_MACRO* defs, ID3DBlob** ppBlob) + { + UINT flag_ = D3DCOMPILE_ENABLE_STRICTNESS; + #ifdef _DEBUG + flag_ |= D3DCOMPILE_DEBUG; + flag_ |= D3DCOMPILE_SKIP_OPTIMIZATION; + #endif + win32::com_ptr errmsg_; + HRESULT hr = gHR = g_d3dcompiler_loader.Compile(data, size, name, defs, &g_include_loader, "main", target, flag_, 0, ppBlob, errmsg_.put()); + if (FAILED(hr)) + { + Logger::error("[core] [Renderer] compile shader '{}' failed: {}", name, (char*)errmsg_->GetBufferPointer()); + return false; + } + return true; + } + static bool compileVertexShaderMacro11(char const* name, void const* data, size_t size, const D3D_SHADER_MACRO* defs, ID3DBlob** ppBlob) + { + return compileShaderMacro(name, data, size, "vs_4_0", defs, ppBlob); + } + static bool compilePixelShaderMacro11(char const* name, void const* data, size_t size, const D3D_SHADER_MACRO* defs, ID3DBlob** ppBlob) + { + return compileShaderMacro(name, data, size, "ps_4_0", defs, ppBlob); + } + + bool PostEffectShader_D3D11::createResources() + { + if (!d3d_ps_blob) + { + if (is_path) + { + SmartReference src; + if (!FileSystemManager::readFile(source, src.put())) + return false; + if (!compilePixelShaderMacro11(source.c_str(), src->data(), src->size(), nullptr, d3d_ps_blob.put())) + return false; + } + else + { + if (!compilePixelShaderMacro11(source.c_str(), source.data(), source.size(), nullptr, d3d_ps_blob.put())) + return false; + } + } + assert(m_device->GetD3D11Device()); + HRESULT hr = gHR = m_device->GetD3D11Device()->CreatePixelShader(d3d_ps_blob->GetBufferPointer(), d3d_ps_blob->GetBufferSize(), nullptr, d3d11_ps.put()); + if (FAILED(hr)) + return false; + M_D3D_SET_DEBUG_NAME_SIMPLE(d3d11_ps.get()); + + // 着色器反射 + + if (!d3d11_ps_reflect) + { + hr = gHR = g_d3dcompiler_loader.Reflect(d3d_ps_blob->GetBufferPointer(), d3d_ps_blob->GetBufferSize(), IID_PPV_ARGS(d3d11_ps_reflect.put())); + if (FAILED(hr)) return false; + + // 获得着色器信息 + + D3D11_SHADER_DESC shader_info{}; + hr = gHR = d3d11_ps_reflect->GetDesc(&shader_info); + if (FAILED(hr)) return false; + + // 常量缓冲区 + + m_buffer_map.reserve(shader_info.ConstantBuffers); + for (UINT i = 0; i < shader_info.ConstantBuffers; i += 1) + { + auto* constant_buffer = d3d11_ps_reflect->GetConstantBufferByIndex(i); + + D3D11_SHADER_BUFFER_DESC constant_buffer_info{}; + hr = gHR = constant_buffer->GetDesc(&constant_buffer_info); + if (FAILED(hr)) return false; + + D3D11_SHADER_INPUT_BIND_DESC bind_info{}; + hr = gHR = d3d11_ps_reflect->GetResourceBindingDescByName(constant_buffer_info.Name, &bind_info); + if (FAILED(hr)) return false; + + LocalConstantBuffer local_buffer; + local_buffer.index = bind_info.BindPoint; + local_buffer.buffer.resize(constant_buffer_info.Size); + local_buffer.variable.reserve(constant_buffer_info.Variables); + + for (UINT j = 0; j < constant_buffer_info.Variables; j += 1) + { + auto* variable = constant_buffer->GetVariableByIndex(j); + + D3D11_SHADER_VARIABLE_DESC variable_info{}; + hr = gHR = variable->GetDesc(&variable_info); + if (FAILED(hr)) return false; + + auto* variable_type = variable->GetType(); + + D3D11_SHADER_TYPE_DESC variable_type_info{}; + hr = gHR = variable_type->GetDesc(&variable_type_info); + if (FAILED(hr)) return false; + + LocalVariable local_variable; + local_variable.offset = variable_info.StartOffset; + local_variable.size = variable_info.Size; + + local_buffer.variable.emplace(variable_info.Name, std::move(local_variable)); + } + + m_buffer_map.emplace(constant_buffer_info.Name, std::move(local_buffer)); + } + + // 纹理 + + m_texture2d_map.reserve(shader_info.BoundResources - shader_info.ConstantBuffers); + for (UINT i = 0; i < shader_info.BoundResources; i += 1) + { + D3D11_SHADER_INPUT_BIND_DESC bind_info{}; + hr = gHR = d3d11_ps_reflect->GetResourceBindingDesc(i, &bind_info); + if (FAILED(hr)) return false; + + if (!(bind_info.Type == D3D_SIT_TEXTURE && bind_info.Dimension == D3D_SRV_DIMENSION_TEXTURE2D)) + { + continue; // 并非所需 + } + + LocalTexture2D local_texture2d; + local_texture2d.index = bind_info.BindPoint; + + m_texture2d_map.emplace(bind_info.Name, std::move(local_texture2d)); + } + } + + // 创建缓冲区 + + for (auto& v : m_buffer_map) + { + D3D11_BUFFER_DESC desc_ = { + .ByteWidth = static_cast(v.second.buffer.size()), + .Usage = D3D11_USAGE_DYNAMIC, + .BindFlags = D3D11_BIND_CONSTANT_BUFFER, + .CPUAccessFlags = D3D11_CPU_ACCESS_WRITE, + .MiscFlags = 0, + .StructureByteStride = 0, + }; + hr = gHR = m_device->GetD3D11Device()->CreateBuffer(&desc_, NULL, v.second.d3d11_buffer.put()); + if (FAILED(hr)) + return false; + } + + return true; + } + + bool Renderer_D3D11::createShaders() + { + assert(m_device->GetD3D11Device()); + + HRESULT hr = 0; + + // vertex shader + { + auto load_ = [&](FogState f, void const* data, size_t size) + { + hr = gHR = m_device->GetD3D11Device()->CreateVertexShader( + data, + size, + NULL, + _vertex_shader[IDX(f)].put()); + }; + + #define load(f, name)\ + load_(f, vertex_shader_##name, sizeof(vertex_shader_##name));\ + if (FAILED(hr)) return false;\ + M_D3D_SET_DEBUG_NAME_SIMPLE(_vertex_shader[IDX(f)].get()); + + load(FogState::Disable, normal); + load(FogState::Linear, fog); + load(FogState::Exp, fog); + load(FogState::Exp2, fog); + + #undef load + } + + // input layout + { + D3D11_INPUT_ELEMENT_DESC layout_[] = + { + // DrawVertex2D + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0 , D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "COLOR", 0, DXGI_FORMAT_B8G8R8A8_UNORM , 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT , 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 }, + }; + hr = gHR = m_device->GetD3D11Device()->CreateInputLayout( + layout_, 3, + vertex_shader_normal, + sizeof(vertex_shader_normal), + _input_layout.put()); + if (FAILED(hr)) + return false; + } + + // pixel shader + { + auto load_ = [&](VertexColorBlendState v, FogState f, TextureAlphaType t, void const* data, size_t size) + { + hr = gHR = m_device->GetD3D11Device()->CreatePixelShader( + data, + size, + NULL, + _pixel_shader[IDX(v)][IDX(f)][IDX(t)].put() + ); + }; + + #define load(v, f, t, name)\ + load_(v, f, t, pixel_shader_##name, sizeof(pixel_shader_##name));\ + if (FAILED(hr)) return false;\ + M_D3D_SET_DEBUG_NAME_SIMPLE(_pixel_shader[IDX(v)][IDX(f)][IDX(t)].get()); + + load(VertexColorBlendState::Zero, FogState::Disable, TextureAlphaType::Normal, zero_none_straight); + load(VertexColorBlendState::One, FogState::Disable, TextureAlphaType::Normal, one_none_straight); + load(VertexColorBlendState::Add, FogState::Disable, TextureAlphaType::Normal, add_none_straight); + load(VertexColorBlendState::Mul, FogState::Disable, TextureAlphaType::Normal, mul_none_straight); + + load(VertexColorBlendState::Zero, FogState::Linear, TextureAlphaType::Normal, zero_linear_straight); + load(VertexColorBlendState::One, FogState::Linear, TextureAlphaType::Normal, one_linear_straight); + load(VertexColorBlendState::Add, FogState::Linear, TextureAlphaType::Normal, add_linear_straight); + load(VertexColorBlendState::Mul, FogState::Linear, TextureAlphaType::Normal, mul_linear_straight); + + load(VertexColorBlendState::Zero, FogState::Exp, TextureAlphaType::Normal, zero_exp_straight); + load(VertexColorBlendState::One, FogState::Exp, TextureAlphaType::Normal, one_exp_straight); + load(VertexColorBlendState::Add, FogState::Exp, TextureAlphaType::Normal, add_exp_straight); + load(VertexColorBlendState::Mul, FogState::Exp, TextureAlphaType::Normal, mul_exp_straight); + + load(VertexColorBlendState::Zero, FogState::Exp2, TextureAlphaType::Normal, zero_exp2_straight); + load(VertexColorBlendState::One, FogState::Exp2, TextureAlphaType::Normal, one_exp2_straight); + load(VertexColorBlendState::Add, FogState::Exp2, TextureAlphaType::Normal, add_exp2_straight); + load(VertexColorBlendState::Mul, FogState::Exp2, TextureAlphaType::Normal, mul_exp2_straight); + + load(VertexColorBlendState::Zero, FogState::Disable, TextureAlphaType::PremulAlpha, zero_none_premul); + load(VertexColorBlendState::One, FogState::Disable, TextureAlphaType::PremulAlpha, one_none_premul); + load(VertexColorBlendState::Add, FogState::Disable, TextureAlphaType::PremulAlpha, add_none_premul); + load(VertexColorBlendState::Mul, FogState::Disable, TextureAlphaType::PremulAlpha, mul_none_premul); + + load(VertexColorBlendState::Zero, FogState::Linear, TextureAlphaType::PremulAlpha, zero_linear_premul); + load(VertexColorBlendState::One, FogState::Linear, TextureAlphaType::PremulAlpha, one_linear_premul); + load(VertexColorBlendState::Add, FogState::Linear, TextureAlphaType::PremulAlpha, add_linear_premul); + load(VertexColorBlendState::Mul, FogState::Linear, TextureAlphaType::PremulAlpha, mul_linear_premul); + + load(VertexColorBlendState::Zero, FogState::Exp, TextureAlphaType::PremulAlpha, zero_exp_premul); + load(VertexColorBlendState::One, FogState::Exp, TextureAlphaType::PremulAlpha, one_exp_premul); + load(VertexColorBlendState::Add, FogState::Exp, TextureAlphaType::PremulAlpha, add_exp_premul); + load(VertexColorBlendState::Mul, FogState::Exp, TextureAlphaType::PremulAlpha, mul_exp_premul); + + load(VertexColorBlendState::Zero, FogState::Exp2, TextureAlphaType::PremulAlpha, zero_exp2_premul); + load(VertexColorBlendState::One, FogState::Exp2, TextureAlphaType::PremulAlpha, one_exp2_premul); + load(VertexColorBlendState::Add, FogState::Exp2, TextureAlphaType::PremulAlpha, add_exp2_premul); + load(VertexColorBlendState::Mul, FogState::Exp2, TextureAlphaType::PremulAlpha, mul_exp2_premul); + + #undef load + } + + return true; + } +} diff --git a/LuaSTG/Core/Graphics/Sprite.hpp b/engine/graphics/core/Graphics/Sprite.hpp similarity index 95% rename from LuaSTG/Core/Graphics/Sprite.hpp rename to engine/graphics/core/Graphics/Sprite.hpp index a4fc2308..55d891be 100644 --- a/LuaSTG/Core/Graphics/Sprite.hpp +++ b/engine/graphics/core/Graphics/Sprite.hpp @@ -1,47 +1,47 @@ -#pragma once -#include "core/ReferenceCounted.hpp" -#include "Core/Graphics/Renderer.hpp" - -namespace core::Graphics -{ - struct ISprite : IReferenceCounted { - virtual ITexture2D* getTexture() = 0; - virtual void setTexture(ITexture2D* p_texture) = 0; - virtual void setTextureRect(RectF const& rc) = 0; - virtual RectF getTextureRect() = 0; - virtual void setTextureCenter(Vector2F const& pt) = 0; - virtual Vector2F getTextureCenter() = 0; - virtual void setUnitsPerPixel(float v) = 0; - virtual float getUnitsPerPixel() = 0; - virtual bool clone(ISprite** pp_sprite) = 0; - - static bool create(ITexture2D* p_texture, ISprite** pp_sprite); - }; - - struct ISpriteRenderer : IReferenceCounted { - virtual void setTransform(RectF const& rect) = 0; - virtual void setTransform(Vector2F const& p1, Vector2F const& p2, Vector2F const& p3, Vector2F const& p4) = 0; - virtual void setTransform(Vector3F const& p1, Vector3F const& p2, Vector3F const& p3, Vector3F const& p4) = 0; - virtual void setTransform(Vector2F const& position, Vector2F const& scale, float rotation) = 0; - virtual void setSprite(ISprite* sprite) = 0; - virtual void setColor(Color4B color) = 0; - virtual void setColor(Color4B c1, Color4B c2, Color4B c3, Color4B c4) = 0; - virtual void setZ(float z) = 0; - virtual void setLegacyBlendState(IRenderer::VertexColorBlendState vertex_color_blend_state, IRenderer::BlendState blend_state) = 0; - virtual void draw(IRenderer* renderer) = 0; - - static bool create(ISpriteRenderer** output); - }; -} - -namespace core { - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.ISprite - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("291cd55f-be6c-5abf-a014-cbd47ab655a3"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.ISpriteRenderer - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("928af8d9-f387-557b-a7d9-d1395b9bc0f1"); } -} +#pragma once +#include "core/ReferenceCounted.hpp" +#include "core/Graphics/Renderer.hpp" + +namespace core::Graphics +{ + struct ISprite : IReferenceCounted { + virtual ITexture2D* getTexture() = 0; + virtual void setTexture(ITexture2D* p_texture) = 0; + virtual void setTextureRect(RectF const& rc) = 0; + virtual RectF getTextureRect() = 0; + virtual void setTextureCenter(Vector2F const& pt) = 0; + virtual Vector2F getTextureCenter() = 0; + virtual void setUnitsPerPixel(float v) = 0; + virtual float getUnitsPerPixel() = 0; + virtual bool clone(ISprite** pp_sprite) = 0; + + static bool create(ITexture2D* p_texture, ISprite** pp_sprite); + }; + + struct ISpriteRenderer : IReferenceCounted { + virtual void setTransform(RectF const& rect) = 0; + virtual void setTransform(Vector2F const& p1, Vector2F const& p2, Vector2F const& p3, Vector2F const& p4) = 0; + virtual void setTransform(Vector3F const& p1, Vector3F const& p2, Vector3F const& p3, Vector3F const& p4) = 0; + virtual void setTransform(Vector2F const& position, Vector2F const& scale, float rotation) = 0; + virtual void setSprite(ISprite* sprite) = 0; + virtual void setColor(Color4B color) = 0; + virtual void setColor(Color4B c1, Color4B c2, Color4B c3, Color4B c4) = 0; + virtual void setZ(float z) = 0; + virtual void setLegacyBlendState(IRenderer::VertexColorBlendState vertex_color_blend_state, IRenderer::BlendState blend_state) = 0; + virtual void draw(IRenderer* renderer) = 0; + + static bool create(ISpriteRenderer** output); + }; +} + +namespace core { + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.ISprite + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("291cd55f-be6c-5abf-a014-cbd47ab655a3"); } + + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.ISpriteRenderer + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("928af8d9-f387-557b-a7d9-d1395b9bc0f1"); } +} diff --git a/LuaSTG/Core/Graphics/SwapChain.hpp b/engine/graphics/core/Graphics/SwapChain.hpp similarity index 84% rename from LuaSTG/Core/Graphics/SwapChain.hpp rename to engine/graphics/core/Graphics/SwapChain.hpp index 5e82b552..b095223f 100644 --- a/LuaSTG/Core/Graphics/SwapChain.hpp +++ b/engine/graphics/core/Graphics/SwapChain.hpp @@ -1,61 +1,61 @@ -#pragma once -#include "core/Vector2.hpp" -#include "core/Rational.hpp" -#include "core/ReferenceCounted.hpp" -#include "Core/Graphics/Window.hpp" -#include "Core/Graphics/Format.hpp" -#include "Core/Graphics/Device.hpp" - -namespace core::Graphics -{ - struct DisplayMode - { - uint32_t width{ 0 }; - uint32_t height{ 0 }; - Rational refresh_rate; - Format format{ Format::B8G8R8A8_UNORM }; - }; - - enum class SwapChainScalingMode - { - Stretch, - AspectRatio, - }; - - struct ISwapChainEventListener - { - virtual void onSwapChainCreate() = 0; - virtual void onSwapChainDestroy() = 0; - }; - - struct ISwapChain : public IReferenceCounted - { - virtual void addEventListener(ISwapChainEventListener* e) = 0; - virtual void removeEventListener(ISwapChainEventListener* e) = 0; - - virtual bool setWindowMode(Vector2U size) = 0; - virtual bool setCanvasSize(Vector2U size) = 0; - virtual Vector2U getCanvasSize() = 0; - - virtual void setScalingMode(SwapChainScalingMode mode) = 0; - virtual SwapChainScalingMode getScalingMode() = 0; - - virtual void clearRenderAttachment() = 0; - virtual void applyRenderAttachment() = 0; - virtual void waitFrameLatency() = 0; - virtual void setVSync(bool enable) = 0; - virtual bool getVSync() = 0; - virtual bool present() = 0; - - virtual bool saveSnapshotToFile(StringView path) = 0; - - static bool create(IWindow* p_window, IDevice* p_device, ISwapChain** pp_swapchain); - }; -} - -namespace core { - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.ISwapChain - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("9036abca-4134-5258-9021-a79b7bfe5a58"); } -} +#pragma once +#include "core/Vector2.hpp" +#include "core/Rational.hpp" +#include "core/ReferenceCounted.hpp" +#include "core/Window.hpp" +#include "core/Graphics/Format.hpp" +#include "core/GraphicsDevice.hpp" + +namespace core::Graphics +{ + struct DisplayMode + { + uint32_t width{ 0 }; + uint32_t height{ 0 }; + Rational refresh_rate; + Format format{ Format::B8G8R8A8_UNORM }; + }; + + enum class SwapChainScalingMode + { + Stretch, + AspectRatio, + }; + + struct ISwapChainEventListener + { + virtual void onSwapChainCreate() = 0; + virtual void onSwapChainDestroy() = 0; + }; + + struct ISwapChain : public IReferenceCounted + { + virtual void addEventListener(ISwapChainEventListener* e) = 0; + virtual void removeEventListener(ISwapChainEventListener* e) = 0; + + virtual bool setWindowMode(Vector2U size) = 0; + virtual bool setCanvasSize(Vector2U size) = 0; + virtual Vector2U getCanvasSize() = 0; + + virtual void setScalingMode(SwapChainScalingMode mode) = 0; + virtual SwapChainScalingMode getScalingMode() = 0; + + virtual void clearRenderAttachment() = 0; + virtual void applyRenderAttachment() = 0; + virtual void waitFrameLatency() = 0; + virtual void setVSync(bool enable) = 0; + virtual bool getVSync() = 0; + virtual bool present() = 0; + + virtual bool saveSnapshotToFile(StringView path) = 0; + + static bool create(IWindow* p_window, IGraphicsDevice* p_device, ISwapChain** pp_swapchain); + }; +} + +namespace core { + // UUID v5 + // ns:URL + // https://www.luastg-sub.com/core.ISwapChain + template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("9036abca-4134-5258-9021-a79b7bfe5a58"); } +} diff --git a/LuaSTG/Core/Graphics/SwapChain_D3D11.cpp b/engine/graphics/core/Graphics/SwapChain_D3D11.cpp similarity index 82% rename from LuaSTG/Core/Graphics/SwapChain_D3D11.cpp rename to engine/graphics/core/Graphics/SwapChain_D3D11.cpp index 4eb30df7..3eced47e 100644 --- a/LuaSTG/Core/Graphics/SwapChain_D3D11.cpp +++ b/engine/graphics/core/Graphics/SwapChain_D3D11.cpp @@ -1,2302 +1,2329 @@ -#include "Core/Graphics/SwapChain_D3D11.hpp" -#include "Core/i18n.hpp" -#include "core/Configuration.hpp" -#include "Platform/WindowsVersion.hpp" -#include "Platform/DesktopWindowManager.hpp" -#include "Platform/Direct3D11.hpp" -#include "Platform/DXGI.hpp" -#include "Platform/RuntimeLoader/D3DKMT.hpp" -#include "utf8.hpp" - -#include "ScreenGrab11.h" - -//#define _log(x) OutputDebugStringA(x "\n") -#define _log(x) - -#define HRNew HRESULT hr = S_OK; -#define HRGet hr = gHR -#define HRCheckCallReport(x) if (FAILED(hr)) { i18n_core_system_call_report_error(x); } -#define HRCheckCallReturnBool(x) if (FAILED(hr)) { i18n_core_system_call_report_error(x); assert(false); return false; } -#define HRCheckCallNoAssertReturnBool(x) if (FAILED(hr)) { i18n_core_system_call_report_error(x); return false; } - -#define NTNew NTSTATUS nt{}; -#define NTGet nt -#define NTCheckCallReport(x) if (nt != STATUS_SUCCESS) { i18n_core_system_call_report_error(x); } -#define NTCheckCallReturnBool(x) if (nt != STATUS_SUCCESS) { i18n_core_system_call_report_error(x); assert(false); return false; } -#define NTCheckCallNoAssertReturnBool(x) if (nt != STATUS_SUCCESS) { i18n_core_system_call_report_error(x); return false; } - -#define ReportError(x) i18n_core_system_call_report_error(x) - -namespace { - bool resolveOutput(HWND const window, IDXGISwapChain* const swap_chain, IDXGIOutput** const output_output) { - HRNew; - - auto const monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST); - if (monitor == nullptr) { - ReportError("MonitorFromWindow (MONITOR_DEFAULT_TO_NEAREST)"); - return false; - } - - Microsoft::WRL::ComPtr factory; - HRGet = swap_chain->GetParent(IID_PPV_ARGS(factory.ReleaseAndGetAddressOf())); - HRCheckCallNoAssertReturnBool("IDXGISwapChain::GetParent -> IDXGIFactory1"); - - Microsoft::WRL::ComPtr adapter; - Microsoft::WRL::ComPtr output; - - for (UINT adapter_index = 0; SUCCEEDED(factory->EnumAdapters1(adapter_index, adapter.ReleaseAndGetAddressOf())); adapter_index++) { - for (UINT output_index = 0; SUCCEEDED(adapter->EnumOutputs(output_index, output.ReleaseAndGetAddressOf())); output_index++) { - DXGI_OUTPUT_DESC output_info{}; - HRGet = output->GetDesc(&output_info); - if (FAILED(hr)) { - ReportError("IDXGIOutput::GetDesc"); - continue; - } - if (monitor == output_info.Monitor) { - *output_output = output.Detach(); - return true; - } - } - } - - return false; - } -} - -namespace core::Graphics -{ - constexpr DXGI_FORMAT const COLOR_BUFFER_FORMAT = DXGI_FORMAT_B8G8R8A8_UNORM; - constexpr DXGI_FORMAT const DEPTH_BUFFER_FORMAT = DXGI_FORMAT_D24_UNORM_S8_UINT; - - inline std::string_view to_string(DXGI_MODE_SCANLINE_ORDER v) - { - switch (v) - { - default: - case DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED: - assert(false); return "未知扫描方式"; - case DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE: - return "逐行扫描"; - case DXGI_MODE_SCANLINE_ORDER_UPPER_FIELD_FIRST: - return "隔行扫描(先奇数行)"; - case DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST: - return "隔行扫描(先偶数行)"; - } - } - inline std::string_view to_string(DXGI_MODE_SCALING v) - { - switch (v) - { - default: - case DXGI_MODE_SCALING_UNSPECIFIED: - return "自动缩放"; - case DXGI_MODE_SCALING_CENTERED: - return "居中显示"; - case DXGI_MODE_SCALING_STRETCHED: - return "拉伸全屏"; - } - } - - inline bool makeLetterboxing(Vector2U rect, Vector2U inner_rect, DXGI_MATRIX_3X2_F& mat) - { - if (rect == inner_rect) - { - return false; // 不需要 - } - else - { - double const hscale = (double)rect.x / (double)inner_rect.x; - double const vscale = (double)rect.y / (double)inner_rect.y; - double const scale = std::min(hscale, vscale); - double const width = scale * (double)inner_rect.x; - double const height = scale * (double)inner_rect.y; - double const x = ((double)rect.x - width) * 0.5; - double const y = ((double)rect.y - height) * 0.5; - mat = DXGI_MATRIX_3X2_F{ - FLOAT(scale), 0.0f, - 0.0f, FLOAT(scale), - FLOAT(x), FLOAT(y), - }; - return true; - } - } - inline DXGI_SWAP_CHAIN_DESC1 getDefaultSwapChainInfo7() - { - return DXGI_SWAP_CHAIN_DESC1{ - .Width = 0, - .Height = 0, - .Format = COLOR_BUFFER_FORMAT, - .Stereo = FALSE, - .SampleDesc = DXGI_SAMPLE_DESC{ - .Count = 1, - .Quality = 0, - }, - .BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, - .BufferCount = 1, - .Scaling = DXGI_SCALING_STRETCH, - .SwapEffect = DXGI_SWAP_EFFECT_DISCARD, - .AlphaMode = DXGI_ALPHA_MODE_IGNORE, - .Flags = 0, - }; - } - inline DXGI_SWAP_CHAIN_DESC1 getDefaultSwapChainInfo10() - { - return DXGI_SWAP_CHAIN_DESC1{ - .Width = 0, - .Height = 0, - .Format = COLOR_BUFFER_FORMAT, - .Stereo = FALSE, - .SampleDesc = DXGI_SAMPLE_DESC{ - .Count = 1, - .Quality = 0, - }, - .BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, - .BufferCount = 3, - .Scaling = DXGI_SCALING_NONE, - .SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD, - .AlphaMode = DXGI_ALPHA_MODE_IGNORE, - .Flags = 0, - }; - } - - static bool findBestDisplayMode(HWND const window, IDXGISwapChain1* dxgi_swapchain, Vector2U canvas_size, DXGI_MODE_DESC1& mode) - { - HRNew; - - Microsoft::WRL::ComPtr dxgi_output; - HRGet = dxgi_swapchain->GetContainingOutput(&dxgi_output); - if (FAILED(hr)) { - ReportError("IDXGISwapChain1::GetContainingOutput"); - if (!resolveOutput(window, dxgi_swapchain, dxgi_output.ReleaseAndGetAddressOf())) { - return false; - } - } - - Microsoft::WRL::ComPtr dxgi_output_1; - HRGet = dxgi_output.As(&dxgi_output_1); - HRCheckCallReturnBool("IDXGIOutput::QueryInterface -> IDXGIOutput1"); - - DXGI_OUTPUT_DESC dxgi_output_info = {}; - HRGet = dxgi_output_1->GetDesc(&dxgi_output_info); - HRCheckCallReturnBool("IDXGIOutput1::GetDesc"); - assert(dxgi_output_info.AttachedToDesktop); - assert(dxgi_output_info.Monitor); - assert(dxgi_output_info.DesktopCoordinates.right > dxgi_output_info.DesktopCoordinates.left); - assert(dxgi_output_info.DesktopCoordinates.bottom > dxgi_output_info.DesktopCoordinates.top); - UINT const monitor_w = static_cast(dxgi_output_info.DesktopCoordinates.right - dxgi_output_info.DesktopCoordinates.left); - UINT const monitor_h = static_cast(dxgi_output_info.DesktopCoordinates.bottom - dxgi_output_info.DesktopCoordinates.top); - - UINT dxgi_mode_count = 0; - HRGet = dxgi_output_1->GetDisplayModeList1(COLOR_BUFFER_FORMAT, 0, &dxgi_mode_count, NULL); - HRCheckCallReturnBool("IDXGIOutput1::GetDisplayModeList1 -> DXGI_FORMAT_B8G8R8A8_UNORM"); - assert(dxgi_mode_count > 0); - - std::vector mode_list(dxgi_mode_count); - HRGet = dxgi_output_1->GetDisplayModeList1(COLOR_BUFFER_FORMAT, 0, &dxgi_mode_count, mode_list.data()); - HRCheckCallReturnBool("IDXGIOutput1::GetDisplayModeList1 -> DXGI_FORMAT_B8G8R8A8_UNORM"); - - // 公共函数 - - auto scoreRefreshRate = [](DXGI_MODE_DESC1 const& v) -> int - { - int final_score = 0; - - double const refresh_rate_f = (double)v.RefreshRate.Numerator / (double)v.RefreshRate.Denominator; - assert(refresh_rate_f >= 1.0); // 理论上不存在刷新率等于或者小于 0 的情况 - double const multiple_f = refresh_rate_f / 60.0; // 相对 60Hz 的倍数 - assert(multiple_f > 0.0); - - double const multiple = std::ceil(multiple_f); - assert(multiple > 0.0); - double const range_low = (60.0 * multiple) - multiple; - double const range_high = (60.0 * multiple) + multiple; - assert(range_low > 0.0); - assert(range_high > 0.0); - - if (refresh_rate_f > range_low && refresh_rate_f < range_high) - { - // 是 60Hz 或者 60Hz 的倍数的刷新率 - int multiple_i = std::clamp((int)multiple, 1, 100); // 限制范围防止 int 乘上去后溢出 - final_score = 10000000 * multiple_i; - } - else if (refresh_rate_f > 118.0) - { - // 只要是 120Hz 或以上的刷新率,就已经可以满足游戏需求,无论是 144Hz 还是 165Hz 这种奇异刷新率 - final_score = 5000000; - } - else if (refresh_rate_f > 59.0) - { - // 还能接受的刷新率,比如 75Hz 和 90Hz - final_score = 1000000; - } - else - { - // 以上要求都达不到,我只能说,你这个显示器就是个几把 - final_score = 0; - } - - int const refresh_rate_v = std::clamp((int)(refresh_rate_f * 100.0), 0, 999999); // 理论上不会有超过一万刷新率的屏幕? - final_score += refresh_rate_v; // 后面补上刷新率的 100 倍整数方便一次性比较 - - return final_score; - }; - - auto compareRefreshRate = [=](DXGI_MODE_DESC1 const& a, DXGI_MODE_DESC1 const& b) -> bool - { - return scoreRefreshRate(a) > scoreRefreshRate(b); - }; - - auto checkRequiredRefreshRate = [](DXGI_MODE_DESC1 const& v) -> bool - { - return (double)v.RefreshRate.Numerator / (double)v.RefreshRate.Denominator >= 59.0; - }; - - auto checkRequiredCanvasSize = [&](DXGI_MODE_DESC1 const& v) -> bool - { - return v.Width >= canvas_size.x && v.Height >= canvas_size.y; - }; - - auto checkRequiredAspectRatio = [&](DXGI_MODE_DESC1 const& v) -> bool - { - if (monitor_w > monitor_h) - { - UINT const width = v.Height * monitor_w / monitor_h; - assert(width > 0); - if (width == 0) return false; - else if (v.Width == width) return true; - else if (width > v.Width && (width - v.Width) <= 2) return true; - else if (v.Width > width && (v.Width - width) <= 2) return true; - else return false; - } - else - { - UINT const height = v.Width * monitor_h / monitor_w; - assert(height > 0); - if (height == 0) return false; - else if (v.Height == height) return true; - else if (height > v.Height && (height - v.Height) <= 2) return true; - else if (v.Height > height && (v.Height - height) <= 2) return true; - else return false; - } - }; - - // 默认的桌面分辨率 - - std::vector default_mode_list; - for (auto const& v : mode_list) - { - if (v.Width == monitor_w && v.Height == monitor_h) - { - default_mode_list.emplace_back(v); - } - } - - assert(!default_mode_list.empty()); - if (default_mode_list.empty()) return false; - - std::sort(default_mode_list.begin(), default_mode_list.end(), compareRefreshRate); - DXGI_MODE_DESC1 default_mode = default_mode_list.at(0); - default_mode_list.clear(); - - // 剔除隔行扫描(理论情况下不会出现) - - for (auto it = mode_list.begin(); it != mode_list.end();) - { - if (!(it->ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED || it->ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE)) - it = mode_list.erase(it); - else - it++; - } - - // 剔除刷新率过低的 - - for (auto it = mode_list.begin(); it != mode_list.end();) - { - if (!checkRequiredRefreshRate(*it)) - { - it = mode_list.erase(it); - } - else - { - it++; - } - } - - // 剔除分辨率比画布分辨率低的 - - for (auto it = mode_list.begin(); it != mode_list.end();) - { - if (!checkRequiredCanvasSize(*it)) - { - it = mode_list.erase(it); - } - else - { - it++; - } - } - - // 剔除横纵比不和显示器匹配的 - - for (auto it = mode_list.begin(); it != mode_list.end();) - { - if (!checkRequiredAspectRatio(*it)) - { - it = mode_list.erase(it); - } - else - { - it++; - } - } - - // 根据面积比和刷新率进行排序,优先刷新率,然后是面积比 - - auto compareByRefreshRateAndSize = [&](DXGI_MODE_DESC1 const& a, DXGI_MODE_DESC1 const& b) -> bool - { - double const canvas_sz = (double)canvas_size.x * (double)canvas_size.y; - double const sz_a = canvas_sz / ((double)a.Width * (double)a.Height); - double const sz_b = canvas_sz / ((double)b.Width * (double)b.Height); - if (sz_a == sz_b) - { - return compareRefreshRate(a, b); - } - else - { - return sz_b > sz_b; - } - }; - - std::sort(mode_list.begin(), mode_list.end(), compareByRefreshRateAndSize); - - // 打印结果 - - i18n_log_info_fmt("[core].SwapChain_D3D11.found_N_DisplayMode_fmt", mode_list.size()); - for (size_t i = 0; i < mode_list.size(); i += 1) - { - spdlog::info("{: >4d}: ({: >5d} x {: >5d}) {:.2f}Hz {} {}" - , i - , mode_list[i].Width, mode_list[i].Height - , (double)mode_list[i].RefreshRate.Numerator / (double)mode_list[i].RefreshRate.Denominator - , to_string(mode_list[i].Scaling) - , to_string(mode_list[i].ScanlineOrdering) - ); - } - - // 最终,挑选出面积比最大且刷新率最高的 - - if (!mode_list.empty()) - { - mode = mode_list.at(0); - } - else - { - mode = default_mode; - } - - return true; - } - static bool checkModernSwapChainModelAvailable(ID3D11Device* device) - { - // 是否需要统一开启现代交换链模型 - // 我们划定一个红线,红线以下永远不开启,红线以上永远开启 - // 这样可以简化逻辑的处理 - - assert(device); - HRNew; - NTNew; - - // 预检系统版本 Windows 10 1809 - // * DXGI_SWAP_EFFECT_FLIP_DISCARD 从 Windows 10 开始支持 - // * 在 Windows 10 1709 (16299) Fall Creators Update 中修复了 - // Frame Latency Waitable Object 和 SetMaximumFrameLatency 实际上至少有 2 帧的问题 - // * Windows 10 1809 (17763) 是目前微软还在支持的长期支持版本 - // https://learn.microsoft.com/en-us/windows/release-health/release-information - // * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT 从 Windows 8.1 开始支持,我们跳过它 - - if (!Platform::WindowsVersion::Is10Build17763()) { - return false; - } - - // 检查 PresentAllowTearing - // * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING 从 Windows 10 开始支持 - // * DXGI_PRESENT_ALLOW_TEARING 从 Windows 10 开始支持 - // * 此外还有别的要求,比如WDDM支持、MPO支持、显卡驱动支持等 - // * 注意,就算报告支持,实际运行的时候可能仍然不允许撕裂 - // * 系统安装了 KB3156421 更新,也就是 Windows 10 在 2016 年 5 月 10 日的更新 - // https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/variable-refresh-rate-displays - - Microsoft::WRL::ComPtr dxgi_factory; - HRGet = Platform::Direct3D11::GetDeviceFactory(device, &dxgi_factory); - HRCheckCallReturnBool("Platform::Direct3D11::GetDeviceFactory"); - BOOL present_allow_tearing = Platform::DXGI::CheckFeatureSupportPresentAllowTearing(dxgi_factory.Get()); - - // 检查 DirectFlip - - Microsoft::WRL::ComPtr dxgi_adapter; - HRGet = Platform::Direct3D11::GetDeviceAdater(device, &dxgi_adapter); - HRCheckCallReturnBool("Platform::Direct3D11::GetDeviceAdater"); - DXGI_ADAPTER_DESC1 dxgi_adapter_info{}; - HRGet = dxgi_adapter->GetDesc1(&dxgi_adapter_info); - HRCheckCallReturnBool("IDXGIAdapter1::GetDesc1"); - - Platform::RuntimeLoader::D3DKMT d3dkmt; - - D3DKMT_OPENADAPTERFROMLUID open_adapter_from_luid{}; - open_adapter_from_luid.AdapterLuid = dxgi_adapter_info.AdapterLuid; - NTGet = d3dkmt.OpenAdapterFromLuid(&open_adapter_from_luid); - NTCheckCallReturnBool("D3DKMTOpenAdapterFromLuid"); - - auto auto_close_adapter = wil::scope_exit([&open_adapter_from_luid, &d3dkmt] - { - D3DKMT_CLOSEADAPTER close_adapter{}; - close_adapter.hAdapter = open_adapter_from_luid.hAdapter; - NTNew; - NTGet = d3dkmt.CloseAdapter(&close_adapter); - NTCheckCallReport("D3DKMTCloseAdapter"); - }); - - D3DKMT_CREATEDEVICE create_device{}; - create_device.hAdapter = open_adapter_from_luid.hAdapter; - NTGet = d3dkmt.CreateDevice(&create_device); - NTCheckCallReturnBool("D3DKMTCreateDevice"); - - auto auto_close_device = wil::scope_exit([&create_device, &d3dkmt] - { - D3DKMT_DESTROYDEVICE destroy_device{}; - destroy_device.hDevice = create_device.hDevice; - NTNew; - NTGet = d3dkmt.DestroyDevice(&destroy_device); - NTCheckCallReport("D3DKMTDestroyDevice"); - }); - - auto query_adapter_info = [&open_adapter_from_luid, &d3dkmt](KMTQUERYADAPTERINFOTYPE type, T, std::string_view type_name) -> T { - T data{}; - D3DKMT_QUERYADAPTERINFO query{}; - query.hAdapter = open_adapter_from_luid.hAdapter; - query.Type = type; - query.pPrivateDriverData = &data; - query.PrivateDriverDataSize = sizeof(data); - NTNew; - NTGet = d3dkmt.QueryAdapterInfo(&query); - NTCheckCallReport(std::string("D3DKMTQueryAdapterInfo -> ").append(type_name)); - return data; - }; - - // wddm 1.2 - auto const direct_flip_caps = query_adapter_info(KMTQAITYPE_DIRECTFLIP_SUPPORT, D3DKMT_DIRECTFLIP_SUPPORT{}, "D3DKMT_DIRECTFLIP_SUPPORT"); - // wddm 2.0 - auto const independent_flip_support = query_adapter_info(KMTQAITYPE_INDEPENDENTFLIP_SUPPORT, D3DKMT_INDEPENDENTFLIP_SUPPORT{}, "D3DKMT_INDEPENDENTFLIP_SUPPORT"); - - // 打印信息 - - auto bool_to_string = [](bool v) { return v ? "true" : "false"; }; - - spdlog::info( - "[core] Graphics Device: {}\n" - " Direct Flip Support: {}\n" - " Independent Flip Support: {}\n" - " Present Allow Tearing: {}" - , utf8::to_string(dxgi_adapter_info.Description) - , bool_to_string(direct_flip_caps.Supported) - , bool_to_string(independent_flip_support.Supported) - , bool_to_string(present_allow_tearing) - ); - - return present_allow_tearing && direct_flip_caps.Supported && independent_flip_support.Supported; - } - static bool checkMultiPlaneOverlaySupport(ID3D11Device* device) - { - // 是否有多平面叠加支持,如果有,就可以提供更好的性能 - - assert(device); - HRNew; - NTNew; - - // 用户禁用了 MPO 则跳过 - - if (Platform::DesktopWindowManager::IsOverlayTestModeExists()) { - spdlog::warn("[core] Multi Plane Overlay is disabled by user"); - return false; - } - - // 检查各个显示输出的支持情况 - - Microsoft::WRL::ComPtr dxgi_factory; - HRGet = Platform::Direct3D11::GetDeviceFactory(device, &dxgi_factory); - HRCheckCallReturnBool("Platform::Direct3D11::GetDeviceFactory"); - - Platform::RuntimeLoader::D3DKMT d3dkmt; - - Microsoft::WRL::ComPtr dxgi_adapter; - for (UINT adapter_index = 0; SUCCEEDED(dxgi_factory->EnumAdapters1(adapter_index, &dxgi_adapter)); adapter_index += 1) { - DXGI_ADAPTER_DESC1 dxgi_adapter_info{}; - HRGet = dxgi_adapter->GetDesc1(&dxgi_adapter_info); - HRCheckCallReturnBool("IDXGIAdapter1::GetDesc1"); - - Microsoft::WRL::ComPtr dxgi_output; - for (UINT output_index = 0; SUCCEEDED(dxgi_adapter->EnumOutputs(output_index, &dxgi_output)); output_index += 1) { - DXGI_OUTPUT_DESC dxgi_output_info{}; - HRGet = dxgi_output->GetDesc(&dxgi_output_info); - HRCheckCallReturnBool("IDXGIOutput::GetDesc"); - - D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME open_adapter_from_gdi{}; - std::memcpy(open_adapter_from_gdi.DeviceName, dxgi_output_info.DeviceName, sizeof(dxgi_output_info.DeviceName)); - NTGet = d3dkmt.OpenAdapterFromGdiDisplayName(&open_adapter_from_gdi); - NTCheckCallReturnBool("D3DKMTOpenAdapterFromGdiDisplayName"); - - auto auto_close_adapter = wil::scope_exit([&open_adapter_from_gdi, &d3dkmt] - { - D3DKMT_CLOSEADAPTER close_adapter{}; - close_adapter.hAdapter = open_adapter_from_gdi.hAdapter; - NTNew; - NTGet = d3dkmt.CloseAdapter(&close_adapter); - NTCheckCallReport("D3DKMTCloseAdapter"); - }); - - D3DKMT_CREATEDEVICE create_device{}; - create_device.hAdapter = open_adapter_from_gdi.hAdapter; - NTGet = d3dkmt.CreateDevice(&create_device); - NTCheckCallReturnBool("D3DKMTCreateDevice"); - - auto auto_close_device = wil::scope_exit([&create_device, &d3dkmt] - { - D3DKMT_DESTROYDEVICE destroy_device{}; - destroy_device.hDevice = create_device.hDevice; - NTNew; - NTGet = d3dkmt.DestroyDevice(&destroy_device); - NTCheckCallReport("D3DKMTDestroyDevice"); - }); - - auto query_adapter_info = [&open_adapter_from_gdi, &d3dkmt](KMTQUERYADAPTERINFOTYPE type, T, std::string_view type_name) -> T { - T data{}; - D3DKMT_QUERYADAPTERINFO query{}; - query.hAdapter = open_adapter_from_gdi.hAdapter; - query.Type = type; - query.pPrivateDriverData = &data; - query.PrivateDriverDataSize = sizeof(data); - NTNew; - NTGet = d3dkmt.QueryAdapterInfo(&query); - NTCheckCallReport(std::string("D3DKMTQueryAdapterInfo -> ").append(type_name)); - return data; - }; - - // 检查多平面叠加支持 - - auto mpo_support = query_adapter_info(KMTQAITYPE_MULTIPLANEOVERLAY_SUPPORT, D3DKMT_MULTIPLANEOVERLAY_SUPPORT{}, "D3DKMT_MULTIPLANEOVERLAY_SUPPORT"); - - // 进一步检查多平面叠加功能支持 - - D3DKMT_GET_MULTIPLANE_OVERLAY_CAPS get_mpo_caps{}; - get_mpo_caps.hAdapter = open_adapter_from_gdi.hAdapter; - get_mpo_caps.VidPnSourceId = open_adapter_from_gdi.VidPnSourceId; - NTGet = d3dkmt.GetMultiPlaneOverlayCaps(&get_mpo_caps); - NTCheckCallReturnBool("D3DKMTGetMultiPlaneOverlayCaps"); - - // 检查额外的功能 - - BOOL overlays = FALSE; // 我们只打印信息,但不使用这个值,因为它代表的含义并不清晰 - Microsoft::WRL::ComPtr dxgi_output2; - HRGet = dxgi_output.As(&dxgi_output2); - HRCheckCallReport("IDXGIOutput::QueryInterface -> IDXGIOutput2"); - if (dxgi_output2) - { - overlays = dxgi_output2->SupportsOverlays(); - } - - UINT hardware_composition_support{}; - Microsoft::WRL::ComPtr dxgi_output6; - HRGet = dxgi_output.As(&dxgi_output6); - HRCheckCallReport("IDXGIOutput::QueryInterface -> IDXGIOutput6"); - if (dxgi_output6) - { - HRGet = dxgi_output6->CheckHardwareCompositionSupport(&hardware_composition_support); - HRCheckCallReport("IDXGIOutput6::CheckHardwareCompositionSupport"); - } - - // 打印信息 - - auto bool_to_string = [](bool v) { return v ? "true" : "false"; }; - - spdlog::info( - "[core] Display Output: {} -> {}\n" - " Overlays Support: {}\n" - " Multi Plane Overlay:\n" - " Support: {}\n" - " Max Planes: {}\n" - " Max RGB Planes: {}\n" - " Max YUV Planes: {}\n" - " Overlay Capabilities:\n" - " Rotation: {}\n" - " Rotation Without Independent Flip: {}\n" - " Vertical Flip: {}\n" - " Horizontal Flip: {}\n" - " Stretch RGB: {}\n" - " Stretch YUV: {}\n" - " Bilinear Filter: {}\n" - " High Filter: {}\n" - " Shared: {}\n" - " Immediate: {}\n" - " Plane 0 For Virtual Mode Only: {}\n" - " Version 3 DDI Support: {}\n" - " Max Stretch Factor: {:.2f}x\n" - " Max Shrink Factor: {:.2f}x\n" - " Hardware Composition:\n" - " Fullscreen: {}\n" - " Windowed: {}\n" - " Cursor Stretched: {}" - , utf8::to_string(dxgi_adapter_info.Description) - , utf8::to_string(dxgi_output_info.DeviceName) - , bool_to_string(overlays) - , bool_to_string(mpo_support.Supported) - , get_mpo_caps.MaxPlanes - , get_mpo_caps.MaxRGBPlanes - , get_mpo_caps.MaxYUVPlanes - , bool_to_string(get_mpo_caps.OverlayCaps.Rotation) - , bool_to_string(get_mpo_caps.OverlayCaps.RotationWithoutIndependentFlip) - , bool_to_string(get_mpo_caps.OverlayCaps.VerticalFlip) - , bool_to_string(get_mpo_caps.OverlayCaps.HorizontalFlip) - , bool_to_string(get_mpo_caps.OverlayCaps.StretchRGB) - , bool_to_string(get_mpo_caps.OverlayCaps.StretchYUV) - , bool_to_string(get_mpo_caps.OverlayCaps.BilinearFilter) - , bool_to_string(get_mpo_caps.OverlayCaps.HighFilter) - , bool_to_string(get_mpo_caps.OverlayCaps.Shared) - , bool_to_string(get_mpo_caps.OverlayCaps.Immediate) - , bool_to_string(get_mpo_caps.OverlayCaps.Plane0ForVirtualModeOnly) - , bool_to_string(get_mpo_caps.OverlayCaps.Version3DDISupport) - , get_mpo_caps.MaxStretchFactor - , get_mpo_caps.MaxShrinkFactor - , bool_to_string(hardware_composition_support & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_FULLSCREEN) - , bool_to_string(hardware_composition_support & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_WINDOWED) - , bool_to_string(hardware_composition_support & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_CURSOR_STRETCHED) - ); - - // 多平面叠加不支持 - - if (!mpo_support.Supported) { - return false; - } - - // 平面数量少于 2(特别是 RGB 平面),那肯定是不支持了 - - if (get_mpo_caps.MaxPlanes < 2 || get_mpo_caps.MaxRGBPlanes < 2) { - return false; - } - - // 看起来似乎不支持缩放 - - if (!get_mpo_caps.OverlayCaps.StretchRGB || std::abs(get_mpo_caps.MaxStretchFactor - 1.0f) < 0.1f || std::abs(get_mpo_caps.MaxShrinkFactor - 1.0f) < 0.1f) { - return false; - } - - // TODO: 检测 get_mpo_caps.OverlayCaps.Immediate 的作用 - - // 全屏模式的合成不支持 - - if (!(hardware_composition_support & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_FULLSCREEN)) { - return false; - } - } - } - - // 大概是支持的吧…… - - return true; - } - inline bool isModernSwapChainModel(DXGI_SWAP_CHAIN_DESC1 const& info) - { - return info.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL - || info.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD - ; - } - inline bool isModernSwapChainModel(IDXGISwapChain1* dxgi_swapchain) - { - HRNew; - - DXGI_SWAP_CHAIN_DESC1 info = {}; - HRGet = dxgi_swapchain->GetDesc1(&info); - HRCheckCallReturnBool("IDXGISwapChain1::GetDesc1"); - - return isModernSwapChainModel(info); - } - - bool SecondarySwapChain::createRenderAttachment() { - assert(d3d11_device); -#ifdef LUASTG_ENABLE_DIRECT2D - assert(d2d1_device_context); -#endif - assert(dxgi_swap_chain); - HRNew; - - wil::com_ptr_nothrow texture; - HRGet = dxgi_swap_chain->GetBuffer(0, IID_PPV_ARGS(texture.put())); - HRCheckCallReturnBool("IDXGISwapChain::GetBuffer"); - - HRGet = d3d11_device->CreateRenderTargetView(texture.get(), NULL, d3d11_rtv.put()); - HRCheckCallReturnBool("ID3D11Device::CreateRenderTargetView"); - - wil::com_ptr_nothrow surface; - HRGet = dxgi_swap_chain->GetBuffer(0, IID_PPV_ARGS(surface.put())); - HRCheckCallReturnBool("IDXGISwapChain::GetBuffer"); - -#ifdef LUASTG_ENABLE_DIRECT2D - D2D1_BITMAP_PROPERTIES1 bitmap_info{}; - bitmap_info.pixelFormat.format = info.Format; - bitmap_info.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; - bitmap_info.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; - HRGet = d2d1_device_context->CreateBitmapFromDxgiSurface(surface.get(), &bitmap_info, d2d1_bitmap.put()); - HRCheckCallReturnBool("ID2D1DeviceContext::CreateBitmapFromDxgiSurface"); -#endif - - return true; - } - void SecondarySwapChain::destroyRenderAttachment() { - if (d3d11_device_context) { - d3d11_device_context->ClearState(); - d3d11_device_context->Flush(); - } - d3d11_rtv.reset(); -#ifdef LUASTG_ENABLE_DIRECT2D - d2d1_bitmap.reset(); -#endif - } - - bool SecondarySwapChain::create(IDXGIFactory2* factory, ID3D11Device* device, ID2D1DeviceContext* context, Vector2U const& size) { - assert(factory); - assert(device); - assert(context); - assert(size.x > 0 && size.y > 0); - HRNew; - - dxgi_factory = factory; - d3d11_device = device; - d3d11_device->GetImmediateContext(d3d11_device_context.put()); -#ifdef LUASTG_ENABLE_DIRECT2D - d2d1_device_context = context; -#endif - - info.Width = size.x; - info.Height = size.y; - info.Format = COLOR_BUFFER_FORMAT; - info.SampleDesc.Count = 1; - info.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - info.BufferCount = 2; - info.Scaling = DXGI_SCALING_STRETCH; - info.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; - info.AlphaMode = DXGI_ALPHA_MODE_IGNORE; - info.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING; - - HRGet = dxgi_factory->CreateSwapChainForComposition(d3d11_device.get(), &info, NULL, dxgi_swap_chain.put()); - HRCheckCallReturnBool("IDXGIFactory2::CreateSwapChainForComposition"); - - return createRenderAttachment(); - } - void SecondarySwapChain::destroy() { - destroyRenderAttachment(); - dxgi_factory.reset(); - d3d11_device.reset(); - d3d11_device_context.reset(); -#ifdef LUASTG_ENABLE_DIRECT2D - d2d1_device_context.reset(); -#endif - dxgi_swap_chain.reset(); - } - bool SecondarySwapChain::setSize(Vector2U const& size) { - assert(size.x > 0 && size.y > 0); - if (size.x == 0 || size.y == 0) { - return false; - } - HRNew; - destroyRenderAttachment(); - info.Width = size.x; - info.Height = size.y; - HRGet = dxgi_swap_chain->ResizeBuffers(info.BufferCount, info.Width, info.Height, info.Format, info.Flags); - HRCheckCallReturnBool("IDXGISwapChain::ResizeBuffers"); - return createRenderAttachment(); - } - void SecondarySwapChain::clearRenderTarget() { - assert(d3d11_device_context); - assert(d3d11_rtv); - if (d3d11_device_context && d3d11_rtv) { - FLOAT const solid_black[4]{ 0.0f, 0.0f, 0.0f, 1.0f }; - d3d11_device_context->ClearRenderTargetView(d3d11_rtv.get(), solid_black); - } - } - bool SecondarySwapChain::present() { - assert(dxgi_swap_chain); - if (!dxgi_swap_chain) { - return false; - } - HRNew; - HRGet = dxgi_swap_chain->Present(0, DXGI_PRESENT_ALLOW_TEARING); - HRCheckCallReturnBool("IDXGISwapChain::Present"); - return true; - } - - void SwapChain_D3D11::dispatchEvent(EventType t) - { - // 回调 - m_is_dispatch_event = true; - switch (t) - { - case EventType::SwapChainCreate: - for (auto& v : m_eventobj) - { - if (v) v->onSwapChainCreate(); - } - break; - case EventType::SwapChainDestroy: - for (auto& v : m_eventobj) - { - if (v) v->onSwapChainDestroy(); - } - break; - } - m_is_dispatch_event = false; - // 处理那些延迟的对象 - removeEventListener(nullptr); - for (auto& v : m_eventobj_late) - { - m_eventobj.emplace_back(v); - } - m_eventobj_late.clear(); - } - void SwapChain_D3D11::addEventListener(ISwapChainEventListener* e) - { - removeEventListener(e); - if (m_is_dispatch_event) - { - m_eventobj_late.emplace_back(e); - } - else - { - m_eventobj.emplace_back(e); - } - } - void SwapChain_D3D11::removeEventListener(ISwapChainEventListener* e) - { - if (m_is_dispatch_event) - { - for (auto& v : m_eventobj) - { - if (v == e) - { - v = nullptr; // 不破坏遍历过程 - } - } - } - else - { - for (auto it = m_eventobj.begin(); it != m_eventobj.end();) - { - if (*it == e) - it = m_eventobj.erase(it); - else - it++; - } - } - } - - void SwapChain_D3D11::onDeviceCreate() - { - m_modern_swap_chain_available = checkModernSwapChainModelAvailable(m_device->GetD3D11Device()); - m_scaling_renderer.AttachDevice(m_device->GetD3D11Device()); - if (m_init) // 曾经设置过 - { - setWindowMode(m_canvas_size); - if (m_swap_chain_fullscreen_mode) - { - // 重新进入独占全屏 - onWindowFullscreenStateChange(true); - } - } - } - void SwapChain_D3D11::onDeviceDestroy() - { - destroySwapChain(); - m_scaling_renderer.DetachDevice(); - m_modern_swap_chain_available = false; - } - void SwapChain_D3D11::onWindowCreate() - { - // 目前窗口的重新创建只会被交换链触发,所以这里留空 - } - void SwapChain_D3D11::onWindowDestroy() - { - // 目前窗口的重新创建只会被交换链触发,所以这里留空 - } - void SwapChain_D3D11::onWindowActive() - { - if (!dxgi_swapchain) - return; - _log("onWindowActive"); - m_swapchain_want_present_reset = TRUE; - enterExclusiveFullscreenTemporarily(); - } - void SwapChain_D3D11::onWindowInactive() - { - if (!dxgi_swapchain) - return; - _log("onWindowInactive"); - leaveExclusiveFullscreenTemporarily(); - } - void SwapChain_D3D11::onWindowSize(core::Vector2U size) - { - if (size.x == 0 || size.y == 0) - return; // 忽略窗口最小化 - if (!dxgi_swapchain) - return; // 此时交换链还未初始化 - if (m_is_composition_mode) - { - handleDirectCompositionWindowSize(size); - } - else - { - handleSwapChainWindowSize(size); - } - } - void SwapChain_D3D11::onWindowFullscreenStateChange(bool state) - { - if (!dxgi_swapchain) - return; - if (state) - enterExclusiveFullscreen(); - else - leaveExclusiveFullscreen(); - } - - bool SwapChain_D3D11::createSwapChain(bool fullscreen, DXGI_MODE_DESC1 const& mode, bool no_attachment) - { - _log("createSwapChain"); - - i18n_log_info("[core].SwapChain_D3D11.start_creating_swapchain"); - - // 必须成功的操作 - - if (!m_window->GetWindow()) - { - i18n_log_error("[core].SwapChain_D3D11.create_swapchain_failed_null_window"); - assert(false); return false; - } - if (!m_device->GetD3D11Device()) - { - i18n_log_error("[core].SwapChain_D3D11.create_swapchain_failed_null_device"); - assert(false); return false; - } - - HRNew; - - // 填写交换链描述 - - m_swap_chain_info = getDefaultSwapChainInfo7(); - m_swap_chain_fullscreen_info = {}; - - // 切换为 FLIP 交换链模型,独占全屏也支持 - if (m_modern_swap_chain_available) { - m_swap_chain_info.BufferCount = 3; - m_swap_chain_info.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; - } - - if (!fullscreen) - { - // 获取窗口尺寸 - RECT rc = {}; - if (!GetClientRect(m_window->GetWindow(), &rc)) - { - HRGet = HRESULT_FROM_WIN32(GetLastError()); - HRCheckCallReturnBool("GetClientRect"); - } - if (rc.right <= rc.left || rc.bottom <= rc.top) - { - i18n_log_error_fmt("[core].SwapChain_D3D11.create_swapchain_failed_invalid_size_fmt", - rc.right - rc.left, - rc.bottom - rc.top); - assert(false); return false; - } - // 使用窗口尺寸 - m_swap_chain_info.Width = static_cast(rc.right - rc.left); - m_swap_chain_info.Height = static_cast(rc.bottom - rc.top); - // 进一步配置 FLIP 交换链模型 - if (m_modern_swap_chain_available) - { - m_swap_chain_info.BufferCount = 3; // 三个缓冲区能带来更平稳的性能 - m_swap_chain_info.Scaling = DXGI_SCALING_NONE; // 禁用 DWM 对交换链的缩放 - m_swap_chain_info.Flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; // 低延迟呈现技术 - m_swap_chain_info.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING; // 立即刷新和可变刷新率 - } - } - else - { - // 使用显示模式尺寸 - m_swap_chain_info.Width = mode.Width; - m_swap_chain_info.Height = mode.Height; - // 允许切换显示模式 - m_swap_chain_info.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; - // 配置全屏模式 - m_swap_chain_fullscreen_info.RefreshRate = mode.RefreshRate; - m_swap_chain_fullscreen_info.ScanlineOrdering = mode.ScanlineOrdering; - m_swap_chain_fullscreen_info.Scaling = mode.Scaling; - m_swap_chain_fullscreen_info.Windowed = TRUE; // 稍后再切换到独占全屏 - } - - // 创建交换链 - - HRGet = m_device->GetDXGIFactory2()->CreateSwapChainForHwnd( - m_device->GetD3D11Device(), - m_window->GetWindow(), - &m_swap_chain_info, - fullscreen ? &m_swap_chain_fullscreen_info : NULL, - NULL, - &dxgi_swapchain); - HRCheckCallReturnBool("IDXGIFactory2::CreateSwapChainForHwnd"); - - m_swap_chain_fullscreen_mode = fullscreen; - - // 关闭傻逼快捷键,别他妈乱切换了 - // 注意这里他妈的有坑,新创建的 DXGI 工厂和交换链内部的的不是同一个 - - HRGet = Platform::DXGI::MakeSwapChainWindowAssociation( - dxgi_swapchain.Get(), DXGI_MWA_NO_ALT_ENTER); - HRCheckCallReturnBool("IDXGIFactory1::MakeWindowAssociation -> DXGI_MWA_NO_ALT_ENTER"); - - // 设置设备最大帧延迟为 1 - - HRGet = Platform::DXGI::SetDeviceMaximumFrameLatency( - dxgi_swapchain.Get(), 1); - HRCheckCallReturnBool("IDXGIDevice1::SetMaximumFrameLatency -> 1"); - - // 如果启用了低延迟呈现技术,则设置交换链最大帧延迟为 1 - - if (m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) - { - HANDLE event_handle{}; - HRGet = Platform::DXGI::SetSwapChainMaximumFrameLatency( - dxgi_swapchain.Get(), 1, &event_handle); - HRCheckCallReturnBool("IDXGISwapChain2::SetMaximumFrameLatency -> 1"); - dxgi_swapchain_event.Attach(event_handle); - } - - //i18n_log_info("[core].SwapChain_D3D11.created_swapchain"); - - auto refresh_rate_string = fmt::format("{:.2f}Hz", (double)mode.RefreshRate.Numerator / (double)mode.RefreshRate.Denominator); - if (!fullscreen) refresh_rate_string = i18n("DXGI.DisplayMode.RefreshRate.Desktop"); - std::string_view swapchain_model = i18n("DXGI.SwapChain.SwapEffect.Discard"); - if (m_swap_chain_info.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) swapchain_model = i18n("DXGI.SwapChain.SwapEffect.FlipSequential"); - if (m_swap_chain_info.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD) swapchain_model = i18n("DXGI.SwapChain.SwapEffect.FlipDiscard"); - auto enable_or_disable = [](bool v) -> std::string_view { return v ? i18n("Enable") : i18n("Disable"); }; - i18n_log_info_fmt("[core].SwapChain_D3D11.created_swapchain_info_fmt" - , mode.Width, mode.Height, refresh_rate_string - , enable_or_disable(fullscreen) - , swapchain_model - , enable_or_disable(m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) - , enable_or_disable(m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) - ); - - // 渲染附件 - - if (!no_attachment) - { - if (!createRenderAttachment()) return false; - } - - // 标记 - - m_swapchain_want_present_reset = TRUE; - -#ifdef LUASTG_ENABLE_DIRECT2D - m_window->getTitleBarController().createResources(m_window->GetWindow(), m_device->GetD2D1DeviceContext()); -#endif - - return true; - } - void SwapChain_D3D11::destroySwapChain() - { - _log("destroySwapChain"); - - m_window->getTitleBarController().destroyResources(); - destroyDirectCompositionResources(); - destroyRenderAttachment(); - if (dxgi_swapchain) - { - // 退出独占全屏 - HRNew; - BOOL bFullscreen = FALSE; - Microsoft::WRL::ComPtr dxgi_output; - HRGet = dxgi_swapchain->GetFullscreenState(&bFullscreen, &dxgi_output); - HRCheckCallReport("IDXGISwapChain::GetFullscreenState"); - if (SUCCEEDED(hr) && bFullscreen) - { - i18n_log_info("[core].SwapChain_D3D11.leave_exclusive_fullscreen"); - HRGet = dxgi_swapchain->SetFullscreenState(FALSE, NULL); - HRCheckCallReport("IDXGISwapChain::SetFullscreenState -> FALSE"); - } - } - dxgi_swapchain_event.Close(); - dxgi_swapchain.Reset(); - } - void SwapChain_D3D11::waitFrameLatency(uint32_t timeout, bool reset) - { - //_log("waitFrameLatency"); - - if (m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) - { - if (reset && dxgi_swapchain) - { - HRNew; - - // 微软不知道写了什么狗屎bug,有时候dwm临时接管桌面合成后会导致上屏延迟多一倍 - // 重新设置最大帧延迟并创建延迟等待对象似乎能解决该问题 - dxgi_swapchain_event.Close(); - - Microsoft::WRL::ComPtr dxgi_swap_chain2; - HRGet = dxgi_swapchain.As(&dxgi_swap_chain2); - HRCheckCallReport("IDXGISwapChain1 -> IDXGISwapChain2"); - if (FAILED(hr)) return; - HRGet = dxgi_swap_chain2->SetMaximumFrameLatency(1); - HRCheckCallReport("IDXGISwapChain2::SetMaximumFrameLatency(1)"); - if (FAILED(hr)) return; - - dxgi_swapchain_event.Attach(dxgi_swap_chain2->GetFrameLatencyWaitableObject()); - } - if (dxgi_swapchain_event.IsValid()) - { - DWORD const result = WaitForSingleObject(dxgi_swapchain_event.Get(), timeout); - if (!(result == WAIT_OBJECT_0 || result == WAIT_TIMEOUT)) - { - gHRLastError; - i18n_core_system_call_report_error("WaitForSingleObject"); - } - } - } - } - bool SwapChain_D3D11::enterExclusiveFullscreenTemporarily() - { - if (!m_swap_chain_fullscreen_mode) - { - return true; - } - if (!dxgi_swapchain) - { - assert(false); return false; - } - - HRNew; - - BOOL get_state = FALSE; - HRGet = dxgi_swapchain->GetFullscreenState(&get_state, NULL); - HRCheckCallReturnBool("IDXGISwapChain::GetFullscreenState"); - - if (get_state) - { - return true; - } - - _log("IDXGISwapChain::SetFullscreenState -> TRUE\n"); - i18n_log_info("[core].SwapChain_D3D11.enter_exclusive_fullscreen"); - HRGet = dxgi_swapchain->SetFullscreenState(TRUE, NULL); - HRCheckCallReturnBool("IDXGISwapChain::SetFullscreenState -> TRUE"); - - return true; - } - bool SwapChain_D3D11::leaveExclusiveFullscreenTemporarily() - { - if (!m_swap_chain_fullscreen_mode) - { - return true; - } - if (!dxgi_swapchain) - { - assert(false); return false; - } - - HRNew; - - BOOL get_state = FALSE; - HRGet = dxgi_swapchain->GetFullscreenState(&get_state, NULL); - HRCheckCallReturnBool("IDXGISwapChain::GetFullscreenState"); - - if (!get_state) - { - return true; - } - - _log("IDXGISwapChain::SetFullscreenState -> FALSE\n"); - i18n_log_info("[core].SwapChain_D3D11.leave_exclusive_fullscreen"); - HRGet = dxgi_swapchain->SetFullscreenState(FALSE, NULL); - HRCheckCallReturnBool("IDXGISwapChain::SetFullscreenState -> FALSE"); - - m_window->setLayer(WindowLayer::Normal); // 强制取消窗口置顶 - - return true; - } - bool SwapChain_D3D11::enterExclusiveFullscreen() { - if (m_disable_exclusive_fullscreen) { - return false; - } - if (!dxgi_swapchain) { - assert(false); - return false; - } - if (dcomp_visual_swap_chain) { - return false; - } - - DXGI_MODE_DESC1 display_mode{}; - if (!findBestDisplayMode(m_window->GetWindow(), dxgi_swapchain.Get(), m_canvas_size, display_mode)) { - return false; - } - - dispatchEvent(EventType::SwapChainDestroy); - destroySwapChain(); - - m_window->setSize({ display_mode.Width, display_mode.Height }); - - if (!createSwapChain(true, display_mode, true /* 稍后创建渲染附件 */)) { - return false; - } - - HRNew; - - // 进入全屏 - i18n_log_info("[core].SwapChain_D3D11.enter_exclusive_fullscreen"); - HRGet = dxgi_swapchain->SetFullscreenState(TRUE, nullptr); - HRCheckCallReturnBool("IDXGISwapChain::SetFullscreenState -> TRUE"); - - // 需要重设交换链大小(特别是 Flip 交换链模型) - HRGet = dxgi_swapchain->ResizeBuffers(0, display_mode.Width, display_mode.Height, DXGI_FORMAT_UNKNOWN, m_swap_chain_info.Flags); - HRCheckCallReturnBool("IDXGISwapChain::ResizeBuffers"); - - // 创建渲染附件 - if (!createRenderAttachment()) { - return false; - } - if (!updateLetterBoxingRendererTransform()) { - return false; - } - - // 记录状态 - m_init = TRUE; - - // 广播 - dispatchEvent(EventType::SwapChainCreate); - - return true; - } - bool SwapChain_D3D11::leaveExclusiveFullscreen() - { - HRNew; - - BOOL get_state = FALSE; - HRGet = dxgi_swapchain->GetFullscreenState(&get_state, NULL); - HRCheckCallReturnBool("IDXGISwapChain::GetFullscreenState"); - - if (get_state) - { - i18n_log_info("[core].SwapChain_D3D11.leave_exclusive_fullscreen"); - HRGet = dxgi_swapchain->SetFullscreenState(FALSE, NULL); - HRCheckCallReturnBool("IDXGISwapChain::SetFullscreenState -> FALSE"); - } - - if (m_swap_chain_fullscreen_mode) - { - m_swap_chain_fullscreen_mode = FALSE; // 手动离开全屏模式 - - dispatchEvent(EventType::SwapChainDestroy); - destroySwapChain(); - - if (!createSwapChain(false, {}, false)) - { - return false; - } - - if (!updateLetterBoxingRendererTransform()) return false; - - // 记录状态 - m_init = TRUE; - - // 广播 - dispatchEvent(EventType::SwapChainCreate); - - return true; - } - - return true; - } - - bool SwapChain_D3D11::createDirectCompositionResources() - { - assert(m_modern_swap_chain_available); - _log("createDirectCompositionResources"); - - // 我们限制 DirectComposition 仅在 Windows 10+ 使用 - - HRNew; - - // 必须成功的操作 - -#ifdef LUASTG_ENABLE_DIRECT2D - Microsoft::WRL::ComPtr dxgi_device; - HRGet = m_device->GetD3D11Device()->QueryInterface(IID_PPV_ARGS(&dxgi_device)); - HRCheckCallReturnBool("ID3D11Device::QueryInterface -> IDXGIDevice"); - - // 创建基本组件 - - HRGet = dcomp_loader.CreateDevice(dxgi_device.Get(), IID_PPV_ARGS(&dcomp_desktop_device)); - HRCheckCallReturnBool("DCompositionCreateDevice"); -#else - HRGet = dcomp_loader.CreateDevice(nullptr, IID_PPV_ARGS(&dcomp_desktop_device)); - HRCheckCallReturnBool("DCompositionCreateDevice"); -#endif - - #ifdef _DEBUG - Microsoft::WRL::ComPtr dcomp_device_debug; - HRGet = dcomp_desktop_device.As(&dcomp_device_debug); - HRCheckCallReport("IDCompositionDesktopDevice::QueryInterface -> IDCompositionDeviceDebug"); - if (SUCCEEDED(hr)) - { - HRGet = dcomp_device_debug->EnableDebugCounters(); - HRCheckCallReport("IDCompositionDeviceDebug::EnableDebugCounters"); - } - #endif - - HRGet = dcomp_desktop_device->CreateTargetForHwnd(m_window->GetWindow(), TRUE, &dcomp_target); - HRCheckCallReturnBool("IDCompositionDesktopDevice::CreateTargetForHwnd"); - - - HRGet = dcomp_desktop_device->CreateVisual(&dcomp_visual_swap_chain); - HRCheckCallReturnBool("IDCompositionDesktopDevice::CreateVisual"); - - // 桌面合成引擎模式,创建背景平面+交换链平面 - - if (m_is_composition_mode) - { - HRGet = dcomp_desktop_device->CreateVisual(&dcomp_visual_root); - HRCheckCallReturnBool("IDCompositionDesktopDevice::CreateVisual"); - -#ifdef LUASTG_ENABLE_DIRECT2D - HRGet = dcomp_desktop_device->CreateVisual(&dcomp_visual_title_bar); - HRCheckCallReturnBool("IDCompositionDesktopDevice::CreateVisual"); - - if (!swap_chain_title_bar.create( - m_device->GetDXGIFactory2(), - m_device->GetD3D11Device(), - m_device->GetD2D1DeviceContext(), - m_window->_getCurrentSize() - )) { - return false; - } - // 标题栏交换链需要的时候再使用 - - HRGet = dcomp_visual_title_bar->SetContent(swap_chain_title_bar.GetDXGISwapChain1()); - HRCheckCallReturnBool("IDCompositionVisual2::SetContent"); -#endif - } - - // 把交换链塞进可视物 - - HRGet = dcomp_visual_swap_chain->SetContent(dxgi_swapchain.Get()); - HRCheckCallReturnBool("IDCompositionVisual2::SetContent"); - - HRGet = dcomp_visual_swap_chain->SetBitmapInterpolationMode(DCOMPOSITION_BITMAP_INTERPOLATION_MODE_LINEAR); // TODO: 支持改为临近缩放 - HRCheckCallReturnBool("IDCompositionVisual2::SetBitmapInterpolationMode -> DCOMPOSITION_BITMAP_INTERPOLATION_MODE_LINEAR"); - - // 构建视觉树 - - if (m_is_composition_mode) - { - HRGet = dcomp_visual_root->AddVisual(dcomp_visual_swap_chain.Get(), TRUE, nullptr); - HRCheckCallReturnBool("IDCompositionVisual2::AddVisual"); - - HRGet = dcomp_target->SetRoot(dcomp_visual_root.Get()); - HRCheckCallReturnBool("IDCompositionTarget::SetRoot"); - - // 设置变换并提交 - - if (!updateDirectCompositionTransform()) return false; - } - else - { - HRGet = dcomp_target->SetRoot(dcomp_visual_swap_chain.Get()); - HRCheckCallReturnBool("IDCompositionTarget::SetRoot"); - - // 直接提交 - if (!commitDirectComposition()) return false; - } - - return true; - } - void SwapChain_D3D11::destroyDirectCompositionResources() - { - _log("destroyDirectCompositionResources"); - - // 我也不知道为什么要这样清理,但是不这么做的话会出现内存不足,后续创建设备和资源的操作会失败 - - HRNew; - - if (dcomp_target) - { - HRGet = dcomp_target->SetRoot(NULL); - HRCheckCallReport("IDCompositionTarget::SetRoot -> NULL"); - } - if (dcomp_visual_root) - { - HRGet = dcomp_visual_root->RemoveAllVisuals(); - HRCheckCallReport("IDCompositionVisual2::RemoveAllVisuals"); - } - if (dcomp_visual_swap_chain) - { - HRGet = dcomp_visual_swap_chain->SetContent(NULL); - HRCheckCallReport("IDCompositionVisual2::SetContent -> NULL"); - } -#ifdef LUASTG_ENABLE_DIRECT2D - if (dcomp_visual_title_bar) - { - HRGet = dcomp_visual_title_bar->SetContent(NULL); - HRCheckCallReport("IDCompositionVisual2::SetContent -> NULL"); - } -#endif - - dcomp_target.Reset(); - dcomp_visual_root.Reset(); - dcomp_visual_swap_chain.Reset(); -#ifdef LUASTG_ENABLE_DIRECT2D - dcomp_visual_title_bar.Reset(); - swap_chain_title_bar.destroy(); - m_title_bar_attached = false; -#endif - - if (dcomp_desktop_device) - { - HRGet = dcomp_desktop_device->Commit(); - HRCheckCallReport("IDCompositionDesktopDevice::Commit"); - HRGet = dcomp_desktop_device->WaitForCommitCompletion(); - HRCheckCallReport("IDCompositionDesktopDevice::WaitForCommitCompletion"); - } - - dcomp_desktop_device.Reset(); - } - bool SwapChain_D3D11::updateDirectCompositionTransform() - { - assert(m_is_composition_mode); - _log("updateDirectCompositionTransform"); - - HRNew; - - // 必须成功的操作 - - DXGI_SWAP_CHAIN_DESC1 desc1 = {}; - HRGet = dxgi_swapchain->GetDesc1(&desc1); - HRCheckCallReturnBool("IDXGISwapChain1::GetDesc1"); - - RECT rc = {}; - if (!GetClientRect(m_window->GetWindow(), &rc)) - { - HRGet = HRESULT_FROM_WIN32(GetLastError()); - HRCheckCallReturnBool("GetClientRect"); - } - auto const window_size_u = Vector2U( - (uint32_t)(rc.right - rc.left), - (uint32_t)(rc.bottom - rc.top)); - - // 让背景铺满整个画面(由 Window Class 的背景来处理) - - - // 设置交换链内容内接放大 - - if (m_scaling_mode == SwapChainScalingMode::Stretch) - { - auto const mat_d2d = D2D1::Matrix3x2F::Scale( - (float)window_size_u.x / (float)desc1.Width, - (float)window_size_u.y / (float)desc1.Height); - HRGet = dcomp_visual_swap_chain->SetTransform(mat_d2d); - HRCheckCallReturnBool("IDCompositionVisual2::SetTransform"); - } - else - { - DXGI_MATRIX_3X2_F mat{}; - if (makeLetterboxing(window_size_u, Vector2U(desc1.Width, desc1.Height), mat)) - { - D2D_MATRIX_3X2_F const mat_d2d = { - mat._11, mat._12, - mat._21, mat._22, - mat._31, mat._32, - }; - HRGet = dcomp_visual_swap_chain->SetTransform(mat_d2d); - HRCheckCallReturnBool("IDCompositionVisual2::SetTransform"); - } - else - { - auto const mat_d2d = D2D1::Matrix3x2F::Identity(); - HRGet = dcomp_visual_swap_chain->SetTransform(mat_d2d); - HRCheckCallReturnBool("IDCompositionVisual2::SetTransform"); - } - } - - // 同步窗口宽度 - -#ifdef LUASTG_ENABLE_DIRECT2D - if (!swap_chain_title_bar.setSize(Vector2U(window_size_u.x, swap_chain_title_bar.getSize().y))) { - return false; - } -#endif - - // 提交 - - if (!commitDirectComposition()) return false; - - return true; - } - bool SwapChain_D3D11::commitDirectComposition() - { - _log("commitDirectComposition"); - - HRNew; - - HRGet = dcomp_desktop_device->Commit(); - HRCheckCallReturnBool("IDCompositionDesktopDevice::Commit"); - - HRGet = dcomp_desktop_device->WaitForCommitCompletion(); - HRCheckCallReturnBool("IDCompositionDesktopDevice::WaitForCommitCompletion"); - - return true; - } - bool SwapChain_D3D11::createCompositionSwapChain(Vector2U size, bool latency_event) - { - _log("createCompositionSwapChain"); - - // 我们限制 DirectComposition 仅在 Windows 10+ 使用 - - HRNew; - - i18n_log_info("[core].SwapChain_D3D11.start_creating_swapchain"); - - // 检查组件 - - if (!m_window->GetWindow()) - { - i18n_log_error("[core].SwapChain_D3D11.create_swapchain_failed_null_window"); - assert(false); return false; - } - if (!m_device->GetD3D11Device()) - { - i18n_log_error("[core].SwapChain_D3D11.create_swapchain_failed_null_device"); - assert(false); return false; - } - - // 填充交换链描述 - - m_swap_chain_info = getDefaultSwapChainInfo10(); - m_swap_chain_info.Width = size.x; - m_swap_chain_info.Height = size.y; - m_swap_chain_info.Scaling = DXGI_SCALING_STRETCH; // DirectComposition 要求这个缩放模式 - - if (m_device->IsTearingSupport()) // Windows 10+ 且要求系统支持 - { - m_swap_chain_info.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING; // 允许撕裂 - } - if (latency_event) - { - m_swap_chain_info.BufferCount = 3; // 三重缓冲 - m_swap_chain_info.Flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; // 低延迟渲染 - } - - // 创建交换链 - - HRGet = m_device->GetDXGIFactory2()->CreateSwapChainForComposition( - m_device->GetD3D11Device(), - &m_swap_chain_info, NULL, - &dxgi_swapchain); - HRCheckCallReturnBool("IDXGIFactory2::CreateSwapChainForComposition"); - - m_swap_chain_fullscreen_mode = FALSE; - - // 设置最大帧延迟为 1 - - HRGet = Platform::DXGI::SetDeviceMaximumFrameLatency(dxgi_swapchain.Get(), 1); - HRCheckCallReturnBool("IDXGIDevice1::SetMaximumFrameLatency -> 1"); - - if (m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) - { - HANDLE event_handle{}; - HRGet = Platform::DXGI::SetSwapChainMaximumFrameLatency( - dxgi_swapchain.Get(), 1, &event_handle); - HRCheckCallReturnBool("IDXGISwapChain2::SetMaximumFrameLatency -> 1"); - dxgi_swapchain_event.Attach(event_handle); - } - - // 打印信息 - - auto refresh_rate_string = i18n("DXGI.DisplayMode.RefreshRate.Desktop"); - std::string_view swapchain_model = i18n("DXGI.SwapChain.SwapEffect.FlipSequential"); - if (m_swap_chain_info.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD) swapchain_model = i18n("DXGI.SwapChain.SwapEffect.FlipDiscard"); - auto enable_or_disable = [](bool v) -> std::string_view { return v ? i18n("Enable") : i18n("Disable"); }; - i18n_log_info_fmt("[core].SwapChain_D3D11.created_swapchain_info_fmt" - , size.x, size.y, refresh_rate_string - , i18n("Disable") // 没有独占全屏 - , swapchain_model - , enable_or_disable(m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) - , enable_or_disable(m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) - ); - - // 渲染附件 - - if (!createRenderAttachment()) return false; - - // 创建合成器 - - if (!createDirectCompositionResources()) return false; - - // 标记 - - m_swapchain_want_present_reset = TRUE; - -#ifdef LUASTG_ENABLE_DIRECT2D - m_window->getTitleBarController().createResources(m_window->GetWindow(), m_device->GetD2D1DeviceContext()); -#endif - - return true; - } - - bool SwapChain_D3D11::createSwapChainRenderTarget() - { - _log("createSwapChainRenderTarget"); - - if (!dxgi_swapchain) - { - assert(false); return false; - } - - if (!m_device->GetD3D11Device()) - { - assert(false); return false; - } - - HRNew; - - Microsoft::WRL::ComPtr d3d11_texture2d; - HRGet = dxgi_swapchain->GetBuffer(0, IID_PPV_ARGS(&d3d11_texture2d)); - HRCheckCallReturnBool("IDXGISwapChain::GetBuffer -> 0"); - - // TODO: 线性颜色空间 - HRGet = m_device->GetD3D11Device()->CreateRenderTargetView(d3d11_texture2d.Get(), NULL, &m_swap_chain_d3d11_rtv); - HRCheckCallReturnBool("ID3D11Device::CreateRenderTargetView"); - - Microsoft::WRL::ComPtr dxgi_surface; - HRGet = dxgi_swapchain->GetBuffer(0, IID_PPV_ARGS(&dxgi_surface)); - HRCheckCallReturnBool("IDXGISwapChain::GetBuffer -> 0"); - -#ifdef LUASTG_ENABLE_DIRECT2D - // TODO: 线性颜色空间 - D2D1_BITMAP_PROPERTIES1 d2d1_bitmap_info{}; - d2d1_bitmap_info.pixelFormat.format = COLOR_BUFFER_FORMAT; - d2d1_bitmap_info.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; - d2d1_bitmap_info.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; - HRGet = m_device->GetD2D1DeviceContext()->CreateBitmapFromDxgiSurface(dxgi_surface.Get(), &d2d1_bitmap_info, &m_swap_chain_d2d1_bitmap); - HRCheckCallReturnBool("ID2D1DeviceContext::CreateBitmapFromDxgiSurface"); -#endif - - return true; - } - void SwapChain_D3D11::destroySwapChainRenderTarget() - { - _log("destroySwapChainRenderTarget"); - - if (m_device->GetD3D11DeviceContext()) - { - m_device->GetD3D11DeviceContext()->ClearState(); - m_device->GetD3D11DeviceContext()->Flush(); - } - m_swap_chain_d3d11_rtv.Reset(); -#ifdef LUASTG_ENABLE_DIRECT2D - m_swap_chain_d2d1_bitmap.Reset(); -#endif - } - bool SwapChain_D3D11::createCanvasColorBuffer() - { - _log("createCanvasColorBuffer"); - - if (m_canvas_size.x == 0 || m_canvas_size.y == 0) - { - assert(false); return false; - } - - if (!m_device->GetD3D11Device()) - { - assert(false); return false; - } - - HRNew; - - // Color Buffer - - D3D11_TEXTURE2D_DESC cb_info = {}; - cb_info.Width = m_canvas_size.x; - cb_info.Height = m_canvas_size.y; - cb_info.MipLevels = 1; - cb_info.ArraySize = 1; - cb_info.Format = COLOR_BUFFER_FORMAT; - cb_info.SampleDesc.Count = 1; - cb_info.Usage = D3D11_USAGE_DEFAULT; - cb_info.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; - - Microsoft::WRL::ComPtr cb_texture; - HRGet = m_device->GetD3D11Device()->CreateTexture2D(&cb_info, NULL, &cb_texture); - HRCheckCallReturnBool("ID3D11Device::CreateTexture2D"); - - // Shader Resource - - D3D11_SHADER_RESOURCE_VIEW_DESC srv_info = {}; - srv_info.Format = cb_info.Format; // TODO: 线性颜色空间 - srv_info.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - srv_info.Texture2D.MipLevels = cb_info.MipLevels; - - HRGet = m_device->GetD3D11Device()->CreateShaderResourceView(cb_texture.Get(), &srv_info, &m_canvas_d3d11_srv); - HRCheckCallReturnBool("ID3D11Device::CreateShaderResourceView"); - - // Render Target - - D3D11_RENDER_TARGET_VIEW_DESC rtv_info = {}; - rtv_info.Format = cb_info.Format; // TODO: 线性颜色空间 - rtv_info.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; - - HRGet = m_device->GetD3D11Device()->CreateRenderTargetView(cb_texture.Get(), &rtv_info, &m_canvas_d3d11_rtv); - HRCheckCallReturnBool("ID3D11Device::CreateRenderTargetView"); - - return true; - } - void SwapChain_D3D11::destroyCanvasColorBuffer() - { - _log("destroyCanvasColorBuffer"); - - m_canvas_d3d11_srv.Reset(); - m_canvas_d3d11_rtv.Reset(); - } - bool SwapChain_D3D11::createCanvasDepthStencilBuffer() - { - _log("createCanvasDepthStencilBuffer"); - - if (m_canvas_size.x == 0 || m_canvas_size.y == 0) - { - assert(false); return false; - } - - if (!m_device->GetD3D11Device()) - { - assert(false); return false; - } - - HRNew; - - // Depth Stencil Buffer - - D3D11_TEXTURE2D_DESC ds_info = {}; - ds_info.Width = m_canvas_size.x; - ds_info.Height = m_canvas_size.y; - ds_info.MipLevels = 1; - ds_info.ArraySize = 1; - ds_info.Format = DEPTH_BUFFER_FORMAT; - ds_info.SampleDesc.Count = 1; - ds_info.Usage = D3D11_USAGE_DEFAULT; - ds_info.BindFlags = D3D11_BIND_DEPTH_STENCIL; - - Microsoft::WRL::ComPtr ds_texture; - HRGet = m_device->GetD3D11Device()->CreateTexture2D(&ds_info, NULL, &ds_texture); - HRCheckCallReturnBool("ID3D11Device::CreateTexture2D"); - - // Depth Stencil View - - D3D11_DEPTH_STENCIL_VIEW_DESC dsv_info = {}; - dsv_info.Format = ds_info.Format; - dsv_info.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; - - HRGet = m_device->GetD3D11Device()->CreateDepthStencilView(ds_texture.Get(), &dsv_info, &m_canvas_d3d11_dsv); - HRCheckCallReturnBool("ID3D11Device::CreateDepthStencilView"); - - return true; - } - void SwapChain_D3D11::destroyCanvasDepthStencilBuffer() - { - _log("destroyCanvasDepthStencilBuffer"); - - m_canvas_d3d11_dsv.Reset(); - } - bool SwapChain_D3D11::createRenderAttachment() - { - _log("createRenderAttachment"); - - if (!createSwapChainRenderTarget()) return false; - if (m_is_composition_mode) - { - // 此时画布颜色缓冲区就是交换链的后台缓冲区 - m_canvas_d3d11_srv.Reset(); // 不使用 - m_canvas_d3d11_rtv = m_swap_chain_d3d11_rtv; - } - else - { - if (!createCanvasColorBuffer()) return false; - } - if (!createCanvasDepthStencilBuffer()) return false; - return true; - } - void SwapChain_D3D11::destroyRenderAttachment() - { - _log("destroyRenderAttachment"); - - destroyCanvasDepthStencilBuffer(); - destroyCanvasColorBuffer(); - destroySwapChainRenderTarget(); - } - void SwapChain_D3D11::applyRenderAttachment() - { - //_log("applyRenderAttachment"); - - if (auto* ctx = m_device->GetD3D11DeviceContext()) - { - ID3D11RenderTargetView* rtvs[1] = { m_canvas_d3d11_rtv.Get() }; - ctx->OMSetRenderTargets(1, rtvs, m_canvas_d3d11_dsv.Get()); - } - } - void SwapChain_D3D11::clearRenderAttachment() - { - //_log("clearRenderAttachment"); - - if (auto* ctx = m_device->GetD3D11DeviceContext()) - { - if (m_canvas_d3d11_rtv) - { - FLOAT const clear_color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; - ctx->ClearRenderTargetView(m_canvas_d3d11_rtv.Get(), clear_color); - } - if (m_canvas_d3d11_dsv) - { - ctx->ClearDepthStencilView(m_canvas_d3d11_dsv.Get(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0u); - } - ctx->Flush(); // 让命令立即提交到 GPU - } - } - - bool SwapChain_D3D11::updateLetterBoxingRendererTransform() - { - _log("updateLetterBoxingRendererTransform"); - assert(m_canvas_d3d11_srv); - assert(m_swap_chain_d3d11_rtv); - - return m_scaling_renderer.UpdateTransform( - m_canvas_d3d11_srv.Get(), - m_swap_chain_d3d11_rtv.Get(), - m_scaling_mode == SwapChainScalingMode::Stretch - ); - } - bool SwapChain_D3D11::presentLetterBoxingRenderer() - { - _log("presentLetterBoxingRenderer"); - assert(m_canvas_d3d11_srv); - assert(m_swap_chain_d3d11_rtv); - - return m_scaling_renderer.Draw( - m_canvas_d3d11_srv.Get(), - m_swap_chain_d3d11_rtv.Get(), - true - ); - } - - bool SwapChain_D3D11::handleDirectCompositionWindowSize(Vector2U size) - { - _log("handleDirectCompositionWindowSize"); - - if (size.x == 0 || size.y == 0) - { - assert(false); return false; - } - - if (!dxgi_swapchain) - { - assert(false); return false; - } - - // 此时交换链和画布一致,不应该修改交换链本身,而是修改合成变换 - - if (!updateDirectCompositionTransform()) return false; - - return true; - } - bool SwapChain_D3D11::handleSwapChainWindowSize(Vector2U size) - { - _log("handleSwapChainWindowSize"); - - if (size.x == 0 || size.y == 0) - { - assert(false); return false; - } - - if (!dxgi_swapchain) - { - assert(false); return false; - } - - // 此时交换链和画布分离,应该重新调整交换链尺寸 - - HRNew; - - destroySwapChainRenderTarget(); - - HRGet = dxgi_swapchain->ResizeBuffers(0, size.x, size.y, DXGI_FORMAT_UNKNOWN, m_swap_chain_info.Flags); - HRCheckCallReturnBool("IDXGISwapChain::ResizeBuffers"); - - if (!createSwapChainRenderTarget()) return false; - - if (!updateLetterBoxingRendererTransform()) return false; - - // TODO: 对于现代交换链模型,由于使用了 DirectComposition,还需要重新设置一次 Content - - return true; - } - - bool SwapChain_D3D11::setWindowMode(Vector2U size) - { - _log("setWindowMode"); - - if (size.x < 1 || size.y < 1) - { - i18n_log_error_fmt("[core].SwapChain_D3D11.create_swapchain_failed_invalid_size_fmt", size.x, size.y); - assert(false); return false; - } - - if (m_enable_composition || (!m_disable_composition && m_modern_swap_chain_available && checkMultiPlaneOverlaySupport(m_device->GetD3D11Device()))) - { - m_is_composition_mode = true; - return setCompositionWindowMode(size); - } - else - { - m_is_composition_mode = false; - } - - dispatchEvent(EventType::SwapChainDestroy); - destroySwapChain(); - - if (!m_disable_modern_swap_chain && m_modern_swap_chain_available) - { - // TODO: 这样就没法独占全屏了,因为拿不到包含的Output - m_canvas_size = size; - if (!createCompositionSwapChain(size, /* latency event */ true)) // 让它创建渲染附件 - { - return false; - } - } - else - { - m_canvas_size = size; - if (!createSwapChain(false, {}, false)) // 让它创建渲染附件 - { - return false; - } - } - - // 更新数据 - - m_init = TRUE; - if (!updateLetterBoxingRendererTransform()) return false; - - // 通知各个组件交换链已重新创建 - - dispatchEvent(EventType::SwapChainCreate); - - return true; - } - bool SwapChain_D3D11::setCompositionWindowMode(Vector2U size) - { - _log("setCompositionWindowMode"); - - // 销毁旧交换链 - - dispatchEvent(EventType::SwapChainDestroy); - destroySwapChain(); - - // 创建交换链 - - bool latency_event = true; - m_canvas_size = size; - if (!createCompositionSwapChain(size, latency_event)) - { - return false; - } - - // 更新数据 - - m_init = TRUE; - - // 通知各个组件交换链已重新创建 - - dispatchEvent(EventType::SwapChainCreate); - - return true; - } - - bool SwapChain_D3D11::setCanvasSize(Vector2U size) - { - _log("setCanvasSize"); - - if (size.x == 0 || size.y == 0) - { - i18n_log_error_fmt("[core].SwapChain_D3D11.resize_canvas_failed_invalid_size_fmt", - size.x, size.y); - assert(false); return false; - } - - m_canvas_size = size; - - // TODO: 如果尺寸没变,是不是可以直接返回? - - if (!dxgi_swapchain) - { - return true; // 当交换链还未初始化时,仅保存画布尺寸 - } - - dispatchEvent(EventType::SwapChainDestroy); - - if (m_is_composition_mode) - { - // 对于合成交换链,由于交换链和画布是一致的,所以要调整交换链尺寸 - - destroyRenderAttachment(); - - HRNew; - HRGet = dxgi_swapchain->ResizeBuffers(0, size.x, size.y, DXGI_FORMAT_UNKNOWN, m_swap_chain_info.Flags); - HRCheckCallReturnBool("IDXGISwapChain::ResizeBuffers"); - - if (!createRenderAttachment()) return false; - - if (!updateDirectCompositionTransform()) return false; - } - else - { - // 对于普通交换链,由于画布是独立的,只需重新创建画布 - - destroyCanvasDepthStencilBuffer(); - destroyCanvasColorBuffer(); - - if (!createCanvasColorBuffer()) return false; - if (!createCanvasDepthStencilBuffer()) return false; - - if (!updateLetterBoxingRendererTransform()) return false; - } - - dispatchEvent(EventType::SwapChainCreate); - - if (!m_is_composition_mode && m_swap_chain_fullscreen_mode) - { - // TODO: LuaSTG 那边会先调用 setCanvasSize 再调用 setWindowMode 触发两次交换链创建 - // 重新选择合适的独占全屏模式 - leaveExclusiveFullscreen(); - enterExclusiveFullscreen(); - } - - return true; - } - - void SwapChain_D3D11::setScalingMode(SwapChainScalingMode mode) - { - m_scaling_mode = mode; - if (m_is_composition_mode) - updateDirectCompositionTransform(); - else - updateLetterBoxingRendererTransform(); - } - - void SwapChain_D3D11::waitFrameLatency() - { - if (m_swapchain_want_present_reset) - { - m_swapchain_want_present_reset = FALSE; - waitFrameLatency(1000, true); - } - else - { - waitFrameLatency(1000, false); - } - } - void SwapChain_D3D11::setVSync(bool enable) - { - m_swap_chain_vsync = enable; - } - bool SwapChain_D3D11::present() - { - HRESULT hr = S_OK; - - // 手动合成画面的情况下,通过内接缩放渲染器来缩放显示 - - if (!m_is_composition_mode) { - tracy_d3d11_context_zone(m_device->GetTracyContext(), "PreScaling"); - if (!presentLetterBoxingRenderer()) { - return false; - } - m_device->GetD3D11DeviceContext()->Flush(); // 立即提交命令到 GPU - } - - // 绘制标题栏 - -#ifdef LUASTG_ENABLE_DIRECT2D - if (m_is_composition_mode) { - tracy_d3d11_context_zone(m_device->GetTracyContext(), "TitleBarComposition"); - // 绘制标题栏到单独的表面 - if (m_window->getTitleBarController().isVisible()) { - if (!m_title_bar_attached) { - HRGet = dcomp_visual_root->AddVisual(dcomp_visual_title_bar.Get(), TRUE, dcomp_visual_swap_chain.Get()); - HRCheckCallReturnBool("IDCompositionVisual2::AddVisual"); - if (!commitDirectComposition()) return false; - m_title_bar_attached = true; - } - auto const swap_chain_size = swap_chain_title_bar.getSize(); - auto const title_bar_height = m_window->getTitleBarController().getHeight(); - if (title_bar_height != swap_chain_size.y) { - if (!swap_chain_title_bar.setSize(Vector2U(swap_chain_size.x, title_bar_height))) { - return false; - } - } - swap_chain_title_bar.clearRenderTarget(); - m_window->getTitleBarController().draw(swap_chain_title_bar.GetD2D1Bitmap1()); - if (!swap_chain_title_bar.present()) { - return false; - } - } - else if (m_title_bar_attached) { - HRGet = dcomp_visual_root->RemoveVisual(dcomp_visual_title_bar.Get()); - HRCheckCallReturnBool("IDCompositionVisual2::RemoveVisual"); - if (!commitDirectComposition()) return false; - m_title_bar_attached = false; - } - } - else { - tracy_d3d11_context_zone(m_device->GetTracyContext(), "DrawTitleBar"); - // 绘制标题栏到交换链上,而不是画布上 - m_window->getTitleBarController().draw(m_swap_chain_d2d1_bitmap.Get()); - } -#endif - - // 呈现 - - UINT interval = 0; - UINT flags = 0; - if (isModernSwapChainModel(m_swap_chain_info)) { - // 现代交换链模型 - if (!m_swap_chain_vsync && (m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING)) { - // 如果禁用了垂直同步,且支持 DXGI_FEATURE_PRESENT_ALLOW_TEARING 功能,使用该模式获得最低延迟 - // 如果系统、硬件(特别是显示器)、驱动支持可变刷新率,那么将不会造成画面撕裂 - flags |= DXGI_PRESENT_ALLOW_TEARING; - } - else { - // 异步三重缓冲模式 - flags |= DXGI_PRESENT_DO_NOT_WAIT; - } - } - else { - // 传统交换链模型,通过指定同步间隔开/关垂直同步 - // 注意:从 Windows 8 开始才支持 DXGI_PRESENT_DO_NOT_WAIT - interval = m_swap_chain_vsync ? 1 : 0; - } - hr = gHR = dxgi_swapchain->Present(interval, flags); - - // 清空渲染状态并丢弃内容 - - m_device->GetD3D11DeviceContext()->ClearState(); - m_device->GetD3D11DeviceContext1()->DiscardView(m_swap_chain_d3d11_rtv.Get()); - - // 检查结果 - - if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) { - // 设备丢失 - return m_device->handleDeviceLost(); - } - else if (hr != DXGI_ERROR_WAS_STILL_DRAWING && FAILED(hr)) { - i18n_core_system_call_report_error("IDXGISwapChain::Present"); - return false; - } - - // 检查 DXGI 工厂有效性 - - if (!m_device->validateDXGIFactory()) - return false; - - return true; - } - - bool SwapChain_D3D11::saveSnapshotToFile(StringView path) - { - std::wstring wpath(utf8::to_wstring(path)); - - HRESULT hr = S_OK; - - Microsoft::WRL::ComPtr d3d11_resource; - m_canvas_d3d11_rtv->GetResource(&d3d11_resource); - - hr = gHR = DirectX::SaveWICTextureToFile( - m_device->GetD3D11DeviceContext(), - d3d11_resource.Get(), - GUID_ContainerFormatJpeg, - wpath.c_str(), - &GUID_WICPixelFormat24bppBGR); - if (FAILED(hr)) - { - i18n_core_system_call_report_error("DirectX::SaveWICTextureToFile"); - return false; - } - - return true; - } - - SwapChain_D3D11::SwapChain_D3D11(Window_Win32* p_window, Direct3D11::Device* p_device) - : m_window(p_window) - , m_device(p_device) - { - assert(p_window); - assert(p_device); - auto const& gs = core::ConfigurationLoader::getInstance().getGraphicsSystem(); - m_modern_swap_chain_available = checkModernSwapChainModelAvailable(m_device->GetD3D11Device()); - m_disable_exclusive_fullscreen = !gs.isAllowExclusiveFullscreen(); - m_disable_modern_swap_chain = !gs.isAllowModernSwapChain(); - m_enable_composition = false; // TODO - m_disable_composition = !gs.isAllowDirectComposition(); - m_scaling_renderer.AttachDevice(m_device->GetD3D11Device()); - m_window->addEventListener(this); - m_device->addEventListener(this); - } - SwapChain_D3D11::~SwapChain_D3D11() - { - m_window->removeEventListener(this); - m_device->removeEventListener(this); - destroySwapChain(); - m_scaling_renderer.DetachDevice(); - m_modern_swap_chain_available = false; - assert(m_eventobj.size() == 0); - assert(m_eventobj_late.size() == 0); - } - - bool SwapChain_D3D11::create(Window_Win32* p_window, Direct3D11::Device* p_device, SwapChain_D3D11** pp_swapchain) - { - try - { - *pp_swapchain = new SwapChain_D3D11(p_window, p_device); - return true; - } - catch (...) - { - *pp_swapchain = nullptr; - return false; - } - } - - bool ISwapChain::create(IWindow* p_window, IDevice* p_device, ISwapChain** pp_swapchain) - { - try - { - *pp_swapchain = new SwapChain_D3D11(dynamic_cast(p_window), dynamic_cast(p_device)); - return true; - } - catch (...) - { - *pp_swapchain = nullptr; - return false; - } - } -} +#include "core/Graphics/SwapChain_D3D11.hpp" +#include "windows/Window.hpp" +#include "core/Configuration.hpp" +#include "core/Logger.hpp" +#include "d3d11/GraphicsDeviceManager.hpp" +#include "windows/WindowsVersion.hpp" +#include "windows/DesktopWindowManager.hpp" +#include "windows/Direct3D11.hpp" +#include "windows/DXGI.hpp" +#include "windows/RuntimeLoader/D3DKMT.hpp" +#include "utf8.hpp" + +#include "ScreenGrab11.h" + +//#define _log(x) OutputDebugStringA(x "\n") +#define _log(x) + +#define HRNew HRESULT hr = S_OK; +#define HRGet hr = gHR +#define HRCheckCallReport(x) if (FAILED(hr)) { core::Logger::error("Windows API failed: " x); } +#define HRCheckCallReturnBool(x) if (FAILED(hr)) { core::Logger::error("Windows API failed: " x); assert(false); return false; } +#define HRCheckCallNoAssertReturnBool(x) if (FAILED(hr)) { core::Logger::error("Windows API failed: " x); return false; } + +#define NTNew NTSTATUS nt{}; +#define NTGet nt +#define NTCheckCallReport(x) if (nt != STATUS_SUCCESS) { core::Logger::error("Windows API failed: " x); } +#define NTCheckCallReportRuntime(x) if (nt != STATUS_SUCCESS) { core::Logger::error("Windows API failed: {}", x); } +#define NTCheckCallReturnBool(x) if (nt != STATUS_SUCCESS) { core::Logger::error("Windows API failed: " x); assert(false); return false; } +#define NTCheckCallNoAssertReturnBool(x) if (nt != STATUS_SUCCESS) { core::Logger::error("Windows API failed: " x); return false; } + +#define ReportError(x) core::Logger::error("Windows API failed: " x) + +namespace { + bool resolveOutput(HWND const window, IDXGISwapChain* const swap_chain, IDXGIOutput** const output_output) { + HRNew; + + auto const monitor = MonitorFromWindow(window, MONITOR_DEFAULTTONEAREST); + if (monitor == nullptr) { + ReportError("MonitorFromWindow (MONITOR_DEFAULT_TO_NEAREST)"); + return false; + } + + win32::com_ptr factory; + HRGet = swap_chain->GetParent(IID_PPV_ARGS(factory.put())); + HRCheckCallNoAssertReturnBool("IDXGISwapChain::GetParent -> IDXGIFactory1"); + + win32::com_ptr adapter; + win32::com_ptr output; + + for (UINT adapter_index = 0; SUCCEEDED(factory->EnumAdapters1(adapter_index, adapter.put())); adapter_index++) { + for (UINT output_index = 0; SUCCEEDED(adapter->EnumOutputs(output_index, output.put())); output_index++) { + DXGI_OUTPUT_DESC output_info{}; + HRGet = output->GetDesc(&output_info); + if (FAILED(hr)) { + ReportError("IDXGIOutput::GetDesc"); + continue; + } + if (monitor == output_info.Monitor) { + *output_output = output.detach(); + return true; + } + } + } + + return false; + } +} + +namespace core::Graphics +{ + constexpr DXGI_FORMAT const COLOR_BUFFER_FORMAT = DXGI_FORMAT_B8G8R8A8_UNORM; + constexpr DXGI_FORMAT const DEPTH_BUFFER_FORMAT = DXGI_FORMAT_D24_UNORM_S8_UINT; + + inline std::string_view to_string(DXGI_MODE_SCANLINE_ORDER v) + { + switch (v) + { + default: + case DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED: + assert(false); return "未知扫描方式"; + case DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE: + return "逐行扫描"; + case DXGI_MODE_SCANLINE_ORDER_UPPER_FIELD_FIRST: + return "隔行扫描(先奇数行)"; + case DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST: + return "隔行扫描(先偶数行)"; + } + } + inline std::string_view to_string(DXGI_MODE_SCALING v) + { + switch (v) + { + default: + case DXGI_MODE_SCALING_UNSPECIFIED: + return "自动缩放"; + case DXGI_MODE_SCALING_CENTERED: + return "居中显示"; + case DXGI_MODE_SCALING_STRETCHED: + return "拉伸全屏"; + } + } + + inline bool makeLetterboxing(Vector2U rect, Vector2U inner_rect, DXGI_MATRIX_3X2_F& mat) + { + if (rect == inner_rect) + { + return false; // 不需要 + } + else + { + double const hscale = (double)rect.x / (double)inner_rect.x; + double const vscale = (double)rect.y / (double)inner_rect.y; + double const scale = std::min(hscale, vscale); + double const width = scale * (double)inner_rect.x; + double const height = scale * (double)inner_rect.y; + double const x = ((double)rect.x - width) * 0.5; + double const y = ((double)rect.y - height) * 0.5; + mat = DXGI_MATRIX_3X2_F{ + FLOAT(scale), 0.0f, + 0.0f, FLOAT(scale), + FLOAT(x), FLOAT(y), + }; + return true; + } + } + inline DXGI_SWAP_CHAIN_DESC1 getDefaultSwapChainInfo7() + { + return DXGI_SWAP_CHAIN_DESC1{ + .Width = 0, + .Height = 0, + .Format = COLOR_BUFFER_FORMAT, + .Stereo = FALSE, + .SampleDesc = DXGI_SAMPLE_DESC{ + .Count = 1, + .Quality = 0, + }, + .BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, + .BufferCount = 1, + .Scaling = DXGI_SCALING_STRETCH, + .SwapEffect = DXGI_SWAP_EFFECT_DISCARD, + .AlphaMode = DXGI_ALPHA_MODE_IGNORE, + .Flags = 0, + }; + } + inline DXGI_SWAP_CHAIN_DESC1 getDefaultSwapChainInfo10() + { + return DXGI_SWAP_CHAIN_DESC1{ + .Width = 0, + .Height = 0, + .Format = COLOR_BUFFER_FORMAT, + .Stereo = FALSE, + .SampleDesc = DXGI_SAMPLE_DESC{ + .Count = 1, + .Quality = 0, + }, + .BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT, + .BufferCount = 3, + .Scaling = DXGI_SCALING_NONE, + .SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD, + .AlphaMode = DXGI_ALPHA_MODE_IGNORE, + .Flags = 0, + }; + } + + static bool findBestDisplayMode(HWND const window, IDXGISwapChain1* dxgi_swapchain, Vector2U canvas_size, DXGI_MODE_DESC1& mode) + { + HRNew; + + win32::com_ptr dxgi_output; + HRGet = dxgi_swapchain->GetContainingOutput(dxgi_output.put()); + if (FAILED(hr)) { + ReportError("IDXGISwapChain1::GetContainingOutput"); + if (!resolveOutput(window, dxgi_swapchain, dxgi_output.put())) { + return false; + } + } + + win32::com_ptr dxgi_output_1; + HRGet = dxgi_output->QueryInterface(dxgi_output_1.put()); + HRCheckCallReturnBool("IDXGIOutput::QueryInterface -> IDXGIOutput1"); + + DXGI_OUTPUT_DESC dxgi_output_info = {}; + HRGet = dxgi_output_1->GetDesc(&dxgi_output_info); + HRCheckCallReturnBool("IDXGIOutput1::GetDesc"); + assert(dxgi_output_info.AttachedToDesktop); + assert(dxgi_output_info.Monitor); + assert(dxgi_output_info.DesktopCoordinates.right > dxgi_output_info.DesktopCoordinates.left); + assert(dxgi_output_info.DesktopCoordinates.bottom > dxgi_output_info.DesktopCoordinates.top); + UINT const monitor_w = static_cast(dxgi_output_info.DesktopCoordinates.right - dxgi_output_info.DesktopCoordinates.left); + UINT const monitor_h = static_cast(dxgi_output_info.DesktopCoordinates.bottom - dxgi_output_info.DesktopCoordinates.top); + + UINT dxgi_mode_count = 0; + HRGet = dxgi_output_1->GetDisplayModeList1(COLOR_BUFFER_FORMAT, 0, &dxgi_mode_count, NULL); + HRCheckCallReturnBool("IDXGIOutput1::GetDisplayModeList1 -> DXGI_FORMAT_B8G8R8A8_UNORM"); + assert(dxgi_mode_count > 0); + + std::vector mode_list(dxgi_mode_count); + HRGet = dxgi_output_1->GetDisplayModeList1(COLOR_BUFFER_FORMAT, 0, &dxgi_mode_count, mode_list.data()); + HRCheckCallReturnBool("IDXGIOutput1::GetDisplayModeList1 -> DXGI_FORMAT_B8G8R8A8_UNORM"); + + // 公共函数 + + auto scoreRefreshRate = [](DXGI_MODE_DESC1 const& v) -> int + { + int final_score = 0; + + double const refresh_rate_f = (double)v.RefreshRate.Numerator / (double)v.RefreshRate.Denominator; + assert(refresh_rate_f >= 1.0); // 理论上不存在刷新率等于或者小于 0 的情况 + double const multiple_f = refresh_rate_f / 60.0; // 相对 60Hz 的倍数 + assert(multiple_f > 0.0); + + double const multiple = std::ceil(multiple_f); + assert(multiple > 0.0); + double const range_low = (60.0 * multiple) - multiple; + double const range_high = (60.0 * multiple) + multiple; + assert(range_low > 0.0); + assert(range_high > 0.0); + + if (refresh_rate_f > range_low && refresh_rate_f < range_high) + { + // 是 60Hz 或者 60Hz 的倍数的刷新率 + int multiple_i = std::clamp((int)multiple, 1, 100); // 限制范围防止 int 乘上去后溢出 + final_score = 10000000 * multiple_i; + } + else if (refresh_rate_f > 118.0) + { + // 只要是 120Hz 或以上的刷新率,就已经可以满足游戏需求,无论是 144Hz 还是 165Hz 这种奇异刷新率 + final_score = 5000000; + } + else if (refresh_rate_f > 59.0) + { + // 还能接受的刷新率,比如 75Hz 和 90Hz + final_score = 1000000; + } + else + { + // 以上要求都达不到,我只能说,你这个显示器就是个几把 + final_score = 0; + } + + int const refresh_rate_v = std::clamp((int)(refresh_rate_f * 100.0), 0, 999999); // 理论上不会有超过一万刷新率的屏幕? + final_score += refresh_rate_v; // 后面补上刷新率的 100 倍整数方便一次性比较 + + return final_score; + }; + + auto compareRefreshRate = [=](DXGI_MODE_DESC1 const& a, DXGI_MODE_DESC1 const& b) -> bool + { + return scoreRefreshRate(a) > scoreRefreshRate(b); + }; + + auto checkRequiredRefreshRate = [](DXGI_MODE_DESC1 const& v) -> bool + { + return (double)v.RefreshRate.Numerator / (double)v.RefreshRate.Denominator >= 59.0; + }; + + auto checkRequiredCanvasSize = [&](DXGI_MODE_DESC1 const& v) -> bool + { + return v.Width >= canvas_size.x && v.Height >= canvas_size.y; + }; + + auto checkRequiredAspectRatio = [&](DXGI_MODE_DESC1 const& v) -> bool + { + if (monitor_w > monitor_h) + { + UINT const width = v.Height * monitor_w / monitor_h; + assert(width > 0); + if (width == 0) return false; + else if (v.Width == width) return true; + else if (width > v.Width && (width - v.Width) <= 2) return true; + else if (v.Width > width && (v.Width - width) <= 2) return true; + else return false; + } + else + { + UINT const height = v.Width * monitor_h / monitor_w; + assert(height > 0); + if (height == 0) return false; + else if (v.Height == height) return true; + else if (height > v.Height && (height - v.Height) <= 2) return true; + else if (v.Height > height && (v.Height - height) <= 2) return true; + else return false; + } + }; + + // 默认的桌面分辨率 + + std::vector default_mode_list; + for (auto const& v : mode_list) + { + if (v.Width == monitor_w && v.Height == monitor_h) + { + default_mode_list.emplace_back(v); + } + } + + assert(!default_mode_list.empty()); + if (default_mode_list.empty()) return false; + + std::sort(default_mode_list.begin(), default_mode_list.end(), compareRefreshRate); + DXGI_MODE_DESC1 default_mode = default_mode_list.at(0); + default_mode_list.clear(); + + // 剔除隔行扫描(理论情况下不会出现) + + for (auto it = mode_list.begin(); it != mode_list.end();) + { + if (!(it->ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED || it->ScanlineOrdering == DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE)) + it = mode_list.erase(it); + else + it++; + } + + // 剔除刷新率过低的 + + for (auto it = mode_list.begin(); it != mode_list.end();) + { + if (!checkRequiredRefreshRate(*it)) + { + it = mode_list.erase(it); + } + else + { + it++; + } + } + + // 剔除分辨率比画布分辨率低的 + + for (auto it = mode_list.begin(); it != mode_list.end();) + { + if (!checkRequiredCanvasSize(*it)) + { + it = mode_list.erase(it); + } + else + { + it++; + } + } + + // 剔除横纵比不和显示器匹配的 + + for (auto it = mode_list.begin(); it != mode_list.end();) + { + if (!checkRequiredAspectRatio(*it)) + { + it = mode_list.erase(it); + } + else + { + it++; + } + } + + // 根据面积比和刷新率进行排序,优先刷新率,然后是面积比 + + auto compareByRefreshRateAndSize = [&](DXGI_MODE_DESC1 const& a, DXGI_MODE_DESC1 const& b) -> bool + { + double const canvas_sz = (double)canvas_size.x * (double)canvas_size.y; + double const sz_a = canvas_sz / ((double)a.Width * (double)a.Height); + double const sz_b = canvas_sz / ((double)b.Width * (double)b.Height); + if (sz_a == sz_b) + { + return compareRefreshRate(a, b); + } + else + { + return sz_b > sz_b; + } + }; + + std::sort(mode_list.begin(), mode_list.end(), compareByRefreshRateAndSize); + + // 打印结果 + + Logger::info("[core] [SwapChain] found {} DisplayMode", mode_list.size()); + for (size_t i = 0; i < mode_list.size(); i += 1) { + Logger::info("{: >4d}: ({: >5d} x {: >5d}) {:.2f}Hz {} {}" + , i + , mode_list[i].Width, mode_list[i].Height + , (double)mode_list[i].RefreshRate.Numerator / (double)mode_list[i].RefreshRate.Denominator + , to_string(mode_list[i].Scaling) + , to_string(mode_list[i].ScanlineOrdering) + ); + } + + // 最终,挑选出面积比最大且刷新率最高的 + + if (!mode_list.empty()) + { + mode = mode_list.at(0); + } + else + { + mode = default_mode; + } + + return true; + } + static bool checkModernSwapChainModelAvailable(ID3D11Device* device) + { + // 是否需要统一开启现代交换链模型 + // 我们划定一个红线,红线以下永远不开启,红线以上永远开启 + // 这样可以简化逻辑的处理 + + assert(device); + HRNew; + NTNew; + + // 预检系统版本 Windows 10 1809 + // * DXGI_SWAP_EFFECT_FLIP_DISCARD 从 Windows 10 开始支持 + // * 在 Windows 10 1709 (16299) Fall Creators Update 中修复了 + // Frame Latency Waitable Object 和 SetMaximumFrameLatency 实际上至少有 2 帧的问题 + // * Windows 10 1809 (17763) 是目前微软还在支持的长期支持版本 + // https://learn.microsoft.com/en-us/windows/release-health/release-information + // * DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT 从 Windows 8.1 开始支持,我们跳过它 + + if (!Platform::WindowsVersion::Is10Build17763()) { + return false; + } + + // 检查 PresentAllowTearing + // * DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING 从 Windows 10 开始支持 + // * DXGI_PRESENT_ALLOW_TEARING 从 Windows 10 开始支持 + // * 此外还有别的要求,比如WDDM支持、MPO支持、显卡驱动支持等 + // * 注意,就算报告支持,实际运行的时候可能仍然不允许撕裂 + // * 系统安装了 KB3156421 更新,也就是 Windows 10 在 2016 年 5 月 10 日的更新 + // https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/variable-refresh-rate-displays + + win32::com_ptr dxgi_factory; + HRGet = Platform::Direct3D11::GetDeviceFactory(device, dxgi_factory.put()); + HRCheckCallReturnBool("Platform::Direct3D11::GetDeviceFactory"); + BOOL present_allow_tearing = Platform::DXGI::CheckFeatureSupportPresentAllowTearing(dxgi_factory.get()); + + // 检查 DirectFlip + + win32::com_ptr dxgi_adapter; + HRGet = Platform::Direct3D11::GetDeviceAdater(device, dxgi_adapter.put()); + HRCheckCallReturnBool("Platform::Direct3D11::GetDeviceAdater"); + DXGI_ADAPTER_DESC1 dxgi_adapter_info{}; + HRGet = dxgi_adapter->GetDesc1(&dxgi_adapter_info); + HRCheckCallReturnBool("IDXGIAdapter1::GetDesc1"); + + Platform::RuntimeLoader::D3DKMT d3dkmt; + + D3DKMT_OPENADAPTERFROMLUID open_adapter_from_luid{}; + open_adapter_from_luid.AdapterLuid = dxgi_adapter_info.AdapterLuid; + NTGet = d3dkmt.OpenAdapterFromLuid(&open_adapter_from_luid); + NTCheckCallReturnBool("D3DKMTOpenAdapterFromLuid"); + + auto auto_close_adapter = wil::scope_exit([&open_adapter_from_luid, &d3dkmt] + { + D3DKMT_CLOSEADAPTER close_adapter{}; + close_adapter.hAdapter = open_adapter_from_luid.hAdapter; + NTNew; + NTGet = d3dkmt.CloseAdapter(&close_adapter); + NTCheckCallReport("D3DKMTCloseAdapter"); + }); + + D3DKMT_CREATEDEVICE create_device{}; + create_device.hAdapter = open_adapter_from_luid.hAdapter; + NTGet = d3dkmt.CreateDevice(&create_device); + NTCheckCallReturnBool("D3DKMTCreateDevice"); + + auto auto_close_device = wil::scope_exit([&create_device, &d3dkmt] + { + D3DKMT_DESTROYDEVICE destroy_device{}; + destroy_device.hDevice = create_device.hDevice; + NTNew; + NTGet = d3dkmt.DestroyDevice(&destroy_device); + NTCheckCallReport("D3DKMTDestroyDevice"); + }); + + auto query_adapter_info = [&open_adapter_from_luid, &d3dkmt](KMTQUERYADAPTERINFOTYPE type, T, std::string_view type_name) -> T { + T data{}; + D3DKMT_QUERYADAPTERINFO query{}; + query.hAdapter = open_adapter_from_luid.hAdapter; + query.Type = type; + query.pPrivateDriverData = &data; + query.PrivateDriverDataSize = sizeof(data); + NTNew; + NTGet = d3dkmt.QueryAdapterInfo(&query); + NTCheckCallReportRuntime(std::string("D3DKMTQueryAdapterInfo -> ").append(type_name)); + return data; + }; + + // wddm 1.2 + auto const direct_flip_caps = query_adapter_info(KMTQAITYPE_DIRECTFLIP_SUPPORT, D3DKMT_DIRECTFLIP_SUPPORT{}, "D3DKMT_DIRECTFLIP_SUPPORT"); + // wddm 2.0 + auto const independent_flip_support = query_adapter_info(KMTQAITYPE_INDEPENDENTFLIP_SUPPORT, D3DKMT_INDEPENDENTFLIP_SUPPORT{}, "D3DKMT_INDEPENDENTFLIP_SUPPORT"); + + // 打印信息 + + auto bool_to_string = [](bool v) { return v ? "true" : "false"; }; + + Logger::info( + "[core] Graphics Device: {}\n" + " Direct Flip Support: {}\n" + " Independent Flip Support: {}\n" + " Present Allow Tearing: {}" + , utf8::to_string(dxgi_adapter_info.Description) + , bool_to_string(direct_flip_caps.Supported) + , bool_to_string(independent_flip_support.Supported) + , bool_to_string(present_allow_tearing) + ); + + return present_allow_tearing && direct_flip_caps.Supported && independent_flip_support.Supported; + } + static bool checkMultiPlaneOverlaySupport(ID3D11Device* device) + { + // 是否有多平面叠加支持,如果有,就可以提供更好的性能 + + assert(device); + HRNew; + NTNew; + + // 用户禁用了 MPO 则跳过 + + if (Platform::DesktopWindowManager::IsOverlayTestModeExists()) { + Logger::warn("[core] Multi Plane Overlay is disabled by user"); + return false; + } + + // 检查各个显示输出的支持情况 + + win32::com_ptr dxgi_factory; + HRGet = Platform::Direct3D11::GetDeviceFactory(device, dxgi_factory.put()); + HRCheckCallReturnBool("Platform::Direct3D11::GetDeviceFactory"); + + Platform::RuntimeLoader::D3DKMT d3dkmt; + + win32::com_ptr dxgi_adapter; + for (UINT adapter_index = 0; SUCCEEDED(dxgi_factory->EnumAdapters1(adapter_index, dxgi_adapter.put())); adapter_index += 1) { + DXGI_ADAPTER_DESC1 dxgi_adapter_info{}; + HRGet = dxgi_adapter->GetDesc1(&dxgi_adapter_info); + HRCheckCallReturnBool("IDXGIAdapter1::GetDesc1"); + + win32::com_ptr dxgi_output; + for (UINT output_index = 0; SUCCEEDED(dxgi_adapter->EnumOutputs(output_index, dxgi_output.put())); output_index += 1) { + DXGI_OUTPUT_DESC dxgi_output_info{}; + HRGet = dxgi_output->GetDesc(&dxgi_output_info); + HRCheckCallReturnBool("IDXGIOutput::GetDesc"); + + D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME open_adapter_from_gdi{}; + std::memcpy(open_adapter_from_gdi.DeviceName, dxgi_output_info.DeviceName, sizeof(dxgi_output_info.DeviceName)); + NTGet = d3dkmt.OpenAdapterFromGdiDisplayName(&open_adapter_from_gdi); + NTCheckCallReturnBool("D3DKMTOpenAdapterFromGdiDisplayName"); + + auto auto_close_adapter = wil::scope_exit([&open_adapter_from_gdi, &d3dkmt] + { + D3DKMT_CLOSEADAPTER close_adapter{}; + close_adapter.hAdapter = open_adapter_from_gdi.hAdapter; + NTNew; + NTGet = d3dkmt.CloseAdapter(&close_adapter); + NTCheckCallReport("D3DKMTCloseAdapter"); + }); + + D3DKMT_CREATEDEVICE create_device{}; + create_device.hAdapter = open_adapter_from_gdi.hAdapter; + NTGet = d3dkmt.CreateDevice(&create_device); + NTCheckCallReturnBool("D3DKMTCreateDevice"); + + auto auto_close_device = wil::scope_exit([&create_device, &d3dkmt] + { + D3DKMT_DESTROYDEVICE destroy_device{}; + destroy_device.hDevice = create_device.hDevice; + NTNew; + NTGet = d3dkmt.DestroyDevice(&destroy_device); + NTCheckCallReport("D3DKMTDestroyDevice"); + }); + + auto query_adapter_info = [&open_adapter_from_gdi, &d3dkmt](KMTQUERYADAPTERINFOTYPE type, T, std::string_view type_name) -> T { + T data{}; + D3DKMT_QUERYADAPTERINFO query{}; + query.hAdapter = open_adapter_from_gdi.hAdapter; + query.Type = type; + query.pPrivateDriverData = &data; + query.PrivateDriverDataSize = sizeof(data); + NTNew; + NTGet = d3dkmt.QueryAdapterInfo(&query); + NTCheckCallReportRuntime(std::string("D3DKMTQueryAdapterInfo -> ").append(type_name)); + return data; + }; + + // 检查多平面叠加支持 + + auto mpo_support = query_adapter_info(KMTQAITYPE_MULTIPLANEOVERLAY_SUPPORT, D3DKMT_MULTIPLANEOVERLAY_SUPPORT{}, "D3DKMT_MULTIPLANEOVERLAY_SUPPORT"); + + // 进一步检查多平面叠加功能支持 + + D3DKMT_GET_MULTIPLANE_OVERLAY_CAPS get_mpo_caps{}; + get_mpo_caps.hAdapter = open_adapter_from_gdi.hAdapter; + get_mpo_caps.VidPnSourceId = open_adapter_from_gdi.VidPnSourceId; + NTGet = d3dkmt.GetMultiPlaneOverlayCaps(&get_mpo_caps); + NTCheckCallReturnBool("D3DKMTGetMultiPlaneOverlayCaps"); + + // 检查额外的功能 + + BOOL overlays = FALSE; // 我们只打印信息,但不使用这个值,因为它代表的含义并不清晰 + win32::com_ptr dxgi_output2; + HRGet = dxgi_output->QueryInterface(dxgi_output2.put()); + HRCheckCallReport("IDXGIOutput::QueryInterface -> IDXGIOutput2"); + if (dxgi_output2) + { + overlays = dxgi_output2->SupportsOverlays(); + } + + UINT hardware_composition_support{}; + win32::com_ptr dxgi_output6; + HRGet = dxgi_output->QueryInterface(dxgi_output6.put()); + HRCheckCallReport("IDXGIOutput::QueryInterface -> IDXGIOutput6"); + if (dxgi_output6) + { + HRGet = dxgi_output6->CheckHardwareCompositionSupport(&hardware_composition_support); + HRCheckCallReport("IDXGIOutput6::CheckHardwareCompositionSupport"); + } + + // 打印信息 + + auto bool_to_string = [](bool v) { return v ? "true" : "false"; }; + + Logger::info( + "[core] Display Output: {} -> {}\n" + " Overlays Support: {}\n" + " Multi Plane Overlay:\n" + " Support: {}\n" + " Max Planes: {}\n" + " Max RGB Planes: {}\n" + " Max YUV Planes: {}\n" + " Overlay Capabilities:\n" + " Rotation: {}\n" + " Rotation Without Independent Flip: {}\n" + " Vertical Flip: {}\n" + " Horizontal Flip: {}\n" + " Stretch RGB: {}\n" + " Stretch YUV: {}\n" + " Bilinear Filter: {}\n" + " High Filter: {}\n" + " Shared: {}\n" + " Immediate: {}\n" + " Plane 0 For Virtual Mode Only: {}\n" + " Version 3 DDI Support: {}\n" + " Max Stretch Factor: {:.2f}x\n" + " Max Shrink Factor: {:.2f}x\n" + " Hardware Composition:\n" + " Fullscreen: {}\n" + " Windowed: {}\n" + " Cursor Stretched: {}" + , utf8::to_string(dxgi_adapter_info.Description) + , utf8::to_string(dxgi_output_info.DeviceName) + , bool_to_string(overlays) + , bool_to_string(mpo_support.Supported) + , get_mpo_caps.MaxPlanes + , get_mpo_caps.MaxRGBPlanes + , get_mpo_caps.MaxYUVPlanes + , bool_to_string(get_mpo_caps.OverlayCaps.Rotation) + , bool_to_string(get_mpo_caps.OverlayCaps.RotationWithoutIndependentFlip) + , bool_to_string(get_mpo_caps.OverlayCaps.VerticalFlip) + , bool_to_string(get_mpo_caps.OverlayCaps.HorizontalFlip) + , bool_to_string(get_mpo_caps.OverlayCaps.StretchRGB) + , bool_to_string(get_mpo_caps.OverlayCaps.StretchYUV) + , bool_to_string(get_mpo_caps.OverlayCaps.BilinearFilter) + , bool_to_string(get_mpo_caps.OverlayCaps.HighFilter) + , bool_to_string(get_mpo_caps.OverlayCaps.Shared) + , bool_to_string(get_mpo_caps.OverlayCaps.Immediate) + , bool_to_string(get_mpo_caps.OverlayCaps.Plane0ForVirtualModeOnly) + , bool_to_string(get_mpo_caps.OverlayCaps.Version3DDISupport) + , get_mpo_caps.MaxStretchFactor + , get_mpo_caps.MaxShrinkFactor + , bool_to_string(hardware_composition_support & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_FULLSCREEN) + , bool_to_string(hardware_composition_support & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_WINDOWED) + , bool_to_string(hardware_composition_support & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_CURSOR_STRETCHED) + ); + + // 多平面叠加不支持 + + if (!mpo_support.Supported) { + return false; + } + + // 平面数量少于 2(特别是 RGB 平面),那肯定是不支持了 + + if (get_mpo_caps.MaxPlanes < 2 || get_mpo_caps.MaxRGBPlanes < 2) { + return false; + } + + // 看起来似乎不支持缩放 + + if (!get_mpo_caps.OverlayCaps.StretchRGB || std::abs(get_mpo_caps.MaxStretchFactor - 1.0f) < 0.1f || std::abs(get_mpo_caps.MaxShrinkFactor - 1.0f) < 0.1f) { + return false; + } + + // TODO: 检测 get_mpo_caps.OverlayCaps.Immediate 的作用 + + // 全屏模式的合成不支持 + + if (!(hardware_composition_support & DXGI_HARDWARE_COMPOSITION_SUPPORT_FLAG_FULLSCREEN)) { + return false; + } + } + } + + // 大概是支持的吧…… + + return true; + } + inline bool isModernSwapChainModel(DXGI_SWAP_CHAIN_DESC1 const& info) + { + return info.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL + || info.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD + ; + } + inline bool isModernSwapChainModel(IDXGISwapChain1* dxgi_swapchain) + { + HRNew; + + DXGI_SWAP_CHAIN_DESC1 info = {}; + HRGet = dxgi_swapchain->GetDesc1(&info); + HRCheckCallReturnBool("IDXGISwapChain1::GetDesc1"); + + return isModernSwapChainModel(info); + } + + bool SecondarySwapChain::createRenderAttachment() { + assert(d3d11_device); +#ifdef LUASTG_ENABLE_DIRECT2D + assert(d2d1_device_context); +#endif + assert(dxgi_swap_chain); + HRNew; + + win32::com_ptr texture; + HRGet = dxgi_swap_chain->GetBuffer(0, IID_PPV_ARGS(texture.put())); + HRCheckCallReturnBool("IDXGISwapChain::GetBuffer"); + + HRGet = d3d11_device->CreateRenderTargetView(texture.get(), NULL, d3d11_rtv.put()); + HRCheckCallReturnBool("ID3D11Device::CreateRenderTargetView"); + + win32::com_ptr surface; + HRGet = dxgi_swap_chain->GetBuffer(0, IID_PPV_ARGS(surface.put())); + HRCheckCallReturnBool("IDXGISwapChain::GetBuffer"); + +#ifdef LUASTG_ENABLE_DIRECT2D + D2D1_BITMAP_PROPERTIES1 bitmap_info{}; + bitmap_info.pixelFormat.format = info.Format; + bitmap_info.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + bitmap_info.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; + HRGet = d2d1_device_context->CreateBitmapFromDxgiSurface(surface.get(), &bitmap_info, d2d1_bitmap.put()); + HRCheckCallReturnBool("ID2D1DeviceContext::CreateBitmapFromDxgiSurface"); +#endif + + return true; + } + void SecondarySwapChain::destroyRenderAttachment() { + if (d3d11_device_context) { + d3d11_device_context->ClearState(); + d3d11_device_context->Flush(); + } + d3d11_rtv.reset(); +#ifdef LUASTG_ENABLE_DIRECT2D + d2d1_bitmap.reset(); +#endif + } + + bool SecondarySwapChain::create(IDXGIFactory2* factory, ID3D11Device* device, ID2D1DeviceContext* context, Vector2U const& size) { + assert(factory); + assert(device); + assert(context); + assert(size.x > 0 && size.y > 0); + HRNew; + + dxgi_factory = factory; + d3d11_device = device; + d3d11_device->GetImmediateContext(d3d11_device_context.put()); +#ifdef LUASTG_ENABLE_DIRECT2D + d2d1_device_context = context; +#endif + + info.Width = size.x; + info.Height = size.y; + info.Format = COLOR_BUFFER_FORMAT; + info.SampleDesc.Count = 1; + info.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + info.BufferCount = 2; + info.Scaling = DXGI_SCALING_STRETCH; + info.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; + info.AlphaMode = DXGI_ALPHA_MODE_IGNORE; + info.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING; + + HRGet = dxgi_factory->CreateSwapChainForComposition(d3d11_device.get(), &info, NULL, dxgi_swap_chain.put()); + HRCheckCallReturnBool("IDXGIFactory2::CreateSwapChainForComposition"); + + return createRenderAttachment(); + } + void SecondarySwapChain::destroy() { + destroyRenderAttachment(); + dxgi_factory.reset(); + d3d11_device.reset(); + d3d11_device_context.reset(); +#ifdef LUASTG_ENABLE_DIRECT2D + d2d1_device_context.reset(); +#endif + dxgi_swap_chain.reset(); + } + bool SecondarySwapChain::setSize(Vector2U const& size) { + assert(size.x > 0 && size.y > 0); + if (size.x == 0 || size.y == 0) { + return false; + } + HRNew; + destroyRenderAttachment(); + info.Width = size.x; + info.Height = size.y; + HRGet = dxgi_swap_chain->ResizeBuffers(info.BufferCount, info.Width, info.Height, info.Format, info.Flags); + HRCheckCallReturnBool("IDXGISwapChain::ResizeBuffers"); + return createRenderAttachment(); + } + void SecondarySwapChain::clearRenderTarget() { + assert(d3d11_device_context); + assert(d3d11_rtv); + if (d3d11_device_context && d3d11_rtv) { + FLOAT const solid_black[4]{ 0.0f, 0.0f, 0.0f, 1.0f }; + d3d11_device_context->ClearRenderTargetView(d3d11_rtv.get(), solid_black); + } + } + bool SecondarySwapChain::present() { + assert(dxgi_swap_chain); + if (!dxgi_swap_chain) { + return false; + } + HRNew; + HRGet = dxgi_swap_chain->Present(0, DXGI_PRESENT_ALLOW_TEARING); + HRCheckCallReturnBool("IDXGISwapChain::Present"); + return true; + } + + void SwapChain_D3D11::dispatchEvent(EventType t) + { + // 回调 + m_is_dispatch_event = true; + switch (t) + { + case EventType::SwapChainCreate: + for (auto& v : m_eventobj) + { + if (v) v->onSwapChainCreate(); + } + break; + case EventType::SwapChainDestroy: + for (auto& v : m_eventobj) + { + if (v) v->onSwapChainDestroy(); + } + break; + } + m_is_dispatch_event = false; + // 处理那些延迟的对象 + removeEventListener(nullptr); + for (auto& v : m_eventobj_late) + { + m_eventobj.emplace_back(v); + } + m_eventobj_late.clear(); + } + void SwapChain_D3D11::addEventListener(ISwapChainEventListener* e) + { + removeEventListener(e); + if (m_is_dispatch_event) + { + m_eventobj_late.emplace_back(e); + } + else + { + m_eventobj.emplace_back(e); + } + } + void SwapChain_D3D11::removeEventListener(ISwapChainEventListener* e) + { + if (m_is_dispatch_event) + { + for (auto& v : m_eventobj) + { + if (v == e) + { + v = nullptr; // 不破坏遍历过程 + } + } + } + else + { + for (auto it = m_eventobj.begin(); it != m_eventobj.end();) + { + if (*it == e) + it = m_eventobj.erase(it); + else + it++; + } + } + } + + void SwapChain_D3D11::onGraphicsDeviceCreate() + { + m_modern_swap_chain_available = checkModernSwapChainModelAvailable(m_device->GetD3D11Device()); + m_scaling_renderer.AttachDevice(m_device->GetD3D11Device()); + if (m_init) // 曾经设置过 + { + setWindowMode(m_canvas_size); + if (m_swap_chain_fullscreen_mode) + { + // 重新进入独占全屏 + onWindowFullscreenStateChange(true); + } + } + } + void SwapChain_D3D11::onGraphicsDeviceDestroy() + { + destroySwapChain(); + m_scaling_renderer.DetachDevice(); + m_modern_swap_chain_available = false; + } + void SwapChain_D3D11::onWindowCreate() + { + // 目前窗口的重新创建只会被交换链触发,所以这里留空 + } + void SwapChain_D3D11::onWindowDestroy() + { + // 目前窗口的重新创建只会被交换链触发,所以这里留空 + } + void SwapChain_D3D11::onWindowActive() + { + if (!dxgi_swapchain) + return; + _log("onWindowActive"); + m_swapchain_want_present_reset = TRUE; + enterExclusiveFullscreenTemporarily(); + } + void SwapChain_D3D11::onWindowInactive() + { + if (!dxgi_swapchain) + return; + _log("onWindowInactive"); + leaveExclusiveFullscreenTemporarily(); + } + void SwapChain_D3D11::onWindowSize(core::Vector2U size) + { + if (size.x == 0 || size.y == 0) + return; // 忽略窗口最小化 + if (!dxgi_swapchain) + return; // 此时交换链还未初始化 + if (m_is_composition_mode) + { + handleDirectCompositionWindowSize(size); + } + else + { + handleSwapChainWindowSize(size); + } + } + void SwapChain_D3D11::onWindowFullscreenStateChange(bool state) + { + if (!dxgi_swapchain) + return; + if (state) + enterExclusiveFullscreen(); + else + leaveExclusiveFullscreen(); + } + + bool SwapChain_D3D11::createSwapChain(bool fullscreen, DXGI_MODE_DESC1 const& mode, bool no_attachment) + { + _log("createSwapChain"); + + Logger::info("[core] [SwapChain] creating..."); + + // 必须成功的操作 + + const auto win = static_cast(m_window->getNativeHandle()); + if (!win) { + Logger::error("[core] [SwapChain] create failed: Window not initialized"); + assert(false); return false; + } + if (!m_device->getNativeHandle()) { + Logger::error("[core] [SwapChain] create failed: GraphicsDevice not initialized"); + assert(false); return false; + } + win32::com_ptr dxgi_factory; + if (!core::GraphicsDeviceManagerDXGI::refreshAndGetFactory(dxgi_factory.put())) { + Logger::error("[core] [SwapChain] create failed: DXGI not available"); + assert(false); return false; + } + + HRNew; + + // 填写交换链描述 + + m_swap_chain_info = getDefaultSwapChainInfo7(); + m_swap_chain_fullscreen_info = {}; + + // 切换为 FLIP 交换链模型,独占全屏也支持 + if (m_modern_swap_chain_available) { + m_swap_chain_info.BufferCount = 3; + m_swap_chain_info.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; + } + + if (!fullscreen) + { + // 获取窗口尺寸 + RECT rc = {}; + if (!GetClientRect(win, &rc)) + { + HRGet = HRESULT_FROM_WIN32(GetLastError()); + HRCheckCallReturnBool("GetClientRect"); + } + if (rc.right <= rc.left || rc.bottom <= rc.top) + { + Logger::error( + "[core] [SwapChain] size cannot be ({}x{})", + rc.right - rc.left, + rc.bottom - rc.top + ); + assert(false); return false; + } + // 使用窗口尺寸 + m_swap_chain_info.Width = static_cast(rc.right - rc.left); + m_swap_chain_info.Height = static_cast(rc.bottom - rc.top); + // 进一步配置 FLIP 交换链模型 + if (m_modern_swap_chain_available) + { + m_swap_chain_info.BufferCount = 3; // 三个缓冲区能带来更平稳的性能 + m_swap_chain_info.Scaling = DXGI_SCALING_NONE; // 禁用 DWM 对交换链的缩放 + m_swap_chain_info.Flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; // 低延迟呈现技术 + m_swap_chain_info.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING; // 立即刷新和可变刷新率 + } + } + else + { + // 使用显示模式尺寸 + m_swap_chain_info.Width = mode.Width; + m_swap_chain_info.Height = mode.Height; + // 允许切换显示模式 + m_swap_chain_info.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + // 配置全屏模式 + m_swap_chain_fullscreen_info.RefreshRate = mode.RefreshRate; + m_swap_chain_fullscreen_info.ScanlineOrdering = mode.ScanlineOrdering; + m_swap_chain_fullscreen_info.Scaling = mode.Scaling; + m_swap_chain_fullscreen_info.Windowed = TRUE; // 稍后再切换到独占全屏 + } + + // 创建交换链 + + HRGet = dxgi_factory->CreateSwapChainForHwnd( + m_device->GetD3D11Device(), + win, + &m_swap_chain_info, + fullscreen ? &m_swap_chain_fullscreen_info : NULL, + NULL, + dxgi_swapchain.put()); + HRCheckCallReturnBool("IDXGIFactory2::CreateSwapChainForHwnd"); + + m_swap_chain_fullscreen_mode = fullscreen; + + // 关闭傻逼快捷键,别他妈乱切换了 + // 注意这里他妈的有坑,新创建的 DXGI 工厂和交换链内部的的不是同一个 + + HRGet = Platform::DXGI::MakeSwapChainWindowAssociation( + dxgi_swapchain.get(), DXGI_MWA_NO_ALT_ENTER); + HRCheckCallReturnBool("IDXGIFactory1::MakeWindowAssociation -> DXGI_MWA_NO_ALT_ENTER"); + + // 设置设备最大帧延迟为 1 + + HRGet = Platform::DXGI::SetDeviceMaximumFrameLatency( + dxgi_swapchain.get(), 1); + HRCheckCallReturnBool("IDXGIDevice1::SetMaximumFrameLatency -> 1"); + + // 如果启用了低延迟呈现技术,则设置交换链最大帧延迟为 1 + + if (m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) + { + HANDLE event_handle{}; + HRGet = Platform::DXGI::SetSwapChainMaximumFrameLatency( + dxgi_swapchain.get(), 1, &event_handle); + HRCheckCallReturnBool("IDXGISwapChain2::SetMaximumFrameLatency -> 1"); + dxgi_swapchain_event.reset(event_handle); + } + + auto refresh_rate_string = std::format("{:.2f}Hz", (double)mode.RefreshRate.Numerator / (double)mode.RefreshRate.Denominator); + if (!fullscreen) refresh_rate_string = "Desktop RefreshRate"; + std::string_view swapchain_model = "Discard"; + if (m_swap_chain_info.SwapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) swapchain_model = "FlipSequential"; + if (m_swap_chain_info.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD) swapchain_model = "FlipDiscard"; + auto enable_or_disable = [](bool v) -> std::string_view { return v ? "Enable" : "Disable"; }; + Logger::info( + "[core] [SwapChain] created:\n" + " Display Mode: {}x{}@{}\n" + " Exclusive Fullscreen:{}\n" + " SwapChain swap effect: {}\n" + " Present Allow Tearing: {}\n" + " Frame Latency Waitable Object: {}" + , mode.Width, mode.Height, refresh_rate_string + , enable_or_disable(fullscreen) + , swapchain_model + , enable_or_disable(m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) + , enable_or_disable(m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) + ); + + // 渲染附件 + + if (!no_attachment) + { + if (!createRenderAttachment()) return false; + } + + // 标记 + + m_swapchain_want_present_reset = TRUE; + +#ifdef LUASTG_ENABLE_DIRECT2D + static_cast(m_window.get())->getTitleBarController().createResources(win, m_device->GetD2D1DeviceContext()); +#endif + + return true; + } + void SwapChain_D3D11::destroySwapChain() + { + _log("destroySwapChain"); + + static_cast(m_window.get())->getTitleBarController().destroyResources(); + destroyDirectCompositionResources(); + destroyRenderAttachment(); + if (dxgi_swapchain) + { + // 退出独占全屏 + HRNew; + BOOL bFullscreen = FALSE; + win32::com_ptr dxgi_output; + HRGet = dxgi_swapchain->GetFullscreenState(&bFullscreen, dxgi_output.put()); + HRCheckCallReport("IDXGISwapChain::GetFullscreenState"); + if (SUCCEEDED(hr) && bFullscreen) + { + Logger::info("[core] [SwapChain] leave exclusive fullscreen"); + HRGet = dxgi_swapchain->SetFullscreenState(FALSE, NULL); + HRCheckCallReport("IDXGISwapChain::SetFullscreenState -> FALSE"); + } + } + dxgi_swapchain_event.reset(); + dxgi_swapchain.reset(); + } + void SwapChain_D3D11::waitFrameLatency(uint32_t timeout, bool reset) + { + //_log("waitFrameLatency"); + + if (m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) + { + if (reset && dxgi_swapchain) + { + HRNew; + + // 微软不知道写了什么狗屎bug,有时候dwm临时接管桌面合成后会导致上屏延迟多一倍 + // 重新设置最大帧延迟并创建延迟等待对象似乎能解决该问题 + dxgi_swapchain_event.reset(); + + win32::com_ptr dxgi_swap_chain2; + HRGet = dxgi_swapchain->QueryInterface(dxgi_swap_chain2.put()); + HRCheckCallReport("IDXGISwapChain1 -> IDXGISwapChain2"); + if (FAILED(hr)) return; + HRGet = dxgi_swap_chain2->SetMaximumFrameLatency(1); + HRCheckCallReport("IDXGISwapChain2::SetMaximumFrameLatency(1)"); + if (FAILED(hr)) return; + + dxgi_swapchain_event.reset(dxgi_swap_chain2->GetFrameLatencyWaitableObject()); + } + if (dxgi_swapchain_event) + { + DWORD const result = WaitForSingleObject(dxgi_swapchain_event.get(), timeout); + if (!(result == WAIT_OBJECT_0 || result == WAIT_TIMEOUT)) + { + win32::check_hresult(HRESULT_FROM_WIN32(GetLastError())); + Logger::error("Windows API failed: WaitForSingleObject"); + } + } + } + } + bool SwapChain_D3D11::enterExclusiveFullscreenTemporarily() + { + if (!m_swap_chain_fullscreen_mode) + { + return true; + } + if (!dxgi_swapchain) + { + assert(false); return false; + } + + HRNew; + + BOOL get_state = FALSE; + HRGet = dxgi_swapchain->GetFullscreenState(&get_state, NULL); + HRCheckCallReturnBool("IDXGISwapChain::GetFullscreenState"); + + if (get_state) + { + return true; + } + + _log("IDXGISwapChain::SetFullscreenState -> TRUE\n"); + Logger::info("[core] [SwapChain] enter exclusive fullscreen"); + HRGet = dxgi_swapchain->SetFullscreenState(TRUE, NULL); + HRCheckCallReturnBool("IDXGISwapChain::SetFullscreenState -> TRUE"); + + return true; + } + bool SwapChain_D3D11::leaveExclusiveFullscreenTemporarily() + { + if (!m_swap_chain_fullscreen_mode) + { + return true; + } + if (!dxgi_swapchain) + { + assert(false); return false; + } + + HRNew; + + BOOL get_state = FALSE; + HRGet = dxgi_swapchain->GetFullscreenState(&get_state, NULL); + HRCheckCallReturnBool("IDXGISwapChain::GetFullscreenState"); + + if (!get_state) + { + return true; + } + + _log("IDXGISwapChain::SetFullscreenState -> FALSE\n"); + Logger::info("[core] [SwapChain] leave exclusive fullscreen"); + HRGet = dxgi_swapchain->SetFullscreenState(FALSE, NULL); + HRCheckCallReturnBool("IDXGISwapChain::SetFullscreenState -> FALSE"); + + m_window->setLayer(WindowLayer::Normal); // 强制取消窗口置顶 + + return true; + } + bool SwapChain_D3D11::enterExclusiveFullscreen() { + if (m_disable_exclusive_fullscreen) { + return false; + } + if (!dxgi_swapchain) { + assert(false); + return false; + } + if (dcomp_visual_swap_chain) { + return false; + } + + DXGI_MODE_DESC1 display_mode{}; + if (!findBestDisplayMode(static_cast(m_window->getNativeHandle()), dxgi_swapchain.get(), m_canvas_size, display_mode)) { + return false; + } + + dispatchEvent(EventType::SwapChainDestroy); + destroySwapChain(); + + m_window->setSize({ display_mode.Width, display_mode.Height }); + + if (!createSwapChain(true, display_mode, true /* 稍后创建渲染附件 */)) { + return false; + } + + HRNew; + + // 进入全屏 + Logger::info("[core] [SwapChain] enter exclusive fullscreen"); + HRGet = dxgi_swapchain->SetFullscreenState(TRUE, nullptr); + HRCheckCallReturnBool("IDXGISwapChain::SetFullscreenState -> TRUE"); + + // 需要重设交换链大小(特别是 Flip 交换链模型) + HRGet = dxgi_swapchain->ResizeBuffers(0, display_mode.Width, display_mode.Height, DXGI_FORMAT_UNKNOWN, m_swap_chain_info.Flags); + HRCheckCallReturnBool("IDXGISwapChain::ResizeBuffers"); + + // 创建渲染附件 + if (!createRenderAttachment()) { + return false; + } + if (!updateLetterBoxingRendererTransform()) { + return false; + } + + // 记录状态 + m_init = TRUE; + + // 广播 + dispatchEvent(EventType::SwapChainCreate); + + return true; + } + bool SwapChain_D3D11::leaveExclusiveFullscreen() + { + HRNew; + + BOOL get_state = FALSE; + HRGet = dxgi_swapchain->GetFullscreenState(&get_state, NULL); + HRCheckCallReturnBool("IDXGISwapChain::GetFullscreenState"); + + if (get_state) + { + Logger::info("[core] [SwapChain] leave exclusive fullscreen"); + HRGet = dxgi_swapchain->SetFullscreenState(FALSE, NULL); + HRCheckCallReturnBool("IDXGISwapChain::SetFullscreenState -> FALSE"); + } + + if (m_swap_chain_fullscreen_mode) + { + m_swap_chain_fullscreen_mode = FALSE; // 手动离开全屏模式 + + dispatchEvent(EventType::SwapChainDestroy); + destroySwapChain(); + + if (!createSwapChain(false, {}, false)) + { + return false; + } + + if (!updateLetterBoxingRendererTransform()) return false; + + // 记录状态 + m_init = TRUE; + + // 广播 + dispatchEvent(EventType::SwapChainCreate); + + return true; + } + + return true; + } + + bool SwapChain_D3D11::createDirectCompositionResources() + { + assert(m_modern_swap_chain_available); + _log("createDirectCompositionResources"); + + // 我们限制 DirectComposition 仅在 Windows 10+ 使用 + + HRNew; + + // 必须成功的操作 + + win32::com_ptr dxgi_factory; + if (!core::GraphicsDeviceManagerDXGI::refreshAndGetFactory(dxgi_factory.put())) { + Logger::error("[core] [SwapChain] create failed: DXGI not available"); + assert(false); return false; + } + +#ifdef LUASTG_ENABLE_DIRECT2D + win32::com_ptr dxgi_device; + HRGet = m_device->GetD3D11Device()->QueryInterface(dxgi_device.put()); + HRCheckCallReturnBool("ID3D11Device::QueryInterface -> IDXGIDevice"); + + // 创建基本组件 + + HRGet = dcomp_loader.CreateDevice(dxgi_device.get(), IID_PPV_ARGS(dcomp_desktop_device.put())); + HRCheckCallReturnBool("DCompositionCreateDevice"); +#else + HRGet = dcomp_loader.CreateDevice(nullptr, IID_PPV_ARGS(dcomp_desktop_device.put())); + HRCheckCallReturnBool("DCompositionCreateDevice"); +#endif + + #ifdef _DEBUG + win32::com_ptr dcomp_device_debug; + HRGet = dcomp_desktop_device->QueryInterface(dcomp_device_debug.put()); + HRCheckCallReport("IDCompositionDesktopDevice::QueryInterface -> IDCompositionDeviceDebug"); + if (SUCCEEDED(hr)) + { + HRGet = dcomp_device_debug->EnableDebugCounters(); + HRCheckCallReport("IDCompositionDeviceDebug::EnableDebugCounters"); + } + #endif + + HRGet = dcomp_desktop_device->CreateTargetForHwnd(static_cast(m_window->getNativeHandle()), TRUE, dcomp_target.put()); + HRCheckCallReturnBool("IDCompositionDesktopDevice::CreateTargetForHwnd"); + + + HRGet = dcomp_desktop_device->CreateVisual(dcomp_visual_swap_chain.put()); + HRCheckCallReturnBool("IDCompositionDesktopDevice::CreateVisual"); + + // 桌面合成引擎模式,创建背景平面+交换链平面 + + if (m_is_composition_mode) + { + HRGet = dcomp_desktop_device->CreateVisual(dcomp_visual_root.put()); + HRCheckCallReturnBool("IDCompositionDesktopDevice::CreateVisual"); + +#ifdef LUASTG_ENABLE_DIRECT2D + HRGet = dcomp_desktop_device->CreateVisual(dcomp_visual_title_bar.put()); + HRCheckCallReturnBool("IDCompositionDesktopDevice::CreateVisual"); + + if (!swap_chain_title_bar.create( + dxgi_factory.get(), + m_device->GetD3D11Device(), + m_device->GetD2D1DeviceContext(), + m_window->_getCurrentSize() + )) { + return false; + } + // 标题栏交换链需要的时候再使用 + + HRGet = dcomp_visual_title_bar->SetContent(swap_chain_title_bar.GetDXGISwapChain1()); + HRCheckCallReturnBool("IDCompositionVisual2::SetContent"); +#endif + } + + // 把交换链塞进可视物 + + HRGet = dcomp_visual_swap_chain->SetContent(dxgi_swapchain.get()); + HRCheckCallReturnBool("IDCompositionVisual2::SetContent"); + + HRGet = dcomp_visual_swap_chain->SetBitmapInterpolationMode(DCOMPOSITION_BITMAP_INTERPOLATION_MODE_LINEAR); // TODO: 支持改为临近缩放 + HRCheckCallReturnBool("IDCompositionVisual2::SetBitmapInterpolationMode -> DCOMPOSITION_BITMAP_INTERPOLATION_MODE_LINEAR"); + + // 构建视觉树 + + if (m_is_composition_mode) + { + HRGet = dcomp_visual_root->AddVisual(dcomp_visual_swap_chain.get(), TRUE, nullptr); + HRCheckCallReturnBool("IDCompositionVisual2::AddVisual"); + + HRGet = dcomp_target->SetRoot(dcomp_visual_root.get()); + HRCheckCallReturnBool("IDCompositionTarget::SetRoot"); + + // 设置变换并提交 + + if (!updateDirectCompositionTransform()) return false; + } + else + { + HRGet = dcomp_target->SetRoot(dcomp_visual_swap_chain.get()); + HRCheckCallReturnBool("IDCompositionTarget::SetRoot"); + + // 直接提交 + if (!commitDirectComposition()) return false; + } + + return true; + } + void SwapChain_D3D11::destroyDirectCompositionResources() + { + _log("destroyDirectCompositionResources"); + + // 我也不知道为什么要这样清理,但是不这么做的话会出现内存不足,后续创建设备和资源的操作会失败 + + HRNew; + + if (dcomp_target) + { + HRGet = dcomp_target->SetRoot(NULL); + HRCheckCallReport("IDCompositionTarget::SetRoot -> NULL"); + } + if (dcomp_visual_root) + { + HRGet = dcomp_visual_root->RemoveAllVisuals(); + HRCheckCallReport("IDCompositionVisual2::RemoveAllVisuals"); + } + if (dcomp_visual_swap_chain) + { + HRGet = dcomp_visual_swap_chain->SetContent(NULL); + HRCheckCallReport("IDCompositionVisual2::SetContent -> NULL"); + } +#ifdef LUASTG_ENABLE_DIRECT2D + if (dcomp_visual_title_bar) + { + HRGet = dcomp_visual_title_bar->SetContent(NULL); + HRCheckCallReport("IDCompositionVisual2::SetContent -> NULL"); + } +#endif + + dcomp_target.reset(); + dcomp_visual_root.reset(); + dcomp_visual_swap_chain.reset(); +#ifdef LUASTG_ENABLE_DIRECT2D + dcomp_visual_title_bar.reset(); + swap_chain_title_bar.destroy(); + m_title_bar_attached = false; +#endif + + if (dcomp_desktop_device) + { + HRGet = dcomp_desktop_device->Commit(); + HRCheckCallReport("IDCompositionDesktopDevice::Commit"); + HRGet = dcomp_desktop_device->WaitForCommitCompletion(); + HRCheckCallReport("IDCompositionDesktopDevice::WaitForCommitCompletion"); + } + + dcomp_desktop_device.reset(); + } + bool SwapChain_D3D11::updateDirectCompositionTransform() + { + assert(m_is_composition_mode); + _log("updateDirectCompositionTransform"); + + HRNew; + + // 必须成功的操作 + + DXGI_SWAP_CHAIN_DESC1 desc1 = {}; + HRGet = dxgi_swapchain->GetDesc1(&desc1); + HRCheckCallReturnBool("IDXGISwapChain1::GetDesc1"); + + RECT rc = {}; + if (!GetClientRect(static_cast(m_window->getNativeHandle()), &rc)) + { + HRGet = HRESULT_FROM_WIN32(GetLastError()); + HRCheckCallReturnBool("GetClientRect"); + } + auto const window_size_u = Vector2U( + (uint32_t)(rc.right - rc.left), + (uint32_t)(rc.bottom - rc.top)); + + // 让背景铺满整个画面(由 Window Class 的背景来处理) + + + // 设置交换链内容内接放大 + + if (m_scaling_mode == SwapChainScalingMode::Stretch) + { + auto const mat_d2d = D2D1::Matrix3x2F::Scale( + (float)window_size_u.x / (float)desc1.Width, + (float)window_size_u.y / (float)desc1.Height); + HRGet = dcomp_visual_swap_chain->SetTransform(mat_d2d); + HRCheckCallReturnBool("IDCompositionVisual2::SetTransform"); + } + else + { + DXGI_MATRIX_3X2_F mat{}; + if (makeLetterboxing(window_size_u, Vector2U(desc1.Width, desc1.Height), mat)) + { + D2D_MATRIX_3X2_F const mat_d2d = { + mat._11, mat._12, + mat._21, mat._22, + mat._31, mat._32, + }; + HRGet = dcomp_visual_swap_chain->SetTransform(mat_d2d); + HRCheckCallReturnBool("IDCompositionVisual2::SetTransform"); + } + else + { + auto const mat_d2d = D2D1::Matrix3x2F::Identity(); + HRGet = dcomp_visual_swap_chain->SetTransform(mat_d2d); + HRCheckCallReturnBool("IDCompositionVisual2::SetTransform"); + } + } + + // 同步窗口宽度 + +#ifdef LUASTG_ENABLE_DIRECT2D + if (!swap_chain_title_bar.setSize(Vector2U(window_size_u.x, swap_chain_title_bar.getSize().y))) { + return false; + } +#endif + + // 提交 + + if (!commitDirectComposition()) return false; + + return true; + } + bool SwapChain_D3D11::commitDirectComposition() + { + _log("commitDirectComposition"); + + HRNew; + + HRGet = dcomp_desktop_device->Commit(); + HRCheckCallReturnBool("IDCompositionDesktopDevice::Commit"); + + HRGet = dcomp_desktop_device->WaitForCommitCompletion(); + HRCheckCallReturnBool("IDCompositionDesktopDevice::WaitForCommitCompletion"); + + return true; + } + bool SwapChain_D3D11::createCompositionSwapChain(Vector2U size, bool latency_event) + { + _log("createCompositionSwapChain"); + + // 我们限制 DirectComposition 仅在 Windows 10+ 使用 + + HRNew; + + Logger::info("[core] [SwapChain] creating... (DirectComposition)"); + + // 检查组件 + + if (!m_window->getNativeHandle()) { + Logger::error("[core] [SwapChain] create failed: Window not initialized"); + assert(false); return false; + } + if (!m_device->getNativeHandle()) { + Logger::error("[core] [SwapChain] create failed: GraphicsDevice not initialized"); + assert(false); return false; + } + win32::com_ptr dxgi_factory; + if (!core::GraphicsDeviceManagerDXGI::refreshAndGetFactory(dxgi_factory.put())) { + Logger::error("[core] [SwapChain] create failed: DXGI not available"); + assert(false); return false; + } + + // 填充交换链描述 + + m_swap_chain_info = getDefaultSwapChainInfo10(); + m_swap_chain_info.Width = size.x; + m_swap_chain_info.Height = size.y; + m_swap_chain_info.Scaling = DXGI_SCALING_STRETCH; // DirectComposition 要求这个缩放模式 + + m_swap_chain_info.Flags |= DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING; // 必须支持 + if (latency_event) + { + m_swap_chain_info.BufferCount = 3; // 三重缓冲 + m_swap_chain_info.Flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT; // 低延迟渲染 + } + + // 创建交换链 + + HRGet = dxgi_factory->CreateSwapChainForComposition( + m_device->GetD3D11Device(), + &m_swap_chain_info, NULL, + dxgi_swapchain.put()); + HRCheckCallReturnBool("IDXGIFactory2::CreateSwapChainForComposition"); + + m_swap_chain_fullscreen_mode = FALSE; + + // 设置最大帧延迟为 1 + + HRGet = Platform::DXGI::SetDeviceMaximumFrameLatency(dxgi_swapchain.get(), 1); + HRCheckCallReturnBool("IDXGIDevice1::SetMaximumFrameLatency -> 1"); + + if (m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) + { + HANDLE event_handle{}; + HRGet = Platform::DXGI::SetSwapChainMaximumFrameLatency( + dxgi_swapchain.get(), 1, &event_handle); + HRCheckCallReturnBool("IDXGISwapChain2::SetMaximumFrameLatency -> 1"); + dxgi_swapchain_event.reset(event_handle); + } + + // 打印信息 + + auto refresh_rate_string = "Desktop RefreshRate"; + std::string_view swapchain_model = "FlipSequential"; + if (m_swap_chain_info.SwapEffect == DXGI_SWAP_EFFECT_FLIP_DISCARD) swapchain_model = "FlipDiscard"; + auto enable_or_disable = [](bool v) -> std::string_view { return v ? "Enable" : "Disable"; }; + Logger::info( + "[core] [SwapChain] created:\n" + " Display Mode: {}x{}@{}\n" + " Exclusive Fullscreen:{}\n" + " SwapChain swap effect: {}\n" + " Present Allow Tearing: {}\n" + " Frame Latency Waitable Object: {}" + , size.x, size.y, refresh_rate_string + , "Disable" // 没有独占全屏 + , swapchain_model + , enable_or_disable(m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING) + , enable_or_disable(m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) + ); + + // 渲染附件 + + if (!createRenderAttachment()) return false; + + // 创建合成器 + + if (!createDirectCompositionResources()) return false; + + // 标记 + + m_swapchain_want_present_reset = TRUE; + +#ifdef LUASTG_ENABLE_DIRECT2D + static_cast(m_window.get())->getTitleBarController().createResources(static_cast(m_window->getNativeHandle()), m_device->GetD2D1DeviceContext()); +#endif + + return true; + } + + bool SwapChain_D3D11::createSwapChainRenderTarget() + { + _log("createSwapChainRenderTarget"); + + if (!dxgi_swapchain) + { + assert(false); return false; + } + + if (!m_device->GetD3D11Device()) + { + assert(false); return false; + } + + HRNew; + + win32::com_ptr d3d11_texture2d; + HRGet = dxgi_swapchain->GetBuffer(0, IID_PPV_ARGS(d3d11_texture2d.put())); + HRCheckCallReturnBool("IDXGISwapChain::GetBuffer -> 0"); + + // TODO: 线性颜色空间 + HRGet = m_device->GetD3D11Device()->CreateRenderTargetView(d3d11_texture2d.get(), NULL, m_swap_chain_d3d11_rtv.put()); + HRCheckCallReturnBool("ID3D11Device::CreateRenderTargetView"); + + win32::com_ptr dxgi_surface; + HRGet = dxgi_swapchain->GetBuffer(0, IID_PPV_ARGS(dxgi_surface.put())); + HRCheckCallReturnBool("IDXGISwapChain::GetBuffer -> 0"); + +#ifdef LUASTG_ENABLE_DIRECT2D + // TODO: 线性颜色空间 + D2D1_BITMAP_PROPERTIES1 d2d1_bitmap_info{}; + d2d1_bitmap_info.pixelFormat.format = COLOR_BUFFER_FORMAT; + d2d1_bitmap_info.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + d2d1_bitmap_info.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; + HRGet = m_device->GetD2D1DeviceContext()->CreateBitmapFromDxgiSurface(dxgi_surface.get(), &d2d1_bitmap_info, m_swap_chain_d2d1_bitmap.put()); + HRCheckCallReturnBool("ID2D1DeviceContext::CreateBitmapFromDxgiSurface"); +#endif + + return true; + } + void SwapChain_D3D11::destroySwapChainRenderTarget() + { + _log("destroySwapChainRenderTarget"); + + if (m_device->GetD3D11DeviceContext()) + { + m_device->GetD3D11DeviceContext()->ClearState(); + m_device->GetD3D11DeviceContext()->Flush(); + } + m_swap_chain_d3d11_rtv.reset(); +#ifdef LUASTG_ENABLE_DIRECT2D + m_swap_chain_d2d1_bitmap.reset(); +#endif + } + bool SwapChain_D3D11::createCanvasColorBuffer() + { + _log("createCanvasColorBuffer"); + + if (m_canvas_size.x == 0 || m_canvas_size.y == 0) + { + assert(false); return false; + } + + if (!m_device->GetD3D11Device()) + { + assert(false); return false; + } + + HRNew; + + // Color Buffer + + D3D11_TEXTURE2D_DESC cb_info = {}; + cb_info.Width = m_canvas_size.x; + cb_info.Height = m_canvas_size.y; + cb_info.MipLevels = 1; + cb_info.ArraySize = 1; + cb_info.Format = COLOR_BUFFER_FORMAT; + cb_info.SampleDesc.Count = 1; + cb_info.Usage = D3D11_USAGE_DEFAULT; + cb_info.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; + + win32::com_ptr cb_texture; + HRGet = m_device->GetD3D11Device()->CreateTexture2D(&cb_info, NULL, cb_texture.put()); + HRCheckCallReturnBool("ID3D11Device::CreateTexture2D"); + + // Shader Resource + + D3D11_SHADER_RESOURCE_VIEW_DESC srv_info = {}; + srv_info.Format = cb_info.Format; // TODO: 线性颜色空间 + srv_info.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + srv_info.Texture2D.MipLevels = cb_info.MipLevels; + + HRGet = m_device->GetD3D11Device()->CreateShaderResourceView(cb_texture.get(), &srv_info, m_canvas_d3d11_srv.put()); + HRCheckCallReturnBool("ID3D11Device::CreateShaderResourceView"); + + // Render Target + + D3D11_RENDER_TARGET_VIEW_DESC rtv_info = {}; + rtv_info.Format = cb_info.Format; // TODO: 线性颜色空间 + rtv_info.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D; + + HRGet = m_device->GetD3D11Device()->CreateRenderTargetView(cb_texture.get(), &rtv_info, m_canvas_d3d11_rtv.put()); + HRCheckCallReturnBool("ID3D11Device::CreateRenderTargetView"); + + return true; + } + void SwapChain_D3D11::destroyCanvasColorBuffer() + { + _log("destroyCanvasColorBuffer"); + + m_canvas_d3d11_srv.reset(); + m_canvas_d3d11_rtv.reset(); + } + bool SwapChain_D3D11::createCanvasDepthStencilBuffer() + { + _log("createCanvasDepthStencilBuffer"); + + if (m_canvas_size.x == 0 || m_canvas_size.y == 0) + { + assert(false); return false; + } + + if (!m_device->GetD3D11Device()) + { + assert(false); return false; + } + + HRNew; + + // Depth Stencil Buffer + + D3D11_TEXTURE2D_DESC ds_info = {}; + ds_info.Width = m_canvas_size.x; + ds_info.Height = m_canvas_size.y; + ds_info.MipLevels = 1; + ds_info.ArraySize = 1; + ds_info.Format = DEPTH_BUFFER_FORMAT; + ds_info.SampleDesc.Count = 1; + ds_info.Usage = D3D11_USAGE_DEFAULT; + ds_info.BindFlags = D3D11_BIND_DEPTH_STENCIL; + + win32::com_ptr ds_texture; + HRGet = m_device->GetD3D11Device()->CreateTexture2D(&ds_info, NULL, ds_texture.put()); + HRCheckCallReturnBool("ID3D11Device::CreateTexture2D"); + + // Depth Stencil View + + D3D11_DEPTH_STENCIL_VIEW_DESC dsv_info = {}; + dsv_info.Format = ds_info.Format; + dsv_info.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; + + HRGet = m_device->GetD3D11Device()->CreateDepthStencilView(ds_texture.get(), &dsv_info, m_canvas_d3d11_dsv.put()); + HRCheckCallReturnBool("ID3D11Device::CreateDepthStencilView"); + + return true; + } + void SwapChain_D3D11::destroyCanvasDepthStencilBuffer() + { + _log("destroyCanvasDepthStencilBuffer"); + + m_canvas_d3d11_dsv.reset(); + } + bool SwapChain_D3D11::createRenderAttachment() + { + _log("createRenderAttachment"); + + if (!createSwapChainRenderTarget()) return false; + if (m_is_composition_mode) + { + // 此时画布颜色缓冲区就是交换链的后台缓冲区 + m_canvas_d3d11_srv.reset(); // 不使用 + m_canvas_d3d11_rtv = m_swap_chain_d3d11_rtv; + } + else + { + if (!createCanvasColorBuffer()) return false; + } + if (!createCanvasDepthStencilBuffer()) return false; + return true; + } + void SwapChain_D3D11::destroyRenderAttachment() + { + _log("destroyRenderAttachment"); + + destroyCanvasDepthStencilBuffer(); + destroyCanvasColorBuffer(); + destroySwapChainRenderTarget(); + } + void SwapChain_D3D11::applyRenderAttachment() + { + //_log("applyRenderAttachment"); + + if (auto* ctx = m_device->GetD3D11DeviceContext()) + { + ID3D11RenderTargetView* rtvs[1] = { m_canvas_d3d11_rtv.get() }; + ctx->OMSetRenderTargets(1, rtvs, m_canvas_d3d11_dsv.get()); + } + } + void SwapChain_D3D11::clearRenderAttachment() + { + //_log("clearRenderAttachment"); + + if (auto* ctx = m_device->GetD3D11DeviceContext()) + { + if (m_canvas_d3d11_rtv) + { + FLOAT const clear_color[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; + ctx->ClearRenderTargetView(m_canvas_d3d11_rtv.get(), clear_color); + } + if (m_canvas_d3d11_dsv) + { + ctx->ClearDepthStencilView(m_canvas_d3d11_dsv.get(), D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0u); + } + ctx->Flush(); // 让命令立即提交到 GPU + } + } + + bool SwapChain_D3D11::updateLetterBoxingRendererTransform() + { + _log("updateLetterBoxingRendererTransform"); + assert(m_canvas_d3d11_srv); + assert(m_swap_chain_d3d11_rtv); + + return m_scaling_renderer.UpdateTransform( + m_canvas_d3d11_srv.get(), + m_swap_chain_d3d11_rtv.get(), + m_scaling_mode == SwapChainScalingMode::Stretch + ); + } + bool SwapChain_D3D11::presentLetterBoxingRenderer() + { + _log("presentLetterBoxingRenderer"); + assert(m_canvas_d3d11_srv); + assert(m_swap_chain_d3d11_rtv); + + return m_scaling_renderer.Draw( + m_canvas_d3d11_srv.get(), + m_swap_chain_d3d11_rtv.get(), + true + ); + } + + bool SwapChain_D3D11::handleDirectCompositionWindowSize(Vector2U size) + { + _log("handleDirectCompositionWindowSize"); + + if (size.x == 0 || size.y == 0) + { + assert(false); return false; + } + + if (!dxgi_swapchain) + { + assert(false); return false; + } + + // 此时交换链和画布一致,不应该修改交换链本身,而是修改合成变换 + + if (!updateDirectCompositionTransform()) return false; + + return true; + } + bool SwapChain_D3D11::handleSwapChainWindowSize(Vector2U size) + { + _log("handleSwapChainWindowSize"); + + if (size.x == 0 || size.y == 0) + { + assert(false); return false; + } + + if (!dxgi_swapchain) + { + assert(false); return false; + } + + // 此时交换链和画布分离,应该重新调整交换链尺寸 + + HRNew; + + destroySwapChainRenderTarget(); + + HRGet = dxgi_swapchain->ResizeBuffers(0, size.x, size.y, DXGI_FORMAT_UNKNOWN, m_swap_chain_info.Flags); + HRCheckCallReturnBool("IDXGISwapChain::ResizeBuffers"); + + if (!createSwapChainRenderTarget()) return false; + + if (!updateLetterBoxingRendererTransform()) return false; + + // TODO: 对于现代交换链模型,由于使用了 DirectComposition,还需要重新设置一次 Content + + return true; + } + + bool SwapChain_D3D11::setWindowMode(Vector2U size) + { + _log("setWindowMode"); + + if (size.x < 1 || size.y < 1) + { + Logger::error( + "[core] [SwapChain] size cannot be ({}x{})", + size.x, size.y + ); + assert(false); return false; + } + + if (m_enable_composition || (!m_disable_composition && m_modern_swap_chain_available && checkMultiPlaneOverlaySupport(m_device->GetD3D11Device()))) + { + m_is_composition_mode = true; + return setCompositionWindowMode(size); + } + else + { + m_is_composition_mode = false; + } + + dispatchEvent(EventType::SwapChainDestroy); + destroySwapChain(); + + if (!m_disable_modern_swap_chain && m_modern_swap_chain_available) + { + // TODO: 这样就没法独占全屏了,因为拿不到包含的Output + m_canvas_size = size; + if (!createCompositionSwapChain(size, /* latency event */ true)) // 让它创建渲染附件 + { + return false; + } + } + else + { + m_canvas_size = size; + if (!createSwapChain(false, {}, false)) // 让它创建渲染附件 + { + return false; + } + } + + // 更新数据 + + m_init = TRUE; + if (!updateLetterBoxingRendererTransform()) return false; + + // 通知各个组件交换链已重新创建 + + dispatchEvent(EventType::SwapChainCreate); + + return true; + } + bool SwapChain_D3D11::setCompositionWindowMode(Vector2U size) + { + _log("setCompositionWindowMode"); + + // 销毁旧交换链 + + dispatchEvent(EventType::SwapChainDestroy); + destroySwapChain(); + + // 创建交换链 + + bool latency_event = true; + m_canvas_size = size; + if (!createCompositionSwapChain(size, latency_event)) + { + return false; + } + + // 更新数据 + + m_init = TRUE; + + // 通知各个组件交换链已重新创建 + + dispatchEvent(EventType::SwapChainCreate); + + return true; + } + + bool SwapChain_D3D11::setCanvasSize(Vector2U size) + { + _log("setCanvasSize"); + + if (size.x == 0 || size.y == 0) + { + Logger::error( + "[core] [SwapChain] size cannot be ({}x{})", + size.x, size.y + ); + assert(false); return false; + } + + m_canvas_size = size; + + // TODO: 如果尺寸没变,是不是可以直接返回? + + if (!dxgi_swapchain) + { + return true; // 当交换链还未初始化时,仅保存画布尺寸 + } + + dispatchEvent(EventType::SwapChainDestroy); + + if (m_is_composition_mode) + { + // 对于合成交换链,由于交换链和画布是一致的,所以要调整交换链尺寸 + + destroyRenderAttachment(); + + HRNew; + HRGet = dxgi_swapchain->ResizeBuffers(0, size.x, size.y, DXGI_FORMAT_UNKNOWN, m_swap_chain_info.Flags); + HRCheckCallReturnBool("IDXGISwapChain::ResizeBuffers"); + + if (!createRenderAttachment()) return false; + + if (!updateDirectCompositionTransform()) return false; + } + else + { + // 对于普通交换链,由于画布是独立的,只需重新创建画布 + + destroyCanvasDepthStencilBuffer(); + destroyCanvasColorBuffer(); + + if (!createCanvasColorBuffer()) return false; + if (!createCanvasDepthStencilBuffer()) return false; + + if (!updateLetterBoxingRendererTransform()) return false; + } + + dispatchEvent(EventType::SwapChainCreate); + + if (!m_is_composition_mode && m_swap_chain_fullscreen_mode) + { + // TODO: LuaSTG 那边会先调用 setCanvasSize 再调用 setWindowMode 触发两次交换链创建 + // 重新选择合适的独占全屏模式 + leaveExclusiveFullscreen(); + enterExclusiveFullscreen(); + } + + return true; + } + + void SwapChain_D3D11::setScalingMode(SwapChainScalingMode mode) + { + m_scaling_mode = mode; + if (m_is_composition_mode) + updateDirectCompositionTransform(); + else + updateLetterBoxingRendererTransform(); + } + + void SwapChain_D3D11::waitFrameLatency() + { + if (m_swapchain_want_present_reset) + { + m_swapchain_want_present_reset = FALSE; + waitFrameLatency(1000, true); + } + else + { + waitFrameLatency(1000, false); + } + } + void SwapChain_D3D11::setVSync(bool enable) + { + m_swap_chain_vsync = enable; + } + bool SwapChain_D3D11::present() + { + HRESULT hr = S_OK; + + // 手动合成画面的情况下,通过内接缩放渲染器来缩放显示 + + if (!m_is_composition_mode) { + tracy_d3d11_context_zone(m_device->GetTracyContext(), "PreScaling"); + if (!presentLetterBoxingRenderer()) { + return false; + } + m_device->GetD3D11DeviceContext()->Flush(); // 立即提交命令到 GPU + } + + // 绘制标题栏 + +#ifdef LUASTG_ENABLE_DIRECT2D + auto& title_bar_controller = static_cast(m_window.get())->getTitleBarController(); + if (m_is_composition_mode) { + tracy_d3d11_context_zone(m_device->GetTracyContext(), "TitleBarComposition"); + // 绘制标题栏到单独的表面 + if (title_bar_controller.isVisible()) { + if (!m_title_bar_attached) { + HRGet = dcomp_visual_root->AddVisual(dcomp_visual_title_bar.get(), TRUE, dcomp_visual_swap_chain.get()); + HRCheckCallReturnBool("IDCompositionVisual2::AddVisual"); + if (!commitDirectComposition()) return false; + m_title_bar_attached = true; + } + auto const swap_chain_size = swap_chain_title_bar.getSize(); + auto const title_bar_height = title_bar_controller.getHeight(); + if (title_bar_height != swap_chain_size.y) { + if (!swap_chain_title_bar.setSize(Vector2U(swap_chain_size.x, title_bar_height))) { + return false; + } + } + swap_chain_title_bar.clearRenderTarget(); + title_bar_controller.draw(swap_chain_title_bar.GetD2D1Bitmap1()); + if (!swap_chain_title_bar.present()) { + return false; + } + } + else if (m_title_bar_attached) { + HRGet = dcomp_visual_root->RemoveVisual(dcomp_visual_title_bar.get()); + HRCheckCallReturnBool("IDCompositionVisual2::RemoveVisual"); + if (!commitDirectComposition()) return false; + m_title_bar_attached = false; + } + } + else { + tracy_d3d11_context_zone(m_device->GetTracyContext(), "DrawTitleBar"); + // 绘制标题栏到交换链上,而不是画布上 + title_bar_controller.draw(m_swap_chain_d2d1_bitmap.get()); + } +#endif + + // 呈现 + + UINT interval = 0; + UINT flags = 0; + if (isModernSwapChainModel(m_swap_chain_info)) { + // 现代交换链模型 + if (!m_swap_chain_vsync && (m_swap_chain_info.Flags & DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING)) { + // 如果禁用了垂直同步,且支持 DXGI_FEATURE_PRESENT_ALLOW_TEARING 功能,使用该模式获得最低延迟 + // 如果系统、硬件(特别是显示器)、驱动支持可变刷新率,那么将不会造成画面撕裂 + flags |= DXGI_PRESENT_ALLOW_TEARING; + } + else { + // 异步三重缓冲模式 + flags |= DXGI_PRESENT_DO_NOT_WAIT; + } + } + else { + // 传统交换链模型,通过指定同步间隔开/关垂直同步 + // 注意:从 Windows 8 开始才支持 DXGI_PRESENT_DO_NOT_WAIT + interval = m_swap_chain_vsync ? 1 : 0; + } + hr = gHR = dxgi_swapchain->Present(interval, flags); + + // 清空渲染状态并丢弃内容 + + m_device->GetD3D11DeviceContext()->ClearState(); + if (const auto ctx1 = m_device->GetD3D11DeviceContext1(); ctx1 != nullptr) { + ctx1->DiscardView(m_swap_chain_d3d11_rtv.get()); + } + + // 检查结果 + + if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) { + // 设备丢失 + return m_device->handleDeviceLost(); + } + else if (hr != DXGI_ERROR_WAS_STILL_DRAWING && FAILED(hr)) { + Logger::error("Windows API failed: IDXGISwapChain::Present"); + return false; + } + + return true; + } + + bool SwapChain_D3D11::saveSnapshotToFile(StringView path) + { + std::wstring wpath(utf8::to_wstring(path)); + + HRESULT hr = S_OK; + + win32::com_ptr d3d11_resource; + m_canvas_d3d11_rtv->GetResource(d3d11_resource.put()); + + hr = gHR = DirectX::SaveWICTextureToFile( + m_device->GetD3D11DeviceContext(), + d3d11_resource.get(), + GUID_ContainerFormatJpeg, + wpath.c_str(), + &GUID_WICPixelFormat24bppBGR); + if (FAILED(hr)) + { + Logger::error("Windows API failed: DirectX::SaveWICTextureToFile"); + return false; + } + + return true; + } + + SwapChain_D3D11::SwapChain_D3D11(IWindow* p_window, GraphicsDevice* p_device) + : m_window(p_window) + , m_device(p_device) + { + assert(p_window); + assert(p_device); + auto const& gs = core::ConfigurationLoader::getInstance().getGraphicsSystem(); + m_modern_swap_chain_available = checkModernSwapChainModelAvailable(m_device->GetD3D11Device()); + m_disable_exclusive_fullscreen = !gs.isAllowExclusiveFullscreen(); + m_disable_modern_swap_chain = !gs.isAllowModernSwapChain(); + m_enable_composition = false; // TODO + m_disable_composition = !gs.isAllowDirectComposition(); + m_scaling_renderer.AttachDevice(m_device->GetD3D11Device()); + m_window->addEventListener(this); + m_device->addEventListener(this); + } + SwapChain_D3D11::~SwapChain_D3D11() + { + m_window->removeEventListener(this); + m_device->removeEventListener(this); + destroySwapChain(); + m_scaling_renderer.DetachDevice(); + m_modern_swap_chain_available = false; + assert(m_eventobj.size() == 0); + assert(m_eventobj_late.size() == 0); + } + + bool SwapChain_D3D11::create(IWindow* p_window, GraphicsDevice* p_device, SwapChain_D3D11** pp_swapchain) + { + try + { + *pp_swapchain = new SwapChain_D3D11(p_window, p_device); + return true; + } + catch (...) + { + *pp_swapchain = nullptr; + return false; + } + } + + bool ISwapChain::create(IWindow* p_window, IGraphicsDevice* p_device, ISwapChain** pp_swapchain) + { + try + { + *pp_swapchain = new SwapChain_D3D11(p_window, static_cast(p_device)); + return true; + } + catch (...) + { + *pp_swapchain = nullptr; + return false; + } + } +} diff --git a/LuaSTG/Core/Graphics/SwapChain_D3D11.hpp b/engine/graphics/core/Graphics/SwapChain_D3D11.hpp similarity index 66% rename from LuaSTG/Core/Graphics/SwapChain_D3D11.hpp rename to engine/graphics/core/Graphics/SwapChain_D3D11.hpp index 6a37de46..1f11ad49 100644 --- a/LuaSTG/Core/Graphics/SwapChain_D3D11.hpp +++ b/engine/graphics/core/Graphics/SwapChain_D3D11.hpp @@ -1,27 +1,27 @@ #pragma once #include "core/SmartReference.hpp" #include "core/implement/ReferenceCounted.hpp" -#include "Core/Graphics/SwapChain.hpp" -#include "Core/Graphics/Window_Win32.hpp" -#include "Core/Graphics/Direct3D11/Device.hpp" -#include "Core/Graphics/Direct3D11/LetterBoxingRenderer.hpp" -#include "Platform/RuntimeLoader/DirectComposition.hpp" +#include "core/Graphics/SwapChain.hpp" +#include "core/Graphics/Direct3D11/LetterBoxingRenderer.hpp" +#include "d3d11/GraphicsDevice.hpp" +#include "windows/RuntimeLoader/DirectComposition.hpp" +#include namespace core::Graphics { class SecondarySwapChain { private: DXGI_SWAP_CHAIN_DESC1 info{}; - wil::com_ptr_nothrow dxgi_factory; - wil::com_ptr_nothrow d3d11_device; - wil::com_ptr_nothrow d3d11_device_context; + win32::com_ptr dxgi_factory; + win32::com_ptr d3d11_device; + win32::com_ptr d3d11_device_context; #ifdef LUASTG_ENABLE_DIRECT2D - wil::com_ptr_nothrow d2d1_device_context; + win32::com_ptr d2d1_device_context; #endif - wil::com_ptr_nothrow dxgi_swap_chain; - wil::com_ptr_nothrow d3d11_rtv; + win32::com_ptr dxgi_swap_chain; + win32::com_ptr d3d11_rtv; #ifdef LUASTG_ENABLE_DIRECT2D - wil::com_ptr_nothrow d2d1_bitmap; + win32::com_ptr d2d1_bitmap; #endif private: bool createRenderAttachment(); @@ -43,15 +43,15 @@ namespace core::Graphics class SwapChain_D3D11 : public implement::ReferenceCounted , public IWindowEventListener - , public IDeviceEventListener + , public IGraphicsDeviceEventListener { private: - SmartReference m_window; - SmartReference m_device; + SmartReference m_window; + SmartReference m_device; Direct3D11::LetterBoxingRenderer m_scaling_renderer; - Microsoft::WRL::Wrappers::Event dxgi_swapchain_event; - Microsoft::WRL::ComPtr dxgi_swapchain; + wil::unique_event_nothrow dxgi_swapchain_event; + win32::com_ptr dxgi_swapchain; DXGI_SWAP_CHAIN_DESC1 m_swap_chain_info{}; DXGI_SWAP_CHAIN_FULLSCREEN_DESC m_swap_chain_fullscreen_info{}; BOOL m_swap_chain_fullscreen_mode{ FALSE }; @@ -69,15 +69,15 @@ namespace core::Graphics SwapChainScalingMode m_scaling_mode{ SwapChainScalingMode::AspectRatio }; - private: - void onDeviceCreate(); - void onDeviceDestroy(); - void onWindowCreate(); - void onWindowDestroy(); - void onWindowActive(); - void onWindowInactive(); - void onWindowSize(core::Vector2U size); - void onWindowFullscreenStateChange(bool state); + public: + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; + void onWindowCreate() override; + void onWindowDestroy() override; + void onWindowActive() override; + void onWindowInactive() override; + void onWindowSize(core::Vector2U size) override; + void onWindowFullscreenStateChange(bool state) override; private: void destroySwapChain(); @@ -91,12 +91,12 @@ namespace core::Graphics private: bool m_is_composition_mode{ false }; Platform::RuntimeLoader::DirectComposition dcomp_loader; - Microsoft::WRL::ComPtr dcomp_desktop_device; - Microsoft::WRL::ComPtr dcomp_target; - Microsoft::WRL::ComPtr dcomp_visual_root; - Microsoft::WRL::ComPtr dcomp_visual_swap_chain; + win32::com_ptr dcomp_desktop_device; + win32::com_ptr dcomp_target; + win32::com_ptr dcomp_visual_root; + win32::com_ptr dcomp_visual_swap_chain; #ifdef LUASTG_ENABLE_DIRECT2D - Microsoft::WRL::ComPtr dcomp_visual_title_bar; + win32::com_ptr dcomp_visual_title_bar; SecondarySwapChain swap_chain_title_bar; bool m_title_bar_attached{ false }; #endif @@ -108,14 +108,14 @@ namespace core::Graphics bool createCompositionSwapChain(Vector2U size, bool latency_event); private: - Microsoft::WRL::ComPtr m_swap_chain_d3d11_rtv; + win32::com_ptr m_swap_chain_d3d11_rtv; #ifdef LUASTG_ENABLE_DIRECT2D - Microsoft::WRL::ComPtr m_swap_chain_d2d1_bitmap; + win32::com_ptr m_swap_chain_d2d1_bitmap; #endif Vector2U m_canvas_size{ 640,480 }; - Microsoft::WRL::ComPtr m_canvas_d3d11_srv; - Microsoft::WRL::ComPtr m_canvas_d3d11_rtv; - Microsoft::WRL::ComPtr m_canvas_d3d11_dsv; + win32::com_ptr m_canvas_d3d11_srv; + win32::com_ptr m_canvas_d3d11_rtv; + win32::com_ptr m_canvas_d3d11_dsv; private: bool createSwapChainRenderTarget(); void destroySwapChainRenderTarget(); @@ -167,9 +167,9 @@ namespace core::Graphics bool saveSnapshotToFile(StringView path); public: - SwapChain_D3D11(Window_Win32* p_window, Direct3D11::Device* p_device); + SwapChain_D3D11(IWindow* p_window, GraphicsDevice* p_device); ~SwapChain_D3D11(); public: - static bool create(Window_Win32* p_window, Direct3D11::Device* p_device, SwapChain_D3D11** pp_swapchain); + static bool create(IWindow* p_window, GraphicsDevice* p_device, SwapChain_D3D11** pp_swapchain); }; } diff --git a/engine/graphics/core/GraphicsBuffer.hpp b/engine/graphics/core/GraphicsBuffer.hpp new file mode 100644 index 00000000..112b96d1 --- /dev/null +++ b/engine/graphics/core/GraphicsBuffer.hpp @@ -0,0 +1,16 @@ +#pragma once +#include "core/ReferenceCounted.hpp" + +namespace core { + CORE_INTERFACE IGraphicsBuffer : IReferenceCounted { + virtual void* getNativeResource() const = 0; + virtual void* getNativeView() const = 0; + + virtual uint32_t getSizeInBytes() const = 0; + virtual bool map(void** out_pointer, bool cycle) = 0; + virtual bool unmap() = 0; + virtual bool update(const void* data, uint32_t size, bool cycle) = 0; + }; + + CORE_INTERFACE_ID(IGraphicsBuffer, "b76fab56-f2e9-5908-8d0b-a762275b2b7f") +} diff --git a/engine/graphics/core/GraphicsDevice.hpp b/engine/graphics/core/GraphicsDevice.hpp new file mode 100644 index 00000000..e5c389dd --- /dev/null +++ b/engine/graphics/core/GraphicsDevice.hpp @@ -0,0 +1,64 @@ +#pragma once +#include "core/ReferenceCounted.hpp" +#include "core/ImmutableString.hpp" +#include "core/GraphicsBuffer.hpp" +#include "core/GraphicsSampler.hpp" +#include "core/DepthStencilBuffer.hpp" + +#include "core/Graphics/Device.hpp" + +namespace core { + CORE_INTERFACE IGraphicsDeviceEventListener { + virtual void onGraphicsDeviceCreate() = 0; + virtual void onGraphicsDeviceDestroy() = 0; + }; + + struct GraphicsDeviceMemoryStatistics { + struct Scope { + uint64_t budget; + uint64_t current_usage; + uint64_t available_for_reservation; + uint64_t current_reservation; + }; + Scope local{}; + Scope non_local{}; + }; + + CORE_INTERFACE IGraphicsDevice : IReferenceCounted { + virtual void* getNativeDevice() = 0; + + virtual void addEventListener(IGraphicsDeviceEventListener* listener) = 0; + virtual void removeEventListener(IGraphicsDeviceEventListener* listener) = 0; + + virtual bool createVertexBuffer(uint32_t size_in_bytes, IGraphicsBuffer** output_buffer) = 0; + virtual bool createIndexBuffer(uint32_t size_in_bytes, IGraphicsBuffer** output_buffer) = 0; + virtual bool createConstantBuffer(uint32_t size_in_bytes, IGraphicsBuffer** output_buffer) = 0; + + virtual bool createSampler(const GraphicsSamplerInfo& info, IGraphicsSampler** out_sampler) = 0; + + virtual bool createDepthStencilBuffer(Vector2U size, IDepthStencilBuffer** out_depth_stencil_buffer) = 0; + + static bool create(StringView preferred_gpu, IGraphicsDevice** output); + + // from IDevice + + virtual GraphicsDeviceMemoryStatistics getMemoryStatistics() = 0; + + virtual bool recreate() = 0; + virtual void setPreferenceGpu(StringView preferred_gpu) = 0; + virtual uint32_t getGpuCount() = 0; + virtual StringView getGpuName(uint32_t index) = 0; + virtual StringView getCurrentGpuName() const noexcept = 0; + + virtual void* getNativeHandle() = 0; + virtual void* getNativeRendererHandle() = 0; + + virtual bool createTextureFromFile(StringView path, bool mipmap, Graphics::ITexture2D** pp_texture) = 0; + virtual bool createTextureFromImage(IImage* image, bool mipmap, Graphics::ITexture2D** pp_texture) = 0; + virtual bool createTexture(Vector2U size, Graphics::ITexture2D** pp_texture) = 0; + + virtual bool createRenderTarget(Vector2U size, Graphics::IRenderTarget** pp_rt) = 0; + }; + + CORE_INTERFACE_ID(IGraphicsDevice, "17b76b63-ceb6-5f87-aa5f-366e89d7176e") +} diff --git a/engine/graphics/core/GraphicsDeviceManager.hpp b/engine/graphics/core/GraphicsDeviceManager.hpp new file mode 100644 index 00000000..e1b34659 --- /dev/null +++ b/engine/graphics/core/GraphicsDeviceManager.hpp @@ -0,0 +1,21 @@ +#pragma once +#include "core/ImmutableString.hpp" + +#ifdef log +#undef log +#endif + +namespace core { + enum class GraphicsSystemFeature { + windows_dxgi_present_allow_tearing, + }; + + class GraphicsDeviceManager { + public: + static bool refresh(); + static bool isFeatureSupported(GraphicsSystemFeature feature); + static uint32_t getPhysicalDeviceCount(); + static StringView getPhysicalDeviceName(uint32_t index); + static void log(); + }; +} diff --git a/engine/graphics/core/GraphicsFormat.hpp b/engine/graphics/core/GraphicsFormat.hpp new file mode 100644 index 00000000..9fc8adf2 --- /dev/null +++ b/engine/graphics/core/GraphicsFormat.hpp @@ -0,0 +1,154 @@ +#pragma once +#include + +namespace core { + enum class GraphicsFormat : int32_t { + unknown = 0, + + // float + + r32_g32_b32_a32_float, + r32_g32_b32_float, + r32_g32_float, + r32_float, + + r16_g16_b16_a16_float, + r16_g16_float, + r16_float, + + // unsigned float + + r11_g11_b10_ufloat, + + // int + + r32_g32_b32_a32_int, + r32_g32_b32_int, + r32_g32_int, + r32_int, + + r16_g16_b16_a16_int, + r16_g16_int, + r16_int, + + r8_g8_b8_a8_int, + r8_g8_int, + r8_int, + + // uint + + r32_g32_b32_a32_uint, + r32_g32_b32_uint, + r32_g32_uint, + r32_uint, + + r16_g16_b16_a16_uint, + r16_g16_uint, + r16_uint, + + r8_g8_b8_a8_uint, + r8_g8_uint, + r8_uint, + + // signed normalized + + r16_g16_b16_a16_snorm, + r16_g16_snorm, + r16_snorm, + + r8_g8_b8_a8_snorm, + r8_g8_snorm, + r8_snorm, + + // unsigned normalized + + r16_g16_b16_a16_unorm, + r16_g16_unorm, + r16_unorm, + + r10_g10_b10_a2_unorm, + + r8_g8_b8_a8_unorm, + r8_g8_unorm, + r8_unorm, + a8_unorm, + + b8_g8_r8_a8_unorm, + + b5_g6_r5_unorm, + b5_g5_r5_a1_unorm, + + // sRGB + + r8_g8_b8_a8_unorm_srgb, + b8_g8_r8_a8_unorm_srgb, + + // depth stencil + + d32_float, + d32_float_s8_x24_uint, + + d24_unorm_s8_uint, // d24_unorm + + d16_unorm, + + // bc + + bc1_unorm, + bc1_unorm_srgb, + + bc2_unorm, + bc2_unorm_srgb, + + bc3_unorm, + bc3_unorm_srgb, + + bc4_unorm, + bc4_snorm, + + bc5_unorm, + bc5_snorm, + + bc6h_uf16, + bc6h_sf16, + + bc7_unorm, + bc7_unorm_srgb, + + // other + + r32_g32_b32_a32_typeless, + r32_g32_b32_typeless, + r32_g32_typeless, + r32_g8_x24_typeless, + r32_float_x8_x24_typeless, + x32_typeless_g8_x24_uint, + r32_typeless, + + r24_g8_typeless, + r24_unorm_x8_typeless, + x24_typeless_g8_uint, + + r16_g16_b16_a16_typeless, + r16_g16_typeless, + r16_typeless, + + r10_g10_b10_a2_typeless, + r10_g10_b10_xr_bias_a2_unorm, + + r8_g8_b8_a8_typeless, + r8_g8_typeless, + r8_typeless, + + b8_g8_r8_a8_typeless, + b8_g8_r8_x8_typeless, + + bc1_typeless, + bc2_typeless, + bc3_typeless, + bc4_typeless, + bc5_typeless, + bc6h_typeless, + bc7_typeless, + }; +} diff --git a/engine/graphics/core/GraphicsSampler.hpp b/engine/graphics/core/GraphicsSampler.hpp new file mode 100644 index 00000000..79af538c --- /dev/null +++ b/engine/graphics/core/GraphicsSampler.hpp @@ -0,0 +1,71 @@ +#pragma once +#include "core/ReferenceCounted.hpp" + +namespace core { + enum class GraphicsFilterType : int32_t { + point = 0, + linear = 1, + }; + +#define FILTER_TYPE_MASK 0x3 +#define MIN_FILTER_SHIFT 4 +#define MAG_FILTER_SHIFT 2 +#define MIP_FILTER_SHIFT 0 +#define ANISOTROPIC_FILTER_BIT 0x40 + +#define ENCODE_FILTER(MIN, MAG, MIP) \ + ((static_cast(MIN) & FILTER_TYPE_MASK) << MIN_FILTER_SHIFT) | \ + ((static_cast(MAG) & FILTER_TYPE_MASK) << MAG_FILTER_SHIFT) | \ + ((static_cast(MIP) & FILTER_TYPE_MASK) << MIP_FILTER_SHIFT) + +#define FILTER_VALUE(MIN, MAG, MIP) min_##MIN##_mag_##MAG##_mip_##MIP = ENCODE_FILTER(GraphicsFilterType::##MIN, GraphicsFilterType::##MAG, GraphicsFilterType::##MIP) + + enum class GraphicsFilter : int32_t { + FILTER_VALUE(point , point , point ), + FILTER_VALUE(linear, point , point ), + FILTER_VALUE(point , linear, point ), + FILTER_VALUE(point , point , linear), + FILTER_VALUE(linear, linear, point ), + FILTER_VALUE(linear, point , linear), + FILTER_VALUE(point , linear, linear), + FILTER_VALUE(linear, linear, linear), + + point = min_point_mag_point_mip_point, + linear = min_linear_mag_linear_mip_linear, + anisotropic = ENCODE_FILTER(GraphicsFilterType::linear, GraphicsFilterType::linear, GraphicsFilterType::linear) | ANISOTROPIC_FILTER_BIT, + }; + +#undef FILTER_TYPE_MASK +#undef MIN_FILTER_SHIFT +#undef MAG_FILTER_SHIFT +#undef MIP_FILTER_SHIFT +#undef ANISOTROPIC_FILTER_BIT + +#undef ENCODE_FILTER + +#undef FILTER_VALUE + + enum class GraphicsTextureAddressMode : int32_t { + wrap = 1, + clamp = 3, + }; + + struct GraphicsSamplerInfo { + GraphicsFilter filter; + GraphicsTextureAddressMode address_u; + GraphicsTextureAddressMode address_v; + GraphicsTextureAddressMode address_w; + float mip_lod_bias; + uint32_t max_anisotropy; + float min_lod; + float max_lod; + }; + + CORE_INTERFACE IGraphicsSampler : IReferenceCounted { + virtual void* getNativeHandle() const noexcept = 0; + + virtual const GraphicsSamplerInfo* getInfo() const noexcept = 0; + }; + + CORE_INTERFACE_ID(IGraphicsSampler, "446fb2a1-0bb3-50c1-bb64-4de769036200"); +} diff --git a/engine/graphics/core/RenderTarget.hpp b/engine/graphics/core/RenderTarget.hpp new file mode 100644 index 00000000..7b9637ef --- /dev/null +++ b/engine/graphics/core/RenderTarget.hpp @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/engine/graphics/core/Texture2D.hpp b/engine/graphics/core/Texture2D.hpp new file mode 100644 index 00000000..fbb4c4b5 --- /dev/null +++ b/engine/graphics/core/Texture2D.hpp @@ -0,0 +1,45 @@ +#pragma once +#include "core/ReferenceCounted.hpp" +#include "core/Vector2.hpp" +#include "core/Rect.hpp" +#include "core/ImmutableString.hpp" +#include "core/Image.hpp" +#include "core/GraphicsFormat.hpp" +#include "core/GraphicsSampler.hpp" + +namespace core { + enum class TextureBindFlag { + shader_resource = 0x8, + render_target = 0x20, + depth_stencil_buffer = 0x40, + }; + + struct TextureInfo { + GraphicsFormat format; + TextureBindFlag bind_flags; + uint32_t width; + uint32_t height; + uint32_t mipmap_level; + }; + + CORE_INTERFACE ITexture2D : IReferenceCounted { + virtual void* getNativeResource() const noexcept = 0; + virtual void* getNativeView() const noexcept = 0; + + virtual bool isDynamic() const noexcept = 0; + virtual bool isPremultipliedAlpha() const noexcept = 0; + virtual void setPremultipliedAlpha(bool v) = 0; + virtual Vector2U getSize() const noexcept = 0; + + virtual bool resize(Vector2U size) = 0; + virtual bool update(RectU rect, void const* data, uint32_t row_pitch_in_bytes) = 0; + virtual void setImage(IImage* image) = 0; + + virtual bool saveToFile(StringView path) = 0; + + virtual void setSamplerState(IGraphicsSampler* sampler) = 0; + virtual IGraphicsSampler* getSamplerState() const noexcept = 0; + }; + + CORE_INTERFACE_ID(ITexture2D, "5477054a-61c9-5071-9339-a9959e538a21") +} diff --git a/engine/graphics/d3d11/DepthStencilBuffer.cpp b/engine/graphics/d3d11/DepthStencilBuffer.cpp new file mode 100644 index 00000000..455ebefe --- /dev/null +++ b/engine/graphics/d3d11/DepthStencilBuffer.cpp @@ -0,0 +1,108 @@ +#include "d3d11/DepthStencilBuffer.hpp" +#include "core/Logger.hpp" + +namespace core { + // IDepthStencilBuffer + + bool DepthStencilBuffer::setSize(Vector2U const size) { + m_texture.reset(); + m_view.reset(); + m_size = size; + return createResource(); + } + + // IGraphicsDeviceEventListener + + void DepthStencilBuffer::onGraphicsDeviceCreate() { + if (m_initialized) { + createResource(); + } + } + void DepthStencilBuffer::onGraphicsDeviceDestroy() { + m_texture.reset(); + m_view.reset(); + } + + // DepthStencilBuffer + + DepthStencilBuffer::DepthStencilBuffer() = default; + DepthStencilBuffer::~DepthStencilBuffer() { + if (m_initialized && m_device) { + m_device->removeEventListener(this); + } + } + + bool DepthStencilBuffer::initialize(IGraphicsDevice* const device, const Vector2U size) { + assert(device); + assert(size.x > 0 && size.y > 0); + m_device = device; + m_size = size; + if (!createResource()) { + return false; + } + m_initialized = true; + m_device->addEventListener(this); + return true; + } + bool DepthStencilBuffer::createResource() { + HRESULT hr = S_OK; + + const auto d3d11_device = static_cast(m_device->getNativeHandle()); + if (!d3d11_device) + return false; + win32::com_ptr d3d11_devctx; + d3d11_device->GetImmediateContext(d3d11_devctx.put()); + if (!d3d11_devctx) + return false; + + D3D11_TEXTURE2D_DESC tex2ddef = { + .Width = m_size.x, + .Height = m_size.y, + .MipLevels = 1, + .ArraySize = 1, + .Format = DXGI_FORMAT_D24_UNORM_S8_UINT, + .SampleDesc = DXGI_SAMPLE_DESC{.Count = 1,.Quality = 0,}, + .Usage = D3D11_USAGE_DEFAULT, + .BindFlags = D3D11_BIND_DEPTH_STENCIL, + .CPUAccessFlags = 0, + .MiscFlags = 0, + }; + hr = gHR = d3d11_device->CreateTexture2D(&tex2ddef, nullptr, m_texture.put()); + if (FAILED(hr)) { + Logger::error("Windows API failed: ID3D11Device::CreateTexture2D"); + return false; + } + M_D3D_SET_DEBUG_NAME(m_texture.get(), "DepthStencilBuffer_D3D11::d3d11_texture2d"); + + D3D11_DEPTH_STENCIL_VIEW_DESC dsvdef = { + .Format = tex2ddef.Format, + .ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D, + .Texture2D = D3D11_TEX2D_DSV{.MipSlice = 0,}, + }; + hr = gHR = d3d11_device->CreateDepthStencilView(m_texture.get(), &dsvdef, m_view.put()); + if (FAILED(hr)) { + Logger::error("Windows API failed: ID3D11Device::CreateDepthStencilView"); + return false; + } + M_D3D_SET_DEBUG_NAME(m_view.get(), "DepthStencilBuffer_D3D11::d3d11_dsv"); + + return true; + } +} + +#include "d3d11/GraphicsDevice.hpp" + +namespace core { + bool GraphicsDevice::createDepthStencilBuffer(const Vector2U size, IDepthStencilBuffer** const out_depth_stencil_buffer) { + if (out_depth_stencil_buffer == nullptr) { + assert(false); return false; + } + SmartReference buffer; + buffer.attach(new DepthStencilBuffer); + if (!buffer->initialize(this, size)) { + return false; + } + *out_depth_stencil_buffer = buffer.detach(); + return true; + } +} diff --git a/engine/graphics/d3d11/DepthStencilBuffer.hpp b/engine/graphics/d3d11/DepthStencilBuffer.hpp new file mode 100644 index 00000000..88dd9e5e --- /dev/null +++ b/engine/graphics/d3d11/DepthStencilBuffer.hpp @@ -0,0 +1,45 @@ +#pragma once +#include "core/DepthStencilBuffer.hpp" +#include "core/SmartReference.hpp" +#include "core/implement/ReferenceCounted.hpp" +#include "core/GraphicsDevice.hpp" +#include "d3d11/pch.h" + +namespace core { + class DepthStencilBuffer final : + public implement::ReferenceCounted, + public IGraphicsDeviceEventListener { + public: + // IDepthStencilBuffer + + void* getNativeResource() const noexcept override { return m_texture.get(); } + void* getNativeView() const noexcept override { return m_view.get(); } + + bool setSize(Vector2U size) override; + Vector2U getSize() const noexcept override { return m_size; } + + // IGraphicsDeviceEventListener + + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; + + // DepthStencilBuffer + + DepthStencilBuffer(); + DepthStencilBuffer(DepthStencilBuffer const&) = delete; + DepthStencilBuffer(DepthStencilBuffer&&) = delete; + DepthStencilBuffer& operator=(DepthStencilBuffer const&) = delete; + DepthStencilBuffer& operator=(DepthStencilBuffer&&) = delete; + ~DepthStencilBuffer(); + + bool initialize(IGraphicsDevice* device, Vector2U size); + bool createResource(); + + private: + SmartReference m_device; + win32::com_ptr m_texture; + win32::com_ptr m_view; + Vector2U m_size{}; + bool m_initialized{ false }; + }; +} diff --git a/engine/graphics/d3d11/DeviceHelper.cpp b/engine/graphics/d3d11/DeviceHelper.cpp new file mode 100644 index 00000000..090bc691 --- /dev/null +++ b/engine/graphics/d3d11/DeviceHelper.cpp @@ -0,0 +1,576 @@ +#include "d3d11/DeviceHelper.hpp" +#include "d3d11/ToStringHelper.hpp" +#include "core/Logger.hpp" + +namespace d3d11 { + using std::string_view_literals::operator ""sv; + + // NOTE: Direct3D 11 does not support D3D_FEATURE_LEVEL_12_2 + + bool createDevice( + IDXGIAdapter1* const adapter, + ID3D11Device** const device, ID3D11DeviceContext** const device_context, D3D_FEATURE_LEVEL* const feature_level + ) { + const auto driver_type = (adapter != nullptr) ? D3D_DRIVER_TYPE_UNKNOWN : D3D_DRIVER_TYPE_HARDWARE; + UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + flags |= D3D11_CREATE_DEVICE_DEBUG; + #endif + constexpr D3D_FEATURE_LEVEL feature_levels[] { + D3D_FEATURE_LEVEL_12_1, + D3D_FEATURE_LEVEL_12_0, + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1, + }; + std::vector results{}; + for (UINT offset = 0; offset <= 3; offset += 1) { + const auto hr = D3D11CreateDevice( + adapter, driver_type, nullptr, + flags, feature_levels + offset, 9u - offset, D3D11_SDK_VERSION, + device, feature_level, device_context + ); + if (SUCCEEDED(hr)) { + return true; + } + results.push_back(hr); + } + for (const auto hr : results) { + win32::check_hresult(hr, "D3D11CreateDevice"sv); + } + return false; + } + + bool createSoftwareDevice( + std::vector& results, const D3D_DRIVER_TYPE driver_type, + ID3D11Device** const device, ID3D11DeviceContext** const device_context, D3D_FEATURE_LEVEL* const feature_level + ) { + UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT; + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + flags |= D3D11_CREATE_DEVICE_DEBUG; + #endif + constexpr D3D_FEATURE_LEVEL feature_levels[] { + D3D_FEATURE_LEVEL_12_1, + D3D_FEATURE_LEVEL_12_0, + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1, + }; + for (UINT offset = 0; offset <= 3; offset += 1) { + win32::com_ptr local_devcie; + win32::com_ptr local_device_context; + D3D_FEATURE_LEVEL local_feature_level{}; + const auto hr = D3D11CreateDevice( + nullptr, driver_type, nullptr, + flags, feature_levels + offset, 9u - offset, D3D11_SDK_VERSION, + local_devcie.put(), &local_feature_level, local_device_context.put() + ); + if (SUCCEEDED(hr) && local_feature_level >= D3D_FEATURE_LEVEL_10_0) { + if (device) *device = local_devcie.detach(); + if (device_context) *device_context = local_device_context.detach(); + if (feature_level) *feature_level = local_feature_level; + return true; + } + results.push_back(hr); + } + return false; + } + bool createSoftwareDevice( + ID3D11Device** const device, ID3D11DeviceContext** const device_context, D3D_FEATURE_LEVEL* const feature_level, + D3D_DRIVER_TYPE* const driver_type + ) { + std::vector results{}; + + results.clear(); + if (createSoftwareDevice(results, D3D_DRIVER_TYPE_WARP, device, device_context, feature_level)) { + if (driver_type) *driver_type = D3D_DRIVER_TYPE_WARP; + return true; + } + for (const auto hr : results) { + win32::check_hresult(hr, "D3D11CreateDevice (D3D_DRIVER_TYPE_WARP)"sv); + } + + results.clear(); + if (createSoftwareDevice(results, D3D_DRIVER_TYPE_SOFTWARE, device, device_context, feature_level)) { + if (driver_type) *driver_type = D3D_DRIVER_TYPE_SOFTWARE; + return true; + } + for (const auto hr : results) { + win32::check_hresult(hr, "D3D11CreateDevice (D3D_DRIVER_TYPE_SOFTWARE)"sv); + } + + results.clear(); + if (createSoftwareDevice(results, D3D_DRIVER_TYPE_REFERENCE, device, device_context, feature_level)) { + if (driver_type) *driver_type = D3D_DRIVER_TYPE_REFERENCE; + return true; + } + for (const auto hr : results) { + win32::check_hresult(hr, "D3D11CreateDevice (D3D_DRIVER_TYPE_REFERENCE)"sv); + } + + return false; + } + + bool checkFormatSupport(ID3D11Device* const device, const DXGI_FORMAT format, UINT* const support, UINT* const support2) { + if (device == nullptr) { + assert(false); return false; + } + + D3D11_FEATURE_DATA_FORMAT_SUPPORT info{}; + D3D11_FEATURE_DATA_FORMAT_SUPPORT2 info2{}; + info.InFormat = info2.InFormat = format; + device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &info, sizeof(info)); + device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &info2, sizeof(info2)); + + if (support) *support = info.OutFormatSupport; + if (support2) *support2 = info2.OutFormatSupport2; + return true; + } + + void logDeviceFeatureSupportDetails(ID3D11Device* const device) { + assert(device != nullptr); + + std::string s; + s.append("[core] [GraphicsDevice] device feature support details:\n"sv); + + const auto feature_level = device->GetFeatureLevel(); + s.append(std::format(" Direct3D feature level: {}\n"sv, toStringView(feature_level))); + + #define GET_FEATURE(FEATURE) if (D3D11_FEATURE_DATA_##FEATURE info{}; SUCCEEDED(device->CheckFeatureSupport(D3D11_FEATURE_##FEATURE, &info, sizeof(info)))) + + GET_FEATURE(THREADING) { + s.append(std::format( + " Threading:\n"sv + " Driver concurrent creates: {}\n"sv + " Driver command lists: {}\n"sv + , toStringView(info.DriverConcurrentCreates == TRUE, Semantic::support) + , toStringView(info.DriverCommandLists == TRUE, Semantic::support) + )); + } + + GET_FEATURE(DOUBLES) { + s.append(std::format( + " Doubles:\n"sv + " Double precision float shader ops: {}\n"sv + , toStringView(info.DoublePrecisionFloatShaderOps == TRUE, Semantic::support) + )); + } + + GET_FEATURE(D3D10_X_HARDWARE_OPTIONS) { + s.append(std::format( + " Direct3D 10.x hardware options:\n"sv + " ComputeShaders + Raw/StructuredBuffers via shader 4.x: {}\n"sv + , toStringView(info.ComputeShaders_Plus_RawAndStructuredBuffers_Via_Shader_4_x == TRUE, Semantic::support) + )); + } + + GET_FEATURE(D3D11_OPTIONS) { + s.append(std::format( + " Direct3D 11 options:\n"sv + " Output merger logic op: {}\n"sv + " UAV only rendering forced sample count: {}\n"sv + " Discard APIs seen by driver: {}\n"sv + " Flags for update and copy seen by driver: {}\n"sv + " Clear view: {}\n"sv + " Copy with overlap: {}\n"sv + " ConstantBuffer partial update: {}\n"sv + " ConstantBuffer offsetting: {}\n"sv + " Map no overwrite on dynamic ConstantBuffer: {}\n"sv + " Map no overwrite on dynamic buffer SRV: {}\n"sv + " Multisample RTV with forced sample count one: {}\n"sv + " SAD4 shader instructions: {}\n"sv + " Extended doubles shader instructions: {}\n"sv + " Extended resource sharing: {}\n"sv + , toStringView(info.OutputMergerLogicOp == TRUE, Semantic::support) + , toStringView(info.UAVOnlyRenderingForcedSampleCount == TRUE, Semantic::support) + , toStringView(info.DiscardAPIsSeenByDriver == TRUE, Semantic::support) + , toStringView(info.FlagsForUpdateAndCopySeenByDriver == TRUE, Semantic::support) + , toStringView(info.ClearView == TRUE, Semantic::support) + , toStringView(info.CopyWithOverlap == TRUE, Semantic::support) + , toStringView(info.ConstantBufferPartialUpdate == TRUE, Semantic::support) + , toStringView(info.ConstantBufferOffsetting == TRUE, Semantic::support) + , toStringView(info.MapNoOverwriteOnDynamicConstantBuffer == TRUE, Semantic::support) + , toStringView(info.MapNoOverwriteOnDynamicBufferSRV == TRUE, Semantic::support) + , toStringView(info.MultisampleRTVWithForcedSampleCountOne == TRUE, Semantic::support) + , toStringView(info.SAD4ShaderInstructions == TRUE, Semantic::support) + , toStringView(info.ExtendedDoublesShaderInstructions == TRUE, Semantic::support) + , toStringView(info.ExtendedResourceSharing == TRUE, Semantic::support) + )); + } + + GET_FEATURE(ARCHITECTURE_INFO) { + s.append(std::format( + " Architecture info:\n"sv + " Tile based deferred renderer: {}\n"sv + , toStringView(info.TileBasedDeferredRenderer == TRUE, Semantic::yes_no) + )); + } + + GET_FEATURE(D3D9_OPTIONS) { + s.append(std::format( + " Direct3D 9 options:\n"sv + " Full non-pow2 texture support: {}\n"sv + , toStringView(info.FullNonPow2TextureSupport == TRUE, Semantic::support) + )); + } + + GET_FEATURE(SHADER_MIN_PRECISION_SUPPORT) { + s.append(std::format( + " Shader min precision support:\n"sv + " Pixel shader min precision: {}\n"sv + " All other shader stages min precision: {}\n"sv + , toStringView(static_cast(info.PixelShaderMinPrecision)) + , toStringView(static_cast(info.AllOtherShaderStagesMinPrecision)) + )); + } + + GET_FEATURE(D3D9_SHADOW_SUPPORT) { + s.append(std::format( + " Direct3D 9 shadow support:\n"sv + " Supports depth as texture with less-equal comparison filter: {}\n"sv + , toStringView(info.SupportsDepthAsTextureWithLessEqualComparisonFilter == TRUE, Semantic::support) + )); + } + + GET_FEATURE(D3D11_OPTIONS1) { + s.append(std::format( + " Direct3D 11 options 1:\n"sv + " Tiled resources tier: {}\n"sv + " Min max filtering: {}\n"sv + " Clear view also supports depth only formats: {}\n"sv + " Map on default buffers: {}\n"sv + , toStringView(info.TiledResourcesTier) + , toStringView(info.MinMaxFiltering == TRUE, Semantic::support) + , toStringView(info.ClearViewAlsoSupportsDepthOnlyFormats == TRUE, Semantic::support) + , toStringView(info.MapOnDefaultBuffers == TRUE, Semantic::support) + )); + } + + GET_FEATURE(D3D9_SIMPLE_INSTANCING_SUPPORT) { + s.append(std::format( + " Direct3D 9 simple instancing support:\n"sv + " Simple instancing supported: {}\n"sv + , toStringView(info.SimpleInstancingSupported == TRUE, Semantic::support) + )); + } + + GET_FEATURE(MARKER_SUPPORT) { + s.append(std::format( + " Marker support:\n"sv + " Profile: {}\n"sv + , toStringView(info.Profile == TRUE, Semantic::support) + )); + } + + GET_FEATURE(D3D9_OPTIONS1) { + s.append(std::format( + " Direct3D 9 options 1:\n"sv + " Full non-pow2 texture supported: {}\n"sv + " Depth as texture with less-equal comparison filter supported: {}\n"sv + " Simple instancing supported: {}\n"sv + " TextureCube face RenderTarget with non cube DepthStencil supported: {}\n"sv + , toStringView(info.FullNonPow2TextureSupported == TRUE, Semantic::support) + , toStringView(info.DepthAsTextureWithLessEqualComparisonFilterSupported == TRUE, Semantic::support) + , toStringView(info.SimpleInstancingSupported == TRUE, Semantic::support) + , toStringView(info.TextureCubeFaceRenderTargetWithNonCubeDepthStencilSupported == TRUE, Semantic::support) + )); + } + + GET_FEATURE(D3D11_OPTIONS2) { + s.append(std::format( + " Direct3D 11 options 1:\n"sv + " PS specified stencil ref supported: {}\n"sv + " Typed UAV load additional formats: {}\n"sv + " ROVs supported: {}\n"sv + " Conservative rasterization tier: {}\n"sv + " Tiled resources tier: {}\n"sv + " Map on default textures: {}\n"sv + " Standard swizzle: {}\n"sv + " Unified memory architecture: {}\n"sv + , toStringView(info.PSSpecifiedStencilRefSupported == TRUE, Semantic::support) + , toStringView(info.TypedUAVLoadAdditionalFormats == TRUE, Semantic::support) + , toStringView(info.ROVsSupported == TRUE, Semantic::support) + , toStringView(info.ConservativeRasterizationTier) + , toStringView(info.TiledResourcesTier) + , toStringView(info.MapOnDefaultTextures == TRUE, Semantic::support) + , toStringView(info.StandardSwizzle == TRUE, Semantic::support) + , toStringView(info.UnifiedMemoryArchitecture == TRUE, Semantic::support) + )); + } + + GET_FEATURE(D3D11_OPTIONS3) { + s.append(std::format( + " Direct3D 11 options 3:\n"sv + " VP and RT array index from any shader feeding rasterizer: {}\n"sv + , toStringView(info.VPAndRTArrayIndexFromAnyShaderFeedingRasterizer == TRUE, Semantic::support) + )); + } + + GET_FEATURE(GPU_VIRTUAL_ADDRESS_SUPPORT) { + s.append(std::format( + " GPU virtual address support:\n"sv + " Max GPU virtual address bits per resource: {}\n"sv + " Max GPU virtual address bits per process: {}\n"sv + , info.MaxGPUVirtualAddressBitsPerResource + , info.MaxGPUVirtualAddressBitsPerProcess + )); + } + + GET_FEATURE(D3D11_OPTIONS4) { + s.append(std::format( + " Direct3D 11 options 4:\n"sv + " Extended NV12 shared texture supported: {}\n"sv + , toStringView(info.ExtendedNV12SharedTextureSupported == TRUE, Semantic::support) + )); + } + + GET_FEATURE(SHADER_CACHE) { + s.append(std::format( + " Shader cache:\n"sv + " Support flags: {}\n"sv + , toStringView(static_cast(info.SupportFlags)) + )); + } + + GET_FEATURE(D3D11_OPTIONS5) { + s.append(std::format( + " Direct3D 11 options 5:\n"sv + " Shared resource tier: {}\n"sv + , toStringView(info.SharedResourceTier) + )); + } + + GET_FEATURE(DISPLAYABLE) { + s.append(std::format( + " Displayable:\n"sv + " Displayable texture: {}\n"sv + " Shared resource tier: {}\n"sv + , toStringView(info.DisplayableTexture == TRUE, Semantic::support) + , toStringView(info.SharedResourceTier) + )); + } + + GET_FEATURE(D3D11_OPTIONS6) { + s.append(std::format( + " Direct3D 11 options 6:\n"sv + " Shader access restricted resource tier: {}\n"sv + , toStringView(info.ShaderAccessRestrictedResourceTier) + )); + } + + #undef GET_FEATURE + + if (s.back() == '\n') { + s.pop_back(); + } + core::Logger::info(s); + } + + void logDeviceFormatSupportDetail(const D3D11_FEATURE_DATA_FORMAT_SUPPORT& info, const D3D11_FEATURE_DATA_FORMAT_SUPPORT2& info2, const std::string_view name, std::string& s) { + s.append(std::format(" {}:"sv, name)); + if (info.OutFormatSupport != 0) { + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_BUFFER) s.append(" BUFFER"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER) s.append(" IA_VERTEX_BUFFER"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER) s.append(" IA_INDEX_BUFFER"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_SO_BUFFER) s.append(" SO_BUFFER"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_TEXTURE1D) s.append(" TEXTURE1D"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_TEXTURE2D) s.append(" TEXTURE2D"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_TEXTURE3D) s.append(" TEXTURE3D"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_TEXTURECUBE) s.append(" TEXTURECUBE"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_SHADER_LOAD) s.append(" SHADER_LOAD"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE) s.append(" SHADER_SAMPLE"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON) s.append(" SHADER_SAMPLE_COMPARISON"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_MONO_TEXT) s.append(" SHADER_SAMPLE_MONO_TEXT"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_MIP) s.append(" MIP"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_MIP_AUTOGEN) s.append(" MIP_AUTOGEN"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_RENDER_TARGET) s.append(" RENDER_TARGET"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_BLENDABLE) s.append(" BLENDABLE"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL) s.append(" DEPTH_STENCIL"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_CPU_LOCKABLE) s.append(" CPU_LOCKABLE"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RESOLVE) s.append(" MULTISAMPLE_RESOLVE"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_DISPLAY) s.append(" DISPLAY"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_CAST_WITHIN_BIT_LAYOUT) s.append(" CAST_WITHIN_BIT_LAYOUT"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_RENDERTARGET) s.append(" MULTISAMPLE_RENDERTARGET"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_MULTISAMPLE_LOAD) s.append(" MULTISAMPLE_LOAD"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_SHADER_GATHER) s.append(" SHADER_GATHER"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_BACK_BUFFER_CAST) s.append(" BACK_BUFFER_CAST"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_TYPED_UNORDERED_ACCESS_VIEW) s.append(" TYPED_UNORDERED_ACCESS_VIEW"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON) s.append(" SHADER_GATHER_COMPARISON"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_DECODER_OUTPUT) s.append(" DECODER_OUTPUT"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT) s.append(" VIDEO_PROCESSOR_OUTPUT"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_INPUT) s.append(" VIDEO_PROCESSOR_INPUT"sv); + if (info.OutFormatSupport & D3D11_FORMAT_SUPPORT_VIDEO_ENCODER) s.append(" VIDEO_ENCODER"sv); + } + if (info2.OutFormatSupport2 != 0) { + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_ADD) s.append(" UAV_ATOMIC_ADD"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_BITWISE_OPS) s.append(" UAV_ATOMIC_BITWISE_OPS"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_COMPARE_STORE_OR_COMPARE_EXCHANGE) s.append(" UAV_ATOMIC_COMPARE_STORE_OR_COMPARE_EXCHANGE"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_EXCHANGE) s.append(" UAV_ATOMIC_EXCHANGE"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_SIGNED_MIN_OR_MAX) s.append(" UAV_ATOMIC_SIGNED_MIN_OR_MAX"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_UAV_ATOMIC_UNSIGNED_MIN_OR_MAX) s.append(" UAV_ATOMIC_UNSIGNED_MIN_OR_MAX"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_UAV_TYPED_LOAD) s.append(" UAV_TYPED_LOAD"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_UAV_TYPED_STORE) s.append(" UAV_TYPED_STORE"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_OUTPUT_MERGER_LOGIC_OP) s.append(" OUTPUT_MERGER_LOGIC_OP"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_TILED) s.append(" TILED"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_SHAREABLE) s.append(" SHAREABLE"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_MULTIPLANE_OVERLAY) s.append(" MULTIPLANE_OVERLAY"sv); + if (info2.OutFormatSupport2 & D3D11_FORMAT_SUPPORT2_DISPLAYABLE) s.append(" DISPLAYABLE"sv); + } + s.push_back('\n'); + } + void logDeviceFormatSupportDetails(ID3D11Device* const device) { + assert(device != nullptr); + + std::string s; + s.append("[core] [GraphicsDevice] device format support details:\n"sv); + + #define GET_SUPPORT(IN_FORMAT) \ + {\ + D3D11_FEATURE_DATA_FORMAT_SUPPORT info{}; D3D11_FEATURE_DATA_FORMAT_SUPPORT2 info2{}; \ + info.InFormat = info2.InFormat = DXGI_FORMAT_##IN_FORMAT; \ + device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT, &info, sizeof(info)); \ + device->CheckFeatureSupport(D3D11_FEATURE_FORMAT_SUPPORT2, &info2, sizeof(info2)); \ + logDeviceFormatSupportDetail(info, info2, #IN_FORMAT ""sv, s); \ + } + + GET_SUPPORT(R32G32B32A32_TYPELESS); + GET_SUPPORT(R32G32B32A32_FLOAT); + GET_SUPPORT(R32G32B32A32_UINT); + GET_SUPPORT(R32G32B32A32_SINT); + GET_SUPPORT(R32G32B32_TYPELESS); + GET_SUPPORT(R32G32B32_FLOAT); + GET_SUPPORT(R32G32B32_UINT); + GET_SUPPORT(R32G32B32_SINT); + GET_SUPPORT(R16G16B16A16_TYPELESS); + GET_SUPPORT(R16G16B16A16_FLOAT); + GET_SUPPORT(R16G16B16A16_UNORM); + GET_SUPPORT(R16G16B16A16_UINT); + GET_SUPPORT(R16G16B16A16_SNORM); + GET_SUPPORT(R16G16B16A16_SINT); + GET_SUPPORT(R32G32_TYPELESS); + GET_SUPPORT(R32G32_FLOAT); + GET_SUPPORT(R32G32_UINT); + GET_SUPPORT(R32G32_SINT); + GET_SUPPORT(R32G8X24_TYPELESS); + GET_SUPPORT(D32_FLOAT_S8X24_UINT); + GET_SUPPORT(R32_FLOAT_X8X24_TYPELESS); + GET_SUPPORT(X32_TYPELESS_G8X24_UINT); + GET_SUPPORT(R10G10B10A2_TYPELESS); + GET_SUPPORT(R10G10B10A2_UNORM); + GET_SUPPORT(R10G10B10A2_UINT); + GET_SUPPORT(R11G11B10_FLOAT); + GET_SUPPORT(R8G8B8A8_TYPELESS); + GET_SUPPORT(R8G8B8A8_UNORM); + GET_SUPPORT(R8G8B8A8_UNORM_SRGB); + GET_SUPPORT(R8G8B8A8_UINT); + GET_SUPPORT(R8G8B8A8_SNORM); + GET_SUPPORT(R8G8B8A8_SINT); + GET_SUPPORT(R16G16_TYPELESS); + GET_SUPPORT(R16G16_FLOAT); + GET_SUPPORT(R16G16_UNORM); + GET_SUPPORT(R16G16_UINT); + GET_SUPPORT(R16G16_SNORM); + GET_SUPPORT(R16G16_SINT); + GET_SUPPORT(R32_TYPELESS); + GET_SUPPORT(D32_FLOAT); + GET_SUPPORT(R32_FLOAT); + GET_SUPPORT(R32_UINT); + GET_SUPPORT(R32_SINT); + GET_SUPPORT(R24G8_TYPELESS); + GET_SUPPORT(D24_UNORM_S8_UINT); + GET_SUPPORT(R24_UNORM_X8_TYPELESS); + GET_SUPPORT(X24_TYPELESS_G8_UINT); + GET_SUPPORT(R8G8_TYPELESS); + GET_SUPPORT(R8G8_UNORM); + GET_SUPPORT(R8G8_UINT); + GET_SUPPORT(R8G8_SNORM); + GET_SUPPORT(R8G8_SINT); + GET_SUPPORT(R16_TYPELESS); + GET_SUPPORT(R16_FLOAT); + GET_SUPPORT(D16_UNORM); + GET_SUPPORT(R16_UNORM); + GET_SUPPORT(R16_UINT); + GET_SUPPORT(R16_SNORM); + GET_SUPPORT(R16_SINT); + GET_SUPPORT(R8_TYPELESS); + GET_SUPPORT(R8_UNORM); + GET_SUPPORT(R8_UINT); + GET_SUPPORT(R8_SNORM); + GET_SUPPORT(R8_SINT); + GET_SUPPORT(A8_UNORM); + GET_SUPPORT(R1_UNORM); + GET_SUPPORT(R9G9B9E5_SHAREDEXP); + GET_SUPPORT(R8G8_B8G8_UNORM); + GET_SUPPORT(G8R8_G8B8_UNORM); + GET_SUPPORT(BC1_TYPELESS); + GET_SUPPORT(BC1_UNORM); + GET_SUPPORT(BC1_UNORM_SRGB); + GET_SUPPORT(BC2_TYPELESS); + GET_SUPPORT(BC2_UNORM); + GET_SUPPORT(BC2_UNORM_SRGB); + GET_SUPPORT(BC3_TYPELESS); + GET_SUPPORT(BC3_UNORM); + GET_SUPPORT(BC3_UNORM_SRGB); + GET_SUPPORT(BC4_TYPELESS); + GET_SUPPORT(BC4_UNORM); + GET_SUPPORT(BC4_SNORM); + GET_SUPPORT(BC5_TYPELESS); + GET_SUPPORT(BC5_UNORM); + GET_SUPPORT(BC5_SNORM); + GET_SUPPORT(B5G6R5_UNORM); + GET_SUPPORT(B5G5R5A1_UNORM); + GET_SUPPORT(B8G8R8A8_UNORM); + GET_SUPPORT(B8G8R8X8_UNORM); + GET_SUPPORT(R10G10B10_XR_BIAS_A2_UNORM); + GET_SUPPORT(B8G8R8A8_TYPELESS); + GET_SUPPORT(B8G8R8A8_UNORM_SRGB); + GET_SUPPORT(B8G8R8X8_TYPELESS); + GET_SUPPORT(B8G8R8X8_UNORM_SRGB); + GET_SUPPORT(BC6H_TYPELESS); + GET_SUPPORT(BC6H_UF16); + GET_SUPPORT(BC6H_SF16); + GET_SUPPORT(BC7_TYPELESS); + GET_SUPPORT(BC7_UNORM); + GET_SUPPORT(BC7_UNORM_SRGB); + GET_SUPPORT(AYUV); + GET_SUPPORT(Y410); + GET_SUPPORT(Y416); + GET_SUPPORT(NV12); + GET_SUPPORT(P010); + GET_SUPPORT(P016); + GET_SUPPORT(420_OPAQUE); + GET_SUPPORT(YUY2); + GET_SUPPORT(Y210); + GET_SUPPORT(Y216); + GET_SUPPORT(NV11); + GET_SUPPORT(AI44); + GET_SUPPORT(IA44); + GET_SUPPORT(P8); + GET_SUPPORT(A8P8); + GET_SUPPORT(B4G4R4A4_UNORM); + + GET_SUPPORT(P208); + GET_SUPPORT(V208); + GET_SUPPORT(V408); + + GET_SUPPORT(SAMPLER_FEEDBACK_MIN_MIP_OPAQUE); + GET_SUPPORT(SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE); + + GET_SUPPORT(A4B4G4R4_UNORM); + + #undef GET_SUPPORT + + if (s.back() == '\n') { + s.pop_back(); + } + core::Logger::info(s); + } +} diff --git a/engine/graphics/d3d11/DeviceHelper.hpp b/engine/graphics/d3d11/DeviceHelper.hpp new file mode 100644 index 00000000..57c305f8 --- /dev/null +++ b/engine/graphics/d3d11/DeviceHelper.hpp @@ -0,0 +1,20 @@ +#pragma once +#include "d3d11/pch.h" + +namespace d3d11 { + bool createDevice( + IDXGIAdapter1* adapter, + ID3D11Device** device, ID3D11DeviceContext** device_context, D3D_FEATURE_LEVEL* feature_level + ); + + bool createSoftwareDevice( + ID3D11Device** device, ID3D11DeviceContext** device_context, D3D_FEATURE_LEVEL* feature_level, + D3D_DRIVER_TYPE* driver_type + ); + + bool checkFormatSupport(ID3D11Device* device, DXGI_FORMAT format, UINT* support, UINT* support2 = nullptr); + + void logDeviceFeatureSupportDetails(ID3D11Device* device); + + void logDeviceFormatSupportDetails(ID3D11Device* device); +} diff --git a/engine/graphics/d3d11/FormatHelper.cpp b/engine/graphics/d3d11/FormatHelper.cpp new file mode 100644 index 00000000..cc670814 --- /dev/null +++ b/engine/graphics/d3d11/FormatHelper.cpp @@ -0,0 +1,285 @@ +#include "d3d11/FormatHelper.hpp" + +namespace d3d11 { + DXGI_FORMAT toFormat(const core::GraphicsFormat format) { + switch (format) { + case core::GraphicsFormat::unknown: return DXGI_FORMAT_UNKNOWN; + + // float + + case core::GraphicsFormat::r32_g32_b32_a32_float: return DXGI_FORMAT_R32G32B32A32_FLOAT; + case core::GraphicsFormat::r32_g32_b32_float: return DXGI_FORMAT_R32G32B32_FLOAT; + case core::GraphicsFormat::r32_g32_float: return DXGI_FORMAT_R32G32_FLOAT; + case core::GraphicsFormat::r32_float: return DXGI_FORMAT_R32_FLOAT; + + case core::GraphicsFormat::r16_g16_b16_a16_float: return DXGI_FORMAT_R16G16B16A16_FLOAT; + case core::GraphicsFormat::r16_g16_float: return DXGI_FORMAT_R16G16_FLOAT; + case core::GraphicsFormat::r16_float: return DXGI_FORMAT_R16_FLOAT; + + // unsigned float + + case core::GraphicsFormat::r11_g11_b10_ufloat: return DXGI_FORMAT_R11G11B10_FLOAT; + + // int + + case core::GraphicsFormat::r32_g32_b32_a32_int: return DXGI_FORMAT_R32G32B32A32_SINT; + case core::GraphicsFormat::r32_g32_b32_int: return DXGI_FORMAT_R32G32B32_SINT; + case core::GraphicsFormat::r32_g32_int: return DXGI_FORMAT_R32G32_SINT; + case core::GraphicsFormat::r32_int: return DXGI_FORMAT_R32_SINT; + + case core::GraphicsFormat::r16_g16_b16_a16_int: return DXGI_FORMAT_R16G16B16A16_SINT; + case core::GraphicsFormat::r16_g16_int: return DXGI_FORMAT_R16G16_SINT; + case core::GraphicsFormat::r16_int: return DXGI_FORMAT_R16_SINT; + + case core::GraphicsFormat::r8_g8_b8_a8_int: return DXGI_FORMAT_R8G8B8A8_SINT; + case core::GraphicsFormat::r8_g8_int: return DXGI_FORMAT_R8G8_SINT; + case core::GraphicsFormat::r8_int: return DXGI_FORMAT_R8_SINT; + + // uint + + case core::GraphicsFormat::r32_g32_b32_a32_uint: return DXGI_FORMAT_R32G32B32A32_UINT; + case core::GraphicsFormat::r32_g32_b32_uint: return DXGI_FORMAT_R32G32B32_UINT; + case core::GraphicsFormat::r32_g32_uint: return DXGI_FORMAT_R32G32_UINT; + case core::GraphicsFormat::r32_uint: return DXGI_FORMAT_R32_UINT; + + case core::GraphicsFormat::r16_g16_b16_a16_uint: return DXGI_FORMAT_R16G16B16A16_UINT; + case core::GraphicsFormat::r16_g16_uint: return DXGI_FORMAT_R16G16_UINT; + case core::GraphicsFormat::r16_uint: return DXGI_FORMAT_R16_UINT; + + case core::GraphicsFormat::r8_g8_b8_a8_uint: return DXGI_FORMAT_R8G8B8A8_UINT; + case core::GraphicsFormat::r8_g8_uint: return DXGI_FORMAT_R8G8_UINT; + case core::GraphicsFormat::r8_uint: return DXGI_FORMAT_R8_UINT; + + // signed normalized + + case core::GraphicsFormat::r16_g16_b16_a16_snorm: return DXGI_FORMAT_R16G16B16A16_SNORM; + case core::GraphicsFormat::r16_g16_snorm: return DXGI_FORMAT_R16G16_SNORM; + case core::GraphicsFormat::r16_snorm: return DXGI_FORMAT_R16_SNORM; + + case core::GraphicsFormat::r8_g8_b8_a8_snorm: return DXGI_FORMAT_R8G8B8A8_SNORM; + case core::GraphicsFormat::r8_g8_snorm: return DXGI_FORMAT_R8G8_SNORM; + case core::GraphicsFormat::r8_snorm: return DXGI_FORMAT_R8_SNORM; + + // unsigned normalized + + case core::GraphicsFormat::r16_g16_b16_a16_unorm: return DXGI_FORMAT_R16G16B16A16_UNORM; + case core::GraphicsFormat::r16_g16_unorm: return DXGI_FORMAT_R16G16_UNORM; + case core::GraphicsFormat::r16_unorm: return DXGI_FORMAT_R16_UNORM; + + case core::GraphicsFormat::r10_g10_b10_a2_unorm: return DXGI_FORMAT_R10G10B10A2_UNORM; + + case core::GraphicsFormat::r8_g8_b8_a8_unorm: return DXGI_FORMAT_R8G8B8A8_UNORM; + case core::GraphicsFormat::r8_g8_unorm: return DXGI_FORMAT_R8G8_UNORM; + case core::GraphicsFormat::r8_unorm: return DXGI_FORMAT_R8_UNORM; + case core::GraphicsFormat::a8_unorm: return DXGI_FORMAT_A8_UNORM; + + case core::GraphicsFormat::b8_g8_r8_a8_unorm: return DXGI_FORMAT_B8G8R8A8_UNORM; + + case core::GraphicsFormat::b5_g6_r5_unorm: return DXGI_FORMAT_B5G6R5_UNORM; + case core::GraphicsFormat::b5_g5_r5_a1_unorm: return DXGI_FORMAT_B5G5R5A1_UNORM; + + // sRGB + + case core::GraphicsFormat::r8_g8_b8_a8_unorm_srgb: return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; + case core::GraphicsFormat::b8_g8_r8_a8_unorm_srgb: return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB; + + // depth stencil + + case core::GraphicsFormat::d32_float: return DXGI_FORMAT_D32_FLOAT; + case core::GraphicsFormat::d32_float_s8_x24_uint: return DXGI_FORMAT_D32_FLOAT_S8X24_UINT; + + case core::GraphicsFormat::d24_unorm_s8_uint: return DXGI_FORMAT_D24_UNORM_S8_UINT; + + case core::GraphicsFormat::d16_unorm: return DXGI_FORMAT_D16_UNORM; + + // bc + + case core::GraphicsFormat::bc1_unorm: return DXGI_FORMAT_BC1_UNORM; + case core::GraphicsFormat::bc1_unorm_srgb: return DXGI_FORMAT_BC1_UNORM_SRGB; + + case core::GraphicsFormat::bc2_unorm: return DXGI_FORMAT_BC2_UNORM; + case core::GraphicsFormat::bc2_unorm_srgb: return DXGI_FORMAT_BC2_UNORM_SRGB; + + case core::GraphicsFormat::bc3_unorm: return DXGI_FORMAT_BC3_UNORM; + case core::GraphicsFormat::bc3_unorm_srgb: return DXGI_FORMAT_BC3_UNORM_SRGB; + + case core::GraphicsFormat::bc4_unorm: return DXGI_FORMAT_BC4_UNORM; + case core::GraphicsFormat::bc4_snorm: return DXGI_FORMAT_BC4_SNORM; + + case core::GraphicsFormat::bc5_unorm: return DXGI_FORMAT_BC5_UNORM; + case core::GraphicsFormat::bc5_snorm: return DXGI_FORMAT_BC5_SNORM; + + case core::GraphicsFormat::bc6h_uf16: return DXGI_FORMAT_BC6H_UF16; + case core::GraphicsFormat::bc6h_sf16: return DXGI_FORMAT_BC6H_SF16; + + case core::GraphicsFormat::bc7_unorm: return DXGI_FORMAT_BC7_UNORM; + case core::GraphicsFormat::bc7_unorm_srgb: return DXGI_FORMAT_BC7_UNORM_SRGB; + + // other + + case core::GraphicsFormat::r32_g32_b32_a32_typeless: return DXGI_FORMAT_R32G32B32A32_TYPELESS; + case core::GraphicsFormat::r32_g32_b32_typeless: return DXGI_FORMAT_R32G32B32_TYPELESS; + case core::GraphicsFormat::r32_g32_typeless: return DXGI_FORMAT_R32G32_TYPELESS; + case core::GraphicsFormat::r32_g8_x24_typeless: return DXGI_FORMAT_R32G8X24_TYPELESS; + case core::GraphicsFormat::r32_float_x8_x24_typeless: return DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS; + case core::GraphicsFormat::x32_typeless_g8_x24_uint: return DXGI_FORMAT_X32_TYPELESS_G8X24_UINT; + case core::GraphicsFormat::r32_typeless: return DXGI_FORMAT_R32_TYPELESS; + + case core::GraphicsFormat::r24_g8_typeless: return DXGI_FORMAT_R24G8_TYPELESS; + case core::GraphicsFormat::r24_unorm_x8_typeless: return DXGI_FORMAT_R24_UNORM_X8_TYPELESS; + case core::GraphicsFormat::x24_typeless_g8_uint: return DXGI_FORMAT_X24_TYPELESS_G8_UINT; + + case core::GraphicsFormat::r16_g16_b16_a16_typeless: return DXGI_FORMAT_R16G16B16A16_TYPELESS; + case core::GraphicsFormat::r16_g16_typeless: return DXGI_FORMAT_R16G16_TYPELESS; + case core::GraphicsFormat::r16_typeless: return DXGI_FORMAT_R16_TYPELESS; + + case core::GraphicsFormat::r10_g10_b10_a2_typeless: return DXGI_FORMAT_R10G10B10A2_TYPELESS; + case core::GraphicsFormat::r10_g10_b10_xr_bias_a2_unorm: return DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM; + + case core::GraphicsFormat::r8_g8_b8_a8_typeless: return DXGI_FORMAT_R8G8B8A8_TYPELESS; + case core::GraphicsFormat::r8_g8_typeless: return DXGI_FORMAT_R8G8_TYPELESS; + case core::GraphicsFormat::r8_typeless: return DXGI_FORMAT_R8_TYPELESS; + + case core::GraphicsFormat::b8_g8_r8_a8_typeless: return DXGI_FORMAT_B8G8R8A8_TYPELESS; + case core::GraphicsFormat::b8_g8_r8_x8_typeless: return DXGI_FORMAT_B8G8R8X8_TYPELESS; + + case core::GraphicsFormat::bc1_typeless: return DXGI_FORMAT_BC1_TYPELESS; + case core::GraphicsFormat::bc2_typeless: return DXGI_FORMAT_BC2_TYPELESS; + case core::GraphicsFormat::bc3_typeless: return DXGI_FORMAT_BC3_TYPELESS; + case core::GraphicsFormat::bc4_typeless: return DXGI_FORMAT_BC4_TYPELESS; + case core::GraphicsFormat::bc5_typeless: return DXGI_FORMAT_BC5_TYPELESS; + case core::GraphicsFormat::bc6h_typeless: return DXGI_FORMAT_BC6H_TYPELESS; + case core::GraphicsFormat::bc7_typeless: return DXGI_FORMAT_BC7_TYPELESS; + + // fallback + + default: assert(false); return DXGI_FORMAT_UNKNOWN; + }; + } +} + +// [x] DXGI_FORMAT_R32G32B32A32_TYPELESS +// [x] DXGI_FORMAT_R32G32B32A32_FLOAT +// [x] DXGI_FORMAT_R32G32B32A32_UINT +// [x] DXGI_FORMAT_R32G32B32A32_SINT +// [x] DXGI_FORMAT_R32G32B32_TYPELESS +// [x] DXGI_FORMAT_R32G32B32_FLOAT +// [x] DXGI_FORMAT_R32G32B32_UINT +// [x] DXGI_FORMAT_R32G32B32_SINT +// [x] DXGI_FORMAT_R16G16B16A16_TYPELESS +// [x] DXGI_FORMAT_R16G16B16A16_FLOAT +// [x] DXGI_FORMAT_R16G16B16A16_UNORM +// [x] DXGI_FORMAT_R16G16B16A16_UINT +// [x] DXGI_FORMAT_R16G16B16A16_SNORM +// [x] DXGI_FORMAT_R16G16B16A16_SINT +// [x] DXGI_FORMAT_R32G32_TYPELESS +// [x] DXGI_FORMAT_R32G32_FLOAT +// [x] DXGI_FORMAT_R32G32_UINT +// [x] DXGI_FORMAT_R32G32_SINT +// [x] DXGI_FORMAT_R32G8X24_TYPELESS +// [x] DXGI_FORMAT_D32_FLOAT_S8X24_UINT +// [x] DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS +// [x] DXGI_FORMAT_X32_TYPELESS_G8X24_UINT +// [x] DXGI_FORMAT_R10G10B10A2_TYPELESS +// [x] DXGI_FORMAT_R10G10B10A2_UNORM +// [ ] DXGI_FORMAT_R10G10B10A2_UINT +// [x] DXGI_FORMAT_R11G11B10_FLOAT +// [x] DXGI_FORMAT_R8G8B8A8_TYPELESS +// [x] DXGI_FORMAT_R8G8B8A8_UNORM +// [x] DXGI_FORMAT_R8G8B8A8_UNORM_SRGB +// [x] DXGI_FORMAT_R8G8B8A8_UINT +// [x] DXGI_FORMAT_R8G8B8A8_SNORM +// [x] DXGI_FORMAT_R8G8B8A8_SINT +// [x] DXGI_FORMAT_R16G16_TYPELESS +// [x] DXGI_FORMAT_R16G16_FLOAT +// [x] DXGI_FORMAT_R16G16_UNORM +// [x] DXGI_FORMAT_R16G16_UINT +// [x] DXGI_FORMAT_R16G16_SNORM +// [x] DXGI_FORMAT_R16G16_SINT +// [x] DXGI_FORMAT_R32_TYPELESS +// [x] DXGI_FORMAT_D32_FLOAT +// [x] DXGI_FORMAT_R32_FLOAT +// [x] DXGI_FORMAT_R32_UINT +// [x] DXGI_FORMAT_R32_SINT +// [x] DXGI_FORMAT_R24G8_TYPELESS +// [x] DXGI_FORMAT_D24_UNORM_S8_UINT +// [x] DXGI_FORMAT_R24_UNORM_X8_TYPELESS +// [x] DXGI_FORMAT_X24_TYPELESS_G8_UINT +// [x] DXGI_FORMAT_R8G8_TYPELESS +// [x] DXGI_FORMAT_R8G8_UNORM +// [x] DXGI_FORMAT_R8G8_UINT +// [x] DXGI_FORMAT_R8G8_SNORM +// [x] DXGI_FORMAT_R8G8_SINT +// [x] DXGI_FORMAT_R16_TYPELESS +// [x] DXGI_FORMAT_R16_FLOAT +// [x] DXGI_FORMAT_D16_UNORM +// [x] DXGI_FORMAT_R16_UNORM +// [x] DXGI_FORMAT_R16_UINT +// [x] DXGI_FORMAT_R16_SNORM +// [x] DXGI_FORMAT_R16_SINT +// [x] DXGI_FORMAT_R8_TYPELESS +// [x] DXGI_FORMAT_R8_UNORM +// [x] DXGI_FORMAT_R8_UINT +// [x] DXGI_FORMAT_R8_SNORM +// [x] DXGI_FORMAT_R8_SINT +// [x] DXGI_FORMAT_A8_UNORM +// [ ] DXGI_FORMAT_R1_UNORM +// [ ] DXGI_FORMAT_R9G9B9E5_SHAREDEXP +// [ ] DXGI_FORMAT_R8G8_B8G8_UNORM +// [ ] DXGI_FORMAT_G8R8_G8B8_UNORM +// [x] DXGI_FORMAT_BC1_TYPELESS +// [x] DXGI_FORMAT_BC1_UNORM +// [x] DXGI_FORMAT_BC1_UNORM_SRGB +// [x] DXGI_FORMAT_BC2_TYPELESS +// [x] DXGI_FORMAT_BC2_UNORM +// [x] DXGI_FORMAT_BC2_UNORM_SRGB +// [x] DXGI_FORMAT_BC3_TYPELESS +// [x] DXGI_FORMAT_BC3_UNORM +// [x] DXGI_FORMAT_BC3_UNORM_SRGB +// [x] DXGI_FORMAT_BC4_TYPELESS +// [x] DXGI_FORMAT_BC4_UNORM +// [x] DXGI_FORMAT_BC4_SNORM +// [x] DXGI_FORMAT_BC5_TYPELESS +// [x] DXGI_FORMAT_BC5_UNORM +// [x] DXGI_FORMAT_BC5_SNORM +// [x] DXGI_FORMAT_B5G6R5_UNORM +// [x] DXGI_FORMAT_B5G5R5A1_UNORM +// [x] DXGI_FORMAT_B8G8R8A8_UNORM +// [ ] DXGI_FORMAT_B8G8R8X8_UNORM +// [x] DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM +// [x] DXGI_FORMAT_B8G8R8A8_TYPELESS +// [x] DXGI_FORMAT_B8G8R8A8_UNORM_SRGB +// [x] DXGI_FORMAT_B8G8R8X8_TYPELESS +// [ ] DXGI_FORMAT_B8G8R8X8_UNORM_SRGB +// [x] DXGI_FORMAT_BC6H_TYPELESS +// [x] DXGI_FORMAT_BC6H_UF16 +// [x] DXGI_FORMAT_BC6H_SF16 +// [x] DXGI_FORMAT_BC7_TYPELESS +// [x] DXGI_FORMAT_BC7_UNORM +// [x] DXGI_FORMAT_BC7_UNORM_SRGB +// +// [ ] DXGI_FORMAT_AYUV +// [ ] DXGI_FORMAT_Y410 +// [ ] DXGI_FORMAT_Y416 +// [ ] DXGI_FORMAT_NV12 +// [ ] DXGI_FORMAT_P010 +// [ ] DXGI_FORMAT_P016 +// [ ] DXGI_FORMAT_420_OPAQUE +// [ ] DXGI_FORMAT_YUY2 +// [ ] DXGI_FORMAT_Y210 +// [ ] DXGI_FORMAT_Y216 +// [ ] DXGI_FORMAT_NV11 +// [ ] DXGI_FORMAT_AI44 +// [ ] DXGI_FORMAT_IA44 +// [ ] DXGI_FORMAT_P8 +// [ ] DXGI_FORMAT_A8P8 +// [ ] DXGI_FORMAT_B4G4R4A4_UNORM +// +// [ ] DXGI_FORMAT_P208 +// [ ] DXGI_FORMAT_V208 +// [ ] DXGI_FORMAT_V408 +// +// [ ] DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE +// [ ] DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE +// +// [ ] DXGI_FORMAT_A4B4G4R4_UNORM diff --git a/engine/graphics/d3d11/FormatHelper.hpp b/engine/graphics/d3d11/FormatHelper.hpp new file mode 100644 index 00000000..2eaa1700 --- /dev/null +++ b/engine/graphics/d3d11/FormatHelper.hpp @@ -0,0 +1,7 @@ +#pragma once +#include "core/GraphicsFormat.hpp" +#include "d3d11/pch.h" + +namespace d3d11 { + DXGI_FORMAT toFormat(core::GraphicsFormat format); +} diff --git a/engine/graphics/d3d11/GraphicsBuffer.cpp b/engine/graphics/d3d11/GraphicsBuffer.cpp new file mode 100644 index 00000000..4824893d --- /dev/null +++ b/engine/graphics/d3d11/GraphicsBuffer.cpp @@ -0,0 +1,538 @@ +#include "d3d11/GraphicsBuffer.hpp" + +namespace { + using std::string_view_literals::operator ""sv; + + uint32_t alignTo16(const uint32_t size) { + return ((size + 15u) / 16u) * 16; + } +} + +namespace core { + // IGraphicsDeviceEventListener + + void VertexBuffer::onGraphicsDeviceCreate() { + if (m_initialized) { + createResources(); + } + } + void VertexBuffer::onGraphicsDeviceDestroy() { + m_buffer.reset(); + } + + // IVertexBuffer + + void* VertexBuffer::getNativeResource() const { + return m_buffer.get(); + } + void* VertexBuffer::getNativeView() const { + return nullptr; + } + + uint32_t VertexBuffer::getSizeInBytes() const { + return m_size_in_bytes; + } + bool VertexBuffer::map(void** const out_pointer, const bool cycle) { + if (!out_pointer) { + assert(false); + return false; + } + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + D3D11_MAPPED_SUBRESOURCE mapped{}; + if (!win32::check_hresult_as_boolean( + context->Map( + m_buffer.get(), + 0, // sub resource + cycle ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE, + 0, // flags + &mapped + ), + "ID3D11DeviceContext::Map"sv + )) { + return false; + } + *out_pointer = mapped.pData; + return true; + } + bool VertexBuffer::unmap() { + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + context->Unmap(m_buffer.get(), 0); + return true; + } + bool VertexBuffer::update(const void* data, uint32_t size, bool cycle) { + if (size == 0) { + return true; + } + if (size > m_size_in_bytes) { + assert(false); + return false; + } + if (!data) { + assert(false); + return false; + } + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + D3D11_MAPPED_SUBRESOURCE mapped{}; + if (!win32::check_hresult_as_boolean( + context->Map(m_buffer.get(), 0, cycle ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped), + "ID3D11DeviceContext::Map"sv + )) { + return false; + } + std::memcpy(mapped.pData, data, size); + context->Unmap(m_buffer.get(), 0); + return true; + } + + // VertexBuffer + + VertexBuffer::VertexBuffer() = default; + VertexBuffer::~VertexBuffer() { + if (m_initialized && m_device) { + m_device->removeEventListener(this); + } + } + + bool VertexBuffer::createResources() { + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + D3D11_BUFFER_DESC info{}; + info.ByteWidth = m_size_in_bytes; + info.Usage = D3D11_USAGE_DYNAMIC; + info.BindFlags = D3D11_BIND_VERTEX_BUFFER; + info.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + return win32::check_hresult_as_boolean( + device->CreateBuffer(&info, nullptr, m_buffer.put()), + "ID3D11Device::CreateBuffer"sv + ); + } + bool VertexBuffer::createResources(IGraphicsDevice* const device, uint32_t const size_in_bytes) { + if (!device) { + assert(false); + return false; + } + if (size_in_bytes == 0) { + assert(false); + return false; + } + m_device = device; + m_size_in_bytes = size_in_bytes; + if (!createResources()) { + return false; + } + m_initialized = true; + m_device->addEventListener(this); + return true; + } +} + +namespace core { + // IGraphicsDeviceEventListener + + void IndexBuffer::onGraphicsDeviceCreate() { + if (m_initialized) { + createResources(); + } + } + void IndexBuffer::onGraphicsDeviceDestroy() { + m_buffer.reset(); + } + + // IIndexBuffer + + void* IndexBuffer::getNativeResource() const { + return m_buffer.get(); + } + void* IndexBuffer::getNativeView() const { + return nullptr; + } + + uint32_t IndexBuffer::getSizeInBytes() const { + return m_size_in_bytes; + } + bool IndexBuffer::map(void** const out_pointer, const bool cycle) { + if (!out_pointer) { + assert(false); + return false; + } + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + D3D11_MAPPED_SUBRESOURCE mapped{}; + if (!win32::check_hresult_as_boolean( + context->Map( + m_buffer.get(), + 0, // sub resource + cycle ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE, + 0, // flags + &mapped + ), + "ID3D11DeviceContext::Map"sv + )) { + return false; + } + *out_pointer = mapped.pData; + return true; + } + bool IndexBuffer::unmap() { + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + context->Unmap(m_buffer.get(), 0); + return true; + } + bool IndexBuffer::update(const void* data, uint32_t size, bool cycle) { + if (size == 0) { + return true; + } + if (size > m_size_in_bytes) { + assert(false); + return false; + } + if (!data) { + assert(false); + return false; + } + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + D3D11_MAPPED_SUBRESOURCE mapped{}; + if (!win32::check_hresult_as_boolean( + context->Map(m_buffer.get(), 0, cycle ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mapped), + "ID3D11DeviceContext::Map"sv + )) { + return false; + } + std::memcpy(mapped.pData, data, size); + context->Unmap(m_buffer.get(), 0); + return true; + } + + // IndexBuffer + + IndexBuffer::IndexBuffer() = default; + IndexBuffer::~IndexBuffer() { + if (m_initialized && m_device) { + m_device->removeEventListener(this); + } + } + + bool IndexBuffer::createResources() { + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + D3D11_BUFFER_DESC info{}; + info.ByteWidth = m_size_in_bytes; + info.Usage = D3D11_USAGE_DYNAMIC; + info.BindFlags = D3D11_BIND_INDEX_BUFFER; + info.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + return win32::check_hresult_as_boolean( + device->CreateBuffer(&info, nullptr, m_buffer.put()), + "ID3D11Device::CreateBuffer"sv + ); + } + bool IndexBuffer::createResources(IGraphicsDevice* const device, uint32_t const size_in_bytes) { + if (!device) { + assert(false); + return false; + } + if (size_in_bytes == 0) { + assert(false); + return false; + } + m_device = device; + m_size_in_bytes = size_in_bytes; + if (!createResources()) { + return false; + } + m_initialized = true; + m_device->addEventListener(this); + return true; + } +} + +namespace core { + // IGraphicsDeviceEventListener + + void ConstantBuffer::onGraphicsDeviceCreate() { + if (m_initialized) { + createResources(); + } + } + void ConstantBuffer::onGraphicsDeviceDestroy() { + m_buffer.reset(); + } + + // IConstantBuffer + + void* ConstantBuffer::getNativeResource() const { + return m_buffer.get(); + } + void* ConstantBuffer::getNativeView() const { + return nullptr; + } + + uint32_t ConstantBuffer::getSizeInBytes() const { + return m_size_in_bytes; + } + bool ConstantBuffer::map(void** const out_pointer, const bool cycle) { + if (!out_pointer) { + assert(false); + return false; + } + if (!cycle) { + assert(false); + return false; + } + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + D3D11_MAPPED_SUBRESOURCE mapped{}; + if (!win32::check_hresult_as_boolean( + context->Map( + m_buffer.get(), + 0, // sub resource + cycle ? D3D11_MAP_WRITE_DISCARD : D3D11_MAP_WRITE_NO_OVERWRITE, + 0, // flags + &mapped + ), + "ID3D11DeviceContext::Map"sv + )) { + return false; + } + *out_pointer = mapped.pData; + return true; + } + bool ConstantBuffer::unmap() { + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + context->Unmap(m_buffer.get(), 0); + return true; + } + bool ConstantBuffer::update(const void* data, uint32_t size, bool cycle) { + if (size == 0) { + return true; + } + if (size > m_size_in_bytes) { + assert(false); + return false; + } + if (!data) { + assert(false); + return false; + } + if (!cycle) { + assert(false); + return false; + } + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + D3D11_MAPPED_SUBRESOURCE mapped{}; + if (!win32::check_hresult_as_boolean( + context->Map(m_buffer.get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mapped), + "ID3D11DeviceContext::Map"sv + )) { + return false; + } + std::memcpy(mapped.pData, data, size); + context->Unmap(m_buffer.get(), 0); + return true; + } + + // ConstantBuffer + + ConstantBuffer::ConstantBuffer() = default; + ConstantBuffer::~ConstantBuffer() { + if (m_initialized && m_device) { + m_device->removeEventListener(this); + } + } + + bool ConstantBuffer::createResources() { + auto const device = static_cast(m_device->getNativeDevice()); + if (!device) { + assert(false); + return false; + } + win32::com_ptr context; + device->GetImmediateContext(context.put()); + if (!context) { + assert(false); + return false; + } + D3D11_BUFFER_DESC info{}; + // For a constant buffer (BindFlags of D3D11_BUFFER_DESC set to D3D11_BIND_CONSTANT_BUFFER), + // you must set the ByteWidth value of D3D11_BUFFER_DESC in multiples of 16, and less than or equal to D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT. + // https://learn.microsoft.com/en-us/windows/win32/api/D3D11/nf-d3d11-id3d11device-createbuffer + info.ByteWidth = alignTo16(m_size_in_bytes); + info.Usage = D3D11_USAGE_DYNAMIC; + info.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + info.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + return win32::check_hresult_as_boolean( + device->CreateBuffer(&info, nullptr, m_buffer.put()), + "ID3D11Device::CreateBuffer"sv + ); + } + bool ConstantBuffer::createResources(IGraphicsDevice* const device, uint32_t const size_in_bytes) { + if (!device) { + assert(false); + return false; + } + if (size_in_bytes == 0) { + assert(false); + return false; + } + m_device = device; + m_size_in_bytes = size_in_bytes; + if (!createResources()) { + return false; + } + m_initialized = true; + m_device->addEventListener(this); + return true; + } +} + +#include "d3d11/GraphicsDevice.hpp" + +namespace core { + bool GraphicsDevice::createVertexBuffer(uint32_t const size_in_bytes, IGraphicsBuffer** const output_buffer) { + if (!output_buffer) { + assert(false); + return false; + } + *output_buffer = nullptr; + SmartReference buffer; + buffer.attach(new VertexBuffer()); + if (!buffer->createResources(this, size_in_bytes)) { + return false; + } + *output_buffer = buffer.detach(); + return true; + } + bool GraphicsDevice::createIndexBuffer(uint32_t const size_in_bytes, IGraphicsBuffer** const output_buffer) { + if (!output_buffer) { + assert(false); + return false; + } + *output_buffer = nullptr; + SmartReference buffer; + buffer.attach(new IndexBuffer()); + if (!buffer->createResources(this, size_in_bytes)) { + return false; + } + *output_buffer = buffer.detach(); + return true; + } + bool GraphicsDevice::createConstantBuffer(uint32_t const size_in_bytes, IGraphicsBuffer** const output_buffer) { + if (!output_buffer) { + assert(false); + return false; + } + *output_buffer = nullptr; + SmartReference buffer; + buffer.attach(new ConstantBuffer()); + if (!buffer->createResources(this, size_in_bytes)) { + return false; + } + *output_buffer = buffer.detach(); + return true; + } +} diff --git a/engine/graphics/d3d11/GraphicsBuffer.hpp b/engine/graphics/d3d11/GraphicsBuffer.hpp new file mode 100644 index 00000000..9b9b86aa --- /dev/null +++ b/engine/graphics/d3d11/GraphicsBuffer.hpp @@ -0,0 +1,128 @@ +#pragma once +#include "core/GraphicsDevice.hpp" +#include "core/SmartReference.hpp" +#include "core/implement/ReferenceCounted.hpp" +#include "pch.h" + +namespace core { + class VertexBuffer final : + public implement::ReferenceCounted, + public IGraphicsDeviceEventListener + { + public: + // IGraphicsDeviceEventListener + + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; + + // IGraphicsBuffer + + void* getNativeResource() const override; + void* getNativeView() const override; + + uint32_t getSizeInBytes() const override; + bool map(void** out_pointer, bool cycle) override; + bool unmap() override; + bool update(const void* data, uint32_t size, bool cycle) override; + + // VertexBuffer + + VertexBuffer(); + VertexBuffer(VertexBuffer const&) = delete; + VertexBuffer(VertexBuffer&&) = delete; + VertexBuffer& operator=(VertexBuffer const&) = delete; + VertexBuffer& operator=(VertexBuffer&&) = delete; + ~VertexBuffer(); + + bool createResources(); + bool createResources(IGraphicsDevice* device, uint32_t size_in_bytes); + + private: + SmartReference m_device; + win32::com_ptr m_buffer; + uint32_t m_size_in_bytes{}; + bool m_initialized{}; + }; +} + +namespace core { + class IndexBuffer final : + public implement::ReferenceCounted, + public IGraphicsDeviceEventListener + { + public: + // IGraphicsDeviceEventListener + + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; + + // IGraphicsBuffer + + void* getNativeResource() const override; + void* getNativeView() const override; + + uint32_t getSizeInBytes() const override; + bool map(void** out_pointer, bool cycle) override; + bool unmap() override; + bool update(const void* data, uint32_t size, bool cycle) override; + + // IndexBuffer + + IndexBuffer(); + IndexBuffer(IndexBuffer const&) = delete; + IndexBuffer(IndexBuffer&&) = delete; + IndexBuffer& operator=(IndexBuffer const&) = delete; + IndexBuffer& operator=(IndexBuffer&&) = delete; + ~IndexBuffer(); + + bool createResources(); + bool createResources(IGraphicsDevice* device, uint32_t size_in_bytes); + + private: + SmartReference m_device; + win32::com_ptr m_buffer; + uint32_t m_size_in_bytes{}; + bool m_initialized{}; + }; +} + +namespace core { + class ConstantBuffer final : + public implement::ReferenceCounted, + public IGraphicsDeviceEventListener + { + public: + // IGraphicsDeviceEventListener + + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; + + // IGraphicsBuffer + + void* getNativeResource() const override; + void* getNativeView() const override; + + uint32_t getSizeInBytes() const override; + bool map(void** out_pointer, bool cycle) override; + bool unmap() override; + bool update(const void* data, uint32_t size, bool cycle) override; + + // ConstantBuffer + + ConstantBuffer(); + ConstantBuffer(ConstantBuffer const&) = delete; + ConstantBuffer(ConstantBuffer&&) = delete; + ConstantBuffer& operator=(ConstantBuffer const&) = delete; + ConstantBuffer& operator=(ConstantBuffer&&) = delete; + ~ConstantBuffer(); + + bool createResources(); + bool createResources(IGraphicsDevice* device, uint32_t size_in_bytes); + + private: + SmartReference m_device; + win32::com_ptr m_buffer; + uint32_t m_size_in_bytes{}; + bool m_initialized{}; + }; +} diff --git a/engine/graphics/d3d11/GraphicsDevice.cpp b/engine/graphics/d3d11/GraphicsDevice.cpp new file mode 100644 index 00000000..7a742f99 --- /dev/null +++ b/engine/graphics/d3d11/GraphicsDevice.cpp @@ -0,0 +1,394 @@ +#include "d3d11/GraphicsDevice.hpp" +#include "core/SmartReference.hpp" +#include "core/Configuration.hpp" +#include "core/Logger.hpp" +#include "d3d11/GraphicsDeviceManager.hpp" +#include "d3d11/ToStringHelper.hpp" +#include "d3d11/DeviceHelper.hpp" +#include "windows/AdapterPolicy.hpp" +#include "windows/Direct3D11.hpp" +#include "utf8.hpp" + +namespace { + using std::string_view_literals::operator ""sv; +} + +namespace core { + // IGraphicsDevice + + void* GraphicsDevice::getNativeDevice() { + return d3d11_device.get(); + } + + void GraphicsDevice::addEventListener(IGraphicsDeviceEventListener* const listener) { + assert(!m_is_dispatching_event); + std::erase(m_event_listeners, listener); + m_event_listeners.emplace_back(listener); + } + void GraphicsDevice::removeEventListener(IGraphicsDeviceEventListener* const listener) { + assert(!m_is_dispatching_event); + std::erase(m_event_listeners, listener); + } + + // GraphicsDevice + + GraphicsDevice::GraphicsDevice() = default; + GraphicsDevice::~GraphicsDevice() { + destroy(); + } +} + +namespace core { + // IGraphicsDevice + + GraphicsDeviceMemoryStatistics GraphicsDevice::getMemoryStatistics() { + GraphicsDeviceMemoryStatistics data{}; + win32::com_ptr adapter; + if (win32::check_hresult_as_boolean(dxgi_adapter->QueryInterface(adapter.put()))) { + DXGI_QUERY_VIDEO_MEMORY_INFO info = {}; + if (win32::check_hresult_as_boolean(adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_LOCAL, &info))) { + data.local.budget = info.Budget; + data.local.current_usage = info.CurrentUsage; + data.local.available_for_reservation = info.AvailableForReservation; + data.local.current_reservation = info.CurrentReservation; + } + if (win32::check_hresult_as_boolean(adapter->QueryVideoMemoryInfo(0, DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, &info))) { + data.non_local.budget = info.Budget; + data.non_local.current_usage = info.CurrentUsage; + data.non_local.available_for_reservation = info.AvailableForReservation; + data.non_local.current_reservation = info.CurrentReservation; + } + } + return data; + } + + bool GraphicsDevice::recreate() { + return doDestroyAndCreate(); + } + + // GraphicsDevice + + bool GraphicsDevice::create() { + Logger::info("[core] [GraphicsDevice] initializing..."); + + testAdapterPolicy(); + if (!createDXGI()) + return false; + if (!createD3D11()) + return false; + if (!createWIC()) + return false; +#ifdef LUASTG_ENABLE_DIRECT2D + if (!createD2D1()) + return false; +#endif + + Logger::info("[core] [GraphicsDevice] initialization complete"); + return true; + } + void GraphicsDevice::destroy() { + // 清理对象 +#ifdef LUASTG_ENABLE_DIRECT2D + destroyD2D1(); +#endif + destroyWIC(); // 长生存期 + destroyD3D11(); + destroyDXGI(); + assert(m_event_listeners.size() == 0); + } + bool GraphicsDevice::handleDeviceLost() { + if (d3d11_device) { + gHR = d3d11_device->GetDeviceRemovedReason(); + } + return doDestroyAndCreate(); + } + + // GraphicsDevice: private + + void GraphicsDevice::dispatchEvent(const Event e) { + assert(!m_is_dispatching_event); + m_is_dispatching_event = true; + + switch (e) { + case Event::create: + for (const auto listener : m_event_listeners) { + listener->onGraphicsDeviceCreate(); + } + break; + case Event::destroy: + for (const auto listener : m_event_listeners) { + listener->onGraphicsDeviceDestroy(); + } + break; + } + + m_is_dispatching_event = false; + } + + bool GraphicsDevice::testAdapterPolicy() { + if (preferred_adapter_name.empty()) { + return true; // default GPU + } + + auto testStage = [](const std::string& name, const bool nv, const bool amd) -> bool { + Platform::AdapterPolicy::setNVIDIA(nv); + Platform::AdapterPolicy::setAMD(amd); + if (!core::GraphicsDeviceManager::refresh()) { + return false; + } + if (core::GraphicsDeviceManager::getPhysicalDeviceCount() == 0) { + return false; + } + return core::GraphicsDeviceManager::getPhysicalDeviceName(0) == name; + }; + + // Stage 1 - Disable and test + if (testStage(preferred_adapter_name, false, false)) return true; + // Stage 2 - Enable and test + if (testStage(preferred_adapter_name, true, true)) return true; + // Stage 3 - NVIDIA and test + if (testStage(preferred_adapter_name, true, false)) return true; + // Stage 4 - AMD and test + if (testStage(preferred_adapter_name, false, true)) return true; + // Stage 5 - Disable and failed + Platform::AdapterPolicy::setAll(false); + + return false; + } + bool GraphicsDevice::selectAdapter() { + Logger::info("[core] [GraphicsDevice] enumerate physical devices"sv); + + win32::com_ptr adapter; + std::string adapter_name; + core::GraphicsDeviceManagerDXGI::refreshAndFindAdapter(preferred_adapter_name, adapter.put(), &adapter_name); + core::GraphicsDeviceManager::log(); + + if (adapter) { + if (!win32::check_hresult_as_boolean( + adapter->GetParent(IID_PPV_ARGS(dxgi_factory.put())), + "IDXGIObject::GetParent (IDXGIFactory2)"sv + )) { + return false; + } + dxgi_adapter = adapter; + dxgi_adapter_name = adapter_name; + } + + dxgi_adapter_name_list.clear(); + for (uint32_t i = 0; i < core::GraphicsDeviceManager::getPhysicalDeviceCount(); i += 1) { + dxgi_adapter_name_list.emplace_back(core::GraphicsDeviceManager::getPhysicalDeviceName(i)); + } + + if (!dxgi_adapter) { + Logger::error("[core] [GraphicsDevice] no physical device available"); + return false; + } + + //if (!link_to_output) { + // Logger::warn( + // "[core] [GraphicsDevice] {} doesn't appear to connect to any display output, which could result in:\n" + // " Buffer is copied over PCI-E when in exclusive fullscreen\n" + // " Desktop Window Manager takes over desktop composition when in exclusive fullscreen\n" + // " Degraded performance and increased frame latency" + // ); + //} + + Logger::info("[core] [GraphicsDevice] current physical device: {}", dxgi_adapter_name); + return true; + } + bool GraphicsDevice::createDXGI() { + if (!selectAdapter()) { + if (!core::ConfigurationLoader::getInstance().getGraphicsSystem().isAllowSoftwareDevice()) { + return false; + } + } + return true; + } + void GraphicsDevice::destroyDXGI() { + dxgi_factory.reset(); + dxgi_adapter.reset(); + + dxgi_adapter_name.clear(); + dxgi_adapter_name_list.clear(); + } + bool GraphicsDevice::createD3D11() { + HRESULT hr = S_OK; + + // 创建 + + if (dxgi_adapter) { + d3d11::createDevice( + dxgi_adapter.get(), + d3d11_device.put(), d3d11_devctx.put(), &d3d_feature_level + ); + } + else if (core::ConfigurationLoader::getInstance().getGraphicsSystem().isAllowSoftwareDevice()) { + D3D_DRIVER_TYPE driver_type{}; + if (d3d11::createSoftwareDevice( + d3d11_device.put(), d3d11_devctx.put(), &d3d_feature_level, + &driver_type + )) { + Logger::info("[core] [GraphicsDevice] software device type: {}", toStringView(driver_type)); + } + } + + if (!d3d11_device) { + Logger::error("[core] [GraphicsDevice] no device available"); + return false; + } + + if (!dxgi_adapter) { + hr = gHR = Platform::Direct3D11::GetDeviceAdater(d3d11_device.get(), dxgi_adapter.put()); + if (FAILED(hr)) { + Logger::error("Windows API failed: Platform::Direct3D11::GetDeviceAdater"); + return false; + } + } + + d3d11_devctx->QueryInterface(d3d11_devctx1.put()); // error can be safely ignored + + // 特性检查 + + d3d11::logDeviceFeatureSupportDetails(d3d11_device.get()); + d3d11::logDeviceFormatSupportDetails(d3d11_device.get()); + + UINT bgra32_support{}, bgra32_support2{}; + d3d11::checkFormatSupport(d3d11_device.get(), DXGI_FORMAT_B8G8R8A8_UNORM, &bgra32_support, &bgra32_support2); // error can be safely ignored + + constexpr UINT required_support = D3D11_FORMAT_SUPPORT_TEXTURE2D + | D3D11_FORMAT_SUPPORT_IA_VERTEX_BUFFER + | D3D11_FORMAT_SUPPORT_MIP + | D3D11_FORMAT_SUPPORT_RENDER_TARGET + | D3D11_FORMAT_SUPPORT_BLENDABLE + | D3D11_FORMAT_SUPPORT_DISPLAY; + if ((bgra32_support & required_support) != required_support) { + Logger::warn("[core] [GraphicsDevice] device does not fully support the B8G8R8A8 format"sv); + } + + tracy_context = tracy_d3d11_context_create(d3d11_device.get(), d3d11_devctx.get()); + + return true; + } + void GraphicsDevice::destroyD3D11() { + tracy_d3d11_context_destroy(tracy_context); + tracy_context = nullptr; + + d3d_feature_level = D3D_FEATURE_LEVEL_10_0; + + d3d11_device.reset(); + d3d11_devctx.reset(); + d3d11_devctx1.reset(); + } + bool GraphicsDevice::createWIC() { + HRESULT hr = S_OK; + + hr = gHR = CoCreateInstance(CLSID_WICImagingFactory2, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(wic_factory2.put())); + if (SUCCEEDED(hr)) { + hr = gHR = wic_factory2->QueryInterface(wic_factory.put()); + assert(SUCCEEDED(hr)); + if (FAILED(hr)) { + Logger::error("Windows API failed: IWICImagingFactory2::QueryInterface -> IWICImagingFactory"); + return false; + } + } + else { + Logger::error("Windows API failed: CoCreateInstance -> IWICImagingFactory2"); + // 没有那么严重,来再一次 + hr = gHR = CoCreateInstance(CLSID_WICImagingFactory1, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(wic_factory.put())); + assert(SUCCEEDED(hr)); + if (FAILED(hr)) { + Logger::error("Windows API failed: CoCreateInstance -> IWICImagingFactory"); + return false; + } + } + + return true; + } + void GraphicsDevice::destroyWIC() { + wic_factory.reset(); + wic_factory2.reset(); + } +#ifdef LUASTG_ENABLE_DIRECT2D + bool GraphicsDevice::createD2D1() { + HRESULT hr = S_OK; + + D2D1_FACTORY_OPTIONS d2d1_options{}; + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + d2d1_options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION; + #endif + hr = gHR = D2D1CreateFactory( + D2D1_FACTORY_TYPE_MULTI_THREADED, + __uuidof(ID2D1Factory1), + &d2d1_options, + d2d1_factory.put()); + if (FAILED(hr)) { + Logger::error("Windows API failed: D2D1CreateFactory -> ID2D1Factory1"); + assert(false); return false; + } + + win32::com_ptr dxgi_device; + hr = gHR = d3d11_device->QueryInterface(dxgi_device.put()); + if (FAILED(hr)) { + Logger::error("Windows API failed: ID3D11Device::QueryInterface -> IDXGIDevice"); + assert(false); return false; + } + + hr = gHR = d2d1_factory->CreateDevice(dxgi_device.get(), d2d1_device.put()); + if (FAILED(hr)) { + Logger::error("Windows API failed: ID2D1Factory1::CreateDevice"); + assert(false); return false; + } + + hr = gHR = d2d1_device->CreateDeviceContext(D2D1_DEVICE_CONTEXT_OPTIONS_NONE, d2d1_devctx.put()); + if (FAILED(hr)) { + Logger::error("Windows API failed: ID2D1Device::CreateDeviceContext"); + assert(false); return false; + } + + return true; + } + void GraphicsDevice::destroyD2D1() { + d2d1_factory.reset(); + d2d1_device.reset(); + d2d1_devctx.reset(); + } +#endif + bool GraphicsDevice::doDestroyAndCreate() { + dispatchEvent(Event::destroy); + +#ifdef LUASTG_ENABLE_DIRECT2D + destroyD2D1(); +#endif + //destroyWIC(); // 长生存期 + destroyD3D11(); + destroyDXGI(); + + testAdapterPolicy(); + + if (!createDXGI()) return false; + if (!createD3D11()) return false; + //if (!createWIC()) return false; // 长生存期 +#ifdef LUASTG_ENABLE_DIRECT2D + if (!createD2D1()) return false; +#endif + + dispatchEvent(Event::create); + return true; + } +} + +namespace core { + bool IGraphicsDevice::create(const StringView preferred_gpu, IGraphicsDevice** const output) { + if (output == nullptr) { + assert(false); return false; + } + SmartReference device; + device.attach(new GraphicsDevice()); + device->setPreferenceGpu(preferred_gpu); + if (!device->create()) { + return false; + } + *output = device.detach(); + return true; + } +} diff --git a/engine/graphics/d3d11/GraphicsDevice.hpp b/engine/graphics/d3d11/GraphicsDevice.hpp new file mode 100644 index 00000000..ec1efc07 --- /dev/null +++ b/engine/graphics/d3d11/GraphicsDevice.hpp @@ -0,0 +1,138 @@ +#pragma once +#include "core/GraphicsDevice.hpp" +#include "core/implement/ReferenceCounted.hpp" +#include "d3d11/pch.h" + +namespace core { + class GraphicsDevice final : public implement::ReferenceCounted { + public: + // IGraphicsDevice + + void* getNativeDevice() override; + + void addEventListener(IGraphicsDeviceEventListener* listener) override; + void removeEventListener(IGraphicsDeviceEventListener* listener) override; + + bool createVertexBuffer(uint32_t size_in_bytes, IGraphicsBuffer** output_buffer) override; + bool createIndexBuffer(uint32_t size_in_bytes, IGraphicsBuffer** output_buffer) override; + bool createConstantBuffer(uint32_t size_in_bytes, IGraphicsBuffer** output_buffer) override; + + bool createSampler(const GraphicsSamplerInfo& info, IGraphicsSampler** out_sampler) override; + + bool createDepthStencilBuffer(Vector2U size, IDepthStencilBuffer** out_depth_stencil_buffer) override; + + // from IDevice + + GraphicsDeviceMemoryStatistics getMemoryStatistics() override; + + bool recreate() override; + void setPreferenceGpu(StringView preferred_gpu) override { preferred_adapter_name = preferred_gpu; } + uint32_t getGpuCount() override { return static_cast(dxgi_adapter_name_list.size()); } + StringView getGpuName(uint32_t index) override { return dxgi_adapter_name_list[index]; } + StringView getCurrentGpuName() const noexcept override { return dxgi_adapter_name; } + + void* getNativeHandle() override { return d3d11_device.get(); } +#ifdef LUASTG_ENABLE_DIRECT2D + void* getNativeRendererHandle() override { return d2d1_devctx.get(); } +#else + void* getNativeRendererHandle() override { return nullptr; } +#endif + + bool createTextureFromFile(StringView path, bool mipmap, Graphics::ITexture2D** pp_texture) override; + bool createTexture(Vector2U size, Graphics::ITexture2D** pp_texture) override; + bool createTextureFromImage(IImage* image, bool mipmap, Graphics::ITexture2D** pp_texture) override; + + bool createRenderTarget(Vector2U size, Graphics::IRenderTarget** pp_rt) override; + + // GraphicsDevice + + GraphicsDevice(); + GraphicsDevice(GraphicsDevice const&) = delete; + GraphicsDevice(GraphicsDevice&&) = delete; + ~GraphicsDevice(); + + GraphicsDevice& operator=(GraphicsDevice const&) = delete; + GraphicsDevice& operator=(GraphicsDevice&&) = delete; + + ID3D11Device* GetD3D11Device() const noexcept { return d3d11_device.get(); } + ID3D11DeviceContext* GetD3D11DeviceContext() const noexcept { return d3d11_devctx.get(); } + ID3D11DeviceContext1* GetD3D11DeviceContext1() const noexcept { return d3d11_devctx1.get(); } + +#ifdef LUASTG_ENABLE_DIRECT2D + ID2D1Device* GetD2D1Device() const noexcept { return d2d1_device.get(); } + ID2D1DeviceContext* GetD2D1DeviceContext() const noexcept { return d2d1_devctx.get(); } +#endif + + IWICImagingFactory* GetWICImagingFactory() const noexcept { return wic_factory.get(); } + + tracy_d3d11_context_t GetTracyContext() const noexcept { return tracy_context; } + + bool create(); + void destroy(); + bool handleDeviceLost(); + + private: + enum class Event { + create, + destroy, + }; + + void dispatchEvent(Event e); + + bool testAdapterPolicy(); + bool selectAdapter(); + bool createDXGI(); + void destroyDXGI(); + bool createD3D11(); + void destroyD3D11(); + bool createWIC(); + void destroyWIC(); +#ifdef LUASTG_ENABLE_DIRECT2D + bool createD2D1(); + void destroyD2D1(); +#endif + bool doDestroyAndCreate(); + + // Event dispatcher + + std::vector m_event_listeners; + bool m_is_dispatching_event{ false }; + + // DXGI + + win32::com_ptr dxgi_factory; + win32::com_ptr dxgi_adapter; + + std::string preferred_adapter_name; + + std::string dxgi_adapter_name; + std::vector dxgi_adapter_name_list; + + // Direct3D + + D3D_FEATURE_LEVEL d3d_feature_level{ D3D_FEATURE_LEVEL_10_0 }; + + // Direct3D 11 + + win32::com_ptr d3d11_device; + win32::com_ptr d3d11_devctx; + win32::com_ptr d3d11_devctx1; + + // Window Image Component + + win32::com_ptr wic_factory; + win32::com_ptr wic_factory2; + + // Direct2D 1 + +#ifdef LUASTG_ENABLE_DIRECT2D + win32::com_ptr d2d1_factory; + win32::com_ptr d2d1_device; + win32::com_ptr d2d1_devctx; +#endif + + // Debug + + tracy_d3d11_context_t tracy_context{}; + }; +} diff --git a/engine/graphics/d3d11/GraphicsDeviceManager.cpp b/engine/graphics/d3d11/GraphicsDeviceManager.cpp new file mode 100644 index 00000000..d336422b --- /dev/null +++ b/engine/graphics/d3d11/GraphicsDeviceManager.cpp @@ -0,0 +1,317 @@ +#include "d3d11/GraphicsDeviceManager.hpp" +#include "utf8.hpp" +#include "core/Logger.hpp" +#include "d3d11/ToStringHelper.hpp" + +namespace { + using std::string_view_literals::operator ""sv; + + struct PhysicalDeviceInfo { + std::string name; + win32::com_ptr adapter; + DXGI_ADAPTER_DESC3 info{}; + int info_level{}; + D3D_FEATURE_LEVEL feature_level{ D3D_FEATURE_LEVEL_9_1 }; + }; + + std::vector physical_device_info; + std::vector physical_device_info_not_supported; + bool is_present_allow_tearing_supported{}; + + struct AutoReleaseaAapters { + ~AutoReleaseaAapters() { + for (auto& v : physical_device_info) { + v.adapter.reset(); + } + for (auto& v : physical_device_info_not_supported) { + v.adapter.reset(); + } + } + }; + + decltype(&CreateDXGIFactory2) getCreateFactory2() { + if (const auto dxgi = GetModuleHandleW(L"dxgi.dll"); dxgi != nullptr) { + return reinterpret_cast(GetProcAddress(dxgi, "CreateDXGIFactory2")); + } + return nullptr; + } + + bool createFactory(win32::com_ptr& factory) { + UINT flags{}; + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + flags |= DXGI_CREATE_FACTORY_DEBUG; + #endif + if (const auto createFactory2 = getCreateFactory2(); createFactory2 != nullptr) { + if (!win32::check_hresult_as_boolean( + createFactory2(flags, IID_PPV_ARGS(factory.put())), + "CreateDXGIFactory2"sv + )) { + return false; + } + } + else { + if (!win32::check_hresult_as_boolean( + CreateDXGIFactory1(IID_PPV_ARGS(factory.put())), + "CreateDXGIFactory1"sv + )) { + return false; + } + } + return true; + } + + bool isSoftwareOrRemoteAdapter(const DXGI_ADAPTER_DESC3& info) { + // https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/d3d10-graphics-programming-guide-dxgi#new-info-about-enumerating-adapters-for-windows-8 + // https://walbourn.github.io/anatomy-of-direct3d-11-create-device/ + return ((info.VendorId == 0x1414) && (info.DeviceId == 0x8c)) + || (info.Flags & DXGI_ADAPTER_FLAG3_REMOTE) + || (info.Flags & DXGI_ADAPTER_FLAG3_SOFTWARE); + } + + D3D_FEATURE_LEVEL testAdapterFeatureLevel(win32::com_ptr& adapter) { + constexpr UINT flags{ D3D11_CREATE_DEVICE_BGRA_SUPPORT }; + constexpr D3D_FEATURE_LEVEL feature_levels[] { + D3D_FEATURE_LEVEL_12_1, + D3D_FEATURE_LEVEL_12_0, + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1, + }; + D3D_FEATURE_LEVEL feature_level{}; + for (UINT offset = 0; offset <= 3; offset += 1) { + const auto hr = D3D11CreateDevice( + adapter.get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, + flags, feature_levels + offset, 9u - offset, D3D11_SDK_VERSION, + nullptr, &feature_level, nullptr + ); + if (SUCCEEDED(hr)) { + break; + } + } + return feature_level; + } + + bool internalRefresh(win32::com_ptr& factory, const bool save_adapter) { + if (!createFactory(factory)) { + return false; + } + + win32::com_ptr factory5; + std::ignore = factory->QueryInterface(factory5.put()); + if (factory5) { + BOOL supported{}; + if (win32::check_hresult_as_boolean( + factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &supported, sizeof(supported)), + "IDXGIFactory5::CheckFeatureSupport (DXGI_FEATURE_PRESENT_ALLOW_TEARING)"sv + )) { + is_present_allow_tearing_supported = supported == TRUE; + } + } + + win32::com_ptr adapter; + for (UINT i = 0; ; i += 1) { + const auto hr = factory->EnumAdapters1(i, adapter.put()); + if (hr == DXGI_ERROR_NOT_FOUND) { + break; + } + else if (FAILED(hr)) { + win32::check_hresult(hr, "IDXGIFactory1::EnumAdapters1"); + break; + } + + win32::com_ptr adapter2; + std::ignore = adapter->QueryInterface(adapter2.put()); + win32::com_ptr adapter4; + std::ignore = adapter->QueryInterface(adapter4.put()); + + PhysicalDeviceInfo info; + + if (adapter4 && win32::check_hresult_as_boolean( + adapter4->GetDesc3(&info.info), + "IDXGIAdapter4::GetDesc3"sv + )) { + info.info_level = 4; + } + + static_assert(sizeof(DXGI_ADAPTER_DESC2) == sizeof(DXGI_ADAPTER_DESC3), "bad reinterpret_cast"); + if (info.info_level == 0 && adapter2 && win32::check_hresult_as_boolean( + adapter2->GetDesc2(reinterpret_cast(&info.info)), + "IDXGIAdapter2::GetDesc2"sv + )) { + info.info_level = 2; + } + + static_assert(sizeof(DXGI_ADAPTER_DESC1) == sizeof(DXGI_ADAPTER_DESC3) - 8, "bad reinterpret_cast"); + if (info.info_level == 0 && win32::check_hresult_as_boolean( + adapter->GetDesc1(reinterpret_cast(&info.info)), + "IDXGIAdapter1::GetDesc1"sv + )) { + info.info_level = 1; + } + + info.feature_level = testAdapterFeatureLevel(adapter); + + if (info.info_level > 0) { + info.name = utf8::to_string(info.info.Description); + if (save_adapter) { + info.adapter = adapter; + } + if (info.feature_level >= D3D_FEATURE_LEVEL_10_0 && !isSoftwareOrRemoteAdapter(info.info)) { + physical_device_info.emplace_back(info); + } + else if (info.feature_level >= D3D_FEATURE_LEVEL_9_1) { + physical_device_info_not_supported.emplace_back(info); + } + // else: compute-only or software device + } + } + + return true; + } + + void logCollection(const std::vector& collection, std::string& s) { + for (const auto& v : collection) { + s.append(std::format( + " {}:\n"sv + " Direct3D feature level: {}\n"sv + " VendorId: 0x{:08x}\n"sv + " DeviceId: 0x{:08x}\n"sv + " SubSysId: 0x{:08x}\n"sv + " Revision: {}\n"sv + " Dedicated video memory: {} ({})\n"sv + " Dedicated system memory: {} ({})\n"sv + " Shared system memory: {} ({})\n"sv + " Adapter LUID: {:08x}-{:08x}\n"sv + " Flags: {}\n"sv + , v.name + , toStringView(v.feature_level) + , v.info.VendorId + , v.info.DeviceId + , v.info.SubSysId + , v.info.Revision + , v.info.DedicatedVideoMemory, toString(v.info.DedicatedVideoMemory, Semantic::data_size) + , v.info.DedicatedSystemMemory, toString(v.info.DedicatedSystemMemory, Semantic::data_size) + , v.info.SharedSystemMemory, toString(v.info.SharedSystemMemory, Semantic::data_size) + , static_cast(v.info.AdapterLuid.HighPart), v.info.AdapterLuid.LowPart + , toString(v.info.Flags) + )); + if (v.info_level < 4) { + continue; + } + s.append(std::format( + " Graphics preemption granularity: {}\n"sv + " Compute preemption granularity: {}\n"sv + , toStringView(v.info.GraphicsPreemptionGranularity) + , toStringView(v.info.ComputePreemptionGranularity) + )); + } + } +} + +namespace core { + bool GraphicsDeviceManager::refresh() { + physical_device_info.clear(); + physical_device_info_not_supported.clear(); + is_present_allow_tearing_supported = false; + + win32::com_ptr factory; + return internalRefresh(factory, false); + } + bool GraphicsDeviceManager::isFeatureSupported(const GraphicsSystemFeature feature) { + if (feature == GraphicsSystemFeature::windows_dxgi_present_allow_tearing) { + return is_present_allow_tearing_supported; + } + return false; + } + uint32_t GraphicsDeviceManager::getPhysicalDeviceCount() { + return static_cast(physical_device_info.size()); + } + StringView GraphicsDeviceManager::getPhysicalDeviceName(const uint32_t index) { + if (index >= physical_device_info.size()) { + return ""sv; + } + return physical_device_info.at(index).name; + } + void GraphicsDeviceManager::log() { + std::string s; + s.append(std::format( + "[core] [GraphicsDeviceManager] Graphics System details:\n"sv + " Features:\n"sv + " Present allow tearing (Windows DXGI): {}\n"sv + " Physical devices:\n"sv + , toStringView(is_present_allow_tearing_supported, Semantic::support) + )); + if (!physical_device_info.empty()) { + logCollection(physical_device_info, s); + } + else { + s.append(" N/A\n"sv); + } + if (!physical_device_info_not_supported.empty()) { + s.append(" Physical devices (unmet requirements):\n"sv); + logCollection(physical_device_info_not_supported, s); + } + if (s.back() == '\n') { + s.pop_back(); + } + Logger::info(s); + } +} + +namespace core { + bool GraphicsDeviceManagerDXGI::refreshAndGetFactory(IDXGIFactory2** const out_factory) { + if (out_factory == nullptr) { + assert(false); return false; + } + win32::com_ptr factory; + if (!internalRefresh(factory, false)) { + return false; + } + *out_factory = factory.detach(); + return true; + } + bool GraphicsDeviceManagerDXGI::refreshAndFindAdapter(const std::string_view name, IDXGIAdapter1** const adapter, std::string* const adapter_name) { + physical_device_info.clear(); + physical_device_info_not_supported.clear(); + is_present_allow_tearing_supported = false; + + if (adapter == nullptr) { + assert(false); return false; + } + + win32::com_ptr factory; + [[maybe_unused]] const AutoReleaseaAapters auto_release_adapters; + if (!internalRefresh(factory, true)) { + return false; + } + + if (!name.empty()) { + for (const auto& v : physical_device_info) { + if (v.name == name) { + v.adapter->AddRef(); + *adapter = v.adapter.get(); + if (adapter_name != nullptr) { + *adapter_name = v.name; + } + return true; + } + } + } + + if (!physical_device_info.empty()) { + const auto& v = physical_device_info.front(); + v.adapter->AddRef(); + *adapter = v.adapter.get(); + if (adapter_name != nullptr) { + *adapter_name = v.name; + } + return true; + } + + return false; + } +} diff --git a/engine/graphics/d3d11/GraphicsDeviceManager.hpp b/engine/graphics/d3d11/GraphicsDeviceManager.hpp new file mode 100644 index 00000000..3560d92a --- /dev/null +++ b/engine/graphics/d3d11/GraphicsDeviceManager.hpp @@ -0,0 +1,11 @@ +#pragma once +#include "core/GraphicsDeviceManager.hpp" +#include "d3d11/pch.h" + +namespace core { + class GraphicsDeviceManagerDXGI { + public: + static bool refreshAndGetFactory(IDXGIFactory2** out_factory); + static bool refreshAndFindAdapter(std::string_view name, IDXGIAdapter1** adapter, std::string* adapter_name = nullptr); + }; +} diff --git a/engine/graphics/d3d11/GraphicsSampler.cpp b/engine/graphics/d3d11/GraphicsSampler.cpp new file mode 100644 index 00000000..8616ef49 --- /dev/null +++ b/engine/graphics/d3d11/GraphicsSampler.cpp @@ -0,0 +1,99 @@ +#include "d3d11/GraphicsSampler.hpp" +#include "core/Logger.hpp" + +namespace { + D3D11_FILTER toFilter(const core::GraphicsFilter filter) { + #define FILTER_VALUE(MIN, MAG, MIP) core::GraphicsFilter::min_##MIN##_mag_##MAG##_mip_##MIP + switch (filter) { + case FILTER_VALUE(point , point , point ): return D3D11_FILTER_MIN_MAG_MIP_POINT; break; + case FILTER_VALUE(linear, point , point ): return D3D11_FILTER_MIN_LINEAR_MAG_MIP_POINT; break; + case FILTER_VALUE(point , linear, point ): return D3D11_FILTER_MIN_POINT_MAG_LINEAR_MIP_POINT; break; + case FILTER_VALUE(point , point , linear): return D3D11_FILTER_MIN_MAG_POINT_MIP_LINEAR; break; + case FILTER_VALUE(linear, linear, point ): return D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; break; + case FILTER_VALUE(linear, point , linear): return D3D11_FILTER_MIN_LINEAR_MAG_POINT_MIP_LINEAR; break; + case FILTER_VALUE(point , linear, linear): return D3D11_FILTER_MIN_POINT_MAG_MIP_LINEAR; break; + case FILTER_VALUE(linear, linear, linear): return D3D11_FILTER_MIN_MAG_MIP_LINEAR; break; + case core::GraphicsFilter::anisotropic: return D3D11_FILTER_ANISOTROPIC; break; + default: assert(false); return D3D11_FILTER_MIN_MAG_MIP_LINEAR; + } + #undef FILTER_VALUE + } + D3D11_TEXTURE_ADDRESS_MODE toTextureAddressMode(const core::GraphicsTextureAddressMode mode) { + switch (mode) { + case core::GraphicsTextureAddressMode::wrap: return D3D11_TEXTURE_ADDRESS_WRAP; + case core::GraphicsTextureAddressMode::clamp: return D3D11_TEXTURE_ADDRESS_CLAMP; + default: assert(false); return D3D11_TEXTURE_ADDRESS_CLAMP; + } + } +} + +namespace core { + // IGraphicsDeviceEventListener + + void GraphicsSampler::onGraphicsDeviceCreate() { + if (m_initialized) { + createResource(); + } + } + void GraphicsSampler::onGraphicsDeviceDestroy() { + m_sampler.reset(); + } + + // GraphicsSampler + + GraphicsSampler::GraphicsSampler() = default; + GraphicsSampler::~GraphicsSampler() { + if (m_initialized && m_device) { + m_device->removeEventListener(this); + } + } + + bool GraphicsSampler::initialize(IGraphicsDevice* const device, const GraphicsSamplerInfo& info) { + assert(device); + m_device = device; + m_info = info; + if (!createResource()) { + return false; + } + m_initialized = true; + m_device->addEventListener(this); + return true; + } + bool GraphicsSampler::createResource() { + const auto device = static_cast(m_device->getNativeHandle()); + if (device == nullptr) { + assert(false); return false; + } + D3D11_SAMPLER_DESC desc{}; + desc.Filter = toFilter(m_info.filter); + desc.AddressU = toTextureAddressMode(m_info.address_u); + desc.AddressV = toTextureAddressMode(m_info.address_v); + desc.AddressW = toTextureAddressMode(m_info.address_w); + desc.MipLODBias = m_info.mip_lod_bias; + desc.MaxAnisotropy = m_info.max_anisotropy; + desc.ComparisonFunc = D3D11_COMPARISON_NEVER; + desc.MinLOD = m_info.min_lod; + desc.MaxLOD = m_info.max_lod; + return win32::check_hresult_as_boolean( + device->CreateSamplerState(&desc, m_sampler.put()), + "ID3D11Device::CreateSamplerState" + ); + } +} + +#include "d3d11/GraphicsDevice.hpp" + +namespace core { + bool GraphicsDevice::createSampler(const GraphicsSamplerInfo& info, IGraphicsSampler** const out_sampler) { + if (out_sampler == nullptr) { + assert(false); return false; + } + SmartReference buffer; + buffer.attach(new GraphicsSampler()); + if (!buffer->initialize(this, info)) { + return false; + } + *out_sampler = buffer.detach(); + return true; + } +} diff --git a/engine/graphics/d3d11/GraphicsSampler.hpp b/engine/graphics/d3d11/GraphicsSampler.hpp new file mode 100644 index 00000000..3a2b3520 --- /dev/null +++ b/engine/graphics/d3d11/GraphicsSampler.hpp @@ -0,0 +1,42 @@ +#pragma once +#include "core/GraphicsDevice.hpp" +#include "core/SmartReference.hpp" +#include "core/implement/ReferenceCounted.hpp" +#include "d3d11/pch.h" + +namespace core { + class GraphicsSampler final : + public implement::ReferenceCounted, + public IGraphicsDeviceEventListener { + public: + // IGraphicsSampler + + void* getNativeHandle() const noexcept override { return m_sampler.get(); } + + const GraphicsSamplerInfo* getInfo() const noexcept override { return &m_info; } + + // IGraphicsDeviceEventListener + + void onGraphicsDeviceCreate() override; + void onGraphicsDeviceDestroy() override; + + // GraphicsSampler + + GraphicsSampler(); + GraphicsSampler(GraphicsSampler const&) = delete; + GraphicsSampler(GraphicsSampler&&) = delete; + ~GraphicsSampler(); + + GraphicsSampler& operator=(GraphicsSampler const&) = delete; + GraphicsSampler& operator=(GraphicsSampler&&) = delete; + + bool initialize(IGraphicsDevice* device, const GraphicsSamplerInfo& info); + bool createResource(); + + private: + SmartReference m_device; + win32::com_ptr m_sampler; + GraphicsSamplerInfo m_info{}; + bool m_initialized{ false }; + }; +} diff --git a/engine/graphics/d3d11/RenderTarget.cpp b/engine/graphics/d3d11/RenderTarget.cpp new file mode 100644 index 00000000..03524c61 --- /dev/null +++ b/engine/graphics/d3d11/RenderTarget.cpp @@ -0,0 +1 @@ +#include "d3d11/RenderTarget.hpp" \ No newline at end of file diff --git a/engine/graphics/d3d11/RenderTarget.hpp b/engine/graphics/d3d11/RenderTarget.hpp new file mode 100644 index 00000000..330a26e9 --- /dev/null +++ b/engine/graphics/d3d11/RenderTarget.hpp @@ -0,0 +1,4 @@ +#pragma once +#include "core/RenderTarget.hpp" + + diff --git a/engine/graphics/d3d11/Texture2D.cpp b/engine/graphics/d3d11/Texture2D.cpp new file mode 100644 index 00000000..f6b49bce --- /dev/null +++ b/engine/graphics/d3d11/Texture2D.cpp @@ -0,0 +1,3 @@ +#include "d3d11/Texture2D.hpp" + + diff --git a/engine/graphics/d3d11/Texture2D.hpp b/engine/graphics/d3d11/Texture2D.hpp new file mode 100644 index 00000000..54890a13 --- /dev/null +++ b/engine/graphics/d3d11/Texture2D.hpp @@ -0,0 +1,2 @@ +#pragma once +#include "core/Texture2D.hpp" diff --git a/engine/graphics/d3d11/ToStringHelper.hpp b/engine/graphics/d3d11/ToStringHelper.hpp new file mode 100644 index 00000000..b1557b30 --- /dev/null +++ b/engine/graphics/d3d11/ToStringHelper.hpp @@ -0,0 +1,180 @@ +#pragma once +#include "d3d11/pch.h" + +namespace { + using std::string_view_literals::operator ""sv; + + enum class Semantic { + boolean, + integer, + support, + yes_no, + data_size, + }; + + std::string_view toStringView(const bool v, Semantic semantic = Semantic::boolean) { + switch (semantic) { + default: + case Semantic::boolean: return v ? "true"sv : "false"sv; + case Semantic::support: return v ? "supported"sv : "not supported"sv; + case Semantic::yes_no: return v ? "yes"sv : "no"sv; + } + } + + std::string toString(const uint64_t v, Semantic semantic = Semantic::integer) { + switch (semantic) { + default: + case Semantic::integer: return std::to_string(v); + case Semantic::data_size: + { + constexpr uint64_t KiB{ 1024ull }; + constexpr uint64_t MiB{ 1024ull * 1024ull }; + constexpr uint64_t GiB{ 1024ull * 1024ull * 1024ull }; + constexpr uint64_t TiB{ 1024ull * 1024ull * 1024ull * 1024ull }; + if (v < KiB) { + return std::format("{}B"sv, v); + } + else if (v < MiB) { + return std::format("{:.3f}KiB"sv, static_cast(v) / static_cast(KiB)); + } + else if (v < GiB) { + return std::format("{:.3f}MiB"sv, static_cast(v) / static_cast(MiB)); + } + else if (v < TiB) { + return std::format("{:.3f}GiB"sv, static_cast(v) / static_cast(GiB)); + } + else { + return std::format("{:.3f}TiB"sv, static_cast(v) / static_cast(TiB)); + } + } + } + } + + std::string_view toStringView(const D3D_FEATURE_LEVEL v) { + switch (v) { + case D3D_FEATURE_LEVEL_1_0_GENERIC: return "1.0 (generic)"sv; + case D3D_FEATURE_LEVEL_1_0_CORE: return "1.0 (core)"sv; + case D3D_FEATURE_LEVEL_9_1: return "9.1"sv; + case D3D_FEATURE_LEVEL_9_2: return "9.2"sv; + case D3D_FEATURE_LEVEL_9_3: return "9.3"sv; + case D3D_FEATURE_LEVEL_10_0: return "10.0"sv; + case D3D_FEATURE_LEVEL_10_1: return "10.1"sv; + case D3D_FEATURE_LEVEL_11_0: return "11.0"sv; + case D3D_FEATURE_LEVEL_11_1: return "11.1"sv; + case D3D_FEATURE_LEVEL_12_0: return "12.0"sv; + case D3D_FEATURE_LEVEL_12_1: return "12.1"sv; + case D3D_FEATURE_LEVEL_12_2: return "12.2"sv; + default: return "unknown"sv; + } + } + + std::string_view toStringView(const D3D_DRIVER_TYPE v) { + switch (v) { + default: + case D3D_DRIVER_TYPE_UNKNOWN: return "unknown"sv; + case D3D_DRIVER_TYPE_HARDWARE: return "hardware"sv; + case D3D_DRIVER_TYPE_REFERENCE: return "reference"sv; + case D3D_DRIVER_TYPE_NULL: return "null"sv; + case D3D_DRIVER_TYPE_SOFTWARE: return "software"sv; + case D3D_DRIVER_TYPE_WARP: return "Windows Advanced Rasterization Platform (WARP)"sv; + } + } + + std::string_view toStringView(const DXGI_GRAPHICS_PREEMPTION_GRANULARITY v) { + switch (v) { + case DXGI_GRAPHICS_PREEMPTION_DMA_BUFFER_BOUNDARY: return "DMA_BUFFER_BOUNDARY"sv; + case DXGI_GRAPHICS_PREEMPTION_PRIMITIVE_BOUNDARY: return "PRIMITIVE_BOUNDARY"sv; + case DXGI_GRAPHICS_PREEMPTION_TRIANGLE_BOUNDARY: return "TRIANGLE_BOUNDARY"sv; + case DXGI_GRAPHICS_PREEMPTION_PIXEL_BOUNDARY: return "PIXEL_BOUNDARY"sv; + case DXGI_GRAPHICS_PREEMPTION_INSTRUCTION_BOUNDARY: return "INSTRUCTION_BOUNDARY"sv; + default: return "unknown"sv; + } + } + + std::string_view toStringView(const DXGI_COMPUTE_PREEMPTION_GRANULARITY v) { + switch (v) { + case DXGI_COMPUTE_PREEMPTION_DMA_BUFFER_BOUNDARY: return "DMA_BUFFER_BOUNDARY"sv; + case DXGI_COMPUTE_PREEMPTION_DISPATCH_BOUNDARY: return "DISPATCH_BOUNDARY"sv; + case DXGI_COMPUTE_PREEMPTION_THREAD_GROUP_BOUNDARY: return "THREAD_GROUP_BOUNDARY"sv; + case DXGI_COMPUTE_PREEMPTION_THREAD_BOUNDARY: return "THREAD_BOUNDARY"sv; + case DXGI_COMPUTE_PREEMPTION_INSTRUCTION_BOUNDARY: return "INSTRUCTION_BOUNDARY"sv; + default: return "unknown"sv; + } + } + + std::string toString(const DXGI_ADAPTER_FLAG3 v) { + std::string s; + if (v & DXGI_ADAPTER_FLAG3_REMOTE) s.append("REMOTE "sv); + if (v & DXGI_ADAPTER_FLAG3_SOFTWARE) s.append("SOFTWARE "sv); + if (v & DXGI_ADAPTER_FLAG3_ACG_COMPATIBLE) s.append("ACG_COMPATIBLE "sv); + if (v & DXGI_ADAPTER_FLAG3_SUPPORT_MONITORED_FENCES) s.append("SUPPORT_MONITORED_FENCES "sv); + if (v & DXGI_ADAPTER_FLAG3_SUPPORT_NON_MONITORED_FENCES) s.append("SUPPORT_NON_MONITORED_FENCES "sv); + if (v & DXGI_ADAPTER_FLAG3_KEYED_MUTEX_CONFORMANCE) s.append("KEYED_MUTEX_CONFORMANCE "sv); + if (!s.empty()) if (s.back() == ' ') s.pop_back(); + return s; + } + + std::string_view toStringView(const D3D11_SHADER_MIN_PRECISION_SUPPORT flags) { + if ((flags & D3D11_SHADER_MIN_PRECISION_10_BIT) && (flags & D3D11_SHADER_MIN_PRECISION_16_BIT)) { + return "10bit 16bit"sv; + } + if (flags & D3D11_SHADER_MIN_PRECISION_10_BIT) { + return "10bit"sv; + } + if (flags & D3D11_SHADER_MIN_PRECISION_16_BIT) { + return "16bit"sv; + } + return "N/A"sv; + } + + std::string_view toStringView(const D3D11_TILED_RESOURCES_TIER v) { + switch (v) { + case D3D11_TILED_RESOURCES_NOT_SUPPORTED: return "not supported"sv; + case D3D11_TILED_RESOURCES_TIER_1: return "1"sv; + case D3D11_TILED_RESOURCES_TIER_2: return "2"sv; + case D3D11_TILED_RESOURCES_TIER_3: return "3"sv; + default: return "unknown"sv; + } + } + + std::string_view toStringView(const D3D11_CONSERVATIVE_RASTERIZATION_TIER v) { + switch (v) { + case D3D11_CONSERVATIVE_RASTERIZATION_NOT_SUPPORTED: return "not supported"sv; + case D3D11_CONSERVATIVE_RASTERIZATION_TIER_1: return "1"sv; + case D3D11_CONSERVATIVE_RASTERIZATION_TIER_2: return "2"sv; + case D3D11_CONSERVATIVE_RASTERIZATION_TIER_3: return "3"sv; + default: return "unknown"sv; + } + } + + std::string_view toStringView(const D3D11_SHADER_CACHE_SUPPORT_FLAGS flags) { + if ((flags & D3D11_SHADER_CACHE_SUPPORT_AUTOMATIC_INPROC_CACHE) && (flags & D3D11_SHADER_CACHE_SUPPORT_AUTOMATIC_DISK_CACHE)) { + return "AUTOMATIC_INPROC_CACHE AUTOMATIC_DISK_CACHE"sv; + } + if (flags & D3D11_SHADER_CACHE_SUPPORT_AUTOMATIC_INPROC_CACHE) { + return "AUTOMATIC_INPROC_CACHE"sv; + } + if (flags & D3D11_SHADER_CACHE_SUPPORT_AUTOMATIC_DISK_CACHE) { + return "AUTOMATIC_DISK_CACHE"sv; + } + return "NONE"sv; + } + + std::string_view toStringView(const D3D11_SHARED_RESOURCE_TIER v) { + switch (v) { + case D3D11_SHARED_RESOURCE_TIER_0: return "0"sv; + case D3D11_SHARED_RESOURCE_TIER_1: return "1"sv; + case D3D11_SHARED_RESOURCE_TIER_2: return "2"sv; + case D3D11_SHARED_RESOURCE_TIER_3: return "3"sv; + default: return "unknown"sv; + } + } + + std::string_view toStringView(const D3D11_SHADER_ACCESS_RESTRICTED_RESOURCE_TIER v) { + switch (v) { + case D3D11_SHADER_ACCESS_RESTRICTED_RESOURCE_TIER_0: return "0"sv; + case D3D11_SHADER_ACCESS_RESTRICTED_RESOURCE_TIER_1: return "1"sv; + default: return "unknown"sv; + } + } +} diff --git a/engine/graphics/d3d11/pch.cpp b/engine/graphics/d3d11/pch.cpp new file mode 100644 index 00000000..fe237128 --- /dev/null +++ b/engine/graphics/d3d11/pch.cpp @@ -0,0 +1 @@ +#include "d3d11/pch.h" diff --git a/engine/graphics/d3d11/pch.h b/engine/graphics/d3d11/pch.h new file mode 100644 index 00000000..5a2b8a32 --- /dev/null +++ b/engine/graphics/d3d11/pch.h @@ -0,0 +1,70 @@ +#pragma once + +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif +#ifdef NTDDI_VERSION +#undef NTDDI_VERSION +#endif +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tracy/Tracy.hpp" +#include "tracy/TracyD3D11.hpp" +#include "tracy/TracyAPI.hpp" + +#include "windows/HResultChecker.hpp" + +#ifdef NDEBUG +#define M_D3D_SET_DEBUG_NAME(OBJ, STR) +#define M_D3D_SET_DEBUG_NAME_SIMPLE(OBJ) +#else +inline void F_D3D_SET_DEBUG_NAME(IDXGIObject* ptr, std::string_view file, int line, std::string_view name) { + if (ptr) { + const auto str = std::format("{}:{}: IDXGIObject: {}", file, line, name); + ptr->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast(str.length()), str.c_str()); + } +} +inline void F_D3D_SET_DEBUG_NAME(ID3D11Device* ptr, std::string_view file, int line, std::string_view name) { + if (ptr) { + const auto str = std::format("{}:{}: ID3D11Device: {}", file, line, name); + ptr->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast(str.length()), str.c_str()); + } +} +inline void F_D3D_SET_DEBUG_NAME(ID3D11DeviceChild* ptr, std::string_view file, int line, std::string_view name) { + if (ptr) { + const auto str = std::format("{}:{}: ID3D11DeviceChild: {}", file, line, name); + ptr->SetPrivateData(WKPDID_D3DDebugObjectName, static_cast(str.length()), str.c_str()); + } +} +#define M_D3D_SET_DEBUG_NAME(OBJ, STR) F_D3D_SET_DEBUG_NAME(OBJ, __FILE__, __LINE__, STR) +#define M_D3D_SET_DEBUG_NAME_SIMPLE(OBJ) M_D3D_SET_DEBUG_NAME(OBJ, #OBJ) +#endif diff --git a/LuaSTG/Shader/luastg/sub/renderer/gltf_2_0_shader.hlsl b/engine/graphics/d3d11/shader/model/gltf_2_0_shader.hlsl similarity index 100% rename from LuaSTG/Shader/luastg/sub/renderer/gltf_2_0_shader.hlsl rename to engine/graphics/d3d11/shader/model/gltf_2_0_shader.hlsl diff --git a/LuaSTG/Shader/luastg/sub/renderer/screen_door.glsl b/engine/graphics/d3d11/shader/model/screen_door.glsl similarity index 100% rename from LuaSTG/Shader/luastg/sub/renderer/screen_door.glsl rename to engine/graphics/d3d11/shader/model/screen_door.glsl diff --git a/engine/graphics/d3d11/shader/renderer/compile.bat b/engine/graphics/d3d11/shader/renderer/compile.bat new file mode 100644 index 00000000..1ec8139e --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/compile.bat @@ -0,0 +1,50 @@ +fxc /nologo /T vs_4_0 /E main /O3 /Ges /Fh vertex_shader_normal.h /Vn vertex_shader_normal vertex_shader.hlsl +fxc /nologo /T vs_4_0 /E main /O3 /Ges /D FOG_ENABLE /Fh vertex_shader_fog.h /Vn vertex_shader_fog vertex_shader.hlsl + +:: vertex color: add + +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ADD /Fh pixel_shader_add_none_straight.h /Vn pixel_shader_add_none_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ADD /D FOG_ENABLE /D FOG_LINEAR /Fh pixel_shader_add_linear_straight.h /Vn pixel_shader_add_linear_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ADD /D FOG_ENABLE /D FOG_EXP /Fh pixel_shader_add_exp_straight.h /Vn pixel_shader_add_exp_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ADD /D FOG_ENABLE /D FOG_EXP2 /Fh pixel_shader_add_exp2_straight.h /Vn pixel_shader_add_exp2_straight pixel_shader.hlsl + +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ADD /D PREMUL_ALPHA /Fh pixel_shader_add_none_premul.h /Vn pixel_shader_add_none_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ADD /D FOG_ENABLE /D FOG_LINEAR /D PREMUL_ALPHA /Fh pixel_shader_add_linear_premul.h /Vn pixel_shader_add_linear_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ADD /D FOG_ENABLE /D FOG_EXP /D PREMUL_ALPHA /Fh pixel_shader_add_exp_premul.h /Vn pixel_shader_add_exp_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ADD /D FOG_ENABLE /D FOG_EXP2 /D PREMUL_ALPHA /Fh pixel_shader_add_exp2_premul.h /Vn pixel_shader_add_exp2_premul pixel_shader.hlsl + +:: vertex color: mul + +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_MUL /Fh pixel_shader_mul_none_straight.h /Vn pixel_shader_mul_none_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_MUL /D FOG_ENABLE /D FOG_LINEAR /Fh pixel_shader_mul_linear_straight.h /Vn pixel_shader_mul_linear_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_MUL /D FOG_ENABLE /D FOG_EXP /Fh pixel_shader_mul_exp_straight.h /Vn pixel_shader_mul_exp_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_MUL /D FOG_ENABLE /D FOG_EXP2 /Fh pixel_shader_mul_exp2_straight.h /Vn pixel_shader_mul_exp2_straight pixel_shader.hlsl + +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_MUL /D PREMUL_ALPHA /Fh pixel_shader_mul_none_premul.h /Vn pixel_shader_mul_none_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_MUL /D FOG_ENABLE /D FOG_LINEAR /D PREMUL_ALPHA /Fh pixel_shader_mul_linear_premul.h /Vn pixel_shader_mul_linear_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_MUL /D FOG_ENABLE /D FOG_EXP /D PREMUL_ALPHA /Fh pixel_shader_mul_exp_premul.h /Vn pixel_shader_mul_exp_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_MUL /D FOG_ENABLE /D FOG_EXP2 /D PREMUL_ALPHA /Fh pixel_shader_mul_exp2_premul.h /Vn pixel_shader_mul_exp2_premul pixel_shader.hlsl + +:: vertex color: one + +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ONE /Fh pixel_shader_one_none_straight.h /Vn pixel_shader_one_none_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ONE /D FOG_ENABLE /D FOG_LINEAR /Fh pixel_shader_one_linear_straight.h /Vn pixel_shader_one_linear_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ONE /D FOG_ENABLE /D FOG_EXP /Fh pixel_shader_one_exp_straight.h /Vn pixel_shader_one_exp_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ONE /D FOG_ENABLE /D FOG_EXP2 /Fh pixel_shader_one_exp2_straight.h /Vn pixel_shader_one_exp2_straight pixel_shader.hlsl + +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ONE /D PREMUL_ALPHA /Fh pixel_shader_one_none_premul.h /Vn pixel_shader_one_none_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ONE /D FOG_ENABLE /D FOG_LINEAR /D PREMUL_ALPHA /Fh pixel_shader_one_linear_premul.h /Vn pixel_shader_one_linear_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ONE /D FOG_ENABLE /D FOG_EXP /D PREMUL_ALPHA /Fh pixel_shader_one_exp_premul.h /Vn pixel_shader_one_exp_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ONE /D FOG_ENABLE /D FOG_EXP2 /D PREMUL_ALPHA /Fh pixel_shader_one_exp2_premul.h /Vn pixel_shader_one_exp2_premul pixel_shader.hlsl + +:: vertex color: zero + +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ZERO /Fh pixel_shader_zero_none_straight.h /Vn pixel_shader_zero_none_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ZERO /D FOG_ENABLE /D FOG_LINEAR /Fh pixel_shader_zero_linear_straight.h /Vn pixel_shader_zero_linear_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ZERO /D FOG_ENABLE /D FOG_EXP /Fh pixel_shader_zero_exp_straight.h /Vn pixel_shader_zero_exp_straight pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ZERO /D FOG_ENABLE /D FOG_EXP2 /Fh pixel_shader_zero_exp2_straight.h /Vn pixel_shader_zero_exp2_straight pixel_shader.hlsl + +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ZERO /D PREMUL_ALPHA /Fh pixel_shader_zero_none_premul.h /Vn pixel_shader_zero_none_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ZERO /D FOG_ENABLE /D FOG_LINEAR /D PREMUL_ALPHA /Fh pixel_shader_zero_linear_premul.h /Vn pixel_shader_zero_linear_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ZERO /D FOG_ENABLE /D FOG_EXP /D PREMUL_ALPHA /Fh pixel_shader_zero_exp_premul.h /Vn pixel_shader_zero_exp_premul pixel_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /D VERTEX_COLOR_BLEND_ZERO /D FOG_ENABLE /D FOG_EXP2 /D PREMUL_ALPHA /Fh pixel_shader_zero_exp2_premul.h /Vn pixel_shader_zero_exp2_premul pixel_shader.hlsl diff --git a/LuaSTG/Shader/luastg/sub/renderer/pixel_shader.hlsl b/engine/graphics/d3d11/shader/renderer/pixel_shader.hlsl similarity index 99% rename from LuaSTG/Shader/luastg/sub/renderer/pixel_shader.hlsl rename to engine/graphics/d3d11/shader/renderer/pixel_shader.hlsl index 746dd88b..a62b6161 100644 --- a/LuaSTG/Shader/luastg/sub/renderer/pixel_shader.hlsl +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader.hlsl @@ -1,10 +1,9 @@ - - #if defined(FOG_ENABLE) cbuffer camera_data : register(b0) { float4 camera_pos; }; + cbuffer fog_data : register(b1) { float4 fog_color; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp2_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp2_premul.h new file mode 100644 index 00000000..fa460c5f --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp2_premul.h @@ -0,0 +1,375 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +sample r0.xyzw, v2.xyxx, t0.xyzw, s0 +lt r1.x, r0.w, l(0.003922) +discard_nz r1.x +div r0.xyz, r0.xyzx, r0.wwww +add r0.xyz, r0.xyzx, v3.xyzx +min r0.xyz, r0.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000) +mul r0.w, r0.w, v3.w +mul r0.xyz, r0.wwww, r0.xyzx +add r1.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r1.x, r1.xyzx, r1.xyzx +sqrt r1.x, r1.x +mul r1.x, r1.x, cb1[1].x +mul r1.x, r1.x, r1.x +mul r1.x, r1.x, l(-1.442695) +exp r1.x, r1.x +add r1.x, -r1.x, l(1.000000) +add r1.y, -r1.x, l(1.000000) +mul r1.z, r0.w, r1.x +mul r1.z, r1.z, cb1[0].w +mad r0.w, r1.y, r0.w, r1.z +mad r1.z, r1.x, cb1[0].w, r1.y +mul r1.y, r1.z, r1.y +mul r1.x, r0.w, r1.x +mul r1.xzw, r1.xxxx, cb1[0].xxyz +mad o0.xyz, r1.yyyy, r0.xyzx, r1.xzwx +mov o0.w, r0.w +ret +// Approximately 27 instruction slots used +#endif + +const BYTE pixel_shader_add_exp2_premul[] = +{ + 68, 88, 66, 67, 175, 136, + 14, 24, 85, 99, 223, 170, + 11, 164, 87, 102, 222, 247, + 223, 144, 1, 0, 0, 0, + 152, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 28, 6, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 124, 3, 0, 0, + 64, 0, 0, 0, 223, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 49, 0, + 0, 7, 18, 0, 16, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 129, 128, + 128, 59, 13, 0, 4, 3, + 10, 0, 16, 0, 1, 0, + 0, 0, 14, 0, 0, 7, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 7, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 3, 0, 0, 0, 51, 0, + 0, 10, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 128, 63, 0, 0, 128, 63, + 0, 0, 128, 63, 0, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 16, + 16, 0, 3, 0, 0, 0, + 56, 0, 0, 7, 114, 0, + 16, 0, 0, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 59, 170, + 184, 191, 25, 0, 0, 5, + 18, 0, 16, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 0, 0, + 0, 8, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 0, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 0, 0, 0, 8, 34, 0, + 16, 0, 1, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 56, 0, 0, 7, + 66, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 8, 66, 0, + 16, 0, 1, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 58, 128, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 130, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 10, + 66, 0, 16, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 210, 0, 16, 0, 1, 0, + 0, 0, 6, 0, 16, 0, + 1, 0, 0, 0, 6, 137, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 86, 5, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 134, 3, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 27, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 23, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp2_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp2_straight.h new file mode 100644 index 00000000..17f4d70f --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp2_straight.h @@ -0,0 +1,360 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, r0.x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r0.w, r1.w, v3.w +add r1.xyz, r1.xyzx, v3.xyzx +min r1.xyz, r1.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000) +mul r1.xyz, r0.wwww, r1.xyzx +mul r1.w, r0.w, r0.x +mul r1.w, r1.w, cb1[0].w +mad r0.y, r0.y, r0.w, r1.w +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 24 instruction slots used +#endif + +const BYTE pixel_shader_add_exp2_straight[] = +{ + 68, 88, 66, 67, 198, 28, + 207, 137, 139, 177, 129, 154, + 100, 168, 125, 57, 84, 14, + 240, 14, 1, 0, 0, 0, + 84, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 216, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 56, 3, 0, 0, + 64, 0, 0, 0, 206, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 59, 170, + 184, 191, 25, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 128, 65, 0, 0, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 58, 16, 16, 0, 3, 0, + 0, 0, 0, 0, 0, 7, + 114, 0, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 0, 3, 0, 0, 0, + 51, 0, 0, 10, 114, 0, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 128, 63, 0, 0, + 128, 63, 0, 0, 128, 63, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 0, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 8, 130, 0, + 16, 0, 1, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 58, 128, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 34, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 8, + 178, 0, 16, 0, 0, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 136, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 166, 10, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 3, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 24, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 21, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp_premul.h new file mode 100644 index 00000000..1034e80a --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp_premul.h @@ -0,0 +1,375 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +sample r0.xyzw, v2.xyxx, t0.xyzw, s0 +lt r1.x, r0.w, l(0.003922) +discard_nz r1.x +div r0.xyz, r0.xyzx, r0.wwww +add r0.xyz, r0.xyzx, v3.xyzx +min r0.xyz, r0.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000) +mul r0.w, r0.w, v3.w +mul r0.xyz, r0.wwww, r0.xyzx +add r1.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r1.x, r1.xyzx, r1.xyzx +sqrt r1.x, r1.x +mul r1.x, r1.x, cb1[1].x +mul r1.x, r1.x, l(-1.442695) +exp r1.x, r1.x +add r1.x, -r1.x, l(1.000000) +max r1.x, r1.x, l(0.000000) +add r1.y, -r1.x, l(1.000000) +mul r1.z, r0.w, r1.x +mul r1.z, r1.z, cb1[0].w +mad r0.w, r1.y, r0.w, r1.z +mad r1.z, r1.x, cb1[0].w, r1.y +mul r1.y, r1.z, r1.y +mul r1.x, r0.w, r1.x +mul r1.xzw, r1.xxxx, cb1[0].xxyz +mad o0.xyz, r1.yyyy, r0.xyzx, r1.xzwx +mov o0.w, r0.w +ret +// Approximately 27 instruction slots used +#endif + +const BYTE pixel_shader_add_exp_premul[] = +{ + 68, 88, 66, 67, 39, 69, + 76, 166, 135, 219, 25, 64, + 71, 241, 91, 198, 183, 37, + 117, 222, 1, 0, 0, 0, + 152, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 28, 6, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 124, 3, 0, 0, + 64, 0, 0, 0, 223, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 49, 0, + 0, 7, 18, 0, 16, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 129, 128, + 128, 59, 13, 0, 4, 3, + 10, 0, 16, 0, 1, 0, + 0, 0, 14, 0, 0, 7, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 7, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 3, 0, 0, 0, 51, 0, + 0, 10, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 128, 63, 0, 0, 128, 63, + 0, 0, 128, 63, 0, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 16, + 16, 0, 3, 0, 0, 0, + 56, 0, 0, 7, 114, 0, + 16, 0, 0, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 1, 64, 0, 0, + 59, 170, 184, 191, 25, 0, + 0, 5, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 0, 0, 0, 8, 18, 0, + 16, 0, 1, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 52, 0, 0, 7, + 18, 0, 16, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 1, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 56, 0, 0, 7, + 66, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 8, 66, 0, + 16, 0, 1, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 58, 128, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 130, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 10, + 66, 0, 16, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 210, 0, 16, 0, 1, 0, + 0, 0, 6, 0, 16, 0, + 1, 0, 0, 0, 6, 137, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 86, 5, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 134, 3, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 27, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 23, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp_straight.h new file mode 100644 index 00000000..aa805c43 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_exp_straight.h @@ -0,0 +1,360 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +max r0.x, r0.x, l(0.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r0.w, r1.w, v3.w +add r1.xyz, r1.xyzx, v3.xyzx +min r1.xyz, r1.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000) +mul r1.xyz, r0.wwww, r1.xyzx +mul r1.w, r0.w, r0.x +mul r1.w, r1.w, cb1[0].w +mad r0.y, r0.y, r0.w, r1.w +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 24 instruction slots used +#endif + +const BYTE pixel_shader_add_exp_straight[] = +{ + 68, 88, 66, 67, 125, 86, + 36, 42, 134, 79, 81, 173, + 102, 84, 62, 106, 47, 51, + 68, 206, 1, 0, 0, 0, + 84, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 216, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 56, 3, 0, 0, + 64, 0, 0, 0, 206, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 59, 170, 184, 191, 25, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 52, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 58, 16, 16, 0, 3, 0, + 0, 0, 0, 0, 0, 7, + 114, 0, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 0, 3, 0, 0, 0, + 51, 0, 0, 10, 114, 0, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 128, 63, 0, 0, + 128, 63, 0, 0, 128, 63, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 0, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 8, 130, 0, + 16, 0, 1, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 58, 128, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 34, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 8, + 178, 0, 16, 0, 0, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 136, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 166, 10, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 3, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 24, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 21, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_add_linear_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_linear_premul.h new file mode 100644 index 00000000..7b21a215 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_linear_premul.h @@ -0,0 +1,360 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +sample r0.xyzw, v2.xyxx, t0.xyzw, s0 +lt r1.x, r0.w, l(0.003922) +discard_nz r1.x +div r0.xyz, r0.xyzx, r0.wwww +add r0.xyz, r0.xyzx, v3.xyzx +min r0.xyz, r0.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000) +mul r0.w, r0.w, v3.w +mul r0.xyz, r0.wwww, r0.xyzx +add r1.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r1.x, r1.xyzx, r1.xyzx +sqrt r1.x, r1.x +add r1.x, r1.x, -cb1[1].x +div_sat r1.x, r1.x, cb1[1].w +add r1.y, -r1.x, l(1.000000) +mul r1.z, r0.w, r1.x +mul r1.z, r1.z, cb1[0].w +mad r0.w, r1.y, r0.w, r1.z +mad r1.z, r1.x, cb1[0].w, r1.y +mul r1.y, r1.z, r1.y +mul r1.x, r0.w, r1.x +mul r1.xzw, r1.xxxx, cb1[0].xxyz +mad o0.xyz, r1.yyyy, r0.xyzx, r1.xzwx +mov o0.w, r0.w +ret +// Approximately 24 instruction slots used +#endif + +const BYTE pixel_shader_add_linear_premul[] = +{ + 68, 88, 66, 67, 4, 116, + 84, 72, 142, 152, 243, 154, + 133, 109, 115, 151, 163, 17, + 86, 117, 1, 0, 0, 0, + 80, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 212, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 52, 3, 0, 0, + 64, 0, 0, 0, 205, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 49, 0, + 0, 7, 18, 0, 16, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 129, 128, + 128, 59, 13, 0, 4, 3, + 10, 0, 16, 0, 1, 0, + 0, 0, 14, 0, 0, 7, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 7, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 3, 0, 0, 0, 51, 0, + 0, 10, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 128, 63, 0, 0, 128, 63, + 0, 0, 128, 63, 0, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 16, + 16, 0, 3, 0, 0, 0, + 56, 0, 0, 7, 114, 0, + 16, 0, 0, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 1, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 0, 0, + 0, 9, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 10, 128, 32, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 14, 32, + 0, 8, 18, 0, 16, 0, + 1, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 1, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 56, 0, 0, 7, + 66, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 8, 66, 0, + 16, 0, 1, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 58, 128, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 130, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 50, 0, 0, 10, + 66, 0, 16, 0, 1, 0, + 0, 0, 10, 0, 16, 0, + 1, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 34, 0, + 16, 0, 1, 0, 0, 0, + 42, 0, 16, 0, 1, 0, + 0, 0, 26, 0, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 1, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 210, 0, 16, 0, 1, 0, + 0, 0, 6, 0, 16, 0, + 1, 0, 0, 0, 6, 137, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 86, 5, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 134, 3, 16, 0, + 1, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 24, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 20, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_add_linear_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_linear_straight.h new file mode 100644 index 00000000..ef874b61 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_linear_straight.h @@ -0,0 +1,345 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +add r0.x, r0.x, -cb1[1].x +div_sat r0.x, r0.x, cb1[1].w +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +add r1.xyz, r1.xyzx, v3.xyzx +mul r0.w, r1.w, v3.w +min r1.xyz, r1.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000) +mul r1.xyz, r0.wwww, r1.xyzx +mul r1.w, r0.w, r0.x +mul r1.w, r1.w, cb1[0].w +mad r0.y, r0.y, r0.w, r1.w +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 21 instruction slots used +#endif + +const BYTE pixel_shader_add_linear_straight[] = +{ + 68, 88, 66, 67, 206, 96, + 191, 216, 91, 208, 215, 210, + 36, 45, 136, 98, 160, 223, + 158, 13, 1, 0, 0, 0, + 12, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 144, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 240, 2, 0, 0, + 64, 0, 0, 0, 188, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 14, 32, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 7, 114, 0, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 18, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 58, 16, + 16, 0, 3, 0, 0, 0, + 51, 0, 0, 10, 114, 0, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 128, 63, 0, 0, + 128, 63, 0, 0, 128, 63, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 0, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 8, 130, 0, + 16, 0, 1, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 58, 128, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 34, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 8, + 178, 0, 16, 0, 0, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 136, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 166, 10, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 3, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 21, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 18, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_add_none_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_none_premul.h new file mode 100644 index 00000000..1369251f --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_none_premul.h @@ -0,0 +1,193 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// TEXCOORD 0 xy 1 NONE float xy +// COLOR 0 xyzw 2 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xy +dcl_input_ps linear v2.xyzw +dcl_output o0.xyzw +dcl_temps 2 +sample r0.xyzw, v1.xyxx, t0.xyzw, s0 +lt r1.x, r0.w, l(0.003922) +discard_nz r1.x +div r0.xyz, r0.xyzx, r0.wwww +add r0.xyz, r0.xyzx, v2.xyzx +min r0.xyz, r0.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000) +mul r0.w, r0.w, v2.w +mul o0.xyz, r0.wwww, r0.xyzx +mov o0.w, r0.w +ret +// Approximately 10 instruction slots used +#endif + +const BYTE pixel_shader_add_none_premul[] = +{ + 68, 88, 66, 67, 77, 126, + 17, 192, 188, 176, 49, 170, + 29, 6, 176, 185, 228, 37, + 32, 68, 1, 0, 0, 0, + 76, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 212, 0, 0, 0, 72, 1, + 0, 0, 124, 1, 0, 0, + 208, 2, 0, 0, 82, 68, + 69, 70, 152, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 110, 0, 0, 0, 92, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 115, 97, 109, 112, + 108, 101, 114, 48, 0, 116, + 101, 120, 116, 117, 114, 101, + 48, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 171, 171, 73, 83, 71, 78, + 108, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 92, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 3, 3, 0, 0, + 101, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 84, 69, 88, 67, 79, 79, + 82, 68, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 76, 1, 0, 0, 64, 0, + 0, 0, 83, 0, 0, 0, + 90, 0, 0, 3, 0, 96, + 16, 0, 0, 0, 0, 0, + 88, 24, 0, 4, 0, 112, + 16, 0, 0, 0, 0, 0, + 85, 85, 0, 0, 98, 16, + 0, 3, 50, 16, 16, 0, + 1, 0, 0, 0, 98, 16, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 0, 0, 0, 0, 104, 0, + 0, 2, 2, 0, 0, 0, + 69, 0, 0, 9, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 16, 16, 0, 1, 0, + 0, 0, 70, 126, 16, 0, + 0, 0, 0, 0, 0, 96, + 16, 0, 0, 0, 0, 0, + 49, 0, 0, 7, 18, 0, + 16, 0, 1, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 129, 128, 128, 59, 13, 0, + 4, 3, 10, 0, 16, 0, + 1, 0, 0, 0, 14, 0, + 0, 7, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 0, 0, 0, 7, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 51, 0, 0, 10, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 128, 63, 0, 0, + 128, 63, 0, 0, 128, 63, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 56, 0, 0, 7, + 114, 32, 16, 0, 0, 0, + 0, 0, 246, 15, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 10, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 6, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_add_none_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_none_straight.h new file mode 100644 index 00000000..31a4201b --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_add_none_straight.h @@ -0,0 +1,179 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// TEXCOORD 0 xy 1 NONE float xy +// COLOR 0 xyzw 2 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xy +dcl_input_ps linear v2.xyzw +dcl_output o0.xyzw +dcl_temps 1 +sample r0.xyzw, v1.xyxx, t0.xyzw, s0 +add r0.xyz, r0.xyzx, v2.xyzx +mul r0.w, r0.w, v2.w +min r0.xyz, r0.xyzx, l(1.000000, 1.000000, 1.000000, 0.000000) +mul o0.xyz, r0.wwww, r0.xyzx +mov o0.w, r0.w +ret +// Approximately 7 instruction slots used +#endif + +const BYTE pixel_shader_add_none_straight[] = +{ + 68, 88, 66, 67, 225, 85, + 138, 223, 191, 59, 115, 10, + 231, 182, 203, 253, 137, 65, + 21, 51, 1, 0, 0, 0, + 8, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 212, 0, 0, 0, 72, 1, + 0, 0, 124, 1, 0, 0, + 140, 2, 0, 0, 82, 68, + 69, 70, 152, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 110, 0, 0, 0, 92, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 115, 97, 109, 112, + 108, 101, 114, 48, 0, 116, + 101, 120, 116, 117, 114, 101, + 48, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 171, 171, 73, 83, 71, 78, + 108, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 92, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 3, 3, 0, 0, + 101, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 84, 69, 88, 67, 79, 79, + 82, 68, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 8, 1, 0, 0, 64, 0, + 0, 0, 66, 0, 0, 0, + 90, 0, 0, 3, 0, 96, + 16, 0, 0, 0, 0, 0, + 88, 24, 0, 4, 0, 112, + 16, 0, 0, 0, 0, 0, + 85, 85, 0, 0, 98, 16, + 0, 3, 50, 16, 16, 0, + 1, 0, 0, 0, 98, 16, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 0, 0, 0, 0, 104, 0, + 0, 2, 1, 0, 0, 0, + 69, 0, 0, 9, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 16, 16, 0, 1, 0, + 0, 0, 70, 126, 16, 0, + 0, 0, 0, 0, 0, 96, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 7, 114, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 2, 0, + 0, 0, 51, 0, 0, 10, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 2, 64, + 0, 0, 0, 0, 128, 63, + 0, 0, 128, 63, 0, 0, + 128, 63, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 0, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 7, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp2_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp2_premul.h new file mode 100644 index 00000000..febdc71e --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp2_premul.h @@ -0,0 +1,347 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, r0.x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r1.xyzw, r1.xyzw, v3.xyzw +mul r0.w, r0.x, r1.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, r1.w, r0.w +mul r1.xyz, r1.xyzx, v3.wwww +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 22 instruction slots used +#endif + +const BYTE pixel_shader_mul_exp2_premul[] = +{ + 68, 88, 66, 67, 45, 168, + 6, 16, 28, 251, 8, 229, + 117, 233, 36, 222, 200, 233, + 139, 84, 1, 0, 0, 0, + 16, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 148, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 244, 2, 0, 0, + 64, 0, 0, 0, 189, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 59, 170, + 184, 191, 25, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 128, 65, 0, 0, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 70, 30, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 8, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 58, 128, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 34, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 0, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 8, 178, 0, + 16, 0, 0, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 136, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 114, 32, 16, 0, 0, 0, + 0, 0, 166, 10, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 3, 16, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 22, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 19, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp2_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp2_straight.h new file mode 100644 index 00000000..d9705013 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp2_straight.h @@ -0,0 +1,347 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, r0.x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r1.xyzw, r1.xyzw, v3.xyzw +mul r0.w, r0.x, r1.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, r1.w, r0.w +mul r1.xyz, r1.wwww, r1.xyzx +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 22 instruction slots used +#endif + +const BYTE pixel_shader_mul_exp2_straight[] = +{ + 68, 88, 66, 67, 17, 236, + 174, 82, 171, 1, 169, 218, + 130, 179, 146, 96, 99, 232, + 230, 128, 1, 0, 0, 0, + 16, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 148, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 244, 2, 0, 0, + 64, 0, 0, 0, 189, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 59, 170, + 184, 191, 25, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 128, 65, 0, 0, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 70, 30, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 8, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 58, 128, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 34, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 0, 16, 0, 1, 0, + 0, 0, 246, 15, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 8, 178, 0, + 16, 0, 0, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 136, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 114, 32, 16, 0, 0, 0, + 0, 0, 166, 10, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 3, 16, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 22, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 19, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp_premul.h new file mode 100644 index 00000000..d8aabcb4 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp_premul.h @@ -0,0 +1,347 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +max r0.x, r0.x, l(0.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r1.xyzw, r1.xyzw, v3.xyzw +mul r0.w, r0.x, r1.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, r1.w, r0.w +mul r1.xyz, r1.xyzx, v3.wwww +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 22 instruction slots used +#endif + +const BYTE pixel_shader_mul_exp_premul[] = +{ + 68, 88, 66, 67, 138, 148, + 75, 201, 226, 202, 64, 84, + 238, 90, 113, 43, 227, 165, + 36, 169, 1, 0, 0, 0, + 16, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 148, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 244, 2, 0, 0, + 64, 0, 0, 0, 189, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 59, 170, 184, 191, 25, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 52, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 70, 30, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 8, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 58, 128, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 34, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 0, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 246, 31, + 16, 0, 3, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 8, 178, 0, + 16, 0, 0, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 136, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 114, 32, 16, 0, 0, 0, + 0, 0, 166, 10, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 3, 16, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 22, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 19, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp_straight.h new file mode 100644 index 00000000..6dbfb3bd --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_exp_straight.h @@ -0,0 +1,347 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +max r0.x, r0.x, l(0.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r1.xyzw, r1.xyzw, v3.xyzw +mul r0.w, r0.x, r1.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, r1.w, r0.w +mul r1.xyz, r1.wwww, r1.xyzx +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 22 instruction slots used +#endif + +const BYTE pixel_shader_mul_exp_straight[] = +{ + 68, 88, 66, 67, 193, 253, + 138, 226, 240, 201, 213, 218, + 198, 217, 243, 43, 230, 191, + 240, 40, 1, 0, 0, 0, + 16, 6, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 148, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 244, 2, 0, 0, + 64, 0, 0, 0, 189, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 59, 170, 184, 191, 25, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 52, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 14, + 16, 0, 1, 0, 0, 0, + 70, 30, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 8, 130, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 58, 128, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 34, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 1, 0, 0, 0, + 58, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 114, 0, 16, 0, 1, 0, + 0, 0, 246, 15, 16, 0, + 1, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 8, 178, 0, + 16, 0, 0, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 136, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 114, 32, 16, 0, 0, 0, + 0, 0, 166, 10, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 70, 3, 16, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 22, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 19, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_linear_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_linear_premul.h new file mode 100644 index 00000000..e3360416 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_linear_premul.h @@ -0,0 +1,332 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +add r0.x, r0.x, -cb1[1].x +div_sat r0.x, r0.x, cb1[1].w +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r1.xyzw, r1.xyzw, v3.xyzw +mul r0.y, r0.x, r1.w +mul r0.y, r0.y, cb1[0].w +add r0.z, -r0.x, l(1.000000) +mad r0.y, r0.z, r1.w, r0.y +mul r1.xyz, r1.xyzx, v3.wwww +mul r0.w, r0.y, r0.x +mov o0.w, r0.y +mad r0.x, r0.x, cb1[0].w, r0.z +mul r0.x, r0.x, r0.z +mul r0.yzw, r0.wwww, cb1[0].xxyz +mad o0.xyz, r0.xxxx, r1.xyzx, r0.yzwy +ret +// Approximately 19 instruction slots used +#endif + +const BYTE pixel_shader_mul_linear_premul[] = +{ + 68, 88, 66, 67, 161, 213, + 237, 197, 69, 49, 47, 221, + 157, 192, 37, 212, 113, 74, + 198, 25, 1, 0, 0, 0, + 200, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 76, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 172, 2, 0, 0, + 64, 0, 0, 0, 171, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 14, 32, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 69, 0, 0, 9, 242, 0, + 16, 0, 1, 0, 0, 0, + 70, 16, 16, 0, 2, 0, + 0, 0, 70, 126, 16, 0, + 0, 0, 0, 0, 0, 96, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 242, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 7, 34, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 34, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 66, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 128, 65, 0, 0, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 50, 0, 0, 9, 34, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 0, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 246, 31, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 10, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 42, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 8, 226, 0, + 16, 0, 0, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 6, 137, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 114, 32, 16, 0, 0, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 150, 7, 16, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 19, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_linear_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_linear_straight.h new file mode 100644 index 00000000..7a5a9258 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_linear_straight.h @@ -0,0 +1,332 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +add r0.x, r0.x, -cb1[1].x +div_sat r0.x, r0.x, cb1[1].w +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r1.xyzw, r1.xyzw, v3.xyzw +mul r0.y, r0.x, r1.w +mul r0.y, r0.y, cb1[0].w +add r0.z, -r0.x, l(1.000000) +mad r0.y, r0.z, r1.w, r0.y +mul r1.xyz, r1.wwww, r1.xyzx +mul r0.w, r0.y, r0.x +mov o0.w, r0.y +mad r0.x, r0.x, cb1[0].w, r0.z +mul r0.x, r0.x, r0.z +mul r0.yzw, r0.wwww, cb1[0].xxyz +mad o0.xyz, r0.xxxx, r1.xyzx, r0.yzwy +ret +// Approximately 19 instruction slots used +#endif + +const BYTE pixel_shader_mul_linear_straight[] = +{ + 68, 88, 66, 67, 215, 126, + 136, 159, 180, 143, 29, 139, + 215, 107, 197, 201, 139, 190, + 108, 128, 1, 0, 0, 0, + 200, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 76, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 172, 2, 0, 0, + 64, 0, 0, 0, 171, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 14, 32, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 69, 0, 0, 9, 242, 0, + 16, 0, 1, 0, 0, 0, + 70, 16, 16, 0, 2, 0, + 0, 0, 70, 126, 16, 0, + 0, 0, 0, 0, 0, 96, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 242, 0, + 16, 0, 1, 0, 0, 0, + 70, 14, 16, 0, 1, 0, + 0, 0, 70, 30, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 7, 34, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 34, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 66, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 128, 65, 0, 0, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 50, 0, 0, 9, 34, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 1, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 0, + 16, 0, 1, 0, 0, 0, + 246, 15, 16, 0, 1, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 50, 0, + 0, 10, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 42, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 8, 226, 0, + 16, 0, 0, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 6, 137, 32, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 50, 0, 0, 9, + 114, 32, 16, 0, 0, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 1, 0, 0, 0, + 150, 7, 16, 0, 0, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 19, 0, 0, 0, + 2, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_none_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_none_premul.h new file mode 100644 index 00000000..89f26edc --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_none_premul.h @@ -0,0 +1,165 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// TEXCOORD 0 xy 1 NONE float xy +// COLOR 0 xyzw 2 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xy +dcl_input_ps linear v2.xyzw +dcl_output o0.xyzw +dcl_temps 1 +sample r0.xyzw, v1.xyxx, t0.xyzw, s0 +mul r0.xyzw, r0.xyzw, v2.xyzw +mul o0.xyz, r0.xyzx, v2.wwww +mov o0.w, r0.w +ret +// Approximately 5 instruction slots used +#endif + +const BYTE pixel_shader_mul_none_premul[] = +{ + 68, 88, 66, 67, 47, 249, + 78, 89, 172, 171, 238, 173, + 247, 228, 130, 19, 146, 218, + 113, 138, 1, 0, 0, 0, + 196, 2, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 212, 0, 0, 0, 72, 1, + 0, 0, 124, 1, 0, 0, + 72, 2, 0, 0, 82, 68, + 69, 70, 152, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 110, 0, 0, 0, 92, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 115, 97, 109, 112, + 108, 101, 114, 48, 0, 116, + 101, 120, 116, 117, 114, 101, + 48, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 171, 171, 73, 83, 71, 78, + 108, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 92, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 3, 3, 0, 0, + 101, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 84, 69, 88, 67, 79, 79, + 82, 68, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 196, 0, 0, 0, 64, 0, + 0, 0, 49, 0, 0, 0, + 90, 0, 0, 3, 0, 96, + 16, 0, 0, 0, 0, 0, + 88, 24, 0, 4, 0, 112, + 16, 0, 0, 0, 0, 0, + 85, 85, 0, 0, 98, 16, + 0, 3, 50, 16, 16, 0, + 1, 0, 0, 0, 98, 16, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 0, 0, 0, 0, 104, 0, + 0, 2, 1, 0, 0, 0, + 69, 0, 0, 9, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 16, 16, 0, 1, 0, + 0, 0, 70, 126, 16, 0, + 0, 0, 0, 0, 0, 96, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 30, 16, 0, + 2, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 246, 31, 16, 0, 2, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 5, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_none_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_none_straight.h new file mode 100644 index 00000000..6c17e747 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_mul_none_straight.h @@ -0,0 +1,165 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// TEXCOORD 0 xy 1 NONE float xy +// COLOR 0 xyzw 2 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xy +dcl_input_ps linear v2.xyzw +dcl_output o0.xyzw +dcl_temps 1 +sample r0.xyzw, v1.xyxx, t0.xyzw, s0 +mul r0.xyzw, r0.xyzw, v2.xyzw +mul o0.xyz, r0.wwww, r0.xyzx +mov o0.w, r0.w +ret +// Approximately 5 instruction slots used +#endif + +const BYTE pixel_shader_mul_none_straight[] = +{ + 68, 88, 66, 67, 207, 123, + 147, 64, 186, 183, 243, 191, + 238, 54, 130, 44, 6, 30, + 68, 115, 1, 0, 0, 0, + 196, 2, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 212, 0, 0, 0, 72, 1, + 0, 0, 124, 1, 0, 0, + 72, 2, 0, 0, 82, 68, + 69, 70, 152, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 110, 0, 0, 0, 92, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 115, 97, 109, 112, + 108, 101, 114, 48, 0, 116, + 101, 120, 116, 117, 114, 101, + 48, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 171, 171, 73, 83, 71, 78, + 108, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 92, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 3, 3, 0, 0, + 101, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 84, 69, 88, 67, 79, 79, + 82, 68, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 196, 0, 0, 0, 64, 0, + 0, 0, 49, 0, 0, 0, + 90, 0, 0, 3, 0, 96, + 16, 0, 0, 0, 0, 0, + 88, 24, 0, 4, 0, 112, + 16, 0, 0, 0, 0, 0, + 85, 85, 0, 0, 98, 16, + 0, 3, 50, 16, 16, 0, + 1, 0, 0, 0, 98, 16, + 0, 3, 242, 16, 16, 0, + 2, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 0, 0, 0, 0, 104, 0, + 0, 2, 1, 0, 0, 0, + 69, 0, 0, 9, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 16, 16, 0, 1, 0, + 0, 0, 70, 126, 16, 0, + 0, 0, 0, 0, 0, 96, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 30, 16, 0, + 2, 0, 0, 0, 56, 0, + 0, 7, 114, 32, 16, 0, + 0, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 5, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp2_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp2_premul.h new file mode 100644 index 00000000..d257cd39 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp2_premul.h @@ -0,0 +1,304 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_input_ps linear v1.xyz +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 1 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, r0.x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +mul r0.w, r0.x, v3.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, v3.w, r0.w +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, v3.xyzx, r0.xywx +ret +// Approximately 19 instruction slots used +#endif + +const BYTE pixel_shader_one_exp2_premul[] = +{ + 68, 88, 66, 67, 192, 154, + 207, 90, 135, 137, 54, 139, + 29, 173, 73, 187, 168, 176, + 217, 47, 1, 0, 0, 0, + 60, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 128, 1, 0, 0, 20, 2, + 0, 0, 72, 2, 0, 0, + 192, 4, 0, 0, 82, 68, + 69, 70, 68, 1, 0, 0, + 2, 0, 0, 0, 116, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 28, 1, 0, 0, 92, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 100, 97, 116, + 97, 0, 102, 111, 103, 95, + 100, 97, 116, 97, 0, 171, + 171, 171, 92, 0, 0, 0, + 1, 0, 0, 0, 164, 0, + 0, 0, 16, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 104, 0, 0, 0, + 2, 0, 0, 0, 216, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 188, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 200, 0, 0, 0, 0, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 112, 111, 115, + 0, 171, 1, 0, 3, 0, + 1, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 8, 1, 0, 0, 0, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 18, 1, 0, 0, 16, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 102, 111, 103, 95, 99, 111, + 108, 111, 114, 0, 102, 111, + 103, 95, 114, 97, 110, 103, + 101, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 116, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 15, 7, 0, 0, 125, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 3, 0, 0, 0, 134, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, + 73, 79, 78, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 84, 69, 88, 67, 79, + 79, 82, 68, 0, 67, 79, + 76, 79, 82, 0, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 112, 2, 0, 0, 64, 0, + 0, 0, 156, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 89, 0, + 0, 4, 70, 142, 32, 0, + 1, 0, 0, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 1, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 59, 170, + 184, 191, 25, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 128, 65, 0, 0, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 8, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 3, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 178, 0, 16, 0, + 0, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 136, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 50, 0, 0, 9, 114, 32, + 16, 0, 0, 0, 0, 0, + 166, 10, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 3, 0, 0, 0, 70, 3, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 19, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 17, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp2_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp2_straight.h new file mode 100644 index 00000000..63be27cf --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp2_straight.h @@ -0,0 +1,309 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_input_ps linear v1.xyz +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, r0.x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +mul r0.w, r0.x, v3.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, v3.w, r0.w +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mul r1.xyz, v3.wwww, v3.xyzx +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 20 instruction slots used +#endif + +const BYTE pixel_shader_one_exp2_straight[] = +{ + 68, 88, 66, 67, 155, 197, + 198, 154, 255, 227, 164, 166, + 31, 159, 144, 132, 91, 42, + 126, 45, 1, 0, 0, 0, + 88, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 128, 1, 0, 0, 20, 2, + 0, 0, 72, 2, 0, 0, + 220, 4, 0, 0, 82, 68, + 69, 70, 68, 1, 0, 0, + 2, 0, 0, 0, 116, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 28, 1, 0, 0, 92, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 100, 97, 116, + 97, 0, 102, 111, 103, 95, + 100, 97, 116, 97, 0, 171, + 171, 171, 92, 0, 0, 0, + 1, 0, 0, 0, 164, 0, + 0, 0, 16, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 104, 0, 0, 0, + 2, 0, 0, 0, 216, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 188, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 200, 0, 0, 0, 0, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 112, 111, 115, + 0, 171, 1, 0, 3, 0, + 1, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 8, 1, 0, 0, 0, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 18, 1, 0, 0, 16, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 102, 111, 103, 95, 99, 111, + 108, 111, 114, 0, 102, 111, + 103, 95, 114, 97, 110, 103, + 101, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 116, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 15, 7, 0, 0, 125, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 3, 0, 0, 0, 134, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, + 73, 79, 78, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 84, 69, 88, 67, 79, + 79, 82, 68, 0, 67, 79, + 76, 79, 82, 0, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 140, 2, 0, 0, 64, 0, + 0, 0, 163, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 89, 0, + 0, 4, 70, 142, 32, 0, + 1, 0, 0, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 59, 170, + 184, 191, 25, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 128, 65, 0, 0, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 8, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 3, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 178, 0, 16, 0, + 0, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 136, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 18, 16, 0, + 3, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 166, 10, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 3, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 20, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 18, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp_premul.h new file mode 100644 index 00000000..10da2180 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp_premul.h @@ -0,0 +1,304 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_input_ps linear v1.xyz +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 1 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +max r0.x, r0.x, l(0.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +mul r0.w, r0.x, v3.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, v3.w, r0.w +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, v3.xyzx, r0.xywx +ret +// Approximately 19 instruction slots used +#endif + +const BYTE pixel_shader_one_exp_premul[] = +{ + 68, 88, 66, 67, 177, 74, + 174, 240, 221, 61, 29, 128, + 104, 145, 181, 36, 242, 94, + 236, 1, 1, 0, 0, 0, + 60, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 128, 1, 0, 0, 20, 2, + 0, 0, 72, 2, 0, 0, + 192, 4, 0, 0, 82, 68, + 69, 70, 68, 1, 0, 0, + 2, 0, 0, 0, 116, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 28, 1, 0, 0, 92, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 100, 97, 116, + 97, 0, 102, 111, 103, 95, + 100, 97, 116, 97, 0, 171, + 171, 171, 92, 0, 0, 0, + 1, 0, 0, 0, 164, 0, + 0, 0, 16, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 104, 0, 0, 0, + 2, 0, 0, 0, 216, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 188, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 200, 0, 0, 0, 0, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 112, 111, 115, + 0, 171, 1, 0, 3, 0, + 1, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 8, 1, 0, 0, 0, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 18, 1, 0, 0, 16, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 102, 111, 103, 95, 99, 111, + 108, 111, 114, 0, 102, 111, + 103, 95, 114, 97, 110, 103, + 101, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 116, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 15, 7, 0, 0, 125, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 3, 0, 0, 0, 134, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, + 73, 79, 78, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 84, 69, 88, 67, 79, + 79, 82, 68, 0, 67, 79, + 76, 79, 82, 0, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 112, 2, 0, 0, 64, 0, + 0, 0, 156, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 89, 0, + 0, 4, 70, 142, 32, 0, + 1, 0, 0, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 1, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 59, 170, 184, 191, 25, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 52, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 8, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 3, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 178, 0, 16, 0, + 0, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 136, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 50, 0, 0, 9, 114, 32, + 16, 0, 0, 0, 0, 0, + 166, 10, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 3, 0, 0, 0, 70, 3, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 19, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 17, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp_straight.h new file mode 100644 index 00000000..982f6b30 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_exp_straight.h @@ -0,0 +1,309 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_input_ps linear v1.xyz +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +max r0.x, r0.x, l(0.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +mul r0.w, r0.x, v3.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, v3.w, r0.w +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mul r1.xyz, v3.wwww, v3.xyzx +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 20 instruction slots used +#endif + +const BYTE pixel_shader_one_exp_straight[] = +{ + 68, 88, 66, 67, 66, 20, + 62, 170, 29, 152, 0, 74, + 133, 36, 220, 214, 144, 163, + 41, 42, 1, 0, 0, 0, + 88, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 128, 1, 0, 0, 20, 2, + 0, 0, 72, 2, 0, 0, + 220, 4, 0, 0, 82, 68, + 69, 70, 68, 1, 0, 0, + 2, 0, 0, 0, 116, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 28, 1, 0, 0, 92, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 100, 97, 116, + 97, 0, 102, 111, 103, 95, + 100, 97, 116, 97, 0, 171, + 171, 171, 92, 0, 0, 0, + 1, 0, 0, 0, 164, 0, + 0, 0, 16, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 104, 0, 0, 0, + 2, 0, 0, 0, 216, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 188, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 200, 0, 0, 0, 0, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 112, 111, 115, + 0, 171, 1, 0, 3, 0, + 1, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 8, 1, 0, 0, 0, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 18, 1, 0, 0, 16, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 102, 111, 103, 95, 99, 111, + 108, 111, 114, 0, 102, 111, + 103, 95, 114, 97, 110, 103, + 101, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 116, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 15, 7, 0, 0, 125, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 3, 0, 0, 0, 134, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, + 73, 79, 78, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 84, 69, 88, 67, 79, + 79, 82, 68, 0, 67, 79, + 76, 79, 82, 0, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 140, 2, 0, 0, 64, 0, + 0, 0, 163, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 89, 0, + 0, 4, 70, 142, 32, 0, + 1, 0, 0, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 59, 170, 184, 191, 25, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 52, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 3, 0, + 0, 0, 56, 0, 0, 8, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 3, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 178, 0, 16, 0, + 0, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 136, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 18, 16, 0, + 3, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 166, 10, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 3, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 20, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 18, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_one_linear_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_linear_premul.h new file mode 100644 index 00000000..b45a751b --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_linear_premul.h @@ -0,0 +1,289 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_input_ps linear v1.xyz +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 1 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +add r0.x, r0.x, -cb1[1].x +div_sat r0.x, r0.x, cb1[1].w +mul r0.y, r0.x, v3.w +mul r0.y, r0.y, cb1[0].w +add r0.z, -r0.x, l(1.000000) +mad r0.y, r0.z, v3.w, r0.y +mul r0.w, r0.y, r0.x +mov o0.w, r0.y +mad r0.x, r0.x, cb1[0].w, r0.z +mul r0.x, r0.x, r0.z +mul r0.yzw, r0.wwww, cb1[0].xxyz +mad o0.xyz, r0.xxxx, v3.xyzx, r0.yzwy +ret +// Approximately 16 instruction slots used +#endif + +const BYTE pixel_shader_one_linear_premul[] = +{ + 68, 88, 66, 67, 143, 243, + 168, 95, 251, 245, 240, 77, + 37, 184, 108, 163, 172, 121, + 67, 57, 1, 0, 0, 0, + 244, 4, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 128, 1, 0, 0, 20, 2, + 0, 0, 72, 2, 0, 0, + 120, 4, 0, 0, 82, 68, + 69, 70, 68, 1, 0, 0, + 2, 0, 0, 0, 116, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 28, 1, 0, 0, 92, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 100, 97, 116, + 97, 0, 102, 111, 103, 95, + 100, 97, 116, 97, 0, 171, + 171, 171, 92, 0, 0, 0, + 1, 0, 0, 0, 164, 0, + 0, 0, 16, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 104, 0, 0, 0, + 2, 0, 0, 0, 216, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 188, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 200, 0, 0, 0, 0, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 112, 111, 115, + 0, 171, 1, 0, 3, 0, + 1, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 8, 1, 0, 0, 0, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 18, 1, 0, 0, 16, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 102, 111, 103, 95, 99, 111, + 108, 111, 114, 0, 102, 111, + 103, 95, 114, 97, 110, 103, + 101, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 116, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 15, 7, 0, 0, 125, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 3, 0, 0, 0, 134, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, + 73, 79, 78, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 84, 69, 88, 67, 79, + 79, 82, 68, 0, 67, 79, + 76, 79, 82, 0, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 40, 2, 0, 0, 64, 0, + 0, 0, 138, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 89, 0, + 0, 4, 70, 142, 32, 0, + 1, 0, 0, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 1, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 14, 32, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 58, 16, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 8, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 66, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 9, + 34, 0, 16, 0, 0, 0, + 0, 0, 42, 0, 16, 0, + 0, 0, 0, 0, 58, 16, + 16, 0, 3, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 10, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 42, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 42, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 226, 0, 16, 0, + 0, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 6, 137, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 50, 0, 0, 9, 114, 32, + 16, 0, 0, 0, 0, 0, + 6, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 3, 0, 0, 0, 150, 7, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 16, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 14, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_one_linear_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_linear_straight.h new file mode 100644 index 00000000..ce796bbd --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_linear_straight.h @@ -0,0 +1,294 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float +// COLOR 0 xyzw 3 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_input_ps linear v1.xyz +dcl_input_ps linear v3.xyzw +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +add r0.x, r0.x, -cb1[1].x +div_sat r0.x, r0.x, cb1[1].w +mul r0.y, r0.x, v3.w +mul r0.y, r0.y, cb1[0].w +add r0.z, -r0.x, l(1.000000) +mad r0.y, r0.z, v3.w, r0.y +mul r0.w, r0.y, r0.x +mov o0.w, r0.y +mad r0.x, r0.x, cb1[0].w, r0.z +mul r0.x, r0.x, r0.z +mul r0.yzw, r0.wwww, cb1[0].xxyz +mul r1.xyz, v3.wwww, v3.xyzx +mad o0.xyz, r0.xxxx, r1.xyzx, r0.yzwy +ret +// Approximately 17 instruction slots used +#endif + +const BYTE pixel_shader_one_linear_straight[] = +{ + 68, 88, 66, 67, 2, 223, + 197, 206, 159, 43, 53, 238, + 92, 94, 125, 202, 96, 97, + 53, 55, 1, 0, 0, 0, + 16, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 128, 1, 0, 0, 20, 2, + 0, 0, 72, 2, 0, 0, + 148, 4, 0, 0, 82, 68, + 69, 70, 68, 1, 0, 0, + 2, 0, 0, 0, 116, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 28, 1, 0, 0, 92, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 100, 97, 116, + 97, 0, 102, 111, 103, 95, + 100, 97, 116, 97, 0, 171, + 171, 171, 92, 0, 0, 0, + 1, 0, 0, 0, 164, 0, + 0, 0, 16, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 104, 0, 0, 0, + 2, 0, 0, 0, 216, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 188, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 200, 0, 0, 0, 0, 0, + 0, 0, 99, 97, 109, 101, + 114, 97, 95, 112, 111, 115, + 0, 171, 1, 0, 3, 0, + 1, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 8, 1, 0, 0, 0, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 18, 1, 0, 0, 16, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 200, 0, + 0, 0, 0, 0, 0, 0, + 102, 111, 103, 95, 99, 111, + 108, 111, 114, 0, 102, 111, + 103, 95, 114, 97, 110, 103, + 101, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 73, 83, 71, 78, 140, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 116, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 15, 7, 0, 0, 125, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 3, 0, 0, 0, 134, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 3, 0, 0, 0, + 15, 15, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, + 73, 79, 78, 0, 80, 79, + 83, 73, 84, 73, 79, 78, + 0, 84, 69, 88, 67, 79, + 79, 82, 68, 0, 67, 79, + 76, 79, 82, 0, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 68, 2, 0, 0, 64, 0, + 0, 0, 145, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 89, 0, + 0, 4, 70, 142, 32, 0, + 1, 0, 0, 0, 2, 0, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 242, 16, 16, 0, 3, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 14, 32, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 58, 16, 16, 0, + 3, 0, 0, 0, 56, 0, + 0, 8, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 66, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 9, + 34, 0, 16, 0, 0, 0, + 0, 0, 42, 0, 16, 0, + 0, 0, 0, 0, 58, 16, + 16, 0, 3, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 7, + 130, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 10, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 42, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 42, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 226, 0, 16, 0, + 0, 0, 0, 0, 246, 15, + 16, 0, 0, 0, 0, 0, + 6, 137, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 0, + 16, 0, 1, 0, 0, 0, + 246, 31, 16, 0, 3, 0, + 0, 0, 70, 18, 16, 0, + 3, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 150, 7, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 17, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 15, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_one_none_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_none_premul.h new file mode 100644 index 00000000..c0694725 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_none_premul.h @@ -0,0 +1,113 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// TEXCOORD 0 xy 1 NONE float +// COLOR 0 xyzw 2 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v2.xyzw +dcl_output o0.xyzw +mov o0.xyzw, v2.xyzw +ret +// Approximately 2 instruction slots used +#endif + +const BYTE pixel_shader_one_none_premul[] = +{ + 68, 88, 66, 67, 255, 120, + 75, 56, 80, 231, 155, 40, + 198, 140, 99, 13, 168, 6, + 148, 114, 1, 0, 0, 0, + 228, 1, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 128, 0, 0, 0, 244, 0, + 0, 0, 40, 1, 0, 0, + 104, 1, 0, 0, 82, 68, + 69, 70, 68, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 28, 0, 0, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 108, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 92, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 3, 0, 0, 0, + 101, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 84, 69, 88, 67, 79, 79, + 82, 68, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 56, 0, 0, 0, 64, 0, + 0, 0, 14, 0, 0, 0, + 98, 16, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 242, 32, + 16, 0, 0, 0, 0, 0, + 70, 30, 16, 0, 2, 0, + 0, 0, 62, 0, 0, 1, + 83, 84, 65, 84, 116, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_one_none_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_none_straight.h new file mode 100644 index 00000000..0ea9d8a7 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_one_none_straight.h @@ -0,0 +1,119 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// TEXCOORD 0 xy 1 NONE float +// COLOR 0 xyzw 2 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_input_ps linear v2.xyzw +dcl_output o0.xyzw +mul o0.xyz, v2.wwww, v2.xyzx +mov o0.w, v2.w +ret +// Approximately 3 instruction slots used +#endif + +const BYTE pixel_shader_one_none_straight[] = +{ + 68, 88, 66, 67, 232, 70, + 201, 115, 200, 96, 8, 70, + 10, 28, 216, 168, 247, 74, + 245, 185, 1, 0, 0, 0, + 0, 2, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 128, 0, 0, 0, 244, 0, + 0, 0, 40, 1, 0, 0, + 132, 1, 0, 0, 82, 68, + 69, 70, 68, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 28, 0, 0, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 108, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 92, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 3, 0, 0, 0, + 101, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 15, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 84, 69, 88, 67, 79, 79, + 82, 68, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 84, 0, 0, 0, 64, 0, + 0, 0, 21, 0, 0, 0, + 98, 16, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 0, 0, 0, 0, + 246, 31, 16, 0, 2, 0, + 0, 0, 70, 18, 16, 0, + 2, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 0, 0, 0, 0, 58, 16, + 16, 0, 2, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 2, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp2_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp2_premul.h new file mode 100644 index 00000000..ff5abe7f --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp2_premul.h @@ -0,0 +1,333 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, r0.x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r0.w, r0.x, r1.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, r1.w, r0.w +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 20 instruction slots used +#endif + +const BYTE pixel_shader_zero_exp2_premul[] = +{ + 68, 88, 66, 67, 228, 228, + 14, 30, 95, 171, 116, 157, + 100, 143, 51, 248, 107, 83, + 19, 170, 1, 0, 0, 0, + 204, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 80, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 176, 2, 0, 0, + 64, 0, 0, 0, 172, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 59, 170, + 184, 191, 25, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 128, 65, 0, 0, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 178, 0, 16, 0, + 0, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 136, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 50, 0, 0, 9, 114, 32, + 16, 0, 0, 0, 0, 0, + 166, 10, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 70, 3, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 20, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 17, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp2_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp2_straight.h new file mode 100644 index 00000000..32a44cdc --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp2_straight.h @@ -0,0 +1,338 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, r0.x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r0.w, r0.x, r1.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, r1.w, r0.w +mul r1.xyz, r1.wwww, r1.xyzx +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 21 instruction slots used +#endif + +const BYTE pixel_shader_zero_exp2_straight[] = +{ + 68, 88, 66, 67, 108, 245, + 179, 60, 234, 202, 228, 255, + 194, 148, 196, 246, 255, 169, + 237, 206, 1, 0, 0, 0, + 232, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 108, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 204, 2, 0, 0, + 64, 0, 0, 0, 179, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 59, 170, + 184, 191, 25, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 128, 65, 0, 0, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 0, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 8, + 178, 0, 16, 0, 0, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 136, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 166, 10, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 3, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 21, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 18, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp_premul.h new file mode 100644 index 00000000..b6201d89 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp_premul.h @@ -0,0 +1,333 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +max r0.x, r0.x, l(0.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r0.w, r0.x, r1.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, r1.w, r0.w +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 20 instruction slots used +#endif + +const BYTE pixel_shader_zero_exp_premul[] = +{ + 68, 88, 66, 67, 210, 13, + 242, 136, 239, 144, 166, 160, + 235, 245, 178, 46, 164, 18, + 105, 228, 1, 0, 0, 0, + 204, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 80, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 176, 2, 0, 0, + 64, 0, 0, 0, 172, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 59, 170, 184, 191, 25, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 52, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 178, 0, 16, 0, + 0, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 136, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 50, 0, 0, 9, 114, 32, + 16, 0, 0, 0, 0, 0, + 166, 10, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 70, 3, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 20, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 17, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp_straight.h new file mode 100644 index 00000000..1c77bf8c --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_exp_straight.h @@ -0,0 +1,338 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +mul r0.x, r0.x, cb1[1].x +mul r0.x, r0.x, l(-1.442695) +exp r0.x, r0.x +add r0.x, -r0.x, l(1.000000) +max r0.x, r0.x, l(0.000000) +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r0.w, r0.x, r1.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, r1.w, r0.w +mul r1.xyz, r1.wwww, r1.xyzx +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 21 instruction slots used +#endif + +const BYTE pixel_shader_zero_exp_straight[] = +{ + 68, 88, 66, 67, 3, 120, + 173, 163, 185, 226, 69, 135, + 6, 147, 72, 170, 140, 149, + 3, 79, 1, 0, 0, 0, + 232, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 108, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 204, 2, 0, 0, + 64, 0, 0, 0, 179, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 56, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 1, 64, 0, 0, + 59, 170, 184, 191, 25, 0, + 0, 5, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 18, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 52, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 0, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 8, + 178, 0, 16, 0, 0, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 136, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 166, 10, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 3, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 21, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 18, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_linear_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_linear_premul.h new file mode 100644 index 00000000..e6ee7b75 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_linear_premul.h @@ -0,0 +1,318 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +add r0.x, r0.x, -cb1[1].x +div_sat r0.x, r0.x, cb1[1].w +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r0.w, r0.x, r1.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, r1.w, r0.w +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 17 instruction slots used +#endif + +const BYTE pixel_shader_zero_linear_premul[] = +{ + 68, 88, 66, 67, 92, 36, + 249, 176, 64, 198, 68, 101, + 167, 200, 109, 125, 117, 85, + 26, 40, 1, 0, 0, 0, + 132, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 8, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 104, 2, 0, 0, + 64, 0, 0, 0, 154, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 14, 32, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 0, 0, 0, + 0, 0, 54, 0, 0, 5, + 130, 32, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 8, 178, 0, 16, 0, + 0, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 70, 136, 32, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 50, 0, 0, 9, 114, 32, + 16, 0, 0, 0, 0, 0, + 166, 10, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 1, 0, 0, 0, 70, 3, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 17, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 14, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_linear_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_linear_straight.h new file mode 100644 index 00000000..c01e721b --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_linear_straight.h @@ -0,0 +1,323 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer camera_data +// { +// +// float4 camera_pos; // Offset: 0 Size: 16 +// +// } +// +// cbuffer fog_data +// { +// +// float4 fog_color; // Offset: 0 Size: 16 +// float4 fog_range; // Offset: 16 Size: 16 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// camera_data cbuffer NA NA cb0 1 +// fog_data cbuffer NA NA cb1 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// POSITION 0 xyzw 1 NONE float xyz +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_constantbuffer CB0[1], immediateIndexed +dcl_constantbuffer CB1[2], immediateIndexed +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyz +dcl_input_ps linear v2.xy +dcl_output o0.xyzw +dcl_temps 2 +add r0.xyz, -v1.xyzx, cb0[0].xyzx +dp3 r0.x, r0.xyzx, r0.xyzx +sqrt r0.x, r0.x +add r0.x, r0.x, -cb1[1].x +div_sat r0.x, r0.x, cb1[1].w +add r0.y, -r0.x, l(1.000000) +mad r0.z, r0.x, cb1[0].w, r0.y +mul r0.z, r0.z, r0.y +sample r1.xyzw, v2.xyxx, t0.xyzw, s0 +mul r0.w, r0.x, r1.w +mul r0.w, r0.w, cb1[0].w +mad r0.y, r0.y, r1.w, r0.w +mul r1.xyz, r1.wwww, r1.xyzx +mul r0.x, r0.y, r0.x +mov o0.w, r0.y +mul r0.xyw, r0.xxxx, cb1[0].xyxz +mad o0.xyz, r0.zzzz, r1.xyzx, r0.xywx +ret +// Approximately 18 instruction slots used +#endif + +const BYTE pixel_shader_zero_linear_straight[] = +{ + 68, 88, 66, 67, 195, 180, + 94, 84, 228, 226, 201, 65, + 48, 170, 36, 55, 107, 170, + 109, 85, 1, 0, 0, 0, + 160, 5, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 208, 1, 0, 0, 100, 2, + 0, 0, 152, 2, 0, 0, + 36, 5, 0, 0, 82, 68, + 69, 70, 148, 1, 0, 0, + 2, 0, 0, 0, 196, 0, + 0, 0, 4, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 108, 1, 0, 0, 156, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 165, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 174, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 186, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 99, 97, 109, 101, 114, 97, + 95, 100, 97, 116, 97, 0, + 102, 111, 103, 95, 100, 97, + 116, 97, 0, 171, 174, 0, + 0, 0, 1, 0, 0, 0, + 244, 0, 0, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 186, 0, + 0, 0, 2, 0, 0, 0, + 40, 1, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 12, 1, + 0, 0, 0, 0, 0, 0, + 16, 0, 0, 0, 2, 0, + 0, 0, 24, 1, 0, 0, + 0, 0, 0, 0, 99, 97, + 109, 101, 114, 97, 95, 112, + 111, 115, 0, 171, 1, 0, + 3, 0, 1, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 88, 1, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 98, 1, 0, 0, + 16, 0, 0, 0, 16, 0, + 0, 0, 2, 0, 0, 0, + 24, 1, 0, 0, 0, 0, + 0, 0, 102, 111, 103, 95, + 99, 111, 108, 111, 114, 0, + 102, 111, 103, 95, 114, 97, + 110, 103, 101, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 7, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 79, 83, 71, 78, 44, 0, + 0, 0, 1, 0, 0, 0, + 8, 0, 0, 0, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 83, 86, + 95, 84, 65, 82, 71, 69, + 84, 0, 171, 171, 83, 72, + 68, 82, 132, 2, 0, 0, + 64, 0, 0, 0, 161, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 1, 0, 0, 0, + 2, 0, 0, 0, 90, 0, + 0, 3, 0, 96, 16, 0, + 0, 0, 0, 0, 88, 24, + 0, 4, 0, 112, 16, 0, + 0, 0, 0, 0, 85, 85, + 0, 0, 98, 16, 0, 3, + 114, 16, 16, 0, 1, 0, + 0, 0, 98, 16, 0, 3, + 50, 16, 16, 0, 2, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 0, 0, + 0, 0, 104, 0, 0, 2, + 2, 0, 0, 0, 0, 0, + 0, 9, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 128, 65, 0, 0, 0, + 1, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 0, + 0, 7, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 2, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 75, 0, 0, 5, + 18, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 9, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 10, 128, 32, 128, 65, 0, + 0, 0, 1, 0, 0, 0, + 1, 0, 0, 0, 14, 32, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 128, 32, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 8, 34, 0, + 16, 0, 0, 0, 0, 0, + 10, 0, 16, 128, 65, 0, + 0, 0, 0, 0, 0, 0, + 1, 64, 0, 0, 0, 0, + 128, 63, 50, 0, 0, 10, + 66, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 66, 0, + 16, 0, 0, 0, 0, 0, + 42, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 0, 16, 0, + 1, 0, 0, 0, 70, 16, + 16, 0, 2, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 130, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 130, 0, 16, 0, 0, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 58, 128, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 34, 0, 16, 0, + 0, 0, 0, 0, 26, 0, + 16, 0, 0, 0, 0, 0, + 58, 0, 16, 0, 1, 0, + 0, 0, 58, 0, 16, 0, + 0, 0, 0, 0, 56, 0, + 0, 7, 114, 0, 16, 0, + 1, 0, 0, 0, 246, 15, + 16, 0, 1, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 7, + 18, 0, 16, 0, 0, 0, + 0, 0, 26, 0, 16, 0, + 0, 0, 0, 0, 10, 0, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 56, 0, 0, 8, + 178, 0, 16, 0, 0, 0, + 0, 0, 6, 0, 16, 0, + 0, 0, 0, 0, 70, 136, + 32, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 50, 0, + 0, 9, 114, 32, 16, 0, + 0, 0, 0, 0, 166, 10, + 16, 0, 0, 0, 0, 0, + 70, 2, 16, 0, 1, 0, + 0, 0, 70, 3, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 18, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 15, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_none_premul.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_none_premul.h new file mode 100644 index 00000000..e2e80eb4 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_none_premul.h @@ -0,0 +1,144 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// TEXCOORD 0 xy 1 NONE float xy +// COLOR 0 xyzw 2 NONE float +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xy +dcl_output o0.xyzw +sample o0.xyzw, v1.xyxx, t0.xyzw, s0 +ret +// Approximately 2 instruction slots used +#endif + +const BYTE pixel_shader_zero_none_premul[] = +{ + 68, 88, 66, 67, 231, 213, + 70, 51, 81, 117, 49, 152, + 20, 123, 4, 142, 226, 229, + 205, 136, 1, 0, 0, 0, + 100, 2, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 212, 0, 0, 0, 72, 1, + 0, 0, 124, 1, 0, 0, + 232, 1, 0, 0, 82, 68, + 69, 70, 152, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 110, 0, 0, 0, 92, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 115, 97, 109, 112, + 108, 101, 114, 48, 0, 116, + 101, 120, 116, 117, 114, 101, + 48, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 171, 171, 73, 83, 71, 78, + 108, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 92, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 3, 3, 0, 0, + 101, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 84, 69, 88, 67, 79, 79, + 82, 68, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 100, 0, 0, 0, 64, 0, + 0, 0, 25, 0, 0, 0, + 90, 0, 0, 3, 0, 96, + 16, 0, 0, 0, 0, 0, + 88, 24, 0, 4, 0, 112, + 16, 0, 0, 0, 0, 0, + 85, 85, 0, 0, 98, 16, + 0, 3, 50, 16, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 0, 0, 0, 0, 69, 0, + 0, 9, 242, 32, 16, 0, + 0, 0, 0, 0, 70, 16, + 16, 0, 1, 0, 0, 0, + 70, 126, 16, 0, 0, 0, + 0, 0, 0, 96, 16, 0, + 0, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_none_straight.h b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_none_straight.h new file mode 100644 index 00000000..676edaec --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/pixel_shader_zero_none_straight.h @@ -0,0 +1,157 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// TEXCOORD 0 xy 1 NONE float xy +// COLOR 0 xyzw 2 NONE float +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_TARGET 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xy +dcl_output o0.xyzw +dcl_temps 1 +sample r0.xyzw, v1.xyxx, t0.xyzw, s0 +mul o0.xyz, r0.wwww, r0.xyzx +mov o0.w, r0.w +ret +// Approximately 4 instruction slots used +#endif + +const BYTE pixel_shader_zero_none_straight[] = +{ + 68, 88, 66, 67, 189, 104, + 27, 226, 125, 48, 254, 27, + 45, 76, 211, 235, 81, 117, + 38, 167, 1, 0, 0, 0, + 156, 2, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 212, 0, 0, 0, 72, 1, + 0, 0, 124, 1, 0, 0, + 32, 2, 0, 0, 82, 68, + 69, 70, 152, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 110, 0, 0, 0, 92, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 13, 0, + 0, 0, 115, 97, 109, 112, + 108, 101, 114, 48, 0, 116, + 101, 120, 116, 117, 114, 101, + 48, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 171, 171, 73, 83, 71, 78, + 108, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 92, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 3, 3, 0, 0, + 101, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 84, 69, 88, 67, 79, 79, + 82, 68, 0, 67, 79, 76, + 79, 82, 0, 171, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 65, 82, 71, 69, 84, 0, + 171, 171, 83, 72, 68, 82, + 156, 0, 0, 0, 64, 0, + 0, 0, 39, 0, 0, 0, + 90, 0, 0, 3, 0, 96, + 16, 0, 0, 0, 0, 0, + 88, 24, 0, 4, 0, 112, + 16, 0, 0, 0, 0, 0, + 85, 85, 0, 0, 98, 16, + 0, 3, 50, 16, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 0, 0, 0, 0, 104, 0, + 0, 2, 1, 0, 0, 0, + 69, 0, 0, 9, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 16, 16, 0, 1, 0, + 0, 0, 70, 126, 16, 0, + 0, 0, 0, 0, 0, 96, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 114, 32, + 16, 0, 0, 0, 0, 0, + 246, 15, 16, 0, 0, 0, + 0, 0, 70, 2, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 0, 0, 0, 0, 58, 0, + 16, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 83, 84, + 65, 84, 116, 0, 0, 0, + 4, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 2, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0 +}; diff --git a/LuaSTG/Shader/luastg/sub/renderer/vertex_shader.hlsl b/engine/graphics/d3d11/shader/renderer/vertex_shader.hlsl similarity index 99% rename from LuaSTG/Shader/luastg/sub/renderer/vertex_shader.hlsl rename to engine/graphics/d3d11/shader/renderer/vertex_shader.hlsl index 7232e611..9220217f 100644 --- a/LuaSTG/Shader/luastg/sub/renderer/vertex_shader.hlsl +++ b/engine/graphics/d3d11/shader/renderer/vertex_shader.hlsl @@ -1,9 +1,8 @@ - - cbuffer view_proj_buffer : register(b0) { float4x4 view_proj; }; + #if defined(WORLD_MATRIX) cbuffer world_buffer : register(b1) { @@ -17,6 +16,7 @@ struct VS_Input float2 uv : TEXCOORD0; float4 col : COLOR0; }; + struct VS_Output { float4 sxy : SV_POSITION; @@ -46,4 +46,3 @@ VS_Output main(VS_Input input) return output; }; - diff --git a/engine/graphics/d3d11/shader/renderer/vertex_shader_fog.h b/engine/graphics/d3d11/shader/renderer/vertex_shader_fog.h new file mode 100644 index 00000000..edd26b08 --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/vertex_shader_fog.h @@ -0,0 +1,232 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer view_proj_buffer +// { +// +// float4x4 view_proj; // Offset: 0 Size: 64 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// view_proj_buffer cbuffer NA NA cb0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xy 1 NONE float xy +// COLOR 0 xyzw 2 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float xyzw +// POSITION 0 xyzw 1 NONE float xyzw +// TEXCOORD 0 xy 2 NONE float xy +// COLOR 0 xyzw 3 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer CB0[4], immediateIndexed +dcl_input v0.xyz +dcl_input v1.xy +dcl_input v2.xyzw +dcl_output_siv o0.xyzw, position +dcl_output o1.xyzw +dcl_output o2.xy +dcl_output o3.xyzw +dcl_temps 1 +mul r0.xyzw, v0.yyyy, cb0[1].xyzw +mad r0.xyzw, cb0[0].xyzw, v0.xxxx, r0.xyzw +mad r0.xyzw, cb0[2].xyzw, v0.zzzz, r0.xyzw +add o0.xyzw, r0.xyzw, cb0[3].xyzw +mov o1.xyz, v0.xyzx +mov o1.w, l(1.000000) +mov o2.xy, v1.xyxx +mov o3.xyzw, v2.xyzw +ret +// Approximately 9 instruction slots used +#endif + +const BYTE vertex_shader_fog[] = +{ + 68, 88, 66, 67, 213, 236, + 107, 106, 63, 244, 72, 34, + 117, 223, 197, 222, 187, 95, + 135, 33, 1, 0, 0, 0, + 228, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 0, 1, 0, 0, 112, 1, + 0, 0, 4, 2, 0, 0, + 104, 3, 0, 0, 82, 68, + 69, 70, 196, 0, 0, 0, + 1, 0, 0, 0, 80, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 137, 0, 0, + 156, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 118, 105, 101, 119, 95, 112, + 114, 111, 106, 95, 98, 117, + 102, 102, 101, 114, 0, 171, + 171, 171, 60, 0, 0, 0, + 1, 0, 0, 0, 104, 0, + 0, 0, 64, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 128, 0, 0, 0, + 0, 0, 0, 0, 64, 0, + 0, 0, 2, 0, 0, 0, + 140, 0, 0, 0, 0, 0, + 0, 0, 118, 105, 101, 119, + 95, 112, 114, 111, 106, 0, + 171, 171, 3, 0, 3, 0, + 4, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 77, 105, 99, 114, 111, 115, + 111, 102, 116, 32, 40, 82, + 41, 32, 72, 76, 83, 76, + 32, 83, 104, 97, 100, 101, + 114, 32, 67, 111, 109, 112, + 105, 108, 101, 114, 32, 49, + 48, 46, 49, 0, 73, 83, + 71, 78, 104, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 7, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 3, 3, + 0, 0, 98, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 15, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 67, 79, 76, 79, + 82, 0, 79, 83, 71, 78, + 140, 0, 0, 0, 4, 0, + 0, 0, 8, 0, 0, 0, + 104, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 116, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 0, 0, 0, + 125, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 12, 0, 0, + 134, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 3, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 67, 79, 76, 79, 82, 0, + 83, 72, 68, 82, 92, 1, + 0, 0, 64, 0, 1, 0, + 87, 0, 0, 0, 89, 0, + 0, 4, 70, 142, 32, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 95, 0, 0, 3, + 114, 16, 16, 0, 0, 0, + 0, 0, 95, 0, 0, 3, + 50, 16, 16, 0, 1, 0, + 0, 0, 95, 0, 0, 3, + 242, 16, 16, 0, 2, 0, + 0, 0, 103, 0, 0, 4, + 242, 32, 16, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 50, 32, + 16, 0, 2, 0, 0, 0, + 101, 0, 0, 3, 242, 32, + 16, 0, 3, 0, 0, 0, + 104, 0, 0, 2, 1, 0, + 0, 0, 56, 0, 0, 8, + 242, 0, 16, 0, 0, 0, + 0, 0, 86, 21, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 50, 0, + 0, 10, 242, 0, 16, 0, + 0, 0, 0, 0, 70, 142, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 6, 16, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 50, 0, 0, 10, + 242, 0, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 166, 26, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 242, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 54, 0, 0, 5, + 114, 32, 16, 0, 1, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 32, 16, 0, + 1, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 54, 0, 0, 5, 50, 32, + 16, 0, 2, 0, 0, 0, + 70, 16, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 5, + 242, 32, 16, 0, 3, 0, + 0, 0, 70, 30, 16, 0, + 2, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 9, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/d3d11/shader/renderer/vertex_shader_normal.h b/engine/graphics/d3d11/shader/renderer/vertex_shader_normal.h new file mode 100644 index 00000000..54fd953a --- /dev/null +++ b/engine/graphics/d3d11/shader/renderer/vertex_shader_normal.h @@ -0,0 +1,214 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer view_proj_buffer +// { +// +// float4x4 view_proj; // Offset: 0 Size: 64 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// view_proj_buffer cbuffer NA NA cb0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xyz 0 NONE float xyz +// TEXCOORD 0 xy 1 NONE float xy +// COLOR 0 xyzw 2 NONE float xyzw +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float xyzw +// TEXCOORD 0 xy 1 NONE float xy +// COLOR 0 xyzw 2 NONE float xyzw +// +vs_4_0 +dcl_constantbuffer CB0[4], immediateIndexed +dcl_input v0.xyz +dcl_input v1.xy +dcl_input v2.xyzw +dcl_output_siv o0.xyzw, position +dcl_output o1.xy +dcl_output o2.xyzw +dcl_temps 1 +mul r0.xyzw, v0.yyyy, cb0[1].xyzw +mad r0.xyzw, cb0[0].xyzw, v0.xxxx, r0.xyzw +mad r0.xyzw, cb0[2].xyzw, v0.zzzz, r0.xyzw +add o0.xyzw, r0.xyzw, cb0[3].xyzw +mov o1.xy, v1.xyxx +mov o2.xyzw, v2.xyzw +ret +// Approximately 7 instruction slots used +#endif + +const BYTE vertex_shader_normal[] = +{ + 68, 88, 66, 67, 67, 208, + 43, 25, 109, 184, 168, 179, + 217, 104, 255, 163, 112, 100, + 156, 68, 1, 0, 0, 0, + 144, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 0, 1, 0, 0, 112, 1, + 0, 0, 228, 1, 0, 0, + 20, 3, 0, 0, 82, 68, + 69, 70, 196, 0, 0, 0, + 1, 0, 0, 0, 80, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 137, 0, 0, + 156, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 118, 105, 101, 119, 95, 112, + 114, 111, 106, 95, 98, 117, + 102, 102, 101, 114, 0, 171, + 171, 171, 60, 0, 0, 0, + 1, 0, 0, 0, 104, 0, + 0, 0, 64, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 128, 0, 0, 0, + 0, 0, 0, 0, 64, 0, + 0, 0, 2, 0, 0, 0, + 140, 0, 0, 0, 0, 0, + 0, 0, 118, 105, 101, 119, + 95, 112, 114, 111, 106, 0, + 171, 171, 3, 0, 3, 0, + 4, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 77, 105, 99, 114, 111, 115, + 111, 102, 116, 32, 40, 82, + 41, 32, 72, 76, 83, 76, + 32, 83, 104, 97, 100, 101, + 114, 32, 67, 111, 109, 112, + 105, 108, 101, 114, 32, 49, + 48, 46, 49, 0, 73, 83, + 71, 78, 104, 0, 0, 0, + 3, 0, 0, 0, 8, 0, + 0, 0, 80, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 7, + 0, 0, 89, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 1, 0, 0, 0, 3, 3, + 0, 0, 98, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 15, 15, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 84, + 69, 88, 67, 79, 79, 82, + 68, 0, 67, 79, 76, 79, + 82, 0, 79, 83, 71, 78, + 108, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 92, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 3, 12, 0, 0, + 101, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 84, 69, 88, 67, 79, 79, + 82, 68, 0, 67, 79, 76, + 79, 82, 0, 171, 83, 72, + 68, 82, 40, 1, 0, 0, + 64, 0, 1, 0, 74, 0, + 0, 0, 89, 0, 0, 4, + 70, 142, 32, 0, 0, 0, + 0, 0, 4, 0, 0, 0, + 95, 0, 0, 3, 114, 16, + 16, 0, 0, 0, 0, 0, + 95, 0, 0, 3, 50, 16, + 16, 0, 1, 0, 0, 0, + 95, 0, 0, 3, 242, 16, + 16, 0, 2, 0, 0, 0, + 103, 0, 0, 4, 242, 32, + 16, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 50, 32, 16, 0, + 1, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 2, 0, 0, 0, 104, 0, + 0, 2, 1, 0, 0, 0, + 56, 0, 0, 8, 242, 0, + 16, 0, 0, 0, 0, 0, + 86, 21, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 50, 0, 0, 10, + 242, 0, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 6, 16, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 50, 0, 0, 10, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 142, 32, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 166, 26, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 242, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 142, 32, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 54, 0, 0, 5, 50, 32, + 16, 0, 1, 0, 0, 0, + 70, 16, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 5, + 242, 32, 16, 0, 2, 0, + 0, 0, 70, 30, 16, 0, + 2, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 7, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 6, 0, + 0, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/engine/graphics/design.md b/engine/graphics/design.md new file mode 100644 index 00000000..f8142c09 --- /dev/null +++ b/engine/graphics/design.md @@ -0,0 +1,71 @@ +# Design + +## D3D10 style + +IGraphicsDevice + +IVertexBuffer +IIndexBuffer +IConstantBuffer +IRenderTarget +IDepthStencilBuffer +ITexture2D + +IInputLayout +IVertexShader +IRasterizerState +ISamplerState +IPixelShader +IDepthStencilState +IBlendState + +## Minimal + +IGraphicsDevice + +IBuffer +IRenderTarget +IDepthStencilBuffer +ITexture2D + +IPipelineState +ISamplerState + +## Mixed style + +IGraphicsDevice + +IVertexBuffer +IIndexBuffer +IConstantBuffer +IRenderTarget +IDepthStencilBuffer +ITexture2D + +IPipelineState +ISamplerState + +## Tree + +GraphicsResource +- GraphicsBuffer + - VertexBuffer + - IndexBuffer + - ConstantBuffer +- GraphicsTexture + - LineTexture + - SurfaceTexture + - CubeTexture + - VolumeTexture + +## HLSL Semantics + +- LUASTG_CAMERA_POSITION +- LUASTG_CAMERA_UP +- LUASTG_CAMERA_DIRECTION +- LUASTG_TEXTURE_SIZE +- LUASTG_TEXTURE_PREMUL_ALPHA +- LUASTG_FOG_NEAR +- LUASTG_FOG_FAR +- LUASTG_FOG_COLOR +- LUASTG_FOG_DENSITY diff --git a/engine/image/backend/Image.cpp b/engine/image/backend/Image.cpp index 02062754..0bbda53b 100644 --- a/engine/image/backend/Image.cpp +++ b/engine/image/backend/Image.cpp @@ -22,6 +22,10 @@ namespace { core::Logger::error("[core] unknown image color space ({})"sv, static_cast(description.color_space)); return false; } + if (I(description.alpha_mode) <= I(core::ImageAlphaMode::unknown) || I(description.alpha_mode) >= I(core::ImageAlphaMode::count)) { + core::Logger::error("[core] unknown image alpha mode ({})"sv, static_cast(description.alpha_mode)); + return false; + } #undef I if (description.color_space == core::ImageColorSpace::srgb_gamma_2_2) { switch (description.format) { diff --git a/engine/image/backend/JpegImageFactory.cpp b/engine/image/backend/JpegImageFactory.cpp index 988962be..8e602ecf 100644 --- a/engine/image/backend/JpegImageFactory.cpp +++ b/engine/image/backend/JpegImageFactory.cpp @@ -66,6 +66,7 @@ namespace core { description.size.y = static_cast(height); description.format = ImageFormat::b8g8r8a8_normalized; description.color_space = ImageColorSpace::srgb_gamma_2_2; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; image.attach(new Image()); diff --git a/engine/image/backend/PngImageFactory.cpp b/engine/image/backend/PngImageFactory.cpp index 6eb5b9dd..3e2b15db 100644 --- a/engine/image/backend/PngImageFactory.cpp +++ b/engine/image/backend/PngImageFactory.cpp @@ -60,6 +60,7 @@ namespace core { description.size.y = png.height; description.format = ImageFormat::b8g8r8a8_normalized; description.color_space = ImageColorSpace::srgb_gamma_2_2; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; image.attach(new Image()); diff --git a/engine/image/backend/QoiImageFactory.cpp b/engine/image/backend/QoiImageFactory.cpp index 9c6122ef..a1f8a01a 100644 --- a/engine/image/backend/QoiImageFactory.cpp +++ b/engine/image/backend/QoiImageFactory.cpp @@ -55,6 +55,7 @@ namespace core { description.color_space = info.colorspace == QOI_LINEAR ? ImageColorSpace::linear : ImageColorSpace::srgb_gamma_2_2; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; image.attach(new Image()); diff --git a/engine/image/backend/StbImageFactory.cpp b/engine/image/backend/StbImageFactory.cpp index 9b0789c6..9cfe9895 100644 --- a/engine/image/backend/StbImageFactory.cpp +++ b/engine/image/backend/StbImageFactory.cpp @@ -69,6 +69,7 @@ namespace core { description.size.y = static_cast(height); description.format = ImageFormat::r8g8b8a8_normalized; description.color_space = ImageColorSpace::srgb_gamma_2_2; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; image.attach(new Image()); diff --git a/engine/image/backend/WebpImageFactory.cpp b/engine/image/backend/WebpImageFactory.cpp index 6db55d96..c15edbf9 100644 --- a/engine/image/backend/WebpImageFactory.cpp +++ b/engine/image/backend/WebpImageFactory.cpp @@ -44,6 +44,7 @@ namespace core { description.size.y = static_cast(height); description.format = ImageFormat::b8g8r8a8_normalized; description.color_space = ImageColorSpace::srgb_gamma_2_2; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; image.attach(new Image()); diff --git a/engine/image/backend/WicImageFactory.cpp b/engine/image/backend/WicImageFactory.cpp index 0bf59c44..ae599a12 100644 --- a/engine/image/backend/WicImageFactory.cpp +++ b/engine/image/backend/WicImageFactory.cpp @@ -162,6 +162,7 @@ namespace core { description.size.y = height; description.format = ImageFormat::r8g8b8a8_normalized; description.color_space = ImageColorSpace::srgb_gamma_2_2; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; image.attach(new Image()); diff --git a/engine/image/core/Image.hpp b/engine/image/core/Image.hpp index 3b816564..9b1d3023 100644 --- a/engine/image/core/Image.hpp +++ b/engine/image/core/Image.hpp @@ -40,10 +40,31 @@ namespace core { count, }; + enum class ImageAlphaMode : int32_t { + // Indicate that an error has occurred + unknown, + + // Always ignore alpha channel + opaque, + + // A commonly used format for storing images, + // where color channels represent color and + // the alpha channel represents transparency. + straight, + + // The color channels have already been pre-multiplied with the alpha channel. + // This is typically due to performing alpha blending of two or more images. + premultiplied, + + // Image alpha mode count + count, + }; + struct ImageDescription { Vector2U size; ImageFormat format{}; ImageColorSpace color_space{}; + ImageAlphaMode alpha_mode{}; }; struct ImageMappedBuffer { @@ -106,6 +127,9 @@ namespace core { // Get current image color-space, or return unknown if failed or not initialized. inline ImageColorSpace getColorSpace() const noexcept { return getDescription()->color_space; } + + // Get current image alpha-mode, or return unknown if failed or not initialized. + inline ImageAlphaMode getAlphaMode() const noexcept { return getDescription()->alpha_mode; } }; CORE_INTERFACE_ID(IImage, "5e4c12e0-e094-5346-b129-b9ddbb881373") diff --git a/engine/image/test/test.cpp b/engine/image/test/test.cpp index 2a22b07c..b3aab172 100644 --- a/engine/image/test/test.cpp +++ b/engine/image/test/test.cpp @@ -48,6 +48,7 @@ TEST(Image, create) { description.size.y = 1; description.format = ImageFormat::r8g8b8a8_normalized; description.color_space = ImageColorSpace::linear; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; ASSERT_TRUE(ImageFactory::create(description, image.put())); @@ -62,6 +63,7 @@ TEST(Image, create_with_nullptr) { description.size.y = 1; description.format = ImageFormat::r8g8b8a8_normalized; description.color_space = ImageColorSpace::linear; + description.alpha_mode = ImageAlphaMode::straight; ASSERT_FALSE(ImageFactory::create(description, nullptr)); } @@ -73,6 +75,7 @@ TEST(Image, create_with_wrong_size) { ImageDescription description; description.format = ImageFormat::r8g8b8a8_normalized; description.color_space = ImageColorSpace::linear; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; @@ -102,6 +105,7 @@ TEST(Image, create_with_wrong_format) { description.size.y = 1; description.format = ImageFormat::unknown; description.color_space = ImageColorSpace::linear; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; ASSERT_FALSE(ImageFactory::create(description, image.put())); @@ -115,6 +119,7 @@ TEST(Image, create_with_wrong_color_space) { description.size.x = 1; description.size.y = 1; description.color_space = ImageColorSpace::srgb_gamma_2_2; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; @@ -145,6 +150,7 @@ TEST(Image, map) { description.size.y = 1; description.format = ImageFormat::r8g8b8a8_normalized; description.color_space = ImageColorSpace::linear; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; ASSERT_TRUE(ImageFactory::create(description, image.put())); @@ -163,6 +169,7 @@ TEST(Image, r8g8b8a8_normalized_map_write_unmap_getPixel) { description.size.y = 1; description.format = ImageFormat::r8g8b8a8_normalized; description.color_space = ImageColorSpace::linear; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; ASSERT_TRUE(ImageFactory::create(description, image.put())); @@ -186,6 +193,7 @@ TEST(Image, b8g8r8a8_normalized_map_write_unmap_getPixel) { description.size.y = 1; description.format = ImageFormat::b8g8r8a8_normalized; description.color_space = ImageColorSpace::linear; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; ASSERT_TRUE(ImageFactory::create(description, image.put())); @@ -209,6 +217,7 @@ TEST(Image, r16g16b16a16_float_map_write_unmap_getPixel) { description.size.y = 1; description.format = ImageFormat::r16g16b16a16_float; description.color_space = ImageColorSpace::linear; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; ASSERT_TRUE(ImageFactory::create(description, image.put())); @@ -236,6 +245,7 @@ TEST(Image, r32g32b32a32_float_map_write_unmap_getPixel) { description.size.y = 1; description.format = ImageFormat::r32g32b32a32_float; description.color_space = ImageColorSpace::linear; + description.alpha_mode = ImageAlphaMode::straight; SmartReference image; ASSERT_TRUE(ImageFactory::create(description, image.put())); diff --git a/engine/reference-counted/core/ReferenceCounted.hpp b/engine/reference-counted/core/ReferenceCounted.hpp index 78874a79..f450fdd3 100644 --- a/engine/reference-counted/core/ReferenceCounted.hpp +++ b/engine/reference-counted/core/ReferenceCounted.hpp @@ -2,8 +2,8 @@ #include #include "core/UUID.hpp" -#define CORE_NO_VIRTUAL_TABLE __declspec(novtable) #define CORE_INTERFACE struct __declspec(novtable) + #define CORE_INTERFACE_ID(NAME, ID) template<> constexpr InterfaceId getInterfaceId() { return UUID::parse(ID); } namespace core { @@ -12,12 +12,13 @@ namespace core { template InterfaceId getInterfaceId() { return Interface::interface_uuid; } - struct CORE_NO_VIRTUAL_TABLE IReferenceCounted { + CORE_INTERFACE IReferenceCounted { virtual bool queryInterface(InterfaceId const& uuid, void** output) = 0; virtual int32_t retain() = 0; virtual int32_t release() = 0; - template bool queryInterface(Interface** const output) { + template + bool queryInterface(Interface** const output) { static_assert(std::is_base_of_v); return queryInterface(getInterfaceId(), reinterpret_cast(output)); } @@ -26,5 +27,5 @@ namespace core { // UUID v5 // ns:URL // https://www.luastg-sub.com/core.IReferenceCounted - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("b6a42c9f-376b-57e7-95a0-68b74556d1e4"); } + CORE_INTERFACE_ID(IReferenceCounted, "b6a42c9f-376b-57e7-95a0-68b74556d1e4") } diff --git a/engine/reference-counted/core/WeakReference.hpp b/engine/reference-counted/core/WeakReference.hpp index 86169e92..bd708f50 100644 --- a/engine/reference-counted/core/WeakReference.hpp +++ b/engine/reference-counted/core/WeakReference.hpp @@ -2,10 +2,11 @@ #include "core/ReferenceCounted.hpp" namespace core { - struct CORE_NO_VIRTUAL_TABLE IWeakReference : IReferenceCounted { + CORE_INTERFACE IWeakReference : IReferenceCounted { virtual bool resolve(InterfaceId const& uuid, void** output) = 0; - template bool resolve(Interface** const output) { + template + bool resolve(Interface** const output) { static_assert(std::is_base_of_v); return resolve(getInterfaceId(), reinterpret_cast(output)); } @@ -14,5 +15,5 @@ namespace core { // UUID v5 // ns:URL // https://www.luastg-sub.com/core.IWeakReference - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("cef127a6-3ae3-541c-a8e2-42257d983eaa"); } + CORE_INTERFACE_ID(IWeakReference, "cef127a6-3ae3-541c-a8e2-42257d983eaa") } diff --git a/engine/reference-counted/core/WeakReferenceSource.hpp b/engine/reference-counted/core/WeakReferenceSource.hpp index 8992d510..3bdbbb3c 100644 --- a/engine/reference-counted/core/WeakReferenceSource.hpp +++ b/engine/reference-counted/core/WeakReferenceSource.hpp @@ -2,12 +2,12 @@ #include "core/WeakReference.hpp" namespace core { - struct CORE_NO_VIRTUAL_TABLE IWeakReferenceSource : IReferenceCounted { + CORE_INTERFACE IWeakReferenceSource : IReferenceCounted { virtual void getWeakReference(IWeakReference** output) = 0; }; // UUID v5 // ns:URL // https://www.luastg-sub.com/core.IWeakReferenceSource - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("beabd630-bc16-5df7-b4f1-595f4c55d1a4"); } + CORE_INTERFACE_ID(IWeakReferenceSource, "beabd630-bc16-5df7-b4f1-595f4c55d1a4") } } diff --git a/engine/reference-counted/core/implement/ReferenceCounted.hpp b/engine/reference-counted/core/implement/ReferenceCounted.hpp index a70dc422..71a94450 100644 --- a/engine/reference-counted/core/implement/ReferenceCounted.hpp +++ b/engine/reference-counted/core/implement/ReferenceCounted.hpp @@ -5,13 +5,21 @@ #include namespace core::implement { + template + struct FirstTypeHelper { + using type = Type; + }; + + template + using FirstType = typename FirstTypeHelper::type; + struct ReferenceCounter { std::atomic_int32_t strong{ 1 }; std::atomic_int32_t weak{ 1 }; }; - template - class NoOperationReferenceCounted : public T { + template + class NoOperationReferenceCounted : public Interfaces... { public: int32_t retain() override { return 1; @@ -19,18 +27,15 @@ namespace core::implement { int32_t release() override { return 1; } - bool queryInterface(InterfaceId const& uuid, void** const output) override { - assert(output != nullptr); - if (uuid == getInterfaceId()) { - *output = static_cast(this); - return true; + bool queryInterface(const InterfaceId& uuid, void** const output) override { + if (output == nullptr) { + assert(false); return false; } - if (uuid == getInterfaceId()) { - *output = static_cast(this); + if (uuid == getInterfaceId()) { + *output = static_cast*>(this); return true; } - *output = nullptr; - return false; + return query(uuid, output); } NoOperationReferenceCounted() = default; @@ -40,10 +45,25 @@ namespace core::implement { NoOperationReferenceCounted& operator=(NoOperationReferenceCounted const&) = delete; NoOperationReferenceCounted& operator=(NoOperationReferenceCounted&&) = delete; + + private: + template + bool query(const InterfaceId& uuid, void** const output) { + if (uuid == getInterfaceId()) { + *output = static_cast(this); + return true; + } + if constexpr (sizeof...(Rest) > 0) { + return query(uuid, output); + } + else { + return false; + } + } }; - template - class ReferenceCounted : public T { + template + class ReferenceCounted : public Interfaces... { public: int32_t retain() override { return m_counter.fetch_add(1) + 1; @@ -55,20 +75,16 @@ namespace core::implement { } return last_counter - 1; } - bool queryInterface(InterfaceId const& uuid, void** const output) override { - assert(output != nullptr); - if (uuid == getInterfaceId()) { - retain(); - *output = static_cast(this); - return true; + bool queryInterface(const InterfaceId& uuid, void** const output) override { + if (output == nullptr) { + assert(false); return false; } - if (uuid == getInterfaceId()) { + if (uuid == getInterfaceId()) { retain(); - *output = static_cast(this); + *output = static_cast*>(this); return true; } - *output = nullptr; - return false; + return query(uuid, output); } ReferenceCounted() : m_counter{ 1 } { @@ -88,6 +104,21 @@ namespace core::implement { ReferenceCounted& operator=(ReferenceCounted&&) = delete; private: + template + bool query(const InterfaceId& uuid, void** const output) { + if (uuid == getInterfaceId()) { + retain(); + *output = static_cast(this); + return true; + } + if constexpr (sizeof...(Rest) > 0) { + return query(uuid, output); + } + else { + return false; + } + } + std::atomic_int32_t m_counter; }; } diff --git a/engine/reference-counted/test/Test.cpp b/engine/reference-counted/test/Test.cpp index ae4d7a0c..cfedaecd 100644 --- a/engine/reference-counted/test/Test.cpp +++ b/engine/reference-counted/test/Test.cpp @@ -13,11 +13,11 @@ #include "gtest/gtest.h" namespace { - struct CORE_NO_VIRTUAL_TABLE IAlpha : core::IReferenceCounted { + CORE_INTERFACE IAlpha : core::IReferenceCounted { virtual void print() = 0; }; - struct CORE_NO_VIRTUAL_TABLE IResource : core::IWeakReferenceSource { + CORE_INTERFACE IResource : core::IWeakReferenceSource { virtual void download() = 0; }; } diff --git a/engine/string/core/ImmutableString.hpp b/engine/string/core/ImmutableString.hpp index f28dde36..77c2857d 100644 --- a/engine/string/core/ImmutableString.hpp +++ b/engine/string/core/ImmutableString.hpp @@ -8,7 +8,7 @@ namespace core { // 不可变的空终止字符串 - struct CORE_NO_VIRTUAL_TABLE IImmutableString : IReferenceCounted { + CORE_INTERFACE IImmutableString : IReferenceCounted { [[nodiscard]] virtual bool empty() const noexcept = 0; [[nodiscard]] virtual char const* data() const noexcept = 0; [[nodiscard]] virtual size_t size() const noexcept = 0; diff --git a/engine/win32/CMakeLists.txt b/engine/win32/CMakeLists.txt index 01c6dd71..69aaf6f8 100644 --- a/engine/win32/CMakeLists.txt +++ b/engine/win32/CMakeLists.txt @@ -1,4 +1,4 @@ -file(GLOB_RECURSE lib_src RELATIVE ${CMAKE_CURRENT_LIST_DIR} win32/*.hpp win32/*.cpp) +file(GLOB_RECURSE lib_src RELATIVE ${CMAKE_CURRENT_LIST_DIR} win32/*.hpp win32/*.cpp windows/*.hpp windows/*.cpp) source_group(TREE ${CMAKE_CURRENT_LIST_DIR} FILES ${lib_src}) set(lib_name "win32") @@ -6,9 +6,12 @@ set(lib_name "win32") add_library(${lib_name}) luastg_target_common_options(${lib_name}) luastg_target_more_warning(${lib_name}) +if (LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE) + target_compile_definitions(${lib_name} PRIVATE LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE) +endif () target_include_directories(${lib_name} PUBLIC .) target_sources(${lib_name} PRIVATE ${lib_src}) target_link_libraries(${lib_name} PRIVATE options_compile_utf8) -#target_link_libraries(${lib_name} PUBLIC) +target_link_libraries(${lib_name} PUBLIC beautiful_win32_api) set_target_properties(${lib_name} PROPERTIES FOLDER engine) diff --git a/LuaSTG/Platform/AdapterPolicy.cpp b/engine/win32/windows/AdapterPolicy.cpp similarity index 96% rename from LuaSTG/Platform/AdapterPolicy.cpp rename to engine/win32/windows/AdapterPolicy.cpp index a551f141..0731033d 100644 --- a/LuaSTG/Platform/AdapterPolicy.cpp +++ b/engine/win32/windows/AdapterPolicy.cpp @@ -1,28 +1,28 @@ -#include "AdapterPolicy.hpp" - -using uint32 = unsigned int; - -static_assert(sizeof(uint32) == 4); - -// https://developer.download.nvidia.cn/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf -extern "C" __declspec(dllexport) uint32 NvOptimusEnablement = 0x00000000; - -// https://gpuopen.com/learn/amdpowerxpressrequesthighperformance/ -extern "C" __declspec(dllexport) uint32 AmdPowerXpressRequestHighPerformance = 0x00000000; - -namespace Platform -{ - void AdapterPolicy::setAll(bool active) - { - setNVIDIA(active); - setAMD(active); - } - void AdapterPolicy::setNVIDIA(bool active) - { - NvOptimusEnablement = active ? 0x00000001 : 0x00000000; - } - void AdapterPolicy::setAMD(bool active) - { - AmdPowerXpressRequestHighPerformance = active ? 0x00000001 : 0x00000000; - } -} +#include "AdapterPolicy.hpp" + +using uint32 = unsigned int; + +static_assert(sizeof(uint32) == 4); + +// https://developer.download.nvidia.cn/devzone/devcenter/gamegraphics/files/OptimusRenderingPolicies.pdf +extern "C" __declspec(dllexport) uint32 NvOptimusEnablement = 0x00000000; + +// https://gpuopen.com/learn/amdpowerxpressrequesthighperformance/ +extern "C" __declspec(dllexport) uint32 AmdPowerXpressRequestHighPerformance = 0x00000000; + +namespace Platform +{ + void AdapterPolicy::setAll(bool active) + { + setNVIDIA(active); + setAMD(active); + } + void AdapterPolicy::setNVIDIA(bool active) + { + NvOptimusEnablement = active ? 0x00000001 : 0x00000000; + } + void AdapterPolicy::setAMD(bool active) + { + AmdPowerXpressRequestHighPerformance = active ? 0x00000001 : 0x00000000; + } +} diff --git a/LuaSTG/Platform/AdapterPolicy.hpp b/engine/win32/windows/AdapterPolicy.hpp similarity index 93% rename from LuaSTG/Platform/AdapterPolicy.hpp rename to engine/win32/windows/AdapterPolicy.hpp index 5f9899f0..739bc793 100644 --- a/LuaSTG/Platform/AdapterPolicy.hpp +++ b/engine/win32/windows/AdapterPolicy.hpp @@ -1,12 +1,12 @@ -#pragma once - -namespace Platform -{ - class AdapterPolicy - { - public: - static void setAll(bool active); - static void setNVIDIA(bool active); - static void setAMD(bool active); - }; -} +#pragma once + +namespace Platform +{ + class AdapterPolicy + { + public: + static void setAll(bool active); + static void setNVIDIA(bool active); + static void setAMD(bool active); + }; +} diff --git a/LuaSTG/Platform/All.cpp b/engine/win32/windows/All.cpp similarity index 94% rename from LuaSTG/Platform/All.cpp rename to engine/win32/windows/All.cpp index d6eb0992..7c3329a9 100644 --- a/LuaSTG/Platform/All.cpp +++ b/engine/win32/windows/All.cpp @@ -1,398 +1,398 @@ -#include "Platform/Shared.hpp" -#include "Platform/RuntimeLoader/DXGI.hpp" -#include "Platform/RuntimeLoader/Direct3D11.hpp" - -#include "Platform/DesktopWindowManager.hpp" - -namespace Platform -{ - class ScopeRegKey - { - private: - HKEY hKey{ NULL }; - public: - HKEY Get() const noexcept { return hKey; } - HKEY* GetAddressOf() noexcept { return &hKey; } - void Close() { if (hKey) RegCloseKey(hKey); hKey = NULL; } - public: - ScopeRegKey() = default; - ~ScopeRegKey() { Close(); } - }; - - static BOOL _IsOverlayTestModeExists(DWORD option) - { - // 在 MPO 启用且支持工作的情况下,DWM 会专门分配一个 plane 来独立呈现 - // 但是 MPO 似乎因为各种问题给用户带来了困扰,NVIDIA 甚至专门给出了禁用方法 - // https://nvidia.custhelp.com/app/answers/detail/a_id/5157/~/after-updating-to-nvidia-game-ready-driver-461.09-or-newer%2C-some-desktop-apps - // 禁用 MPO 后,DirectComposition 的延迟会大大增加,因为 DWM 会始终控制合成 - // 为了处理这个特例,我们需要检测该注册表项 - - LSTATUS ls = ERROR_SUCCESS; - - ScopeRegKey hKey; - ls = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\Dwm", 0, KEY_READ | option, hKey.GetAddressOf()); - if (ERROR_SUCCESS != ls) return FALSE; - - DWORD dwValue = 0; - DWORD dwValueSize = 4; - DWORD dwType = 0; - ls = RegQueryValueExW(hKey.Get(), L"OverlayTestMode", NULL, &dwType, (BYTE*)&dwValue, &dwValueSize); - if (ERROR_SUCCESS != ls) return FALSE; - if (REG_DWORD != dwType) return FALSE; - - return 5 == dwValue; - } - - BOOL DesktopWindowManager::IsOverlayTestModeExists() - { - if (_IsOverlayTestModeExists(0x0)) - { - return TRUE; // 理论上在 64 位程序下会触发这个 - } - - if (_IsOverlayTestModeExists(KEY_WOW64_32KEY)) - { - return TRUE; // 理论上不会触发,但是以防万一,省的微软妈又死了 - } - - if (_IsOverlayTestModeExists(KEY_WOW64_64KEY)) - { - return TRUE; // 理论上在 32 位程序下会触发这个 - } - - return FALSE; - } -} - -#include "Platform/Direct3D11.hpp" - -namespace Platform -{ - HRESULT Direct3D11::GetDeviceAdater(ID3D11Device* pDevice, IDXGIAdapter1** ppAdapter) - { - assert(pDevice); - assert(ppAdapter); - - HRESULT hr = S_OK; - - Microsoft::WRL::ComPtr dxgi_device; - hr = pDevice->QueryInterface(IID_PPV_ARGS(&dxgi_device)); - if (FAILED(hr)) return hr; - - Microsoft::WRL::ComPtr dxgi_adapter; - hr = dxgi_device->GetAdapter(&dxgi_adapter); - if (FAILED(hr)) return hr; - - hr = dxgi_adapter->QueryInterface(IID_PPV_ARGS(ppAdapter)); - if (FAILED(hr)) return hr; - - return hr; - } - HRESULT Direct3D11::GetDeviceFactory(ID3D11Device* pDevice, IDXGIFactory2** ppFactory) - { - assert(pDevice); - assert(ppFactory); - - HRESULT hr = S_OK; - - Microsoft::WRL::ComPtr dxgi_adapter; - hr = GetDeviceAdater(pDevice, &dxgi_adapter); - if (FAILED(hr)) return hr; - - hr = dxgi_adapter->GetParent(IID_PPV_ARGS(ppFactory)); - if (FAILED(hr)) return hr; - - return hr; - } - BOOL Direct3D11::HasDevice(UINT Flags, D3D_FEATURE_LEVEL TargetFeatureLevel) - { - HRESULT hr = S_OK; - RuntimeLoader::DXGI dxgi; - RuntimeLoader::Direct3D11 d3d11; - Microsoft::WRL::ComPtr dxgi_factory; - hr = dxgi.CreateFactory(IID_PPV_ARGS(&dxgi_factory)); - if (FAILED(hr)) return FALSE; - Microsoft::WRL::ComPtr dxgi_adapter; - UINT count = 0; - for (UINT index = 0; SUCCEEDED(dxgi_factory->EnumAdapters1(index, &dxgi_adapter)); index += 1) - { - DXGI_ADAPTER_DESC1 dxgi_adapter_info{}; - hr = dxgi_adapter->GetDesc1(&dxgi_adapter_info); - if (FAILED(hr)) continue; - // skip software device - if (dxgi_adapter_info.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) continue; - if (dxgi_adapter_info.Flags & DXGI_ADAPTER_FLAG_REMOTE) continue; - // test feature level - hr = d3d11.CreateDeviceFromAdapter(dxgi_adapter.Get(), Flags, TargetFeatureLevel, - NULL, NULL, NULL); - if (SUCCEEDED(hr)) count += 1; - } - return count > 0 ? TRUE : FALSE; - } -} - -#include "Platform/DXGI.hpp" - -namespace Platform -{ - BOOL DXGI::CheckFeatureSupportPresentAllowTearing(IDXGIFactory* pFactory) - { - Microsoft::WRL::ComPtr dxgi_factory = pFactory; - Microsoft::WRL::ComPtr dxgi_factory5; - if (SUCCEEDED(dxgi_factory.As(&dxgi_factory5))) - { - BOOL feature_supported = FALSE; - if (SUCCEEDED(dxgi_factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &feature_supported, sizeof(feature_supported)))) - { - return feature_supported; - } - } - return FALSE; - } - HRESULT DXGI::MakeSwapChainWindowAssociation(IDXGISwapChain* pSwapChain, UINT flags) - { - assert(pSwapChain); - - HRESULT hr = S_OK; - - HWND hwnd = NULL; - Microsoft::WRL::ComPtr pSwapChain1; - hr = pSwapChain->QueryInterface(IID_PPV_ARGS(&pSwapChain1)); - if (SUCCEEDED(hr)) - { - hr = pSwapChain1->GetHwnd(&hwnd); - if (FAILED(hr)) return hr; // the swap chain might not be HWND-based - } - else - { - DXGI_SWAP_CHAIN_DESC desc = {}; - hr = pSwapChain->GetDesc(&desc); - if (FAILED(hr)) return hr; - hwnd = desc.OutputWindow; - } - - Microsoft::WRL::ComPtr pDxgiDevice; - hr = pSwapChain->GetDevice(IID_PPV_ARGS(&pDxgiDevice)); - if (FAILED(hr)) return hr; - - Microsoft::WRL::ComPtr pDxgiAdapter; - hr = pDxgiDevice->GetAdapter(&pDxgiAdapter); - if (FAILED(hr)) return hr; - - Microsoft::WRL::ComPtr pDxgiFactory; - hr = pDxgiAdapter->GetParent(IID_PPV_ARGS(&pDxgiFactory)); - if (FAILED(hr)) return hr; - - hr = pDxgiFactory->MakeWindowAssociation(hwnd, flags); - return hr; - } - HRESULT DXGI::SetSwapChainMaximumFrameLatency(IDXGISwapChain* pSwapChain, UINT MaxLatency, HANDLE* pEvent) - { - assert(pSwapChain); - assert(pEvent); - - HRESULT hr = S_OK; - - Microsoft::WRL::ComPtr dxgi_swapchain2; - hr = pSwapChain->QueryInterface(IID_PPV_ARGS(&dxgi_swapchain2)); - if (FAILED(hr)) return hr; - - hr = dxgi_swapchain2->SetMaximumFrameLatency(MaxLatency); - if (FAILED(hr)) return hr; - - HANDLE event = dxgi_swapchain2->GetFrameLatencyWaitableObject(); - assert(event); - if (!event) return E_FAIL; - - *pEvent = event; - - return hr; - } - HRESULT DXGI::SetDeviceMaximumFrameLatency(IDXGISwapChain* pSwapChain, UINT MaxLatency) - { - assert(pSwapChain); - - HRESULT hr = S_OK; - - Microsoft::WRL::ComPtr dxgi_device; - hr = pSwapChain->GetDevice(IID_PPV_ARGS(&dxgi_device)); - if (FAILED(hr)) return hr; - - hr = dxgi_device->SetMaximumFrameLatency(MaxLatency); - if (FAILED(hr)) return hr; - - return hr; - } -} - -#include "Platform/ModuleLoader.hpp" - -namespace Platform -{ - HRESULT ModuleLoader::Load(std::string_view const name, bool search_only_in_system) - { - assert(!m_module); - if (m_module) - { - FreeLibrary(m_module); - m_module = NULL; - } - DWORD const flags = search_only_in_system ? LOAD_LIBRARY_SEARCH_SYSTEM32 : 0; - m_module = LoadLibraryExW(to_wide(name).c_str(), NULL, flags); - if (!m_module) - { - return HRESULT_FROM_WIN32(GetLastError()); - } - return S_OK; - } - void* ModuleLoader::GetFunction(std::string_view const name) - { - assert(m_module); - std::array buffer{}; - std::pmr::monotonic_buffer_resource resource(buffer.data(), buffer.size()); - std::pmr::string const name_c_str(name, &resource); - return static_cast(GetProcAddress(m_module, name_c_str.c_str())); - } - - ModuleLoader::ModuleLoader() = default; - ModuleLoader::ModuleLoader(ModuleLoader&& right) noexcept - : m_module(std::exchange(right.m_module, m_module)) - { - } - ModuleLoader::~ModuleLoader() - { - if (m_module) - { - FreeLibrary(m_module); - m_module = NULL; - } - } - - bool ModuleLoader::IsSearchOnlyInSystemSupported() - { - ModuleLoader kernel32_loader; - if (FAILED(kernel32_loader.Load("kernel32.dll", true))) - { - return false; // 一般到这一步就已经知道支不支持了 - } - auto api_SetDefaultDllDirectories = kernel32_loader.GetFunction("SetDefaultDllDirectories"); - auto api_AddDllDirectory = kernel32_loader.GetFunction("AddDllDirectory"); - auto api_RemoveDllDirectory = kernel32_loader.GetFunction("RemoveDllDirectory"); - if (!api_SetDefaultDllDirectories || !api_AddDllDirectory || !api_RemoveDllDirectory) - { - return false; // 以防万一,检测这三个函数 - } - return true; - } -} - -#include "Platform/ApplicationSingleInstance.hpp" - -namespace Platform -{ - static constexpr std::string_view error_message_en_us_uuid{"UUID cannot be empty."}; - static constexpr std::string_view error_message_zh_cn_uuid{"UUID不能为空。"}; - static constexpr std::string_view error_message_en_us_convert{"Convert string encoding failed."}; - static constexpr std::string_view error_message_zh_cn_convert{"转换字符串编码失败。"}; - static constexpr std::string_view error_message_en_us_initialize{"Single instance application model has been enabled."}; - static constexpr std::string_view error_message_zh_cn_initialize{"单实例应用程序模型已被启用。"}; - static constexpr std::string_view error_message_en_us_create{"Launch single application instance failed."}; - static constexpr std::string_view error_message_zh_cn_create{"启动单实例应用程序失败。"}; - static constexpr std::string_view error_message_en_us_test{"Launch multiple application instances is not allowed, please terminate the existing instance."}; - static constexpr std::string_view error_message_zh_cn_test{"无法启动多个应用程序实例,请终止已存在的实例。"}; - - inline bool IsChineseSimplified() - { - LANGID const language_chinese_simplified = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED); - // TODO: This is a deprecated API - #pragma warning(push) - #pragma warning(disable: 6387) - LANGID const language_user_default = LANGIDFROMLCID(LocaleNameToLCID(LOCALE_NAME_USER_DEFAULT, 0)); - #pragma warning(pop) - return language_user_default == language_chinese_simplified; - } - inline std::wstring Utf8ToWide(std::string_view const str) - { - std::wstring wstr; - int const length = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), nullptr, 0); - if (length <= 0) { - return wstr; - } - wstr.resize(static_cast(length)); - int const result = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), wstr.data(), length); - if (length != result) { - wstr.clear(); - } - return wstr; - } - inline std::string_view LocalizeString(std::string_view const en_us, std::string_view const zh_cn) - { - return IsChineseSimplified() ? zh_cn : en_us; - } - - void ApplicationSingleInstance::ShowErrorWindow(std::string_view const text) - { - std::wstring wide_text(Utf8ToWide(text)); - std::wstring wide_title(Utf8ToWide(m_title)); - MessageBoxW( - nullptr, - wide_text.c_str(), - wide_title.c_str(), - MB_ICONERROR | MB_OK - ); - } - void ApplicationSingleInstance::Clear() - { - if (m_event) { - CloseHandle(m_event); - m_event = nullptr; - } - } - - void ApplicationSingleInstance::SetErrorWindowTitle(std::string_view const title) - { - m_title = title; - } - void ApplicationSingleInstance::Initialize(std::string_view const uuid) - { - if (m_event != nullptr) { - ShowErrorWindow(LocalizeString(error_message_en_us_initialize, error_message_zh_cn_initialize)); - std::exit(EXIT_FAILURE); - } - if (uuid.empty()) { - ShowErrorWindow(LocalizeString(error_message_en_us_uuid, error_message_zh_cn_uuid)); - std::exit(EXIT_FAILURE); - } - std::string name; - name.append("Local\\ApplicationInstance-"); - name.append(uuid); - std::wstring wide_name(Utf8ToWide(name)); - if (wide_name.empty()) { - // unlikely - ShowErrorWindow(LocalizeString(error_message_en_us_convert, error_message_zh_cn_convert)); - std::exit(EXIT_FAILURE); - } - SetLastError(0); - m_event = CreateEventExW(nullptr, wide_name.c_str(), 0, EVENT_ALL_ACCESS); - if (nullptr == m_event) { - ShowErrorWindow(LocalizeString(error_message_en_us_create, error_message_zh_cn_create)); - std::exit(EXIT_FAILURE); - } - if (ERROR_ALREADY_EXISTS == GetLastError()) { - Clear(); - ShowErrorWindow(LocalizeString(error_message_en_us_test, error_message_zh_cn_test)); - std::exit(EXIT_FAILURE); - } - } - - ApplicationSingleInstance::ApplicationSingleInstance() = default; - ApplicationSingleInstance::ApplicationSingleInstance(std::string_view const title) : m_title(title) {} - ApplicationSingleInstance::ApplicationSingleInstance(std::string_view const title, std::string_view const uuid) : m_title(title) - { - Initialize(uuid); - } - ApplicationSingleInstance::~ApplicationSingleInstance() - { - Clear(); - } -} +#include "Shared.hpp" +#include "RuntimeLoader/DXGI.hpp" +#include "RuntimeLoader/Direct3D11.hpp" + +#include "DesktopWindowManager.hpp" + +namespace Platform +{ + class ScopeRegKey + { + private: + HKEY hKey{ NULL }; + public: + HKEY Get() const noexcept { return hKey; } + HKEY* GetAddressOf() noexcept { return &hKey; } + void Close() { if (hKey) RegCloseKey(hKey); hKey = NULL; } + public: + ScopeRegKey() = default; + ~ScopeRegKey() { Close(); } + }; + + static BOOL _IsOverlayTestModeExists(DWORD option) + { + // 在 MPO 启用且支持工作的情况下,DWM 会专门分配一个 plane 来独立呈现 + // 但是 MPO 似乎因为各种问题给用户带来了困扰,NVIDIA 甚至专门给出了禁用方法 + // https://nvidia.custhelp.com/app/answers/detail/a_id/5157/~/after-updating-to-nvidia-game-ready-driver-461.09-or-newer%2C-some-desktop-apps + // 禁用 MPO 后,DirectComposition 的延迟会大大增加,因为 DWM 会始终控制合成 + // 为了处理这个特例,我们需要检测该注册表项 + + LSTATUS ls = ERROR_SUCCESS; + + ScopeRegKey hKey; + ls = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\Dwm", 0, KEY_READ | option, hKey.GetAddressOf()); + if (ERROR_SUCCESS != ls) return FALSE; + + DWORD dwValue = 0; + DWORD dwValueSize = 4; + DWORD dwType = 0; + ls = RegQueryValueExW(hKey.Get(), L"OverlayTestMode", NULL, &dwType, (BYTE*)&dwValue, &dwValueSize); + if (ERROR_SUCCESS != ls) return FALSE; + if (REG_DWORD != dwType) return FALSE; + + return 5 == dwValue; + } + + BOOL DesktopWindowManager::IsOverlayTestModeExists() + { + if (_IsOverlayTestModeExists(0x0)) + { + return TRUE; // 理论上在 64 位程序下会触发这个 + } + + if (_IsOverlayTestModeExists(KEY_WOW64_32KEY)) + { + return TRUE; // 理论上不会触发,但是以防万一,省的微软妈又死了 + } + + if (_IsOverlayTestModeExists(KEY_WOW64_64KEY)) + { + return TRUE; // 理论上在 32 位程序下会触发这个 + } + + return FALSE; + } +} + +#include "Direct3D11.hpp" + +namespace Platform +{ + HRESULT Direct3D11::GetDeviceAdater(ID3D11Device* pDevice, IDXGIAdapter1** ppAdapter) + { + assert(pDevice); + assert(ppAdapter); + + HRESULT hr = S_OK; + + Microsoft::WRL::ComPtr dxgi_device; + hr = pDevice->QueryInterface(IID_PPV_ARGS(&dxgi_device)); + if (FAILED(hr)) return hr; + + Microsoft::WRL::ComPtr dxgi_adapter; + hr = dxgi_device->GetAdapter(&dxgi_adapter); + if (FAILED(hr)) return hr; + + hr = dxgi_adapter->QueryInterface(IID_PPV_ARGS(ppAdapter)); + if (FAILED(hr)) return hr; + + return hr; + } + HRESULT Direct3D11::GetDeviceFactory(ID3D11Device* pDevice, IDXGIFactory2** ppFactory) + { + assert(pDevice); + assert(ppFactory); + + HRESULT hr = S_OK; + + Microsoft::WRL::ComPtr dxgi_adapter; + hr = GetDeviceAdater(pDevice, &dxgi_adapter); + if (FAILED(hr)) return hr; + + hr = dxgi_adapter->GetParent(IID_PPV_ARGS(ppFactory)); + if (FAILED(hr)) return hr; + + return hr; + } + BOOL Direct3D11::HasDevice(UINT Flags, D3D_FEATURE_LEVEL TargetFeatureLevel) + { + HRESULT hr = S_OK; + RuntimeLoader::DXGI dxgi; + RuntimeLoader::Direct3D11 d3d11; + Microsoft::WRL::ComPtr dxgi_factory; + hr = dxgi.CreateFactory(IID_PPV_ARGS(&dxgi_factory)); + if (FAILED(hr)) return FALSE; + Microsoft::WRL::ComPtr dxgi_adapter; + UINT count = 0; + for (UINT index = 0; SUCCEEDED(dxgi_factory->EnumAdapters1(index, &dxgi_adapter)); index += 1) + { + DXGI_ADAPTER_DESC1 dxgi_adapter_info{}; + hr = dxgi_adapter->GetDesc1(&dxgi_adapter_info); + if (FAILED(hr)) continue; + // skip software device + if (dxgi_adapter_info.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) continue; + if (dxgi_adapter_info.Flags & DXGI_ADAPTER_FLAG_REMOTE) continue; + // test feature level + hr = d3d11.CreateDeviceFromAdapter(dxgi_adapter.Get(), Flags, TargetFeatureLevel, + NULL, NULL, NULL); + if (SUCCEEDED(hr)) count += 1; + } + return count > 0 ? TRUE : FALSE; + } +} + +#include "DXGI.hpp" + +namespace Platform +{ + BOOL DXGI::CheckFeatureSupportPresentAllowTearing(IDXGIFactory* pFactory) + { + Microsoft::WRL::ComPtr dxgi_factory = pFactory; + Microsoft::WRL::ComPtr dxgi_factory5; + if (SUCCEEDED(dxgi_factory.As(&dxgi_factory5))) + { + BOOL feature_supported = FALSE; + if (SUCCEEDED(dxgi_factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &feature_supported, sizeof(feature_supported)))) + { + return feature_supported; + } + } + return FALSE; + } + HRESULT DXGI::MakeSwapChainWindowAssociation(IDXGISwapChain* pSwapChain, UINT flags) + { + assert(pSwapChain); + + HRESULT hr = S_OK; + + HWND hwnd = NULL; + Microsoft::WRL::ComPtr pSwapChain1; + hr = pSwapChain->QueryInterface(IID_PPV_ARGS(&pSwapChain1)); + if (SUCCEEDED(hr)) + { + hr = pSwapChain1->GetHwnd(&hwnd); + if (FAILED(hr)) return hr; // the swap chain might not be HWND-based + } + else + { + DXGI_SWAP_CHAIN_DESC desc = {}; + hr = pSwapChain->GetDesc(&desc); + if (FAILED(hr)) return hr; + hwnd = desc.OutputWindow; + } + + Microsoft::WRL::ComPtr pDxgiDevice; + hr = pSwapChain->GetDevice(IID_PPV_ARGS(&pDxgiDevice)); + if (FAILED(hr)) return hr; + + Microsoft::WRL::ComPtr pDxgiAdapter; + hr = pDxgiDevice->GetAdapter(&pDxgiAdapter); + if (FAILED(hr)) return hr; + + Microsoft::WRL::ComPtr pDxgiFactory; + hr = pDxgiAdapter->GetParent(IID_PPV_ARGS(&pDxgiFactory)); + if (FAILED(hr)) return hr; + + hr = pDxgiFactory->MakeWindowAssociation(hwnd, flags); + return hr; + } + HRESULT DXGI::SetSwapChainMaximumFrameLatency(IDXGISwapChain* pSwapChain, UINT MaxLatency, HANDLE* pEvent) + { + assert(pSwapChain); + assert(pEvent); + + HRESULT hr = S_OK; + + Microsoft::WRL::ComPtr dxgi_swapchain2; + hr = pSwapChain->QueryInterface(IID_PPV_ARGS(&dxgi_swapchain2)); + if (FAILED(hr)) return hr; + + hr = dxgi_swapchain2->SetMaximumFrameLatency(MaxLatency); + if (FAILED(hr)) return hr; + + HANDLE event = dxgi_swapchain2->GetFrameLatencyWaitableObject(); + assert(event); + if (!event) return E_FAIL; + + *pEvent = event; + + return hr; + } + HRESULT DXGI::SetDeviceMaximumFrameLatency(IDXGISwapChain* pSwapChain, UINT MaxLatency) + { + assert(pSwapChain); + + HRESULT hr = S_OK; + + Microsoft::WRL::ComPtr dxgi_device; + hr = pSwapChain->GetDevice(IID_PPV_ARGS(&dxgi_device)); + if (FAILED(hr)) return hr; + + hr = dxgi_device->SetMaximumFrameLatency(MaxLatency); + if (FAILED(hr)) return hr; + + return hr; + } +} + +#include "ModuleLoader.hpp" + +namespace Platform +{ + HRESULT ModuleLoader::Load(std::string_view const name, bool search_only_in_system) + { + assert(!m_module); + if (m_module) + { + FreeLibrary(m_module); + m_module = NULL; + } + DWORD const flags = search_only_in_system ? LOAD_LIBRARY_SEARCH_SYSTEM32 : 0; + m_module = LoadLibraryExW(to_wide(name).c_str(), NULL, flags); + if (!m_module) + { + return HRESULT_FROM_WIN32(GetLastError()); + } + return S_OK; + } + void* ModuleLoader::GetFunction(std::string_view const name) + { + assert(m_module); + std::array buffer{}; + std::pmr::monotonic_buffer_resource resource(buffer.data(), buffer.size()); + std::pmr::string const name_c_str(name, &resource); + return static_cast(GetProcAddress(m_module, name_c_str.c_str())); + } + + ModuleLoader::ModuleLoader() = default; + ModuleLoader::ModuleLoader(ModuleLoader&& right) noexcept + : m_module(std::exchange(right.m_module, m_module)) + { + } + ModuleLoader::~ModuleLoader() + { + if (m_module) + { + FreeLibrary(m_module); + m_module = NULL; + } + } + + bool ModuleLoader::IsSearchOnlyInSystemSupported() + { + ModuleLoader kernel32_loader; + if (FAILED(kernel32_loader.Load("kernel32.dll", true))) + { + return false; // 一般到这一步就已经知道支不支持了 + } + auto api_SetDefaultDllDirectories = kernel32_loader.GetFunction("SetDefaultDllDirectories"); + auto api_AddDllDirectory = kernel32_loader.GetFunction("AddDllDirectory"); + auto api_RemoveDllDirectory = kernel32_loader.GetFunction("RemoveDllDirectory"); + if (!api_SetDefaultDllDirectories || !api_AddDllDirectory || !api_RemoveDllDirectory) + { + return false; // 以防万一,检测这三个函数 + } + return true; + } +} + +#include "ApplicationSingleInstance.hpp" + +namespace Platform +{ + static constexpr std::string_view error_message_en_us_uuid{"UUID cannot be empty."}; + static constexpr std::string_view error_message_zh_cn_uuid{"UUID不能为空。"}; + static constexpr std::string_view error_message_en_us_convert{"Convert string encoding failed."}; + static constexpr std::string_view error_message_zh_cn_convert{"转换字符串编码失败。"}; + static constexpr std::string_view error_message_en_us_initialize{"Single instance application model has been enabled."}; + static constexpr std::string_view error_message_zh_cn_initialize{"单实例应用程序模型已被启用。"}; + static constexpr std::string_view error_message_en_us_create{"Launch single application instance failed."}; + static constexpr std::string_view error_message_zh_cn_create{"启动单实例应用程序失败。"}; + static constexpr std::string_view error_message_en_us_test{"Launch multiple application instances is not allowed, please terminate the existing instance."}; + static constexpr std::string_view error_message_zh_cn_test{"无法启动多个应用程序实例,请终止已存在的实例。"}; + + inline bool IsChineseSimplified() + { + LANGID const language_chinese_simplified = MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED); + // TODO: This is a deprecated API + #pragma warning(push) + #pragma warning(disable: 6387) + LANGID const language_user_default = LANGIDFROMLCID(LocaleNameToLCID(LOCALE_NAME_USER_DEFAULT, 0)); + #pragma warning(pop) + return language_user_default == language_chinese_simplified; + } + inline std::wstring Utf8ToWide(std::string_view const str) + { + std::wstring wstr; + int const length = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), nullptr, 0); + if (length <= 0) { + return wstr; + } + wstr.resize(static_cast(length)); + int const result = MultiByteToWideChar(CP_UTF8, 0, str.data(), static_cast(str.size()), wstr.data(), length); + if (length != result) { + wstr.clear(); + } + return wstr; + } + inline std::string_view LocalizeString(std::string_view const en_us, std::string_view const zh_cn) + { + return IsChineseSimplified() ? zh_cn : en_us; + } + + void ApplicationSingleInstance::ShowErrorWindow(std::string_view const text) + { + std::wstring wide_text(Utf8ToWide(text)); + std::wstring wide_title(Utf8ToWide(m_title)); + MessageBoxW( + nullptr, + wide_text.c_str(), + wide_title.c_str(), + MB_ICONERROR | MB_OK + ); + } + void ApplicationSingleInstance::Clear() + { + if (m_event) { + CloseHandle(m_event); + m_event = nullptr; + } + } + + void ApplicationSingleInstance::SetErrorWindowTitle(std::string_view const title) + { + m_title = title; + } + void ApplicationSingleInstance::Initialize(std::string_view const uuid) + { + if (m_event != nullptr) { + ShowErrorWindow(LocalizeString(error_message_en_us_initialize, error_message_zh_cn_initialize)); + std::exit(EXIT_FAILURE); + } + if (uuid.empty()) { + ShowErrorWindow(LocalizeString(error_message_en_us_uuid, error_message_zh_cn_uuid)); + std::exit(EXIT_FAILURE); + } + std::string name; + name.append("Local\\ApplicationInstance-"); + name.append(uuid); + std::wstring wide_name(Utf8ToWide(name)); + if (wide_name.empty()) { + // unlikely + ShowErrorWindow(LocalizeString(error_message_en_us_convert, error_message_zh_cn_convert)); + std::exit(EXIT_FAILURE); + } + SetLastError(0); + m_event = CreateEventExW(nullptr, wide_name.c_str(), 0, EVENT_ALL_ACCESS); + if (nullptr == m_event) { + ShowErrorWindow(LocalizeString(error_message_en_us_create, error_message_zh_cn_create)); + std::exit(EXIT_FAILURE); + } + if (ERROR_ALREADY_EXISTS == GetLastError()) { + Clear(); + ShowErrorWindow(LocalizeString(error_message_en_us_test, error_message_zh_cn_test)); + std::exit(EXIT_FAILURE); + } + } + + ApplicationSingleInstance::ApplicationSingleInstance() = default; + ApplicationSingleInstance::ApplicationSingleInstance(std::string_view const title) : m_title(title) {} + ApplicationSingleInstance::ApplicationSingleInstance(std::string_view const title, std::string_view const uuid) : m_title(title) + { + Initialize(uuid); + } + ApplicationSingleInstance::~ApplicationSingleInstance() + { + Clear(); + } +} diff --git a/LuaSTG/Platform/ApplicationSingleInstance.hpp b/engine/win32/windows/ApplicationSingleInstance.hpp similarity index 100% rename from LuaSTG/Platform/ApplicationSingleInstance.hpp rename to engine/win32/windows/ApplicationSingleInstance.hpp diff --git a/LuaSTG/Platform/CleanWindows.hpp b/engine/win32/windows/CleanWindows.hpp similarity index 92% rename from LuaSTG/Platform/CleanWindows.hpp rename to engine/win32/windows/CleanWindows.hpp index dfb42a4c..44bbeb29 100644 --- a/LuaSTG/Platform/CleanWindows.hpp +++ b/engine/win32/windows/CleanWindows.hpp @@ -1,33 +1,33 @@ -#pragma once - -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#define NOSERVICE -#define NOMCX -#define NOIME - -#include - -// Now, let's FUCK Windows.h - -#ifdef DrawText -#undef DrawText -#endif - -#ifdef CreateWindow -#undef CreateWindow -#endif - -#ifdef DefWindowProc -#undef DefWindowProc -#endif - -#ifdef MessageBox -#undef MessageBox -#endif - -#undef WIN32_LEAN_AND_MEAN -#undef NOMINMAX -#undef NOSERVICE -#undef NOMCX -#undef NOIME +#pragma once + +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#define NOSERVICE +#define NOMCX +#define NOIME + +#include + +// Now, let's FUCK Windows.h + +#ifdef DrawText +#undef DrawText +#endif + +#ifdef CreateWindow +#undef CreateWindow +#endif + +#ifdef DefWindowProc +#undef DefWindowProc +#endif + +#ifdef MessageBox +#undef MessageBox +#endif + +#undef WIN32_LEAN_AND_MEAN +#undef NOMINMAX +#undef NOSERVICE +#undef NOMCX +#undef NOIME diff --git a/LuaSTG/Platform/DXGI.hpp b/engine/win32/windows/DXGI.hpp similarity index 97% rename from LuaSTG/Platform/DXGI.hpp rename to engine/win32/windows/DXGI.hpp index 94ed4bc7..d230e735 100644 --- a/LuaSTG/Platform/DXGI.hpp +++ b/engine/win32/windows/DXGI.hpp @@ -1,13 +1,13 @@ -#pragma once - -namespace Platform -{ - class DXGI - { - public: - static BOOL CheckFeatureSupportPresentAllowTearing(IDXGIFactory* pFactory); - static HRESULT MakeSwapChainWindowAssociation(IDXGISwapChain* pSwapChain, UINT flags); - static HRESULT SetSwapChainMaximumFrameLatency(IDXGISwapChain* pSwapChain, UINT MaxLatency, HANDLE* pEvent); - static HRESULT SetDeviceMaximumFrameLatency(IDXGISwapChain* pSwapChain, UINT MaxLatency); - }; -} +#pragma once + +namespace Platform +{ + class DXGI + { + public: + static BOOL CheckFeatureSupportPresentAllowTearing(IDXGIFactory* pFactory); + static HRESULT MakeSwapChainWindowAssociation(IDXGISwapChain* pSwapChain, UINT flags); + static HRESULT SetSwapChainMaximumFrameLatency(IDXGISwapChain* pSwapChain, UINT MaxLatency, HANDLE* pEvent); + static HRESULT SetDeviceMaximumFrameLatency(IDXGISwapChain* pSwapChain, UINT MaxLatency); + }; +} diff --git a/LuaSTG/Platform/DesktopWindowManager.hpp b/engine/win32/windows/DesktopWindowManager.hpp similarity index 93% rename from LuaSTG/Platform/DesktopWindowManager.hpp rename to engine/win32/windows/DesktopWindowManager.hpp index 70409440..758c2cc2 100644 --- a/LuaSTG/Platform/DesktopWindowManager.hpp +++ b/engine/win32/windows/DesktopWindowManager.hpp @@ -1,10 +1,10 @@ -#pragma once - -namespace Platform -{ - class DesktopWindowManager - { - public: - static BOOL IsOverlayTestModeExists(); - }; -} +#pragma once + +namespace Platform +{ + class DesktopWindowManager + { + public: + static BOOL IsOverlayTestModeExists(); + }; +} diff --git a/LuaSTG/Platform/DetectCPU.cpp b/engine/win32/windows/DetectCPU.cpp.bak similarity index 97% rename from LuaSTG/Platform/DetectCPU.cpp rename to engine/win32/windows/DetectCPU.cpp.bak index 92713b68..d2469d7a 100644 --- a/LuaSTG/Platform/DetectCPU.cpp +++ b/engine/win32/windows/DetectCPU.cpp.bak @@ -1,163 +1,163 @@ -#include "DetectCPU.hpp" -#include - -InstructionSet::InstructionSet_Internal::InstructionSet_Internal() - : nIds_{ 0 } - , nExIds_{ 0 } - , isIntel_{ false } - , isAMD_{ false } - , f_1_ECX_{ 0 } - , f_1_EDX_{ 0 } - , f_7_EBX_{ 0 } - , f_7_ECX_{ 0 } - , f_81_ECX_{ 0 } - , f_81_EDX_{ 0 } - , data_{} - , extdata_{} -{ - //int cpuInfo[4] = {-1}; - std::array cpui; - - // Calling __cpuid with 0x0 as the function_id argument - // gets the number of the highest valid function ID. - __cpuid(cpui.data(), 0); - nIds_ = cpui[0]; - - for (int i = 0; i <= nIds_; ++i) - { - __cpuidex(cpui.data(), i, 0); - data_.push_back(cpui); - } - - // Capture vendor string - char vendor[0x20]; - memset(vendor, 0, sizeof(vendor)); - *reinterpret_cast(vendor) = data_[0][1]; - *reinterpret_cast(vendor + 4) = data_[0][3]; - *reinterpret_cast(vendor + 8) = data_[0][2]; - vendor_ = vendor; - if (vendor_ == "GenuineIntel") - { - isIntel_ = true; - } - else if (vendor_ == "AuthenticAMD") - { - isAMD_ = true; - } - - // load bitset with flags for function 0x00000001 - if (nIds_ >= 1) - { - f_1_ECX_ = data_[1][2]; - f_1_EDX_ = data_[1][3]; - } - - // load bitset with flags for function 0x00000007 - if (nIds_ >= 7) - { - f_7_EBX_ = data_[7][1]; - f_7_ECX_ = data_[7][2]; - } - - // Calling __cpuid with 0x80000000 as the function_id argument - // gets the number of the highest valid extended ID. - __cpuid(cpui.data(), 0x80000000); - nExIds_ = cpui[0]; - - char brand[0x40]; - memset(brand, 0, sizeof(brand)); - - for (int i = 0x80000000; i <= nExIds_; ++i) - { - __cpuidex(cpui.data(), i, 0); - extdata_.push_back(cpui); - } - - // load bitset with flags for function 0x80000001 - if (nExIds_ >= 0x80000001) - { - f_81_ECX_ = extdata_[1][2]; - f_81_EDX_ = extdata_[1][3]; - } - - // Interpret CPU brand string if reported - if (nExIds_ >= 0x80000004) - { - memcpy(brand, extdata_[2].data(), sizeof(cpui)); - memcpy(brand + 16, extdata_[3].data(), sizeof(cpui)); - memcpy(brand + 32, extdata_[4].data(), sizeof(cpui)); - brand_ = brand; - } -}; - -// Initialize static member data -const InstructionSet::InstructionSet_Internal InstructionSet::CPU_Rep; - -/* -#include - -// Print out supported instruction set extensions -int main() -{ - auto& outstream = std::cout; - - auto support_message = [&outstream](std::string isa_feature, bool is_supported) { - outstream << isa_feature << (is_supported ? " supported" : " not supported") << std::endl; - }; - - std::cout << InstructionSet::Vendor() << std::endl; - std::cout << InstructionSet::Brand() << std::endl; - - support_message("3DNOW", InstructionSet::_3DNOW()); - support_message("3DNOWEXT", InstructionSet::_3DNOWEXT()); - support_message("ABM", InstructionSet::ABM()); - support_message("ADX", InstructionSet::ADX()); - support_message("AES", InstructionSet::AES()); - support_message("AVX", InstructionSet::AVX()); - support_message("AVX2", InstructionSet::AVX2()); - support_message("AVX512CD", InstructionSet::AVX512CD()); - support_message("AVX512ER", InstructionSet::AVX512ER()); - support_message("AVX512F", InstructionSet::AVX512F()); - support_message("AVX512PF", InstructionSet::AVX512PF()); - support_message("BMI1", InstructionSet::BMI1()); - support_message("BMI2", InstructionSet::BMI2()); - support_message("CLFSH", InstructionSet::CLFSH()); - support_message("CMPXCHG16B", InstructionSet::CMPXCHG16B()); - support_message("CX8", InstructionSet::CX8()); - support_message("ERMS", InstructionSet::ERMS()); - support_message("F16C", InstructionSet::F16C()); - support_message("FMA", InstructionSet::FMA()); - support_message("FSGSBASE", InstructionSet::FSGSBASE()); - support_message("FXSR", InstructionSet::FXSR()); - support_message("HLE", InstructionSet::HLE()); - support_message("INVPCID", InstructionSet::INVPCID()); - support_message("LAHF", InstructionSet::LAHF()); - support_message("LZCNT", InstructionSet::LZCNT()); - support_message("MMX", InstructionSet::MMX()); - support_message("MMXEXT", InstructionSet::MMXEXT()); - support_message("MONITOR", InstructionSet::MONITOR()); - support_message("MOVBE", InstructionSet::MOVBE()); - support_message("MSR", InstructionSet::MSR()); - support_message("OSXSAVE", InstructionSet::OSXSAVE()); - support_message("PCLMULQDQ", InstructionSet::PCLMULQDQ()); - support_message("POPCNT", InstructionSet::POPCNT()); - support_message("PREFETCHWT1", InstructionSet::PREFETCHWT1()); - support_message("RDRAND", InstructionSet::RDRAND()); - support_message("RDSEED", InstructionSet::RDSEED()); - support_message("RDTSCP", InstructionSet::RDTSCP()); - support_message("RTM", InstructionSet::RTM()); - support_message("SEP", InstructionSet::SEP()); - support_message("SHA", InstructionSet::SHA()); - support_message("SSE", InstructionSet::SSE()); - support_message("SSE2", InstructionSet::SSE2()); - support_message("SSE3", InstructionSet::SSE3()); - support_message("SSE4.1", InstructionSet::SSE41()); - support_message("SSE4.2", InstructionSet::SSE42()); - support_message("SSE4a", InstructionSet::SSE4a()); - support_message("SSSE3", InstructionSet::SSSE3()); - support_message("SYSCALL", InstructionSet::SYSCALL()); - support_message("TBM", InstructionSet::TBM()); - support_message("XOP", InstructionSet::XOP()); - support_message("XSAVE", InstructionSet::XSAVE()); -} -//*/ +#include "DetectCPU.hpp" +#include + +InstructionSet::InstructionSet_Internal::InstructionSet_Internal() + : nIds_{ 0 } + , nExIds_{ 0 } + , isIntel_{ false } + , isAMD_{ false } + , f_1_ECX_{ 0 } + , f_1_EDX_{ 0 } + , f_7_EBX_{ 0 } + , f_7_ECX_{ 0 } + , f_81_ECX_{ 0 } + , f_81_EDX_{ 0 } + , data_{} + , extdata_{} +{ + //int cpuInfo[4] = {-1}; + std::array cpui; + + // Calling __cpuid with 0x0 as the function_id argument + // gets the number of the highest valid function ID. + __cpuid(cpui.data(), 0); + nIds_ = cpui[0]; + + for (int i = 0; i <= nIds_; ++i) + { + __cpuidex(cpui.data(), i, 0); + data_.push_back(cpui); + } + + // Capture vendor string + char vendor[0x20]; + memset(vendor, 0, sizeof(vendor)); + *reinterpret_cast(vendor) = data_[0][1]; + *reinterpret_cast(vendor + 4) = data_[0][3]; + *reinterpret_cast(vendor + 8) = data_[0][2]; + vendor_ = vendor; + if (vendor_ == "GenuineIntel") + { + isIntel_ = true; + } + else if (vendor_ == "AuthenticAMD") + { + isAMD_ = true; + } + + // load bitset with flags for function 0x00000001 + if (nIds_ >= 1) + { + f_1_ECX_ = data_[1][2]; + f_1_EDX_ = data_[1][3]; + } + + // load bitset with flags for function 0x00000007 + if (nIds_ >= 7) + { + f_7_EBX_ = data_[7][1]; + f_7_ECX_ = data_[7][2]; + } + + // Calling __cpuid with 0x80000000 as the function_id argument + // gets the number of the highest valid extended ID. + __cpuid(cpui.data(), 0x80000000); + nExIds_ = cpui[0]; + + char brand[0x40]; + memset(brand, 0, sizeof(brand)); + + for (int i = 0x80000000; i <= nExIds_; ++i) + { + __cpuidex(cpui.data(), i, 0); + extdata_.push_back(cpui); + } + + // load bitset with flags for function 0x80000001 + if (nExIds_ >= 0x80000001) + { + f_81_ECX_ = extdata_[1][2]; + f_81_EDX_ = extdata_[1][3]; + } + + // Interpret CPU brand string if reported + if (nExIds_ >= 0x80000004) + { + memcpy(brand, extdata_[2].data(), sizeof(cpui)); + memcpy(brand + 16, extdata_[3].data(), sizeof(cpui)); + memcpy(brand + 32, extdata_[4].data(), sizeof(cpui)); + brand_ = brand; + } +}; + +// Initialize static member data +const InstructionSet::InstructionSet_Internal InstructionSet::CPU_Rep; + +/* +#include + +// Print out supported instruction set extensions +int main() +{ + auto& outstream = std::cout; + + auto support_message = [&outstream](std::string isa_feature, bool is_supported) { + outstream << isa_feature << (is_supported ? " supported" : " not supported") << std::endl; + }; + + std::cout << InstructionSet::Vendor() << std::endl; + std::cout << InstructionSet::Brand() << std::endl; + + support_message("3DNOW", InstructionSet::_3DNOW()); + support_message("3DNOWEXT", InstructionSet::_3DNOWEXT()); + support_message("ABM", InstructionSet::ABM()); + support_message("ADX", InstructionSet::ADX()); + support_message("AES", InstructionSet::AES()); + support_message("AVX", InstructionSet::AVX()); + support_message("AVX2", InstructionSet::AVX2()); + support_message("AVX512CD", InstructionSet::AVX512CD()); + support_message("AVX512ER", InstructionSet::AVX512ER()); + support_message("AVX512F", InstructionSet::AVX512F()); + support_message("AVX512PF", InstructionSet::AVX512PF()); + support_message("BMI1", InstructionSet::BMI1()); + support_message("BMI2", InstructionSet::BMI2()); + support_message("CLFSH", InstructionSet::CLFSH()); + support_message("CMPXCHG16B", InstructionSet::CMPXCHG16B()); + support_message("CX8", InstructionSet::CX8()); + support_message("ERMS", InstructionSet::ERMS()); + support_message("F16C", InstructionSet::F16C()); + support_message("FMA", InstructionSet::FMA()); + support_message("FSGSBASE", InstructionSet::FSGSBASE()); + support_message("FXSR", InstructionSet::FXSR()); + support_message("HLE", InstructionSet::HLE()); + support_message("INVPCID", InstructionSet::INVPCID()); + support_message("LAHF", InstructionSet::LAHF()); + support_message("LZCNT", InstructionSet::LZCNT()); + support_message("MMX", InstructionSet::MMX()); + support_message("MMXEXT", InstructionSet::MMXEXT()); + support_message("MONITOR", InstructionSet::MONITOR()); + support_message("MOVBE", InstructionSet::MOVBE()); + support_message("MSR", InstructionSet::MSR()); + support_message("OSXSAVE", InstructionSet::OSXSAVE()); + support_message("PCLMULQDQ", InstructionSet::PCLMULQDQ()); + support_message("POPCNT", InstructionSet::POPCNT()); + support_message("PREFETCHWT1", InstructionSet::PREFETCHWT1()); + support_message("RDRAND", InstructionSet::RDRAND()); + support_message("RDSEED", InstructionSet::RDSEED()); + support_message("RDTSCP", InstructionSet::RDTSCP()); + support_message("RTM", InstructionSet::RTM()); + support_message("SEP", InstructionSet::SEP()); + support_message("SHA", InstructionSet::SHA()); + support_message("SSE", InstructionSet::SSE()); + support_message("SSE2", InstructionSet::SSE2()); + support_message("SSE3", InstructionSet::SSE3()); + support_message("SSE4.1", InstructionSet::SSE41()); + support_message("SSE4.2", InstructionSet::SSE42()); + support_message("SSE4a", InstructionSet::SSE4a()); + support_message("SSSE3", InstructionSet::SSSE3()); + support_message("SYSCALL", InstructionSet::SYSCALL()); + support_message("TBM", InstructionSet::TBM()); + support_message("XOP", InstructionSet::XOP()); + support_message("XSAVE", InstructionSet::XSAVE()); +} +//*/ diff --git a/LuaSTG/Platform/DetectCPU.hpp b/engine/win32/windows/DetectCPU.hpp.bak similarity index 97% rename from LuaSTG/Platform/DetectCPU.hpp rename to engine/win32/windows/DetectCPU.hpp.bak index 7594de20..6303ea00 100644 --- a/LuaSTG/Platform/DetectCPU.hpp +++ b/engine/win32/windows/DetectCPU.hpp.bak @@ -1,104 +1,104 @@ -#pragma once - -// 谢谢你,微软:https://docs.microsoft.com/zh-cn/cpp/intrinsics/cpuid-cpuidex?view=msvc-170 - -// InstructionSet.cpp -// Compile by using: cl /EHsc /W4 InstructionSet.cpp -// processor: x86, x64 -// Uses the __cpuid intrinsic to get information about -// CPU extended instruction set support. - -#include -#include -#include -#include - -class InstructionSet -{ -private: - class InstructionSet_Internal - { - public: - InstructionSet_Internal(); - - int nIds_{ 0 }; - int nExIds_{ 0 }; - std::string vendor_; - std::string brand_; - bool isIntel_{ false }; - bool isAMD_{ false }; - std::bitset<32> f_1_ECX_{}; - std::bitset<32> f_1_EDX_{}; - std::bitset<32> f_7_EBX_{}; - std::bitset<32> f_7_ECX_{}; - std::bitset<32> f_81_ECX_{}; - std::bitset<32> f_81_EDX_{}; - std::vector> data_{}; - std::vector> extdata_{}; - }; - - static const InstructionSet_Internal CPU_Rep; - -public: - // getters - static std::string Vendor(void) { return CPU_Rep.vendor_; } - static std::string Brand(void) { return CPU_Rep.brand_; } - - static bool SSE3(void) { return CPU_Rep.f_1_ECX_[0]; } - static bool PCLMULQDQ(void) { return CPU_Rep.f_1_ECX_[1]; } - static bool MONITOR(void) { return CPU_Rep.f_1_ECX_[3]; } - static bool SSSE3(void) { return CPU_Rep.f_1_ECX_[9]; } - static bool FMA(void) { return CPU_Rep.f_1_ECX_[12]; } - static bool CMPXCHG16B(void) { return CPU_Rep.f_1_ECX_[13]; } - static bool SSE41(void) { return CPU_Rep.f_1_ECX_[19]; } - static bool SSE42(void) { return CPU_Rep.f_1_ECX_[20]; } - static bool MOVBE(void) { return CPU_Rep.f_1_ECX_[22]; } - static bool POPCNT(void) { return CPU_Rep.f_1_ECX_[23]; } - static bool AES(void) { return CPU_Rep.f_1_ECX_[25]; } - static bool XSAVE(void) { return CPU_Rep.f_1_ECX_[26]; } - static bool OSXSAVE(void) { return CPU_Rep.f_1_ECX_[27]; } - static bool AVX(void) { return CPU_Rep.f_1_ECX_[28]; } - static bool F16C(void) { return CPU_Rep.f_1_ECX_[29]; } - static bool RDRAND(void) { return CPU_Rep.f_1_ECX_[30]; } - - static bool MSR(void) { return CPU_Rep.f_1_EDX_[5]; } - static bool CX8(void) { return CPU_Rep.f_1_EDX_[8]; } - static bool SEP(void) { return CPU_Rep.f_1_EDX_[11]; } - static bool CMOV(void) { return CPU_Rep.f_1_EDX_[15]; } - static bool CLFSH(void) { return CPU_Rep.f_1_EDX_[19]; } - static bool MMX(void) { return CPU_Rep.f_1_EDX_[23]; } - static bool FXSR(void) { return CPU_Rep.f_1_EDX_[24]; } - static bool SSE(void) { return CPU_Rep.f_1_EDX_[25]; } - static bool SSE2(void) { return CPU_Rep.f_1_EDX_[26]; } - - static bool FSGSBASE(void) { return CPU_Rep.f_7_EBX_[0]; } - static bool BMI1(void) { return CPU_Rep.f_7_EBX_[3]; } - static bool HLE(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_7_EBX_[4]; } - static bool AVX2(void) { return CPU_Rep.f_7_EBX_[5]; } - static bool BMI2(void) { return CPU_Rep.f_7_EBX_[8]; } - static bool ERMS(void) { return CPU_Rep.f_7_EBX_[9]; } - static bool INVPCID(void) { return CPU_Rep.f_7_EBX_[10]; } - static bool RTM(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_7_EBX_[11]; } - static bool AVX512F(void) { return CPU_Rep.f_7_EBX_[16]; } - static bool RDSEED(void) { return CPU_Rep.f_7_EBX_[18]; } - static bool ADX(void) { return CPU_Rep.f_7_EBX_[19]; } - static bool AVX512PF(void) { return CPU_Rep.f_7_EBX_[26]; } - static bool AVX512ER(void) { return CPU_Rep.f_7_EBX_[27]; } - static bool AVX512CD(void) { return CPU_Rep.f_7_EBX_[28]; } - static bool SHA(void) { return CPU_Rep.f_7_EBX_[29]; } - - static bool PREFETCHWT1(void) { return CPU_Rep.f_7_ECX_[0]; } - - static bool LAHF(void) { return CPU_Rep.f_81_ECX_[0]; } - static bool LZCNT(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_81_ECX_[5]; } - static bool ABM(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[5]; } - static bool SSE4a(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[6]; } - static bool XOP(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[11]; } - static bool TBM(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[21]; } - - static bool SYSCALL(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_81_EDX_[11]; } - static bool MMXEXT(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[22]; } - static bool RDTSCP(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_81_EDX_[27]; } - static bool _3DNOWEXT(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[30]; } - static bool _3DNOW(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[31]; } -}; +#pragma once + +// 谢谢你,微软:https://docs.microsoft.com/zh-cn/cpp/intrinsics/cpuid-cpuidex?view=msvc-170 + +// InstructionSet.cpp +// Compile by using: cl /EHsc /W4 InstructionSet.cpp +// processor: x86, x64 +// Uses the __cpuid intrinsic to get information about +// CPU extended instruction set support. + +#include +#include +#include +#include + +class InstructionSet +{ +private: + class InstructionSet_Internal + { + public: + InstructionSet_Internal(); + + int nIds_{ 0 }; + int nExIds_{ 0 }; + std::string vendor_; + std::string brand_; + bool isIntel_{ false }; + bool isAMD_{ false }; + std::bitset<32> f_1_ECX_{}; + std::bitset<32> f_1_EDX_{}; + std::bitset<32> f_7_EBX_{}; + std::bitset<32> f_7_ECX_{}; + std::bitset<32> f_81_ECX_{}; + std::bitset<32> f_81_EDX_{}; + std::vector> data_{}; + std::vector> extdata_{}; + }; + + static const InstructionSet_Internal CPU_Rep; + +public: + // getters + static std::string Vendor(void) { return CPU_Rep.vendor_; } + static std::string Brand(void) { return CPU_Rep.brand_; } + + static bool SSE3(void) { return CPU_Rep.f_1_ECX_[0]; } + static bool PCLMULQDQ(void) { return CPU_Rep.f_1_ECX_[1]; } + static bool MONITOR(void) { return CPU_Rep.f_1_ECX_[3]; } + static bool SSSE3(void) { return CPU_Rep.f_1_ECX_[9]; } + static bool FMA(void) { return CPU_Rep.f_1_ECX_[12]; } + static bool CMPXCHG16B(void) { return CPU_Rep.f_1_ECX_[13]; } + static bool SSE41(void) { return CPU_Rep.f_1_ECX_[19]; } + static bool SSE42(void) { return CPU_Rep.f_1_ECX_[20]; } + static bool MOVBE(void) { return CPU_Rep.f_1_ECX_[22]; } + static bool POPCNT(void) { return CPU_Rep.f_1_ECX_[23]; } + static bool AES(void) { return CPU_Rep.f_1_ECX_[25]; } + static bool XSAVE(void) { return CPU_Rep.f_1_ECX_[26]; } + static bool OSXSAVE(void) { return CPU_Rep.f_1_ECX_[27]; } + static bool AVX(void) { return CPU_Rep.f_1_ECX_[28]; } + static bool F16C(void) { return CPU_Rep.f_1_ECX_[29]; } + static bool RDRAND(void) { return CPU_Rep.f_1_ECX_[30]; } + + static bool MSR(void) { return CPU_Rep.f_1_EDX_[5]; } + static bool CX8(void) { return CPU_Rep.f_1_EDX_[8]; } + static bool SEP(void) { return CPU_Rep.f_1_EDX_[11]; } + static bool CMOV(void) { return CPU_Rep.f_1_EDX_[15]; } + static bool CLFSH(void) { return CPU_Rep.f_1_EDX_[19]; } + static bool MMX(void) { return CPU_Rep.f_1_EDX_[23]; } + static bool FXSR(void) { return CPU_Rep.f_1_EDX_[24]; } + static bool SSE(void) { return CPU_Rep.f_1_EDX_[25]; } + static bool SSE2(void) { return CPU_Rep.f_1_EDX_[26]; } + + static bool FSGSBASE(void) { return CPU_Rep.f_7_EBX_[0]; } + static bool BMI1(void) { return CPU_Rep.f_7_EBX_[3]; } + static bool HLE(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_7_EBX_[4]; } + static bool AVX2(void) { return CPU_Rep.f_7_EBX_[5]; } + static bool BMI2(void) { return CPU_Rep.f_7_EBX_[8]; } + static bool ERMS(void) { return CPU_Rep.f_7_EBX_[9]; } + static bool INVPCID(void) { return CPU_Rep.f_7_EBX_[10]; } + static bool RTM(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_7_EBX_[11]; } + static bool AVX512F(void) { return CPU_Rep.f_7_EBX_[16]; } + static bool RDSEED(void) { return CPU_Rep.f_7_EBX_[18]; } + static bool ADX(void) { return CPU_Rep.f_7_EBX_[19]; } + static bool AVX512PF(void) { return CPU_Rep.f_7_EBX_[26]; } + static bool AVX512ER(void) { return CPU_Rep.f_7_EBX_[27]; } + static bool AVX512CD(void) { return CPU_Rep.f_7_EBX_[28]; } + static bool SHA(void) { return CPU_Rep.f_7_EBX_[29]; } + + static bool PREFETCHWT1(void) { return CPU_Rep.f_7_ECX_[0]; } + + static bool LAHF(void) { return CPU_Rep.f_81_ECX_[0]; } + static bool LZCNT(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_81_ECX_[5]; } + static bool ABM(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[5]; } + static bool SSE4a(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[6]; } + static bool XOP(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[11]; } + static bool TBM(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[21]; } + + static bool SYSCALL(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_81_EDX_[11]; } + static bool MMXEXT(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[22]; } + static bool RDTSCP(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_81_EDX_[27]; } + static bool _3DNOWEXT(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[30]; } + static bool _3DNOW(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[31]; } +}; diff --git a/LuaSTG/Platform/Direct3D11.hpp b/engine/win32/windows/Direct3D11.hpp similarity index 96% rename from LuaSTG/Platform/Direct3D11.hpp rename to engine/win32/windows/Direct3D11.hpp index d7f8b40e..922bac22 100644 --- a/LuaSTG/Platform/Direct3D11.hpp +++ b/engine/win32/windows/Direct3D11.hpp @@ -1,12 +1,12 @@ -#pragma once - -namespace Platform -{ - class Direct3D11 - { - public: - static HRESULT GetDeviceAdater(ID3D11Device* pDevice, IDXGIAdapter1** ppAdapter); - static HRESULT GetDeviceFactory(ID3D11Device* pDevice, IDXGIFactory2** ppFactory); - static BOOL HasDevice(UINT Flags, D3D_FEATURE_LEVEL TargetFeatureLevel); - }; -} +#pragma once + +namespace Platform +{ + class Direct3D11 + { + public: + static HRESULT GetDeviceAdater(ID3D11Device* pDevice, IDXGIAdapter1** ppAdapter); + static HRESULT GetDeviceFactory(ID3D11Device* pDevice, IDXGIFactory2** ppFactory); + static BOOL HasDevice(UINT Flags, D3D_FEATURE_LEVEL TargetFeatureLevel); + }; +} diff --git a/LuaSTG/Platform/DirectInput.cpp b/engine/win32/windows/DirectInput.cpp similarity index 100% rename from LuaSTG/Platform/DirectInput.cpp rename to engine/win32/windows/DirectInput.cpp diff --git a/LuaSTG/Platform/DirectInput.hpp b/engine/win32/windows/DirectInput.hpp similarity index 100% rename from LuaSTG/Platform/DirectInput.hpp rename to engine/win32/windows/DirectInput.hpp diff --git a/LuaSTG/Platform/HResultChecker.cpp b/engine/win32/windows/HResultChecker.cpp similarity index 88% rename from LuaSTG/Platform/HResultChecker.cpp rename to engine/win32/windows/HResultChecker.cpp index 72ee0f21..4777c8ab 100644 --- a/LuaSTG/Platform/HResultChecker.cpp +++ b/engine/win32/windows/HResultChecker.cpp @@ -1,166 +1,161 @@ -#include "Shared.hpp" -#include "HResultChecker.hpp" - -namespace Platform -{ - struct Lock - { - struct ScopeLock - { - CRITICAL_SECTION& sec_; - ScopeLock(CRITICAL_SECTION& sec) : sec_(sec) - { - EnterCriticalSection(&sec_); - } - ~ScopeLock() - { - LeaveCriticalSection(&sec_); - } - }; - - CRITICAL_SECTION sec_; - - ScopeLock lock() - { - return ScopeLock(sec_); - } - - Lock() - { - InitializeCriticalSection(&sec_); - } - ~Lock() - { - DeleteCriticalSection(&sec_); - } - }; - - static void DefaultPrintCallback(std::string_view const message) - { - OutputDebugStringA(message.data()); - } - - static HResultChecker::PrintCallback g_pfn = &DefaultPrintCallback; - - HResultChecker& HResultChecker::operator=(HResult const hr) - { - if (FAILED(hr)) - { - static Lock lock_; - static WCHAR buffer_[2048]{}; // 去掉空终止字符和换行符,实际上只有 2046 可用 - - // 先锁上,重置缓冲区 - auto scope_lock_ = lock_.lock(); - ZeroMemory(buffer_, sizeof(buffer_)); - // 源文件和行号,错误号 - #ifdef _DEBUG - int const head_result_ = std::swprintf( - buffer_, - 2046u, - L"系统调用出错,文件:'%s' 第 %d 行:(HRESULT = 0x%08X) ", - source_, line_, static_cast(hr)); - assert(head_result_ > 0); - DWORD const head_length_ = (DWORD)head_result_; - #else - int const head_result_ = std::swprintf( - buffer_, - 2046u, - L"系统调用出错:(HRESULT = 0x%08X) ", - static_cast(hr)); - assert(head_result_ > 0); - DWORD const head_length_ = (DWORD)head_result_; - #endif - // 获得人类可读的错误描述 - DWORD body_result_ = FormatMessageW( - FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - static_cast(hr), - LANG_USER_DEFAULT, - buffer_ + head_length_, - 2046u - head_length_, - NULL); - // 移除 /r/n - for (int i_ = 0; i_ < 2; i_ += 1) - { - if (body_result_ > 0) - { - WCHAR& c_ = buffer_[head_length_ + body_result_ - 1]; - if (c_ == L'\r' || c_ == L'\n') - { - c_ = L'\0'; - body_result_ -= 1; - } - } - } - DWORD const body_length_ = (DWORD)body_result_; - // 转换编码并打印 - DWORD const length_ = head_length_ + body_length_; - #ifdef _DEBUG - buffer_[length_] = L'\n'; - OutputDebugStringW(buffer_); - buffer_[length_] = L'\0'; - #endif - std::string const message_(to_utf8(std::wstring_view(buffer_, length_))); - g_pfn(message_); - // 禁用编译器警告 - std::ignore = scope_lock_; - } - hr_ = hr; - return *this; - } - HResultChecker::operator HResult() const noexcept - { - return hr_; - } - - HResultChecker::HResultChecker(WChar const* const source, int const line, HResult const hr) noexcept - : hr_(hr) - #ifdef _DEBUG - , source_(source) - , line_(line) - #endif - { - #ifndef _DEBUG - UNREFERENCED_PARAMETER(source); - UNREFERENCED_PARAMETER(line); - #endif - } - HResultChecker::HResultChecker(WChar const* const source, int const line) noexcept - : hr_(S_OK) - #ifdef _DEBUG - , source_(source) - , line_(line) - #endif - { - #ifndef _DEBUG - UNREFERENCED_PARAMETER(source); - UNREFERENCED_PARAMETER(line); - #endif - } - HResultChecker::HResultChecker(HResult const hr) noexcept - : hr_(hr) - #ifdef _DEBUG - , source_(L"未知") - , line_(0) - #endif - { - } - HResultChecker::HResultChecker() noexcept - : hr_(S_OK) - #ifdef _DEBUG - , source_(L"未知") - , line_(0) - #endif - { - } - - void HResultChecker::SetPrintCallback(PrintCallback pfn) noexcept - { - g_pfn = (pfn != nullptr) ? pfn : &DefaultPrintCallback; - } - - HResultToBool& HResultToBool::operator=(HResult v) noexcept { hr = v; return *this; } - HResultToBool::operator bool() const noexcept { return SUCCEEDED(hr); } - HResultToBool::HResultToBool() noexcept : hr(S_OK) {} - HResultToBool::HResultToBool(HResult const hr_) noexcept : hr(hr_) {} -} +#include "Shared.hpp" +#include "HResultChecker.hpp" + +namespace Platform +{ + struct Lock + { + struct ScopeLock + { + CRITICAL_SECTION& sec_; + ScopeLock(CRITICAL_SECTION& sec) : sec_(sec) + { + EnterCriticalSection(&sec_); + } + ~ScopeLock() + { + LeaveCriticalSection(&sec_); + } + }; + + CRITICAL_SECTION sec_; + + ScopeLock lock() + { + return ScopeLock(sec_); + } + + Lock() + { + InitializeCriticalSection(&sec_); + } + ~Lock() + { + DeleteCriticalSection(&sec_); + } + }; + + static void DefaultPrintCallback(std::string_view const message) + { + OutputDebugStringA(message.data()); + } + + static HResultChecker::PrintCallback g_pfn = &DefaultPrintCallback; + + HResultChecker& HResultChecker::operator=(HResult const hr) + { + if (FAILED(hr)) + { + static Lock lock_; + static WCHAR buffer_[2048]{}; // 去掉空终止字符和换行符,实际上只有 2046 可用 + + // 先锁上,重置缓冲区 + auto scope_lock_ = lock_.lock(); + ZeroMemory(buffer_, sizeof(buffer_)); + // 源文件和行号,错误号 + #ifdef _DEBUG + int const head_result_ = std::swprintf( + buffer_, + 2046u, + L"系统调用出错,文件:'%s' 第 %d 行:(HRESULT = 0x%08X) ", + source_, line_, static_cast(hr)); + assert(head_result_ > 0); + DWORD const head_length_ = (DWORD)head_result_; + #else + int const head_result_ = std::swprintf( + buffer_, + 2046u, + L"系统调用出错:(HRESULT = 0x%08X) ", + static_cast(hr)); + assert(head_result_ > 0); + DWORD const head_length_ = (DWORD)head_result_; + #endif + // 获得人类可读的错误描述 + DWORD body_result_ = FormatMessageW( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + static_cast(hr), + LANG_USER_DEFAULT, + buffer_ + head_length_, + 2046u - head_length_, + NULL); + // 移除 /r/n + for (int i_ = 0; i_ < 2; i_ += 1) + { + if (body_result_ > 0) + { + WCHAR& c_ = buffer_[head_length_ + body_result_ - 1]; + if (c_ == L'\r' || c_ == L'\n') + { + c_ = L'\0'; + body_result_ -= 1; + } + } + } + DWORD const body_length_ = (DWORD)body_result_; + // 转换编码并打印 + DWORD const length_ = head_length_ + body_length_; + #ifdef _DEBUG + buffer_[length_] = L'\n'; + OutputDebugStringW(buffer_); + buffer_[length_] = L'\0'; + #endif + std::string const message_(to_utf8(std::wstring_view(buffer_, length_))); + g_pfn(message_); + // 禁用编译器警告 + std::ignore = scope_lock_; + } + hr_ = hr; + return *this; + } + HResultChecker::operator HResult() const noexcept + { + return hr_; + } + + HResultChecker::HResultChecker(WChar const* const source, int const line, HResult const hr) noexcept + : hr_(hr) + #ifdef _DEBUG + , source_(source) + , line_(line) + #endif + { + #ifndef _DEBUG + UNREFERENCED_PARAMETER(source); + UNREFERENCED_PARAMETER(line); + #endif + } + HResultChecker::HResultChecker(WChar const* const source, int const line) noexcept + : hr_(S_OK) + #ifdef _DEBUG + , source_(source) + , line_(line) + #endif + { + #ifndef _DEBUG + UNREFERENCED_PARAMETER(source); + UNREFERENCED_PARAMETER(line); + #endif + } + HResultChecker::HResultChecker(HResult const hr) noexcept + : hr_(hr) + #ifdef _DEBUG + , source_(L"未知") + , line_(0) + #endif + { + } + HResultChecker::HResultChecker() noexcept + : hr_(S_OK) + #ifdef _DEBUG + , source_(L"未知") + , line_(0) + #endif + { + } + + void HResultChecker::SetPrintCallback(PrintCallback pfn) noexcept + { + g_pfn = (pfn != nullptr) ? pfn : &DefaultPrintCallback; + } +} diff --git a/LuaSTG/Platform/HResultChecker.hpp b/engine/win32/windows/HResultChecker.hpp similarity index 72% rename from LuaSTG/Platform/HResultChecker.hpp rename to engine/win32/windows/HResultChecker.hpp index 94294fce..5dddde0a 100644 --- a/LuaSTG/Platform/HResultChecker.hpp +++ b/engine/win32/windows/HResultChecker.hpp @@ -1,52 +1,40 @@ -#pragma once -#include - -namespace Platform -{ -#ifdef _HRESULT_DEFINED - using HResult = HRESULT; - using WChar = WCHAR; -#else - using HResult = long; - using WChar = wchar_t; -#endif - - class HResultChecker - { - private: - HResult hr_{}; - #ifdef _DEBUG - int const line_{}; - WChar const* const source_{}; - #endif - public: - HResultChecker& operator=(HResult const hr); - operator HResult() const noexcept; - public: - explicit HResultChecker(WChar const* const source, int const line, HResult const hr) noexcept; - explicit HResultChecker(WChar const* const source, int const line) noexcept; - explicit HResultChecker(HResult const hr) noexcept; - explicit HResultChecker() noexcept; - public: - using PrintCallback = void (*)(std::string_view const); - static void SetPrintCallback(PrintCallback pfn = nullptr) noexcept; - }; - - struct HResultToBool - { - HResult hr{}; - HResultToBool& operator=(HResult v) noexcept; - operator bool() const noexcept; - explicit HResultToBool() noexcept; - explicit HResultToBool(HResult const hr_) noexcept; - }; -} - -#ifdef _DEBUG -#define gHR Platform::HResultChecker(__FILEW__, __LINE__) -#else -#define gHR Platform::HResultChecker() -#endif - -#define gHRLastError gHR = HRESULT_FROM_WIN32(GetLastError()) -#define bHR Platform::HResultToBool() +#pragma once +#include + +namespace Platform +{ +#ifdef _HRESULT_DEFINED + using HResult = HRESULT; + using WChar = WCHAR; +#else + using HResult = long; + using WChar = wchar_t; +#endif + + class HResultChecker + { + private: + HResult hr_{}; + #ifdef _DEBUG + int const line_{}; + WChar const* const source_{}; + #endif + public: + HResultChecker& operator=(HResult const hr); + operator HResult() const noexcept; + public: + explicit HResultChecker(WChar const* const source, int const line, HResult const hr) noexcept; + explicit HResultChecker(WChar const* const source, int const line) noexcept; + explicit HResultChecker(HResult const hr) noexcept; + explicit HResultChecker() noexcept; + public: + using PrintCallback = void (*)(std::string_view const); + static void SetPrintCallback(PrintCallback pfn = nullptr) noexcept; + }; +} + +#ifdef _DEBUG +#define gHR Platform::HResultChecker(__FILEW__, __LINE__) +#else +#define gHR Platform::HResultChecker() +#endif diff --git a/LuaSTG/Platform/ImmersiveTitleBarController.cpp b/engine/win32/windows/ImmersiveTitleBarController.cpp similarity index 93% rename from LuaSTG/Platform/ImmersiveTitleBarController.cpp rename to engine/win32/windows/ImmersiveTitleBarController.cpp index ae893d75..1af7cd8a 100644 --- a/LuaSTG/Platform/ImmersiveTitleBarController.cpp +++ b/engine/win32/windows/ImmersiveTitleBarController.cpp @@ -2,6 +2,7 @@ #include #include +#include "win32/base.hpp" #include "win32/win32.hpp" #include "CleanWindows.hpp" @@ -9,7 +10,6 @@ #include #include #include -#include #include "win32/abi.hpp" @@ -123,10 +123,10 @@ namespace platform::windows { UINT win32_window_width{}; UINT win32_window_height{}; UINT win32_window_dpi{ win32::getUserDefaultScreenDpi() }; - wil::com_ptr_nothrow d2d1_device_context; - wil::com_ptr_nothrow dwrite_factory; - wil::com_ptr_nothrow dwrite_text_format_title; - wil::com_ptr_nothrow dwrite_text_format_icon; + win32::com_ptr d2d1_device_context; + win32::com_ptr dwrite_factory; + win32::com_ptr dwrite_text_format_title; + win32::com_ptr dwrite_text_format_icon; std::wstring title_text{ L"Render Window" }; bool feature_enable{ true }; bool dark_mode{ false }; @@ -177,7 +177,7 @@ namespace platform::windows { auto const scaling = getScaling(); auto const& color_schema = getColorSchema(); - wil::com_ptr_nothrow title_bar_background_color; + win32::com_ptr title_bar_background_color; d2d1_device_context->CreateSolidColorBrush(color_schema.title_bar_background, title_bar_background_color.put()); d2d1_device_context->FillRectangle( @@ -185,12 +185,12 @@ namespace platform::windows { title_bar_background_color.get() ); - wil::com_ptr_nothrow title_text_color; + win32::com_ptr title_text_color; d2d1_device_context->CreateSolidColorBrush(color_schema.title_text, title_text_color.put()); auto const title_text_width = (float)win32_window_width - (3.0f * button_width + 2.0f * title_left_padding) * scaling; if (title_text_width > 0) { - wil::com_ptr_nothrow title_text_layout; + win32::com_ptr title_text_layout; dwrite_factory->CreateTextLayout( title_text.c_str(), static_cast(title_text.length()), dwrite_text_format_title.get(), @@ -210,7 +210,7 @@ namespace platform::windows { DWRITE_TEXT_METRICS metrics{}; title_text_layout->GetMetrics(&metrics); if (metrics.width > title_text_width) { - wil::com_ptr_nothrow title_text_more_layout; + win32::com_ptr title_text_more_layout; dwrite_factory->CreateTextLayout( L"...", 3, dwrite_text_format_title.get(), @@ -253,24 +253,24 @@ namespace platform::windows { float const min_button_right = max_button_left; float const min_button_left = min_button_right - button_width * scaling; - wil::com_ptr_nothrow rest_background_color; + win32::com_ptr rest_background_color; d2d1_device_context->CreateSolidColorBrush(color_schema.button_rest_background, rest_background_color.put()); - wil::com_ptr_nothrow rest_text_color; + win32::com_ptr rest_text_color; d2d1_device_context->CreateSolidColorBrush(color_schema.button_rest_text, rest_text_color.put()); - wil::com_ptr_nothrow disabled_background_color; + win32::com_ptr disabled_background_color; d2d1_device_context->CreateSolidColorBrush(color_schema.button_disabled_background, disabled_background_color.put()); - wil::com_ptr_nothrow disabled_text_color; + win32::com_ptr disabled_text_color; d2d1_device_context->CreateSolidColorBrush(color_schema.button_disabled_text, disabled_text_color.put()); - wil::com_ptr_nothrow hover_background_color; + win32::com_ptr hover_background_color; d2d1_device_context->CreateSolidColorBrush(color_schema.button_hover_background, hover_background_color.put()); - wil::com_ptr_nothrow hover_text_color; + win32::com_ptr hover_text_color; d2d1_device_context->CreateSolidColorBrush(color_schema.button_hover_text, hover_text_color.put()); - wil::com_ptr_nothrow press_background_color; + win32::com_ptr press_background_color; d2d1_device_context->CreateSolidColorBrush(color_schema.button_pressed_background, press_background_color.put()); - wil::com_ptr_nothrow press_text_color; + win32::com_ptr press_text_color; d2d1_device_context->CreateSolidColorBrush(color_schema.button_pressed_text, press_text_color.put()); auto getMinimizeButtonBackgroundBrush = [&]() -> ID2D1SolidColorBrush* { @@ -299,14 +299,14 @@ namespace platform::windows { return (pointer_on_maximize_button ? hover_text_color : rest_text_color).get(); }; - wil::com_ptr_nothrow close_hover_background_color; + win32::com_ptr close_hover_background_color; d2d1_device_context->CreateSolidColorBrush(color_schema.close_button_hover_background, close_hover_background_color.put()); - wil::com_ptr_nothrow close_hover_text_color; + win32::com_ptr close_hover_text_color; d2d1_device_context->CreateSolidColorBrush(color_schema.close_button_hover_text, close_hover_text_color.put()); - wil::com_ptr_nothrow close_press_background_color; + win32::com_ptr close_press_background_color; d2d1_device_context->CreateSolidColorBrush(color_schema.close_button_pressed_background, close_press_background_color.put()); - wil::com_ptr_nothrow close_press_text_color; + win32::com_ptr close_press_text_color; d2d1_device_context->CreateSolidColorBrush(color_schema.close_button_pressed_text, close_press_text_color.put()); auto getCloseButtonBackgroundBrush = [&]() -> ID2D1SolidColorBrush* { @@ -346,7 +346,7 @@ namespace platform::windows { .length = 1, }; - wil::com_ptr_nothrow minimize_icon_text_layout; + win32::com_ptr minimize_icon_text_layout; dwrite_factory->CreateTextLayout( icon_schema.chrome_minimize, 1, dwrite_text_format_icon.get(), @@ -362,7 +362,7 @@ namespace platform::windows { getMinimizeButtonTextBrush() ); - wil::com_ptr_nothrow maximize_icon_text_layout; + win32::com_ptr maximize_icon_text_layout; dwrite_factory->CreateTextLayout( window_maximized ? icon_schema.chrome_restore : icon_schema.chrome_maximize, 1, dwrite_text_format_icon.get(), @@ -378,7 +378,7 @@ namespace platform::windows { getMaximizeButtonTextBrush() ); - wil::com_ptr_nothrow close_icon_text_layout; + win32::com_ptr close_icon_text_layout; dwrite_factory->CreateTextLayout( icon_schema.chrome_close, 1, dwrite_text_format_icon.get(), @@ -689,21 +689,21 @@ namespace platform::windows { HRESULT hr{}; initializeWindowDpi(window); RECT client{}; - if (!LOG_IF_WIN32_BOOL_FALSE(GetClientRect(window, &client))) { + if (!GetClientRect(window, &client)) { // TODO: log error return false; } win32_window_width = client.right - client.left; win32_window_height = client.bottom - client.top; d2d1_device_context = context; - hr = dwrite.CreateFactory(DWRITE_FACTORY_TYPE_SHARED, IID_PPV_ARGS(&dwrite_factory)); + hr = dwrite.CreateFactory(DWRITE_FACTORY_TYPE_SHARED, IID_PPV_ARGS(dwrite_factory.put())); if (FAILED(hr)) { - LOG_HR_MSG(hr, "DWriteCreateFactory"); + win32::check_hresult(hr, "DWriteCreateFactory"); return false; } - wil::com_ptr_nothrow system_font_collection; + win32::com_ptr system_font_collection; hr = dwrite_factory->GetSystemFontCollection(system_font_collection.put(), false); if (FAILED(hr)) { - LOG_HR_MSG(hr, "IDWriteFactory::GetSystemFontCollection"); + win32::check_hresult(hr, "IDWriteFactory::GetSystemFontCollection"); return false; } hr = dwrite_factory->CreateTextFormat( @@ -717,7 +717,7 @@ namespace platform::windows { dwrite_text_format_title.put() ); if (FAILED(hr)) { - LOG_HR_MSG(hr, "CreateTextFormat(\"微软雅黑\")"); + win32::check_hresult(hr, "CreateTextFormat(\"微软雅黑\")"); return false; } hr = dwrite_factory->CreateTextFormat( @@ -731,7 +731,7 @@ namespace platform::windows { dwrite_text_format_icon.put() ); if (FAILED(hr)) { - LOG_HR_MSG(hr, "CreateTextFormat(\"Segoe Fluent Icons\")"); + win32::check_hresult(hr, "CreateTextFormat(\"Segoe Fluent Icons\")"); return false; } dark_mode = Platform::WindowTheme::ShouldApplicationEnableDarkMode(); @@ -809,7 +809,7 @@ namespace platform::windows { d2d1_device_context->SetTarget(nullptr); hr = d2d1_device_context->EndDraw(); if (FAILED(hr)) { - LOG_HR_MSG(hr, "ID2D1RenderTarget::EndDraw failed"); + win32::check_hresult(hr, "ID2D1RenderTarget::EndDraw failed"); return false; } return true; diff --git a/LuaSTG/Platform/ImmersiveTitleBarController.hpp b/engine/win32/windows/ImmersiveTitleBarController.hpp similarity index 100% rename from LuaSTG/Platform/ImmersiveTitleBarController.hpp rename to engine/win32/windows/ImmersiveTitleBarController.hpp diff --git a/LuaSTG/Platform/Keyboard.cpp b/engine/win32/windows/Keyboard.cpp similarity index 97% rename from LuaSTG/Platform/Keyboard.cpp rename to engine/win32/windows/Keyboard.cpp index e0ce3d06..d21214a0 100644 --- a/LuaSTG/Platform/Keyboard.cpp +++ b/engine/win32/windows/Keyboard.cpp @@ -1,321 +1,321 @@ -#include "Shared.hpp" -#include "Keyboard.hpp" - -/* - [0|0|0|0000|0|00000000|0000000000000000] - | | | | | | | - | | | | | | +-- The repeat count for the current message. - | | | | | | The value is the number of times the keystroke is autorepeated - | | | | | | as a result of the user holding down the key. - | | | | | | If the keystroke is held long enough, multiple messages are sent. - | | | | | | However, the repeat count is not cumulative. - | | | | | | The repeat count is always 1 for a WM_KEYUP message. - | | | | | | - | | | | | +----------- The scan code. The value depends on the OEM. - | | | | | - | | | | +------------- Indicates whether the key is an extended key, - | | | | such as the right-hand ALT and CTRL keys that - | | | | that appear on an enhanced 101- or 102-key keyboard. - | | | | The value is 1 if it is an extended key; otherwise, it is 0. - | | | | - | | | +------------------ Reserved; do not use. - | | | - | | +-------------------- The context code. The value is always 0 for a WM_KEYUP/WM_KEYDOWN message. - | | - | +---------------------- The previous key state. The value is always 1 for a WM_KEYUP message. - | The value is 1 if the key is down before the message is sent, - | or it is zero if the key is up. - | - +------------------------ The transition state. The value is always 0 for a WM_KEYDOWN message. - The value is always 1 for a WM_KEYUP message. -*/ - -namespace Platform -{ - static_assert(sizeof(unsigned int) == 4); - static_assert(sizeof(Keyboard::State::KeyStateData) == 32); - static_assert(sizeof(Keyboard::State) == (32 * 3 + 4)); - - inline bool IsExtendedKey(LPARAM lParam) - { - constexpr LPARAM const bit_mask = KF_EXTENDED << 16; - return (lParam & bit_mask) == bit_mask; - } - - inline bool GetKey(uint32_t state_[8], uint8_t vk) - { - uint32_t const index = (vk & 0x7FFFFFE0u) >> 5u; - uint32_t const bitmk = 1u << (vk & 0x0000001Fu); - return (state_[index] & bitmk) == bitmk; - } -#if PLATFORM_KEYBOARD_USING_ATOMIC - inline void AtomicSetKey(std::atomic_uint32_t state_[8], uint8_t vk, bool down) - { - uint32_t const index = (vk & 0x7FFFFFE0u) >> 5u; - uint32_t const bitmk = 1u << (vk & 0x0000001Fu); - if (down) - state_[index].fetch_or(bitmk); - else - state_[index].fetch_and(~bitmk); - } -#else - inline void AtomicSetKey(uint32_t state_[8], uint8_t vk, bool down) - { - uint32_t const index = (vk & 0x7FFFFFE0u) >> 5u; - uint32_t const bitmk = 1u << (vk & 0x0000001Fu); - if (down) - state_[index] |= bitmk; - else - state_[index] &= (~bitmk); - } -#endif - - constexpr uint8_t const VK_NUMPADENTER = 0xE8u; // Unassigned Virtual-Key Code - - void Keyboard::State::Reset() - { - std::memset(this, 0, sizeof(State)); - } - bool Keyboard::State::IsKeyDown(Keyboard::Key key, bool include_history) - { - return GetKey(include_history ? KeyDown.Data : KeyState.Data, static_cast(key)); - } - bool Keyboard::State::IsKeyUp(Keyboard::Key key, bool include_history) - { - return GetKey(include_history ? KeyUp.Data : KeyState.Data, static_cast(key)); - } - - void Keyboard::Reset() - { - #if PLATFORM_KEYBOARD_USING_ATOMIC - KeyState[0].store(0u); - KeyState[1].store(0u); - KeyState[2].store(0u); - KeyState[3].store(0u); - KeyState[4].store(0u); - KeyState[5].store(0u); - KeyState[6].store(0u); - KeyState[7].store(0u); - #else - KeyState[0] = (0u); - KeyState[1] = (0u); - KeyState[2] = (0u); - KeyState[3] = (0u); - KeyState[4] = (0u); - KeyState[5] = (0u); - KeyState[6] = (0u); - KeyState[7] = (0u); - #endif - ResetFrame(); - _Padding[0] = 0; - _Padding[1] = 0; - } - void Keyboard::ResetFrame() - { - #if PLATFORM_KEYBOARD_USING_ATOMIC - KeyDown[0].store(0u); - KeyDown[1].store(0u); - KeyDown[2].store(0u); - KeyDown[3].store(0u); - KeyDown[4].store(0u); - KeyDown[5].store(0u); - KeyDown[6].store(0u); - KeyDown[7].store(0u); - KeyUp[0].store(0u); - KeyUp[1].store(0u); - KeyUp[2].store(0u); - KeyUp[3].store(0u); - KeyUp[4].store(0u); - KeyUp[5].store(0u); - KeyUp[6].store(0u); - KeyUp[7].store(0u); - LastKeyDown.store(0u); - LastKeyUp.store(0u); - #else - KeyDown[0] = (0u); - KeyDown[1] = (0u); - KeyDown[2] = (0u); - KeyDown[3] = (0u); - KeyDown[4] = (0u); - KeyDown[5] = (0u); - KeyDown[6] = (0u); - KeyDown[7] = (0u); - KeyUp[0] = (0u); - KeyUp[1] = (0u); - KeyUp[2] = (0u); - KeyUp[3] = (0u); - KeyUp[4] = (0u); - KeyUp[5] = (0u); - KeyUp[6] = (0u); - KeyUp[7] = (0u); - LastKeyDown = (0u); - LastKeyUp = (0u); - #endif - } - - Keyboard::State Keyboard::GetState(bool new_frame) - { - Keyboard::State Copy = {}; - GetState(Copy, new_frame); - return Copy; - } - void Keyboard::GetState(Keyboard::State& Ref, bool new_frame) - { - #if PLATFORM_KEYBOARD_USING_ATOMIC - Ref.KeyState.Data[0] = KeyState[0].load(); - Ref.KeyState.Data[1] = KeyState[1].load(); - Ref.KeyState.Data[2] = KeyState[2].load(); - Ref.KeyState.Data[3] = KeyState[3].load(); - Ref.KeyState.Data[4] = KeyState[4].load(); - Ref.KeyState.Data[5] = KeyState[5].load(); - Ref.KeyState.Data[6] = KeyState[6].load(); - Ref.KeyState.Data[7] = KeyState[7].load(); - if (new_frame) - { - Ref.KeyDown.Data[0] = KeyDown[0].exchange(0u); - Ref.KeyDown.Data[1] = KeyDown[1].exchange(0u); - Ref.KeyDown.Data[2] = KeyDown[2].exchange(0u); - Ref.KeyDown.Data[3] = KeyDown[3].exchange(0u); - Ref.KeyDown.Data[4] = KeyDown[4].exchange(0u); - Ref.KeyDown.Data[5] = KeyDown[5].exchange(0u); - Ref.KeyDown.Data[6] = KeyDown[6].exchange(0u); - Ref.KeyDown.Data[7] = KeyDown[7].exchange(0u); - Ref.KeyUp.Data[0] = KeyUp[0].exchange(0u); - Ref.KeyUp.Data[1] = KeyUp[1].exchange(0u); - Ref.KeyUp.Data[2] = KeyUp[2].exchange(0u); - Ref.KeyUp.Data[3] = KeyUp[3].exchange(0u); - Ref.KeyUp.Data[4] = KeyUp[4].exchange(0u); - Ref.KeyUp.Data[5] = KeyUp[5].exchange(0u); - Ref.KeyUp.Data[6] = KeyUp[6].exchange(0u); - Ref.KeyUp.Data[7] = KeyUp[7].exchange(0u); - Ref.LastKeyDown = static_cast(LastKeyDown.exchange(0)); - Ref.LastKeyUp = static_cast(LastKeyUp.exchange(0)); - } - else - { - Ref.KeyDown.Data[0] = KeyDown[0].load(); - Ref.KeyDown.Data[1] = KeyDown[1].load(); - Ref.KeyDown.Data[2] = KeyDown[2].load(); - Ref.KeyDown.Data[3] = KeyDown[3].load(); - Ref.KeyDown.Data[4] = KeyDown[4].load(); - Ref.KeyDown.Data[5] = KeyDown[5].load(); - Ref.KeyDown.Data[6] = KeyDown[6].load(); - Ref.KeyDown.Data[7] = KeyDown[7].load(); - Ref.KeyUp.Data[0] = KeyUp[0].load(); - Ref.KeyUp.Data[1] = KeyUp[1].load(); - Ref.KeyUp.Data[2] = KeyUp[2].load(); - Ref.KeyUp.Data[3] = KeyUp[3].load(); - Ref.KeyUp.Data[4] = KeyUp[4].load(); - Ref.KeyUp.Data[5] = KeyUp[5].load(); - Ref.KeyUp.Data[6] = KeyUp[6].load(); - Ref.KeyUp.Data[7] = KeyUp[7].load(); - Ref.LastKeyDown = static_cast(LastKeyDown.load()); - Ref.LastKeyUp = static_cast(LastKeyUp.load()); - } - #else - Ref.KeyState.Data[0] = KeyState[0]; - Ref.KeyState.Data[1] = KeyState[1]; - Ref.KeyState.Data[2] = KeyState[2]; - Ref.KeyState.Data[3] = KeyState[3]; - Ref.KeyState.Data[4] = KeyState[4]; - Ref.KeyState.Data[5] = KeyState[5]; - Ref.KeyState.Data[6] = KeyState[6]; - Ref.KeyState.Data[7] = KeyState[7]; - Ref.KeyDown.Data[0] = KeyDown[0]; - Ref.KeyDown.Data[1] = KeyDown[1]; - Ref.KeyDown.Data[2] = KeyDown[2]; - Ref.KeyDown.Data[3] = KeyDown[3]; - Ref.KeyDown.Data[4] = KeyDown[4]; - Ref.KeyDown.Data[5] = KeyDown[5]; - Ref.KeyDown.Data[6] = KeyDown[6]; - Ref.KeyDown.Data[7] = KeyDown[7]; - Ref.KeyUp.Data[0] = KeyUp[0]; - Ref.KeyUp.Data[1] = KeyUp[1]; - Ref.KeyUp.Data[2] = KeyUp[2]; - Ref.KeyUp.Data[3] = KeyUp[3]; - Ref.KeyUp.Data[4] = KeyUp[4]; - Ref.KeyUp.Data[5] = KeyUp[5]; - Ref.KeyUp.Data[6] = KeyUp[6]; - Ref.KeyUp.Data[7] = KeyUp[7]; - Ref.LastKeyDown = static_cast(LastKeyDown); - Ref.LastKeyUp = static_cast(LastKeyUp); - if (new_frame) - { - ResetFrame(); - } - #endif - } - - void Keyboard::ProcessMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) - { - std::ignore = hWnd; - bool down = false; - switch (uMsg) - { - default: - return; // ignore other message - case WM_ACTIVATE: - case WM_ACTIVATEAPP: - Reset(); - return; // skip - case WM_KEYDOWN: - case WM_SYSKEYDOWN: - down = true; - break; - case WM_KEYUP: - case WM_SYSKEYUP: - down = false; - break; - } - if (wParam > 0xFFu) - { - return; // ignore unknown key code - } - uint8_t const vk = wParam & 0xFFu; - uint8_t vk_translated = vk; - switch (vk) - { - case VK_RETURN: - vk_translated = IsExtendedKey(lParam) ? VK_NUMPADENTER : VK_RETURN; - break; - case VK_SHIFT: - vk_translated = IsExtendedKey(lParam) ? VK_RSHIFT : VK_LSHIFT; - if (!down) - { - // Windows system feature :( - AtomicSetKey(KeyState, VK_RSHIFT, false); - AtomicSetKey(KeyState, VK_LSHIFT, false); - } - break; - case VK_CONTROL: - vk_translated = IsExtendedKey(lParam) ? VK_RCONTROL : VK_LCONTROL; - break; - case VK_MENU: - vk_translated = IsExtendedKey(lParam) ? VK_RMENU : VK_LMENU; - break; - } - AtomicSetKey(KeyState, vk, down); - if (vk != vk_translated) - { - AtomicSetKey(KeyState, vk_translated, down); - } - if (down) - { - AtomicSetKey(KeyDown, vk_translated, true); - #if PLATFORM_KEYBOARD_USING_ATOMIC - LastKeyDown.store(vk_translated); - #else - LastKeyDown = (vk_translated); - #endif - } - else - { - AtomicSetKey(KeyUp, vk_translated, true); - #if PLATFORM_KEYBOARD_USING_ATOMIC - LastKeyUp.store(vk_translated); - #else - LastKeyUp = (vk_translated); - #endif - } - } -} +#include "Shared.hpp" +#include "Keyboard.hpp" + +/* + [0|0|0|0000|0|00000000|0000000000000000] + | | | | | | | + | | | | | | +-- The repeat count for the current message. + | | | | | | The value is the number of times the keystroke is autorepeated + | | | | | | as a result of the user holding down the key. + | | | | | | If the keystroke is held long enough, multiple messages are sent. + | | | | | | However, the repeat count is not cumulative. + | | | | | | The repeat count is always 1 for a WM_KEYUP message. + | | | | | | + | | | | | +----------- The scan code. The value depends on the OEM. + | | | | | + | | | | +------------- Indicates whether the key is an extended key, + | | | | such as the right-hand ALT and CTRL keys that + | | | | that appear on an enhanced 101- or 102-key keyboard. + | | | | The value is 1 if it is an extended key; otherwise, it is 0. + | | | | + | | | +------------------ Reserved; do not use. + | | | + | | +-------------------- The context code. The value is always 0 for a WM_KEYUP/WM_KEYDOWN message. + | | + | +---------------------- The previous key state. The value is always 1 for a WM_KEYUP message. + | The value is 1 if the key is down before the message is sent, + | or it is zero if the key is up. + | + +------------------------ The transition state. The value is always 0 for a WM_KEYDOWN message. + The value is always 1 for a WM_KEYUP message. +*/ + +namespace Platform +{ + static_assert(sizeof(unsigned int) == 4); + static_assert(sizeof(Keyboard::State::KeyStateData) == 32); + static_assert(sizeof(Keyboard::State) == (32 * 3 + 4)); + + inline bool IsExtendedKey(LPARAM lParam) + { + constexpr LPARAM const bit_mask = KF_EXTENDED << 16; + return (lParam & bit_mask) == bit_mask; + } + + inline bool GetKey(uint32_t state_[8], uint8_t vk) + { + uint32_t const index = (vk & 0x7FFFFFE0u) >> 5u; + uint32_t const bitmk = 1u << (vk & 0x0000001Fu); + return (state_[index] & bitmk) == bitmk; + } +#if PLATFORM_KEYBOARD_USING_ATOMIC + inline void AtomicSetKey(std::atomic_uint32_t state_[8], uint8_t vk, bool down) + { + uint32_t const index = (vk & 0x7FFFFFE0u) >> 5u; + uint32_t const bitmk = 1u << (vk & 0x0000001Fu); + if (down) + state_[index].fetch_or(bitmk); + else + state_[index].fetch_and(~bitmk); + } +#else + inline void AtomicSetKey(uint32_t state_[8], uint8_t vk, bool down) + { + uint32_t const index = (vk & 0x7FFFFFE0u) >> 5u; + uint32_t const bitmk = 1u << (vk & 0x0000001Fu); + if (down) + state_[index] |= bitmk; + else + state_[index] &= (~bitmk); + } +#endif + + constexpr uint8_t const VK_NUMPADENTER = 0xE8u; // Unassigned Virtual-Key Code + + void Keyboard::State::Reset() + { + std::memset(this, 0, sizeof(State)); + } + bool Keyboard::State::IsKeyDown(Keyboard::Key key, bool include_history) + { + return GetKey(include_history ? KeyDown.Data : KeyState.Data, static_cast(key)); + } + bool Keyboard::State::IsKeyUp(Keyboard::Key key, bool include_history) + { + return GetKey(include_history ? KeyUp.Data : KeyState.Data, static_cast(key)); + } + + void Keyboard::Reset() + { + #if PLATFORM_KEYBOARD_USING_ATOMIC + KeyState[0].store(0u); + KeyState[1].store(0u); + KeyState[2].store(0u); + KeyState[3].store(0u); + KeyState[4].store(0u); + KeyState[5].store(0u); + KeyState[6].store(0u); + KeyState[7].store(0u); + #else + KeyState[0] = (0u); + KeyState[1] = (0u); + KeyState[2] = (0u); + KeyState[3] = (0u); + KeyState[4] = (0u); + KeyState[5] = (0u); + KeyState[6] = (0u); + KeyState[7] = (0u); + #endif + ResetFrame(); + _Padding[0] = 0; + _Padding[1] = 0; + } + void Keyboard::ResetFrame() + { + #if PLATFORM_KEYBOARD_USING_ATOMIC + KeyDown[0].store(0u); + KeyDown[1].store(0u); + KeyDown[2].store(0u); + KeyDown[3].store(0u); + KeyDown[4].store(0u); + KeyDown[5].store(0u); + KeyDown[6].store(0u); + KeyDown[7].store(0u); + KeyUp[0].store(0u); + KeyUp[1].store(0u); + KeyUp[2].store(0u); + KeyUp[3].store(0u); + KeyUp[4].store(0u); + KeyUp[5].store(0u); + KeyUp[6].store(0u); + KeyUp[7].store(0u); + LastKeyDown.store(0u); + LastKeyUp.store(0u); + #else + KeyDown[0] = (0u); + KeyDown[1] = (0u); + KeyDown[2] = (0u); + KeyDown[3] = (0u); + KeyDown[4] = (0u); + KeyDown[5] = (0u); + KeyDown[6] = (0u); + KeyDown[7] = (0u); + KeyUp[0] = (0u); + KeyUp[1] = (0u); + KeyUp[2] = (0u); + KeyUp[3] = (0u); + KeyUp[4] = (0u); + KeyUp[5] = (0u); + KeyUp[6] = (0u); + KeyUp[7] = (0u); + LastKeyDown = (0u); + LastKeyUp = (0u); + #endif + } + + Keyboard::State Keyboard::GetState(bool new_frame) + { + Keyboard::State Copy = {}; + GetState(Copy, new_frame); + return Copy; + } + void Keyboard::GetState(Keyboard::State& Ref, bool new_frame) + { + #if PLATFORM_KEYBOARD_USING_ATOMIC + Ref.KeyState.Data[0] = KeyState[0].load(); + Ref.KeyState.Data[1] = KeyState[1].load(); + Ref.KeyState.Data[2] = KeyState[2].load(); + Ref.KeyState.Data[3] = KeyState[3].load(); + Ref.KeyState.Data[4] = KeyState[4].load(); + Ref.KeyState.Data[5] = KeyState[5].load(); + Ref.KeyState.Data[6] = KeyState[6].load(); + Ref.KeyState.Data[7] = KeyState[7].load(); + if (new_frame) + { + Ref.KeyDown.Data[0] = KeyDown[0].exchange(0u); + Ref.KeyDown.Data[1] = KeyDown[1].exchange(0u); + Ref.KeyDown.Data[2] = KeyDown[2].exchange(0u); + Ref.KeyDown.Data[3] = KeyDown[3].exchange(0u); + Ref.KeyDown.Data[4] = KeyDown[4].exchange(0u); + Ref.KeyDown.Data[5] = KeyDown[5].exchange(0u); + Ref.KeyDown.Data[6] = KeyDown[6].exchange(0u); + Ref.KeyDown.Data[7] = KeyDown[7].exchange(0u); + Ref.KeyUp.Data[0] = KeyUp[0].exchange(0u); + Ref.KeyUp.Data[1] = KeyUp[1].exchange(0u); + Ref.KeyUp.Data[2] = KeyUp[2].exchange(0u); + Ref.KeyUp.Data[3] = KeyUp[3].exchange(0u); + Ref.KeyUp.Data[4] = KeyUp[4].exchange(0u); + Ref.KeyUp.Data[5] = KeyUp[5].exchange(0u); + Ref.KeyUp.Data[6] = KeyUp[6].exchange(0u); + Ref.KeyUp.Data[7] = KeyUp[7].exchange(0u); + Ref.LastKeyDown = static_cast(LastKeyDown.exchange(0)); + Ref.LastKeyUp = static_cast(LastKeyUp.exchange(0)); + } + else + { + Ref.KeyDown.Data[0] = KeyDown[0].load(); + Ref.KeyDown.Data[1] = KeyDown[1].load(); + Ref.KeyDown.Data[2] = KeyDown[2].load(); + Ref.KeyDown.Data[3] = KeyDown[3].load(); + Ref.KeyDown.Data[4] = KeyDown[4].load(); + Ref.KeyDown.Data[5] = KeyDown[5].load(); + Ref.KeyDown.Data[6] = KeyDown[6].load(); + Ref.KeyDown.Data[7] = KeyDown[7].load(); + Ref.KeyUp.Data[0] = KeyUp[0].load(); + Ref.KeyUp.Data[1] = KeyUp[1].load(); + Ref.KeyUp.Data[2] = KeyUp[2].load(); + Ref.KeyUp.Data[3] = KeyUp[3].load(); + Ref.KeyUp.Data[4] = KeyUp[4].load(); + Ref.KeyUp.Data[5] = KeyUp[5].load(); + Ref.KeyUp.Data[6] = KeyUp[6].load(); + Ref.KeyUp.Data[7] = KeyUp[7].load(); + Ref.LastKeyDown = static_cast(LastKeyDown.load()); + Ref.LastKeyUp = static_cast(LastKeyUp.load()); + } + #else + Ref.KeyState.Data[0] = KeyState[0]; + Ref.KeyState.Data[1] = KeyState[1]; + Ref.KeyState.Data[2] = KeyState[2]; + Ref.KeyState.Data[3] = KeyState[3]; + Ref.KeyState.Data[4] = KeyState[4]; + Ref.KeyState.Data[5] = KeyState[5]; + Ref.KeyState.Data[6] = KeyState[6]; + Ref.KeyState.Data[7] = KeyState[7]; + Ref.KeyDown.Data[0] = KeyDown[0]; + Ref.KeyDown.Data[1] = KeyDown[1]; + Ref.KeyDown.Data[2] = KeyDown[2]; + Ref.KeyDown.Data[3] = KeyDown[3]; + Ref.KeyDown.Data[4] = KeyDown[4]; + Ref.KeyDown.Data[5] = KeyDown[5]; + Ref.KeyDown.Data[6] = KeyDown[6]; + Ref.KeyDown.Data[7] = KeyDown[7]; + Ref.KeyUp.Data[0] = KeyUp[0]; + Ref.KeyUp.Data[1] = KeyUp[1]; + Ref.KeyUp.Data[2] = KeyUp[2]; + Ref.KeyUp.Data[3] = KeyUp[3]; + Ref.KeyUp.Data[4] = KeyUp[4]; + Ref.KeyUp.Data[5] = KeyUp[5]; + Ref.KeyUp.Data[6] = KeyUp[6]; + Ref.KeyUp.Data[7] = KeyUp[7]; + Ref.LastKeyDown = static_cast(LastKeyDown); + Ref.LastKeyUp = static_cast(LastKeyUp); + if (new_frame) + { + ResetFrame(); + } + #endif + } + + void Keyboard::ProcessMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) + { + std::ignore = hWnd; + bool down = false; + switch (uMsg) + { + default: + return; // ignore other message + case WM_ACTIVATE: + case WM_ACTIVATEAPP: + Reset(); + return; // skip + case WM_KEYDOWN: + case WM_SYSKEYDOWN: + down = true; + break; + case WM_KEYUP: + case WM_SYSKEYUP: + down = false; + break; + } + if (wParam > 0xFFu) + { + return; // ignore unknown key code + } + uint8_t const vk = wParam & 0xFFu; + uint8_t vk_translated = vk; + switch (vk) + { + case VK_RETURN: + vk_translated = IsExtendedKey(lParam) ? VK_NUMPADENTER : VK_RETURN; + break; + case VK_SHIFT: + vk_translated = IsExtendedKey(lParam) ? VK_RSHIFT : VK_LSHIFT; + if (!down) + { + // Windows system feature :( + AtomicSetKey(KeyState, VK_RSHIFT, false); + AtomicSetKey(KeyState, VK_LSHIFT, false); + } + break; + case VK_CONTROL: + vk_translated = IsExtendedKey(lParam) ? VK_RCONTROL : VK_LCONTROL; + break; + case VK_MENU: + vk_translated = IsExtendedKey(lParam) ? VK_RMENU : VK_LMENU; + break; + } + AtomicSetKey(KeyState, vk, down); + if (vk != vk_translated) + { + AtomicSetKey(KeyState, vk_translated, down); + } + if (down) + { + AtomicSetKey(KeyDown, vk_translated, true); + #if PLATFORM_KEYBOARD_USING_ATOMIC + LastKeyDown.store(vk_translated); + #else + LastKeyDown = (vk_translated); + #endif + } + else + { + AtomicSetKey(KeyUp, vk_translated, true); + #if PLATFORM_KEYBOARD_USING_ATOMIC + LastKeyUp.store(vk_translated); + #else + LastKeyUp = (vk_translated); + #endif + } + } +} diff --git a/LuaSTG/Platform/Keyboard.hpp b/engine/win32/windows/Keyboard.hpp similarity index 96% rename from LuaSTG/Platform/Keyboard.hpp rename to engine/win32/windows/Keyboard.hpp index c83e7daf..833fce7c 100644 --- a/LuaSTG/Platform/Keyboard.hpp +++ b/engine/win32/windows/Keyboard.hpp @@ -1,434 +1,434 @@ -#pragma once -// Single/Multi Thread Model Keyboard Input - -#define PLATFORM_KEYBOARD_USING_ATOMIC 0 - -#if PLATFORM_KEYBOARD_USING_ATOMIC -#include -#else -#include -#endif - -namespace Platform -{ - class Keyboard - { - public: - // from DirectXTK Keyboard.h - enum Key : uint8_t - { - None = 0, - - Back = 0x8, - Tab = 0x9, - - Enter = 0xd, - - Pause = 0x13, - CapsLock = 0x14, - Kana = 0x15, - ImeOn = 0x16, - - Kanji = 0x19, - - ImeOff = 0x1a, - Escape = 0x1b, - ImeConvert = 0x1c, - ImeNoConvert = 0x1d, - - Space = 0x20, - PageUp = 0x21, - PageDown = 0x22, - End = 0x23, - Home = 0x24, - Left = 0x25, - Up = 0x26, - Right = 0x27, - Down = 0x28, - Select = 0x29, - Print = 0x2a, - Execute = 0x2b, - PrintScreen = 0x2c, - Insert = 0x2d, - Delete = 0x2e, - Help = 0x2f, - D0 = 0x30, - D1 = 0x31, - D2 = 0x32, - D3 = 0x33, - D4 = 0x34, - D5 = 0x35, - D6 = 0x36, - D7 = 0x37, - D8 = 0x38, - D9 = 0x39, - - A = 0x41, - B = 0x42, - C = 0x43, - D = 0x44, - E = 0x45, - F = 0x46, - G = 0x47, - H = 0x48, - I = 0x49, - J = 0x4a, - K = 0x4b, - L = 0x4c, - M = 0x4d, - N = 0x4e, - O = 0x4f, - P = 0x50, - Q = 0x51, - R = 0x52, - S = 0x53, - T = 0x54, - U = 0x55, - V = 0x56, - W = 0x57, - X = 0x58, - Y = 0x59, - Z = 0x5a, - LeftWindows = 0x5b, - RightWindows = 0x5c, - Apps = 0x5d, - - Sleep = 0x5f, - NumPad0 = 0x60, - NumPad1 = 0x61, - NumPad2 = 0x62, - NumPad3 = 0x63, - NumPad4 = 0x64, - NumPad5 = 0x65, - NumPad6 = 0x66, - NumPad7 = 0x67, - NumPad8 = 0x68, - NumPad9 = 0x69, - Multiply = 0x6a, - Add = 0x6b, - Separator = 0x6c, - Subtract = 0x6d, - - Decimal = 0x6e, - Divide = 0x6f, - F1 = 0x70, - F2 = 0x71, - F3 = 0x72, - F4 = 0x73, - F5 = 0x74, - F6 = 0x75, - F7 = 0x76, - F8 = 0x77, - F9 = 0x78, - F10 = 0x79, - F11 = 0x7a, - F12 = 0x7b, - F13 = 0x7c, - F14 = 0x7d, - F15 = 0x7e, - F16 = 0x7f, - F17 = 0x80, - F18 = 0x81, - F19 = 0x82, - F20 = 0x83, - F21 = 0x84, - F22 = 0x85, - F23 = 0x86, - F24 = 0x87, - - NumLock = 0x90, - Scroll = 0x91, - - LeftShift = 0xa0, - RightShift = 0xa1, - LeftControl = 0xa2, - RightControl = 0xa3, - LeftAlt = 0xa4, - RightAlt = 0xa5, - BrowserBack = 0xa6, - BrowserForward = 0xa7, - BrowserRefresh = 0xa8, - BrowserStop = 0xa9, - BrowserSearch = 0xaa, - BrowserFavorites = 0xab, - BrowserHome = 0xac, - VolumeMute = 0xad, - VolumeDown = 0xae, - VolumeUp = 0xaf, - MediaNextTrack = 0xb0, - MediaPreviousTrack = 0xb1, - MediaStop = 0xb2, - MediaPlayPause = 0xb3, - LaunchMail = 0xb4, - SelectMedia = 0xb5, - LaunchApplication1 = 0xb6, - LaunchApplication2 = 0xb7, - - OemSemicolon = 0xba, - OemPlus = 0xbb, - OemComma = 0xbc, - OemMinus = 0xbd, - OemPeriod = 0xbe, - OemQuestion = 0xbf, - OemTilde = 0xc0, - - OemOpenBrackets = 0xdb, - OemPipe = 0xdc, - OemCloseBrackets = 0xdd, - OemQuotes = 0xde, - Oem8 = 0xdf, - - OemBackslash = 0xe2, - - ProcessKey = 0xe5, - NumPadEnter = 0xe8, // [borrowed location] - - OemCopy = 0xf2, - OemAuto = 0xf3, - OemEnlW = 0xf4, - - Attn = 0xf6, - Crsel = 0xf7, - Exsel = 0xf8, - EraseEof = 0xf9, - Play = 0xfa, - Zoom = 0xfb, - - Pa1 = 0xfd, - OemClear = 0xfe, - }; - struct State - { - union KeyStateData - { - // from DirectXTK Keyboard.h - struct - { - uint8_t Reserved0 : 8; - uint8_t Back : 1; // VK_BACK, 0x8 - uint8_t Tab : 1; // VK_TAB, 0x9 - uint8_t Reserved1 : 3; - uint8_t Enter : 1; // VK_RETURN, 0xD - uint8_t Reserved2 : 2; - uint8_t Reserved3 : 3; - uint8_t Pause : 1; // VK_PAUSE, 0x13 - uint8_t CapsLock : 1; // VK_CAPITAL, 0x14 - uint8_t Kana : 1; // VK_KANA, 0x15 - uint8_t ImeOn : 1; // VK_IME_ON, 0x16 - uint8_t Reserved4 : 1; - uint8_t Reserved5 : 1; - uint8_t Kanji : 1; // VK_KANJI, 0x19 - uint8_t ImeOff : 1; // VK_IME_OFF, 0X1A - uint8_t Escape : 1; // VK_ESCAPE, 0x1B - uint8_t ImeConvert : 1; // VK_CONVERT, 0x1C - uint8_t ImeNoConvert : 1; // VK_NONCONVERT, 0x1D - uint8_t Reserved7 : 2; - uint8_t Space : 1; // VK_SPACE, 0x20 - uint8_t PageUp : 1; // VK_PRIOR, 0x21 - uint8_t PageDown : 1; // VK_NEXT, 0x22 - uint8_t End : 1; // VK_END, 0x23 - uint8_t Home : 1; // VK_HOME, 0x24 - uint8_t Left : 1; // VK_LEFT, 0x25 - uint8_t Up : 1; // VK_UP, 0x26 - uint8_t Right : 1; // VK_RIGHT, 0x27 - uint8_t Down : 1; // VK_DOWN, 0x28 - uint8_t Select : 1; // VK_SELECT, 0x29 - uint8_t Print : 1; // VK_PRINT, 0x2A - uint8_t Execute : 1; // VK_EXECUTE, 0x2B - uint8_t PrintScreen : 1; // VK_SNAPSHOT, 0x2C - uint8_t Insert : 1; // VK_INSERT, 0x2D - uint8_t Delete : 1; // VK_DELETE, 0x2E - uint8_t Help : 1; // VK_HELP, 0x2F - uint8_t D0 : 1; // 0x30 - uint8_t D1 : 1; // 0x31 - uint8_t D2 : 1; // 0x32 - uint8_t D3 : 1; // 0x33 - uint8_t D4 : 1; // 0x34 - uint8_t D5 : 1; // 0x35 - uint8_t D6 : 1; // 0x36 - uint8_t D7 : 1; // 0x37 - uint8_t D8 : 1; // 0x38 - uint8_t D9 : 1; // 0x39 - uint8_t Reserved8 : 6; - uint8_t Reserved9 : 1; - uint8_t A : 1; // 0x41 - uint8_t B : 1; // 0x42 - uint8_t C : 1; // 0x43 - uint8_t D : 1; // 0x44 - uint8_t E : 1; // 0x45 - uint8_t F : 1; // 0x46 - uint8_t G : 1; // 0x47 - uint8_t H : 1; // 0x48 - uint8_t I : 1; // 0x49 - uint8_t J : 1; // 0x4A - uint8_t K : 1; // 0x4B - uint8_t L : 1; // 0x4C - uint8_t M : 1; // 0x4D - uint8_t N : 1; // 0x4E - uint8_t O : 1; // 0x4F - uint8_t P : 1; // 0x50 - uint8_t Q : 1; // 0x51 - uint8_t R : 1; // 0x52 - uint8_t S : 1; // 0x53 - uint8_t T : 1; // 0x54 - uint8_t U : 1; // 0x55 - uint8_t V : 1; // 0x56 - uint8_t W : 1; // 0x57 - uint8_t X : 1; // 0x58 - uint8_t Y : 1; // 0x59 - uint8_t Z : 1; // 0x5A - uint8_t LeftWindows : 1; // VK_LWIN, 0x5B - uint8_t RightWindows : 1; // VK_RWIN, 0x5C - uint8_t Apps : 1; // VK_APPS, 0x5D - uint8_t Reserved10 : 1; - uint8_t Sleep : 1; // VK_SLEEP, 0x5F - uint8_t NumPad0 : 1; // VK_NUMPAD0, 0x60 - uint8_t NumPad1 : 1; // VK_NUMPAD1, 0x61 - uint8_t NumPad2 : 1; // VK_NUMPAD2, 0x62 - uint8_t NumPad3 : 1; // VK_NUMPAD3, 0x63 - uint8_t NumPad4 : 1; // VK_NUMPAD4, 0x64 - uint8_t NumPad5 : 1; // VK_NUMPAD5, 0x65 - uint8_t NumPad6 : 1; // VK_NUMPAD6, 0x66 - uint8_t NumPad7 : 1; // VK_NUMPAD7, 0x67 - uint8_t NumPad8 : 1; // VK_NUMPAD8, 0x68 - uint8_t NumPad9 : 1; // VK_NUMPAD9, 0x69 - uint8_t Multiply : 1; // VK_MULTIPLY, 0x6A - uint8_t Add : 1; // VK_ADD, 0x6B - uint8_t Separator : 1; // VK_SEPARATOR, 0x6C - uint8_t Subtract : 1; // VK_SUBTRACT, 0x6D - uint8_t Decimal : 1; // VK_DECIMANL, 0x6E - uint8_t Divide : 1; // VK_DIVIDE, 0x6F - uint8_t F1 : 1; // VK_F1, 0x70 - uint8_t F2 : 1; // VK_F2, 0x71 - uint8_t F3 : 1; // VK_F3, 0x72 - uint8_t F4 : 1; // VK_F4, 0x73 - uint8_t F5 : 1; // VK_F5, 0x74 - uint8_t F6 : 1; // VK_F6, 0x75 - uint8_t F7 : 1; // VK_F7, 0x76 - uint8_t F8 : 1; // VK_F8, 0x77 - uint8_t F9 : 1; // VK_F9, 0x78 - uint8_t F10 : 1; // VK_F10, 0x79 - uint8_t F11 : 1; // VK_F11, 0x7A - uint8_t F12 : 1; // VK_F12, 0x7B - uint8_t F13 : 1; // VK_F13, 0x7C - uint8_t F14 : 1; // VK_F14, 0x7D - uint8_t F15 : 1; // VK_F15, 0x7E - uint8_t F16 : 1; // VK_F16, 0x7F - uint8_t F17 : 1; // VK_F17, 0x80 - uint8_t F18 : 1; // VK_F18, 0x81 - uint8_t F19 : 1; // VK_F19, 0x82 - uint8_t F20 : 1; // VK_F20, 0x83 - uint8_t F21 : 1; // VK_F21, 0x84 - uint8_t F22 : 1; // VK_F22, 0x85 - uint8_t F23 : 1; // VK_F23, 0x86 - uint8_t F24 : 1; // VK_F24, 0x87 - uint8_t Reserved11 : 8; - uint8_t NumLock : 1; // VK_NUMLOCK, 0x90 - uint8_t Scroll : 1; // VK_SCROLL, 0x91 - uint8_t Reserved12 : 6; - uint8_t Reserved13 : 8; - uint8_t LeftShift : 1; // VK_LSHIFT, 0xA0 - uint8_t RightShift : 1; // VK_RSHIFT, 0xA1 - uint8_t LeftControl : 1; // VK_LCONTROL, 0xA2 - uint8_t RightControl : 1; // VK_RCONTROL, 0xA3 - uint8_t LeftAlt : 1; // VK_LMENU, 0xA4 - uint8_t RightAlt : 1; // VK_RMENU, 0xA5 - uint8_t BrowserBack : 1; // VK_BROWSER_BACK, 0xA6 - uint8_t BrowserForward : 1; // VK_BROWSER_FORWARD, 0xA7 - uint8_t BrowserRefresh : 1; // VK_BROWSER_REFRESH, 0xA8 - uint8_t BrowserStop : 1; // VK_BROWSER_STOP, 0xA9 - uint8_t BrowserSearch : 1; // VK_BROWSER_SEARCH, 0xAA - uint8_t BrowserFavorites : 1; // VK_BROWSER_FAVORITES, 0xAB - uint8_t BrowserHome : 1; // VK_BROWSER_HOME, 0xAC - uint8_t VolumeMute : 1; // VK_VOLUME_MUTE, 0xAD - uint8_t VolumeDown : 1; // VK_VOLUME_DOWN, 0xAE - uint8_t VolumeUp : 1; // VK_VOLUME_UP, 0xAF - uint8_t MediaNextTrack : 1; // VK_MEDIA_NEXT_TRACK, 0xB0 - uint8_t MediaPreviousTrack : 1;// VK_MEDIA_PREV_TRACK, 0xB1 - uint8_t MediaStop : 1; // VK_MEDIA_STOP, 0xB2 - uint8_t MediaPlayPause : 1; // VK_MEDIA_PLAY_PAUSE, 0xB3 - uint8_t LaunchMail : 1; // VK_LAUNCH_MAIL, 0xB4 - uint8_t SelectMedia : 1; // VK_LAUNCH_MEDIA_SELECT, 0xB5 - uint8_t LaunchApplication1 : 1;// VK_LAUNCH_APP1, 0xB6 - uint8_t LaunchApplication2 : 1;// VK_LAUNCH_APP2, 0xB7 - uint8_t Reserved14 : 2; - uint8_t OemSemicolon : 1; // VK_OEM_1, 0xBA - uint8_t OemPlus : 1; // VK_OEM_PLUS, 0xBB - uint8_t OemComma : 1; // VK_OEM_COMMA, 0xBC - uint8_t OemMinus : 1; // VK_OEM_MINUS, 0xBD - uint8_t OemPeriod : 1; // VK_OEM_PERIOD, 0xBE - uint8_t OemQuestion : 1; // VK_OEM_2, 0xBF - uint8_t OemTilde : 1; // VK_OEM_3, 0xC0 - uint8_t Reserved15 : 7; - uint8_t Reserved16 : 8; - uint8_t Reserved17 : 8; - uint8_t Reserved18 : 3; - uint8_t OemOpenBrackets : 1; // VK_OEM_4, 0xDB - uint8_t OemPipe : 1; // VK_OEM_5, 0xDC - uint8_t OemCloseBrackets : 1; // VK_OEM_6, 0xDD - uint8_t OemQuotes : 1; // VK_OEM_7, 0xDE - uint8_t Oem8 : 1; // VK_OEM_8, 0xDF - uint8_t Reserved19 : 2; - uint8_t OemBackslash : 1; // VK_OEM_102, 0xE2 - uint8_t Reserved20 : 2; - uint8_t ProcessKey : 1; // VK_PROCESSKEY, 0xE5 - uint8_t Reserved21 : 2; - uint8_t NumPadEnter : 1; // [borrowed location], 0xE8 VK_NUMPADENTER - uint8_t Reserved22 : 7; - uint8_t Reserved23 : 2; - uint8_t OemCopy : 1; // 0XF2 - uint8_t OemAuto : 1; // 0xF3 - uint8_t OemEnlW : 1; // 0xF4 - uint8_t Reserved24 : 1; - uint8_t Attn : 1; // VK_ATTN, 0xF6 - uint8_t Crsel : 1; // VK_CRSEL, 0xF7 - uint8_t Exsel : 1; // VK_EXSEL, 0xF8 - uint8_t EraseEof : 1; // VK_EREOF, 0xF9 - uint8_t Play : 1; // VK_PLAY, 0xFA - uint8_t Zoom : 1; // VK_ZOOM, 0xFB - uint8_t Reserved25 : 1; - uint8_t Pa1 : 1; // VK_PA1, 0xFD - uint8_t OemClear : 1; // VK_OEM_CLEAR, 0xFE - uint8_t Reserved26 : 1; - } Key; - uint32_t Data[8]; - }; - - KeyStateData KeyState; - KeyStateData KeyDown; - KeyStateData KeyUp; - Key LastKeyDown; - Key LastKeyUp; - uint8_t _Padding[2]; - - void Reset(); - bool IsKeyDown(Key key, bool include_history = false); - bool IsKeyUp(Key key, bool include_history = false); - }; - private: - #if PLATFORM_KEYBOARD_USING_ATOMIC - std::atomic_uint32_t KeyState[8]{}; - std::atomic_uint32_t KeyDown[8]{}; - std::atomic_uint32_t KeyUp[8]{}; - std::atomic_uint8_t LastKeyDown{}; - std::atomic_uint8_t LastKeyUp{}; - #else - uint32_t KeyState[8]{}; - uint32_t KeyDown[8]{}; - uint32_t KeyUp[8]{}; - uint8_t LastKeyDown{}; - uint8_t LastKeyUp{}; - #endif - uint8_t _Padding[2]{}; - public: - void Reset(); - void ResetFrame(); - State GetState(bool new_frame = false); - void GetState(State& Ref, bool new_frame = false); - #ifdef WM_USER - void ProcessMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); - #else - void ProcessMessage(void*, unsigned int, void*, void*); - #endif - }; -} +#pragma once +// Single/Multi Thread Model Keyboard Input + +#define PLATFORM_KEYBOARD_USING_ATOMIC 0 + +#if PLATFORM_KEYBOARD_USING_ATOMIC +#include +#else +#include +#endif + +namespace Platform +{ + class Keyboard + { + public: + // from DirectXTK Keyboard.h + enum Key : uint8_t + { + None = 0, + + Back = 0x8, + Tab = 0x9, + + Enter = 0xd, + + Pause = 0x13, + CapsLock = 0x14, + Kana = 0x15, + ImeOn = 0x16, + + Kanji = 0x19, + + ImeOff = 0x1a, + Escape = 0x1b, + ImeConvert = 0x1c, + ImeNoConvert = 0x1d, + + Space = 0x20, + PageUp = 0x21, + PageDown = 0x22, + End = 0x23, + Home = 0x24, + Left = 0x25, + Up = 0x26, + Right = 0x27, + Down = 0x28, + Select = 0x29, + Print = 0x2a, + Execute = 0x2b, + PrintScreen = 0x2c, + Insert = 0x2d, + Delete = 0x2e, + Help = 0x2f, + D0 = 0x30, + D1 = 0x31, + D2 = 0x32, + D3 = 0x33, + D4 = 0x34, + D5 = 0x35, + D6 = 0x36, + D7 = 0x37, + D8 = 0x38, + D9 = 0x39, + + A = 0x41, + B = 0x42, + C = 0x43, + D = 0x44, + E = 0x45, + F = 0x46, + G = 0x47, + H = 0x48, + I = 0x49, + J = 0x4a, + K = 0x4b, + L = 0x4c, + M = 0x4d, + N = 0x4e, + O = 0x4f, + P = 0x50, + Q = 0x51, + R = 0x52, + S = 0x53, + T = 0x54, + U = 0x55, + V = 0x56, + W = 0x57, + X = 0x58, + Y = 0x59, + Z = 0x5a, + LeftWindows = 0x5b, + RightWindows = 0x5c, + Apps = 0x5d, + + Sleep = 0x5f, + NumPad0 = 0x60, + NumPad1 = 0x61, + NumPad2 = 0x62, + NumPad3 = 0x63, + NumPad4 = 0x64, + NumPad5 = 0x65, + NumPad6 = 0x66, + NumPad7 = 0x67, + NumPad8 = 0x68, + NumPad9 = 0x69, + Multiply = 0x6a, + Add = 0x6b, + Separator = 0x6c, + Subtract = 0x6d, + + Decimal = 0x6e, + Divide = 0x6f, + F1 = 0x70, + F2 = 0x71, + F3 = 0x72, + F4 = 0x73, + F5 = 0x74, + F6 = 0x75, + F7 = 0x76, + F8 = 0x77, + F9 = 0x78, + F10 = 0x79, + F11 = 0x7a, + F12 = 0x7b, + F13 = 0x7c, + F14 = 0x7d, + F15 = 0x7e, + F16 = 0x7f, + F17 = 0x80, + F18 = 0x81, + F19 = 0x82, + F20 = 0x83, + F21 = 0x84, + F22 = 0x85, + F23 = 0x86, + F24 = 0x87, + + NumLock = 0x90, + Scroll = 0x91, + + LeftShift = 0xa0, + RightShift = 0xa1, + LeftControl = 0xa2, + RightControl = 0xa3, + LeftAlt = 0xa4, + RightAlt = 0xa5, + BrowserBack = 0xa6, + BrowserForward = 0xa7, + BrowserRefresh = 0xa8, + BrowserStop = 0xa9, + BrowserSearch = 0xaa, + BrowserFavorites = 0xab, + BrowserHome = 0xac, + VolumeMute = 0xad, + VolumeDown = 0xae, + VolumeUp = 0xaf, + MediaNextTrack = 0xb0, + MediaPreviousTrack = 0xb1, + MediaStop = 0xb2, + MediaPlayPause = 0xb3, + LaunchMail = 0xb4, + SelectMedia = 0xb5, + LaunchApplication1 = 0xb6, + LaunchApplication2 = 0xb7, + + OemSemicolon = 0xba, + OemPlus = 0xbb, + OemComma = 0xbc, + OemMinus = 0xbd, + OemPeriod = 0xbe, + OemQuestion = 0xbf, + OemTilde = 0xc0, + + OemOpenBrackets = 0xdb, + OemPipe = 0xdc, + OemCloseBrackets = 0xdd, + OemQuotes = 0xde, + Oem8 = 0xdf, + + OemBackslash = 0xe2, + + ProcessKey = 0xe5, + NumPadEnter = 0xe8, // [borrowed location] + + OemCopy = 0xf2, + OemAuto = 0xf3, + OemEnlW = 0xf4, + + Attn = 0xf6, + Crsel = 0xf7, + Exsel = 0xf8, + EraseEof = 0xf9, + Play = 0xfa, + Zoom = 0xfb, + + Pa1 = 0xfd, + OemClear = 0xfe, + }; + struct State + { + union KeyStateData + { + // from DirectXTK Keyboard.h + struct + { + uint8_t Reserved0 : 8; + uint8_t Back : 1; // VK_BACK, 0x8 + uint8_t Tab : 1; // VK_TAB, 0x9 + uint8_t Reserved1 : 3; + uint8_t Enter : 1; // VK_RETURN, 0xD + uint8_t Reserved2 : 2; + uint8_t Reserved3 : 3; + uint8_t Pause : 1; // VK_PAUSE, 0x13 + uint8_t CapsLock : 1; // VK_CAPITAL, 0x14 + uint8_t Kana : 1; // VK_KANA, 0x15 + uint8_t ImeOn : 1; // VK_IME_ON, 0x16 + uint8_t Reserved4 : 1; + uint8_t Reserved5 : 1; + uint8_t Kanji : 1; // VK_KANJI, 0x19 + uint8_t ImeOff : 1; // VK_IME_OFF, 0X1A + uint8_t Escape : 1; // VK_ESCAPE, 0x1B + uint8_t ImeConvert : 1; // VK_CONVERT, 0x1C + uint8_t ImeNoConvert : 1; // VK_NONCONVERT, 0x1D + uint8_t Reserved7 : 2; + uint8_t Space : 1; // VK_SPACE, 0x20 + uint8_t PageUp : 1; // VK_PRIOR, 0x21 + uint8_t PageDown : 1; // VK_NEXT, 0x22 + uint8_t End : 1; // VK_END, 0x23 + uint8_t Home : 1; // VK_HOME, 0x24 + uint8_t Left : 1; // VK_LEFT, 0x25 + uint8_t Up : 1; // VK_UP, 0x26 + uint8_t Right : 1; // VK_RIGHT, 0x27 + uint8_t Down : 1; // VK_DOWN, 0x28 + uint8_t Select : 1; // VK_SELECT, 0x29 + uint8_t Print : 1; // VK_PRINT, 0x2A + uint8_t Execute : 1; // VK_EXECUTE, 0x2B + uint8_t PrintScreen : 1; // VK_SNAPSHOT, 0x2C + uint8_t Insert : 1; // VK_INSERT, 0x2D + uint8_t Delete : 1; // VK_DELETE, 0x2E + uint8_t Help : 1; // VK_HELP, 0x2F + uint8_t D0 : 1; // 0x30 + uint8_t D1 : 1; // 0x31 + uint8_t D2 : 1; // 0x32 + uint8_t D3 : 1; // 0x33 + uint8_t D4 : 1; // 0x34 + uint8_t D5 : 1; // 0x35 + uint8_t D6 : 1; // 0x36 + uint8_t D7 : 1; // 0x37 + uint8_t D8 : 1; // 0x38 + uint8_t D9 : 1; // 0x39 + uint8_t Reserved8 : 6; + uint8_t Reserved9 : 1; + uint8_t A : 1; // 0x41 + uint8_t B : 1; // 0x42 + uint8_t C : 1; // 0x43 + uint8_t D : 1; // 0x44 + uint8_t E : 1; // 0x45 + uint8_t F : 1; // 0x46 + uint8_t G : 1; // 0x47 + uint8_t H : 1; // 0x48 + uint8_t I : 1; // 0x49 + uint8_t J : 1; // 0x4A + uint8_t K : 1; // 0x4B + uint8_t L : 1; // 0x4C + uint8_t M : 1; // 0x4D + uint8_t N : 1; // 0x4E + uint8_t O : 1; // 0x4F + uint8_t P : 1; // 0x50 + uint8_t Q : 1; // 0x51 + uint8_t R : 1; // 0x52 + uint8_t S : 1; // 0x53 + uint8_t T : 1; // 0x54 + uint8_t U : 1; // 0x55 + uint8_t V : 1; // 0x56 + uint8_t W : 1; // 0x57 + uint8_t X : 1; // 0x58 + uint8_t Y : 1; // 0x59 + uint8_t Z : 1; // 0x5A + uint8_t LeftWindows : 1; // VK_LWIN, 0x5B + uint8_t RightWindows : 1; // VK_RWIN, 0x5C + uint8_t Apps : 1; // VK_APPS, 0x5D + uint8_t Reserved10 : 1; + uint8_t Sleep : 1; // VK_SLEEP, 0x5F + uint8_t NumPad0 : 1; // VK_NUMPAD0, 0x60 + uint8_t NumPad1 : 1; // VK_NUMPAD1, 0x61 + uint8_t NumPad2 : 1; // VK_NUMPAD2, 0x62 + uint8_t NumPad3 : 1; // VK_NUMPAD3, 0x63 + uint8_t NumPad4 : 1; // VK_NUMPAD4, 0x64 + uint8_t NumPad5 : 1; // VK_NUMPAD5, 0x65 + uint8_t NumPad6 : 1; // VK_NUMPAD6, 0x66 + uint8_t NumPad7 : 1; // VK_NUMPAD7, 0x67 + uint8_t NumPad8 : 1; // VK_NUMPAD8, 0x68 + uint8_t NumPad9 : 1; // VK_NUMPAD9, 0x69 + uint8_t Multiply : 1; // VK_MULTIPLY, 0x6A + uint8_t Add : 1; // VK_ADD, 0x6B + uint8_t Separator : 1; // VK_SEPARATOR, 0x6C + uint8_t Subtract : 1; // VK_SUBTRACT, 0x6D + uint8_t Decimal : 1; // VK_DECIMANL, 0x6E + uint8_t Divide : 1; // VK_DIVIDE, 0x6F + uint8_t F1 : 1; // VK_F1, 0x70 + uint8_t F2 : 1; // VK_F2, 0x71 + uint8_t F3 : 1; // VK_F3, 0x72 + uint8_t F4 : 1; // VK_F4, 0x73 + uint8_t F5 : 1; // VK_F5, 0x74 + uint8_t F6 : 1; // VK_F6, 0x75 + uint8_t F7 : 1; // VK_F7, 0x76 + uint8_t F8 : 1; // VK_F8, 0x77 + uint8_t F9 : 1; // VK_F9, 0x78 + uint8_t F10 : 1; // VK_F10, 0x79 + uint8_t F11 : 1; // VK_F11, 0x7A + uint8_t F12 : 1; // VK_F12, 0x7B + uint8_t F13 : 1; // VK_F13, 0x7C + uint8_t F14 : 1; // VK_F14, 0x7D + uint8_t F15 : 1; // VK_F15, 0x7E + uint8_t F16 : 1; // VK_F16, 0x7F + uint8_t F17 : 1; // VK_F17, 0x80 + uint8_t F18 : 1; // VK_F18, 0x81 + uint8_t F19 : 1; // VK_F19, 0x82 + uint8_t F20 : 1; // VK_F20, 0x83 + uint8_t F21 : 1; // VK_F21, 0x84 + uint8_t F22 : 1; // VK_F22, 0x85 + uint8_t F23 : 1; // VK_F23, 0x86 + uint8_t F24 : 1; // VK_F24, 0x87 + uint8_t Reserved11 : 8; + uint8_t NumLock : 1; // VK_NUMLOCK, 0x90 + uint8_t Scroll : 1; // VK_SCROLL, 0x91 + uint8_t Reserved12 : 6; + uint8_t Reserved13 : 8; + uint8_t LeftShift : 1; // VK_LSHIFT, 0xA0 + uint8_t RightShift : 1; // VK_RSHIFT, 0xA1 + uint8_t LeftControl : 1; // VK_LCONTROL, 0xA2 + uint8_t RightControl : 1; // VK_RCONTROL, 0xA3 + uint8_t LeftAlt : 1; // VK_LMENU, 0xA4 + uint8_t RightAlt : 1; // VK_RMENU, 0xA5 + uint8_t BrowserBack : 1; // VK_BROWSER_BACK, 0xA6 + uint8_t BrowserForward : 1; // VK_BROWSER_FORWARD, 0xA7 + uint8_t BrowserRefresh : 1; // VK_BROWSER_REFRESH, 0xA8 + uint8_t BrowserStop : 1; // VK_BROWSER_STOP, 0xA9 + uint8_t BrowserSearch : 1; // VK_BROWSER_SEARCH, 0xAA + uint8_t BrowserFavorites : 1; // VK_BROWSER_FAVORITES, 0xAB + uint8_t BrowserHome : 1; // VK_BROWSER_HOME, 0xAC + uint8_t VolumeMute : 1; // VK_VOLUME_MUTE, 0xAD + uint8_t VolumeDown : 1; // VK_VOLUME_DOWN, 0xAE + uint8_t VolumeUp : 1; // VK_VOLUME_UP, 0xAF + uint8_t MediaNextTrack : 1; // VK_MEDIA_NEXT_TRACK, 0xB0 + uint8_t MediaPreviousTrack : 1;// VK_MEDIA_PREV_TRACK, 0xB1 + uint8_t MediaStop : 1; // VK_MEDIA_STOP, 0xB2 + uint8_t MediaPlayPause : 1; // VK_MEDIA_PLAY_PAUSE, 0xB3 + uint8_t LaunchMail : 1; // VK_LAUNCH_MAIL, 0xB4 + uint8_t SelectMedia : 1; // VK_LAUNCH_MEDIA_SELECT, 0xB5 + uint8_t LaunchApplication1 : 1;// VK_LAUNCH_APP1, 0xB6 + uint8_t LaunchApplication2 : 1;// VK_LAUNCH_APP2, 0xB7 + uint8_t Reserved14 : 2; + uint8_t OemSemicolon : 1; // VK_OEM_1, 0xBA + uint8_t OemPlus : 1; // VK_OEM_PLUS, 0xBB + uint8_t OemComma : 1; // VK_OEM_COMMA, 0xBC + uint8_t OemMinus : 1; // VK_OEM_MINUS, 0xBD + uint8_t OemPeriod : 1; // VK_OEM_PERIOD, 0xBE + uint8_t OemQuestion : 1; // VK_OEM_2, 0xBF + uint8_t OemTilde : 1; // VK_OEM_3, 0xC0 + uint8_t Reserved15 : 7; + uint8_t Reserved16 : 8; + uint8_t Reserved17 : 8; + uint8_t Reserved18 : 3; + uint8_t OemOpenBrackets : 1; // VK_OEM_4, 0xDB + uint8_t OemPipe : 1; // VK_OEM_5, 0xDC + uint8_t OemCloseBrackets : 1; // VK_OEM_6, 0xDD + uint8_t OemQuotes : 1; // VK_OEM_7, 0xDE + uint8_t Oem8 : 1; // VK_OEM_8, 0xDF + uint8_t Reserved19 : 2; + uint8_t OemBackslash : 1; // VK_OEM_102, 0xE2 + uint8_t Reserved20 : 2; + uint8_t ProcessKey : 1; // VK_PROCESSKEY, 0xE5 + uint8_t Reserved21 : 2; + uint8_t NumPadEnter : 1; // [borrowed location], 0xE8 VK_NUMPADENTER + uint8_t Reserved22 : 7; + uint8_t Reserved23 : 2; + uint8_t OemCopy : 1; // 0XF2 + uint8_t OemAuto : 1; // 0xF3 + uint8_t OemEnlW : 1; // 0xF4 + uint8_t Reserved24 : 1; + uint8_t Attn : 1; // VK_ATTN, 0xF6 + uint8_t Crsel : 1; // VK_CRSEL, 0xF7 + uint8_t Exsel : 1; // VK_EXSEL, 0xF8 + uint8_t EraseEof : 1; // VK_EREOF, 0xF9 + uint8_t Play : 1; // VK_PLAY, 0xFA + uint8_t Zoom : 1; // VK_ZOOM, 0xFB + uint8_t Reserved25 : 1; + uint8_t Pa1 : 1; // VK_PA1, 0xFD + uint8_t OemClear : 1; // VK_OEM_CLEAR, 0xFE + uint8_t Reserved26 : 1; + } Key; + uint32_t Data[8]; + }; + + KeyStateData KeyState; + KeyStateData KeyDown; + KeyStateData KeyUp; + Key LastKeyDown; + Key LastKeyUp; + uint8_t _Padding[2]; + + void Reset(); + bool IsKeyDown(Key key, bool include_history = false); + bool IsKeyUp(Key key, bool include_history = false); + }; + private: + #if PLATFORM_KEYBOARD_USING_ATOMIC + std::atomic_uint32_t KeyState[8]{}; + std::atomic_uint32_t KeyDown[8]{}; + std::atomic_uint32_t KeyUp[8]{}; + std::atomic_uint8_t LastKeyDown{}; + std::atomic_uint8_t LastKeyUp{}; + #else + uint32_t KeyState[8]{}; + uint32_t KeyDown[8]{}; + uint32_t KeyUp[8]{}; + uint8_t LastKeyDown{}; + uint8_t LastKeyUp{}; + #endif + uint8_t _Padding[2]{}; + public: + void Reset(); + void ResetFrame(); + State GetState(bool new_frame = false); + void GetState(State& Ref, bool new_frame = false); + #ifdef WM_USER + void ProcessMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + #else + void ProcessMessage(void*, unsigned int, void*, void*); + #endif + }; +} diff --git a/LuaSTG/Platform/KnownDirectory.cpp b/engine/win32/windows/KnownDirectory.cpp similarity index 100% rename from LuaSTG/Platform/KnownDirectory.cpp rename to engine/win32/windows/KnownDirectory.cpp diff --git a/LuaSTG/Platform/KnownDirectory.hpp b/engine/win32/windows/KnownDirectory.hpp similarity index 100% rename from LuaSTG/Platform/KnownDirectory.hpp rename to engine/win32/windows/KnownDirectory.hpp diff --git a/LuaSTG/Platform/MessageBox.cpp b/engine/win32/windows/MessageBox.cpp similarity index 87% rename from LuaSTG/Platform/MessageBox.cpp rename to engine/win32/windows/MessageBox.cpp index aa29daa7..e5fda5d0 100644 --- a/LuaSTG/Platform/MessageBox.cpp +++ b/engine/win32/windows/MessageBox.cpp @@ -1,43 +1,43 @@ -#include "Shared.hpp" -#include "MessageBox.hpp" - -namespace Platform -{ - static bool Show(int type, std::string_view title, std::string_view message, HWND window = NULL) - { - std::wstring wide_title(std::move(to_wide(title))); - std::wstring wide_message(std::move(to_wide(message))); - UINT flags = 0; - switch (type) - { - case 1: - flags |= MB_ICONWARNING; - flags |= MB_OKCANCEL; - break; - case 2: - flags = MB_ICONERROR; - flags |= MB_OK; - break; - default: - assert(false); - break; - } - return IDOK == MessageBoxW(window, wide_message.c_str(), wide_title.c_str(), flags); - } - bool MessageBox::Warning(std::string_view title, std::string_view message) - { - return Show(1, title, message); - } - void MessageBox::Error(std::string_view title, std::string_view message) - { - Show(2, title, message); - } - bool MessageBox::WarningFromWindow(std::string_view title, std::string_view message, void* window) - { - return Show(1, title, message, (HWND)window); - } - void MessageBox::ErrorFromWindow(std::string_view title, std::string_view message, void* window) - { - Show(2, title, message, (HWND)window); - } -} +#include "Shared.hpp" +#include "MessageBox.hpp" + +namespace Platform +{ + static bool Show(int type, std::string_view title, std::string_view message, HWND window = NULL) + { + std::wstring wide_title(to_wide(title)); + std::wstring wide_message(to_wide(message)); + UINT flags = 0; + switch (type) + { + case 1: + flags |= MB_ICONWARNING; + flags |= MB_OKCANCEL; + break; + case 2: + flags = MB_ICONERROR; + flags |= MB_OK; + break; + default: + assert(false); + break; + } + return IDOK == MessageBoxW(window, wide_message.c_str(), wide_title.c_str(), flags); + } + bool MessageBox::Warning(std::string_view title, std::string_view message) + { + return Show(1, title, message); + } + void MessageBox::Error(std::string_view title, std::string_view message) + { + Show(2, title, message); + } + bool MessageBox::WarningFromWindow(std::string_view title, std::string_view message, void* window) + { + return Show(1, title, message, (HWND)window); + } + void MessageBox::ErrorFromWindow(std::string_view title, std::string_view message, void* window) + { + Show(2, title, message, (HWND)window); + } +} diff --git a/LuaSTG/Platform/MessageBox.hpp b/engine/win32/windows/MessageBox.hpp similarity index 96% rename from LuaSTG/Platform/MessageBox.hpp rename to engine/win32/windows/MessageBox.hpp index 1c349b2e..40ec0b70 100644 --- a/LuaSTG/Platform/MessageBox.hpp +++ b/engine/win32/windows/MessageBox.hpp @@ -1,20 +1,20 @@ -#pragma once -#include - -// FUCK MICROSOFT - -#ifdef MessageBox -#undef MessageBox -#endif - -namespace Platform -{ - class MessageBox - { - public: - static bool Warning(std::string_view title, std::string_view message); - static void Error(std::string_view title, std::string_view message); - static bool WarningFromWindow(std::string_view title, std::string_view message, void* window); - static void ErrorFromWindow(std::string_view title, std::string_view message, void* window); - }; -} +#pragma once +#include + +// FUCK MICROSOFT + +#ifdef MessageBox +#undef MessageBox +#endif + +namespace Platform +{ + class MessageBox + { + public: + static bool Warning(std::string_view title, std::string_view message); + static void Error(std::string_view title, std::string_view message); + static bool WarningFromWindow(std::string_view title, std::string_view message, void* window); + static void ErrorFromWindow(std::string_view title, std::string_view message, void* window); + }; +} diff --git a/LuaSTG/Platform/ModuleLoader.hpp b/engine/win32/windows/ModuleLoader.hpp similarity index 95% rename from LuaSTG/Platform/ModuleLoader.hpp rename to engine/win32/windows/ModuleLoader.hpp index d716dad1..4132549f 100644 --- a/LuaSTG/Platform/ModuleLoader.hpp +++ b/engine/win32/windows/ModuleLoader.hpp @@ -1,34 +1,34 @@ -#pragma once -#include - -namespace Platform -{ - class ModuleLoader - { - private: - #ifdef _MINWINDEF_ - HMODULE m_module{}; - #else - void* m_module{}; - #endif - public: - #ifdef _MINWINDEF_ - HRESULT Load(std::string_view const name, bool search_only_in_system); - #else - long Load(std::string_view const name, bool search_only_in_system); - #endif - void* GetFunction(std::string_view const name); - template - F* GetFunction(std::string_view const name) - { - return reinterpret_cast(GetFunction(name)); - } - public: - ModuleLoader(); - ModuleLoader(ModuleLoader const&) = delete; - ModuleLoader(ModuleLoader&& right) noexcept; - ~ModuleLoader(); - public: - static bool IsSearchOnlyInSystemSupported(); - }; -} +#pragma once +#include + +namespace Platform +{ + class ModuleLoader + { + private: + #ifdef _MINWINDEF_ + HMODULE m_module{}; + #else + void* m_module{}; + #endif + public: + #ifdef _MINWINDEF_ + HRESULT Load(std::string_view const name, bool search_only_in_system); + #else + long Load(std::string_view const name, bool search_only_in_system); + #endif + void* GetFunction(std::string_view const name); + template + F* GetFunction(std::string_view const name) + { + return reinterpret_cast(GetFunction(name)); + } + public: + ModuleLoader(); + ModuleLoader(ModuleLoader const&) = delete; + ModuleLoader(ModuleLoader&& right) noexcept; + ~ModuleLoader(); + public: + static bool IsSearchOnlyInSystemSupported(); + }; +} diff --git a/LuaSTG/Platform/ProcessorInfo.cpp b/engine/win32/windows/ProcessorInfo.cpp similarity index 84% rename from LuaSTG/Platform/ProcessorInfo.cpp rename to engine/win32/windows/ProcessorInfo.cpp index ee1e6183..0fff5f68 100644 --- a/LuaSTG/Platform/ProcessorInfo.cpp +++ b/engine/win32/windows/ProcessorInfo.cpp @@ -1,6 +1,5 @@ +#include "Shared.hpp" #include "ProcessorInfo.hpp" -#include -#include "utf8.hpp" namespace Platform { std::string ProcessorInfo::name() { @@ -17,7 +16,7 @@ namespace Platform { &size ); if (ERROR_SUCCESS == result) { - return utf8::to_string(buffer); + return to_utf8(buffer); } return "Unknown"; } diff --git a/LuaSTG/Platform/ProcessorInfo.hpp b/engine/win32/windows/ProcessorInfo.hpp similarity index 100% rename from LuaSTG/Platform/ProcessorInfo.hpp rename to engine/win32/windows/ProcessorInfo.hpp diff --git a/LuaSTG/Platform/RuntimeLoader/All.cpp b/engine/win32/windows/RuntimeLoader/All.cpp similarity index 93% rename from LuaSTG/Platform/RuntimeLoader/All.cpp rename to engine/win32/windows/RuntimeLoader/All.cpp index be728c44..9a0e361e 100644 --- a/LuaSTG/Platform/RuntimeLoader/All.cpp +++ b/engine/win32/windows/RuntimeLoader/All.cpp @@ -1,887 +1,887 @@ -#include "Platform/Shared.hpp" -#include "Platform/WindowsVersion.hpp" - -#include "Platform/RuntimeLoader/DXGI.hpp" - -namespace Platform::RuntimeLoader -{ - HRESULT DXGI::CreateFactory(REFIID riid, void** ppFactory) - { - if (api_CreateDXGIFactory2) - { - UINT flags = 0; - #ifdef _DEBUG - flags |= DXGI_CREATE_FACTORY_DEBUG; - #endif - return api_CreateDXGIFactory2(flags, riid, ppFactory); - } - else if (api_CreateDXGIFactory1) - { - return api_CreateDXGIFactory1(riid, ppFactory); - } - else if (api_CreateDXGIFactory) - { - return api_CreateDXGIFactory(riid, ppFactory); - } - else - { - return E_NOTIMPL; - } - } - - DXGI::DXGI() - { - dll_dxgi = LoadLibraryW(L"dxgi.dll"); - if (dll_dxgi) - { - api_CreateDXGIFactory = (decltype(api_CreateDXGIFactory)) - GetProcAddress(dll_dxgi, "CreateDXGIFactory"); - api_CreateDXGIFactory1 = (decltype(api_CreateDXGIFactory1)) - GetProcAddress(dll_dxgi, "CreateDXGIFactory1"); - api_CreateDXGIFactory2 = (decltype(api_CreateDXGIFactory2)) - GetProcAddress(dll_dxgi, "CreateDXGIFactory2"); - } - } - DXGI::~DXGI() - { - if (dll_dxgi) - { - FreeLibrary(dll_dxgi); - } - dll_dxgi = NULL; - api_CreateDXGIFactory = NULL; - api_CreateDXGIFactory1 = NULL; - api_CreateDXGIFactory2 = NULL; - } -} - -#include "Platform/RuntimeLoader/Direct3D11.hpp" - -namespace Platform::RuntimeLoader -{ - HRESULT Direct3D11::CreateDevice( - UINT Flags, - D3D_FEATURE_LEVEL TargetFeatureLevel, - ID3D11Device** ppDevice, - D3D_FEATURE_LEVEL* pFeatureLevel, - ID3D11DeviceContext** ppImmediateContext) - { - if (api_D3D11CreateDevice) - { - #ifdef _DEBUG - Flags |= D3D11_CREATE_DEVICE_DEBUG; - #endif - HRESULT hr = S_OK; - D3D_FEATURE_LEVEL const d3d_feature_level_list[9] = { - //D3D_FEATURE_LEVEL_12_2, // no longer supported - D3D_FEATURE_LEVEL_12_1, - D3D_FEATURE_LEVEL_12_0, - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, - D3D_FEATURE_LEVEL_9_2, - D3D_FEATURE_LEVEL_9_1, - }; - UINT const d3d_feature_level_size = 9; - D3D_FEATURE_LEVEL d3d_feature_level = D3D_FEATURE_LEVEL_9_1; - for (UINT offset = 0; offset < d3d_feature_level_size; offset += 1) - { - hr = api_D3D11CreateDevice( - NULL, - D3D_DRIVER_TYPE_HARDWARE, - NULL, - Flags, - d3d_feature_level_list + offset, - d3d_feature_level_size - offset, - D3D11_SDK_VERSION, - NULL, - &d3d_feature_level, - NULL); - if (SUCCEEDED(hr)) - { - if ((UINT)d3d_feature_level >= (UINT)TargetFeatureLevel) - { - return api_D3D11CreateDevice( - NULL, - D3D_DRIVER_TYPE_HARDWARE, - NULL, - Flags, - d3d_feature_level_list + offset, - d3d_feature_level_size - offset, - D3D11_SDK_VERSION, - ppDevice, - pFeatureLevel, - ppImmediateContext); - } - else - { - return E_NOTIMPL; - } - } - } - return hr; - } - else - { - return E_NOTIMPL; - } - } - HRESULT Direct3D11::CreateDeviceFromAdapter( - IDXGIAdapter* pAdapter, - UINT Flags, - D3D_FEATURE_LEVEL TargetFeatureLevel, - ID3D11Device** ppDevice, - D3D_FEATURE_LEVEL* pFeatureLevel, - ID3D11DeviceContext** ppImmediateContext) - { - if (api_D3D11CreateDevice) - { - #ifdef _DEBUG - Flags |= D3D11_CREATE_DEVICE_DEBUG; - #endif - HRESULT hr = S_OK; - D3D_FEATURE_LEVEL const d3d_feature_level_list[9] = { - //D3D_FEATURE_LEVEL_12_2, // no longer supported - D3D_FEATURE_LEVEL_12_1, - D3D_FEATURE_LEVEL_12_0, - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, - D3D_FEATURE_LEVEL_9_2, - D3D_FEATURE_LEVEL_9_1, - }; - UINT const d3d_feature_level_size = 9; - D3D_FEATURE_LEVEL d3d_feature_level = D3D_FEATURE_LEVEL_9_1; - for (UINT offset = 0; offset < d3d_feature_level_size; offset += 1) - { - hr = api_D3D11CreateDevice( - pAdapter, - D3D_DRIVER_TYPE_UNKNOWN, - NULL, - Flags, - d3d_feature_level_list + offset, - d3d_feature_level_size - offset, - D3D11_SDK_VERSION, - NULL, - &d3d_feature_level, - NULL); - if (SUCCEEDED(hr)) - { - if ((UINT)d3d_feature_level >= (UINT)TargetFeatureLevel) - { - return api_D3D11CreateDevice( - pAdapter, - D3D_DRIVER_TYPE_UNKNOWN, - NULL, - Flags, - d3d_feature_level_list + offset, - d3d_feature_level_size - offset, - D3D11_SDK_VERSION, - ppDevice, - pFeatureLevel, - ppImmediateContext); - } - else - { - return E_NOTIMPL; - } - } - } - return hr; - } - else - { - return E_NOTIMPL; - } - } - HRESULT Direct3D11::CreateDeviceFromSoftAdapter( - UINT Flags, - D3D_FEATURE_LEVEL TargetFeatureLevel, - ID3D11Device** ppDevice, - D3D_FEATURE_LEVEL* pFeatureLevel, - ID3D11DeviceContext** ppImmediateContext, - D3D_DRIVER_TYPE* pType) - { - auto try_create = [&](D3D_DRIVER_TYPE type) -> HRESULT - { - HRESULT hr = S_OK; - D3D_FEATURE_LEVEL const d3d_feature_level_list[9] = { - //D3D_FEATURE_LEVEL_12_2, // NOTE: d3d11 not support level-12-2 - D3D_FEATURE_LEVEL_12_1, - D3D_FEATURE_LEVEL_12_0, - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, - D3D_FEATURE_LEVEL_9_2, - D3D_FEATURE_LEVEL_9_1, - }; - UINT const d3d_feature_level_size = 9; - D3D_FEATURE_LEVEL d3d_feature_level = D3D_FEATURE_LEVEL_9_1; - for (UINT offset = 0; offset < d3d_feature_level_size; offset += 1) - { - hr = api_D3D11CreateDevice( - NULL, - type, - NULL, - Flags, - d3d_feature_level_list + offset, - d3d_feature_level_size - offset, - D3D11_SDK_VERSION, - NULL, - &d3d_feature_level, - NULL); - if (SUCCEEDED(hr)) - { - if ((UINT)d3d_feature_level >= (UINT)TargetFeatureLevel) - { - if (pType) - { - *pType = type; - } - return api_D3D11CreateDevice( - NULL, - type, - NULL, - Flags, - d3d_feature_level_list + offset, - d3d_feature_level_size - offset, - D3D11_SDK_VERSION, - ppDevice, - pFeatureLevel, - ppImmediateContext); - } - else - { - return E_NOTIMPL; - } - } - } - return hr; - }; - if (pType) - { - *pType = D3D_DRIVER_TYPE_UNKNOWN; - } - if (api_D3D11CreateDevice) - { - #ifdef _DEBUG - Flags |= D3D11_CREATE_DEVICE_DEBUG; - #endif - HRESULT hr = S_OK; - hr = try_create(D3D_DRIVER_TYPE_WARP); - if (SUCCEEDED(hr)) return hr; - hr = try_create(D3D_DRIVER_TYPE_SOFTWARE); - if (SUCCEEDED(hr)) return hr; - hr = try_create(D3D_DRIVER_TYPE_REFERENCE); - if (SUCCEEDED(hr)) return hr; - return hr; - } - else - { - return E_NOTIMPL; - } - } - - Direct3D11::Direct3D11() - { - dll_d3d11 = LoadLibraryW(L"d3d11.dll"); - if (dll_d3d11) - { - api_D3D11CreateDevice = (decltype(api_D3D11CreateDevice)) - GetProcAddress(dll_d3d11, "D3D11CreateDevice"); - } - } - Direct3D11::~Direct3D11() - { - if (dll_d3d11) - { - FreeLibrary(dll_d3d11); - } - dll_d3d11 = NULL; - api_D3D11CreateDevice = NULL; - } -} - -#include "Platform/RuntimeLoader/Direct3DCompiler.hpp" - -namespace Platform::RuntimeLoader -{ - HRESULT Direct3DCompiler::Compile(LPCVOID pSrcData, - SIZE_T SrcDataSize, - LPCSTR pSourceName, - CONST D3D_SHADER_MACRO* pDefines, - ID3DInclude* pInclude, - LPCSTR pEntrypoint, - LPCSTR pTarget, - UINT Flags1, - UINT Flags2, - ID3DBlob** ppCode, - ID3DBlob** ppErrorMsgs) - { - if (api_D3DCompile) - { - return api_D3DCompile( - pSrcData, - SrcDataSize, - pSourceName, - pDefines, - pInclude, - pEntrypoint, - pTarget, - Flags1, - Flags2, - ppCode, - ppErrorMsgs); - } - return E_NOTIMPL; - } - HRESULT Direct3DCompiler::Reflect(LPCVOID pSrcData, - SIZE_T SrcDataSize, - REFIID pInterface, - void** ppReflector) - { - if (api_D3DReflect) - { - return api_D3DReflect(pSrcData, - SrcDataSize, - pInterface, - ppReflector); - } - return E_NOTIMPL; - } - - Direct3DCompiler::Direct3DCompiler() - { - dll_d3dcompiler = LoadLibraryW(L"d3dcompiler_47.dll"); - assert(dll_d3dcompiler); - if (dll_d3dcompiler) - { - api_D3DCompile = (decltype(api_D3DCompile)) - GetProcAddress(dll_d3dcompiler, "D3DCompile"); - api_D3DReflect = (decltype(api_D3DReflect)) - GetProcAddress(dll_d3dcompiler, "D3DReflect"); - assert(api_D3DCompile); - assert(api_D3DReflect); - } - } - Direct3DCompiler::~Direct3DCompiler() - { - if (dll_d3dcompiler) - { - FreeLibrary(dll_d3dcompiler); - } - dll_d3dcompiler = NULL; - api_D3DCompile = NULL; - api_D3DReflect = NULL; - } -} - -#include "Platform/RuntimeLoader/DirectComposition.hpp" - -namespace Platform::RuntimeLoader -{ - HRESULT DirectComposition::CreateDevice(IUnknown* renderingDevice, REFIID iid, void** dcompositionDevice) - { - if (api_DCompositionCreateDevice3) - { - return api_DCompositionCreateDevice3(renderingDevice, iid, dcompositionDevice); - } - else if (api_DCompositionCreateDevice2) - { - return api_DCompositionCreateDevice2(renderingDevice, iid, dcompositionDevice); - } - else if (api_DCompositionCreateDevice) - { - HRESULT hr = S_OK; - IDXGIDevice* dxgiDevice = NULL; - hr = renderingDevice->QueryInterface(&dxgiDevice); - if (FAILED(hr)) return hr; - hr = api_DCompositionCreateDevice(dxgiDevice, iid, dcompositionDevice); - dxgiDevice->Release(); - return hr; - } - else - { - return E_NOTIMPL; - } - } - - DirectComposition::DirectComposition() - { - dll_dcomp = LoadLibraryExW(L"dcomp.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); - if (dll_dcomp) - { - api_DCompositionCreateDevice = (decltype(api_DCompositionCreateDevice)) - GetProcAddress(dll_dcomp, "DCompositionCreateDevice"); - api_DCompositionCreateDevice2 = (decltype(api_DCompositionCreateDevice2)) - GetProcAddress(dll_dcomp, "DCompositionCreateDevice2"); - api_DCompositionCreateDevice3 = (decltype(api_DCompositionCreateDevice3)) - GetProcAddress(dll_dcomp, "DCompositionCreateDevice3"); - } - } - DirectComposition::~DirectComposition() - { - if (dll_dcomp) - { - FreeLibrary(dll_dcomp); - } - dll_dcomp = NULL; - api_DCompositionCreateDevice = NULL; - api_DCompositionCreateDevice2 = NULL; - api_DCompositionCreateDevice3 = NULL; - } -} - -#include "Platform/RuntimeLoader/Direct2D1.hpp" - -namespace Platform::RuntimeLoader -{ - HRESULT Direct2D1::CreateFactory( - D2D1_FACTORY_TYPE factoryType, - REFIID riid, - void** ppIFactory) - { - if (api_D2D1CreateFactory) - { - D2D1_FACTORY_OPTIONS options = { - #ifdef _DEBUG - .debugLevel = D2D1_DEBUG_LEVEL_INFORMATION - #else - .debugLevel = D2D1_DEBUG_LEVEL_NONE - #endif - }; - return api_D2D1CreateFactory( - factoryType, - riid, - &options, - ppIFactory); - } - return E_NOTIMPL; - } - HRESULT Direct2D1::CreateDevice( - IDXGIDevice* dxgiDevice, - BOOL multiThread, - ID2D1Device** d2dDevice) - { - if (api_D2D1CreateDevice) - { - D2D1_CREATION_PROPERTIES prop = { - .threadingMode = multiThread - ? D2D1_THREADING_MODE_MULTI_THREADED - : D2D1_THREADING_MODE_SINGLE_THREADED, - #ifdef _DEBUG - .debugLevel = D2D1_DEBUG_LEVEL_INFORMATION, - #else - .debugLevel = D2D1_DEBUG_LEVEL_NONE, - #endif - .options = multiThread - ? D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS - : D2D1_DEVICE_CONTEXT_OPTIONS_NONE, - }; - return api_D2D1CreateDevice(dxgiDevice, &prop, d2dDevice); - } - return E_NOTIMPL; - } - HRESULT Direct2D1::CreateDevice( - IDXGIDevice* dxgiDevice, - BOOL multiThread, - ID2D1Device** d2dDevice, - ID2D1DeviceContext** d2dDeviceContext) - { - if (api_D2D1CreateDevice) - { - D2D1_CREATION_PROPERTIES prop = { - .threadingMode = multiThread - ? D2D1_THREADING_MODE_MULTI_THREADED - : D2D1_THREADING_MODE_SINGLE_THREADED, - #ifdef _DEBUG - .debugLevel = D2D1_DEBUG_LEVEL_INFORMATION, - #else - .debugLevel = D2D1_DEBUG_LEVEL_NONE, - #endif - .options = multiThread - ? D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS - : D2D1_DEVICE_CONTEXT_OPTIONS_NONE, - }; - HRESULT hr = api_D2D1CreateDevice(dxgiDevice, &prop, d2dDevice); - if (FAILED(hr)) return hr; - return (*d2dDevice)->CreateDeviceContext( - multiThread - ? D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS - : D2D1_DEVICE_CONTEXT_OPTIONS_NONE, - d2dDeviceContext); - } - return E_NOTIMPL; - } - - Direct2D1::Direct2D1() - { - dll_d2d1 = LoadLibraryW(L"d2d1.dll"); - if (dll_d2d1) - { - api_D2D1CreateFactory = (decltype(api_D2D1CreateFactory)) - GetProcAddress(dll_d2d1, "D2D1CreateFactory"); - api_D2D1CreateDevice = (decltype(api_D2D1CreateDevice)) - GetProcAddress(dll_d2d1, "D2D1CreateDevice"); - } - } - Direct2D1::~Direct2D1() - { - if (dll_d2d1) - { - FreeLibrary(dll_d2d1); - } - dll_d2d1 = NULL; - api_D2D1CreateFactory = NULL; - api_D2D1CreateDevice = NULL; - } -} - -#include "Platform/RuntimeLoader/DirectWrite.hpp" - -namespace Platform::RuntimeLoader -{ - HRESULT DirectWrite::CreateFactory( - DWRITE_FACTORY_TYPE factoryType, - REFIID iid, - void** factory) - { - if (api_DWriteCreateFactory) - { - return api_DWriteCreateFactory( - factoryType, - iid, - (IUnknown**)factory); - } - return E_NOTIMPL; - } - - DirectWrite::DirectWrite() - { - dll_dwrite = LoadLibraryW(L"dwrite.dll"); - if (dll_dwrite) - { - api_DWriteCreateFactory = (decltype(api_DWriteCreateFactory)) - GetProcAddress(dll_dwrite, "DWriteCreateFactory"); - } - } - DirectWrite::~DirectWrite() - { - if (dll_dwrite) - { - FreeLibrary(dll_dwrite); - } - dll_dwrite = NULL; - api_DWriteCreateFactory = NULL; - } -} - -#include "Platform/RuntimeLoader/DesktopWindowManager.hpp" - -namespace Platform::RuntimeLoader -{ - HRESULT DesktopWindowManager::IsCompositionEnabled(BOOL* pfEnabled) - { - if (api_DwmIsCompositionEnabled) - { - return api_DwmIsCompositionEnabled(pfEnabled); - } - return E_NOTIMPL; - } - HRESULT DesktopWindowManager::EnableBlurBehindWindow(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind) - { - if (api_DwmEnableBlurBehindWindow) - { - return api_DwmEnableBlurBehindWindow(hWnd, pBlurBehind); - } - return E_NOTIMPL; - } - HRESULT DesktopWindowManager::ExtendFrameIntoClientArea(HWND hWnd, const MARGINS* pMarInset) - { - if (api_DwmExtendFrameIntoClientArea) - { - return api_DwmExtendFrameIntoClientArea(hWnd, pMarInset); - } - return E_NOTIMPL; - } - HRESULT DesktopWindowManager::GetColorizationColor(DWORD* pcrColorization, BOOL* pfOpaqueBlend) - { - if (api_DwmGetColorizationColor) - { - return api_DwmGetColorizationColor(pcrColorization, pfOpaqueBlend); - } - return E_NOTIMPL; - } - BOOL DesktopWindowManager::DefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult) - { - if (api_DwmDefWindowProc) - { - return api_DwmDefWindowProc(hWnd, msg, wParam, lParam, plResult); - } - return FALSE; - } - HRESULT DesktopWindowManager::SetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute) - { - if (api_DwmSetWindowAttribute) - { - return api_DwmSetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute); - } - return E_NOTIMPL; - } - HRESULT DesktopWindowManager::GetWindowAttribute(HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute) - { - if (api_DwmGetWindowAttribute) - { - return api_DwmGetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute); - } - return E_NOTIMPL; - } - HRESULT DesktopWindowManager::Flush() - { - if (api_DwmFlush) - { - return api_DwmFlush(); - } - return E_NOTIMPL; - } - - BOOL DesktopWindowManager::IsWindowTransparencySupported() - { - // https://github.com/glfw/glfw/blob/master/src/win32_window.c - - if (!IsWindowsVistaOrGreater()) - return FALSE; - - BOOL composition = FALSE; - if (FAILED(IsCompositionEnabled(&composition)) || !composition) - return FALSE; - - if (!IsWindows8OrGreater()) - { - // HACK: Disable framebuffer transparency on Windows 7 when the - // colorization color is opaque, because otherwise the window - // contents is blended additively with the previous frame instead - // of replacing it - DWORD color = 0x00000000; - BOOL opaque = FALSE; - if (FAILED(GetColorizationColor(&color, &opaque)) || opaque) - return FALSE; - } - - return TRUE; - } - HRESULT DesktopWindowManager::SetWindowTransparency(HWND hWnd, BOOL bEnable) - { - if (bEnable && IsWindowTransparencySupported() && api_CreateRectRgn && api_DeleteObject) - { - HRGN region = api_CreateRectRgn(0, 0, -1, -1); - DWM_BLURBEHIND bb = {}; - bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; - bb.fEnable = TRUE; - bb.hRgnBlur = region; - HRESULT const hr = EnableBlurBehindWindow(hWnd, &bb); - api_DeleteObject(region); - return hr; - } - else - { - DWM_BLURBEHIND bb = {}; - bb.dwFlags = DWM_BB_ENABLE; - return EnableBlurBehindWindow(hWnd, &bb); - } - } - - DesktopWindowManager::DesktopWindowManager() - { - dll_dwmapi = LoadLibraryW(L"dwmapi.dll"); - dll_gdi32 = LoadLibraryW(L"gdi32.dll"); - assert(dll_dwmapi); - assert(dll_gdi32); - if (dll_dwmapi) - { - api_DwmIsCompositionEnabled = (decltype(api_DwmIsCompositionEnabled)) - GetProcAddress(dll_dwmapi, "DwmIsCompositionEnabled"); - api_DwmEnableBlurBehindWindow = (decltype(api_DwmEnableBlurBehindWindow)) - GetProcAddress(dll_dwmapi, "DwmEnableBlurBehindWindow"); - api_DwmExtendFrameIntoClientArea = (decltype(api_DwmExtendFrameIntoClientArea)) - GetProcAddress(dll_dwmapi, "DwmExtendFrameIntoClientArea"); - api_DwmGetColorizationColor = (decltype(api_DwmGetColorizationColor)) - GetProcAddress(dll_dwmapi, "DwmGetColorizationColor"); - api_DwmDefWindowProc = (decltype(api_DwmDefWindowProc)) - GetProcAddress(dll_dwmapi, "DwmDefWindowProc"); - api_DwmSetWindowAttribute = (decltype(api_DwmSetWindowAttribute)) - GetProcAddress(dll_dwmapi, "DwmSetWindowAttribute"); - api_DwmGetWindowAttribute = (decltype(api_DwmGetWindowAttribute)) - GetProcAddress(dll_dwmapi, "DwmGetWindowAttribute"); - api_DwmFlush = (decltype(api_DwmFlush)) - GetProcAddress(dll_dwmapi, "DwmFlush"); - assert(api_DwmIsCompositionEnabled); - assert(api_DwmEnableBlurBehindWindow); - assert(api_DwmExtendFrameIntoClientArea); - assert(api_DwmGetColorizationColor); - assert(api_DwmDefWindowProc); - assert(api_DwmSetWindowAttribute); - assert(api_DwmGetWindowAttribute); - assert(api_DwmFlush); - } - if (dll_gdi32) - { - api_CreateRectRgn = (decltype(api_CreateRectRgn)) - GetProcAddress(dll_gdi32, "CreateRectRgn"); - api_DeleteObject = (decltype(api_DeleteObject)) - GetProcAddress(dll_gdi32, "DeleteObject"); - assert(api_CreateRectRgn); - assert(api_DeleteObject); - } - } - DesktopWindowManager::~DesktopWindowManager() - { - if (dll_dwmapi) - { - FreeLibrary(dll_dwmapi); - } - if (dll_gdi32) - { - FreeLibrary(dll_gdi32); - } - dll_dwmapi = NULL; - dll_gdi32 = NULL; - api_DwmIsCompositionEnabled = NULL; - api_DwmEnableBlurBehindWindow = NULL; - api_DwmExtendFrameIntoClientArea = NULL; - api_DwmGetColorizationColor = NULL; - api_DwmDefWindowProc = NULL; - api_DwmSetWindowAttribute = NULL; - api_DwmGetWindowAttribute = NULL; - api_DwmFlush = NULL; - api_CreateRectRgn = NULL; - api_DeleteObject = NULL; - } -} - -#include "Platform/RuntimeLoader/XAudio2.hpp" - -namespace Platform::RuntimeLoader -{ - HRESULT XAudio2::Create(IXAudio2** ppXAudio2) - { - // 从 Windows 10 1809 开始出现的魔幻 API - - if (api_XAudio2CreateWithVersionInfo) - { - // 逻辑核心掩码 - - XAUDIO2_PROCESSOR processor = XAUDIO2_DEFAULT_PROCESSOR; - if (WindowsVersion::Is10Build18362()) - { - // 从 Windows 10 1903 开始支持 - processor = XAUDIO2_USE_DEFAULT_PROCESSOR; - } - - // Windows NT 版本 - // https://learn.microsoft.com/zh-cn/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlisntddiversionavailable - - DWORD version = NTDDI_WIN10; - // TODO: 等 NI 分支或者之后的分支出来要记得更新一下,也不知道 SB 微软为什么这么设计…… - if (WindowsVersion::Is11Build22000()) - { - // NTDDI_WIN10_MN Windows Server 2022 preview - // NTDDI_WIN10_FE Windows Server 2022 (20348/20349) - // 所以直接跳到了 Windows 11 21H2 - version = NTDDI_WIN10_CO; - } - if (WindowsVersion::Is10Build19041()) - { - // NTDDI_WIN10_VB 难以确定,可能是 Windows 10 1909,也可能 Windows 10 2004/20H1 - // 考虑到 1903/1909 共用一个内核,2004/20H2/21H1/21H2/22H2 共用一个内核 - // 为了保险起见,视其为 Windows 10 2004/20H1 - version = NTDDI_WIN10_VB; - } - else if (WindowsVersion::Is10Build18362()) - { - // Windows 10 1903/19H1 - version = NTDDI_WIN10_19H1; - } - else - { - // Windows 10 1809 - version = NTDDI_WIN10_RS5; - } - - // 终于开始创建了,好麻烦惹 - - HRESULT hr = api_XAudio2CreateWithVersionInfo(ppXAudio2, 0, processor, version); - if (SUCCEEDED(hr)) - { - return hr; - } - } - - // 标准 API - - if (api_XAudio2Create) - { - // 从 Windows 10 1903/19H1 开始支持 - // 或者通过 xaudio2_9redist 支持 - HRESULT hr = api_XAudio2Create(ppXAudio2, 0, XAUDIO2_USE_DEFAULT_PROCESSOR); - if (FAILED(hr)) - { - // 回落到老版本的参数 - hr = api_XAudio2Create(ppXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR); - } - assert(SUCCEEDED(hr)); - return hr; - } - else - { - assert(false); - return E_NOTIMPL; - } - } - - XAudio2::XAudio2() - { - std::array, 3> dll_list = { - std::make_pair(L"xaudio2_9.dll", true), - std::make_pair(L"xaudio2_9redist.dll", false), - std::make_pair(L"xaudio2_8.dll", true), - }; - for (auto const& v : dll_list) - { - DWORD flags = 0; - if (v.second) - { - flags |= LOAD_LIBRARY_SEARCH_SYSTEM32; - } - if (HMODULE dll = LoadLibraryExW(v.first.data(), NULL, flags)) - { - dll_xaudio2 = dll; - break; - } - } - if (dll_xaudio2) - { - api_XAudio2CreateWithVersionInfo = (decltype(api_XAudio2CreateWithVersionInfo)) - GetProcAddress(dll_xaudio2, "XAudio2CreateWithVersionInfo"); - api_XAudio2Create = (decltype(api_XAudio2Create)) - GetProcAddress(dll_xaudio2, "XAudio2Create"); - assert(api_XAudio2Create); - } - } - XAudio2::~XAudio2() - { - if (dll_xaudio2) - { - FreeLibrary(dll_xaudio2); - } - dll_xaudio2 = NULL; - api_XAudio2CreateWithVersionInfo = NULL; - api_XAudio2Create = NULL; - } -} +#include "../Shared.hpp" +#include "../WindowsVersion.hpp" + +#include "./DXGI.hpp" + +namespace Platform::RuntimeLoader +{ + HRESULT DXGI::CreateFactory(REFIID riid, void** ppFactory) + { + if (api_CreateDXGIFactory2) + { + UINT flags = 0; + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + flags |= DXGI_CREATE_FACTORY_DEBUG; + #endif + return api_CreateDXGIFactory2(flags, riid, ppFactory); + } + else if (api_CreateDXGIFactory1) + { + return api_CreateDXGIFactory1(riid, ppFactory); + } + else if (api_CreateDXGIFactory) + { + return api_CreateDXGIFactory(riid, ppFactory); + } + else + { + return E_NOTIMPL; + } + } + + DXGI::DXGI() + { + dll_dxgi = LoadLibraryW(L"dxgi.dll"); + if (dll_dxgi) + { + api_CreateDXGIFactory = (decltype(api_CreateDXGIFactory)) + GetProcAddress(dll_dxgi, "CreateDXGIFactory"); + api_CreateDXGIFactory1 = (decltype(api_CreateDXGIFactory1)) + GetProcAddress(dll_dxgi, "CreateDXGIFactory1"); + api_CreateDXGIFactory2 = (decltype(api_CreateDXGIFactory2)) + GetProcAddress(dll_dxgi, "CreateDXGIFactory2"); + } + } + DXGI::~DXGI() + { + if (dll_dxgi) + { + FreeLibrary(dll_dxgi); + } + dll_dxgi = NULL; + api_CreateDXGIFactory = NULL; + api_CreateDXGIFactory1 = NULL; + api_CreateDXGIFactory2 = NULL; + } +} + +#include "./Direct3D11.hpp" + +namespace Platform::RuntimeLoader +{ + HRESULT Direct3D11::CreateDevice( + UINT Flags, + D3D_FEATURE_LEVEL TargetFeatureLevel, + ID3D11Device** ppDevice, + D3D_FEATURE_LEVEL* pFeatureLevel, + ID3D11DeviceContext** ppImmediateContext) + { + if (api_D3D11CreateDevice) + { + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + Flags |= D3D11_CREATE_DEVICE_DEBUG; + #endif + HRESULT hr = S_OK; + D3D_FEATURE_LEVEL const d3d_feature_level_list[9] = { + //D3D_FEATURE_LEVEL_12_2, // no longer supported + D3D_FEATURE_LEVEL_12_1, + D3D_FEATURE_LEVEL_12_0, + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1, + }; + UINT const d3d_feature_level_size = 9; + D3D_FEATURE_LEVEL d3d_feature_level = D3D_FEATURE_LEVEL_9_1; + for (UINT offset = 0; offset < d3d_feature_level_size; offset += 1) + { + hr = api_D3D11CreateDevice( + NULL, + D3D_DRIVER_TYPE_HARDWARE, + NULL, + Flags, + d3d_feature_level_list + offset, + d3d_feature_level_size - offset, + D3D11_SDK_VERSION, + NULL, + &d3d_feature_level, + NULL); + if (SUCCEEDED(hr)) + { + if ((UINT)d3d_feature_level >= (UINT)TargetFeatureLevel) + { + return api_D3D11CreateDevice( + NULL, + D3D_DRIVER_TYPE_HARDWARE, + NULL, + Flags, + d3d_feature_level_list + offset, + d3d_feature_level_size - offset, + D3D11_SDK_VERSION, + ppDevice, + pFeatureLevel, + ppImmediateContext); + } + else + { + return E_NOTIMPL; + } + } + } + return hr; + } + else + { + return E_NOTIMPL; + } + } + HRESULT Direct3D11::CreateDeviceFromAdapter( + IDXGIAdapter* pAdapter, + UINT Flags, + D3D_FEATURE_LEVEL TargetFeatureLevel, + ID3D11Device** ppDevice, + D3D_FEATURE_LEVEL* pFeatureLevel, + ID3D11DeviceContext** ppImmediateContext) + { + if (api_D3D11CreateDevice) + { + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + Flags |= D3D11_CREATE_DEVICE_DEBUG; + #endif + HRESULT hr = S_OK; + D3D_FEATURE_LEVEL const d3d_feature_level_list[9] = { + //D3D_FEATURE_LEVEL_12_2, // no longer supported + D3D_FEATURE_LEVEL_12_1, + D3D_FEATURE_LEVEL_12_0, + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1, + }; + UINT const d3d_feature_level_size = 9; + D3D_FEATURE_LEVEL d3d_feature_level = D3D_FEATURE_LEVEL_9_1; + for (UINT offset = 0; offset < d3d_feature_level_size; offset += 1) + { + hr = api_D3D11CreateDevice( + pAdapter, + D3D_DRIVER_TYPE_UNKNOWN, + NULL, + Flags, + d3d_feature_level_list + offset, + d3d_feature_level_size - offset, + D3D11_SDK_VERSION, + NULL, + &d3d_feature_level, + NULL); + if (SUCCEEDED(hr)) + { + if ((UINT)d3d_feature_level >= (UINT)TargetFeatureLevel) + { + return api_D3D11CreateDevice( + pAdapter, + D3D_DRIVER_TYPE_UNKNOWN, + NULL, + Flags, + d3d_feature_level_list + offset, + d3d_feature_level_size - offset, + D3D11_SDK_VERSION, + ppDevice, + pFeatureLevel, + ppImmediateContext); + } + else + { + return E_NOTIMPL; + } + } + } + return hr; + } + else + { + return E_NOTIMPL; + } + } + HRESULT Direct3D11::CreateDeviceFromSoftAdapter( + UINT Flags, + D3D_FEATURE_LEVEL TargetFeatureLevel, + ID3D11Device** ppDevice, + D3D_FEATURE_LEVEL* pFeatureLevel, + ID3D11DeviceContext** ppImmediateContext, + D3D_DRIVER_TYPE* pType) + { + auto try_create = [&](D3D_DRIVER_TYPE type) -> HRESULT + { + HRESULT hr = S_OK; + D3D_FEATURE_LEVEL const d3d_feature_level_list[9] = { + //D3D_FEATURE_LEVEL_12_2, // NOTE: d3d11 not support level-12-2 + D3D_FEATURE_LEVEL_12_1, + D3D_FEATURE_LEVEL_12_0, + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + D3D_FEATURE_LEVEL_10_1, + D3D_FEATURE_LEVEL_10_0, + D3D_FEATURE_LEVEL_9_3, + D3D_FEATURE_LEVEL_9_2, + D3D_FEATURE_LEVEL_9_1, + }; + UINT const d3d_feature_level_size = 9; + D3D_FEATURE_LEVEL d3d_feature_level = D3D_FEATURE_LEVEL_9_1; + for (UINT offset = 0; offset < d3d_feature_level_size; offset += 1) + { + hr = api_D3D11CreateDevice( + NULL, + type, + NULL, + Flags, + d3d_feature_level_list + offset, + d3d_feature_level_size - offset, + D3D11_SDK_VERSION, + NULL, + &d3d_feature_level, + NULL); + if (SUCCEEDED(hr)) + { + if ((UINT)d3d_feature_level >= (UINT)TargetFeatureLevel) + { + if (pType) + { + *pType = type; + } + return api_D3D11CreateDevice( + NULL, + type, + NULL, + Flags, + d3d_feature_level_list + offset, + d3d_feature_level_size - offset, + D3D11_SDK_VERSION, + ppDevice, + pFeatureLevel, + ppImmediateContext); + } + else + { + return E_NOTIMPL; + } + } + } + return hr; + }; + if (pType) + { + *pType = D3D_DRIVER_TYPE_UNKNOWN; + } + if (api_D3D11CreateDevice) + { + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + Flags |= D3D11_CREATE_DEVICE_DEBUG; + #endif + HRESULT hr = S_OK; + hr = try_create(D3D_DRIVER_TYPE_WARP); + if (SUCCEEDED(hr)) return hr; + hr = try_create(D3D_DRIVER_TYPE_SOFTWARE); + if (SUCCEEDED(hr)) return hr; + hr = try_create(D3D_DRIVER_TYPE_REFERENCE); + if (SUCCEEDED(hr)) return hr; + return hr; + } + else + { + return E_NOTIMPL; + } + } + + Direct3D11::Direct3D11() + { + dll_d3d11 = LoadLibraryW(L"d3d11.dll"); + if (dll_d3d11) + { + api_D3D11CreateDevice = (decltype(api_D3D11CreateDevice)) + GetProcAddress(dll_d3d11, "D3D11CreateDevice"); + } + } + Direct3D11::~Direct3D11() + { + if (dll_d3d11) + { + FreeLibrary(dll_d3d11); + } + dll_d3d11 = NULL; + api_D3D11CreateDevice = NULL; + } +} + +#include "./Direct3DCompiler.hpp" + +namespace Platform::RuntimeLoader +{ + HRESULT Direct3DCompiler::Compile(LPCVOID pSrcData, + SIZE_T SrcDataSize, + LPCSTR pSourceName, + CONST D3D_SHADER_MACRO* pDefines, + ID3DInclude* pInclude, + LPCSTR pEntrypoint, + LPCSTR pTarget, + UINT Flags1, + UINT Flags2, + ID3DBlob** ppCode, + ID3DBlob** ppErrorMsgs) + { + if (api_D3DCompile) + { + return api_D3DCompile( + pSrcData, + SrcDataSize, + pSourceName, + pDefines, + pInclude, + pEntrypoint, + pTarget, + Flags1, + Flags2, + ppCode, + ppErrorMsgs); + } + return E_NOTIMPL; + } + HRESULT Direct3DCompiler::Reflect(LPCVOID pSrcData, + SIZE_T SrcDataSize, + REFIID pInterface, + void** ppReflector) + { + if (api_D3DReflect) + { + return api_D3DReflect(pSrcData, + SrcDataSize, + pInterface, + ppReflector); + } + return E_NOTIMPL; + } + + Direct3DCompiler::Direct3DCompiler() + { + dll_d3dcompiler = LoadLibraryW(L"d3dcompiler_47.dll"); + assert(dll_d3dcompiler); + if (dll_d3dcompiler) + { + api_D3DCompile = (decltype(api_D3DCompile)) + GetProcAddress(dll_d3dcompiler, "D3DCompile"); + api_D3DReflect = (decltype(api_D3DReflect)) + GetProcAddress(dll_d3dcompiler, "D3DReflect"); + assert(api_D3DCompile); + assert(api_D3DReflect); + } + } + Direct3DCompiler::~Direct3DCompiler() + { + if (dll_d3dcompiler) + { + FreeLibrary(dll_d3dcompiler); + } + dll_d3dcompiler = NULL; + api_D3DCompile = NULL; + api_D3DReflect = NULL; + } +} + +#include "./DirectComposition.hpp" + +namespace Platform::RuntimeLoader +{ + HRESULT DirectComposition::CreateDevice(IUnknown* renderingDevice, REFIID iid, void** dcompositionDevice) + { + if (api_DCompositionCreateDevice3) + { + return api_DCompositionCreateDevice3(renderingDevice, iid, dcompositionDevice); + } + else if (api_DCompositionCreateDevice2) + { + return api_DCompositionCreateDevice2(renderingDevice, iid, dcompositionDevice); + } + else if (api_DCompositionCreateDevice) + { + HRESULT hr = S_OK; + IDXGIDevice* dxgiDevice = NULL; + hr = renderingDevice->QueryInterface(&dxgiDevice); + if (FAILED(hr)) return hr; + hr = api_DCompositionCreateDevice(dxgiDevice, iid, dcompositionDevice); + dxgiDevice->Release(); + return hr; + } + else + { + return E_NOTIMPL; + } + } + + DirectComposition::DirectComposition() + { + dll_dcomp = LoadLibraryExW(L"dcomp.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (dll_dcomp) + { + api_DCompositionCreateDevice = (decltype(api_DCompositionCreateDevice)) + GetProcAddress(dll_dcomp, "DCompositionCreateDevice"); + api_DCompositionCreateDevice2 = (decltype(api_DCompositionCreateDevice2)) + GetProcAddress(dll_dcomp, "DCompositionCreateDevice2"); + api_DCompositionCreateDevice3 = (decltype(api_DCompositionCreateDevice3)) + GetProcAddress(dll_dcomp, "DCompositionCreateDevice3"); + } + } + DirectComposition::~DirectComposition() + { + if (dll_dcomp) + { + FreeLibrary(dll_dcomp); + } + dll_dcomp = NULL; + api_DCompositionCreateDevice = NULL; + api_DCompositionCreateDevice2 = NULL; + api_DCompositionCreateDevice3 = NULL; + } +} + +#include "./Direct2D1.hpp" + +namespace Platform::RuntimeLoader +{ + HRESULT Direct2D1::CreateFactory( + D2D1_FACTORY_TYPE factoryType, + REFIID riid, + void** ppIFactory) + { + if (api_D2D1CreateFactory) + { + D2D1_FACTORY_OPTIONS options = { + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + .debugLevel = D2D1_DEBUG_LEVEL_INFORMATION + #else + .debugLevel = D2D1_DEBUG_LEVEL_NONE + #endif + }; + return api_D2D1CreateFactory( + factoryType, + riid, + &options, + ppIFactory); + } + return E_NOTIMPL; + } + HRESULT Direct2D1::CreateDevice( + IDXGIDevice* dxgiDevice, + BOOL multiThread, + ID2D1Device** d2dDevice) + { + if (api_D2D1CreateDevice) + { + D2D1_CREATION_PROPERTIES prop = { + .threadingMode = multiThread + ? D2D1_THREADING_MODE_MULTI_THREADED + : D2D1_THREADING_MODE_SINGLE_THREADED, + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + .debugLevel = D2D1_DEBUG_LEVEL_INFORMATION, + #else + .debugLevel = D2D1_DEBUG_LEVEL_NONE, + #endif + .options = multiThread + ? D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS + : D2D1_DEVICE_CONTEXT_OPTIONS_NONE, + }; + return api_D2D1CreateDevice(dxgiDevice, &prop, d2dDevice); + } + return E_NOTIMPL; + } + HRESULT Direct2D1::CreateDevice( + IDXGIDevice* dxgiDevice, + BOOL multiThread, + ID2D1Device** d2dDevice, + ID2D1DeviceContext** d2dDeviceContext) + { + if (api_D2D1CreateDevice) + { + D2D1_CREATION_PROPERTIES prop = { + .threadingMode = multiThread + ? D2D1_THREADING_MODE_MULTI_THREADED + : D2D1_THREADING_MODE_SINGLE_THREADED, + #if (!defined(NDEBUG) && defined(LUASTG_GRAPHICS_DEBUG_LAYER_ENABLE)) + .debugLevel = D2D1_DEBUG_LEVEL_INFORMATION, + #else + .debugLevel = D2D1_DEBUG_LEVEL_NONE, + #endif + .options = multiThread + ? D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS + : D2D1_DEVICE_CONTEXT_OPTIONS_NONE, + }; + HRESULT hr = api_D2D1CreateDevice(dxgiDevice, &prop, d2dDevice); + if (FAILED(hr)) return hr; + return (*d2dDevice)->CreateDeviceContext( + multiThread + ? D2D1_DEVICE_CONTEXT_OPTIONS_ENABLE_MULTITHREADED_OPTIMIZATIONS + : D2D1_DEVICE_CONTEXT_OPTIONS_NONE, + d2dDeviceContext); + } + return E_NOTIMPL; + } + + Direct2D1::Direct2D1() + { + dll_d2d1 = LoadLibraryW(L"d2d1.dll"); + if (dll_d2d1) + { + api_D2D1CreateFactory = (decltype(api_D2D1CreateFactory)) + GetProcAddress(dll_d2d1, "D2D1CreateFactory"); + api_D2D1CreateDevice = (decltype(api_D2D1CreateDevice)) + GetProcAddress(dll_d2d1, "D2D1CreateDevice"); + } + } + Direct2D1::~Direct2D1() + { + if (dll_d2d1) + { + FreeLibrary(dll_d2d1); + } + dll_d2d1 = NULL; + api_D2D1CreateFactory = NULL; + api_D2D1CreateDevice = NULL; + } +} + +#include "./DirectWrite.hpp" + +namespace Platform::RuntimeLoader +{ + HRESULT DirectWrite::CreateFactory( + DWRITE_FACTORY_TYPE factoryType, + REFIID iid, + void** factory) + { + if (api_DWriteCreateFactory) + { + return api_DWriteCreateFactory( + factoryType, + iid, + (IUnknown**)factory); + } + return E_NOTIMPL; + } + + DirectWrite::DirectWrite() + { + dll_dwrite = LoadLibraryW(L"dwrite.dll"); + if (dll_dwrite) + { + api_DWriteCreateFactory = (decltype(api_DWriteCreateFactory)) + GetProcAddress(dll_dwrite, "DWriteCreateFactory"); + } + } + DirectWrite::~DirectWrite() + { + if (dll_dwrite) + { + FreeLibrary(dll_dwrite); + } + dll_dwrite = NULL; + api_DWriteCreateFactory = NULL; + } +} + +#include "./DesktopWindowManager.hpp" + +namespace Platform::RuntimeLoader +{ + HRESULT DesktopWindowManager::IsCompositionEnabled(BOOL* pfEnabled) + { + if (api_DwmIsCompositionEnabled) + { + return api_DwmIsCompositionEnabled(pfEnabled); + } + return E_NOTIMPL; + } + HRESULT DesktopWindowManager::EnableBlurBehindWindow(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind) + { + if (api_DwmEnableBlurBehindWindow) + { + return api_DwmEnableBlurBehindWindow(hWnd, pBlurBehind); + } + return E_NOTIMPL; + } + HRESULT DesktopWindowManager::ExtendFrameIntoClientArea(HWND hWnd, const MARGINS* pMarInset) + { + if (api_DwmExtendFrameIntoClientArea) + { + return api_DwmExtendFrameIntoClientArea(hWnd, pMarInset); + } + return E_NOTIMPL; + } + HRESULT DesktopWindowManager::GetColorizationColor(DWORD* pcrColorization, BOOL* pfOpaqueBlend) + { + if (api_DwmGetColorizationColor) + { + return api_DwmGetColorizationColor(pcrColorization, pfOpaqueBlend); + } + return E_NOTIMPL; + } + BOOL DesktopWindowManager::DefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult) + { + if (api_DwmDefWindowProc) + { + return api_DwmDefWindowProc(hWnd, msg, wParam, lParam, plResult); + } + return FALSE; + } + HRESULT DesktopWindowManager::SetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute) + { + if (api_DwmSetWindowAttribute) + { + return api_DwmSetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute); + } + return E_NOTIMPL; + } + HRESULT DesktopWindowManager::GetWindowAttribute(HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute) + { + if (api_DwmGetWindowAttribute) + { + return api_DwmGetWindowAttribute(hwnd, dwAttribute, pvAttribute, cbAttribute); + } + return E_NOTIMPL; + } + HRESULT DesktopWindowManager::Flush() + { + if (api_DwmFlush) + { + return api_DwmFlush(); + } + return E_NOTIMPL; + } + + BOOL DesktopWindowManager::IsWindowTransparencySupported() + { + // https://github.com/glfw/glfw/blob/master/src/win32_window.c + + if (!IsWindowsVistaOrGreater()) + return FALSE; + + BOOL composition = FALSE; + if (FAILED(IsCompositionEnabled(&composition)) || !composition) + return FALSE; + + if (!IsWindows8OrGreater()) + { + // HACK: Disable framebuffer transparency on Windows 7 when the + // colorization color is opaque, because otherwise the window + // contents is blended additively with the previous frame instead + // of replacing it + DWORD color = 0x00000000; + BOOL opaque = FALSE; + if (FAILED(GetColorizationColor(&color, &opaque)) || opaque) + return FALSE; + } + + return TRUE; + } + HRESULT DesktopWindowManager::SetWindowTransparency(HWND hWnd, BOOL bEnable) + { + if (bEnable && IsWindowTransparencySupported() && api_CreateRectRgn && api_DeleteObject) + { + HRGN region = api_CreateRectRgn(0, 0, -1, -1); + DWM_BLURBEHIND bb = {}; + bb.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION; + bb.fEnable = TRUE; + bb.hRgnBlur = region; + HRESULT const hr = EnableBlurBehindWindow(hWnd, &bb); + api_DeleteObject(region); + return hr; + } + else + { + DWM_BLURBEHIND bb = {}; + bb.dwFlags = DWM_BB_ENABLE; + return EnableBlurBehindWindow(hWnd, &bb); + } + } + + DesktopWindowManager::DesktopWindowManager() + { + dll_dwmapi = LoadLibraryW(L"dwmapi.dll"); + dll_gdi32 = LoadLibraryW(L"gdi32.dll"); + assert(dll_dwmapi); + assert(dll_gdi32); + if (dll_dwmapi) + { + api_DwmIsCompositionEnabled = (decltype(api_DwmIsCompositionEnabled)) + GetProcAddress(dll_dwmapi, "DwmIsCompositionEnabled"); + api_DwmEnableBlurBehindWindow = (decltype(api_DwmEnableBlurBehindWindow)) + GetProcAddress(dll_dwmapi, "DwmEnableBlurBehindWindow"); + api_DwmExtendFrameIntoClientArea = (decltype(api_DwmExtendFrameIntoClientArea)) + GetProcAddress(dll_dwmapi, "DwmExtendFrameIntoClientArea"); + api_DwmGetColorizationColor = (decltype(api_DwmGetColorizationColor)) + GetProcAddress(dll_dwmapi, "DwmGetColorizationColor"); + api_DwmDefWindowProc = (decltype(api_DwmDefWindowProc)) + GetProcAddress(dll_dwmapi, "DwmDefWindowProc"); + api_DwmSetWindowAttribute = (decltype(api_DwmSetWindowAttribute)) + GetProcAddress(dll_dwmapi, "DwmSetWindowAttribute"); + api_DwmGetWindowAttribute = (decltype(api_DwmGetWindowAttribute)) + GetProcAddress(dll_dwmapi, "DwmGetWindowAttribute"); + api_DwmFlush = (decltype(api_DwmFlush)) + GetProcAddress(dll_dwmapi, "DwmFlush"); + assert(api_DwmIsCompositionEnabled); + assert(api_DwmEnableBlurBehindWindow); + assert(api_DwmExtendFrameIntoClientArea); + assert(api_DwmGetColorizationColor); + assert(api_DwmDefWindowProc); + assert(api_DwmSetWindowAttribute); + assert(api_DwmGetWindowAttribute); + assert(api_DwmFlush); + } + if (dll_gdi32) + { + api_CreateRectRgn = (decltype(api_CreateRectRgn)) + GetProcAddress(dll_gdi32, "CreateRectRgn"); + api_DeleteObject = (decltype(api_DeleteObject)) + GetProcAddress(dll_gdi32, "DeleteObject"); + assert(api_CreateRectRgn); + assert(api_DeleteObject); + } + } + DesktopWindowManager::~DesktopWindowManager() + { + if (dll_dwmapi) + { + FreeLibrary(dll_dwmapi); + } + if (dll_gdi32) + { + FreeLibrary(dll_gdi32); + } + dll_dwmapi = NULL; + dll_gdi32 = NULL; + api_DwmIsCompositionEnabled = NULL; + api_DwmEnableBlurBehindWindow = NULL; + api_DwmExtendFrameIntoClientArea = NULL; + api_DwmGetColorizationColor = NULL; + api_DwmDefWindowProc = NULL; + api_DwmSetWindowAttribute = NULL; + api_DwmGetWindowAttribute = NULL; + api_DwmFlush = NULL; + api_CreateRectRgn = NULL; + api_DeleteObject = NULL; + } +} + +#include "./XAudio2.hpp" + +namespace Platform::RuntimeLoader +{ + HRESULT XAudio2::Create(IXAudio2** ppXAudio2) + { + // 从 Windows 10 1809 开始出现的魔幻 API + + if (api_XAudio2CreateWithVersionInfo) + { + // 逻辑核心掩码 + + XAUDIO2_PROCESSOR processor = XAUDIO2_DEFAULT_PROCESSOR; + if (WindowsVersion::Is10Build18362()) + { + // 从 Windows 10 1903 开始支持 + processor = XAUDIO2_USE_DEFAULT_PROCESSOR; + } + + // Windows NT 版本 + // https://learn.microsoft.com/zh-cn/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlisntddiversionavailable + + DWORD version = NTDDI_WIN10; + // TODO: 等 NI 分支或者之后的分支出来要记得更新一下,也不知道 SB 微软为什么这么设计…… + if (WindowsVersion::Is11Build22000()) + { + // NTDDI_WIN10_MN Windows Server 2022 preview + // NTDDI_WIN10_FE Windows Server 2022 (20348/20349) + // 所以直接跳到了 Windows 11 21H2 + version = NTDDI_WIN10_CO; + } + if (WindowsVersion::Is10Build19041()) + { + // NTDDI_WIN10_VB 难以确定,可能是 Windows 10 1909,也可能 Windows 10 2004/20H1 + // 考虑到 1903/1909 共用一个内核,2004/20H2/21H1/21H2/22H2 共用一个内核 + // 为了保险起见,视其为 Windows 10 2004/20H1 + version = NTDDI_WIN10_VB; + } + else if (WindowsVersion::Is10Build18362()) + { + // Windows 10 1903/19H1 + version = NTDDI_WIN10_19H1; + } + else + { + // Windows 10 1809 + version = NTDDI_WIN10_RS5; + } + + // 终于开始创建了,好麻烦惹 + + HRESULT hr = api_XAudio2CreateWithVersionInfo(ppXAudio2, 0, processor, version); + if (SUCCEEDED(hr)) + { + return hr; + } + } + + // 标准 API + + if (api_XAudio2Create) + { + // 从 Windows 10 1903/19H1 开始支持 + // 或者通过 xaudio2_9redist 支持 + HRESULT hr = api_XAudio2Create(ppXAudio2, 0, XAUDIO2_USE_DEFAULT_PROCESSOR); + if (FAILED(hr)) + { + // 回落到老版本的参数 + hr = api_XAudio2Create(ppXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR); + } + assert(SUCCEEDED(hr)); + return hr; + } + else + { + assert(false); + return E_NOTIMPL; + } + } + + XAudio2::XAudio2() + { + std::array, 3> dll_list = { + std::make_pair(L"xaudio2_9.dll", true), + std::make_pair(L"xaudio2_9redist.dll", false), + std::make_pair(L"xaudio2_8.dll", true), + }; + for (auto const& v : dll_list) + { + DWORD flags = 0; + if (v.second) + { + flags |= LOAD_LIBRARY_SEARCH_SYSTEM32; + } + if (HMODULE dll = LoadLibraryExW(v.first.data(), NULL, flags)) + { + dll_xaudio2 = dll; + break; + } + } + if (dll_xaudio2) + { + api_XAudio2CreateWithVersionInfo = (decltype(api_XAudio2CreateWithVersionInfo)) + GetProcAddress(dll_xaudio2, "XAudio2CreateWithVersionInfo"); + api_XAudio2Create = (decltype(api_XAudio2Create)) + GetProcAddress(dll_xaudio2, "XAudio2Create"); + assert(api_XAudio2Create); + } + } + XAudio2::~XAudio2() + { + if (dll_xaudio2) + { + FreeLibrary(dll_xaudio2); + } + dll_xaudio2 = NULL; + api_XAudio2CreateWithVersionInfo = NULL; + api_XAudio2Create = NULL; + } +} diff --git a/LuaSTG/Platform/RuntimeLoader/D3DKMT.cpp b/engine/win32/windows/RuntimeLoader/D3DKMT.cpp similarity index 98% rename from LuaSTG/Platform/RuntimeLoader/D3DKMT.cpp rename to engine/win32/windows/RuntimeLoader/D3DKMT.cpp index 9b305709..d42e0948 100644 --- a/LuaSTG/Platform/RuntimeLoader/D3DKMT.cpp +++ b/engine/win32/windows/RuntimeLoader/D3DKMT.cpp @@ -1,4 +1,4 @@ -#include "Platform/RuntimeLoader/D3DKMT.hpp" +#include "./D3DKMT.hpp" namespace Platform::RuntimeLoader { diff --git a/LuaSTG/Platform/RuntimeLoader/D3DKMT.hpp b/engine/win32/windows/RuntimeLoader/D3DKMT.hpp similarity index 100% rename from LuaSTG/Platform/RuntimeLoader/D3DKMT.hpp rename to engine/win32/windows/RuntimeLoader/D3DKMT.hpp diff --git a/LuaSTG/Platform/RuntimeLoader/DXGI.hpp b/engine/win32/windows/RuntimeLoader/DXGI.hpp similarity index 100% rename from LuaSTG/Platform/RuntimeLoader/DXGI.hpp rename to engine/win32/windows/RuntimeLoader/DXGI.hpp diff --git a/LuaSTG/Platform/RuntimeLoader/DesktopWindowManager.hpp b/engine/win32/windows/RuntimeLoader/DesktopWindowManager.hpp similarity index 97% rename from LuaSTG/Platform/RuntimeLoader/DesktopWindowManager.hpp rename to engine/win32/windows/RuntimeLoader/DesktopWindowManager.hpp index 08bba540..e83a7caf 100644 --- a/LuaSTG/Platform/RuntimeLoader/DesktopWindowManager.hpp +++ b/engine/win32/windows/RuntimeLoader/DesktopWindowManager.hpp @@ -1,40 +1,40 @@ -#pragma once - -namespace Platform::RuntimeLoader -{ - class DesktopWindowManager - { - private: - HMODULE dll_dwmapi{}; - HMODULE dll_gdi32{}; - decltype(DwmIsCompositionEnabled)* api_DwmIsCompositionEnabled{}; - decltype(DwmEnableBlurBehindWindow)* api_DwmEnableBlurBehindWindow{}; - decltype(DwmExtendFrameIntoClientArea)* api_DwmExtendFrameIntoClientArea{}; - decltype(DwmGetColorizationColor)* api_DwmGetColorizationColor{}; - decltype(DwmDefWindowProc)* api_DwmDefWindowProc{}; - decltype(DwmSetWindowAttribute)* api_DwmSetWindowAttribute{}; - decltype(DwmGetWindowAttribute)* api_DwmGetWindowAttribute{}; - decltype(DwmFlush)* api_DwmFlush{}; - decltype(CreateRectRgn)* api_CreateRectRgn{}; - decltype(DeleteObject)* api_DeleteObject{}; - public: - HRESULT IsCompositionEnabled(BOOL* pfEnabled); - HRESULT EnableBlurBehindWindow(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind); - HRESULT ExtendFrameIntoClientArea(HWND hWnd, const MARGINS* pMarInset); - HRESULT GetColorizationColor(DWORD* pcrColorization, BOOL* pfOpaqueBlend); - BOOL DefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult); - HRESULT SetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute); - HRESULT GetWindowAttribute(HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute); - HRESULT Flush(); - - // NOTE: Update window transparency on message - // WM_DWMCOMPOSITIONCHANGED - // WM_DWMCOLORIZATIONCOLORCHANGED - - BOOL IsWindowTransparencySupported(); - HRESULT SetWindowTransparency(HWND hWnd, BOOL bEnable); - public: - DesktopWindowManager(); - ~DesktopWindowManager(); - }; -} +#pragma once + +namespace Platform::RuntimeLoader +{ + class DesktopWindowManager + { + private: + HMODULE dll_dwmapi{}; + HMODULE dll_gdi32{}; + decltype(DwmIsCompositionEnabled)* api_DwmIsCompositionEnabled{}; + decltype(DwmEnableBlurBehindWindow)* api_DwmEnableBlurBehindWindow{}; + decltype(DwmExtendFrameIntoClientArea)* api_DwmExtendFrameIntoClientArea{}; + decltype(DwmGetColorizationColor)* api_DwmGetColorizationColor{}; + decltype(DwmDefWindowProc)* api_DwmDefWindowProc{}; + decltype(DwmSetWindowAttribute)* api_DwmSetWindowAttribute{}; + decltype(DwmGetWindowAttribute)* api_DwmGetWindowAttribute{}; + decltype(DwmFlush)* api_DwmFlush{}; + decltype(CreateRectRgn)* api_CreateRectRgn{}; + decltype(DeleteObject)* api_DeleteObject{}; + public: + HRESULT IsCompositionEnabled(BOOL* pfEnabled); + HRESULT EnableBlurBehindWindow(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind); + HRESULT ExtendFrameIntoClientArea(HWND hWnd, const MARGINS* pMarInset); + HRESULT GetColorizationColor(DWORD* pcrColorization, BOOL* pfOpaqueBlend); + BOOL DefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* plResult); + HRESULT SetWindowAttribute(HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute); + HRESULT GetWindowAttribute(HWND hwnd, DWORD dwAttribute, PVOID pvAttribute, DWORD cbAttribute); + HRESULT Flush(); + + // NOTE: Update window transparency on message + // WM_DWMCOMPOSITIONCHANGED + // WM_DWMCOLORIZATIONCOLORCHANGED + + BOOL IsWindowTransparencySupported(); + HRESULT SetWindowTransparency(HWND hWnd, BOOL bEnable); + public: + DesktopWindowManager(); + ~DesktopWindowManager(); + }; +} diff --git a/LuaSTG/Platform/RuntimeLoader/Direct2D1.hpp b/engine/win32/windows/RuntimeLoader/Direct2D1.hpp similarity index 96% rename from LuaSTG/Platform/RuntimeLoader/Direct2D1.hpp rename to engine/win32/windows/RuntimeLoader/Direct2D1.hpp index fd978098..e4be7261 100644 --- a/LuaSTG/Platform/RuntimeLoader/Direct2D1.hpp +++ b/engine/win32/windows/RuntimeLoader/Direct2D1.hpp @@ -1,40 +1,40 @@ -#pragma once - -namespace Platform::RuntimeLoader -{ - class Direct2D1 - { - private: - // FUCK Microsoft - typedef HRESULT(WINAPI* PFN_D2D1CreateFactory)( - D2D1_FACTORY_TYPE factoryType, - REFIID riid, - CONST D2D1_FACTORY_OPTIONS* pFactoryOptions, - void** ppIFactory); - typedef HRESULT(WINAPI* PFN_D2D1CreateDevice)( - IDXGIDevice* dxgiDevice, - CONST D2D1_CREATION_PROPERTIES* creationProperties, - ID2D1Device** d2dDevice); - private: - HMODULE dll_d2d1{}; - PFN_D2D1CreateFactory api_D2D1CreateFactory{}; - PFN_D2D1CreateDevice api_D2D1CreateDevice{}; - public: - HRESULT CreateFactory( - D2D1_FACTORY_TYPE factoryType, - REFIID riid, - void** ppIFactory); - HRESULT CreateDevice( - IDXGIDevice* dxgiDevice, - BOOL multiThread, - ID2D1Device** d2dDevice); - HRESULT CreateDevice( - IDXGIDevice* dxgiDevice, - BOOL multiThread, - ID2D1Device** d2dDevice, - ID2D1DeviceContext** d2dDeviceContext); - public: - Direct2D1(); - ~Direct2D1(); - }; -} +#pragma once + +namespace Platform::RuntimeLoader +{ + class Direct2D1 + { + private: + // FUCK Microsoft + typedef HRESULT(WINAPI* PFN_D2D1CreateFactory)( + D2D1_FACTORY_TYPE factoryType, + REFIID riid, + CONST D2D1_FACTORY_OPTIONS* pFactoryOptions, + void** ppIFactory); + typedef HRESULT(WINAPI* PFN_D2D1CreateDevice)( + IDXGIDevice* dxgiDevice, + CONST D2D1_CREATION_PROPERTIES* creationProperties, + ID2D1Device** d2dDevice); + private: + HMODULE dll_d2d1{}; + PFN_D2D1CreateFactory api_D2D1CreateFactory{}; + PFN_D2D1CreateDevice api_D2D1CreateDevice{}; + public: + HRESULT CreateFactory( + D2D1_FACTORY_TYPE factoryType, + REFIID riid, + void** ppIFactory); + HRESULT CreateDevice( + IDXGIDevice* dxgiDevice, + BOOL multiThread, + ID2D1Device** d2dDevice); + HRESULT CreateDevice( + IDXGIDevice* dxgiDevice, + BOOL multiThread, + ID2D1Device** d2dDevice, + ID2D1DeviceContext** d2dDeviceContext); + public: + Direct2D1(); + ~Direct2D1(); + }; +} diff --git a/LuaSTG/Platform/RuntimeLoader/Direct3D11.hpp b/engine/win32/windows/RuntimeLoader/Direct3D11.hpp similarity index 96% rename from LuaSTG/Platform/RuntimeLoader/Direct3D11.hpp rename to engine/win32/windows/RuntimeLoader/Direct3D11.hpp index f59be84e..0c818c81 100644 --- a/LuaSTG/Platform/RuntimeLoader/Direct3D11.hpp +++ b/engine/win32/windows/RuntimeLoader/Direct3D11.hpp @@ -1,35 +1,35 @@ -#pragma once - -namespace Platform::RuntimeLoader -{ - class Direct3D11 - { - private: - HMODULE dll_d3d11{}; - decltype(D3D11CreateDevice)* api_D3D11CreateDevice{}; - public: - HRESULT CreateDevice( - UINT Flags, - D3D_FEATURE_LEVEL TargetFeatureLevel, - ID3D11Device** ppDevice, - D3D_FEATURE_LEVEL* pFeatureLevel, - ID3D11DeviceContext** ppImmediateContext); - HRESULT CreateDeviceFromAdapter( - IDXGIAdapter* pAdapter, - UINT Flags, - D3D_FEATURE_LEVEL TargetFeatureLevel, - ID3D11Device** ppDevice, - D3D_FEATURE_LEVEL* pFeatureLevel, - ID3D11DeviceContext** ppImmediateContext); - HRESULT CreateDeviceFromSoftAdapter( - UINT Flags, - D3D_FEATURE_LEVEL TargetFeatureLevel, - ID3D11Device** ppDevice, - D3D_FEATURE_LEVEL* pFeatureLevel, - ID3D11DeviceContext** ppImmediateContext, - D3D_DRIVER_TYPE* pType = nullptr); - public: - Direct3D11(); - ~Direct3D11(); - }; -} +#pragma once + +namespace Platform::RuntimeLoader +{ + class Direct3D11 + { + private: + HMODULE dll_d3d11{}; + decltype(D3D11CreateDevice)* api_D3D11CreateDevice{}; + public: + HRESULT CreateDevice( + UINT Flags, + D3D_FEATURE_LEVEL TargetFeatureLevel, + ID3D11Device** ppDevice, + D3D_FEATURE_LEVEL* pFeatureLevel, + ID3D11DeviceContext** ppImmediateContext); + HRESULT CreateDeviceFromAdapter( + IDXGIAdapter* pAdapter, + UINT Flags, + D3D_FEATURE_LEVEL TargetFeatureLevel, + ID3D11Device** ppDevice, + D3D_FEATURE_LEVEL* pFeatureLevel, + ID3D11DeviceContext** ppImmediateContext); + HRESULT CreateDeviceFromSoftAdapter( + UINT Flags, + D3D_FEATURE_LEVEL TargetFeatureLevel, + ID3D11Device** ppDevice, + D3D_FEATURE_LEVEL* pFeatureLevel, + ID3D11DeviceContext** ppImmediateContext, + D3D_DRIVER_TYPE* pType = nullptr); + public: + Direct3D11(); + ~Direct3D11(); + }; +} diff --git a/LuaSTG/Platform/RuntimeLoader/Direct3DCompiler.hpp b/engine/win32/windows/RuntimeLoader/Direct3DCompiler.hpp similarity index 100% rename from LuaSTG/Platform/RuntimeLoader/Direct3DCompiler.hpp rename to engine/win32/windows/RuntimeLoader/Direct3DCompiler.hpp diff --git a/LuaSTG/Platform/RuntimeLoader/DirectComposition.hpp b/engine/win32/windows/RuntimeLoader/DirectComposition.hpp similarity index 96% rename from LuaSTG/Platform/RuntimeLoader/DirectComposition.hpp rename to engine/win32/windows/RuntimeLoader/DirectComposition.hpp index 38ca6e5e..e8a0498d 100644 --- a/LuaSTG/Platform/RuntimeLoader/DirectComposition.hpp +++ b/engine/win32/windows/RuntimeLoader/DirectComposition.hpp @@ -1,18 +1,18 @@ -#pragma once - -namespace Platform::RuntimeLoader -{ - class DirectComposition - { - private: - HMODULE dll_dcomp{}; - decltype(DCompositionCreateDevice)* api_DCompositionCreateDevice{}; - decltype(DCompositionCreateDevice2)* api_DCompositionCreateDevice2{}; - decltype(DCompositionCreateDevice3)* api_DCompositionCreateDevice3{}; - public: - HRESULT CreateDevice(IUnknown* renderingDevice, REFIID iid, void** dcompositionDevice); - public: - DirectComposition(); - ~DirectComposition(); - }; -} +#pragma once + +namespace Platform::RuntimeLoader +{ + class DirectComposition + { + private: + HMODULE dll_dcomp{}; + decltype(DCompositionCreateDevice)* api_DCompositionCreateDevice{}; + decltype(DCompositionCreateDevice2)* api_DCompositionCreateDevice2{}; + decltype(DCompositionCreateDevice3)* api_DCompositionCreateDevice3{}; + public: + HRESULT CreateDevice(IUnknown* renderingDevice, REFIID iid, void** dcompositionDevice); + public: + DirectComposition(); + ~DirectComposition(); + }; +} diff --git a/LuaSTG/Platform/RuntimeLoader/DirectWrite.hpp b/engine/win32/windows/RuntimeLoader/DirectWrite.hpp similarity index 94% rename from LuaSTG/Platform/RuntimeLoader/DirectWrite.hpp rename to engine/win32/windows/RuntimeLoader/DirectWrite.hpp index 2d85cd61..10f9f802 100644 --- a/LuaSTG/Platform/RuntimeLoader/DirectWrite.hpp +++ b/engine/win32/windows/RuntimeLoader/DirectWrite.hpp @@ -1,19 +1,19 @@ -#pragma once - -namespace Platform::RuntimeLoader -{ - class DirectWrite - { - private: - HMODULE dll_dwrite{}; - decltype(DWriteCreateFactory)* api_DWriteCreateFactory{}; - public: - HRESULT CreateFactory( - DWRITE_FACTORY_TYPE factoryType, - REFIID iid, - void** factory); - public: - DirectWrite(); - ~DirectWrite(); - }; -} +#pragma once + +namespace Platform::RuntimeLoader +{ + class DirectWrite + { + private: + HMODULE dll_dwrite{}; + decltype(DWriteCreateFactory)* api_DWriteCreateFactory{}; + public: + HRESULT CreateFactory( + DWRITE_FACTORY_TYPE factoryType, + REFIID iid, + void** factory); + public: + DirectWrite(); + ~DirectWrite(); + }; +} diff --git a/LuaSTG/Platform/RuntimeLoader/XAudio2.hpp b/engine/win32/windows/RuntimeLoader/XAudio2.hpp similarity index 100% rename from LuaSTG/Platform/RuntimeLoader/XAudio2.hpp rename to engine/win32/windows/RuntimeLoader/XAudio2.hpp diff --git a/LuaSTG/Platform/Shared.hpp b/engine/win32/windows/Shared.hpp similarity index 93% rename from LuaSTG/Platform/Shared.hpp rename to engine/win32/windows/Shared.hpp index 323d7d54..e8978179 100644 --- a/LuaSTG/Platform/Shared.hpp +++ b/engine/win32/windows/Shared.hpp @@ -1,114 +1,113 @@ -#pragma once - -#ifdef _WIN32_WINNT -#undef _WIN32_WINNT -#endif -#ifdef NTDDI_VERSION -#undef NTDDI_VERSION -#endif - -#include -#include -#include -#include -#include -#include -#include - -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#define NOSERVICE -#define NOMCX - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -VERSIONHELPERAPI -IsWindows10BuildOrGreater(DWORD build) -{ - OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 }; - DWORDLONG const dwlConditionMask = VerSetConditionMask( - VerSetConditionMask( - VerSetConditionMask( - 0, VER_MAJORVERSION, VER_GREATER_EQUAL), - VER_MINORVERSION, VER_GREATER_EQUAL), - VER_BUILDNUMBER, VER_GREATER_EQUAL); - - osvi.dwMajorVersion = HIBYTE(_WIN32_WINNT_WIN10); - osvi.dwMinorVersion = LOBYTE(_WIN32_WINNT_WIN10); - osvi.dwBuildNumber = build; - - return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER, dwlConditionMask) != FALSE; -} - -VERSIONHELPERAPI -IsWindows11OrGreater() -{ - return IsWindows10BuildOrGreater(22000); -} - -namespace Microsoft::WRL::Wrappers -{ - using ThreadHandle = HandleT; - using SemaphoreHandle = HandleT; -} - -// Now, let's FUCK Windows.h - -#undef CreateWindow -#undef DefWindowProc -#undef DrawText -#undef MessageBox - -#include -#include -#include -#include -#include -#include -#include - -#include - -#undef WIN32_LEAN_AND_MEAN -#undef NOMINMAX -#undef NOSERVICE -#undef NOMCX - -// helper - -inline std::string to_utf8(std::wstring_view const src) -{ - int const size = WideCharToMultiByte(CP_UTF8, 0, src.data(), (int)src.length(), NULL, 0, NULL, NULL); - if (size > 0) - { - std::string buf(size, '\0'); - int const result = WideCharToMultiByte(CP_UTF8, 0, src.data(), (int)src.length(), buf.data(), size, NULL, NULL); - if (result == size) - { - return buf; - } - } - return ""; -} -inline std::wstring to_wide(std::string_view const src) -{ - int const size = MultiByteToWideChar(CP_UTF8, 0, src.data(), (int)src.length(), NULL, 0); - if (size > 0) - { - std::wstring buf(size, L'\0'); - int const result = MultiByteToWideChar(CP_UTF8, 0, src.data(), (int)src.length(), buf.data(), size); - if (result == size) - { - return buf; - } - } - return L""; -} +#pragma once + +#ifdef _WIN32_WINNT +#undef _WIN32_WINNT +#endif +#ifdef NTDDI_VERSION +#undef NTDDI_VERSION +#endif + +#include +#include +#include +#include +#include +#include +#include + +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#define NOSERVICE +#define NOMCX + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +VERSIONHELPERAPI +IsWindows10BuildOrGreater(DWORD build) +{ + OSVERSIONINFOEXW osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 }; + DWORDLONG const dwlConditionMask = VerSetConditionMask( + VerSetConditionMask( + VerSetConditionMask( + 0, VER_MAJORVERSION, VER_GREATER_EQUAL), + VER_MINORVERSION, VER_GREATER_EQUAL), + VER_BUILDNUMBER, VER_GREATER_EQUAL); + + osvi.dwMajorVersion = HIBYTE(_WIN32_WINNT_WIN10); + osvi.dwMinorVersion = LOBYTE(_WIN32_WINNT_WIN10); + osvi.dwBuildNumber = build; + + return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER, dwlConditionMask) != FALSE; +} + +VERSIONHELPERAPI +IsWindows11OrGreater() +{ + return IsWindows10BuildOrGreater(22000); +} + +namespace Microsoft::WRL::Wrappers +{ + using SemaphoreHandle = HandleT; +} + +// Now, let's FUCK Windows.h + +#undef CreateWindow +#undef DefWindowProc +#undef DrawText +#undef MessageBox + +#include +#include +#include +#include +#include +#include +#include + +#include + +#undef WIN32_LEAN_AND_MEAN +#undef NOMINMAX +#undef NOSERVICE +#undef NOMCX + +// helper + +inline std::string to_utf8(std::wstring_view const src) +{ + int const size = WideCharToMultiByte(CP_UTF8, 0, src.data(), (int)src.length(), NULL, 0, NULL, NULL); + if (size > 0) + { + std::string buf(size, '\0'); + int const result = WideCharToMultiByte(CP_UTF8, 0, src.data(), (int)src.length(), buf.data(), size, NULL, NULL); + if (result == size) + { + return buf; + } + } + return ""; +} +inline std::wstring to_wide(std::string_view const src) +{ + int const size = MultiByteToWideChar(CP_UTF8, 0, src.data(), (int)src.length(), NULL, 0); + if (size > 0) + { + std::wstring buf(size, L'\0'); + int const result = MultiByteToWideChar(CP_UTF8, 0, src.data(), (int)src.length(), buf.data(), size); + if (result == size) + { + return buf; + } + } + return L""; +} diff --git a/LuaSTG/Platform/WindowSizeMoveController.cpp b/engine/win32/windows/WindowSizeMoveController.cpp similarity index 97% rename from LuaSTG/Platform/WindowSizeMoveController.cpp rename to engine/win32/windows/WindowSizeMoveController.cpp index 0c5af718..43052e86 100644 --- a/LuaSTG/Platform/WindowSizeMoveController.cpp +++ b/engine/win32/windows/WindowSizeMoveController.cpp @@ -1,241 +1,241 @@ -#include "Shared.hpp" -#include "WindowSizeMoveController.hpp" - -namespace Platform -{ - void WindowSizeMoveController::enterSizeMove(HWND hWnd, LPARAM lParam) - { - if (is_enable) - { - if (!is_size_or_move) - { - is_size_or_move = TRUE; - ::SetCapture(hWnd); - } - POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - ::MapWindowPoints(hWnd, NULL, &pt, 1); - last_mouse_pos.x = pt.x; - last_mouse_pos.y = pt.y; - last_mouse_dpos.x = 0; - last_mouse_dpos.y = 0; - RECT rc = {}; - ::GetWindowRect(hWnd, &rc); - last_window_pos.x = rc.left; - last_window_pos.y = rc.top; - } - } - void WindowSizeMoveController::onSizeMove(HWND hWnd, LPARAM lParam) - { - if (is_size_or_move) - { - POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - ::MapWindowPoints(hWnd, NULL, &pt, 1); - POINT dpt = { pt.x - last_mouse_pos.x, pt.y - last_mouse_pos.y }; - if (dpt.x != last_mouse_dpos.x || dpt.y != last_mouse_dpos.y) - { - last_mouse_dpos.x = dpt.x; - last_mouse_dpos.y = dpt.y; - if (is_enable) - { - ::SetWindowPos(hWnd, NULL, last_window_pos.x + dpt.x, last_window_pos.y + dpt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); - } - } - } - } - void WindowSizeMoveController::leaveSizeMove(HWND hWnd, LPARAM lParam) - { - if (is_size_or_move) - { - is_size_or_move = FALSE; - POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - ::MapWindowPoints(hWnd, NULL, &pt, 1); - POINT dpt = { pt.x - last_mouse_pos.x, pt.y - last_mouse_pos.y }; - if (dpt.x != last_mouse_dpos.x || dpt.y != last_mouse_dpos.y) - { - last_mouse_dpos.x = dpt.x; - last_mouse_dpos.y = dpt.y; - if (is_enable) - { - ::SetWindowPos(hWnd, NULL, last_window_pos.x + dpt.x, last_window_pos.y + dpt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); - } - } - ::ReleaseCapture(); - } - } - void WindowSizeMoveController::abortSizeMove() - { - if (is_size_or_move) - { - is_size_or_move = FALSE; - ::ReleaseCapture(); - } - } - bool WindowSizeMoveController::isMouseInMinimizeButton(LPARAM lParam) - { - LONG mx = GET_X_LPARAM(lParam); - LONG my = GET_Y_LPARAM(lParam); - if (mx >= minimize_button_rect.left && mx < minimize_button_rect.right && my >= minimize_button_rect.top && my < minimize_button_rect.bottom) - { - return true; - } - return false; - } - bool WindowSizeMoveController::isMouseInCloseButton(LPARAM lParam) - { - LONG mx = GET_X_LPARAM(lParam); - LONG my = GET_Y_LPARAM(lParam); - if (mx >= close_button_rect.left && mx < close_button_rect.right && my >= close_button_rect.top && my < close_button_rect.bottom) - { - return true; - } - return false; - } - bool WindowSizeMoveController::isMouseInTitleBar(LPARAM lParam) - { - LONG mx = GET_X_LPARAM(lParam); - LONG my = GET_Y_LPARAM(lParam); - if (mx >= title_bar_rect.left && mx < title_bar_rect.right && my >= title_bar_rect.top && my < title_bar_rect.bottom) - { - return true; - } - return false; - } - void WindowSizeMoveController::onMouseLeftButtonDown(HWND hWnd, LPARAM lParam) - { - if (isMouseInMinimizeButton(lParam)) - { - is_minimize_button_down = TRUE; - } - else if (isMouseInCloseButton(lParam)) - { - is_close_button_down = TRUE; - } - else if (isMouseInTitleBar(lParam)) - { - enterSizeMove(hWnd, lParam); - } - } - void WindowSizeMoveController::onMouseLeftButtonUp(HWND hWnd, LPARAM lParam) - { - if (is_minimize_button_down) - { - is_minimize_button_down = FALSE; - if (is_enable && isMouseInMinimizeButton(lParam)) - { - ::ShowWindow(hWnd, SW_MINIMIZE); - } - } - else if (is_close_button_down) - { - is_close_button_down = FALSE; - if (is_enable && isMouseInCloseButton(lParam)) - { - //::CloseWindow(hWnd); - //::PostQuitMessage(0); - ::SendMessageW(hWnd, WM_CLOSE, 0, 0); - } - } - leaveSizeMove(hWnd, lParam); - } - - void WindowSizeMoveController::setEnable(BOOL b) { is_enable = b; } - void WindowSizeMoveController::setMinimizeButtonRect(RECT rc) { minimize_button_rect = rc; } - void WindowSizeMoveController::setCloseButtonRect(RECT rc) { close_button_rect = rc; } - void WindowSizeMoveController::setTitleBarRect(RECT rc) { title_bar_rect = rc; } - void WindowSizeMoveController::setWindow(HWND hWnd) - { - if (window != hWnd) - { - is_minimize_button_down = FALSE; - is_close_button_down = FALSE; - abortSizeMove(); - if (window) - { - ::RemovePropW(window, L"W:SWCTRL"); - } - window = hWnd; - if (window) - { - ::SetPropW(window, L"W:SWCTRL", this); - } - } - } - WindowSizeMoveController::Result WindowSizeMoveController::handleSizeMove(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) - { - if (window == hWnd) - { - switch (message) - { - case WM_ACTIVATEAPP: - switch (wParam) - { - case FALSE: - is_minimize_button_down = FALSE; - is_close_button_down = FALSE; - abortSizeMove(); - break; - case TRUE: - default: - break; - } - case WM_ACTIVATE: - switch (wParam) - { - case WA_INACTIVE: - is_minimize_button_down = FALSE; - is_close_button_down = FALSE; - abortSizeMove(); - break; - case WA_ACTIVE: - case WA_CLICKACTIVE: - default: - break; - } - case WM_DEVMODECHANGE: - case WM_DISPLAYCHANGE: - //case WM_DPICHANGED: - is_minimize_button_down = FALSE; - is_close_button_down = FALSE; - abortSizeMove(); - break; - case WM_LBUTTONDOWN: - onMouseLeftButtonDown(hWnd, lParam); - break; - case WM_MOUSEMOVE: - onSizeMove(hWnd, lParam); - break; - case WM_LBUTTONUP: - onMouseLeftButtonUp(hWnd, lParam); - break; - } - } - return Result{ 0, FALSE }; - } - WindowSizeMoveController::Result WindowSizeMoveController::handleSizeMoveStatic(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) - { - if (WindowSizeMoveController* self = (WindowSizeMoveController*)GetPropW(hWnd, L"W:SWCTRL")) - { - return self->handleSizeMove(hWnd, message, wParam, lParam); - } - return Result{ 0, FALSE }; - } - - WindowSizeMoveController::WindowSizeMoveController() - : window(NULL) - , title_bar_rect({}) - , minimize_button_rect({}) - , close_button_rect({}) - , last_mouse_pos({}) - , last_mouse_dpos({}) - , last_window_pos({}) - , is_enable(FALSE) - , is_size_or_move(FALSE) - , is_minimize_button_down(FALSE) - , is_close_button_down(FALSE) - { - } - WindowSizeMoveController::~WindowSizeMoveController() - { - setWindow(NULL); - } -} +#include "Shared.hpp" +#include "WindowSizeMoveController.hpp" + +namespace Platform +{ + void WindowSizeMoveController::enterSizeMove(HWND hWnd, LPARAM lParam) + { + if (is_enable) + { + if (!is_size_or_move) + { + is_size_or_move = TRUE; + ::SetCapture(hWnd); + } + POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + ::MapWindowPoints(hWnd, NULL, &pt, 1); + last_mouse_pos.x = pt.x; + last_mouse_pos.y = pt.y; + last_mouse_dpos.x = 0; + last_mouse_dpos.y = 0; + RECT rc = {}; + ::GetWindowRect(hWnd, &rc); + last_window_pos.x = rc.left; + last_window_pos.y = rc.top; + } + } + void WindowSizeMoveController::onSizeMove(HWND hWnd, LPARAM lParam) + { + if (is_size_or_move) + { + POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + ::MapWindowPoints(hWnd, NULL, &pt, 1); + POINT dpt = { pt.x - last_mouse_pos.x, pt.y - last_mouse_pos.y }; + if (dpt.x != last_mouse_dpos.x || dpt.y != last_mouse_dpos.y) + { + last_mouse_dpos.x = dpt.x; + last_mouse_dpos.y = dpt.y; + if (is_enable) + { + ::SetWindowPos(hWnd, NULL, last_window_pos.x + dpt.x, last_window_pos.y + dpt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); + } + } + } + } + void WindowSizeMoveController::leaveSizeMove(HWND hWnd, LPARAM lParam) + { + if (is_size_or_move) + { + is_size_or_move = FALSE; + POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + ::MapWindowPoints(hWnd, NULL, &pt, 1); + POINT dpt = { pt.x - last_mouse_pos.x, pt.y - last_mouse_pos.y }; + if (dpt.x != last_mouse_dpos.x || dpt.y != last_mouse_dpos.y) + { + last_mouse_dpos.x = dpt.x; + last_mouse_dpos.y = dpt.y; + if (is_enable) + { + ::SetWindowPos(hWnd, NULL, last_window_pos.x + dpt.x, last_window_pos.y + dpt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); + } + } + ::ReleaseCapture(); + } + } + void WindowSizeMoveController::abortSizeMove() + { + if (is_size_or_move) + { + is_size_or_move = FALSE; + ::ReleaseCapture(); + } + } + bool WindowSizeMoveController::isMouseInMinimizeButton(LPARAM lParam) + { + LONG mx = GET_X_LPARAM(lParam); + LONG my = GET_Y_LPARAM(lParam); + if (mx >= minimize_button_rect.left && mx < minimize_button_rect.right && my >= minimize_button_rect.top && my < minimize_button_rect.bottom) + { + return true; + } + return false; + } + bool WindowSizeMoveController::isMouseInCloseButton(LPARAM lParam) + { + LONG mx = GET_X_LPARAM(lParam); + LONG my = GET_Y_LPARAM(lParam); + if (mx >= close_button_rect.left && mx < close_button_rect.right && my >= close_button_rect.top && my < close_button_rect.bottom) + { + return true; + } + return false; + } + bool WindowSizeMoveController::isMouseInTitleBar(LPARAM lParam) + { + LONG mx = GET_X_LPARAM(lParam); + LONG my = GET_Y_LPARAM(lParam); + if (mx >= title_bar_rect.left && mx < title_bar_rect.right && my >= title_bar_rect.top && my < title_bar_rect.bottom) + { + return true; + } + return false; + } + void WindowSizeMoveController::onMouseLeftButtonDown(HWND hWnd, LPARAM lParam) + { + if (isMouseInMinimizeButton(lParam)) + { + is_minimize_button_down = TRUE; + } + else if (isMouseInCloseButton(lParam)) + { + is_close_button_down = TRUE; + } + else if (isMouseInTitleBar(lParam)) + { + enterSizeMove(hWnd, lParam); + } + } + void WindowSizeMoveController::onMouseLeftButtonUp(HWND hWnd, LPARAM lParam) + { + if (is_minimize_button_down) + { + is_minimize_button_down = FALSE; + if (is_enable && isMouseInMinimizeButton(lParam)) + { + ::ShowWindow(hWnd, SW_MINIMIZE); + } + } + else if (is_close_button_down) + { + is_close_button_down = FALSE; + if (is_enable && isMouseInCloseButton(lParam)) + { + //::CloseWindow(hWnd); + //::PostQuitMessage(0); + ::SendMessageW(hWnd, WM_CLOSE, 0, 0); + } + } + leaveSizeMove(hWnd, lParam); + } + + void WindowSizeMoveController::setEnable(BOOL b) { is_enable = b; } + void WindowSizeMoveController::setMinimizeButtonRect(RECT rc) { minimize_button_rect = rc; } + void WindowSizeMoveController::setCloseButtonRect(RECT rc) { close_button_rect = rc; } + void WindowSizeMoveController::setTitleBarRect(RECT rc) { title_bar_rect = rc; } + void WindowSizeMoveController::setWindow(HWND hWnd) + { + if (window != hWnd) + { + is_minimize_button_down = FALSE; + is_close_button_down = FALSE; + abortSizeMove(); + if (window) + { + ::RemovePropW(window, L"W:SWCTRL"); + } + window = hWnd; + if (window) + { + ::SetPropW(window, L"W:SWCTRL", this); + } + } + } + WindowSizeMoveController::Result WindowSizeMoveController::handleSizeMove(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + { + if (window == hWnd) + { + switch (message) + { + case WM_ACTIVATEAPP: + switch (wParam) + { + case FALSE: + is_minimize_button_down = FALSE; + is_close_button_down = FALSE; + abortSizeMove(); + break; + case TRUE: + default: + break; + } + case WM_ACTIVATE: + switch (wParam) + { + case WA_INACTIVE: + is_minimize_button_down = FALSE; + is_close_button_down = FALSE; + abortSizeMove(); + break; + case WA_ACTIVE: + case WA_CLICKACTIVE: + default: + break; + } + case WM_DEVMODECHANGE: + case WM_DISPLAYCHANGE: + //case WM_DPICHANGED: + is_minimize_button_down = FALSE; + is_close_button_down = FALSE; + abortSizeMove(); + break; + case WM_LBUTTONDOWN: + onMouseLeftButtonDown(hWnd, lParam); + break; + case WM_MOUSEMOVE: + onSizeMove(hWnd, lParam); + break; + case WM_LBUTTONUP: + onMouseLeftButtonUp(hWnd, lParam); + break; + } + } + return Result{ 0, FALSE }; + } + WindowSizeMoveController::Result WindowSizeMoveController::handleSizeMoveStatic(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) + { + if (WindowSizeMoveController* self = (WindowSizeMoveController*)GetPropW(hWnd, L"W:SWCTRL")) + { + return self->handleSizeMove(hWnd, message, wParam, lParam); + } + return Result{ 0, FALSE }; + } + + WindowSizeMoveController::WindowSizeMoveController() + : window(NULL) + , title_bar_rect({}) + , minimize_button_rect({}) + , close_button_rect({}) + , last_mouse_pos({}) + , last_mouse_dpos({}) + , last_window_pos({}) + , is_enable(FALSE) + , is_size_or_move(FALSE) + , is_minimize_button_down(FALSE) + , is_close_button_down(FALSE) + { + } + WindowSizeMoveController::~WindowSizeMoveController() + { + setWindow(NULL); + } +} diff --git a/LuaSTG/Platform/WindowSizeMoveController.hpp b/engine/win32/windows/WindowSizeMoveController.hpp similarity index 96% rename from LuaSTG/Platform/WindowSizeMoveController.hpp rename to engine/win32/windows/WindowSizeMoveController.hpp index 32a77f35..d9b18450 100644 --- a/LuaSTG/Platform/WindowSizeMoveController.hpp +++ b/engine/win32/windows/WindowSizeMoveController.hpp @@ -1,47 +1,47 @@ -#pragma once - -namespace Platform -{ - class WindowSizeMoveController - { - public: - struct Result - { - LRESULT lResult; - BOOL bReturn; - }; - private: - HWND window; - RECT title_bar_rect; - RECT minimize_button_rect; - RECT close_button_rect; - POINT last_mouse_pos; - POINT last_mouse_dpos; - POINT last_window_pos; - BOOL is_enable; - BOOL is_size_or_move; - BOOL is_minimize_button_down; - BOOL is_close_button_down; - private: - void enterSizeMove(HWND hWnd, LPARAM lParam); - void onSizeMove(HWND hWnd, LPARAM lParam); - void leaveSizeMove(HWND hWnd, LPARAM lParam); - void abortSizeMove(); - bool isMouseInMinimizeButton(LPARAM lParam); - bool isMouseInCloseButton(LPARAM lParam); - bool isMouseInTitleBar(LPARAM lParam); - void onMouseLeftButtonDown(HWND hWnd, LPARAM lParam); - void onMouseLeftButtonUp(HWND hWnd, LPARAM lParam); - public: - void setEnable(BOOL b); - void setMinimizeButtonRect(RECT rc); - void setCloseButtonRect(RECT rc); - void setTitleBarRect(RECT rc); - void setWindow(HWND hWnd); - Result handleSizeMove(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - static Result handleSizeMoveStatic(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); - public: - WindowSizeMoveController(); - ~WindowSizeMoveController(); - }; -} +#pragma once + +namespace Platform +{ + class WindowSizeMoveController + { + public: + struct Result + { + LRESULT lResult; + BOOL bReturn; + }; + private: + HWND window; + RECT title_bar_rect; + RECT minimize_button_rect; + RECT close_button_rect; + POINT last_mouse_pos; + POINT last_mouse_dpos; + POINT last_window_pos; + BOOL is_enable; + BOOL is_size_or_move; + BOOL is_minimize_button_down; + BOOL is_close_button_down; + private: + void enterSizeMove(HWND hWnd, LPARAM lParam); + void onSizeMove(HWND hWnd, LPARAM lParam); + void leaveSizeMove(HWND hWnd, LPARAM lParam); + void abortSizeMove(); + bool isMouseInMinimizeButton(LPARAM lParam); + bool isMouseInCloseButton(LPARAM lParam); + bool isMouseInTitleBar(LPARAM lParam); + void onMouseLeftButtonDown(HWND hWnd, LPARAM lParam); + void onMouseLeftButtonUp(HWND hWnd, LPARAM lParam); + public: + void setEnable(BOOL b); + void setMinimizeButtonRect(RECT rc); + void setCloseButtonRect(RECT rc); + void setTitleBarRect(RECT rc); + void setWindow(HWND hWnd); + Result handleSizeMove(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + static Result handleSizeMoveStatic(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); + public: + WindowSizeMoveController(); + ~WindowSizeMoveController(); + }; +} diff --git a/LuaSTG/Platform/WindowTheme.cpp b/engine/win32/windows/WindowTheme.cpp similarity index 97% rename from LuaSTG/Platform/WindowTheme.cpp rename to engine/win32/windows/WindowTheme.cpp index 22b23de9..a2a7f3a8 100644 --- a/LuaSTG/Platform/WindowTheme.cpp +++ b/engine/win32/windows/WindowTheme.cpp @@ -1,110 +1,110 @@ -#include "Shared.hpp" -#include "WindowTheme.hpp" - -namespace Platform -{ - // https://github.com/microsoft/WindowsAppSDK/issues/41# - - // optional Mica support (but have bug) - // DWORD const DWMWA_MICA_EFFFECT = 0x405; - // BOOL mica_effect = TRUE; - // HRESULT hr = loader().api_DwmSetWindowAttribute(hWnd, DWMWA_MICA_EFFFECT, &mica_effect, sizeof(mica_effect)); - - struct DwmapiLoader - { - HMODULE dll_dwmapi = NULL; - decltype(::DwmSetWindowAttribute)* api_DwmSetWindowAttribute = NULL; - decltype(::DwmGetWindowAttribute)* api_DwmGetWindowAttribute = NULL; - decltype(::DwmEnableBlurBehindWindow)* api_DwmEnableBlurBehindWindow = NULL; - decltype(::DwmExtendFrameIntoClientArea)* api_DwmExtendFrameIntoClientArea = NULL; - DwmapiLoader() - { - dll_dwmapi = LoadLibraryW(L"dwmapi.dll"); - if (dll_dwmapi) - { - api_DwmSetWindowAttribute = (decltype(::DwmSetWindowAttribute)*)GetProcAddress(dll_dwmapi, "DwmSetWindowAttribute"); - api_DwmGetWindowAttribute = (decltype(::DwmGetWindowAttribute)*)GetProcAddress(dll_dwmapi, "DwmGetWindowAttribute"); - api_DwmEnableBlurBehindWindow = (decltype(::DwmEnableBlurBehindWindow)*)GetProcAddress(dll_dwmapi, "DwmEnableBlurBehindWindow"); - api_DwmExtendFrameIntoClientArea = (decltype(::DwmExtendFrameIntoClientArea)*)GetProcAddress(dll_dwmapi, "DwmExtendFrameIntoClientArea"); - } - } - ~DwmapiLoader() - { - if (dll_dwmapi) - { - FreeLibrary(dll_dwmapi); - } - } - }; - static DwmapiLoader& loader() - { - static DwmapiLoader instance; - return instance; - } - - BOOL WindowTheme::IsSystemDarkModeEnabled() - { - HKEY hKey = NULL; - if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_READ, &hKey)) - { - DWORD dwValue = 0; - DWORD dwValueSize = 4; - DWORD dwType = 0; - if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"SystemUsesLightTheme", NULL, &dwType, (BYTE*)&dwValue, &dwValueSize)) - { - RegCloseKey(hKey); - return dwValue == 0; - } - else - { - RegCloseKey(hKey); - return FALSE; - } - } - return FALSE; - } - BOOL WindowTheme::ShouldApplicationEnableDarkMode() - { - auto const key_path{ L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize" }; - auto const value_name{ L"AppsUseLightTheme" }; - DWORD type{}; - DWORD value{}; - DWORD size{ sizeof(DWORD) }; - if (ERROR_SUCCESS != RegGetValueW(HKEY_CURRENT_USER, key_path, value_name, RRF_RT_REG_DWORD, &type, &value, &size)) { - size = DWORD{ sizeof(DWORD) }; - if (ERROR_SUCCESS != RegGetValueW(HKEY_CURRENT_USER, key_path, value_name, RRF_RT_REG_DWORD | KEY_WOW64_64KEY, &type, &value, &size)) { - size = DWORD{ sizeof(DWORD) }; - if (ERROR_SUCCESS != RegGetValueW(HKEY_CURRENT_USER, key_path, value_name, RRF_RT_REG_DWORD | KEY_WOW64_32KEY, &type, &value, &size)) { - return false; - } - } - } - if (type == REG_DWORD && size == sizeof(DWORD)) { - return value == 0; - } - return false; - } - BOOL WindowTheme::SetDarkMode(HWND hWnd, BOOL bEnable, BOOL bFocus) - { - if (loader().api_DwmSetWindowAttribute) - { - // Method 1 (Native but not good?): DWMWA_USE_IMMERSIVE_DARK_MODE - - std::ignore = bFocus; - BOOL dark_mode = bEnable; - HRESULT hr = loader().api_DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &dark_mode, sizeof(dark_mode)); - return SUCCEEDED(hr); - - // Method 2: DWMWA_CAPTION_COLOR - - //COLORREF color = bEnable ? (bFocus ? 0x00202020 : 0x002B2B2B) : 0x00FFFFFF; // 0x002E2E2E - //HRESULT hr = loader().api_DwmSetWindowAttribute(hWnd, DWMWA_CAPTION_COLOR, &color, sizeof(color)); - //return SUCCEEDED(hr); - } - return FALSE; - } - BOOL WindowTheme::UpdateColorMode(HWND hWnd, BOOL bFocus) - { - return SetDarkMode(hWnd, ShouldApplicationEnableDarkMode(), bFocus); - } -} +#include "Shared.hpp" +#include "WindowTheme.hpp" + +namespace Platform +{ + // https://github.com/microsoft/WindowsAppSDK/issues/41# + + // optional Mica support (but have bug) + // DWORD const DWMWA_MICA_EFFFECT = 0x405; + // BOOL mica_effect = TRUE; + // HRESULT hr = loader().api_DwmSetWindowAttribute(hWnd, DWMWA_MICA_EFFFECT, &mica_effect, sizeof(mica_effect)); + + struct DwmapiLoader + { + HMODULE dll_dwmapi = NULL; + decltype(::DwmSetWindowAttribute)* api_DwmSetWindowAttribute = NULL; + decltype(::DwmGetWindowAttribute)* api_DwmGetWindowAttribute = NULL; + decltype(::DwmEnableBlurBehindWindow)* api_DwmEnableBlurBehindWindow = NULL; + decltype(::DwmExtendFrameIntoClientArea)* api_DwmExtendFrameIntoClientArea = NULL; + DwmapiLoader() + { + dll_dwmapi = LoadLibraryW(L"dwmapi.dll"); + if (dll_dwmapi) + { + api_DwmSetWindowAttribute = (decltype(::DwmSetWindowAttribute)*)GetProcAddress(dll_dwmapi, "DwmSetWindowAttribute"); + api_DwmGetWindowAttribute = (decltype(::DwmGetWindowAttribute)*)GetProcAddress(dll_dwmapi, "DwmGetWindowAttribute"); + api_DwmEnableBlurBehindWindow = (decltype(::DwmEnableBlurBehindWindow)*)GetProcAddress(dll_dwmapi, "DwmEnableBlurBehindWindow"); + api_DwmExtendFrameIntoClientArea = (decltype(::DwmExtendFrameIntoClientArea)*)GetProcAddress(dll_dwmapi, "DwmExtendFrameIntoClientArea"); + } + } + ~DwmapiLoader() + { + if (dll_dwmapi) + { + FreeLibrary(dll_dwmapi); + } + } + }; + static DwmapiLoader& loader() + { + static DwmapiLoader instance; + return instance; + } + + BOOL WindowTheme::IsSystemDarkModeEnabled() + { + HKEY hKey = NULL; + if (ERROR_SUCCESS == RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_READ, &hKey)) + { + DWORD dwValue = 0; + DWORD dwValueSize = 4; + DWORD dwType = 0; + if (ERROR_SUCCESS == RegQueryValueExW(hKey, L"SystemUsesLightTheme", NULL, &dwType, (BYTE*)&dwValue, &dwValueSize)) + { + RegCloseKey(hKey); + return dwValue == 0; + } + else + { + RegCloseKey(hKey); + return FALSE; + } + } + return FALSE; + } + BOOL WindowTheme::ShouldApplicationEnableDarkMode() + { + auto const key_path{ L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize" }; + auto const value_name{ L"AppsUseLightTheme" }; + DWORD type{}; + DWORD value{}; + DWORD size{ sizeof(DWORD) }; + if (ERROR_SUCCESS != RegGetValueW(HKEY_CURRENT_USER, key_path, value_name, RRF_RT_REG_DWORD, &type, &value, &size)) { + size = DWORD{ sizeof(DWORD) }; + if (ERROR_SUCCESS != RegGetValueW(HKEY_CURRENT_USER, key_path, value_name, RRF_RT_REG_DWORD | KEY_WOW64_64KEY, &type, &value, &size)) { + size = DWORD{ sizeof(DWORD) }; + if (ERROR_SUCCESS != RegGetValueW(HKEY_CURRENT_USER, key_path, value_name, RRF_RT_REG_DWORD | KEY_WOW64_32KEY, &type, &value, &size)) { + return false; + } + } + } + if (type == REG_DWORD && size == sizeof(DWORD)) { + return value == 0; + } + return false; + } + BOOL WindowTheme::SetDarkMode(HWND hWnd, BOOL bEnable, BOOL bFocus) + { + if (loader().api_DwmSetWindowAttribute) + { + // Method 1 (Native but not good?): DWMWA_USE_IMMERSIVE_DARK_MODE + + std::ignore = bFocus; + BOOL dark_mode = bEnable; + HRESULT hr = loader().api_DwmSetWindowAttribute(hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &dark_mode, sizeof(dark_mode)); + return SUCCEEDED(hr); + + // Method 2: DWMWA_CAPTION_COLOR + + //COLORREF color = bEnable ? (bFocus ? 0x00202020 : 0x002B2B2B) : 0x00FFFFFF; // 0x002E2E2E + //HRESULT hr = loader().api_DwmSetWindowAttribute(hWnd, DWMWA_CAPTION_COLOR, &color, sizeof(color)); + //return SUCCEEDED(hr); + } + return FALSE; + } + BOOL WindowTheme::UpdateColorMode(HWND hWnd, BOOL bFocus) + { + return SetDarkMode(hWnd, ShouldApplicationEnableDarkMode(), bFocus); + } +} diff --git a/LuaSTG/Platform/WindowTheme.hpp b/engine/win32/windows/WindowTheme.hpp similarity index 95% rename from LuaSTG/Platform/WindowTheme.hpp rename to engine/win32/windows/WindowTheme.hpp index b99db0e7..a4d8f0f8 100644 --- a/LuaSTG/Platform/WindowTheme.hpp +++ b/engine/win32/windows/WindowTheme.hpp @@ -1,13 +1,13 @@ -#pragma once - -namespace Platform -{ - class WindowTheme - { - public: - static BOOL IsSystemDarkModeEnabled(); - static BOOL ShouldApplicationEnableDarkMode(); - static BOOL SetDarkMode(HWND hWnd, BOOL bEnable, BOOL bFocus); - static BOOL UpdateColorMode(HWND hWnd, BOOL bFocus); - }; -} +#pragma once + +namespace Platform +{ + class WindowTheme + { + public: + static BOOL IsSystemDarkModeEnabled(); + static BOOL ShouldApplicationEnableDarkMode(); + static BOOL SetDarkMode(HWND hWnd, BOOL bEnable, BOOL bFocus); + static BOOL UpdateColorMode(HWND hWnd, BOOL bFocus); + }; +} diff --git a/LuaSTG/Platform/WindowsVersion.cpp b/engine/win32/windows/WindowsVersion.cpp similarity index 96% rename from LuaSTG/Platform/WindowsVersion.cpp rename to engine/win32/windows/WindowsVersion.cpp index cf89a6b0..e3257c2b 100644 --- a/LuaSTG/Platform/WindowsVersion.cpp +++ b/engine/win32/windows/WindowsVersion.cpp @@ -1,329 +1,329 @@ -#include "Shared.hpp" -#include "WindowsVersion.hpp" - -#pragma comment(lib, "Version.lib") - -namespace Platform -{ - namespace detail - { - static bool read = false; - static std::string_view name = ""; - static bool eos = false; - - void refresh() - { - if (read) - { - return; - } - - #define MAKE(N,S) name = N; eos = S; read = true; return - - // Windows 11 - - if (IsWindows10BuildOrGreater(26201)) - { - MAKE("Windows 11 25H2+", false); - } - if (WindowsVersion::Is11Build26200()) - { - MAKE("Windows 11 25H2", false); - } - if (WindowsVersion::Is11Build26100()) - { - MAKE("Windows 11 24H2", false); - } - if (WindowsVersion::Is11Build22631()) - { - MAKE("Windows 11 23H2", false); - } - if (WindowsVersion::Is11Build22621()) - { - MAKE("Windows 11 22H2", false); - } - if (WindowsVersion::Is11Build22000()) - { - MAKE("Windows 11 21H2", true); - } - if (WindowsVersion::Is11()) - { - MAKE("Windows 11", true); - } - - // Windows 10 - - if (IsWindows10BuildOrGreater(19046)) - { - MAKE("Windows 10 22H2+", false); - } - if (WindowsVersion::Is10Build19045()) - { - MAKE("Windows 10 22H2", false); - } - if (WindowsVersion::Is10Build19044()) - { - MAKE("Windows 10 21H2", true); - } - if (WindowsVersion::Is10Build19043()) - { - MAKE("Windows 10 21H1", true); - } - if (WindowsVersion::Is10Build19042()) - { - MAKE("Windows 10 20H2", true); - } - if (WindowsVersion::Is10Build19041()) - { - MAKE("Windows 10 2004", true); - } - if (WindowsVersion::Is10Build18363()) - { - MAKE("Windows 10 1909", true); - } - if (WindowsVersion::Is10Build18362()) - { - MAKE("Windows 10 1903", true); - } - if (WindowsVersion::Is10Build17763()) - { - MAKE("Windows 10 1809", true); - } - if (WindowsVersion::Is10Build17134()) - { - MAKE("Windows 10 1803", true); - } - if (WindowsVersion::Is10Build16299()) - { - MAKE("Windows 10 1709", true); - } - if (WindowsVersion::Is10Build15063()) - { - MAKE("Windows 10 1703", true); - } - if (WindowsVersion::Is10Build14393()) - { - MAKE("Windows 10 1607", true); - } - if (WindowsVersion::Is10Build10586()) - { - MAKE("Windows 10 1511", true); - } - if (WindowsVersion::Is10Build10240()) - { - MAKE("Windows 10 1507", true); - } - if (WindowsVersion::Is10()) - { - MAKE("Windows 10", true); - } - - // Windows 8 - - if (WindowsVersion::Is8Point1()) - { - MAKE("Windows 8.1", true); - } - if (WindowsVersion::Is8()) - { - MAKE("Windows 8", true); - } - - // Windows 7 - - if (WindowsVersion::Is7SP1WithPlatformUpdate()) - { - MAKE("Windows 7 SP1 With Platform Update", true); - } - if (WindowsVersion::Is7SP1()) - { - MAKE("Windows 7 SP1", true); - } - if (WindowsVersion::Is7()) - { - MAKE("Windows 7", true); - } - - // Windows Vista - - if (IsWindowsVistaSP2OrGreater()) - { - MAKE("Windows Vista SP2", true); - } - if (IsWindowsVistaSP1OrGreater()) - { - MAKE("Windows Vista SP1", true); - } - if (IsWindowsVistaOrGreater()) - { - MAKE("Windows Vista", true); - } - - // Windows XP - - if (IsWindowsXPSP3OrGreater()) - { - MAKE("Windows XP SP3", true); - } - if (IsWindowsXPSP2OrGreater()) - { - MAKE("Windows XP SP2", true); - } - if (IsWindowsXPSP1OrGreater()) - { - MAKE("Windows XP SP1", true); - } - if (IsWindowsXPOrGreater()) - { - MAKE("Windows XP", true); - } - - // Old - - MAKE("Windows ?", true); - - #undef MAKE - } - - static bool read_dxgi = false; - static bool dxgi_1_2 = false; - - bool check_dxgi_1_2() - { - if (read_dxgi) - { - return dxgi_1_2; - } - bool update_exist = false; - if (HMODULE dll_dxgi = LoadLibraryW(L"dxgi.dll")) - { - if (auto* api_CreateDXGIFactory1 = (decltype(CreateDXGIFactory1)*)GetProcAddress(dll_dxgi, "CreateDXGIFactory1")) - { - Microsoft::WRL::ComPtr dxgi_factory; - if (SUCCEEDED(api_CreateDXGIFactory1(IID_PPV_ARGS(&dxgi_factory)))) - { - update_exist = true; - } - } - FreeLibrary(dll_dxgi); - } - read_dxgi = true; - dxgi_1_2 = update_exist; - return dxgi_1_2; - } - } - - std::string_view WindowsVersion::GetName() - { - detail::refresh(); - return detail::name; - } - - bool WindowsVersion::IsEndOfSupport() - { - detail::refresh(); - return detail::eos; - } - - bool WindowsVersion::Is7() { return IsWindows7OrGreater(); } - bool WindowsVersion::Is7SP1() { return IsWindows7SP1OrGreater(); } - bool WindowsVersion::Is7SP1WithPlatformUpdate() { return IsWindows7SP1OrGreater() && detail::check_dxgi_1_2(); } - - bool WindowsVersion::Is8() { return IsWindows8OrGreater(); } - bool WindowsVersion::Is8Point1() { return IsWindows8Point1OrGreater(); } - - bool WindowsVersion::Is10() { return IsWindows10OrGreater(); } - bool WindowsVersion::Is10Build10240() { return IsWindows10BuildOrGreater(10240); } - bool WindowsVersion::Is10Build10586() { return IsWindows10BuildOrGreater(10586); } - bool WindowsVersion::Is10Build14393() { return IsWindows10BuildOrGreater(14393); } - bool WindowsVersion::Is10Build15063() { return IsWindows10BuildOrGreater(15063); } - bool WindowsVersion::Is10Build16299() { return IsWindows10BuildOrGreater(16299); } - bool WindowsVersion::Is10Build17134() { return IsWindows10BuildOrGreater(17134); } - bool WindowsVersion::Is10Build17763() { return IsWindows10BuildOrGreater(17763); } - bool WindowsVersion::Is10Build18362() { return IsWindows10BuildOrGreater(18362); } - bool WindowsVersion::Is10Build18363() { return IsWindows10BuildOrGreater(18363); } - bool WindowsVersion::Is10Build19041() { return IsWindows10BuildOrGreater(19041); } - bool WindowsVersion::Is10Build19042() { return IsWindows10BuildOrGreater(19042); } - bool WindowsVersion::Is10Build19043() { return IsWindows10BuildOrGreater(19043); } - bool WindowsVersion::Is10Build19044() { return IsWindows10BuildOrGreater(19044); } - bool WindowsVersion::Is10Build19045() { return IsWindows10BuildOrGreater(19045); } - - bool WindowsVersion::Is11() { return IsWindows11OrGreater(); } - bool WindowsVersion::Is11Build22000() { return IsWindows10BuildOrGreater(22000); } - bool WindowsVersion::Is11Build22621() { return IsWindows10BuildOrGreater(22621); } - bool WindowsVersion::Is11Build22631() { return IsWindows10BuildOrGreater(22631); } - bool WindowsVersion::Is11Build26100() { return IsWindows10BuildOrGreater(26100); } - bool WindowsVersion::Is11Build26200() { return IsWindows10BuildOrGreater(26200); } - - struct VersionStringBuffer - { - std::array buffer{}; - std::string_view view{ "0.0.0.0" }; - }; - - static bool GetFileVersionString(std::wstring_view file, VersionStringBuffer& sbuffer) - { - std::array windir{}; - UINT const windir_len = GetWindowsDirectoryW(windir.data(), MAX_PATH); - assert(windir_len > 0); - if (windir_len > 0) - { - std::wstring sys32dir; - sys32dir.append(windir.data(), windir_len); - sys32dir.append(std::wstring_view(L"\\System32\\")); - sys32dir.append(file); - - // get file metadata size - DWORD const metadata_size = GetFileVersionInfoSizeW(sys32dir.c_str(), NULL); - assert(metadata_size > 0); - if (metadata_size > 0) - { - // get file metadata - std::vector metadata(metadata_size); - BOOL const status = GetFileVersionInfoW(sys32dir.c_str(), 0, metadata_size, metadata.data()); - assert(status); - if (status) - { - // parser file metadata - VS_FIXEDFILEINFO* info = NULL; - UINT read = 0; - BOOL const query_status = VerQueryValueW(metadata.data(), L"\\", (LPVOID*)&info, &read); - assert(query_status); - if (query_status) - { - // format version - int length = std::snprintf( - sbuffer.buffer.data(), - sbuffer.buffer.size(), - "%d.%d.%d.%d", - (info->dwProductVersionMS >> 16) & 0xFFFF, - info->dwProductVersionMS & 0xFFFF, - (info->dwProductVersionLS >> 16) & 0xFFFF, - info->dwProductVersionLS & 0xFFFF); - sbuffer.view = std::string_view( - sbuffer.buffer.data(), - (size_t)length); - return true; - } - } - } - } - return false; - } - - std::string_view WindowsVersion::GetKernelVersionString() - { - VersionStringBuffer version_ntoskrnl_exe; - VersionStringBuffer version_kernel32_dll; - GetFileVersionString(L"ntoskrnl.exe", version_ntoskrnl_exe); - GetFileVersionString(L"kernel32.dll", version_kernel32_dll); - static std::string buf; - buf.reserve(13 + 23 + 10 + 23); - buf.clear(); - buf.append("NT OS Kernel "); - buf.append(version_ntoskrnl_exe.view); - buf.append(" Kernel32 "); - buf.append(version_kernel32_dll.view); - return buf; - } -} +#include "Shared.hpp" +#include "WindowsVersion.hpp" + +#pragma comment(lib, "Version.lib") + +namespace Platform +{ + namespace detail + { + static bool read = false; + static std::string_view name = ""; + static bool eos = false; + + void refresh() + { + if (read) + { + return; + } + + #define MAKE(N,S) name = N; eos = S; read = true; return + + // Windows 11 + + if (IsWindows10BuildOrGreater(26201)) + { + MAKE("Windows 11 25H2+", false); + } + if (WindowsVersion::Is11Build26200()) + { + MAKE("Windows 11 25H2", false); + } + if (WindowsVersion::Is11Build26100()) + { + MAKE("Windows 11 24H2", false); + } + if (WindowsVersion::Is11Build22631()) + { + MAKE("Windows 11 23H2", false); + } + if (WindowsVersion::Is11Build22621()) + { + MAKE("Windows 11 22H2", false); + } + if (WindowsVersion::Is11Build22000()) + { + MAKE("Windows 11 21H2", true); + } + if (WindowsVersion::Is11()) + { + MAKE("Windows 11", true); + } + + // Windows 10 + + if (IsWindows10BuildOrGreater(19046)) + { + MAKE("Windows 10 22H2+", false); + } + if (WindowsVersion::Is10Build19045()) + { + MAKE("Windows 10 22H2", false); + } + if (WindowsVersion::Is10Build19044()) + { + MAKE("Windows 10 21H2", true); + } + if (WindowsVersion::Is10Build19043()) + { + MAKE("Windows 10 21H1", true); + } + if (WindowsVersion::Is10Build19042()) + { + MAKE("Windows 10 20H2", true); + } + if (WindowsVersion::Is10Build19041()) + { + MAKE("Windows 10 2004", true); + } + if (WindowsVersion::Is10Build18363()) + { + MAKE("Windows 10 1909", true); + } + if (WindowsVersion::Is10Build18362()) + { + MAKE("Windows 10 1903", true); + } + if (WindowsVersion::Is10Build17763()) + { + MAKE("Windows 10 1809", true); + } + if (WindowsVersion::Is10Build17134()) + { + MAKE("Windows 10 1803", true); + } + if (WindowsVersion::Is10Build16299()) + { + MAKE("Windows 10 1709", true); + } + if (WindowsVersion::Is10Build15063()) + { + MAKE("Windows 10 1703", true); + } + if (WindowsVersion::Is10Build14393()) + { + MAKE("Windows 10 1607", true); + } + if (WindowsVersion::Is10Build10586()) + { + MAKE("Windows 10 1511", true); + } + if (WindowsVersion::Is10Build10240()) + { + MAKE("Windows 10 1507", true); + } + if (WindowsVersion::Is10()) + { + MAKE("Windows 10", true); + } + + // Windows 8 + + if (WindowsVersion::Is8Point1()) + { + MAKE("Windows 8.1", true); + } + if (WindowsVersion::Is8()) + { + MAKE("Windows 8", true); + } + + // Windows 7 + + if (WindowsVersion::Is7SP1WithPlatformUpdate()) + { + MAKE("Windows 7 SP1 With Platform Update", true); + } + if (WindowsVersion::Is7SP1()) + { + MAKE("Windows 7 SP1", true); + } + if (WindowsVersion::Is7()) + { + MAKE("Windows 7", true); + } + + // Windows Vista + + if (IsWindowsVistaSP2OrGreater()) + { + MAKE("Windows Vista SP2", true); + } + if (IsWindowsVistaSP1OrGreater()) + { + MAKE("Windows Vista SP1", true); + } + if (IsWindowsVistaOrGreater()) + { + MAKE("Windows Vista", true); + } + + // Windows XP + + if (IsWindowsXPSP3OrGreater()) + { + MAKE("Windows XP SP3", true); + } + if (IsWindowsXPSP2OrGreater()) + { + MAKE("Windows XP SP2", true); + } + if (IsWindowsXPSP1OrGreater()) + { + MAKE("Windows XP SP1", true); + } + if (IsWindowsXPOrGreater()) + { + MAKE("Windows XP", true); + } + + // Old + + MAKE("Windows ?", true); + + #undef MAKE + } + + static bool read_dxgi = false; + static bool dxgi_1_2 = false; + + bool check_dxgi_1_2() + { + if (read_dxgi) + { + return dxgi_1_2; + } + bool update_exist = false; + if (HMODULE dll_dxgi = LoadLibraryW(L"dxgi.dll")) + { + if (auto* api_CreateDXGIFactory1 = (decltype(CreateDXGIFactory1)*)GetProcAddress(dll_dxgi, "CreateDXGIFactory1")) + { + Microsoft::WRL::ComPtr dxgi_factory; + if (SUCCEEDED(api_CreateDXGIFactory1(IID_PPV_ARGS(&dxgi_factory)))) + { + update_exist = true; + } + } + FreeLibrary(dll_dxgi); + } + read_dxgi = true; + dxgi_1_2 = update_exist; + return dxgi_1_2; + } + } + + std::string_view WindowsVersion::GetName() + { + detail::refresh(); + return detail::name; + } + + bool WindowsVersion::IsEndOfSupport() + { + detail::refresh(); + return detail::eos; + } + + bool WindowsVersion::Is7() { return IsWindows7OrGreater(); } + bool WindowsVersion::Is7SP1() { return IsWindows7SP1OrGreater(); } + bool WindowsVersion::Is7SP1WithPlatformUpdate() { return IsWindows7SP1OrGreater() && detail::check_dxgi_1_2(); } + + bool WindowsVersion::Is8() { return IsWindows8OrGreater(); } + bool WindowsVersion::Is8Point1() { return IsWindows8Point1OrGreater(); } + + bool WindowsVersion::Is10() { return IsWindows10OrGreater(); } + bool WindowsVersion::Is10Build10240() { return IsWindows10BuildOrGreater(10240); } + bool WindowsVersion::Is10Build10586() { return IsWindows10BuildOrGreater(10586); } + bool WindowsVersion::Is10Build14393() { return IsWindows10BuildOrGreater(14393); } + bool WindowsVersion::Is10Build15063() { return IsWindows10BuildOrGreater(15063); } + bool WindowsVersion::Is10Build16299() { return IsWindows10BuildOrGreater(16299); } + bool WindowsVersion::Is10Build17134() { return IsWindows10BuildOrGreater(17134); } + bool WindowsVersion::Is10Build17763() { return IsWindows10BuildOrGreater(17763); } + bool WindowsVersion::Is10Build18362() { return IsWindows10BuildOrGreater(18362); } + bool WindowsVersion::Is10Build18363() { return IsWindows10BuildOrGreater(18363); } + bool WindowsVersion::Is10Build19041() { return IsWindows10BuildOrGreater(19041); } + bool WindowsVersion::Is10Build19042() { return IsWindows10BuildOrGreater(19042); } + bool WindowsVersion::Is10Build19043() { return IsWindows10BuildOrGreater(19043); } + bool WindowsVersion::Is10Build19044() { return IsWindows10BuildOrGreater(19044); } + bool WindowsVersion::Is10Build19045() { return IsWindows10BuildOrGreater(19045); } + + bool WindowsVersion::Is11() { return IsWindows11OrGreater(); } + bool WindowsVersion::Is11Build22000() { return IsWindows10BuildOrGreater(22000); } + bool WindowsVersion::Is11Build22621() { return IsWindows10BuildOrGreater(22621); } + bool WindowsVersion::Is11Build22631() { return IsWindows10BuildOrGreater(22631); } + bool WindowsVersion::Is11Build26100() { return IsWindows10BuildOrGreater(26100); } + bool WindowsVersion::Is11Build26200() { return IsWindows10BuildOrGreater(26200); } + + struct VersionStringBuffer + { + std::array buffer{}; + std::string_view view{ "0.0.0.0" }; + }; + + static bool GetFileVersionString(std::wstring_view file, VersionStringBuffer& sbuffer) + { + std::array windir{}; + UINT const windir_len = GetWindowsDirectoryW(windir.data(), MAX_PATH); + assert(windir_len > 0); + if (windir_len > 0) + { + std::wstring sys32dir; + sys32dir.append(windir.data(), windir_len); + sys32dir.append(std::wstring_view(L"\\System32\\")); + sys32dir.append(file); + + // get file metadata size + DWORD const metadata_size = GetFileVersionInfoSizeW(sys32dir.c_str(), NULL); + assert(metadata_size > 0); + if (metadata_size > 0) + { + // get file metadata + std::vector metadata(metadata_size); + BOOL const status = GetFileVersionInfoW(sys32dir.c_str(), 0, metadata_size, metadata.data()); + assert(status); + if (status) + { + // parser file metadata + VS_FIXEDFILEINFO* info = NULL; + UINT read = 0; + BOOL const query_status = VerQueryValueW(metadata.data(), L"\\", (LPVOID*)&info, &read); + assert(query_status); + if (query_status) + { + // format version + int length = std::snprintf( + sbuffer.buffer.data(), + sbuffer.buffer.size(), + "%d.%d.%d.%d", + (info->dwProductVersionMS >> 16) & 0xFFFF, + info->dwProductVersionMS & 0xFFFF, + (info->dwProductVersionLS >> 16) & 0xFFFF, + info->dwProductVersionLS & 0xFFFF); + sbuffer.view = std::string_view( + sbuffer.buffer.data(), + (size_t)length); + return true; + } + } + } + } + return false; + } + + std::string_view WindowsVersion::GetKernelVersionString() + { + VersionStringBuffer version_ntoskrnl_exe; + VersionStringBuffer version_kernel32_dll; + GetFileVersionString(L"ntoskrnl.exe", version_ntoskrnl_exe); + GetFileVersionString(L"kernel32.dll", version_kernel32_dll); + static std::string buf; + buf.reserve(13 + 23 + 10 + 23); + buf.clear(); + buf.append("NT OS Kernel "); + buf.append(version_ntoskrnl_exe.view); + buf.append(" Kernel32 "); + buf.append(version_kernel32_dll.view); + return buf; + } +} diff --git a/LuaSTG/Platform/WindowsVersion.hpp b/engine/win32/windows/WindowsVersion.hpp similarity index 97% rename from LuaSTG/Platform/WindowsVersion.hpp rename to engine/win32/windows/WindowsVersion.hpp index 41528998..d15ba4c8 100644 --- a/LuaSTG/Platform/WindowsVersion.hpp +++ b/engine/win32/windows/WindowsVersion.hpp @@ -1,45 +1,45 @@ -#pragma once -#include - -namespace Platform -{ - class WindowsVersion - { - public: - static std::string_view GetName(); - - static bool IsEndOfSupport(); - - static bool Is7(); // Windows 7 - static bool Is7SP1(); // Windows 7 SP1 - static bool Is7SP1WithPlatformUpdate(); // Windows 7 SP1 + Platform Update (KB2670838) - - static bool Is8(); // Windows 8 - static bool Is8Point1(); // Windows 8.1 - - static bool Is10(); // Windows 10 - static bool Is10Build10240(); // Windows 10 1507 - static bool Is10Build10586(); // Windows 10 1511 - static bool Is10Build14393(); // Windows 10 1607 - static bool Is10Build15063(); // Windows 10 1703 - static bool Is10Build16299(); // Windows 10 1709 - static bool Is10Build17134(); // Windows 10 1803 - static bool Is10Build17763(); // Windows 10 1809 - static bool Is10Build18362(); // Windows 10 1903 - static bool Is10Build18363(); // Windows 10 1909 - static bool Is10Build19041(); // Windows 10 2004 - static bool Is10Build19042(); // Windows 10 20H2 - static bool Is10Build19043(); // Windows 10 21H1 - static bool Is10Build19044(); // Windows 10 21H2 - static bool Is10Build19045(); // Windows 10 22H2 - - static bool Is11(); // Windows 11 - static bool Is11Build22000(); // Windows 11 21H2 - static bool Is11Build22621(); // Windows 11 22H2 - static bool Is11Build22631(); // Windows 11 23H2 - static bool Is11Build26100(); // Windows 11 24H2 - static bool Is11Build26200(); // Windows 11 25H2 - - static std::string_view GetKernelVersionString(); - }; -} +#pragma once +#include + +namespace Platform +{ + class WindowsVersion + { + public: + static std::string_view GetName(); + + static bool IsEndOfSupport(); + + static bool Is7(); // Windows 7 + static bool Is7SP1(); // Windows 7 SP1 + static bool Is7SP1WithPlatformUpdate(); // Windows 7 SP1 + Platform Update (KB2670838) + + static bool Is8(); // Windows 8 + static bool Is8Point1(); // Windows 8.1 + + static bool Is10(); // Windows 10 + static bool Is10Build10240(); // Windows 10 1507 + static bool Is10Build10586(); // Windows 10 1511 + static bool Is10Build14393(); // Windows 10 1607 + static bool Is10Build15063(); // Windows 10 1703 + static bool Is10Build16299(); // Windows 10 1709 + static bool Is10Build17134(); // Windows 10 1803 + static bool Is10Build17763(); // Windows 10 1809 + static bool Is10Build18362(); // Windows 10 1903 + static bool Is10Build18363(); // Windows 10 1909 + static bool Is10Build19041(); // Windows 10 2004 + static bool Is10Build19042(); // Windows 10 20H2 + static bool Is10Build19043(); // Windows 10 21H1 + static bool Is10Build19044(); // Windows 10 21H2 + static bool Is10Build19045(); // Windows 10 22H2 + + static bool Is11(); // Windows 11 + static bool Is11Build22000(); // Windows 11 21H2 + static bool Is11Build22621(); // Windows 11 22H2 + static bool Is11Build22631(); // Windows 11 23H2 + static bool Is11Build26100(); // Windows 11 24H2 + static bool Is11Build26200(); // Windows 11 25H2 + + static std::string_view GetKernelVersionString(); + }; +} diff --git a/LuaSTG/Platform/XInput.cpp b/engine/win32/windows/XInput.cpp similarity index 95% rename from LuaSTG/Platform/XInput.cpp rename to engine/win32/windows/XInput.cpp index 6add7cf0..ece23be0 100644 --- a/LuaSTG/Platform/XInput.cpp +++ b/engine/win32/windows/XInput.cpp @@ -1,280 +1,280 @@ -#include -#include -#include -#define NOMINMAX -#define WIN32_LEAN_AND_MEAN -#include -#include -#include "XInput.hpp" - -namespace Platform::XInput -{ - // NOTICE: XInputEnable is deprecated, we should simulate its behavior - - struct XInputLoader - { - HMODULE dll_xinput{ NULL }; - //decltype(::XInputEnable)* api_XInputEnable{ NULL }; - decltype(::XInputGetState)* api_XInputGetState{ NULL }; - decltype(::XInputSetState)* api_XInputSetState{ NULL }; - decltype(::XInputGetCapabilities)* api_XInputGetCapabilities{ NULL }; - - std::array valid{}; - std::array state{}; - bool enable{ true }; - - XInputLoader() - { - const std::array dll_names = { - L"Xinput1_4.dll", // Windows 8+ - L"xinput1_3.dll", // DirectX SDK - L"Xinput9_1_0.dll", // Windows Vista, Windows 7 - L"xinput1_2.dll", // DirectX SDK - L"xinput1_1.dll", // DirectX SDK - }; - for (auto& v : dll_names) - { - if (HMODULE dll = ::LoadLibraryW(v.data())) - { - dll_xinput = dll; - //api_XInputEnable = (decltype(api_XInputEnable)) - // ::GetProcAddress(dll, "XInputEnable"); - api_XInputGetState = (decltype(api_XInputGetState)) - ::GetProcAddress(dll, "XInputGetState"); - api_XInputSetState = (decltype(api_XInputSetState)) - ::GetProcAddress(dll, "XInputSetState"); - api_XInputGetCapabilities = (decltype(api_XInputGetCapabilities)) - ::GetProcAddress(dll, "XInputGetCapabilities"); - break; - } - } - } - ~XInputLoader() - { - if (dll_xinput) - ::FreeLibrary(dll_xinput); - dll_xinput = NULL; - //api_XInputEnable = NULL; - api_XInputGetState = NULL; - api_XInputSetState = NULL; - api_XInputGetCapabilities = NULL; - } - }; - static XInputLoader XInput; - - void setEnable(bool state) - { - //if (XInput.api_XInputEnable) - //{ - // XInput.api_XInputEnable(state ? TRUE : FALSE); - //} - XInput.enable = state; - if (!state) - { - XInput.state.fill({}); - } - } - bool isConnected(int index) - { - if (index >= 0 && index < XUSER_MAX_COUNT) - { - return XInput.valid[index]; - } - return false; - } - int refresh() - { - int count = 0; - for (DWORD i = 0; i < XUSER_MAX_COUNT; i += 1) - { - if (XInput.api_XInputGetState && ERROR_SUCCESS == XInput.api_XInputGetState(i, &XInput.state[i])) - { - XInput.valid[i] = true; - count += 1; - } - else - { - XInput.valid[i] = false; - XInput.state[i] = {}; - } - } - return count; - } - void update() - { - for (DWORD i = 0; i < XUSER_MAX_COUNT; i += 1) - { - if (XInput.valid[i]) - { - if (XInput.api_XInputGetState && ERROR_SUCCESS != XInput.api_XInputGetState(i, &XInput.state[i])) - { - XInput.valid[i] = false; - XInput.state[i] = {}; - } - } - } - } - - bool getKeyState(int index, int key) - { - if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) - { - return (XInput.state[index].Gamepad.wButtons & key) != 0; - } - return false; - } - - float getLeftTrigger(int index) - { - if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) - { - return std::clamp((float)XInput.state[index].Gamepad.bLeftTrigger / 255.0f, 0.0f, 1.0f); - } - return 0.0f; - } - float getRightTrigger(int index) - { - if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) - { - return std::clamp((float)XInput.state[index].Gamepad.bRightTrigger / 255.0f, 0.0f, 1.0f); - } - return 0.0f; - } - - float getLeftThumbX(int index) - { - if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) - { - return std::clamp((float)XInput.state[index].Gamepad.sThumbLX / 32767.0f, -1.0f, 1.0f); - } - return 0.0f; - } - float getLeftThumbY(int index) - { - if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) - { - return std::clamp((float)XInput.state[index].Gamepad.sThumbLY / 32767.0f, -1.0f, 1.0f); - } - return 0.0f; - } - float getRightThumbX(int index) - { - if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) - { - return std::clamp((float)XInput.state[index].Gamepad.sThumbRX / 32767.0f, -1.0f, 1.0f); - } - return 0.0f; - } - float getRightThumbY(int index) - { - if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) - { - return std::clamp((float)XInput.state[index].Gamepad.sThumbRY / 32767.0f, -1.0f, 1.0f); - } - return 0.0f; - } - - bool getKeyState(int key) - { - for (int i = 0; i < XUSER_MAX_COUNT; i += 1) - { - if (XInput.valid[i]) - { - return getKeyState(i, key); - } - } - return false; - } - - float getLeftTrigger() - { - for (int i = 0; i < XUSER_MAX_COUNT; i += 1) - { - if (XInput.valid[i]) - { - return getLeftTrigger(i); - } - } - return 0.0f; - } - float getRightTrigger() - { - for (int i = 0; i < XUSER_MAX_COUNT; i += 1) - { - if (XInput.valid[i]) - { - return getRightTrigger(i); - } - } - return 0.0f; - } - float getLeftThumbX() - { - for (int i = 0; i < XUSER_MAX_COUNT; i += 1) - { - if (XInput.valid[i]) - { - return getLeftThumbX(i); - } - } - return 0.0f; - } - float getLeftThumbY() - { - for (int i = 0; i < XUSER_MAX_COUNT; i += 1) - { - if (XInput.valid[i]) - { - return getLeftThumbY(i); - } - } - return 0.0f; - } - float getRightThumbX() - { - for (int i = 0; i < XUSER_MAX_COUNT; i += 1) - { - if (XInput.valid[i]) - { - return getRightThumbX(i); - } - } - return 0.0f; - } - float getRightThumbY() - { - for (int i = 0; i < XUSER_MAX_COUNT; i += 1) - { - if (XInput.valid[i]) - { - return getRightThumbY(i); - } - } - return 0.0f; - } - - DWORD getState(DWORD dwUserIndex, XINPUT_STATE* pState) - { - if (XInput.api_XInputGetState) - { - return XInput.api_XInputGetState(dwUserIndex, pState); - } - return ERROR_NOT_SUPPORTED; - } - DWORD setState(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration) - { - if (XInput.api_XInputSetState) - { - return XInput.api_XInputSetState(dwUserIndex, pVibration); - } - return ERROR_NOT_SUPPORTED; - } - DWORD getCapabilities(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities) - { - if (XInput.api_XInputGetCapabilities) - { - return XInput.api_XInputGetCapabilities(dwUserIndex, dwFlags, pCapabilities); - } - return ERROR_NOT_SUPPORTED; - } -} +#include +#include +#include +#define NOMINMAX +#define WIN32_LEAN_AND_MEAN +#include +#include +#include "XInput.hpp" + +namespace Platform::XInput +{ + // NOTICE: XInputEnable is deprecated, we should simulate its behavior + + struct XInputLoader + { + HMODULE dll_xinput{ NULL }; + //decltype(::XInputEnable)* api_XInputEnable{ NULL }; + decltype(::XInputGetState)* api_XInputGetState{ NULL }; + decltype(::XInputSetState)* api_XInputSetState{ NULL }; + decltype(::XInputGetCapabilities)* api_XInputGetCapabilities{ NULL }; + + std::array valid{}; + std::array state{}; + bool enable{ true }; + + XInputLoader() + { + const std::array dll_names = { + L"Xinput1_4.dll", // Windows 8+ + L"xinput1_3.dll", // DirectX SDK + L"Xinput9_1_0.dll", // Windows Vista, Windows 7 + L"xinput1_2.dll", // DirectX SDK + L"xinput1_1.dll", // DirectX SDK + }; + for (auto& v : dll_names) + { + if (HMODULE dll = ::LoadLibraryW(v.data())) + { + dll_xinput = dll; + //api_XInputEnable = (decltype(api_XInputEnable)) + // ::GetProcAddress(dll, "XInputEnable"); + api_XInputGetState = (decltype(api_XInputGetState)) + ::GetProcAddress(dll, "XInputGetState"); + api_XInputSetState = (decltype(api_XInputSetState)) + ::GetProcAddress(dll, "XInputSetState"); + api_XInputGetCapabilities = (decltype(api_XInputGetCapabilities)) + ::GetProcAddress(dll, "XInputGetCapabilities"); + break; + } + } + } + ~XInputLoader() + { + if (dll_xinput) + ::FreeLibrary(dll_xinput); + dll_xinput = NULL; + //api_XInputEnable = NULL; + api_XInputGetState = NULL; + api_XInputSetState = NULL; + api_XInputGetCapabilities = NULL; + } + }; + static XInputLoader XInput; + + void setEnable(bool state) + { + //if (XInput.api_XInputEnable) + //{ + // XInput.api_XInputEnable(state ? TRUE : FALSE); + //} + XInput.enable = state; + if (!state) + { + XInput.state.fill({}); + } + } + bool isConnected(int index) + { + if (index >= 0 && index < XUSER_MAX_COUNT) + { + return XInput.valid[index]; + } + return false; + } + int refresh() + { + int count = 0; + for (DWORD i = 0; i < XUSER_MAX_COUNT; i += 1) + { + if (XInput.api_XInputGetState && ERROR_SUCCESS == XInput.api_XInputGetState(i, &XInput.state[i])) + { + XInput.valid[i] = true; + count += 1; + } + else + { + XInput.valid[i] = false; + XInput.state[i] = {}; + } + } + return count; + } + void update() + { + for (DWORD i = 0; i < XUSER_MAX_COUNT; i += 1) + { + if (XInput.valid[i]) + { + if (XInput.api_XInputGetState && ERROR_SUCCESS != XInput.api_XInputGetState(i, &XInput.state[i])) + { + XInput.valid[i] = false; + XInput.state[i] = {}; + } + } + } + } + + bool getKeyState(int index, int key) + { + if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) + { + return (XInput.state[index].Gamepad.wButtons & key) != 0; + } + return false; + } + + float getLeftTrigger(int index) + { + if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) + { + return std::clamp((float)XInput.state[index].Gamepad.bLeftTrigger / 255.0f, 0.0f, 1.0f); + } + return 0.0f; + } + float getRightTrigger(int index) + { + if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) + { + return std::clamp((float)XInput.state[index].Gamepad.bRightTrigger / 255.0f, 0.0f, 1.0f); + } + return 0.0f; + } + + float getLeftThumbX(int index) + { + if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) + { + return std::clamp((float)XInput.state[index].Gamepad.sThumbLX / 32767.0f, -1.0f, 1.0f); + } + return 0.0f; + } + float getLeftThumbY(int index) + { + if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) + { + return std::clamp((float)XInput.state[index].Gamepad.sThumbLY / 32767.0f, -1.0f, 1.0f); + } + return 0.0f; + } + float getRightThumbX(int index) + { + if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) + { + return std::clamp((float)XInput.state[index].Gamepad.sThumbRX / 32767.0f, -1.0f, 1.0f); + } + return 0.0f; + } + float getRightThumbY(int index) + { + if (XInput.enable && index >= 0 && index < XUSER_MAX_COUNT) + { + return std::clamp((float)XInput.state[index].Gamepad.sThumbRY / 32767.0f, -1.0f, 1.0f); + } + return 0.0f; + } + + bool getKeyState(int key) + { + for (int i = 0; i < XUSER_MAX_COUNT; i += 1) + { + if (XInput.valid[i]) + { + return getKeyState(i, key); + } + } + return false; + } + + float getLeftTrigger() + { + for (int i = 0; i < XUSER_MAX_COUNT; i += 1) + { + if (XInput.valid[i]) + { + return getLeftTrigger(i); + } + } + return 0.0f; + } + float getRightTrigger() + { + for (int i = 0; i < XUSER_MAX_COUNT; i += 1) + { + if (XInput.valid[i]) + { + return getRightTrigger(i); + } + } + return 0.0f; + } + float getLeftThumbX() + { + for (int i = 0; i < XUSER_MAX_COUNT; i += 1) + { + if (XInput.valid[i]) + { + return getLeftThumbX(i); + } + } + return 0.0f; + } + float getLeftThumbY() + { + for (int i = 0; i < XUSER_MAX_COUNT; i += 1) + { + if (XInput.valid[i]) + { + return getLeftThumbY(i); + } + } + return 0.0f; + } + float getRightThumbX() + { + for (int i = 0; i < XUSER_MAX_COUNT; i += 1) + { + if (XInput.valid[i]) + { + return getRightThumbX(i); + } + } + return 0.0f; + } + float getRightThumbY() + { + for (int i = 0; i < XUSER_MAX_COUNT; i += 1) + { + if (XInput.valid[i]) + { + return getRightThumbY(i); + } + } + return 0.0f; + } + + DWORD getState(DWORD dwUserIndex, XINPUT_STATE* pState) + { + if (XInput.api_XInputGetState) + { + return XInput.api_XInputGetState(dwUserIndex, pState); + } + return ERROR_NOT_SUPPORTED; + } + DWORD setState(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration) + { + if (XInput.api_XInputSetState) + { + return XInput.api_XInputSetState(dwUserIndex, pVibration); + } + return ERROR_NOT_SUPPORTED; + } + DWORD getCapabilities(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities) + { + if (XInput.api_XInputGetCapabilities) + { + return XInput.api_XInputGetCapabilities(dwUserIndex, dwFlags, pCapabilities); + } + return ERROR_NOT_SUPPORTED; + } +} diff --git a/LuaSTG/Platform/XInput.hpp b/engine/win32/windows/XInput.hpp similarity index 97% rename from LuaSTG/Platform/XInput.hpp rename to engine/win32/windows/XInput.hpp index 7f8df79f..58b07ac6 100644 --- a/LuaSTG/Platform/XInput.hpp +++ b/engine/win32/windows/XInput.hpp @@ -1,47 +1,47 @@ -#pragma once - -namespace Platform::XInput -{ - constexpr int Null = 0x0000; - constexpr int Up = 0x0001; - constexpr int Down = 0x0002; - constexpr int Left = 0x0004; - constexpr int Right = 0x0008; - constexpr int Start = 0x0010; - constexpr int Back = 0x0020; - constexpr int LeftThumb = 0x0040; - constexpr int RightThumb = 0x0080; - constexpr int LeftShoulder = 0x0100; - constexpr int RightShoulder = 0x0200; - constexpr int A = 0x1000; - constexpr int B = 0x2000; - constexpr int X = 0x4000; - constexpr int Y = 0x8000; - - void setEnable(bool state); - bool isConnected(int index); - int refresh(); - void update(); - - bool getKeyState(int index, int key); - float getLeftTrigger(int index); - float getRightTrigger(int index); - float getLeftThumbX(int index); - float getLeftThumbY(int index); - float getRightThumbX(int index); - float getRightThumbY(int index); - - bool getKeyState(int key); - float getLeftTrigger(); - float getRightTrigger(); - float getLeftThumbX(); - float getLeftThumbY(); - float getRightThumbX(); - float getRightThumbY(); - - #ifdef XINPUT_DLL - DWORD getState(DWORD dwUserIndex, XINPUT_STATE* pState); - DWORD setState(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration); - DWORD getCapabilities(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities); - #endif -} +#pragma once + +namespace Platform::XInput +{ + constexpr int Null = 0x0000; + constexpr int Up = 0x0001; + constexpr int Down = 0x0002; + constexpr int Left = 0x0004; + constexpr int Right = 0x0008; + constexpr int Start = 0x0010; + constexpr int Back = 0x0020; + constexpr int LeftThumb = 0x0040; + constexpr int RightThumb = 0x0080; + constexpr int LeftShoulder = 0x0100; + constexpr int RightShoulder = 0x0200; + constexpr int A = 0x1000; + constexpr int B = 0x2000; + constexpr int X = 0x4000; + constexpr int Y = 0x8000; + + void setEnable(bool state); + bool isConnected(int index); + int refresh(); + void update(); + + bool getKeyState(int index, int key); + float getLeftTrigger(int index); + float getRightTrigger(int index); + float getLeftThumbX(int index); + float getLeftThumbY(int index); + float getRightThumbX(int index); + float getRightThumbY(int index); + + bool getKeyState(int key); + float getLeftTrigger(); + float getRightTrigger(); + float getLeftThumbX(); + float getLeftThumbY(); + float getRightThumbX(); + float getRightThumbY(); + + #ifdef XINPUT_DLL + DWORD getState(DWORD dwUserIndex, XINPUT_STATE* pState); + DWORD setState(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration); + DWORD getCapabilities(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES* pCapabilities); + #endif +} diff --git a/engine/window-system/CMakeLists.txt b/engine/window-system/CMakeLists.txt new file mode 100644 index 00000000..84704dfa --- /dev/null +++ b/engine/window-system/CMakeLists.txt @@ -0,0 +1,25 @@ +# Window System + +set(lib_name "Core.WindowSystem") + +file(GLOB_RECURSE lib_src RELATIVE ${CMAKE_CURRENT_LIST_DIR} core/*.hpp core/*.cpp windows/*.hpp windows/*.cpp) +source_group(TREE ${CMAKE_CURRENT_LIST_DIR} FILES ${lib_src}) + +add_library(${lib_name}) +luastg_target_common_options(${lib_name}) +luastg_target_more_warning(${lib_name}) +target_include_directories(${lib_name} PUBLIC .) +target_sources(${lib_name} PRIVATE ${lib_src}) +target_link_libraries(${lib_name} PRIVATE options_compile_utf8) +target_link_libraries(${lib_name} PUBLIC + Core.ReferenceCounted + Core.Configuration + Core.Logging + Core.Math + Core.String + simdutf::simdutf + win32 + beautiful_win32_api +) + +set_target_properties(${lib_name} PROPERTIES FOLDER engine) diff --git a/engine/window-system/core/Application.hpp b/engine/window-system/core/Application.hpp new file mode 100644 index 00000000..342e4090 --- /dev/null +++ b/engine/window-system/core/Application.hpp @@ -0,0 +1,19 @@ +#pragma once +#include "core/ReferenceCounted.hpp" + +namespace core { + CORE_INTERFACE IApplication { + virtual bool onCreate() = 0; + virtual void onBeforeUpdate() = 0; + virtual bool onUpdate() = 0; + virtual void onDestroy() = 0; + }; + + class ApplicationManager { + public: + static void run(IApplication* application); + static IApplication* getApplication(); + static void requestExit(); + static bool isMainThread(); + }; +} diff --git a/engine/window-system/core/Display.hpp b/engine/window-system/core/Display.hpp new file mode 100644 index 00000000..87577711 --- /dev/null +++ b/engine/window-system/core/Display.hpp @@ -0,0 +1,28 @@ +#pragma once +#include "core/Vector2.hpp" +#include "core/Rect.hpp" +#include "core/ReferenceCounted.hpp" +#include "core/ImmutableString.hpp" + +namespace core { + CORE_INTERFACE IWindow; + + CORE_INTERFACE IDisplay : IReferenceCounted { + virtual void* getNativeHandle() = 0; + virtual void getFriendlyName(IImmutableString** output) = 0; + virtual Vector2U getSize() = 0; + virtual Vector2I getPosition() = 0; + virtual RectI getRect() = 0; + virtual Vector2U getWorkAreaSize() = 0; + virtual Vector2I getWorkAreaPosition() = 0; + virtual RectI getWorkAreaRect() = 0; + virtual bool isPrimary() = 0; + virtual float getDisplayScale() = 0; + + static bool getAll(size_t* count, IDisplay** output); + static bool getPrimary(IDisplay** output); + static bool getNearestFromWindow(IWindow* window, IDisplay** output); + }; + + CORE_INTERFACE_ID(IDisplay, "9432a56d-e3d2-5173-b313-a9581b373155") +} diff --git a/engine/window-system/core/FrameRateController.hpp b/engine/window-system/core/FrameRateController.hpp new file mode 100644 index 00000000..44ca36be --- /dev/null +++ b/engine/window-system/core/FrameRateController.hpp @@ -0,0 +1,79 @@ +#pragma once +#include +#include + +namespace core { + struct FrameRateStatistics { + std::array durations{}; + double duration_average{}; + double duration_min{}; + double duration_max{}; + double duration_total{}; + uint64_t frame_count; + size_t current_index{}; + + double getDuration(const size_t index) const noexcept { + const auto normalized_index = index % durations.size(); + return durations[(current_index + durations.size() - normalized_index) % durations.size()]; + } + + double getAverage(const size_t count) const noexcept { + if (count == 0) { + return 0.0; + } + double result = 0; + const auto n = count < durations.size() ? count : durations.size(); + for (size_t i = 0; i < n; i += 1) { + result += getDuration(i); + } + return result / static_cast(n); + } + + void reset() noexcept { + durations.fill(0.0); + duration_average = 0.0; + duration_min = 0.0; + duration_max = 0.0; + duration_total = 0.0; + frame_count = 0; + current_index = 0u; + } + + void update(const double duration) noexcept { + durations[current_index % durations.size()] = duration; + duration_average = 0; + duration_min = 3600.0; + duration_max = -3600.0; + duration_total += duration; + frame_count += 1; + current_index = (current_index + 1) % durations.size(); + for (const auto v : durations) { + duration_average += v; + if (v < duration_min) duration_min = v; + if (v > duration_max) duration_max = v; + } + const auto factor = 1.0 / static_cast(durations.size()); + duration_average *= factor; + } + }; + + struct IFrameRateController { + virtual bool arrived() const noexcept = 0; + virtual double update() noexcept = 0; + virtual double getFrameRate() const noexcept = 0; + virtual void setFrameRate(double frame_rate) noexcept = 0; + virtual const FrameRateStatistics* getStatistics() const noexcept = 0; + + static IFrameRateController* getInstance(); + }; + + class ScopeTimer { + public: + ScopeTimer(double* value = nullptr); + ~ScopeTimer(); + + private: + double* m_value{}; + int64_t m_last{}; + }; +} diff --git a/LuaSTG/Core/Graphics/Window.hpp b/engine/window-system/core/Window.hpp similarity index 72% rename from LuaSTG/Core/Graphics/Window.hpp rename to engine/window-system/core/Window.hpp index 70239c22..36f45342 100644 --- a/LuaSTG/Core/Graphics/Window.hpp +++ b/engine/window-system/core/Window.hpp @@ -1,160 +1,128 @@ -#pragma once -#include "core/Vector2.hpp" -#include "core/Rect.hpp" -#include "core/ReferenceCounted.hpp" -#include "core/ImmutableString.hpp" - -namespace core::Graphics -{ - struct IWindowEventListener - { - virtual void onWindowCreate() {}; - virtual void onWindowDestroy() {}; - - virtual void onWindowActive() {}; - virtual void onWindowInactive() {}; - - virtual void onWindowSize(Vector2U size) { (void)size; }; - virtual void onWindowFullscreenStateChange(bool state) { (void)state; } - virtual void onWindowDpiChange() {}; - - virtual void onWindowClose() {}; - - virtual void onDeviceChange() {}; - - struct NativeWindowMessageResult - { - intptr_t result; - bool should_return; - - NativeWindowMessageResult() : result(0), should_return(false) {} - NativeWindowMessageResult(intptr_t v, bool b) : result(v), should_return(b) {} - }; - - virtual NativeWindowMessageResult onNativeWindowMessage(void*, uint32_t, uintptr_t, intptr_t) { return {}; }; - }; - - enum class WindowFrameStyle { - None, - Fixed, - Normal, - }; - - enum class WindowLayer { - Bottom, - Normal, - Top, - TopMost, - }; - - enum class WindowCursor { - None, - - Arrow, - Hand, - - Cross, - TextInput, - - Resize, - ResizeEW, - ResizeNS, - ResizeNESW, - ResizeNWSE, - - NotAllowed, - Wait, - }; - - struct IWindow; - - struct IDisplay : public IReferenceCounted { - virtual void* getNativeHandle() = 0; - virtual void getFriendlyName(IImmutableString** output) = 0; - virtual Vector2U getSize() = 0; - virtual Vector2I getPosition() = 0; - virtual RectI getRect() = 0; - virtual Vector2U getWorkAreaSize() = 0; - virtual Vector2I getWorkAreaPosition() = 0; - virtual RectI getWorkAreaRect() = 0; - virtual bool isPrimary() = 0; - virtual float getDisplayScale() = 0; - - static bool getAll(size_t* count, IDisplay** output); - static bool getPrimary(IDisplay** output); - static bool getNearestFromWindow(IWindow* window, IDisplay** output); - }; - - struct IWindow : public IReferenceCounted - { - virtual void addEventListener(IWindowEventListener* e) = 0; - virtual void removeEventListener(IWindowEventListener* e) = 0; - - virtual void* getNativeHandle() = 0; - - virtual void setIMEState(bool enable) = 0; - virtual bool getIMEState() = 0; - - // vvvvvvvv BEGIN WIP - - virtual void setInputMethodPosition(Vector2I position) = 0; - - virtual bool textInput_isEnabled() = 0; - virtual void textInput_setEnabled(bool enabled) = 0; - virtual StringView textInput_getBuffer() = 0; - virtual void textInput_clearBuffer() = 0; - virtual uint32_t textInput_getCursorPosition() = 0; - virtual void textInput_setCursorPosition(uint32_t code_point_index) = 0; - virtual void textInput_addCursorPosition(int32_t offset_by_code_point) = 0; - virtual void textInput_removeBufferRange(uint32_t code_point_index, uint32_t code_point_count) = 0; - virtual void textInput_insertBufferRange(uint32_t code_point_index, StringView str) = 0; - virtual void textInput_backspace(uint32_t code_point_count) = 0; - - // ^^^^^^^^ END WIP - - virtual void setTitleText(StringView str) = 0; - virtual StringView getTitleText() = 0; - - virtual bool setFrameStyle(WindowFrameStyle style) = 0; - virtual WindowFrameStyle getFrameStyle() = 0; - - virtual Vector2U getSize() = 0; // TODO: history problem - virtual Vector2U _getCurrentSize() = 0; // TODO: history problem - virtual bool setSize(Vector2U v) = 0; - virtual bool setLayer(WindowLayer layer) = 0; - - virtual uint32_t getDPI() = 0; - virtual float getDPIScaling() = 0; - - virtual void setWindowMode(Vector2U size, WindowFrameStyle style = WindowFrameStyle::Normal, IDisplay* display = nullptr) = 0; - virtual void setFullScreenMode(IDisplay* display = nullptr) = 0; - virtual void setCentered(bool show, IDisplay* display = nullptr) = 0; - - virtual void setCustomSizeMoveEnable(bool v) = 0; - virtual void setCustomMinimizeButtonRect(RectI v) = 0; - virtual void setCustomCloseButtonRect(RectI v) = 0; - virtual void setCustomMoveButtonRect(RectI v) = 0; - - virtual bool setCursor(WindowCursor type) = 0; - virtual WindowCursor getCursor() = 0; - - // Windows 11 - virtual void setWindowCornerPreference(bool allow) = 0; - virtual void setTitleBarAutoHidePreference(bool allow) = 0; - - static bool create(IWindow** pp_window); - static bool create(Vector2U size, StringView title_text, WindowFrameStyle style, bool show, IWindow** pp_window); - }; -} - -namespace core { - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IDisplay - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("9432a56d-e3d2-5173-b313-a9581b373155"); } - - // UUID v5 - // ns:URL - // https://www.luastg-sub.com/core.IWindow - template<> constexpr InterfaceId getInterfaceId() { return UUID::parse("7be6255c-08f5-5cd4-81d7-2f490256f2e9"); } -} +#pragma once +#include "core/Vector2.hpp" +#include "core/Rect.hpp" +#include "core/ReferenceCounted.hpp" +#include "core/ImmutableString.hpp" +#include "core/Display.hpp" + +namespace core { + struct IWindowEventListener { + virtual void onWindowCreate() {}; + virtual void onWindowDestroy() {}; + + virtual void onWindowActive() {}; + virtual void onWindowInactive() {}; + + virtual void onWindowSize(Vector2U size) { (void)size; }; + virtual void onWindowFullscreenStateChange(bool state) { (void)state; } + virtual void onWindowDpiChange() {}; + + virtual void onWindowClose() {}; + + virtual void onDeviceChange() {}; + + struct NativeWindowMessageResult { + intptr_t result; + bool should_return; + + NativeWindowMessageResult() : result(0), should_return(false) {} + NativeWindowMessageResult(intptr_t v, bool b) : result(v), should_return(b) {} + }; + + virtual NativeWindowMessageResult onNativeWindowMessage(void*, uint32_t, uintptr_t, intptr_t) { return {}; }; + }; + + enum class WindowFrameStyle { + None, + Fixed, + Normal, + }; + + enum class WindowLayer { + Bottom, + Normal, + Top, + TopMost, + }; + + enum class WindowCursor { + None, + + Arrow, + Hand, + + Cross, + TextInput, + + Resize, + ResizeEW, + ResizeNS, + ResizeNESW, + ResizeNWSE, + + NotAllowed, + Wait, + }; + + CORE_INTERFACE IWindow : IReferenceCounted { + virtual void addEventListener(IWindowEventListener* e) = 0; + virtual void removeEventListener(IWindowEventListener* e) = 0; + + virtual void* getNativeHandle() = 0; + + virtual void setIMEState(bool enable) = 0; + virtual bool getIMEState() = 0; + + // vvvvvvvv BEGIN WIP + + virtual void setInputMethodPosition(Vector2I position) = 0; + + virtual bool textInput_isEnabled() = 0; + virtual void textInput_setEnabled(bool enabled) = 0; + virtual StringView textInput_getBuffer() = 0; + virtual void textInput_clearBuffer() = 0; + virtual uint32_t textInput_getCursorPosition() = 0; + virtual void textInput_setCursorPosition(uint32_t code_point_index) = 0; + virtual void textInput_addCursorPosition(int32_t offset_by_code_point) = 0; + virtual void textInput_removeBufferRange(uint32_t code_point_index, uint32_t code_point_count) = 0; + virtual void textInput_insertBufferRange(uint32_t code_point_index, StringView str) = 0; + virtual void textInput_backspace(uint32_t code_point_count) = 0; + + // ^^^^^^^^ END WIP + + virtual void setTitleText(StringView str) = 0; + virtual StringView getTitleText() = 0; + + virtual bool setFrameStyle(WindowFrameStyle style) = 0; + virtual WindowFrameStyle getFrameStyle() = 0; + + virtual Vector2U getSize() = 0; // TODO: history problem + virtual Vector2U _getCurrentSize() = 0; // TODO: history problem + virtual bool setSize(Vector2U v) = 0; + virtual bool setLayer(WindowLayer layer) = 0; + + virtual uint32_t getDPI() = 0; + virtual float getDPIScaling() = 0; + + virtual void setWindowMode(Vector2U size, WindowFrameStyle style = WindowFrameStyle::Normal, IDisplay* display = nullptr) = 0; + virtual void setFullScreenMode(IDisplay* display = nullptr) = 0; + virtual void setCentered(bool show, IDisplay* display = nullptr) = 0; + + virtual void setCustomSizeMoveEnable(bool v) = 0; + virtual void setCustomMinimizeButtonRect(RectI v) = 0; + virtual void setCustomCloseButtonRect(RectI v) = 0; + virtual void setCustomMoveButtonRect(RectI v) = 0; + + virtual bool setCursor(WindowCursor type) = 0; + virtual WindowCursor getCursor() = 0; + + // Windows 11 + virtual void setWindowCornerPreference(bool allow) = 0; + virtual void setTitleBarAutoHidePreference(bool allow) = 0; + + static bool create(IWindow** pp_window); + static bool create(Vector2U size, StringView title_text, WindowFrameStyle style, bool show, IWindow** pp_window); + }; + + CORE_INTERFACE_ID(IWindow, "9432a56d-e3d2-5173-b313-a9581b373155") +} diff --git a/engine/window-system/windows/ApplicationManager.cpp b/engine/window-system/windows/ApplicationManager.cpp new file mode 100644 index 00000000..75f219da --- /dev/null +++ b/engine/window-system/windows/ApplicationManager.cpp @@ -0,0 +1,83 @@ +#include "windows/ApplicationManager.hpp" +#include +#define WIN32_LEAN_AND_MEAN +#include +#include + +namespace { + struct ScopedTimePeriod { + uint32_t period{}; + + ScopedTimePeriod(const uint32_t target_period = 1u) { + if (timeBeginPeriod(target_period) == TIMERR_NOERROR) { + period = target_period; + } + } + ~ScopedTimePeriod() { + if (period > 0u) { + timeEndPeriod(period); + } + } + }; + + core::IApplication* g_application{}; + HANDLE g_main_thread{}; + DWORD g_main_thread_id{}; +} + +namespace core { + void ApplicationManager::run(IApplication* const application) { + // Main thread & UI thread + + assert(application != nullptr); + g_application = application; + g_main_thread = GetCurrentThread(); + g_main_thread_id = GetCurrentThreadId(); + SetThreadAffinityMask(g_main_thread, 0x1); + SetThreadPriority(g_main_thread, THREAD_PRIORITY_HIGHEST); + const ScopedTimePeriod scoped_time_period; + + if (!application->onCreate()) { + return; + } + + bool running = true; + MSG msg{}; + while (running) { + application->onBeforeUpdate(); + + while (PeekMessageW(&msg, nullptr, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) { + running = false; + } + else { + TranslateMessage(&msg); + DispatchMessageW(&msg); + } + } + + if (!running) { + break; + } + + if (!application->onUpdate()) { + running = false; + break; + } + } + + application->onDestroy(); + } + + IApplication* ApplicationManager::getApplication() { + return g_application; + } + + void ApplicationManager::requestExit() { + PostThreadMessageW(g_main_thread_id, WM_QUIT, 0, 0); + } + + bool ApplicationManager::isMainThread() { + return GetCurrentThreadId() == g_main_thread_id; + } +} diff --git a/engine/window-system/windows/ApplicationManager.hpp b/engine/window-system/windows/ApplicationManager.hpp new file mode 100644 index 00000000..1ab49386 --- /dev/null +++ b/engine/window-system/windows/ApplicationManager.hpp @@ -0,0 +1,2 @@ +#pragma once +#include "core/Application.hpp" diff --git a/engine/window-system/windows/Display.cpp b/engine/window-system/windows/Display.cpp new file mode 100644 index 00000000..38a28a68 --- /dev/null +++ b/engine/window-system/windows/Display.cpp @@ -0,0 +1,180 @@ +#include "windows/Display.hpp" +#include "core/Window.hpp" +#include +#include +#include "utf8.hpp" +#include "win32/win32.hpp" +#include "win32/abi.hpp" + +namespace { + template + T getMonitorInfo(const HMONITOR monitor) { + static_assert(std::is_same_v || std::is_same_v); + assert(monitor); + T info{}; + info.cbSize = sizeof(info); + [[maybe_unused]] auto const result = GetMonitorInfoW(monitor, &info); + assert(result); + return info; + } +} + +namespace core { + // IDisplay + + void* Display::getNativeHandle() { + return win32_monitor; + } + void Display::getFriendlyName(IImmutableString** const output) { + auto const info = getMonitorInfo(win32_monitor); + + UINT path_count{}; + UINT mode_count{}; + if (ERROR_SUCCESS == GetDisplayConfigBufferSizes(QDC_DATABASE_CURRENT, &path_count, &mode_count)) { + std::vector path_list(path_count); + std::vector mode_list(mode_count); + DISPLAYCONFIG_TOPOLOGY_ID topology_id{}; + if (ERROR_SUCCESS == QueryDisplayConfig(QDC_DATABASE_CURRENT, &path_count, path_list.data(), &mode_count, mode_list.data(), &topology_id)) { + for (auto const& path : path_list) { + DISPLAYCONFIG_SOURCE_DEVICE_NAME source_device_name{}; + source_device_name.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_SOURCE_NAME; + source_device_name.header.size = sizeof(source_device_name); + source_device_name.header.adapterId = path.sourceInfo.adapterId; + source_device_name.header.id = path.sourceInfo.id; + if (ERROR_SUCCESS == DisplayConfigGetDeviceInfo(&source_device_name.header)) { + if (std::wstring_view(info.szDevice) == std::wstring_view(source_device_name.viewGdiDeviceName)) { + DISPLAYCONFIG_TARGET_DEVICE_NAME target_device_name{}; + target_device_name.header.type = DISPLAYCONFIG_DEVICE_INFO_GET_TARGET_NAME; + target_device_name.header.size = sizeof(target_device_name); + target_device_name.header.adapterId = path.targetInfo.adapterId; + target_device_name.header.id = path.targetInfo.id; + if (ERROR_SUCCESS == DisplayConfigGetDeviceInfo(&target_device_name.header)) { + std::string buffer; + if (target_device_name.flags.edidIdsValid) { + auto const manufacture_id = ((target_device_name.edidManufactureId & 0xff) << 8) | ((target_device_name.edidManufactureId & 0xff00) >> 8); + auto const letter1 = ((manufacture_id & 0x7c00) >> 10) - 1; + auto const letter2 = ((manufacture_id & 0x3e0) >> 5) - 1; + auto const letter3 = (manufacture_id & 0x1f) - 1; + buffer.push_back('A' + static_cast(letter1)); + buffer.push_back('A' + static_cast(letter2)); + buffer.push_back('A' + static_cast(letter3)); + } + if (!std::wstring_view(target_device_name.monitorFriendlyDeviceName).empty()) { + if (!buffer.empty()) { + buffer.push_back(' '); + } + buffer.append(utf8::to_string(target_device_name.monitorFriendlyDeviceName)); + } + else if (target_device_name.flags.edidIdsValid) { + buffer.append(std::format("{:04X}", target_device_name.edidProductCodeId)); + } + IImmutableString::create(buffer, output); + return; + } + } + } + } + } + } + + IImmutableString::create(utf8::to_string(info.szDevice), output); + } + Vector2U Display::getSize() { + auto const info = getMonitorInfo(win32_monitor); + auto const& rc = info.rcMonitor; + return Vector2U(static_cast(rc.right - rc.left), static_cast(rc.bottom - rc.top)); + } + Vector2I Display::getPosition() { + auto const info = getMonitorInfo(win32_monitor); + auto const& rc = info.rcMonitor; + return Vector2I(rc.left, rc.top); + } + RectI Display::getRect() { + auto const info = getMonitorInfo(win32_monitor); + auto const& rc = info.rcMonitor; + return RectI(rc.left, rc.top, rc.right, rc.bottom); + } + Vector2U Display::getWorkAreaSize() { + auto const info = getMonitorInfo(win32_monitor); + auto const& rc = info.rcWork; + return Vector2U(static_cast(rc.right - rc.left), static_cast(rc.bottom - rc.top)); + } + Vector2I Display::getWorkAreaPosition() { + auto const info = getMonitorInfo(win32_monitor); + auto const& rc = info.rcWork; + return Vector2I(rc.left, rc.top); + } + RectI Display::getWorkAreaRect() { + auto const info = getMonitorInfo(win32_monitor); + auto const& rc = info.rcWork; + return RectI(rc.left, rc.top, rc.right, rc.bottom); + } + bool Display::isPrimary() { + auto const info = getMonitorInfo(win32_monitor); + return !!(info.dwFlags & MONITORINFOF_PRIMARY); + } + float Display::getDisplayScale() { + return win32::getDpiScalingForMonitor(win32_monitor); + } + + // Display + + Display::Display(HMONITOR const monitor) : win32_monitor(monitor) { + } + Display::~Display() = default; +} + +namespace core { + bool IDisplay::getAll(size_t* const count, IDisplay** const output) { + assert(count != nullptr); + assert(*count == 0 || (*count > 0 && output != nullptr)); + struct Context { + std::vector list; + static BOOL CALLBACK callback(HMONITOR const monitor, HDC, LPRECT, LPARAM const data) { + auto const context = reinterpret_cast(data); + context->list.emplace_back(monitor); + return TRUE; + } + }; + Context context{}; + if (!EnumDisplayMonitors(nullptr, nullptr, &Context::callback, reinterpret_cast(&context))) { + return false; + } + *count = context.list.size(); + if (output) { + for (size_t i = 0; i < context.list.size(); i += 1) { + output[i] = new Display(context.list.at(i)); + } + } + return true; + } + bool IDisplay::getPrimary(IDisplay** const output) { + assert(output != nullptr); + struct Context { + HMONITOR primary{}; + static BOOL CALLBACK callback(HMONITOR const monitor, HDC, LPRECT, LPARAM const data) { + auto const context = reinterpret_cast(data); + if (auto const info = getMonitorInfo(monitor); info.dwFlags & MONITORINFOF_PRIMARY) { + context->primary = monitor; + } + return TRUE; + }; + }; + Context context{}; + if (!EnumDisplayMonitors(nullptr, nullptr, &Context::callback, reinterpret_cast(&context))) { + return false; + } + *output = new Display(context.primary); + return true; + } + bool IDisplay::getNearestFromWindow(IWindow* const window, IDisplay** const output) { + assert(window != nullptr); + assert(output != nullptr); + auto const monitor = MonitorFromWindow(static_cast(window->getNativeHandle()), MONITOR_DEFAULTTOPRIMARY); + if (!monitor) { + return false; + } + *output = new Display(monitor); + return true; + } +} diff --git a/engine/window-system/windows/Display.hpp b/engine/window-system/windows/Display.hpp new file mode 100644 index 00000000..8c0ff4ea --- /dev/null +++ b/engine/window-system/windows/Display.hpp @@ -0,0 +1,37 @@ +#pragma once +#include "core/Display.hpp" +#include "core/implement/ReferenceCounted.hpp" +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include + +namespace core { + class Display final : public implement::ReferenceCounted { + public: + // IDisplay + + void* getNativeHandle() override; + void getFriendlyName(IImmutableString** output) override; + Vector2U getSize() override; + Vector2I getPosition() override; + RectI getRect() override; + Vector2U getWorkAreaSize() override; + Vector2I getWorkAreaPosition() override; + RectI getWorkAreaRect() override; + bool isPrimary() override; + float getDisplayScale() override; + + // Display + + explicit Display(HMONITOR monitor); + Display(Display const&) = delete; + Display(Display&&) = delete; + ~Display() override; + + Display& operator=(Display const&) = delete; + Display& operator=(Display&&) = delete; + + private: + HMONITOR win32_monitor{}; + }; +} diff --git a/engine/window-system/windows/FrameRateController.cpp b/engine/window-system/windows/FrameRateController.cpp new file mode 100644 index 00000000..674f91f8 --- /dev/null +++ b/engine/window-system/windows/FrameRateController.cpp @@ -0,0 +1,99 @@ +#include "windows/FrameRateController.hpp" + +namespace { + void sleep(uint32_t ms); + int64_t queryPerformanceFrequency(); + int64_t queryPerformanceCounter(); +} + +namespace core { + // IFrameRateController + + bool FrameRateController::arrived() const noexcept { + const auto current = queryPerformanceCounter(); + return current >= m_last + m_interval; + } + double FrameRateController::update() noexcept { + // current + int64_t current = queryPerformanceCounter(); + + // overflow + if (current < m_last) { + const auto fallback_duration = 1.0 / m_frame_rate; + m_last = current; + m_statistics.reset(); + m_statistics.update(fallback_duration); + return fallback_duration; + } + + // inaccurate wait + const auto threshold = m_last + m_interval - (m_frequency * 2 / 1000); + while (current < threshold) { + sleep(0); + current = queryPerformanceCounter(); + } + + // accurate wait + const auto finish_line = m_last + m_interval; + while (current < finish_line) { + current = queryPerformanceCounter(); + } + + // arrived + const auto duration = static_cast(current - m_last) / static_cast(m_frequency); + m_last = current; + m_statistics.update(duration); + return duration; + } + void FrameRateController::setFrameRate(double frame_rate) noexcept { + m_frame_rate = frame_rate > 1.0 ? frame_rate : 1.0; + m_interval = static_cast(static_cast(m_frequency) * (1.0 / frame_rate)); + } + + // FrameRateController + + FrameRateController::FrameRateController(const double frame_rate) noexcept { + m_frequency = queryPerformanceFrequency(); + m_last = queryPerformanceCounter(); + setFrameRate(frame_rate); + } +} + +namespace core { + IFrameRateController* IFrameRateController::getInstance() { + static FrameRateController instance; + return &instance; + } +} + +namespace core { + ScopeTimer::ScopeTimer(double* const value) : m_value(value) { + m_last = queryPerformanceCounter(); + } + ScopeTimer::~ScopeTimer() { + if (m_value != nullptr) { + const auto frequency = queryPerformanceFrequency(); + const auto current = queryPerformanceCounter(); + *m_value = static_cast(current - m_last) / static_cast(frequency); + } + } +} + +#define WIN32_LEAN_AND_MEAN +#include + +namespace { + void sleep(const uint32_t ms) { + Sleep(ms); + } + int64_t queryPerformanceFrequency() { + LARGE_INTEGER value{}; + QueryPerformanceFrequency(&value); + return value.QuadPart; + } + int64_t queryPerformanceCounter() { + LARGE_INTEGER value{}; + QueryPerformanceCounter(&value); + return value.QuadPart; + } +} diff --git a/engine/window-system/windows/FrameRateController.hpp b/engine/window-system/windows/FrameRateController.hpp new file mode 100644 index 00000000..e9ef8b75 --- /dev/null +++ b/engine/window-system/windows/FrameRateController.hpp @@ -0,0 +1,27 @@ +#pragma once +#include "core/FrameRateController.hpp" +#include + +namespace core { + class FrameRateController : public IFrameRateController { + public: + // IFrameRateController + + bool arrived() const noexcept override; + double update() noexcept override; + double getFrameRate() const noexcept override { return m_frame_rate; } + void setFrameRate(double frame_rate) noexcept override; + const FrameRateStatistics* getStatistics() const noexcept override { return &m_statistics; } + + // FrameRateController + + FrameRateController(double frame_rate = 60.0) noexcept; + + private: + double m_frame_rate{ 60.0 }; + int64_t m_frequency{}; + int64_t m_interval{}; + int64_t m_last{}; + FrameRateStatistics m_statistics; + }; +} diff --git a/engine/window-system/windows/Window.cpp b/engine/window-system/windows/Window.cpp new file mode 100644 index 00000000..7663266c --- /dev/null +++ b/engine/window-system/windows/Window.cpp @@ -0,0 +1,1218 @@ +#include "windows/Window.hpp" +#include "core/Logger.hpp" +#include "core/Application.hpp" +#include "core/FrameRateController.hpp" +#include "core/SmartReference.hpp" +#include "core/Configuration.hpp" +#include "utf8.hpp" +#include "simdutf.h" +#include "win32/win32.hpp" +#include "win32/abi.hpp" +#include +#include "windows/WindowsVersion.hpp" +#include "windows/WindowTheme.hpp" +#include "windows/RuntimeLoader/DesktopWindowManager.hpp" +#include "win32/base.hpp" + +namespace { + using std::string_view_literals::operator ""sv; + + constexpr int LUASTG_WM_UPDAE_TITLE = WM_APP + __LINE__; + constexpr int LUASTG_WM_RECREATE = WM_APP + __LINE__; + constexpr int LUASTG_WM_SET_WINDOW_MODE = WM_APP + __LINE__; + constexpr int LUASTG_WM_SET_FULLSCREEN_MODE = WM_APP + __LINE__; + + Platform::RuntimeLoader::DesktopWindowManager dwmapi_loader; + + DWORD mapWindowStyle(const core::WindowFrameStyle style, const bool fullscreen) { + if (fullscreen) { + return WS_VISIBLE | WS_POPUP; + } + switch (style) { + case core::WindowFrameStyle::None: + return WS_VISIBLE | WS_POPUP; + case core::WindowFrameStyle::Fixed: + return WS_VISIBLE | WS_OVERLAPPEDWINDOW ^ (WS_THICKFRAME | WS_MAXIMIZEBOX); + case core::WindowFrameStyle::Normal: + return WS_VISIBLE | WS_OVERLAPPEDWINDOW; + default: + assert(false); return WS_VISIBLE | WS_POPUP; + } + } + + void clearWindowBackground(const HWND window) { + PAINTSTRUCT ps{}; + if (auto const dc = BeginPaint(window, &ps); dc != nullptr) { + RECT rc{}; + GetClientRect(window, &rc); + auto const brush = static_cast(GetStockObject(BLACK_BRUSH)); + FillRect(dc, &rc, brush); + EndPaint(window, &ps); + } + } + + void setAllowWindowCorner(const HWND window, const bool allow) { + DWM_WINDOW_CORNER_PREFERENCE const attr = allow ? DWMWCP_DEFAULT : DWMWCP_DONOTROUND; + if (!win32::check_hresult_as_boolean( + dwmapi_loader.SetWindowAttribute(window, DWMWA_WINDOW_CORNER_PREFERENCE, &attr, sizeof(attr)), + "SetWindowAttribute"sv + )) { + core::Logger::error("[core] DwmSetWindowAttribute ({}) failed"sv, allow ? "DWMWCP_DEFAULT"sv : "DWMWCP_DONOTROUND"sv); + } + } +} + +namespace core { + void Window::textInput_updateBuffer() { + auto const& s32 = m_text_input_buffer; + auto& s8 = m_text_input_buffer_u8; + s8.resize(simdutf::utf8_length_from_utf32(s32.data(), s32.size())); + simdutf::convert_valid_utf32_to_utf8(s32.data(), s32.size(), reinterpret_cast(s8.data())); + } + void Window::textInput_addChar32(char32_t const code) { + m_text_input_buffer.insert(m_text_input_buffer.begin() + m_text_input_cursor, code); + m_text_input_cursor += 1; + textInput_updateBuffer(); + } + void Window::textInput_handleChar32(char32_t const code) { + if (code == U'\t' || code == U'\n' /* || code == U'\r' */ || (code >= 0x20 && code <= 0x7e) || code >= 0x80) { + textInput_addChar32(code); + } + } + void Window::textInput_handleChar16(char16_t const code) { + if (IS_HIGH_SURROGATE(code)) { + m_text_input_last_high_surrogate = code; + } + else if (IS_LOW_SURROGATE(code)) { + if (IS_SURROGATE_PAIR(m_text_input_last_high_surrogate, code)) { + char16_t const str[3]{ m_text_input_last_high_surrogate, code ,0 }; + char32_t buf[2]{}; + simdutf::convert_valid_utf16le_to_utf32(str, 2, buf); + textInput_handleChar32(buf[0]); + } + m_text_input_last_high_surrogate = {}; + } + else { + textInput_handleChar32(static_cast(code)); + } + } + + bool Window::textInput_isEnabled() { + return m_text_input_enabled; + } + void Window::textInput_setEnabled(bool const enabled) { + m_text_input_enabled = enabled; + } + StringView Window::textInput_getBuffer() { + return { reinterpret_cast(m_text_input_buffer_u8.data()), m_text_input_buffer_u8.size() }; + } + void Window::textInput_clearBuffer() { + m_text_input_buffer.clear(); + m_text_input_buffer_u8.clear(); + m_text_input_cursor = 0; + } + uint32_t Window::textInput_getCursorPosition() { + return m_text_input_cursor; + } + void Window::textInput_setCursorPosition(uint32_t const code_point_index) { + m_text_input_cursor = std::min(code_point_index, static_cast(m_text_input_buffer.size())); + } + void Window::textInput_addCursorPosition(int32_t const offset_by_code_point) { + if (offset_by_code_point == 0) { + return; + } + if (offset_by_code_point > 0) { + if ((static_cast(m_text_input_cursor) + offset_by_code_point) <= m_text_input_buffer.size()) { + m_text_input_cursor += offset_by_code_point; + } + else { + m_text_input_cursor = static_cast(m_text_input_buffer.size()); + } + } + else { + if ((static_cast(m_text_input_cursor) + offset_by_code_point) >= 0) { + m_text_input_cursor += offset_by_code_point; + } + else { + m_text_input_cursor = 0; + } + } + } + void Window::textInput_removeBufferRange(uint32_t const code_point_index, uint32_t const code_point_count) { + auto& s32 = m_text_input_buffer; + if (code_point_index >= s32.size()) { + return; + } + auto const right = static_cast(s32.size()) - code_point_index; + auto const count = std::min(code_point_count, right); + s32.erase(code_point_index, count); + m_text_input_cursor = std::min(m_text_input_cursor, static_cast(s32.size())); + textInput_updateBuffer(); + } + void Window::textInput_insertBufferRange(uint32_t const code_point_index, StringView const str) { + if (!simdutf::validate_utf8(str.data(), str.size())) { + return; + } + std::u32string buf; + buf.resize(simdutf::utf32_length_from_utf8(str.data(), str.size())); + simdutf::convert_valid_utf8_to_utf32(str.data(), str.size(), buf.data()); + if (code_point_index < m_text_input_buffer.size()) { + m_text_input_buffer.insert(code_point_index, buf); + } + else { + m_text_input_buffer.append(buf); + } + m_text_input_cursor += static_cast(str.size()); + textInput_updateBuffer(); + } + void Window::textInput_backspace(uint32_t const code_point_count) { + auto const count = std::min(m_text_input_cursor, code_point_count); + m_text_input_cursor -= count; + m_text_input_buffer.erase(m_text_input_cursor, count); + textInput_updateBuffer(); + } + + void Window::setInputMethodPosition(Vector2I position) { + if (!win32_window) { + return; + } + if (HIMC himc = ImmGetContext(win32_window); win32_window) { + COMPOSITIONFORM composition_form = {}; + composition_form.ptCurrentPos.x = position.x; + composition_form.ptCurrentPos.y = position.y; + composition_form.dwStyle = CFS_FORCE_POSITION; + ImmSetCompositionWindow(himc, &composition_form); + CANDIDATEFORM candidate_form = {}; + candidate_form.dwStyle = CFS_CANDIDATEPOS; + candidate_form.ptCurrentPos.x = position.x; + candidate_form.ptCurrentPos.y = position.y; + ImmSetCandidateWindow(himc, &candidate_form); + ImmReleaseContext(win32_window, himc); + } + } +} + +namespace core { + LRESULT CALLBACK Window::win32_window_callback(HWND const window, UINT const message, WPARAM const arg1, LPARAM const arg2) { + if (auto const self = reinterpret_cast(GetWindowLongPtrW(window, GWLP_USERDATA))) { + return self->onMessage(window, message, arg1, arg2); + } + if (message == WM_NCCREATE) { + win32::enableNonClientDpiScaling(window); + if (auto const params = reinterpret_cast(arg2); params->lpCreateParams) { + auto const self = static_cast(params->lpCreateParams); + + SetLastError(0); + SetWindowLongPtrW(window, GWLP_USERDATA, reinterpret_cast(self)); + if (auto const code = GetLastError(); code != 0) { + Logger::error("[core] (LastError = {}) SetWindowLongPtrW (GWLP_USERDATA) failed", code); + return FALSE; + } + + Platform::WindowTheme::UpdateColorMode(window, TRUE); + setAllowWindowCorner(window, self->m_allow_windows_11_window_corner); + } + } + return DefWindowProcW(window, message, arg1, arg2); + } + + LRESULT Window::onMessage(HWND window, UINT message, WPARAM arg1, LPARAM arg2) { + // Window focus debug + if (enable_track_window_focus && win32_window_want_track_focus) { + HWND focus_window = GetForegroundWindow(); + if (focus_window && focus_window != window) + { + win32_window_want_track_focus = FALSE; + std::array buffer1{}; + std::array buffer2{}; + LRESULT const length1 = SendMessageW(focus_window, WM_GETTEXT, 256, (LPARAM)buffer1.data()); + int const length2 = GetClassNameW(focus_window, buffer2.data(), 256); + Logger::info("[core] The window focus has been gained by: [hwnd: {}] (window class: {}) {}", + reinterpret_cast(focus_window), + utf8::to_string(std::wstring_view(buffer2.data(), static_cast(length2))), + utf8::to_string(std::wstring_view(buffer1.data(), static_cast(length1))) + ); + } + } + + // Text input + if (m_text_input_enabled) { + switch (message) { + case WM_CHAR: + if (arg1 <= 0xFFFF) { + textInput_handleChar16(static_cast(arg1)); + } + break; + } + } + + // Window size/move + if (auto const result = m_sizemove.handleSizeMove(window, message, arg1, arg2); result.bReturn) { + return result.lResult; + } + + // TitleBar customize + if (auto const result = m_title_bar_controller.handleWindowMessage(window, message, arg1, arg2); result.returnResult) { + return result.result; + } + + // Additional callback + for (auto& v : m_eventobj) { + if (v) { + const auto r = v->onNativeWindowMessage(window, message, arg1, arg2); + if (r.should_return) { + return r.result; + } + } + } + + // Messages + switch (message) { + case WM_ACTIVATEAPP: + if (arg1 /* == TRUE */) + { + win32_window_want_track_focus = FALSE; + Platform::WindowTheme::UpdateColorMode(window, TRUE); + dispatchEvent(EventType::WindowActive); + } + else + { + win32_window_want_track_focus = TRUE; // 要开始抓内鬼了 + Platform::WindowTheme::UpdateColorMode(window, FALSE); + dispatchEvent(EventType::WindowInactive); + } + m_alt_down = FALSE; // 无论如何,清除该按键状态 + break; + case WM_SIZE: + if (!m_ignore_size_message) + { + EventData d = {}; + d.window_size = Vector2U(LOWORD(arg2), HIWORD(arg2)); + dispatchEvent(EventType::WindowSize, d); + } + break; + case WM_ENTERSIZEMOVE: + win32_window_is_sizemove = TRUE; + InvalidateRect(window, NULL, FALSE); // 标记窗口区域为需要重新绘制,以便产生 WM_PAINT 消息 + return 0; + case WM_EXITSIZEMOVE: + win32_window_is_sizemove = FALSE; + return 0; + case WM_ENTERMENULOOP: + win32_window_is_menu_loop = TRUE; + InvalidateRect(window, NULL, FALSE); // 标记窗口区域为需要重新绘制,以便产生 WM_PAINT 消息 + return 0; + case WM_EXITMENULOOP: + win32_window_is_menu_loop = FALSE; + return 0; + case WM_PAINT: + if (win32_window_is_sizemove || win32_window_is_menu_loop) { + if (const auto application = core::ApplicationManager::getApplication(); application != nullptr) { + const auto frame_rate_controller = core::IFrameRateController::getInstance(); + if (frame_rate_controller->arrived()) { + application->onBeforeUpdate(); + if (!application->onUpdate()) { + core::ApplicationManager::requestExit(); + } + } + } + } + else { + ValidateRect(window, nullptr); + } + return 0; + case WM_SYSKEYDOWN: + case WM_KEYDOWN: + if (arg1 == VK_MENU) + { + m_alt_down = TRUE; + return 0; + } + if (m_alt_down && arg1 == VK_RETURN) + { + _toggleFullScreenMode(); + return 0; + } + break; + case WM_SYSKEYUP: + case WM_KEYUP: + if (arg1 == VK_MENU) + { + m_alt_down = FALSE; + return 0; + } + break; + case WM_GETMINMAXINFO: + { + MINMAXINFO* info = (MINMAXINFO*)arg2; + RECT rect_min = { 0, 0, 320, 240 }; + UINT const dpi = win32::getDpiForWindow(window); + if (m_title_bar_controller.adjustWindowRectExForDpi(&rect_min, win32_window_style, FALSE, win32_window_style_ex, dpi)) + { + info->ptMinTrackSize.x = rect_min.right - rect_min.left; + info->ptMinTrackSize.y = rect_min.bottom - rect_min.top; + } + } + return 0; + case WM_DPICHANGED: + if (getFrameStyle() != WindowFrameStyle::None) + { + RECT rc{}; + GetWindowRect(window, &rc); + setSize(getSize()); // 刷新一次尺寸(因为非客户区可能会变化) + SetWindowPos(window, NULL, rc.left, rc.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE); + dispatchEvent(EventType::WindowDpiChanged); + return 0; + } + dispatchEvent(EventType::WindowDpiChanged); // 仍然需要通知 + break; + case WM_SETTINGCHANGE: + case WM_THEMECHANGED: + Platform::WindowTheme::UpdateColorMode(window, TRUE); + break; + case WM_DEVICECHANGE: + if (arg1 == 0x0007 /* DBT_DEVNODES_CHANGED */) + { + dispatchEvent(EventType::DeviceChange); + } + break; + case WM_SETCURSOR: + if (LOWORD(arg2) == HTCLIENT) + { + SetCursor(win32_window_cursor); + return TRUE; + } + break; + case WM_MENUCHAR: + // 快捷键能不能死全家 + return MAKELRESULT(0, MNC_CLOSE); + case WM_SYSCOMMAND: + // 鼠标左键点击标题栏图标或者 Alt+Space 不会出现菜单 + switch (arg1 & 0xFFF0) + { + case SC_KEYMENU: + case SC_MOUSEMENU: + return 0; + } + break; + case WM_CLOSE: + dispatchEvent(EventType::WindowClose); + PostQuitMessage(EXIT_SUCCESS); + return 0; + case LUASTG_WM_UPDAE_TITLE: + SetWindowTextW(window, win32_window_text_w.data()); + return 0; + case LUASTG_WM_RECREATE: + _recreateWindow(); + return 0; + case LUASTG_WM_SET_WINDOW_MODE: + _setWindowMode(reinterpret_cast(arg1), arg2); + return 0; + case LUASTG_WM_SET_FULLSCREEN_MODE: + _setFullScreenMode(reinterpret_cast(arg2)); + return 0; + } + const auto result = DefWindowProcW(window, message, arg1, arg2); + if (!m_window_created) { + // 在 CreateWindow/CreateWindowEx 期间, + // 即使设置了窗口类的 hbrBackground 为黑色笔刷,窗口背景也会先绘制为白色,再转为黑色。 + // 只有不断追着窗口消息重绘背景,才能 **一定程度** 上避免白色背景(不保证 100% 有效)。 + // CreateWindow/CreateWindowEx 一般会产生以下窗口消息(按先后顺序): + // - WM_GETMINMAXINFO + // - WM_NCCREATE + // - WM_NCCALCSIZE + // - WM_CREATE + // - WM_SHOWWINDOW + // - WM_WINDOWPOSCHANGING + // - WM_NCPAINT + // - WM_GETICON + // - WM_ERASEBKGND + // - WM_GETICON + // - WM_ACTIVATEAPP + // - WM_NCACTIVATE + // - WM_ACTIVATE + // - WM_IME_SETCONTEXT + // - WM_IME_NOTIFY + // - WM_SETFOCUS + // - WM_WINDOWPOSCHANGED + // - WM_SIZE + // - WM_MOVE + // 经过测试,如果在以下三类消息之后重绘背景为黑色,能极大程度地减少看到白色背景的概率: + // - WM_NCPAINT + // - WM_GETICON + // - WM_ERASEBKGND + // 但仅处理以上三类消息,仍然会有一定概率出现白色背景, + // 因此,有理由猜测白色背景的绘制在窗口弹出动画期间都会持续执行(可能由桌面窗口管理器合成)。 + clearWindowBackground(window); + } + return result; + } + bool Window::createWindowClass() { + auto const instance_handle = GetModuleHandleW(nullptr); + if (instance_handle == nullptr) { + assert(false); // unlikely + return false; + } + + HICON icon{}; + if (win32_window_icon_id != 0) { + icon = LoadIcon(instance_handle, MAKEINTRESOURCE(win32_window_icon_id)); + } + + auto& cls = win32_window_class; + cls.style = CS_HREDRAW | CS_VREDRAW; + cls.lpfnWndProc = &win32_window_callback; + cls.hInstance = instance_handle; + cls.hIcon = icon; + cls.hCursor = LoadCursor(nullptr, IDC_ARROW); + cls.hbrBackground = static_cast(GetStockObject(BLACK_BRUSH)); + cls.lpszClassName = L"LuaSTG::Sub::Window"; + cls.hIconSm = icon; + + win32_window_class_atom = RegisterClassExW(&cls); + + if (icon != nullptr) { + DestroyIcon(icon); + } + + if (win32_window_class_atom == 0) { + Logger::error("[core] (LastError = {}) RegisterClassExW failed", GetLastError()); + return false; + } + + return true; + } + void Window::destroyWindowClass() { + if (win32_window_class_atom != 0) { + UnregisterClassW(win32_window_class.lpszClassName, win32_window_class.hInstance); + } + win32_window_class_atom = 0; + } + bool Window::createWindow() { + if (win32_window_class_atom == 0) { + return false; + } + + // 拿到原点位置的显示器信息 + SmartReference display; + if (!IDisplay::getPrimary(display.put())) { + return false; // 理论上 Windows 平台的主显示器都在原点 + } + auto const display_rect = display->getWorkAreaRect(); + auto const display_dpi = static_cast(display->getDisplayScale() * USER_DEFAULT_SCREEN_DPI); + + // 计算初始大小 + + RECT client{ 0, 0, static_cast(win32_window_width),static_cast(win32_window_height) }; + m_title_bar_controller.setEnable(auto_hide_title_bar); + m_title_bar_controller.adjustWindowRectExForDpi(&client, win32_window_style, FALSE, win32_window_style_ex, display_dpi); + + // 创建窗口 + + convertTitleText(); + win32_window = CreateWindowExW( + win32_window_style_ex, + win32_window_class.lpszClassName, + win32_window_text_w.data(), + win32_window_style, + (display_rect.a.x + display_rect.b.x) / 2 - (client.right - client.left) / 2, // x (left) + (display_rect.a.y + display_rect.b.y) / 2 - (client.bottom - client.top) / 2, // y (top) + client.right - client.left, + client.bottom - client.top, + nullptr, // parent + nullptr, // menu + win32_window_class.hInstance, + this + ); + if (win32_window == nullptr) { + Logger::error("[core] (LastError = {}) CreateWindowExW failed", GetLastError()); + return false; + } + m_window_created = true; + + // 配置输入法 + + if (!win32_window_ime_enable) { + ImmAssociateContext(win32_window, nullptr); + } + + // 配置窗口挪动器 + + m_sizemove.setWindow(win32_window); + + return true; + } + void Window::destroyWindow() { + m_sizemove.setWindow(nullptr); + m_window_created = false; + if (win32_window) { + DestroyWindow(win32_window); + win32_window = nullptr; + } + } + bool Window::_recreateWindow() { + BOOL result{ FALSE }; + WINDOWPLACEMENT last_window_placement{}; + last_window_placement.length = sizeof(last_window_placement); + + assert(win32_window); + if (result = GetWindowPlacement(win32_window, &last_window_placement); !result) { + assert(result); + return false; + } + + destroyWindow(); + if (!createWindow()) { + return false; + } + + assert(win32_window); + if (result = SetWindowPlacement(win32_window, &last_window_placement); !result) { + assert(result); + return false; + } + + return true; + } + bool Window::recreateWindow() { + dispatchEvent(EventType::WindowDestroy); + SendMessageW(win32_window, LUASTG_WM_RECREATE, 0, 0); + //if (!_recreateWindow()) { + // return false; + //} + dispatchEvent(EventType::WindowCreate); + return true; + } + void Window::_toggleFullScreenMode() { + if (m_fullscreen_mode) { + SetWindowedModeParameters parameters{}; + parameters.size = Vector2U(win32_window_width, win32_window_height); + parameters.style = m_framestyle; + _setWindowMode(¶meters, true); + } + else { + _setFullScreenMode(nullptr); + } + } + void Window::_setWindowMode(SetWindowedModeParameters* parameters, bool ignore_size) { + assert(parameters); + + m_title_bar_controller.setEnable(auto_hide_title_bar); + + HMONITOR win32_monitor{}; + if (parameters->display) { + win32_monitor = static_cast(parameters->display->getNativeHandle()); + } + else { + win32_monitor = MonitorFromWindow(win32_window, MONITOR_DEFAULTTONEAREST); + } + assert(win32_monitor); + MONITORINFO monitor_info = {}; + monitor_info.cbSize = sizeof(monitor_info); + BOOL const get_monitor_info_result = GetMonitorInfoW(win32_monitor, &monitor_info); + assert(get_monitor_info_result); (void)get_monitor_info_result; + assert(monitor_info.rcWork.right > monitor_info.rcWork.left); + assert(monitor_info.rcWork.bottom > monitor_info.rcWork.top); + + bool const new_fullsceen_mode = false; + m_framestyle = parameters->style; + DWORD new_win32_window_style = mapWindowStyle(m_framestyle, new_fullsceen_mode); + + RECT rect = { 0, 0, (int32_t)parameters->size.x, (int32_t)parameters->size.y }; + m_title_bar_controller.adjustWindowRectExForDpi( + &rect, new_win32_window_style, FALSE, 0, + win32::getDpiForWindow(win32_window)); + + //m_ignore_size_message = TRUE; + SetLastError(0); + SetWindowLongPtrW(win32_window, GWL_STYLE, new_win32_window_style); + DWORD const set_style_result = GetLastError(); + assert(set_style_result == 0); (void)set_style_result; + //SetLastError(0); + //SetWindowLongPtrW(win32_window, GWL_EXSTYLE, 0); + //DWORD const set_style_ex_result = GetLastError(); + //assert(set_style_ex_result == 0); (void)set_style_ex_result; + //m_ignore_size_message = FALSE; + + bool want_restore_placement = false; + + if (m_fullscreen_mode && ignore_size) + { + want_restore_placement = true; + } + else + { + BOOL const set_window_pos_result = SetWindowPos( + win32_window, + HWND_TOP, + (monitor_info.rcWork.right + monitor_info.rcWork.left) / 2 - (rect.right - rect.left) / 2, + (monitor_info.rcWork.bottom + monitor_info.rcWork.top) / 2 - (rect.bottom - rect.top) / 2, + rect.right - rect.left, + rect.bottom - rect.top, + SWP_FRAMECHANGED | SWP_SHOWWINDOW); + assert(set_window_pos_result); (void)set_window_pos_result; + } + + RECT client_rect = {}; + BOOL get_client_rect_result = GetClientRect(win32_window, &client_rect); + assert(get_client_rect_result); (void)get_client_rect_result; + + m_fullscreen_mode = new_fullsceen_mode; + win32_window_style = new_win32_window_style; + win32_window_width = UINT(client_rect.right - client_rect.left); + win32_window_height = UINT(client_rect.bottom - client_rect.top); + + EventData event_data{}; + event_data.window_fullscreen_state = false; + dispatchEvent(EventType::WindowFullscreenStateChange, event_data); + + if (want_restore_placement) + { + BOOL const set_placement_result = SetWindowPlacement(win32_window, &m_last_window_placement); + assert(set_placement_result); (void)set_placement_result; + } + } + void Window::_setFullScreenMode(IDisplay* display) { + m_title_bar_controller.setEnable(false); + + if (!m_fullscreen_mode) + { + BOOL const get_placement_result = GetWindowPlacement(win32_window, &m_last_window_placement); + assert(get_placement_result); (void)get_placement_result; + } + + HMONITOR win32_monitor{}; + if (display) { + win32_monitor = static_cast(display->getNativeHandle()); + } + else { + win32_monitor = MonitorFromWindow(win32_window, MONITOR_DEFAULTTONEAREST); + } + assert(win32_monitor); + MONITORINFO monitor_info = {}; + monitor_info.cbSize = sizeof(monitor_info); + BOOL const get_monitor_info_result = GetMonitorInfoW(win32_monitor, &monitor_info); + assert(get_monitor_info_result); (void)get_monitor_info_result; + assert(monitor_info.rcMonitor.right > monitor_info.rcMonitor.left); + assert(monitor_info.rcMonitor.bottom > monitor_info.rcMonitor.top); + + bool const new_fullsceen_mode = true; + DWORD new_win32_window_style = mapWindowStyle(m_framestyle, new_fullsceen_mode); + + //m_ignore_size_message = TRUE; + SetLastError(0); + SetWindowLongPtrW(win32_window, GWL_STYLE, new_win32_window_style); + DWORD const set_style_result = GetLastError(); + assert(set_style_result == 0); (void)set_style_result; + //SetLastError(0); + //SetWindowLongPtrW(win32_window, GWL_EXSTYLE, 0); + //DWORD const set_style_ex_result = GetLastError(); + //assert(set_style_ex_result == 0); (void)set_style_ex_result; + //m_ignore_size_message = FALSE; + + BOOL const set_window_pos_result = SetWindowPos( + win32_window, + HWND_TOP, + monitor_info.rcMonitor.left, + monitor_info.rcMonitor.top, + monitor_info.rcMonitor.right - monitor_info.rcMonitor.left, + monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top, + SWP_FRAMECHANGED | SWP_SHOWWINDOW); + assert(set_window_pos_result); (void)set_window_pos_result; + + m_fullscreen_mode = new_fullsceen_mode; + win32_window_style = new_win32_window_style; + win32_window_width = UINT(monitor_info.rcMonitor.right - monitor_info.rcMonitor.left); + win32_window_height = UINT(monitor_info.rcMonitor.bottom - monitor_info.rcMonitor.top); + + EventData event_data{}; + event_data.window_fullscreen_state = true; + dispatchEvent(EventType::WindowFullscreenStateChange, event_data); + } + + void Window::convertTitleText() { + win32_window_text_w[0] = L'\0'; + int const size = MultiByteToWideChar(CP_UTF8, 0, win32_window_text.data(), (int)win32_window_text.size(), NULL, 0); + if (size <= 0 || size > (int)(win32_window_text_w.size() - 1)) + { + assert(false); return; + } + win32_window_text_w[size] = L'\0'; + int const result = MultiByteToWideChar(CP_UTF8, 0, win32_window_text.data(), (int)win32_window_text.size(), win32_window_text_w.data(), size); + if (result <= 0 || result != size) + { + assert(false); return; + } + win32_window_text_w[result] = L'\0'; + } + + RectI Window::getRect() { + RECT rc = {}; + GetWindowRect(win32_window, &rc); + return RectI(rc.left, rc.top, rc.right, rc.bottom); + } + bool Window::setRect(RectI v) { + return SetWindowPos(win32_window, NULL, + v.a.x, v.a.y, + v.b.x - v.a.x, v.b.y - v.a.y, + SWP_NOZORDER) != FALSE; + } + RectI Window::getClientRect() { + RECT rc = {}; + GetClientRect(win32_window, &rc); + return RectI(rc.left, rc.top, rc.right, rc.bottom); + } + bool Window::setClientRect(RectI v) { + // 更新 DPI + win32_window_dpi = win32::getDpiForWindow(win32_window); + // 计算包括窗口框架的尺寸 + RECT rc = { v.a.x , v.a.y , v.b.x , v.b.y }; + m_title_bar_controller.adjustWindowRectExForDpi( + &rc, + win32_window_style, + FALSE, + win32_window_style_ex, + win32_window_dpi); + // 获取最近的显示器的位置 + if (HMONITOR monitor = MonitorFromWindow(win32_window, MONITOR_DEFAULTTONEAREST)) + { + MONITORINFO moninfo = { sizeof(MONITORINFO), {}, {}, 0 }; + if (GetMonitorInfoA(monitor, &moninfo)) + { + // 偏移到该显示器0点位置 + rc.left += moninfo.rcMonitor.left; + rc.right += moninfo.rcMonitor.left; + rc.top += moninfo.rcMonitor.top; + rc.bottom += moninfo.rcMonitor.top; + } + } + // 最后再应用 + return SetWindowPos(win32_window, NULL, + rc.left, + rc.top, + rc.right - rc.left, + rc.bottom - rc.top, + SWP_NOZORDER) != FALSE; + } + uint32_t Window::getDPI() { + win32_window_dpi = win32::getDpiForWindow(win32_window); + return win32_window_dpi; + } + + void Window::dispatchEvent(EventType t, EventData d) { + // 回调 + m_is_dispatch_event = true; + switch (t) + { + case EventType::WindowCreate: + for (auto& v : m_eventobj) + { + if (v) v->onWindowCreate(); + } + break; + case EventType::WindowDestroy: + for (auto& v : m_eventobj) + { + if (v) v->onWindowDestroy(); + } + break; + case EventType::WindowActive: + for (auto& v : m_eventobj) + { + if (v) v->onWindowActive(); + } + break; + case EventType::WindowInactive: + for (auto& v : m_eventobj) + { + if (v) v->onWindowInactive(); + } + break; + case EventType::WindowClose: + for (auto& v : m_eventobj) + { + if (v) v->onWindowClose(); + } + break; + case EventType::WindowSize: + for (auto& v : m_eventobj) + { + if (v) v->onWindowSize(d.window_size); + } + break; + case EventType::WindowFullscreenStateChange: + for (auto& v : m_eventobj) + { + if (v) v->onWindowFullscreenStateChange(d.window_fullscreen_state); + } + break; + case EventType::WindowDpiChanged: + for (auto& v : m_eventobj) + { + if (v) v->onWindowDpiChange(); + } + break; + case EventType::DeviceChange: + for (auto& v : m_eventobj) + { + if (v) v->onDeviceChange(); + } + break; + } + m_is_dispatch_event = false; + // 处理那些延迟的对象 + removeEventListener(nullptr); + for (auto& v : m_eventobj_late) + { + m_eventobj.emplace_back(v); + } + m_eventobj_late.clear(); + } + void Window::addEventListener(IWindowEventListener* e) { + removeEventListener(e); + if (m_is_dispatch_event) + { + m_eventobj_late.emplace_back(e); + } + else + { + m_eventobj.emplace_back(e); + } + } + void Window::removeEventListener(IWindowEventListener* e) { + if (m_is_dispatch_event) + { + for (auto& v : m_eventobj) + { + if (v == e) + { + v = nullptr; // 不破坏遍历过程 + } + } + } + else + { + for (auto it = m_eventobj.begin(); it != m_eventobj.end();) + { + if (*it == e) + it = m_eventobj.erase(it); + else + it++; + } + } + } + + void* Window::getNativeHandle() { return win32_window; } + + void Window::setIMEState(bool enable) { + if (!win32_window_ime_enable && enable) { + #pragma warning(push) + #pragma warning(disable: 6387) + // See: https://learn.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immassociatecontextex + // If the application calls this function with IACE_DEFAULT, the operating system restores the default input method context for the window. + ImmAssociateContextEx(win32_window, nullptr /* In this case, the hIMC parameter is ignored. */, IACE_DEFAULT); + #pragma warning (pop) + } + else if (win32_window_ime_enable && !enable) { + ImmAssociateContext(win32_window, nullptr); + } + win32_window_ime_enable = enable; + } + bool Window::getIMEState() { + return win32_window_ime_enable; + } + + void Window::setTitleText(StringView const str) { + win32_window_text = str; + m_title_bar_controller.setTitle(std::string(str)); + convertTitleText(); + if (win32_window) { + PostMessageW(win32_window, LUASTG_WM_UPDAE_TITLE, 0, 0); + } + } + StringView Window::getTitleText() { + return win32_window_text; + } + + bool Window::setFrameStyle(WindowFrameStyle style) { + m_framestyle = style; + win32_window_style = mapWindowStyle(m_framestyle, m_fullscreen_mode); + SetWindowLongPtrW(win32_window, GWL_STYLE, win32_window_style); + //SetWindowLongPtrW(win32_window, GWL_EXSTYLE, win32_window_style_ex); + constexpr UINT flags = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW; + SetWindowPos(win32_window, nullptr, 0, 0, 0, 0, flags); + return true; + } + WindowFrameStyle Window::getFrameStyle() { + return m_framestyle; + } + + Vector2U Window::getSize() { + return { win32_window_width, win32_window_height }; + } + Vector2U Window::_getCurrentSize() { + RECT rc{}; + GetClientRect(win32_window, &rc); + return Vector2U(static_cast(rc.right - rc.left), static_cast(rc.bottom - rc.top)); + } + bool Window::setSize(Vector2U v) { + win32_window_width = v.x; + win32_window_height = v.y; + return setClientRect(RectI(0, 0, (int)v.x, (int)v.y)); + } + bool Window::setLayer(WindowLayer const layer) { + HWND native_layer{}; + switch (layer) { + case WindowLayer::Bottom: + native_layer = HWND_BOTTOM; + break; + case WindowLayer::Normal: + native_layer = HWND_NOTOPMOST; + break; + case WindowLayer::Top: + native_layer = HWND_TOP; + break; + case WindowLayer::TopMost: + native_layer = HWND_TOPMOST; + break; + default: + assert(false); + return false; + } + return SetWindowPos(win32_window, native_layer, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW) != FALSE; + } + + float Window::getDPIScaling() { + return win32::getScalingFromDpi(getDPI()); + } + + void Window::setWindowMode(Vector2U size, WindowFrameStyle style, IDisplay* display) { + SetWindowedModeParameters parameters{}; + parameters.size = size; + parameters.style = style; + parameters.display = display; + SendMessageW(win32_window, LUASTG_WM_SET_WINDOW_MODE, reinterpret_cast(¶meters), FALSE); + } + void Window::setFullScreenMode(IDisplay* display) { + SendMessageW(win32_window, LUASTG_WM_SET_FULLSCREEN_MODE, 0, reinterpret_cast(display)); + } + void Window::setCentered(bool show, IDisplay* display) { + core::SmartReference local_display; + if (!display) { + if (!IDisplay::getNearestFromWindow(this, local_display.put())) { + return; + } + display = local_display.get(); + } + RECT r{}; + [[maybe_unused]] auto const result1 = GetWindowRect(win32_window, &r); + assert(result1); + auto const& m = display->getWorkAreaRect(); + UINT flags = SWP_FRAMECHANGED; + if (show) { + flags |= SWP_SHOWWINDOW; + } + [[maybe_unused]] auto const result2 = SetWindowPos( + win32_window, + HWND_TOP, + (m.a.x + m.b.x) / 2 - (r.right - r.left) / 2, + (m.a.y + m.b.y) / 2 - (r.bottom - r.top) / 2, + r.right - r.left, + r.bottom - r.top, + flags); + assert(result2); + } + + void Window::setCustomSizeMoveEnable(bool v) { + m_sizemove.setEnable(v ? TRUE : FALSE); + } + void Window::setCustomMinimizeButtonRect(RectI v) { + m_sizemove.setMinimizeButtonRect(RECT{ + .left = v.a.x, + .top = v.a.y, + .right = v.b.x, + .bottom = v.b.y, + }); + } + void Window::setCustomCloseButtonRect(RectI v) { + m_sizemove.setCloseButtonRect(RECT{ + .left = v.a.x, + .top = v.a.y, + .right = v.b.x, + .bottom = v.b.y, + }); + } + void Window::setCustomMoveButtonRect(RectI v) { + m_sizemove.setTitleBarRect(RECT{ + .left = v.a.x, + .top = v.a.y, + .right = v.b.x, + .bottom = v.b.y, + }); + } + + bool Window::setCursor(WindowCursor type) { + m_cursor = type; + switch (type) + { + default: + assert(false); return false; + + case WindowCursor::None: + win32_window_cursor = NULL; + break; + + case WindowCursor::Arrow: + win32_window_cursor = LoadCursor(NULL, IDC_ARROW); + break; + case WindowCursor::Hand: + win32_window_cursor = LoadCursor(NULL, IDC_HAND); + break; + + case WindowCursor::Cross: + win32_window_cursor = LoadCursor(NULL, IDC_CROSS); + break; + case WindowCursor::TextInput: + win32_window_cursor = LoadCursor(NULL, IDC_IBEAM); + break; + + case WindowCursor::Resize: + win32_window_cursor = LoadCursor(NULL, IDC_SIZEALL); + break; + case WindowCursor::ResizeEW: + win32_window_cursor = LoadCursor(NULL, IDC_SIZEWE); + break; + case WindowCursor::ResizeNS: + win32_window_cursor = LoadCursor(NULL, IDC_SIZENS); + break; + case WindowCursor::ResizeNESW: + win32_window_cursor = LoadCursor(NULL, IDC_SIZENESW); + break; + case WindowCursor::ResizeNWSE: + win32_window_cursor = LoadCursor(NULL, IDC_SIZENWSE); + break; + + case WindowCursor::NotAllowed: + win32_window_cursor = LoadCursor(NULL, IDC_NO); + break; + case WindowCursor::Wait: + win32_window_cursor = LoadCursor(NULL, IDC_WAIT); + break; + } + POINT pt = {}; + GetCursorPos(&pt); + SetCursorPos(pt.x, pt.y); + return true; + } + WindowCursor Window::getCursor() { + return m_cursor; + } + + void Window::setWindowCornerPreference(bool const allow) { + m_allow_windows_11_window_corner = allow; + if (!Platform::WindowsVersion::Is11()) { + return; + } + assert(win32_window); + setAllowWindowCorner(win32_window, allow); + } + void Window::setTitleBarAutoHidePreference(bool const allow) { + auto_hide_title_bar = allow; + m_title_bar_controller.setEnable(auto_hide_title_bar && !m_fullscreen_mode); + if (!m_fullscreen_mode) { + WINDOWPLACEMENT placement{ .length{sizeof(WINDOWPLACEMENT)} }; + GetWindowPlacement(win32_window, &placement); + SetWindowPos(win32_window, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED); + SetWindowPlacement(win32_window, &placement); + } + else { + SetWindowPos(win32_window, nullptr, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE | SWP_FRAMECHANGED | SWP_SHOWWINDOW); + } + } + + Window::Window() { + auto const& debug_config = ConfigurationLoader::getInstance().getDebug(); + enable_track_window_focus = debug_config.isTrackWindowFocus(); + + auto const& window_config = ConfigurationLoader::getInstance().getWindow(); + if (window_config.hasTitle()) { + win32_window_text = window_config.getTitle(); + } + m_cursor = window_config.isCursorVisible() ? WindowCursor::Arrow : WindowCursor::None; + m_allow_windows_11_window_corner = window_config.isAllowWindowCorner(); + auto_hide_title_bar = window_config.isAllowTitleBarAutoHide(); + + auto const& graphics_config = ConfigurationLoader::getInstance().getGraphicsSystem(); + win32_window_width = graphics_config.getWidth(); + win32_window_height = graphics_config.getHeight(); + + m_title_bar_controller.setTitle(win32_window_text); + convertTitleText(); + win32_window_dpi = win32::getUserDefaultScreenDpi(); + + if (!createWindowClass()) + throw std::runtime_error("createWindowClass failed"); + if (!createWindow()) + throw std::runtime_error("createWindow failed"); + } + Window::~Window() { + destroyWindow(); + destroyWindowClass(); + } + + bool Window::create(Window** pp_window) { + try { + *pp_window = new Window(); + return true; + } + catch (...) { + *pp_window = nullptr; + return false; + } + } + bool Window::create(Vector2U size, StringView title_text, WindowFrameStyle style, bool show, Window** pp_window) { + try { + auto* p = new Window(); + *pp_window = p; + p->setSize(size); + p->setTitleText(title_text); + p->setFrameStyle(style); + if (show) + p->setLayer(WindowLayer::Normal); + return true; + } + catch (...) { + *pp_window = nullptr; + return false; + } + } +} + +namespace core { + bool IWindow::create(IWindow** pp_window) { + try { + *pp_window = new Window(); + return true; + } + catch (...) { + *pp_window = nullptr; + return false; + } + } + bool IWindow::create(Vector2U size, StringView title_text, WindowFrameStyle style, bool show, IWindow** pp_window) { + try { + auto* p = new Window(); + *pp_window = p; + p->setSize(size); + p->setTitleText(title_text); + p->setFrameStyle(style); + if (show) + p->setLayer(WindowLayer::Normal); + return true; + } + catch (...) { + *pp_window = nullptr; + return false; + } + } +} diff --git a/engine/window-system/windows/Window.hpp b/engine/window-system/windows/Window.hpp new file mode 100644 index 00000000..6062c9a6 --- /dev/null +++ b/engine/window-system/windows/Window.hpp @@ -0,0 +1,190 @@ +#pragma once +#include "core/Window.hpp" +#include "core/implement/ReferenceCounted.hpp" +#include +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include +#include +#include "windows/WindowSizeMoveController.hpp" +#include "windows/ImmersiveTitleBarController.hpp" + +namespace core { + struct SetWindowedModeParameters { + Vector2U size; + WindowFrameStyle style{ WindowFrameStyle::None }; + IDisplay* display{}; + }; + + class Window : public implement::ReferenceCounted { + private: + WNDCLASSEXW win32_window_class{ sizeof(WNDCLASSEXW) }; + ATOM win32_window_class_atom{ 0 }; + static LRESULT CALLBACK win32_window_callback(HWND window, UINT message, WPARAM arg1, LPARAM arg2); + + HWND win32_window{}; + bool m_window_created{ false }; + + BOOL win32_window_ime_enable{ FALSE }; + + UINT win32_window_width{ 640 }; + UINT win32_window_height{ 480 }; + UINT win32_window_dpi{ USER_DEFAULT_SCREEN_DPI }; + + INT_PTR win32_window_icon_id{ /* IDI_APPICON THIS IS A HACK */ 101 }; + + std::string win32_window_text{ "LuaSTG Sub" }; + std::array win32_window_text_w{}; + + WindowCursor m_cursor{ WindowCursor::Arrow }; + HCURSOR win32_window_cursor{}; + + WindowFrameStyle m_framestyle{ WindowFrameStyle::Normal }; + DWORD win32_window_style{ WS_VISIBLE | WS_OVERLAPPEDWINDOW ^ (WS_THICKFRAME | WS_MAXIMIZEBOX) }; + DWORD win32_window_style_ex{ 0 }; + WINDOWPLACEMENT m_last_window_placement{}; + BOOL m_alt_down{ FALSE }; + BOOL m_fullscreen_mode{ FALSE }; + BOOL m_ignore_size_message{ FALSE }; // 在 SetWindowLongPtr 修改窗口样式时,可以忽略 WM_SIZE + BOOL m_allow_windows_11_window_corner{ TRUE }; + + BOOL win32_window_is_sizemove{ FALSE }; + BOOL win32_window_is_menu_loop{ FALSE }; + BOOL win32_window_want_track_focus{ FALSE }; + bool enable_track_window_focus{ false }; + bool auto_hide_title_bar{ false }; + + Platform::WindowSizeMoveController m_sizemove; + platform::windows::ImmersiveTitleBarController m_title_bar_controller; + + LRESULT onMessage(HWND window, UINT message, WPARAM arg1, LPARAM arg2); + + bool createWindowClass(); + void destroyWindowClass(); + bool createWindow(); + void destroyWindow(); + + public: + // 内部方法 + + HWND GetWindow() { return win32_window; } + platform::windows::ImmersiveTitleBarController& getTitleBarController() { return m_title_bar_controller; } + + void convertTitleText(); + + RectI getRect(); + bool setRect(RectI v); + RectI getClientRect(); + bool setClientRect(RectI v); + uint32_t getDPI(); + bool _recreateWindow(); + bool recreateWindow(); + void _toggleFullScreenMode(); + void _setWindowMode(SetWindowedModeParameters* parameters, bool ignore_size); + void _setFullScreenMode(IDisplay* display); + + private: + + enum class EventType { + WindowCreate, + WindowDestroy, + + WindowActive, + WindowInactive, + + WindowClose, + + WindowSize, + WindowFullscreenStateChange, + WindowDpiChanged, + + NativeWindowMessage, + + DeviceChange, + }; + + union EventData { + Vector2U window_size; + bool window_fullscreen_state; + }; + + bool m_is_dispatch_event{ false }; + std::vector m_eventobj; + std::vector m_eventobj_late; + + void dispatchEvent(EventType t, EventData d = {}); + + public: + void addEventListener(IWindowEventListener* e) override; + void removeEventListener(IWindowEventListener* e) override; + + private: + std::u32string m_text_input_buffer; + std::u8string m_text_input_buffer_u8; + uint32_t m_text_input_cursor{}; + char16_t m_text_input_last_high_surrogate{}; + bool m_text_input_enabled{ false }; + + void textInput_updateBuffer(); + void textInput_addChar32(char32_t code); + void textInput_handleChar32(char32_t code); + void textInput_handleChar16(char16_t code); + + public: + + // IWindow + + bool textInput_isEnabled() override; + void textInput_setEnabled(bool enabled) override; + StringView textInput_getBuffer() override; + void textInput_clearBuffer() override; + uint32_t textInput_getCursorPosition() override; + void textInput_setCursorPosition(uint32_t code_point_index) override; + void textInput_addCursorPosition(int32_t offset_by_code_point) override; + void textInput_removeBufferRange(uint32_t code_point_index, uint32_t code_point_count) override; + void textInput_insertBufferRange(uint32_t code_point_index, StringView str) override; + void textInput_backspace(uint32_t code_point_count) override; + + void* getNativeHandle() override; + + void setIMEState(bool enable) override; + bool getIMEState() override; + void setInputMethodPosition(Vector2I position) override; + + void setTitleText(StringView str) override; + StringView getTitleText() override; + + bool setFrameStyle(WindowFrameStyle style) override; + WindowFrameStyle getFrameStyle() override; + + Vector2U getSize() override; + Vector2U _getCurrentSize() override; + bool setSize(Vector2U v) override; + bool setLayer(WindowLayer layer) override; + + float getDPIScaling() override; + + void setWindowMode(Vector2U size, WindowFrameStyle style, IDisplay* display) override; + void setFullScreenMode(IDisplay* display) override; + void setCentered(bool show, IDisplay* display) override; + + void setCustomSizeMoveEnable(bool v) override; + void setCustomMinimizeButtonRect(RectI v) override; + void setCustomCloseButtonRect(RectI v) override; + void setCustomMoveButtonRect(RectI v) override; + + bool setCursor(WindowCursor type) override; + WindowCursor getCursor() override; + + void setWindowCornerPreference(bool allow) override; // Windows 11 + void setTitleBarAutoHidePreference(bool allow) override; // Windows 11 + + // Window/Win32 + + Window(); + ~Window() override; + + static bool create(Window** pp_window); + static bool create(Vector2U size, StringView title_text, WindowFrameStyle style, bool show, Window** pp_window); + }; +} diff --git a/imgui/CMakeLists.txt b/imgui/CMakeLists.txt index f06e597b..dae464e2 100644 --- a/imgui/CMakeLists.txt +++ b/imgui/CMakeLists.txt @@ -77,7 +77,6 @@ target_sources(imgui_impl_dx11 PRIVATE ) target_link_libraries(imgui_impl_dx11 PUBLIC imgui - GeneratedShaderHeaders ) set_target_properties(imgui_impl_dx11 PROPERTIES FOLDER external) diff --git a/imgui/backend/imgui_impl_dx11.cpp b/imgui/backend/imgui_impl_dx11.cpp index 0103e9c8..72b57628 100644 --- a/imgui/backend/imgui_impl_dx11.cpp +++ b/imgui/backend/imgui_impl_dx11.cpp @@ -52,9 +52,8 @@ //#ifdef _MSC_VER //#pragma comment(lib, "d3dcompiler") // Automatically link with d3dcompiler.lib as we are using D3DCompile() below. //#endif -#include "imgui/backend/d3d11/vertex_shader.hpp" -#include "imgui/backend/d3d11/pixel_shader.hpp" -namespace hlsl = imgui::backend::d3d11; +#include "shader/vertex_shader.h" +#include "shader/pixel_shader.h" // Clang/GCC warnings with -Weverything #if defined(__clang__) @@ -475,7 +474,7 @@ bool ImGui_ImplDX11_CreateDeviceObjects() //ID3DBlob* vertexShaderBlob; //if (FAILED(D3DCompile(vertexShader, strlen(vertexShader), nullptr, nullptr, nullptr, "main", "vs_4_0", 0, 0, &vertexShaderBlob, nullptr))) // return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! - if (FAILED(bd->pd3dDevice->CreateVertexShader(hlsl::vertex_shader, sizeof(hlsl::vertex_shader), nullptr, &bd->pVertexShader))) + if (FAILED(bd->pd3dDevice->CreateVertexShader(vertex_shader_blob, sizeof(vertex_shader_blob), nullptr, &bd->pVertexShader))) { //vertexShaderBlob->Release(); return false; @@ -488,7 +487,7 @@ bool ImGui_ImplDX11_CreateDeviceObjects() { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, (UINT)offsetof(ImDrawVert, uv), D3D11_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, (UINT)offsetof(ImDrawVert, col), D3D11_INPUT_PER_VERTEX_DATA, 0 }, }; - if (FAILED(bd->pd3dDevice->CreateInputLayout(local_layout, 3, hlsl::vertex_shader, sizeof(hlsl::vertex_shader), &bd->pInputLayout))) + if (FAILED(bd->pd3dDevice->CreateInputLayout(local_layout, 3, vertex_shader_blob, sizeof(vertex_shader_blob), &bd->pInputLayout))) { //vertexShaderBlob->Release(); return false; @@ -528,7 +527,7 @@ bool ImGui_ImplDX11_CreateDeviceObjects() //ID3DBlob* pixelShaderBlob; //if (FAILED(D3DCompile(pixelShader, strlen(pixelShader), nullptr, nullptr, nullptr, "main", "ps_4_0", 0, 0, &pixelShaderBlob, nullptr))) // return false; // NB: Pass ID3DBlob* pErrorBlob to D3DCompile() to get error showing in (const char*)pErrorBlob->GetBufferPointer(). Make sure to Release() the blob! - if (FAILED(bd->pd3dDevice->CreatePixelShader(hlsl::pixel_shader, sizeof(hlsl::pixel_shader), nullptr, &bd->pPixelShader))) + if (FAILED(bd->pd3dDevice->CreatePixelShader(pixel_shader_blob, sizeof(pixel_shader_blob), nullptr, &bd->pPixelShader))) { //pixelShaderBlob->Release(); return false; diff --git a/imgui/backend/shader/compile.bat b/imgui/backend/shader/compile.bat new file mode 100644 index 00000000..2e1106a4 --- /dev/null +++ b/imgui/backend/shader/compile.bat @@ -0,0 +1,2 @@ +fxc /nologo /T vs_4_0 /E main /O3 /Ges /Fh vertex_shader.h /Vn vertex_shader_blob vertex_shader.hlsl +fxc /nologo /T ps_4_0 /E main /O3 /Ges /Fh pixel_shader.h /Vn pixel_shader_blob pixel_shader.hlsl diff --git a/imgui/backend/shader/pixel_shader.h b/imgui/backend/shader/pixel_shader.h new file mode 100644 index 00000000..8e9866f7 --- /dev/null +++ b/imgui/backend/shader/pixel_shader.h @@ -0,0 +1,155 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// sampler0 sampler NA NA s0 1 +// texture0 texture float4 2d t0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float +// COLOR 0 xyzw 1 NONE float xyzw +// TEXCOORD 0 xy 2 NONE float xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_Target 0 xyzw 0 TARGET float xyzw +// +ps_4_0 +dcl_sampler s0, mode_default +dcl_resource_texture2d (float,float,float,float) t0 +dcl_input_ps linear v1.xyzw +dcl_input_ps linear v2.xy +dcl_output o0.xyzw +dcl_temps 1 +sample r0.xyzw, v2.xyxx, t0.xyzw, s0 +mul o0.xyzw, r0.xyzw, v1.xyzw +ret +// Approximately 3 instruction slots used +#endif + +const BYTE pixel_shader_blob[] = +{ + 68, 88, 66, 67, 150, 15, + 87, 30, 151, 248, 241, 233, + 57, 134, 48, 7, 155, 147, + 203, 1, 1, 0, 0, 0, + 148, 2, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 212, 0, 0, 0, 72, 1, + 0, 0, 124, 1, 0, 0, + 24, 2, 0, 0, 82, 68, + 69, 70, 152, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 255, 255, 0, 137, 0, 0, + 110, 0, 0, 0, 92, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 101, 0, 0, 0, 2, 0, + 0, 0, 5, 0, 0, 0, + 4, 0, 0, 0, 255, 255, + 255, 255, 0, 0, 0, 0, + 1, 0, 0, 0, 12, 0, + 0, 0, 115, 97, 109, 112, + 108, 101, 114, 48, 0, 116, + 101, 120, 116, 117, 114, 101, + 48, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 49, 48, 46, 49, 0, + 171, 171, 73, 83, 71, 78, + 108, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 92, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 15, 0, 0, + 98, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 83, 86, 95, 80, 79, 83, + 73, 84, 73, 79, 78, 0, + 67, 79, 76, 79, 82, 0, + 84, 69, 88, 67, 79, 79, + 82, 68, 0, 171, 79, 83, + 71, 78, 44, 0, 0, 0, + 1, 0, 0, 0, 8, 0, + 0, 0, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 15, 0, + 0, 0, 83, 86, 95, 84, + 97, 114, 103, 101, 116, 0, + 171, 171, 83, 72, 68, 82, + 148, 0, 0, 0, 64, 0, + 0, 0, 37, 0, 0, 0, + 90, 0, 0, 3, 0, 96, + 16, 0, 0, 0, 0, 0, + 88, 24, 0, 4, 0, 112, + 16, 0, 0, 0, 0, 0, + 85, 85, 0, 0, 98, 16, + 0, 3, 242, 16, 16, 0, + 1, 0, 0, 0, 98, 16, + 0, 3, 50, 16, 16, 0, + 2, 0, 0, 0, 101, 0, + 0, 3, 242, 32, 16, 0, + 0, 0, 0, 0, 104, 0, + 0, 2, 1, 0, 0, 0, + 69, 0, 0, 9, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 16, 16, 0, 2, 0, + 0, 0, 70, 126, 16, 0, + 0, 0, 0, 0, 0, 96, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 242, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 30, 16, 0, + 1, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/LuaSTG/Shader/imgui/backend/d3d11/pixel_shader.hlsl b/imgui/backend/shader/pixel_shader.hlsl similarity index 100% rename from LuaSTG/Shader/imgui/backend/d3d11/pixel_shader.hlsl rename to imgui/backend/shader/pixel_shader.hlsl index 94bbfbfb..56103382 100644 --- a/LuaSTG/Shader/imgui/backend/d3d11/pixel_shader.hlsl +++ b/imgui/backend/shader/pixel_shader.hlsl @@ -1,6 +1,3 @@ -SamplerState sampler0; -Texture2D texture0; - struct PS_INPUT { float4 pos : SV_POSITION; @@ -8,6 +5,9 @@ struct PS_INPUT float2 uv : TEXCOORD0; }; +SamplerState sampler0; +Texture2D texture0; + float4 main(PS_INPUT input) : SV_Target { float4 out_col = input.col * texture0.Sample(sampler0, input.uv); diff --git a/imgui/backend/shader/vertex_shader.h b/imgui/backend/shader/vertex_shader.h new file mode 100644 index 00000000..d02ba4f8 --- /dev/null +++ b/imgui/backend/shader/vertex_shader.h @@ -0,0 +1,207 @@ +#if 0 +// +// Generated by Microsoft (R) HLSL Shader Compiler 10.1 +// +// +// Buffer Definitions: +// +// cbuffer vertexBuffer +// { +// +// float4x4 ProjectionMatrix; // Offset: 0 Size: 64 +// +// } +// +// +// Resource Bindings: +// +// Name Type Format Dim HLSL Bind Count +// ------------------------------ ---------- ------- ----------- -------------- ------ +// vertexBuffer cbuffer NA NA cb0 1 +// +// +// +// Input signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// POSITION 0 xy 0 NONE float xy +// COLOR 0 xyzw 1 NONE float xyzw +// TEXCOORD 0 xy 2 NONE float xy +// +// +// Output signature: +// +// Name Index Mask Register SysValue Format Used +// -------------------- ----- ------ -------- -------- ------- ------ +// SV_POSITION 0 xyzw 0 POS float xyzw +// COLOR 0 xyzw 1 NONE float xyzw +// TEXCOORD 0 xy 2 NONE float xy +// +vs_4_0 +dcl_constantbuffer CB0[4], immediateIndexed +dcl_input v0.xy +dcl_input v1.xyzw +dcl_input v2.xy +dcl_output_siv o0.xyzw, position +dcl_output o1.xyzw +dcl_output o2.xy +dcl_temps 1 +mul r0.xyzw, v0.yyyy, cb0[1].xyzw +mad r0.xyzw, cb0[0].xyzw, v0.xxxx, r0.xyzw +add o0.xyzw, r0.xyzw, cb0[3].xyzw +mov o1.xyzw, v1.xyzw +mov o2.xy, v2.xyxx +ret +// Approximately 6 instruction slots used +#endif + +const BYTE vertex_shader_blob[] = +{ + 68, 88, 66, 67, 47, 9, + 96, 12, 185, 76, 61, 196, + 112, 150, 210, 53, 19, 102, + 109, 156, 1, 0, 0, 0, + 108, 3, 0, 0, 5, 0, + 0, 0, 52, 0, 0, 0, + 4, 1, 0, 0, 116, 1, + 0, 0, 232, 1, 0, 0, + 240, 2, 0, 0, 82, 68, + 69, 70, 200, 0, 0, 0, + 1, 0, 0, 0, 76, 0, + 0, 0, 1, 0, 0, 0, + 28, 0, 0, 0, 0, 4, + 254, 255, 0, 137, 0, 0, + 160, 0, 0, 0, 60, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, + 118, 101, 114, 116, 101, 120, + 66, 117, 102, 102, 101, 114, + 0, 171, 171, 171, 60, 0, + 0, 0, 1, 0, 0, 0, + 100, 0, 0, 0, 64, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 124, 0, + 0, 0, 0, 0, 0, 0, + 64, 0, 0, 0, 2, 0, + 0, 0, 144, 0, 0, 0, + 0, 0, 0, 0, 80, 114, + 111, 106, 101, 99, 116, 105, + 111, 110, 77, 97, 116, 114, + 105, 120, 0, 171, 171, 171, + 3, 0, 3, 0, 4, 0, + 4, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 77, 105, + 99, 114, 111, 115, 111, 102, + 116, 32, 40, 82, 41, 32, + 72, 76, 83, 76, 32, 83, + 104, 97, 100, 101, 114, 32, + 67, 111, 109, 112, 105, 108, + 101, 114, 32, 49, 48, 46, + 49, 0, 73, 83, 71, 78, + 104, 0, 0, 0, 3, 0, + 0, 0, 8, 0, 0, 0, + 80, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 3, 3, 0, 0, + 89, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 1, 0, + 0, 0, 15, 15, 0, 0, + 95, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 2, 0, + 0, 0, 3, 3, 0, 0, + 80, 79, 83, 73, 84, 73, + 79, 78, 0, 67, 79, 76, + 79, 82, 0, 84, 69, 88, + 67, 79, 79, 82, 68, 0, + 79, 83, 71, 78, 108, 0, + 0, 0, 3, 0, 0, 0, + 8, 0, 0, 0, 80, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 92, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 15, 0, 0, 0, 98, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 3, 12, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, + 73, 79, 78, 0, 67, 79, + 76, 79, 82, 0, 84, 69, + 88, 67, 79, 79, 82, 68, + 0, 171, 83, 72, 68, 82, + 0, 1, 0, 0, 64, 0, + 1, 0, 64, 0, 0, 0, + 89, 0, 0, 4, 70, 142, + 32, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 0, 0, 0, 0, 95, 0, + 0, 3, 242, 16, 16, 0, + 1, 0, 0, 0, 95, 0, + 0, 3, 50, 16, 16, 0, + 2, 0, 0, 0, 103, 0, + 0, 4, 242, 32, 16, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 101, 0, 0, 3, + 242, 32, 16, 0, 1, 0, + 0, 0, 101, 0, 0, 3, + 50, 32, 16, 0, 2, 0, + 0, 0, 104, 0, 0, 2, + 1, 0, 0, 0, 56, 0, + 0, 8, 242, 0, 16, 0, + 0, 0, 0, 0, 86, 21, + 16, 0, 0, 0, 0, 0, + 70, 142, 32, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 50, 0, 0, 10, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 142, 32, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 6, 16, 16, 0, 0, 0, + 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 0, 0, + 0, 8, 242, 32, 16, 0, + 0, 0, 0, 0, 70, 14, + 16, 0, 0, 0, 0, 0, + 70, 142, 32, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 54, 0, 0, 5, 242, 32, + 16, 0, 1, 0, 0, 0, + 70, 30, 16, 0, 1, 0, + 0, 0, 54, 0, 0, 5, + 50, 32, 16, 0, 2, 0, + 0, 0, 70, 16, 16, 0, + 2, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 6, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 6, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 2, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0 +}; diff --git a/LuaSTG/Shader/imgui/backend/d3d11/vertex_shader.hlsl b/imgui/backend/shader/vertex_shader.hlsl similarity index 85% rename from LuaSTG/Shader/imgui/backend/d3d11/vertex_shader.hlsl rename to imgui/backend/shader/vertex_shader.hlsl index 1b9b0589..4336ce4c 100644 --- a/LuaSTG/Shader/imgui/backend/d3d11/vertex_shader.hlsl +++ b/imgui/backend/shader/vertex_shader.hlsl @@ -1,6 +1,6 @@ -cbuffer vertexBuffer : register(b0) +cbuffer vertexBuffer : register(b0) { - float4x4 ProjectionMatrix; + float4x4 ProjectionMatrix; }; struct VS_INPUT