// 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 #include #include using namespace Microsoft::WRL; #pragma comment(lib, "d3d12.lib") #pragma comment(lib, "dxgi.lib") #pragma comment(lib, "d3d11.lib") #include "DirectXTex.h" inline void ThrowIfFailedImg(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 D3D12RenderImage { public: D3D12RenderImage(IDXGIAdapter* pAdapter, const wchar_t* image_filename); 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); std::vector GenerateTextureData(); void ShowNewTexture(const wchar_t* image_filename); 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(); void UpdateImageTexture(ComPtr& textureUploadHeap); void WaitForPreviousFrame(); private: struct XMFLOAT3 { float x; float y; float z; }; struct XMFLOAT2 { float u; float v; }; struct Vertex { XMFLOAT3 position; XMFLOAT2 texture_coord; }; static const UINT MAX_RENDER_TARGETS = 4; private: static const UINT TextureWidth = 256; static const UINT TextureHeight = 256; static const UINT TexturePixelSize = 4; // The number of bytes used to represent a pixel in the texture. std::wstring m_filename; // save the path of the image file to load 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_srvHeap; 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_texture; ComPtr m_commandAllocator; ComPtr m_commandQueue; ComPtr m_commandList; ComPtr m_fence; UINT64 m_fenceValue = 0; HANDLE m_fenceEvent = nullptr; std::atomic_bool update_texture; };