mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
gpu: remove Backend.Resize and fully specify format in Backend.NewTexture
Re-create textures instead to better match direct3d. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+1
-2
@@ -18,7 +18,7 @@ type Backend interface {
|
|||||||
// IsContinuousTime reports whether all timer measurements
|
// IsContinuousTime reports whether all timer measurements
|
||||||
// are valid at the point of call.
|
// are valid at the point of call.
|
||||||
IsTimeContinuous() bool
|
IsTimeContinuous() bool
|
||||||
NewTexture(minFilter, magFilter TextureFilter) Texture
|
NewTexture(format TextureFormat, width, height int, minFilter, magFilter TextureFilter) Texture
|
||||||
DefaultFramebuffer() Framebuffer
|
DefaultFramebuffer() Framebuffer
|
||||||
NilTexture() Texture
|
NilTexture() Texture
|
||||||
NewFramebuffer() Framebuffer
|
NewFramebuffer() Framebuffer
|
||||||
@@ -143,7 +143,6 @@ type Texture interface {
|
|||||||
Upload(img *image.RGBA)
|
Upload(img *image.RGBA)
|
||||||
Release()
|
Release()
|
||||||
Bind(unit int)
|
Bind(unit int)
|
||||||
Resize(format TextureFormat, width, height int)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
+12
-9
@@ -53,6 +53,7 @@ type gpuTimer struct {
|
|||||||
type gpuTexture struct {
|
type gpuTexture struct {
|
||||||
backend *Backend
|
backend *Backend
|
||||||
obj Texture
|
obj Texture
|
||||||
|
triple textureTriple
|
||||||
}
|
}
|
||||||
|
|
||||||
type gpuFramebuffer struct {
|
type gpuFramebuffer struct {
|
||||||
@@ -174,13 +175,22 @@ func (b *Backend) DefaultFramebuffer() gpu.Framebuffer {
|
|||||||
return b.defFBO
|
return b.defFBO
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Backend) NewTexture(minFilter, magFilter gpu.TextureFilter) gpu.Texture {
|
func (b *Backend) NewTexture(format gpu.TextureFormat, width, height int, minFilter, magFilter gpu.TextureFilter) gpu.Texture {
|
||||||
tex := &gpuTexture{backend: b, obj: b.funcs.CreateTexture()}
|
tex := &gpuTexture{backend: b, obj: b.funcs.CreateTexture()}
|
||||||
|
switch format {
|
||||||
|
case gpu.TextureFormatFloat:
|
||||||
|
tex.triple = b.floatTriple
|
||||||
|
case gpu.TextureFormatSRGB:
|
||||||
|
tex.triple = b.srgbaTriple
|
||||||
|
default:
|
||||||
|
panic("unsupported texture format")
|
||||||
|
}
|
||||||
tex.Bind(0)
|
tex.Bind(0)
|
||||||
b.funcs.TexParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, toTexFilter(magFilter))
|
b.funcs.TexParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, toTexFilter(magFilter))
|
||||||
b.funcs.TexParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, toTexFilter(minFilter))
|
b.funcs.TexParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, toTexFilter(minFilter))
|
||||||
b.funcs.TexParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE)
|
b.funcs.TexParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE)
|
||||||
b.funcs.TexParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE)
|
b.funcs.TexParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE)
|
||||||
|
b.funcs.TexImage2D(TEXTURE_2D, 0, tex.triple.internalFormat, width, height, tex.triple.format, tex.triple.typ, nil)
|
||||||
return tex
|
return tex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -571,12 +581,6 @@ func (t *gpuTexture) Release() {
|
|||||||
t.backend.funcs.DeleteTexture(t.obj)
|
t.backend.funcs.DeleteTexture(t.obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *gpuTexture) Resize(format gpu.TextureFormat, width, height int) {
|
|
||||||
t.Bind(0)
|
|
||||||
tt := t.backend.floatTriple
|
|
||||||
t.backend.funcs.TexImage2D(TEXTURE_2D, 0, tt.internalFormat, width, height, tt.format, tt.typ, nil)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *gpuTexture) Upload(img *image.RGBA) {
|
func (t *gpuTexture) Upload(img *image.RGBA) {
|
||||||
t.Bind(0)
|
t.Bind(0)
|
||||||
var pixels []byte
|
var pixels []byte
|
||||||
@@ -588,8 +592,7 @@ func (t *gpuTexture) Upload(img *image.RGBA) {
|
|||||||
start := (b.Min.X + b.Min.Y*w) * 4
|
start := (b.Min.X + b.Min.Y*w) * 4
|
||||||
end := (b.Max.X + (b.Max.Y-1)*w) * 4
|
end := (b.Max.X + (b.Max.Y-1)*w) * 4
|
||||||
pixels = img.Pix[start:end]
|
pixels = img.Pix[start:end]
|
||||||
tt := t.backend.srgbaTriple
|
t.backend.funcs.TexImage2D(TEXTURE_2D, 0, t.triple.internalFormat, w, h, t.triple.format, t.triple.typ, pixels)
|
||||||
t.backend.funcs.TexImage2D(TEXTURE_2D, 0, tt.internalFormat, w, h, tt.format, tt.typ, pixels)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *gpuTimer) Begin() {
|
func (t *gpuTimer) Begin() {
|
||||||
|
|||||||
+1
-1
@@ -378,7 +378,7 @@ func (r *renderer) texHandle(t *texture) Texture {
|
|||||||
if t.tex != nil {
|
if t.tex != nil {
|
||||||
return t.tex
|
return t.tex
|
||||||
}
|
}
|
||||||
t.tex = r.ctx.NewTexture(FilterLinear, FilterLinear)
|
t.tex = r.ctx.NewTexture(TextureFormatSRGB, t.src.Bounds().Dx(), t.src.Bounds().Dy(), FilterLinear, FilterLinear)
|
||||||
t.tex.Upload(t.src)
|
t.tex.Upload(t.src)
|
||||||
return t.tex
|
return t.tex
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-2
@@ -195,7 +195,6 @@ func (s *fboSet) resize(ctx Backend, sizes []image.Point) {
|
|||||||
for i := len(s.fbos); i < len(sizes); i++ {
|
for i := len(s.fbos); i < len(sizes); i++ {
|
||||||
s.fbos = append(s.fbos, stencilFBO{
|
s.fbos = append(s.fbos, stencilFBO{
|
||||||
fbo: ctx.NewFramebuffer(),
|
fbo: ctx.NewFramebuffer(),
|
||||||
tex: ctx.NewTexture(FilterNearest, FilterNearest),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// Resize fbos.
|
// Resize fbos.
|
||||||
@@ -207,8 +206,11 @@ func (s *fboSet) resize(ctx Backend, sizes []image.Point) {
|
|||||||
waste := float32(sz.X*sz.Y) / float32(f.size.X*f.size.Y)
|
waste := float32(sz.X*sz.Y) / float32(f.size.X*f.size.Y)
|
||||||
resize = resize || waste > 1.2
|
resize = resize || waste > 1.2
|
||||||
if resize {
|
if resize {
|
||||||
|
if f.tex != nil {
|
||||||
|
f.tex.Release()
|
||||||
|
}
|
||||||
f.size = sz
|
f.size = sz
|
||||||
f.tex.Resize(TextureFormatFloat, sz.X, sz.Y)
|
f.tex = ctx.NewTexture(TextureFormatFloat, sz.X, sz.Y, FilterNearest, FilterNearest)
|
||||||
f.fbo.BindTexture(f.tex)
|
f.fbo.BindTexture(f.tex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user