Ejemplo n.º 1
0
        public void Create(IMgSwapchainCollection swapchains, IMgRenderPass pass, IMgImageView depthStencilView, uint width, uint height)
        {
            Debug.Assert(mGraphicsConfiguration.Partition != null);

            // Create frame buffers for every swap chain image
            var frameBuffers = new IMgFramebuffer[swapchains.Buffers.Length];

            for (uint i = 0; i < frameBuffers.Length; i++)
            {
                var frameBufferCreateInfo = new MgFramebufferCreateInfo
                {
                    RenderPass  = pass,
                    Attachments = new[]
                    {
                        swapchains.Buffers[i].View,
                        // Depth/Stencil attachment is the same for all frame buffers
                        depthStencilView,
                    },
                    Width  = width,
                    Height = height,
                    Layers = 1,
                };

                var err = mGraphicsConfiguration.Partition.Device.CreateFramebuffer(frameBufferCreateInfo, null, out frameBuffers[i]);
                Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS");
            }

            mFramebuffers = frameBuffers;
        }
Ejemplo n.º 2
0
        public VulkanExample
        (
            IMgGraphicsConfiguration configuration,
            IMgSwapchainCollection swapchains,
            IMgGraphicsDevice graphicsDevice,
            IMgPresentationLayer presentationLayer,
            ITriangleDemoShaderPath shaderPath
        )
        {
            mConfiguration     = configuration;
            mSwapchains        = swapchains;
            mGraphicsDevice    = graphicsDevice;
            mPresentationLayer = presentationLayer;
            mTrianglePath      = shaderPath;

            mWidth  = 1280U;
            mHeight = 720U;

            try
            {
                mConfiguration.Initialize(mWidth, mHeight);
                InitSwapchain(mWidth, mHeight);
                Prepare();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        void CreateFramebuffers(IMgSwapchainCollection swapchains, MgGraphicsDeviceCreateInfo createInfo)
        {
            //IMgFramebuffer[] SetupFrameBuffers(IMgRenderPass renderPass, IMgDepthStencilBuffer depthStencil, IMgSwapchainCollection swapChain, uint width, uint height)
            //{
            // Create frame buffers for every swap chain image
            var frameBuffers = new IMgFramebuffer[swapchains.Buffers.Length];

            for (uint i = 0; i < frameBuffers.Length; i++)
            {
                var frameBufferCreateInfo = new MgFramebufferCreateInfo
                {
                    RenderPass  = mRenderpass,
                    Attachments = new []
                    {
                        swapchains.Buffers[i].View,
                        // Depth/Stencil attachment is the same for all frame buffers
                        mView,
                    },
                    Width  = createInfo.Width,
                    Height = createInfo.Height,
                    Layers = 1,
                };

                var err = mPartition.Device.CreateFramebuffer(frameBufferCreateInfo, null, out frameBuffers[i]);
                Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS");
            }

            mFramebuffers = frameBuffers;
        }
Ejemplo n.º 4
0
        public void Create(IMgCommandBuffer setupCmdBuffer, IMgSwapchainCollection swapchainCollection, MgGraphicsDeviceCreateInfo createInfo)
        {
            if (setupCmdBuffer == null)
            {
                throw new ArgumentNullException(nameof(setupCmdBuffer));
            }

            if (createInfo == null)
            {
                throw new ArgumentNullException(nameof(createInfo));
            }

            if (swapchainCollection == null)
            {
                throw new ArgumentNullException(nameof(swapchainCollection));
            }

            Setup();

            // Check if device supports requested sample count for color and depth frame buffer
            if (
                (mProperties.Limits.FramebufferColorSampleCounts < createInfo.Samples) ||
                (mProperties.Limits.FramebufferDepthSampleCounts < createInfo.Samples))
            {
                throw new ArgumentOutOfRangeException("createInfo.Samples",
                                                      "MgDefaultDepthStencilBuffer : This physical device cannot fulfil the requested sample count for BOTH color and depth frame buffer");
            }

            ReleaseUnmanagedResources();
            mDeviceCreated = false;

            CreateDepthStencil(setupCmdBuffer, createInfo);
            CreateRenderpass(createInfo);
            swapchainCollection.Create(setupCmdBuffer, createInfo.Width, createInfo.Height);
            mFramebuffers.Create(swapchainCollection, mRenderpass, mDepthStencilImageView, 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;
        }
Ejemplo n.º 5
0
 public MgPresentationLayer
 (
     IMgGraphicsConfiguration graphicsConfiguration,
     IMgSwapchainCollection collection,
     IMgPresentationBarrierEntrypoint barrier
 )
 {
     mGraphicsConfiguration = graphicsConfiguration;
     mCollection            = collection;
     mBarrier = barrier;
 }
Ejemplo n.º 6
0
        public AmtPresentationLayer(MTKView view, IMgSwapchainCollection swapchainCollection)
        {
            mView = view;

            mLayers    = new AmtLayerInfo[1];
            mLayers[0] = new AmtLayerInfo
            {
                Inflight = new Semaphore(1, 1),
            };
            mCollection = swapchainCollection;
        }
Ejemplo n.º 7
0
 public MgGraphicsConfigurationManager(
     IMgGraphicsConfiguration configuration,
     IMgSwapchainCollection swapchains,
     IMgGraphicsDevice graphicsDevice,
     IMgPresentationLayer presentationLayer
     )
 {
     mConfiguration     = configuration;
     mSwapchains        = swapchains;
     mGraphicsDevice    = graphicsDevice;
     mPresentationLayer = presentationLayer;
 }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        public SpinningCube(
            IMgGraphicsConfiguration configuration,
            IMgSwapchainCollection swapchains,
            IMgGraphicsDevice graphicsDevice,
            IMgPresentationLayer presentationLayer
            )
        {
            mConfiguration     = configuration;
            mSwapchains        = swapchains;
            mGraphicsDevice    = graphicsDevice;
            mPresentationLayer = presentationLayer;

            mWidth  = 640;
            mHeight = 480;

            mConfiguration.Initialize(mWidth, mHeight);
            SetupGraphicsDevice();

            InitializeMesh();
            InitializeUniforms();
            InitializeRenderCommandBuffers();
            InitializeGraphicsPipeline();
        }
Ejemplo n.º 11
0
        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;
        }