예제 #1
0
 public void SetTexture(IShader shader, string name, ITexture2DArray texture)
 {
     graphicsDevice.Cast <Shader>(shader, "shader");
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     SetTexture(shader, name, graphicsDevice.Cast <Texture2D>(texture, "texture").ResourceView);
 }
예제 #2
0
        public void GenerateMips(ITexture2DArray textureArray)
        {
            var dxTexture = graphicsDevice.Cast <Texture2D>(textureArray, "textureArray");

            if (!dxTexture.Texture.Description.OptionFlags.HasFlag(SharpDX.Direct3D11.ResourceOptionFlags.GenerateMipMaps))
            {
                throw new ArgumentException("TextureArray does not have the GenerateMipMaps flag.", "textureArray");
            }

            renderContext.Context.GenerateMips(dxTexture.ResourceView);
        }
예제 #3
0
        public void GenerateMips(ITexture2DArray textureArray)
        {
            var internalTexture = graphicsDevice.Cast <Texture2DArray>(textureArray, "texture");

            if (internalTexture.IsDisposed)
            {
                throw new ObjectDisposedException("textureArray");
            }

            internalTexture.GenerateMipMaps();
        }
예제 #4
0
        public void Update(ITexture2DArray textureArray, int arrayIndex, int mipLevel, DataRectangle data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            Texture2DArray internalTexture = graphicsDevice.Cast <Texture2DArray>(textureArray, "textureArray");

            if (internalTexture.Usage == ResourceUsage.Immutable)
            {
                throw new ArgumentException("Can't update immutable resource.", "texture");
            }

            internalTexture.SetData(data, arrayIndex, mipLevel);
        }
예제 #5
0
        public void SetTexture(IShader shader, string name, ITexture2DArray texture)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (texture == null)
            {
                throw new ArgumentNullException("texture");
            }
            if (shader == null)
            {
                throw new ArgumentNullException("shader");
            }

            var internalShader = graphicsDevice.Cast <Shader>(shader, "shader");

            graphicsDevice.BindManager.SetTexture(texture, internalShader.GetTextureUnit(name));
        }
예제 #6
0
        internal void SetTexture(ITexture2DArray texture, int unit)
        {
            if (currentTextures[unit] != texture)
            {
                if (texture == null)
                {
                    GL.ActiveTexture(TextureUnit.Texture0 + unit);
                    GL.BindTexture(TextureTarget.TextureCubeMap, 0);
                    GL.BindTexture(TextureTarget.Texture2DArray, 0);
                }
                else
                {
                    Texture2DArray internalTexture = graphicsDevice.Cast <Texture2DArray>(texture, "texture");
                    GL.ActiveTexture(TextureUnit.Texture0 + unit);

                    GL.BindTexture(TextureTarget.Texture2DArray, internalTexture.TextureID);
                }
                currentTextures[unit] = texture;
            }
        }
예제 #7
0
        public void Update(ITexture2DArray textureArray, int arrayIndex, int mipLevel, DataRectangle data)
        {
            var dxTexture = graphicsDevice.Cast <Texture2D>(textureArray, "texture");

            if (dxTexture.Usage == ResourceUsage.Immutable)
            {
                throw new ArgumentException("Can't update immutable resource.", "texture");
            }

            if (arrayIndex < 0 || arrayIndex >= textureArray.ArraySize)
            {
                throw new ArgumentOutOfRangeException("arrayIndex");
            }
            if (mipLevel < 0 || mipLevel >= textureArray.MipLevels)
            {
                throw new ArgumentOutOfRangeException("mipLevel");
            }

            renderContext.Context.UpdateSubresource(new SharpDX.DataBox(data.Pointer, data.Pitch, 0), dxTexture.Texture, Resource.CalculateSubResourceIndex(mipLevel, arrayIndex, textureArray.MipLevels));
        }
