public override DeviceTexture2D CreateTexture(
            int mipLevels,
            int width,
            int height,
            PixelFormat format,
            DeviceTextureCreateOptions createOptions)
        {
            OpenTK.Graphics.OpenGL.PixelFormat pixelFormat = OpenGLFormats.MapPixelFormat(format);
            PixelInternalFormat pixelInternalFormat        = OpenGLFormats.MapPixelInternalFormat(format);

            if (createOptions == DeviceTextureCreateOptions.DepthStencil)
            {
                if (format != PixelFormat.R16_UInt)
                {
                    throw new NotImplementedException("R16_UInt is the only supported depth texture format.");
                }

                pixelFormat         = OpenTK.Graphics.OpenGL.PixelFormat.DepthComponent;
                pixelInternalFormat = PixelInternalFormat.DepthComponent16;
            }

            return(new OpenGLTexture2D(
                       mipLevels,
                       width,
                       height,
                       format,
                       pixelInternalFormat,
                       pixelFormat,
                       OpenGLFormats.MapPixelType(format)));
        }
Beispiel #2
0
 public override DeviceTexture2D CreateTexture(
     int mipLevels,
     int width,
     int height,
     PixelFormat format,
     DeviceTextureCreateOptions createOptions)
 {
     return(new VkTexture2D(
                _device,
                _physicalDevice,
                RenderContext.MemoryManager,
                RenderContext,
                mipLevels,
                width,
                height,
                format,
                createOptions));
 }
Beispiel #3
0
        public override DeviceTexture2D CreateTexture(
            int mipLevels,
            int width,
            int height,
            PixelFormat format,
            DeviceTextureCreateOptions createOptions)
        {
            int pixelSizeInBytes = FormatHelpers.GetPixelSizeInBytes(format);

            OpenTK.Graphics.ES30.PixelFormat pixelFormat = OpenGLESFormats.MapPixelFormat(format);

            if (createOptions == DeviceTextureCreateOptions.DepthStencil)
            {
                if (format != PixelFormat.R16_UInt && format != PixelFormat.R32_Float)
                {
                    throw new NotImplementedException("The only supported depth texture formats are R16_UInt and R32_Float.");
                }

                pixelFormat = OpenTK.Graphics.ES30.PixelFormat.DepthComponent;
            }

            return(new OpenGLESTexture2D(mipLevels, width, height, format, pixelFormat, OpenGLESFormats.MapPixelType(format)));
        }
Beispiel #4
0
 /// <summary>
 /// Creates a new 2D device texture with the given properties.
 /// </summary>
 /// <param name="mipLevels">The number of mipmap levels contained in the texture.</param>
 /// <param name="width">The width of the largest mipmap level.</param>
 /// <param name="height">The height of the largest mipmap level.</param>
 /// <param name="pixelSizeInBytes">The size of individual pixels, in bytes.</param>
 /// <param name="format">The pixel format of the texture.</param>
 /// <param name="createOptions">Specifies how the texture will be used.</param>
 /// <returns></returns>
 public abstract DeviceTexture2D CreateTexture(
     int mipLevels,
     int width,
     int height,
     PixelFormat format,
     DeviceTextureCreateOptions createOptions);
Beispiel #5
0
        public VkTexture2D(
            VkDevice device,
            VkPhysicalDevice physicalDevice,
            VkDeviceMemoryManager memoryManager,
            VkRenderContext rc,
            int mipLevels,
            int width,
            int height,
            PixelFormat veldridFormat,
            DeviceTextureCreateOptions createOptions)
        {
            _device         = device;
            _physicalDevice = physicalDevice;
            _memoryManager  = memoryManager;
            _rc             = rc;

            MipLevels      = mipLevels;
            _width         = width;
            _height        = height;
            _createOptions = createOptions;
            if (createOptions == DeviceTextureCreateOptions.DepthStencil)
            {
                Format = VkFormat.D16Unorm;
            }
            else
            {
                Format = VkFormats.VeldridToVkPixelFormat(veldridFormat);
            }

            _veldridFormat = veldridFormat;

            VkImageCreateInfo imageCI = VkImageCreateInfo.New();

            imageCI.mipLevels     = (uint)mipLevels;
            imageCI.arrayLayers   = 1;
            imageCI.imageType     = VkImageType.Image2D;
            imageCI.extent.width  = (uint)width;
            imageCI.extent.height = (uint)height;
            imageCI.extent.depth  = 1;
            imageCI.initialLayout = VkImageLayout.Preinitialized; // TODO: Use proper VkImageLayout values and transitions.
            imageCI.usage         = VkImageUsageFlags.TransferDst | VkImageUsageFlags.Sampled;
            if (createOptions == DeviceTextureCreateOptions.RenderTarget)
            {
                imageCI.usage |= VkImageUsageFlags.ColorAttachment;
            }
            else if (createOptions == DeviceTextureCreateOptions.DepthStencil)
            {
                imageCI.usage |= VkImageUsageFlags.DepthStencilAttachment;
            }
            imageCI.tiling = createOptions == DeviceTextureCreateOptions.DepthStencil ? VkImageTiling.Optimal : VkImageTiling.Optimal;
            imageCI.format = Format;

            imageCI.samples = VkSampleCountFlags.Count1;

            VkResult result = vkCreateImage(device, ref imageCI, null, out _image);

            CheckResult(result);

            vkGetImageMemoryRequirements(_device, _image, out VkMemoryRequirements memoryRequirements);

            VkMemoryBlock memoryToken = memoryManager.Allocate(
                FindMemoryType(
                    _physicalDevice,
                    memoryRequirements.memoryTypeBits,
                    VkMemoryPropertyFlags.DeviceLocal),
                memoryRequirements.size,
                memoryRequirements.alignment);

            _memory = memoryToken;
            vkBindImageMemory(_device, _image, _memory.DeviceMemory, _memory.Offset);
        }