public void Create(IMgCommandBuffer setupCmdBuffer, IMgSwapchainCollection swapchainCollection, MgGraphicsDeviceCreateInfo createInfo) { if (createInfo == null) { throw new ArgumentNullException(nameof(createInfo)); } if (setupCmdBuffer == null) { throw new ArgumentNullException(nameof(setupCmdBuffer)); } if (swapchainCollection == null) { throw new ArgumentNullException(nameof(swapchainCollection)); } ReleaseUnmanagedResources(); mDeviceCreated = false; SetupContext(createInfo); SetupRenderpass(createInfo); // MANDATORY swapchainCollection.Create(setupCmdBuffer, createInfo.Width, createInfo.Height); SetupSwapchain(swapchainCollection, createInfo); mFramebuffers.Create(swapchainCollection, mRenderpass, mView, createInfo.Width, createInfo.Height); Scissor = new MgRect2D { Extent = new MgExtent2D { Width = createInfo.Width, Height = createInfo.Height }, Offset = new MgOffset2D { X = 0, Y = 0 }, }; // initialize viewport CurrentViewport = new MgViewport { Width = createInfo.Width, Height = createInfo.Height, X = 0, Y = 0, MinDepth = 0f, MaxDepth = 1f, }; mDeviceCreated = true; }
public void Create(IMgCommandBuffer setupCmdBuffer, IMgSwapchainCollection swapchainCollection, MgGraphicsDeviceCreateInfo dsCreateInfo) { if (dsCreateInfo == null) { throw new ArgumentNullException(nameof(dsCreateInfo)); } if (swapchainCollection == null) { throw new ArgumentNullException(nameof(swapchainCollection)); } mDeviceCreated = false; var colorFormat = AmtFormatExtensions.GetPixelFormat(dsCreateInfo.Color); var depthFormat = AmtFormatExtensions.GetPixelFormat(dsCreateInfo.DepthStencil); var sampleCount = AmtSampleCountFlagBitExtensions.TranslateSampleCount(dsCreateInfo.Samples); ReleaseUnmanagedResources(); mApplicationView.SampleCount = sampleCount; // FIXME : RUNTIME ISSUE WITH SETTING COLOR FORMAT; SHOULD "FIGURE" OUT APPROPRIATE COLOR FORMAT SOMEHOW mApplicationView.ColorPixelFormat = colorFormat; mApplicationView.DepthStencilPixelFormat = depthFormat; CreateDepthStencilImageView(); CreateRenderpass(dsCreateInfo); var bSwapchainCollection = (AmtSwapchainCollection)swapchainCollection; bSwapchainCollection.Format = dsCreateInfo.Color; bSwapchainCollection.Create(setupCmdBuffer, dsCreateInfo.Width, dsCreateInfo.Height); mFramebuffers.Create( swapchainCollection, mRenderpass, mDepthStencilView, dsCreateInfo.Width, dsCreateInfo.Height); Scissor = new MgRect2D { Extent = new MgExtent2D { Width = dsCreateInfo.Width, Height = dsCreateInfo.Height }, Offset = new MgOffset2D { X = 0, Y = 0 }, }; // initialise viewport CurrentViewport = new MgViewport { Width = dsCreateInfo.Width, Height = dsCreateInfo.Height, X = 0, Y = 0, MinDepth = 0f, MaxDepth = 1f, }; mDeviceCreated = true; }
void buildCommandBuffers() { var cmdBufInfo = new MgCommandBufferBeginInfo { }; var renderPassBeginInfo = new MgRenderPassBeginInfo { RenderPass = mManager.Graphics.Renderpass, RenderArea = new MgRect2D { Offset = new MgOffset2D { X = 0, Y = 0 }, Extent = new MgExtent2D { Width = mManager.Width, Height = mManager.Height }, }, ClearValues = new MgClearValue[] { MgClearValue.FromColorAndFormat(mManager.Swapchains.Format, new MgColor4f(0f, 0f, 0f, 0f)), new MgClearValue { DepthStencil = new MgClearDepthStencilValue(1024f, 0) } }, }; var cmdBufferCount = (uint)mManager.Graphics.Framebuffers.Length; drawCmdBuffers = new IMgCommandBuffer[cmdBufferCount]; var cmdBufAllocateInfo = new MgCommandBufferAllocateInfo { CommandBufferCount = cmdBufferCount, CommandPool = mManager.Configuration.Partition.CommandPool, Level = MgCommandBufferLevel.PRIMARY, }; var device = mManager.Configuration.Device; Debug.Assert(device != null); var err = device.AllocateCommandBuffers(cmdBufAllocateInfo, drawCmdBuffers); Debug.Assert(err == Result.SUCCESS); for (var i = 0; i < cmdBufferCount; ++i) { // Set target frame buffer renderPassBeginInfo.Framebuffer = mManager.Graphics.Framebuffers[i]; var cmdBuf = drawCmdBuffers[i]; err = cmdBuf.BeginCommandBuffer(cmdBufInfo); Debug.Assert(err == Result.SUCCESS); cmdBuf.CmdBeginRenderPass(renderPassBeginInfo, MgSubpassContents.INLINE); var viewport = new MgViewport { Width = mManager.Width, Height = mManager.Height, MinDepth = 0f, MaxDepth = 2f, }; cmdBuf.CmdSetViewport(0, new[] { viewport }); //var scissor = new MgRect2D { // Extent = new MgExtent2D // { // Height = mManager.Height, // Width = mManager.Width, // }, // Offset = new MgOffset2D // { // X = 0, // Y = 0, // } //}; cmdBuf.CmdSetScissor(0, new [] { mManager.Graphics.Scissor }); cmdBuf.CmdBindDescriptorSets(MgPipelineBindPoint.GRAPHICS, mPipelineLayout, 0, 1, mDescriptorSets, null); cmdBuf.CmdBindPipeline(MgPipelineBindPoint.GRAPHICS, mSolidPipeline); cmdBuf.CmdBindVertexBuffers(0, new[] { vertexBuffer.InternalBuffer }, new[] { 0UL }); cmdBuf.CmdBindIndexBuffer(indexBuffer.InternalBuffer, 0, MgIndexType.UINT32); cmdBuf.CmdDrawIndexed(indexCount, 1, 0, 0, 0); cmdBuf.CmdEndRenderPass(); err = cmdBuf.EndCommandBuffer(); Debug.Assert(err == Result.SUCCESS); } }