コード例 #1
0
        public H1StaticMeshData(H1ModelContext context)
        {
            // looping the mesh context in H1ModelContext
            foreach (H1MeshContext meshContext in context.Meshes)
            {
                // @TODO - need to change this after applying quad splitting
                if (meshContext.Indices.Count == 0)
                {
                    continue;
                }

                H1StaticMeshLODResource meshLOD = new H1StaticMeshLODResource(meshContext);
                m_LODResources.Add(meshLOD);
            }
        }
コード例 #2
0
        private void PopulateCommandLists()
        {
            m_CommandList.CommandAllocator.Reset();
            //m_DeviceContext.MainCommandListPool

            m_CommandList.CommandList.Reset(m_CommandList.CommandAllocator, m_PipelineState);

            // set viewport and sissors
            m_CommandList.CommandList.SetGraphicsRootSignature(m_RootSignature);

            // @TODO - redesign this section
            m_TransformationCBPointer = m_ConstantBuffer.Map(0);
            //Utilities.Write(m_TransformationCBPointer, ref m_TransformationCB);
            List <Matrix> dataToCopy = new List <Matrix>();

            dataToCopy.Add(m_TransformationCB.viewProjectionMatrix);
            foreach (Matrix mtx in m_TransformationCB.BoneMatrices)
            {
                dataToCopy.Add(mtx);
            }
            Utilities.Write(m_TransformationCBPointer, dataToCopy.ToArray(), 0, 101);
            m_ConstantBuffer.Unmap(0);

            m_CommandList.CommandList.SetDescriptorHeaps(1, new DescriptorHeap[] { m_ConstantBufferViewHeap });
            //m_CommandList.SetDescriptorHeaps(2, new DescriptorHeap[] { m_ConstantBufferViewHeap, m_srvDescriptorHeap });

            GpuDescriptorHandle hDescriptor = m_ConstantBufferViewHeap.GPUDescriptorHandleForHeapStart;

            m_CommandList.CommandList.SetGraphicsRootDescriptorTable(0, hDescriptor);

            hDescriptor += m_ConstantBufferDescriptorSize;
            //Int32 sizeInBytes = (Utilities.SizeOf<TransformationCB>() + 255) & ~255;
            //hDescriptor += sizeInBytes;

            m_CommandList.CommandList.SetGraphicsRootDescriptorTable(1, hDescriptor);

            m_CommandList.CommandList.SetViewport(m_Viewport);
            m_CommandList.CommandList.SetScissorRectangles(m_SissorRect);

            // use barrier to notify we are using the m_RenderTarget
            Resource rtvBackBuffer = m_SwapChainDX12.GetBackBuffer(m_FrameIndex);

            m_CommandList.CommandList.ResourceBarrierTransition(rtvBackBuffer, ResourceStates.Present, ResourceStates.RenderTarget);

            //CpuDescriptorHandle rtvHandle = m_RenderTargetViewHeap.CPUDescriptorHandleForHeapStart;
            //rtvHandle += m_FrameIndex * m_RTVDescriptorSize;
            //CpuDescriptorHandle dsvHandle = m_DepthStencilViewHeap.CPUDescriptorHandleForHeapStart;

            CpuDescriptorHandle rtvHandle = m_DeviceContext.Dx12Device.RenderTargetDescriptorCache.GetCpuAddressByOffset(m_FrameIndex);
            // @TODO - need to set the depth value consistent with frame counts!
            CpuDescriptorHandle dsvHandle = m_DeviceContext.Dx12Device.DepthStencilDescriptorCache.GetCpuAddressByOffset(0);

            m_CommandList.CommandList.SetRenderTargets(rtvHandle, dsvHandle);

            // clear the render target & depth stencil
            m_CommandList.CommandList.ClearRenderTargetView(rtvHandle, new Color4(0, 0.2f, 0.4f, 1), 0, null);
            m_CommandList.CommandList.ClearDepthStencilView(dsvHandle, ClearFlags.FlagsDepth, 1.0f, 0, 0, null);

            // record commands
            m_CommandList.CommandList.PrimitiveTopology = SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            //m_CommandList.SetVertexBuffer(0, m_VertexBufferView);
            // @TODO - I need to wrap command list separately!
            //H1StaticMeshLODResource resource = m_TempStaticMesh.StaticMeshData.GetLODResource(0);
            H1StaticMeshLODResource resource = H1Global <H1World> .Instance.PersistentLevel.GetActor(0).GetActorComponent <H1StaticMeshComponent>().StaticMesh.StaticMeshData.GetLODResource(1);

            resource.LocalVertexFactory.setVertexBuffers(m_CommandList.CommandList);

            //m_CommandList.DrawInstanced(3, 1, 0, 0);
            //m_CommandList.SetIndexBuffer(m_IndexBufferView);

            SharpDX.Direct3D12.IndexBufferView rawIBV = ((Gen2Layer.H1IndexBufferView)resource.IndexBuffer.View).View;
            m_CommandList.CommandList.SetIndexBuffer(rawIBV);

            int instanceCount = Convert.ToInt32(resource.IndexBuffer.Count);

            m_CommandList.CommandList.DrawIndexedInstanced(instanceCount, 1, 0, 0, 0);

            // use barrier to notify that we are going to present the render target
            m_CommandList.CommandList.ResourceBarrierTransition(rtvBackBuffer, ResourceStates.RenderTarget, ResourceStates.Present);

            // execute the command
            m_CommandList.CommandList.Close();
        }