public void SetTexture(IShader shader, string name, ITexture3D texture) { graphicsDevice.Cast <Shader>(shader, "shader"); if (name == null) { throw new ArgumentNullException("name"); } throw new NotImplementedException(); //SetTexture(shader, name, graphicsDevice.Cast<Texture3D>(texture, "texture").ResourceView); }
public void GenerateMips(ITexture3D texture) { var internalTexture = graphicsDevice.Cast <Texture3D>(texture, "texture"); if (internalTexture.IsDisposed) { throw new ObjectDisposedException("texture"); } internalTexture.GenerateMipMaps(); }
private void Create3DTexture() { if (m_Texture3D != null) { return; } const int cubeSize = 256; const int width = cubeSize; const int height = cubeSize; const int depth = cubeSize; m_Texture3D = Renderer.CreateTexture3D(width, height, depth); Renderer.UpdateTexture3D(m_Texture3D, Create3DLut(width, height, depth)); }
public void Update(ITexture3D texture, int mipLevel, DataBox data) { if (data == null) { throw new ArgumentNullException("data"); } Texture3D internalTexture = graphicsDevice.Cast <Texture3D>(texture, "textureArray"); if (internalTexture.Usage == ResourceUsage.Immutable) { throw new ArgumentException("Can't update immutable resource.", "texture"); } internalTexture.SetData(data, mipLevel); }
internal void SetTexture(ITexture3D texture, int unit) { if (currentTextures[unit] != texture) { if (texture == null) { GL.ActiveTexture(TextureUnit.Texture0 + unit); GL.BindTexture(TextureTarget.Texture3D, 0); } else { Texture3D internalTexture = graphicsDevice.Cast <Texture3D>(texture, "texture"); GL.ActiveTexture(TextureUnit.Texture0 + unit); GL.BindTexture(TextureTarget.Texture3D, internalTexture.TextureID); } currentTextures[unit] = texture; } }
public void Update(ITexture3D texture, int mipLevel, DataBox data) { var dxTexture = graphicsDevice.Cast <Texture2D>(texture, "texture"); if (dxTexture.Usage == ResourceUsage.Immutable) { throw new ArgumentException("Can't update immutable resource.", "texture"); } if (data == null) { throw new ArgumentNullException("data"); } if (mipLevel < 0 || mipLevel >= texture.MipLevels) { throw new ArgumentOutOfRangeException("mipLevel"); } renderContext.Context.UpdateSubresource(new SharpDX.DataBox(data.Pointer, data.Pitch, data.Slice), dxTexture.Texture, Resource.CalculateSubResourceIndex(mipLevel, 0, texture.MipLevels)); }
public void SetTexture(IShader shader, string name, ITexture3D 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)); }
public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITexture3D texture, int level, int depthLayer) { var newDesc = new FramebufferAttachmentDescription { Type = FramebufferAttachmentType.Texture, TextureTarget = TextureTarget.Texture3D, Texture = texture, Level = level, Layer = depthLayer }; 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, depthLayer); UpdateStoredDescription(attachmentPoint, ref newDesc); }
private unsafe void Upload3DLut(Lut3DHeader header, byte[] lutBuffer) { int inputBitsR = header.InputBitDepth[2]; int inputBitsG = header.InputBitDepth[1]; int inputBitsB = header.InputBitDepth[0]; int rSize = 1 << inputBitsR; int gSize = 1 << inputBitsG; int bSize = 1 << inputBitsB; const int channelCount = 4; var data = new Half[bSize, gSize, rSize *channelCount]; fixed(void *lutByte = lutBuffer) { var lut = (ushort *)lutByte; for (int b = 0; b < bSize; b++) { for (int g = 0; g < gSize; g++) { for (int r = 0; r < rSize; r++) { var lutOffset = ((r << (inputBitsG + inputBitsB)) + (g << inputBitsB) + b) * 3; var max = (float)((1 << header.OutputBitDepth) - 1); data[b, g, r *channelCount + 0] = lut[lutOffset + 2] / max; data[b, g, r *channelCount + 1] = lut[lutOffset + 1] / max; data[b, g, r *channelCount + 2] = lut[lutOffset + 0] / max; data[b, g, r *channelCount + 3] = 1; } } } } m_Texture3D = Renderer.CreateTexture3D(bSize, gSize, rSize); Renderer.UpdateTexture3D(m_Texture3D, data); }
public void Set(ITexture3D resource) { throw new NotImplementedException(); }
public void TestCreationParameters() { // Define variables and constants var defaultBuilder = TextureFactory.NewTexture3D <TexelFormat.RGBA32UInt>().WithUsage(ResourceUsage.DiscardWrite) .WithWidth(100).WithHeight(256).WithDepth(8); 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 ITexture3D 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, 256), tex.NumMips); tex.Dispose(); tex = withDynDetail.Create(); Assert.AreEqual(true, tex.IsGlobalDetailTarget); tex.Dispose(); tex = withMipGen.Create(); Assert.AreEqual(true, tex.IsMipGenTarget); tex.Dispose(); #if !DEVELOPMENT && !RELEASE try { TextureFactory.NewTexture3D <TexelFormat.Float32>() .WithUsage(ResourceUsage.Immutable) .WithInitialData(null) .Create(); Assert.Fail(); } catch (AssuranceFailedException) { } try { TextureFactory.NewTexture3D <TexelFormat.Float32>() .WithUsage(ResourceUsage.DiscardWrite) .WithPermittedBindings(GPUBindings.None) .Create(); Assert.Fail(); } catch (AssuranceFailedException) { } try { TextureFactory.NewTexture3D <TexelFormat.Float32>() .WithUsage(ResourceUsage.StagingRead) .WithPermittedBindings(GPUBindings.ReadableShaderResource) .Create(); Assert.Fail(); } catch (AssuranceFailedException) { } try { TextureFactory.NewTexture3D <TexelFormat.Float32>() .WithWidth(0U) .Create(); Assert.Fail(); } catch (AssuranceFailedException) { } try { TextureFactory.NewTexture3D <TexelFormat.Float32>() .WithMipAllocation(true) .WithWidth(140) .WithHeight(1U) .Create(); Assert.Fail(); } catch (AssuranceFailedException) { } try { TextureFactory.NewTexture3D <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.NewTexture3D <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.NewTexture3D <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.NewTexture3D <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.NewTexture3D <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) { } #endif }
public void GenerateMips(ITexture3D texture) { throw new NotImplementedException(); }
public void AttachTextureImage(FramebufferAttachmentPoint attachmentPoint, ITexture3D texture, int level, int depthLayer) { var newDesc = new FramebufferAttachmentDescription { Type = FramebufferAttachmentType.Texture, TextureTarget = TextureTarget.Texture3D, Texture = texture, Level = level, Layer = depthLayer }; 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, depthLayer); UpdateStoredDescription(attachmentPoint, ref newDesc); }
public static void SetDataCompressed(this ITexture3D texture, int level, IntPtr data, int compressedSize, IBuffer pixelUnpackBuffer = null) { texture.SetDataCompressed(level, 0, 0, 0, texture.CalculateMipWidth(level), texture.CalculateMipHeight(level), texture.CalculateMipDepth(level), data, compressedSize, pixelUnpackBuffer); }
public static void SetData(this ITexture3D texture, int level, IntPtr data, FormatColor format, FormatType type, IBuffer pixelUnpackBuffer = null) { texture.SetData(level, 0, 0, 0, texture.CalculateMipWidth(level), texture.CalculateMipHeight(level), texture.CalculateMipDepth(level), data, format, type, pixelUnpackBuffer); }