public TextureExample(MgGraphicsConfigurationManager manager) { mManager = manager; mZoom = -2.5f; //rotation = { 0.0f, 15.0f, 0.0f }; //title = "Vulkan Example - Texturing"; //enableTextOverlay = true; var createInfo = new MgGraphicsDeviceCreateInfo { Samples = MgSampleCountFlagBits.COUNT_1_BIT, Color = MgFormat.R8G8B8A8_UINT, DepthStencil = MgFormat.X8_D24_UNORM_PACK32, Width = 1280, Height = 720, }; mManager.Initialize(createInfo); mManager.Configuration.Partition.PhysicalDevice.GetPhysicalDeviceProperties(out mPhysicalDeviceProperties); mManager.Configuration.Partition.PhysicalDevice.GetPhysicalDeviceFeatures(out mFeatures); prepare(); }
public void Initialize(MgGraphicsDeviceCreateInfo createInfo) { mWidth = createInfo.Width; mHeight = createInfo.Height; mConfiguration.Initialize(mWidth, mHeight); SetupGraphicsDevice(createInfo); }
// public void CreateDevice (IGraphicsAdapter adapter, GraphicsProfile graphicsProfile) // { // // } void SetupContext(MgGraphicsDeviceCreateInfo createInfo) { //GraphicsMode mode; //var wnd = mWindow.WindowInfo; //// Create an OpenGL compatibility context //var flags = GraphicsContextFlags.Default; //int major = 1; //int minor = 0; //if (Context == null || Context.IsDisposed) //{ // var color = GetColorFormat (createInfo.Color); // var depthBit = GetDepthBit (createInfo.DepthStencil); // var stencilBit = GetStencilBit (createInfo.DepthStencil); // var samples = (int)createInfo.Samples; // if (samples == 0) // { // // Use a default of 4x samples if PreferMultiSampling is enabled // // without explicitly setting the desired MultiSampleCount. // samples = 4; // } // mode = new GraphicsMode (color, depthBit, stencilBit, samples); // try // { // Context = new GraphicsContext (mode, wnd, major, minor, flags); // } // catch (Exception e) // { // mLogger.Log (string.Format ("Failed to create OpenGL context, retrying. Error: {0}", e)); // major = 1; // minor = 0; // flags = GraphicsContextFlags.Default; // Context = new GraphicsContext (mode, wnd, major, minor, flags); // } //} //Context.MakeCurrent (wnd); //(Context as IGraphicsContextInternal).LoadAll (); ////Context.SwapInterval = mDeviceQuery.GetSwapInterval (mPresentation.PresentationInterval); //// TODO : background threading //// Provide the graphics context for background loading //// Note: this context should use the same GraphicsMode, //// major, minor version and flags parameters as the main //// context. Otherwise, context sharing will very likely fail. //// if (Threading.BackgroundContext == null) //// { //// Threading.BackgroundContext = new GraphicsContext(mode, wnd, major, minor, flags); //// Threading.WindowInfo = wnd; //// Threading.BackgroundContext.MakeCurrent(null); //// } //Context.MakeCurrent (wnd); mBBContext.SetupContext(mWindow.WindowInfo, createInfo); mExtensions.Initialize(); //mCapabilities.Initialize (); //mGLPlatform.Initialize (); mSelector.Initialize(); mQueueRenderer.Initialize(); }
public void Initialize(MgGraphicsDeviceCreateInfo createInfo) { mWidth = createInfo.Width; mHeight = createInfo.Height; mConfiguration.Initialize(mWidth, mHeight); Debug.Assert(mConfiguration.Partition != null); const int NO_OF_BUFFERS = 1; var buffers = new IMgCommandBuffer[NO_OF_BUFFERS]; var pAllocateInfo = new MgCommandBufferAllocateInfo { CommandBufferCount = NO_OF_BUFFERS, CommandPool = mConfiguration.Partition.CommandPool, Level = MgCommandBufferLevel.PRIMARY, }; mConfiguration.Device.AllocateCommandBuffers(pAllocateInfo, buffers); var setupCmdBuffer = buffers[0]; var cmdBufInfo = new MgCommandBufferBeginInfo { }; var err = setupCmdBuffer.BeginCommandBuffer(cmdBufInfo); Debug.Assert(err == Result.SUCCESS); mGraphicsDevice.Create(setupCmdBuffer, mSwapchains, createInfo); err = setupCmdBuffer.EndCommandBuffer(); Debug.Assert(err == Result.SUCCESS); var submission = new[] { new MgSubmitInfo { CommandBuffers = new IMgCommandBuffer[] { buffers[0], }, } }; err = mConfiguration.Queue.QueueSubmit(submission, null); Debug.Assert(err == Result.SUCCESS); mConfiguration.Queue.QueueWaitIdle(); mConfiguration.Device.FreeCommandBuffers(mConfiguration.Partition.CommandPool, buffers); }
private void InitSwapchain(uint width, uint height) { Debug.Assert(mConfiguration.Partition != null); const int NO_OF_BUFFERS = 1; var buffers = new IMgCommandBuffer[NO_OF_BUFFERS]; var pAllocateInfo = new MgCommandBufferAllocateInfo { CommandBufferCount = NO_OF_BUFFERS, CommandPool = mConfiguration.Partition.CommandPool, Level = MgCommandBufferLevel.PRIMARY, }; mConfiguration.Device.AllocateCommandBuffers(pAllocateInfo, buffers); var createInfo = new MgGraphicsDeviceCreateInfo { Samples = MgSampleCountFlagBits.COUNT_1_BIT, Color = MgFormat.R8G8B8A8_UINT, DepthStencil = MgFormat.D24_UNORM_S8_UINT, Width = mWidth, Height = mHeight, }; var setupCmdBuffer = buffers[0]; var cmdBufInfo = new MgCommandBufferBeginInfo(); var err = setupCmdBuffer.BeginCommandBuffer(cmdBufInfo); Debug.Assert(err == Result.SUCCESS); mGraphicsDevice.Create(setupCmdBuffer, mSwapchains, createInfo); err = setupCmdBuffer.EndCommandBuffer(); Debug.Assert(err == Result.SUCCESS); var submission = new[] { new MgSubmitInfo { CommandBuffers = new IMgCommandBuffer[] { buffers[0], }, } }; err = mConfiguration.Queue.QueueSubmit(submission, null); Debug.Assert(err == Result.SUCCESS); mConfiguration.Queue.QueueWaitIdle(); mConfiguration.Device.FreeCommandBuffers(mConfiguration.Partition.CommandPool, buffers); }
public void SetupContext(IWindowInfo wnd, MgGraphicsDeviceCreateInfo createInfo) { if (Context != null) { Context.Dispose(); } GraphicsMode mode; // Create an OpenGL compatibility context var flags = GraphicsContextFlags.Default; int major = 1; int minor = 0; if (Context == null || Context.IsDisposed) { var color = GetColorFormat(createInfo.Color); var depthBit = GetDepthBit(createInfo.DepthStencil); var stencilBit = GetStencilBit(createInfo.DepthStencil); var samples = (int)createInfo.Samples; if (samples == 0) { // Use a default of 4x samples if PreferMultiSampling is enabled // without explicitly setting the desired MultiSampleCount. samples = 4; } mode = new GraphicsMode(color, depthBit, stencilBit, samples); try { Context = new GraphicsContext(mode, wnd, major, minor, flags); } catch (Exception e) { mLogger.Log(string.Format("Failed to create OpenGL context, retrying. Error: {0}", e)); major = 1; minor = 0; flags = GraphicsContextFlags.Default; Context = new GraphicsContext(mode, wnd, major, minor, flags); } } Context.MakeCurrent(wnd); (Context as IGraphicsContextInternal).LoadAll(); //Context.SwapInterval = mDeviceQuery.GetSwapInterval (mPresentation.PresentationInterval); // TODO : background threading // Provide the graphics context for background loading // Note: this context should use the same GraphicsMode, // major, minor version and flags parameters as the main // context. Otherwise, context sharing will very likely fail. // if (Threading.BackgroundContext == null) // { // Threading.BackgroundContext = new GraphicsContext(mode, wnd, major, minor, flags); // Threading.WindowInfo = wnd; // Threading.BackgroundContext.MakeCurrent(null); // } Context.MakeCurrent(wnd); }
public void Initialize(MgGraphicsDeviceCreateInfo createInfo) { mWidth = createInfo.Width; mHeight = createInfo.Height; mConfiguration.Initialize(mWidth, mHeight); SetupGraphicsDevice(createInfo); SetupPresentationBarrierCommands(); SetupSemaphores(); }
void SetupGraphicsDevice() { try { var setupCommands = new IMgCommandBuffer[1]; var pAllocateInfo = new MgCommandBufferAllocateInfo { CommandPool = mConfiguration.Partition.CommandPool, CommandBufferCount = 1, Level = MgCommandBufferLevel.PRIMARY, }; var err = mConfiguration.Device.AllocateCommandBuffers(pAllocateInfo, setupCommands); Debug.Assert(err == Result.SUCCESS); var dsCreateInfo = new MgGraphicsDeviceCreateInfo { Color = MgFormat.B8G8R8A8_UNORM, DepthStencil = MgFormat.D32_SFLOAT_S8_UINT, Samples = MgSampleCountFlagBits.COUNT_1_BIT, Width = mWidth, Height = mHeight, }; var cmdBuf = setupCommands[0]; var cmdBufInfo = new MgCommandBufferBeginInfo { }; cmdBuf.BeginCommandBuffer(cmdBufInfo); mGraphicsDevice.Create(cmdBuf, mSwapchains, dsCreateInfo); cmdBuf.EndCommandBuffer(); var pSubmits = new MgSubmitInfo[] { new MgSubmitInfo { CommandBuffers = new IMgCommandBuffer[] { cmdBuf, }, } }; mConfiguration.Partition.Queue.QueueSubmit(pSubmits, null); mConfiguration.Partition.Queue.QueueWaitIdle(); mConfiguration.Partition.Device.FreeCommandBuffers( mConfiguration.Partition.CommandPool, setupCommands); } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } }
void SetupSwapchain(IMgSwapchainCollection swapchainCollection, MgGraphicsDeviceCreateInfo createInfo) { if (swapchainCollection.Swapchain == null) { throw new ArgumentNullException(nameof(swapchainCollection)); } var collection = (OpenTKSwapchainCollection)swapchainCollection; collection.Format = createInfo.Color; var sc = (IOpenTKSwapchainKHR)swapchainCollection.Swapchain; Debug.Assert(sc != null, nameof(swapchainCollection.Swapchain) + " is Not a IOpenTKSwapchainKHR type"); sc.Initialize((uint)swapchainCollection.Buffers.Length); }
void SetupRenderpass(MgGraphicsDeviceCreateInfo createInfo) { var attachmentDescriptions = new [] { new MgAttachmentDescription { Format = createInfo.Color, LoadOp = MgAttachmentLoadOp.CLEAR, StoreOp = MgAttachmentStoreOp.STORE, StencilLoadOp = MgAttachmentLoadOp.DONT_CARE, StencilStoreOp = MgAttachmentStoreOp.DONT_CARE, }, new MgAttachmentDescription { Format = createInfo.DepthStencil, LoadOp = MgAttachmentLoadOp.CLEAR, StoreOp = MgAttachmentStoreOp.STORE, StencilLoadOp = MgAttachmentLoadOp.CLEAR, StencilStoreOp = MgAttachmentStoreOp.STORE, }, }; mRenderpass = new GLRenderPass(attachmentDescriptions); }
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 CreateRenderpass(MgGraphicsDeviceCreateInfo createInfo) { bool isStencilFormat = AmtFormatExtensions.IsStencilFormat(createInfo.DepthStencil); var attachments = new[] { // Color attachment[0] new MgAttachmentDescription { Format = createInfo.Color, // TODO : multisampling Samples = createInfo.Samples, LoadOp = MgAttachmentLoadOp.CLEAR, StoreOp = MgAttachmentStoreOp.STORE, StencilLoadOp = MgAttachmentLoadOp.DONT_CARE, StencilStoreOp = MgAttachmentStoreOp.DONT_CARE, InitialLayout = MgImageLayout.COLOR_ATTACHMENT_OPTIMAL, FinalLayout = MgImageLayout.COLOR_ATTACHMENT_OPTIMAL, }, // Depth attachment[1] new MgAttachmentDescription { Format = createInfo.DepthStencil, // TODO : multisampling Samples = createInfo.Samples, LoadOp = MgAttachmentLoadOp.CLEAR, StoreOp = MgAttachmentStoreOp.STORE, // activate stencil if needed StencilLoadOp = isStencilFormat ? MgAttachmentLoadOp.CLEAR : MgAttachmentLoadOp.DONT_CARE, StencilStoreOp = isStencilFormat ? MgAttachmentStoreOp.STORE : MgAttachmentStoreOp.DONT_CARE, InitialLayout = MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, FinalLayout = MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, } }; var colorReference = new MgAttachmentReference { Attachment = 0, Layout = MgImageLayout.COLOR_ATTACHMENT_OPTIMAL, }; var depthReference = new MgAttachmentReference { Attachment = 1, Layout = MgImageLayout.DEPTH_STENCIL_ATTACHMENT_OPTIMAL, }; var subpass = new MgSubpassDescription { PipelineBindPoint = MgPipelineBindPoint.GRAPHICS, Flags = 0, InputAttachments = null, ColorAttachmentCount = 1, ColorAttachments = new[] { colorReference }, ResolveAttachments = null, DepthStencilAttachment = depthReference, PreserveAttachments = null, }; var renderPassInfo = new MgRenderPassCreateInfo { Attachments = attachments, Subpasses = new[] { subpass }, Dependencies = null, }; Result err; IMgRenderPass renderPass; err = mConfiguration.Device.CreateRenderPass(renderPassInfo, null, out renderPass); Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS"); mRenderpass = renderPass; }
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; }