예제 #8
0
        public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITexture2DArray texture, int level, int layer)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type          = FramebufferAttachmentType.Texture,
                TextureTarget = TextureTarget.Texture2DArray,
                Texture       = texture,
                Level         = level,
                Layer         = layer
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
            {
                return;
            }
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;

            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            GL.FramebufferTextureLayer((int)framebufferTarget, (int)attachmentPoint, texture.Handle, level, layer);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
예제 #9
0
        public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITexture2DArray texture, int level, int layer)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type = FramebufferAttachmentType.Texture,
                TextureTarget = TextureTarget.Texture2DArray,
                Texture = texture,
                Level = level,
                Layer = layer
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
                return;
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;
            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            GL.FramebufferTextureLayer((int)framebufferTarget, (int)attachmentPoint, texture.Handle, level, layer);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
예제 #10
0
 public static void SetDataCompressed(this ITexture2DArray texture, int level, int slice, IntPtr data, int compressedSize, IBuffer pixelUnpackBuffer = null)
 {
     texture.SetDataCompressed(level, 0, 0, slice, texture.CalculateMipWidth(level), texture.CalculateMipHeight(level), 1, data, compressedSize, pixelUnpackBuffer);
 }
예제 #11
0
 public static void SetData(this ITexture2DArray texture, int level, int slice, IntPtr data, FormatColor format, FormatType type, IBuffer pixelUnpackBuffer = null)
 {
     texture.SetData(level, 0, 0, slice, texture.CalculateMipWidth(level), texture.CalculateMipHeight(level), 1, data, format, type, pixelUnpackBuffer);
 }
