diff --git a/gpu/backend.go b/gpu/backend.go index bb210f33..bf84b02b 100644 --- a/gpu/backend.go +++ b/gpu/backend.go @@ -22,7 +22,7 @@ type Backend interface { DefaultFramebuffer() Framebuffer NilTexture() Texture NewFramebuffer() Framebuffer - NewBuffer(typ BufferType) Buffer + NewBuffer(typ BufferType, data []byte) Buffer NewProgram(vertexShader, fragmentShader string, attribMap []string) (Program, error) SetupVertexArray(slot int, size int, dataType DataType, stride, offset int) @@ -49,7 +49,6 @@ type TextureFilter uint8 type TextureFormat uint8 type BufferType uint8 -type BufferUsage uint8 type DataType uint8 @@ -76,7 +75,6 @@ type Uniform interface{} type Buffer interface { Bind() - Upload(usage BufferUsage, data []byte) Release() } @@ -116,10 +114,6 @@ const ( DataTypeShort ) -const ( - BufferUsageStaticDraw BufferUsage = iota -) - const ( BufferTypeIndices BufferType = iota BufferTypeData diff --git a/gpu/gl/backend.go b/gpu/gl/backend.go index 475db765..858c4bce 100644 --- a/gpu/gl/backend.go +++ b/gpu/gl/backend.go @@ -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()) diff --git a/gpu/gpu.go b/gpu/gpu.go index 51f69e3b..6fd29ab2 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -380,14 +380,14 @@ func newBlitter(ctx Backend) *blitter { if err != nil { panic(err) } - quadVerts := ctx.NewBuffer(BufferTypeData) - quadVerts.Upload(BufferUsageStaticDraw, + quadVerts := ctx.NewBuffer(BufferTypeData, gunsafe.BytesView([]float32{ -1, +1, 0, 0, +1, +1, 1, 0, -1, -1, 0, 1, +1, -1, 1, 1, - })) + }), + ) b := &blitter{ ctx: ctx, prog: prog, diff --git a/gpu/path.go b/gpu/path.go index 28e904f4..1275dc24 100644 --- a/gpu/path.go +++ b/gpu/path.go @@ -143,8 +143,7 @@ func newStenciler(ctx Backend) *stenciler { indices[i*6+4] = i*4 + 1 indices[i*6+5] = i*4 + 3 } - indexBuf := ctx.NewBuffer(BufferTypeIndices) - indexBuf.Upload(BufferUsageStaticDraw, gunsafe.BytesView(indices)) + indexBuf := ctx.NewBuffer(BufferTypeIndices, gunsafe.BytesView(indices)) return &stenciler{ ctx: ctx, defFBO: defFBO, @@ -218,8 +217,7 @@ func (c *coverer) release() { } func buildPath(ctx Backend, p []byte) *pathData { - buf := ctx.NewBuffer(BufferTypeData) - buf.Upload(BufferUsageStaticDraw, p) + buf := ctx.NewBuffer(BufferTypeData, p) return &pathData{ ncurves: len(p) / path.VertStride, data: buf,