forked from joejulian/gio
gpu: rename BufferType to BufferBinding and make it a set
Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
+6
-6
@@ -21,8 +21,8 @@ type Backend interface {
|
||||
NewTexture(format TextureFormat, width, height int, minFilter, magFilter TextureFilter) Texture
|
||||
DefaultFramebuffer() Framebuffer
|
||||
NewFramebuffer() Framebuffer
|
||||
NewImmutableBuffer(typ BufferType, data []byte) Buffer
|
||||
NewBuffer(typ BufferType, size int) Buffer
|
||||
NewImmutableBuffer(typ BufferBinding, data []byte) Buffer
|
||||
NewBuffer(typ BufferBinding, size int) Buffer
|
||||
NewProgram(vertexShader, fragmentShader ShaderSources) (Program, error)
|
||||
NewInputLayout(vertexShader ShaderSources, layout []InputDesc) (InputLayout, error)
|
||||
|
||||
@@ -96,7 +96,7 @@ type BufferAttachments uint
|
||||
type TextureFilter uint8
|
||||
type TextureFormat uint8
|
||||
|
||||
type BufferType uint8
|
||||
type BufferBinding uint8
|
||||
|
||||
type DataType uint8
|
||||
|
||||
@@ -159,9 +159,9 @@ const (
|
||||
)
|
||||
|
||||
const (
|
||||
BufferTypeIndices BufferType = iota
|
||||
BufferTypeVertices
|
||||
BufferTypeUniforms
|
||||
BufferBindingIndices BufferBinding = 1 << iota
|
||||
BufferBindingVertices
|
||||
BufferBindingUniforms
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
+27
-27
@@ -64,7 +64,7 @@ type gpuFramebuffer struct {
|
||||
type gpuBuffer struct {
|
||||
backend *Backend
|
||||
obj Buffer
|
||||
typ Enum
|
||||
typ gpu.BufferBinding
|
||||
size int
|
||||
immutable bool
|
||||
version int
|
||||
@@ -190,23 +190,24 @@ func (b *Backend) NewTexture(format gpu.TextureFormat, width, height int, minFil
|
||||
return tex
|
||||
}
|
||||
|
||||
func (b *Backend) NewBuffer(typ gpu.BufferType, size int) gpu.Buffer {
|
||||
gltyp := toBufferType(typ)
|
||||
buf := &gpuBuffer{backend: b, typ: gltyp, size: size}
|
||||
switch typ {
|
||||
case gpu.BufferTypeUniforms:
|
||||
func (b *Backend) NewBuffer(typ gpu.BufferBinding, size int) gpu.Buffer {
|
||||
buf := &gpuBuffer{backend: b, typ: typ, size: size}
|
||||
if typ&gpu.BufferBindingUniforms != 0 {
|
||||
if typ != gpu.BufferBindingUniforms {
|
||||
panic("uniforms buffers cannot be bound as anything else")
|
||||
}
|
||||
// GLES 2 doesn't support uniform buffers.
|
||||
buf.data = make([]byte, size)
|
||||
default:
|
||||
}
|
||||
if typ&^gpu.BufferBindingUniforms != 0 {
|
||||
buf.obj = b.funcs.CreateBuffer()
|
||||
}
|
||||
return buf
|
||||
}
|
||||
|
||||
func (b *Backend) NewImmutableBuffer(typ gpu.BufferType, data []byte) gpu.Buffer {
|
||||
func (b *Backend) NewImmutableBuffer(typ gpu.BufferBinding, data []byte) gpu.Buffer {
|
||||
obj := b.funcs.CreateBuffer()
|
||||
gltyp := toBufferType(typ)
|
||||
buf := &gpuBuffer{backend: b, obj: obj, typ: gltyp, size: len(data)}
|
||||
buf := &gpuBuffer{backend: b, obj: obj, typ: typ, size: len(data)}
|
||||
buf.Upload(data)
|
||||
buf.immutable = true
|
||||
return buf
|
||||
@@ -428,7 +429,7 @@ func (u *uniformsTracker) setup(funcs Functions, p Program, uniformSize int, uni
|
||||
|
||||
func (u *uniformsTracker) setBuffer(buffer gpu.Buffer) {
|
||||
buf := buffer.(*gpuBuffer)
|
||||
if buf.typ != UNIFORM_BUFFER {
|
||||
if buf.typ&gpu.BufferBindingUniforms == 0 {
|
||||
panic("not a uniform buffer")
|
||||
}
|
||||
if buf.size < u.size {
|
||||
@@ -479,25 +480,24 @@ func (b *gpuBuffer) Upload(data []byte) {
|
||||
panic("buffer size overflow")
|
||||
}
|
||||
b.version++
|
||||
switch b.typ {
|
||||
case UNIFORM_BUFFER:
|
||||
if b.typ&gpu.BufferBindingUniforms != 0 {
|
||||
copy(b.data, data)
|
||||
default:
|
||||
b.backend.funcs.BindBuffer(b.typ, b.obj)
|
||||
b.backend.funcs.BufferData(b.typ, data, STATIC_DRAW)
|
||||
}
|
||||
if b.typ&^gpu.BufferBindingUniforms != 0 {
|
||||
firstBinding := firstBufferType(b.typ)
|
||||
b.backend.funcs.BindBuffer(firstBinding, b.obj)
|
||||
b.backend.funcs.BufferData(firstBinding, data, STATIC_DRAW)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *gpuBuffer) Release() {
|
||||
switch b.typ {
|
||||
case UNIFORM_BUFFER:
|
||||
default:
|
||||
if b.typ&^gpu.BufferBindingUniforms != 0 {
|
||||
b.backend.funcs.DeleteBuffer(b.obj)
|
||||
}
|
||||
}
|
||||
|
||||
func (b *gpuBuffer) BindVertex(stride, offset int) {
|
||||
if b.typ != ARRAY_BUFFER {
|
||||
if b.typ&gpu.BufferBindingVertices == 0 {
|
||||
panic("not a vertex buffer")
|
||||
}
|
||||
b.backend.state.buffer = bufferBinding{buf: b, stride: stride, offset: offset}
|
||||
@@ -526,7 +526,7 @@ func (b *Backend) setupVertexArrays() {
|
||||
}
|
||||
|
||||
func (b *gpuBuffer) BindIndex() {
|
||||
if b.typ != ELEMENT_ARRAY_BUFFER {
|
||||
if b.typ&gpu.BufferBindingIndices == 0 {
|
||||
panic("not an index buffer")
|
||||
}
|
||||
b.backend.funcs.BindBuffer(ELEMENT_ARRAY_BUFFER, b.obj)
|
||||
@@ -691,13 +691,13 @@ func hasExtension(exts []string, ext string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func toBufferType(typ gpu.BufferType) Enum {
|
||||
switch typ {
|
||||
case gpu.BufferTypeVertices:
|
||||
return ARRAY_BUFFER
|
||||
case gpu.BufferTypeIndices:
|
||||
func firstBufferType(typ gpu.BufferBinding) Enum {
|
||||
switch {
|
||||
case typ&gpu.BufferBindingIndices != 0:
|
||||
return ELEMENT_ARRAY_BUFFER
|
||||
case gpu.BufferTypeUniforms:
|
||||
case typ&gpu.BufferBindingVertices != 0:
|
||||
return ARRAY_BUFFER
|
||||
case typ&gpu.BufferBindingUniforms != 0:
|
||||
return UNIFORM_BUFFER
|
||||
default:
|
||||
panic("unsupported buffer type")
|
||||
|
||||
+2
-2
@@ -406,7 +406,7 @@ func (r *renderer) release() {
|
||||
}
|
||||
|
||||
func newBlitter(ctx Backend) *blitter {
|
||||
quadVerts := ctx.NewImmutableBuffer(BufferTypeVertices,
|
||||
quadVerts := ctx.NewImmutableBuffer(BufferBindingVertices,
|
||||
gunsafe.BytesView([]float32{
|
||||
-1, +1, 0, 0,
|
||||
+1, +1, 1, 0,
|
||||
@@ -913,7 +913,7 @@ func newUniformBuffer(b Backend, uniformBlock interface{}) *uniformBuffer {
|
||||
size := ref.Elem().Type().Size()
|
||||
// Map the uniforms structure as a byte slice.
|
||||
ptr := (*[1 << 30]byte)(unsafe.Pointer(ref.Pointer()))[:size:size]
|
||||
ubuf := b.NewBuffer(BufferTypeUniforms, len(ptr))
|
||||
ubuf := b.NewBuffer(BufferBindingUniforms, len(ptr))
|
||||
return &uniformBuffer{buf: ubuf, ptr: ptr}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -150,7 +150,7 @@ func newStenciler(ctx Backend) *stenciler {
|
||||
indices[i*6+4] = i*4 + 1
|
||||
indices[i*6+5] = i*4 + 3
|
||||
}
|
||||
indexBuf := ctx.NewImmutableBuffer(BufferTypeIndices, gunsafe.BytesView(indices))
|
||||
indexBuf := ctx.NewImmutableBuffer(BufferBindingIndices, gunsafe.BytesView(indices))
|
||||
progLayout, err := ctx.NewInputLayout(shader_stencil_vert, []InputDesc{
|
||||
{Type: DataTypeShort, Size: 2, Offset: int(unsafe.Offsetof((*(*path.Vertex)(nil)).CornerX))},
|
||||
{Type: DataTypeFloat, Size: 1, Offset: int(unsafe.Offsetof((*(*path.Vertex)(nil)).MaxY))},
|
||||
@@ -255,7 +255,7 @@ func (c *coverer) release() {
|
||||
}
|
||||
|
||||
func buildPath(ctx Backend, p []byte) *pathData {
|
||||
buf := ctx.NewImmutableBuffer(BufferTypeVertices, p)
|
||||
buf := ctx.NewImmutableBuffer(BufferBindingVertices, p)
|
||||
return &pathData{
|
||||
ncurves: len(p) / path.VertStride,
|
||||
data: buf,
|
||||
|
||||
Reference in New Issue
Block a user