예제 #12
0
        public void TestCreationParameters()
        {
            // Define variables and constants
            var defaultBuilder        = TextureFactory.NewTexture2D <TexelFormat.RGBA32UInt>().WithUsage(ResourceUsage.DiscardWrite).WithWidth(100).WithHeight(256);
            var withStagingUsage      = defaultBuilder.WithUsage(ResourceUsage.StagingReadWrite).WithPermittedBindings(GPUBindings.None);
            var withReadWriteBindings = defaultBuilder.WithUsage(ResourceUsage.Write).WithPermittedBindings(GPUBindings.ReadableShaderResource | GPUBindings.WritableShaderResource);
            var withDifferentFormat   = defaultBuilder.WithTexelFormat <TexelFormat.Int8>();
            var withWidth300          = defaultBuilder.WithWidth(300);
            var withMipAllocation     = defaultBuilder.WithUsage(ResourceUsage.Write).WithWidth(1 << 9).WithMipAllocation(true);
            var withDynDetail         = withMipAllocation.WithDynamicDetail(true);
            var withMipGen            = withMipAllocation
                                        .WithUsage(ResourceUsage.Write)
                                        .WithPermittedBindings(GPUBindings.RenderTarget | GPUBindings.ReadableShaderResource)
                                        .WithMipGenerationTarget(true)
                                        .WithTexelFormat <TexelFormat.RGBA8UNorm>();
            var withMS = defaultBuilder.WithMultisampling(true);

            // Set up context

            // Execute

            // Assert outcome
            ITexture2D tex = withStagingUsage.Create();

            Assert.AreEqual(ResourceUsage.StagingReadWrite, tex.Usage);
            tex.Dispose();
            tex = withReadWriteBindings.Create();
            tex.Dispose();
            Assert.AreEqual(GPUBindings.ReadableShaderResource | GPUBindings.WritableShaderResource, tex.PermittedBindings);
            tex = withDifferentFormat.Create();
            tex.Dispose();
            Assert.AreEqual(typeof(TexelFormat.Int8), tex.TexelFormat);
            tex = withWidth300.Create();
            tex.Dispose();
            Assert.AreEqual(300U, tex.Width);
            tex = withMipAllocation.Create();
            tex.Dispose();
            Assert.AreEqual(TextureUtils.GetNumMips(1 << 9, 256), tex.NumMips);
            tex = withDynDetail.Create();
            tex.Dispose();
            Assert.AreEqual(true, tex.IsGlobalDetailTarget);
            tex = withMipGen.Create();
            tex.Dispose();
            Assert.AreEqual(true, tex.IsMipGenTarget);
            tex = withMS.Create();
            tex.Dispose();
            Assert.AreEqual(true, tex.IsMultisampled);
            tex.Dispose();

            ITexture2DArray ta = withStagingUsage.CreateArray(10);

            Assert.AreEqual(ResourceUsage.StagingReadWrite, ta.Usage);
            ta.Dispose();
            ta = withReadWriteBindings.CreateArray(10);
            Assert.AreEqual(GPUBindings.ReadableShaderResource | GPUBindings.WritableShaderResource, ta.PermittedBindings);
            ta.Dispose();
            ta = withDifferentFormat.WithUsage(ResourceUsage.Write).CreateArray(10);
            Assert.AreEqual(typeof(TexelFormat.Int8), ta.TexelFormat);
            ta.Dispose();
            ta = withWidth300.WithUsage(ResourceUsage.Write).CreateArray(10);
            Assert.AreEqual(300U, ta.Width);
            ta.Dispose();
            ta = withMipAllocation.CreateArray(10);
            Assert.AreEqual(TextureUtils.GetNumMips(1 << 9, 256), ta.NumMips);
            ta.Dispose();
            ta = withDynDetail.CreateArray(10);
            Assert.AreEqual(true, ta.IsGlobalDetailTarget);
            ta.Dispose();
            ta = withMipGen.CreateArray(10);
            Assert.AreEqual(true, ta.IsMipGenTarget);
            ta.Dispose();
            ta = withMS.WithUsage(ResourceUsage.Write).CreateArray(10);
            Assert.AreEqual(true, ta.IsMultisampled);
            ta.Dispose();

            ta = defaultBuilder.WithUsage(ResourceUsage.Immutable).WithInitialData(new TexelFormat.RGBA32UInt[10U * 100U * 256U]).CreateArray(10);
            Assert.AreEqual(10U, ta.ArrayLength);
            ta.Dispose();

#if !DEVELOPMENT && !RELEASE
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithUsage(ResourceUsage.Immutable)
                .WithInitialData(null)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithUsage(ResourceUsage.DiscardWrite)
                .WithPermittedBindings(GPUBindings.None)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithUsage(ResourceUsage.StagingRead)
                .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithWidth(0U)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithWidth(140)
                .WithHeight(1U)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithMipGenerationTarget(true)
                .WithWidth(1 << 4)
                .WithHeight(1 << 4)
                .WithUsage(ResourceUsage.Write)
                .WithPermittedBindings(GPUBindings.None)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(false)
                .WithMipGenerationTarget(true)
                .WithWidth(1 << 4)
                .WithHeight(1 << 4)
                .WithUsage(ResourceUsage.Write)
                .WithPermittedBindings(GPUBindings.RenderTarget | GPUBindings.ReadableShaderResource)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithMipGenerationTarget(true)
                .WithWidth(1 << 4)
                .WithHeight(1 << 4)
                .WithUsage(ResourceUsage.Write)
                .WithPermittedBindings(GPUBindings.RenderTarget | GPUBindings.ReadableShaderResource)
                .WithInitialData(new TexelFormat.Float32[(1 << 5) - 1])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithWidth(1 << 4)
                .WithHeight(1 << 4)
                .WithUsage(ResourceUsage.Immutable)
                .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                .WithInitialData(new TexelFormat.Float32[1 << 4])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(false)
                .WithWidth(1 << 4)
                .WithHeight(1 << 4)
                .WithUsage(ResourceUsage.Immutable)
                .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                .WithInitialData(new TexelFormat.Float32[(1 << 5) - 1])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithWidth(32U)
                .WithHeight(32U)
                .WithMultisampling(true)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture2D <TexelFormat.Float32>()
                .WithMipAllocation(false)
                .WithWidth(2U)
                .WithHeight(2U)
                .WithMultisampling(true)
                .WithInitialData(new TexelFormat.Float32[4])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif
        }