From cae97a98618ed451ab6fe37ca3da5da8b2bfbebf Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 20 Feb 2020 23:21:06 +0100 Subject: [PATCH] gpu: add binding flags to Backend.NewTexture Direct3D needs to know the texture bind usage up front, in particular whether the texture is going to be used as a render target. Signed-off-by: Elias Naur --- gpu/backend.go | 4 +++- gpu/gl/backend.go | 2 +- gpu/gpu.go | 2 +- gpu/path.go | 3 ++- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gpu/backend.go b/gpu/backend.go index 8e834f18..894ef805 100644 --- a/gpu/backend.go +++ b/gpu/backend.go @@ -18,7 +18,7 @@ type Backend interface { // IsContinuousTime reports whether all timer measurements // are valid at the point of call. IsTimeContinuous() bool - NewTexture(format TextureFormat, width, height int, minFilter, magFilter TextureFilter) Texture + NewTexture(format TextureFormat, width, height int, minFilter, magFilter TextureFilter, bindings BufferBinding) Texture DefaultFramebuffer() Framebuffer NewFramebuffer() Framebuffer NewImmutableBuffer(typ BufferBinding, data []byte) Buffer @@ -162,6 +162,8 @@ const ( BufferBindingIndices BufferBinding = 1 << iota BufferBindingVertices BufferBindingUniforms + BufferBindingTexture + BufferBindingFramebuffer ) const ( diff --git a/gpu/gl/backend.go b/gpu/gl/backend.go index 0d721429..cd5ad571 100644 --- a/gpu/gl/backend.go +++ b/gpu/gl/backend.go @@ -171,7 +171,7 @@ func (b *Backend) DefaultFramebuffer() gpu.Framebuffer { return b.defFBO } -func (b *Backend) NewTexture(format gpu.TextureFormat, width, height int, minFilter, magFilter gpu.TextureFilter) gpu.Texture { +func (b *Backend) NewTexture(format gpu.TextureFormat, width, height int, minFilter, magFilter gpu.TextureFilter, binding gpu.BufferBinding) gpu.Texture { tex := &gpuTexture{backend: b, obj: b.funcs.CreateTexture()} switch format { case gpu.TextureFormatFloat: diff --git a/gpu/gpu.go b/gpu/gpu.go index 8c646cc9..00460f14 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -378,7 +378,7 @@ func (r *renderer) texHandle(t *texture) Texture { if t.tex != nil { return t.tex } - t.tex = r.ctx.NewTexture(TextureFormatSRGB, t.src.Bounds().Dx(), t.src.Bounds().Dy(), FilterLinear, FilterLinear) + t.tex = r.ctx.NewTexture(TextureFormatSRGB, t.src.Bounds().Dx(), t.src.Bounds().Dy(), FilterLinear, FilterLinear, BufferBindingTexture) t.tex.Upload(t.src) return t.tex } diff --git a/gpu/path.go b/gpu/path.go index 85429880..b4cc7131 100644 --- a/gpu/path.go +++ b/gpu/path.go @@ -210,7 +210,8 @@ func (s *fboSet) resize(ctx Backend, sizes []image.Point) { f.tex.Release() } f.size = sz - f.tex = ctx.NewTexture(TextureFormatFloat, sz.X, sz.Y, FilterNearest, FilterNearest) + f.tex = ctx.NewTexture(TextureFormatFloat, sz.X, sz.Y, FilterNearest, FilterNearest, + BufferBindingTexture|BufferBindingFramebuffer) f.fbo.BindTexture(f.tex) } }