gpu: make Buffers immutable

The GPU implementation only uses immutable buffers so far, so let's
make it easy and performant for the backends.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-02-16 17:48:58 +01:00
parent 49365dbcc5
commit f62725ea77
4 changed files with 11 additions and 28 deletions
+5 -14
View File
@@ -148,7 +148,7 @@ func (b *Backend) NewTexture(minFilter, magFilter gpu.TextureFilter) gpu.Texture
return tex
}
func (b *Backend) NewBuffer(typ gpu.BufferType) gpu.Buffer {
func (b *Backend) NewBuffer(typ gpu.BufferType, data []byte) gpu.Buffer {
obj := b.funcs.CreateBuffer()
var gltyp Enum
switch typ {
@@ -159,7 +159,10 @@ func (b *Backend) NewBuffer(typ gpu.BufferType) gpu.Buffer {
default:
panic("unsupported buffer type")
}
return &gpuBuffer{funcs: b.funcs, obj: obj, typ: gltyp}
buf := &gpuBuffer{funcs: b.funcs, obj: obj, typ: gltyp}
buf.Bind()
b.funcs.BufferData(gltyp, data, STATIC_DRAW)
return buf
}
func (b *Backend) bindTexture(unit int, t *gpuTexture) {
@@ -344,18 +347,6 @@ func (b *gpuBuffer) Bind() {
b.funcs.BindBuffer(b.typ, b.obj)
}
func (b *gpuBuffer) Upload(usage gpu.BufferUsage, data []byte) {
b.Bind()
var glusage Enum
switch usage {
case gpu.BufferUsageStaticDraw:
glusage = STATIC_DRAW
default:
panic("unsupported buffer usage")
}
b.funcs.BufferData(b.typ, data, glusage)
}
func (f *gpuFramebuffer) IsComplete() error {
if st := f.funcs.CheckFramebufferStatus(FRAMEBUFFER); st != FRAMEBUFFER_COMPLETE {
return fmt.Errorf("incomplete framebuffer, status = 0x%x, err = %d", st, f.funcs.GetError())