Beispiel #1
0
        /// <summary>
        /// Initialize the graphic library.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            // - Create a Vulkan instance, this instance must be alive during all the game execution
            Library.Initialize(TargetSurface);

            // - Makes a new device manager
            PhysicalDevice.Initialize(TargetSurface);

            // - Initialize the physical device on this drawing area
            GraphicDevice.Initialize();

            // - Initialize index and vert manager
            VertexManager.Setup();
            IndexManager.Setup();

            // - Makes syncronization semaphores and fances CPU<->GPU
            for (int i = 0; i < MaxFrameInFlight; ++i)
            {
                CommandBuffers.Add(null);
                Commands.Add(GraphicDevice.Handle.CreateCommandPool(GraphicDevice.GraphicQueueIndex, CommandPoolCreateFlags.ResetCommandBuffer));
                ImageAvailableSemaphores.Add(GraphicDevice.Handle.CreateSemaphore());
                RenderFinishedSemaphores.Add(GraphicDevice.Handle.CreateSemaphore());
                InFlightFences.Add(GraphicDevice.Handle.CreateFence(FenceCreateFlags.Signaled));
            }
        }
        public bool AddDrawCommand(GlobalGeometryPartBlockNew part, Bucket sourceBucket, InstanceInfo instanceInfo)
        {
            var primitiveType =
                part.GlobalGeometryPartNewFlags.HasFlag(
                    GlobalGeometryPartBlockNew.Flags.OverrideTriangleList)
                    ? PrimitiveType.Triangles
                    : PrimitiveType.TriangleStrip;

            if (primitiveType != PrimitiveType)
            {
                return(false);
            }
            if (sourceBucket != SourceBucket)
            {
                return(false);
            }

            var locations = sourceBucket[part];
            var command   = new DrawIndirectCmd(
                part.StripLength,
                instanceInfo.Count,
                // Divide by two because this is an offset and we need an index
                locations.IndexBaseOffset / sizeof(ushort) + part.StripStartIndex,
                locations.VertexBaseOffset,
                instanceInfo.BaseInstance);

            CommandBuffers.Add(command);
            return(true);
        }
 /// <summary>
 /// Get the command buffer created for a registered image
 /// </summary>
 /// <param name="image"></param>
 /// <returns></returns>
 public CommandBuffer GetCommandBuffer(VKImage image)
 {
     // Check arguments
     if (image is null)
     {
         throw new ArgumentNullException(nameof(image));
     }
     if (CommandBuffers.TryGetValue(image, out var buffer))
     {
         return(buffer);
     }
     return(RegisterImage(image));
 }
 /// <summary>
 /// Unregister an image from the effect
 /// </summary>
 /// <param name="image"></param>
 public void UnregisterImage(VKImage image)
 {
     // Check arguments
     if (image is null)
     {
         throw new ArgumentNullException(nameof(image));
     }
     // Check if active
     if (!Active)
     {
         throw new InvalidOperationException("Effect is not active");
     }
     // Call OnUnregisterImage and unregister command buffer
     Graphics.Device.WaitIdle();
     OnUnregisterImage(image);
     CommandBuffers[image].Dispose();
     CommandBuffers.Remove(image);
 }
        /// <summary>
        /// Register an image for rendering to
        /// </summary>
        /// <param name="image"></param>
        public CommandBuffer RegisterImage(VKImage image)
        {
            // Check arguments
            if (image is null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            // Check if active
            if (!Active)
            {
                throw new InvalidOperationException("Effect is not active");
            }
            // Create new command buffer, register the image, and reord the command buffer
            var cmd = Graphics.GraphicsQueueFamily.CreateCommandBuffers(CommandBufferLevel.Primary, 1)[0];

            CommandBuffers.Add(image, cmd);
            OnRegisterImage(image);
            OnRecordCommandBuffer(image, cmd);
            return(cmd);
        }
 public void Clear( )
 {
     CommandBuffers.Clear(  );
 }