diff --git a/src/Buffer.h b/src/Buffer.h index 03d777007..0cfb2332f 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -77,6 +77,20 @@ class ConstantBuffer D3D11_BUFFER_DESC desc; }; +template +D3D11_BUFFER_DESC StructuredBufferDesc(UINT a_count = 1) +{ + D3D11_BUFFER_DESC desc{}; + ZeroMemory(&desc, sizeof(desc)); + desc.Usage = D3D11_USAGE_DYNAMIC; + desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + desc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED; + desc.StructureByteStride = sizeof(T); + desc.ByteWidth = sizeof(T) * a_count; + return desc; +} + class StructuredBuffer { public: @@ -168,6 +182,40 @@ class Buffer winrt::com_ptr uav; }; +class Texture1D +{ +public: + Texture1D(D3D11_TEXTURE1D_DESC const& a_desc) + { + desc = a_desc; + auto device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + DX::ThrowIfFailed(device->CreateTexture1D(&desc, nullptr, resource.put())); + } + + void CreateSRV(D3D11_SHADER_RESOURCE_VIEW_DESC const& a_desc) + { + ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + DX::ThrowIfFailed(device->CreateShaderResourceView(resource.get(), &a_desc, srv.put())); + } + void CreateUAV(D3D11_UNORDERED_ACCESS_VIEW_DESC const& a_desc) + { + ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + DX::ThrowIfFailed(device->CreateUnorderedAccessView(resource.get(), &a_desc, uav.put())); + } + + void CreateRTV(D3D11_RENDER_TARGET_VIEW_DESC const& a_desc) + { + ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; + DX::ThrowIfFailed(device->CreateRenderTargetView(resource.get(), &a_desc, rtv.put())); + } + + D3D11_TEXTURE1D_DESC desc; + winrt::com_ptr resource; + winrt::com_ptr srv; + winrt::com_ptr uav; + winrt::com_ptr rtv; +}; + class Texture2D { public: @@ -178,6 +226,12 @@ class Texture2D DX::ThrowIfFailed(device->CreateTexture2D(&desc, nullptr, resource.put())); } + Texture2D(ID3D11Texture2D* a_resource) + { + a_resource->GetDesc(&desc); + resource.attach(a_resource); + } + void CreateSRV(D3D11_SHADER_RESOURCE_VIEW_DESC const& a_desc) { ID3D11Device* device = RE::BSGraphics::Renderer::GetSingleton()->GetRuntimeData().forwarder; diff --git a/src/Util.cpp b/src/Util.cpp index ff16648e8..12a472e7e 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -294,4 +294,40 @@ namespace Util ImGui::EndTooltip(); } } +} + +namespace nlohmann +{ + void to_json(json& j, const float2& v) + { + j = json{ v.x, v.y }; + } + + void from_json(const json& j, float2& v) + { + std::array temp = j; + v = { temp[0], temp[1] }; + } + + void to_json(json& j, const float3& v) + { + j = json{ v.x, v.y, v.z }; + } + + void from_json(const json& j, float3& v) + { + std::array temp = j; + v = { temp[0], temp[1], temp[2] }; + } + + void to_json(json& j, const float4& v) + { + j = json{ v.x, v.y, v.z, v.w }; + } + + void from_json(const json& j, float4& v) + { + std::array temp = j; + v = { temp[0], temp[1], temp[2], temp[3] }; + } } \ No newline at end of file diff --git a/src/Util.h b/src/Util.h index 3ce96896b..ab45133af 100644 --- a/src/Util.h +++ b/src/Util.h @@ -31,4 +31,35 @@ namespace Util ~HoverTooltipWrapper(); inline operator bool() { return hovered; } }; + + /** + * Usage: + * static FrameChecker frame_checker; + * if(frame_checker.isNewFrame()) + * ... + */ + class FrameChecker + { + private: + uint32_t last_frame = UINT32_MAX; + + public: + inline bool isNewFrame(uint32_t frame) + { + bool retval = last_frame != frame; + last_frame = frame; + return retval; + } + inline bool isNewFrame() { return isNewFrame(RE::BSGraphics::State::GetSingleton()->uiFrameCount); } + }; } + +namespace nlohmann +{ + void to_json(json& j, const float2& v); + void from_json(const json& j, float2& v); + void to_json(json& j, const float3& v); + void from_json(const json& j, float3& v); + void to_json(json& j, const float4& v); + void from_json(const json& j, float4& v); +}; \ No newline at end of file