// Copyright (c) 2015, NVIDIA CORPORATION. All rights reserved. // // NVIDIA CORPORATION and its licensors retain all intellectual property // and proprietary rights in and to this software, related documentation // and any modifications thereto. Any use, reproduction, disclosure or // distribution of this software and related documentation without an express // license agreement from NVIDIA CORPORATION is strictly prohibited. // Modified 2024 Bigscreen, Inc // Changed from single, central triangle to 4 colored squares per eye #pragma once #include #include #include #include #include using namespace Microsoft::WRL; #pragma comment(lib, "d3d12.lib") #pragma comment(lib, "dxgi.lib") #pragma comment(lib, "d3d11.lib") inline void ThrowIfFailedVs(HRESULT hr, const char* function, int line) { if (FAILED(hr)) { std::cerr << "Failure result " << hr << " in function " << function << " at line " << line << std::endl; throw; } } class D3D12RenderVs { public: D3D12RenderVs(IDXGIAdapter* pAdapter); void Init(UINT numSharedHandles, HANDLE* pSharedHandles, DXGI_FORMAT dxgiFormat); void SetClearColor(float red, float green, float blue); void Render(); void ResetCommandList(); bool WriteRenderTargetToBMP(const char* path); ComPtr GetDevice() const { return m_device; } UINT GetRenderedFrameIndex() const { return m_renderedFrameIndex; } ComPtr GetCommandList() const { return m_commandList; } ComPtr GetCommandQueue() const { return m_commandQueue; } private: void OpenRenderTargets(UINT numSharedHandles, HANDLE* pSharedHandles, DXGI_FORMAT dxgiFormat); void LoadPipeline(); private: struct XMFLOAT3 { float x; float y; float z; }; struct Vertex { XMFLOAT3 position; }; static const UINT MAX_RENDER_TARGETS = 4; private: bool use_static_color = false; FLOAT m_clearcolor[4]; UINT m_frameIndex = 1; UINT m_renderedFrameIndex = 0; ComPtr m_device; UINT m_numRenderTargets = 0; DXGI_FORMAT m_renderTargetFormat = DXGI_FORMAT_UNKNOWN; ComPtr m_rtvDescriptorHeap; ComPtr m_renderTargets[MAX_RENDER_TARGETS]; D3D12_VIEWPORT m_viewport; D3D12_RECT m_scissorRect; ComPtr m_rootSignature; ComPtr m_pipelineState; ComPtr m_vertexBuffer; D3D12_VERTEX_BUFFER_VIEW m_vertexBufferView; ComPtr m_commandAllocator; ComPtr m_commandQueue; ComPtr m_commandList; ComPtr m_fence; UINT64 m_fenceValue = 0; HANDLE m_fenceEvent = nullptr; };