Exemple #1
0
        public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITexture1D texture, int level)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type          = FramebufferAttachmentType.Texture,
                TextureTarget = TextureTarget.Texture1D,
                Texture       = texture,
                Level         = level
            };

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

            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            //gl.FramebufferTexture((int)framebufferTarget, (int)attachmentPoint, texture.Handle, level);
            GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)texture.Target, texture.Handle, level);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
Exemple #2
0
        public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITexture1D texture, int level)
        {
            var newDesc = new FramebufferAttachmentDescription
            {
                Type = FramebufferAttachmentType.Texture,
                TextureTarget = TextureTarget.Texture1D,
                Texture = texture,
                Level = level
            };

            if (IsRedundant(attachmentPoint, ref newDesc))
                return;
            var framebufferTarget = context.Bindings.Framebuffers.EditingTarget;
            context.Bindings.Framebuffers.ByTarget(framebufferTarget).Set(this);
            //gl.FramebufferTexture((int)framebufferTarget, (int)attachmentPoint, texture.Handle, level);
            GL.FramebufferTexture2D((int)framebufferTarget, (int)attachmentPoint, (int)texture.Target, texture.Handle, level);
            UpdateStoredDescription(attachmentPoint, ref newDesc);
        }
Exemple #3
0
 public static void SetDataCompressed(this ITexture1D texture, int level, IntPtr data, int compressedSize, IBuffer pixelUnpackBuffer = null)
 {
     texture.SetDataCompressed(level, 0, texture.CalculateMipWidth(level), data, compressedSize, pixelUnpackBuffer);
 }
        public void TestCreationParameters()
        {
            // Define variables and constants
            var defaultBuilder        = TextureFactory.NewTexture1D <TexelFormat.RGBA32UInt>().WithUsage(ResourceUsage.DiscardWrite).WithWidth(100);
            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>();

            // Set up context

            // Execute

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

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

            ITexture1DArray 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), 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 = defaultBuilder.WithUsage(ResourceUsage.Immutable).WithInitialData(new TexelFormat.RGBA32UInt[1000]).CreateArray(10);
            Assert.AreEqual(10U, ta.ArrayLength);
            ta.Dispose();

#if !DEVELOPMENT && !RELEASE
            try {
                TextureFactory.NewTexture1D <TexelFormat.Float32>()
                .WithUsage(ResourceUsage.Immutable)
                .WithInitialData(null)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture1D <TexelFormat.Float32>()
                .WithUsage(ResourceUsage.DiscardWrite)
                .WithPermittedBindings(GPUBindings.None)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture1D <TexelFormat.Float32>()
                .WithUsage(ResourceUsage.StagingRead)
                .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture1D <TexelFormat.Float32>()
                .WithWidth(0U)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture1D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithWidth(140)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture1D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithMipGenerationTarget(true)
                .WithWidth(1 << 4)
                .WithUsage(ResourceUsage.Write)
                .WithPermittedBindings(GPUBindings.None)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture1D <TexelFormat.Float32>()
                .WithMipAllocation(false)
                .WithMipGenerationTarget(true)
                .WithWidth(1 << 4)
                .WithUsage(ResourceUsage.Write)
                .WithPermittedBindings(GPUBindings.RenderTarget | GPUBindings.ReadableShaderResource)
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture1D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithMipGenerationTarget(true)
                .WithWidth(1 << 4)
                .WithUsage(ResourceUsage.Write)
                .WithPermittedBindings(GPUBindings.RenderTarget | GPUBindings.ReadableShaderResource)
                .WithInitialData(new TexelFormat.Float32[(1 << 5) - 1])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture1D <TexelFormat.Float32>()
                .WithMipAllocation(true)
                .WithWidth(1 << 4)
                .WithUsage(ResourceUsage.Immutable)
                .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                .WithInitialData(new TexelFormat.Float32[1 << 4])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
            try {
                TextureFactory.NewTexture1D <TexelFormat.Float32>()
                .WithMipAllocation(false)
                .WithWidth(1 << 4)
                .WithUsage(ResourceUsage.Immutable)
                .WithPermittedBindings(GPUBindings.ReadableShaderResource)
                .WithInitialData(new TexelFormat.Float32[(1 << 5) - 1])
                .Create();
                Assert.Fail();
            }
            catch (AssuranceFailedException) { }
#endif
        }
Exemple #5
0
 public static void SetData(this ITexture1D texture, int level, IntPtr data, FormatColor format, FormatType type, IBuffer pixelUnpackBuffer = null)
 {
     texture.SetData(level, 0, texture.CalculateMipWidth(level), data, format, type, pixelUnpackBuffer);
 }