// Copyright (C) 2023 Jérôme "Lynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Graphics module" // For conditions of distribution and use, see copyright notice in Config.hpp #include #include #include #include #include #include #include #include #include namespace Nz { ViewerInstance::ViewerInstance() : m_invProjectionMatrix(Matrix4f::Identity()), m_invViewProjMatrix(Matrix4f::Identity()), m_invViewMatrix(Matrix4f::Identity()), m_projectionMatrix(Matrix4f::Identity()), m_viewProjMatrix(Matrix4f::Identity()), m_viewMatrix(Matrix4f::Identity()), m_targetSize(Vector2f::Zero()), m_eyePosition(Vector3f::Zero()), m_dataInvalidated(true), m_farPlane(-1.f), m_nearPlane(-1.f) { m_viewerDataBuffer = Graphics::Instance()->GetRenderDevice()->InstantiateBuffer(BufferType::Uniform, PredefinedViewerOffsets.totalSize, BufferUsage::DeviceLocal | BufferUsage::Dynamic | BufferUsage::Write); m_viewerDataBuffer->UpdateDebugName("Viewer data"); } void ViewerInstance::OnTransfer(RenderFrame& renderFrame, CommandBufferBuilder& builder) { if (!m_dataInvalidated) return; constexpr auto& viewerDataOffsets = PredefinedViewerOffsets; auto& allocation = renderFrame.GetUploadPool().Allocate(viewerDataOffsets.totalSize); AccessByOffset(allocation.mappedPtr, viewerDataOffsets.eyePositionOffset) = m_eyePosition; AccessByOffset(allocation.mappedPtr, viewerDataOffsets.invTargetSizeOffset) = 1.f / m_targetSize; AccessByOffset(allocation.mappedPtr, viewerDataOffsets.targetSizeOffset) = m_targetSize; AccessByOffset(allocation.mappedPtr, viewerDataOffsets.invProjMatrixOffset) = m_invProjectionMatrix; AccessByOffset(allocation.mappedPtr, viewerDataOffsets.invViewMatrixOffset) = m_invViewMatrix; AccessByOffset(allocation.mappedPtr, viewerDataOffsets.invViewProjMatrixOffset) = m_invViewProjMatrix; AccessByOffset(allocation.mappedPtr, viewerDataOffsets.projMatrixOffset) = m_projectionMatrix; AccessByOffset(allocation.mappedPtr, viewerDataOffsets.viewProjMatrixOffset) = m_viewProjMatrix; AccessByOffset(allocation.mappedPtr, viewerDataOffsets.viewMatrixOffset) = m_viewMatrix; AccessByOffset(allocation.mappedPtr, viewerDataOffsets.nearPlaneOffset) = m_nearPlane; AccessByOffset(allocation.mappedPtr, viewerDataOffsets.farPlaneOffset) = m_farPlane; builder.CopyBuffer(allocation, m_viewerDataBuffer.get()); m_dataInvalidated = false; } }