mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 10:42:42 +01:00
opengl: Refactoring: Replace NewBuffer with new funcs
Replace NewBuffer with NewArrayBuffer and NewElementArrayBuffer
This commit is contained in:
parent
b332f673eb
commit
2d5b062c3c
@ -47,7 +47,7 @@ func (a *arrayBufferLayout) totalBytes() int {
|
||||
}
|
||||
|
||||
func (a *arrayBufferLayout) newArrayBuffer() opengl.Buffer {
|
||||
return opengl.GetContext().NewBuffer(opengl.ArrayBuffer, a.totalBytes()*4*maxQuads, opengl.DynamicDraw)
|
||||
return opengl.GetContext().NewArrayBuffer(a.totalBytes() * 4 * maxQuads)
|
||||
}
|
||||
|
||||
func (a *arrayBufferLayout) enable(program opengl.Program) {
|
||||
@ -169,7 +169,7 @@ func (s *openGLState) reset() error {
|
||||
indices[6*i+4] = 4*i + 2
|
||||
indices[6*i+5] = 4*i + 3
|
||||
}
|
||||
s.indexBufferQuads = opengl.GetContext().NewBuffer(opengl.ElementArrayBuffer, indices, opengl.StaticDraw)
|
||||
s.indexBufferQuads = opengl.GetContext().NewElementArrayBuffer(indices)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -460,21 +460,26 @@ func (c *Context) DisableVertexAttribArray(p Program, location string) {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsage BufferUsage) Buffer {
|
||||
func (c *Context) NewArrayBuffer(size int) Buffer {
|
||||
var buffer Buffer
|
||||
_ = c.runOnContextThread(func() error {
|
||||
var b uint32
|
||||
gl.GenBuffers(1, &b)
|
||||
gl.BindBuffer(uint32(bufferType), b)
|
||||
switch v := v.(type) {
|
||||
case int:
|
||||
gl.BufferData(uint32(bufferType), v, nil, uint32(bufferUsage))
|
||||
case []uint16:
|
||||
// TODO: What about the endianness?
|
||||
gl.BufferData(uint32(bufferType), 2*len(v), gl.Ptr(v), uint32(bufferUsage))
|
||||
default:
|
||||
panic("not reach")
|
||||
}
|
||||
gl.BindBuffer(uint32(ArrayBuffer), b)
|
||||
gl.BufferData(uint32(ArrayBuffer), size, nil, uint32(DynamicDraw))
|
||||
buffer = Buffer(b)
|
||||
return nil
|
||||
})
|
||||
return buffer
|
||||
}
|
||||
|
||||
func (c *Context) NewElementArrayBuffer(indices []uint16) Buffer {
|
||||
var buffer Buffer
|
||||
_ = c.runOnContextThread(func() error {
|
||||
var b uint32
|
||||
gl.GenBuffers(1, &b)
|
||||
gl.BindBuffer(uint32(ElementArrayBuffer), b)
|
||||
gl.BufferData(uint32(ElementArrayBuffer), 2*len(indices), gl.Ptr(indices), uint32(StaticDraw))
|
||||
buffer = Buffer(b)
|
||||
return nil
|
||||
})
|
||||
|
@ -389,11 +389,19 @@ func (c *Context) DisableVertexAttribArray(p Program, location string) {
|
||||
gl.DisableVertexAttribArray(int(l))
|
||||
}
|
||||
|
||||
func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsage BufferUsage) Buffer {
|
||||
func (c *Context) NewArrayBuffer(size int) Buffer {
|
||||
gl := c.gl
|
||||
b := gl.CreateBuffer()
|
||||
gl.BindBuffer(int(bufferType), b)
|
||||
gl.BufferData(int(bufferType), v, int(bufferUsage))
|
||||
gl.BindBuffer(int(ArrayBuffer), b)
|
||||
gl.BufferData(int(ArrayBuffer), size, int(DynamicDraw))
|
||||
return Buffer{b}
|
||||
}
|
||||
|
||||
func (c *Context) NewElementArrayBuffer(indices []uint16) Buffer {
|
||||
gl := c.gl
|
||||
b := gl.CreateBuffer()
|
||||
gl.BindBuffer(int(ElementArrayBuffer), b)
|
||||
gl.BufferData(int(ElementArrayBuffer), indices, int(StaticDraw))
|
||||
return Buffer{b}
|
||||
}
|
||||
|
||||
|
@ -365,18 +365,19 @@ func uint16ToBytes(v []uint16) []uint8 {
|
||||
return b
|
||||
}
|
||||
|
||||
func (c *Context) NewBuffer(bufferType BufferType, v interface{}, bufferUsage BufferUsage) Buffer {
|
||||
func (c *Context) NewArrayBuffer(size int) Buffer {
|
||||
gl := c.gl
|
||||
b := gl.CreateBuffer()
|
||||
gl.BindBuffer(mgl.Enum(bufferType), b)
|
||||
switch v := v.(type) {
|
||||
case int:
|
||||
gl.BufferInit(mgl.Enum(bufferType), v, mgl.Enum(bufferUsage))
|
||||
case []uint16:
|
||||
gl.BufferData(mgl.Enum(bufferType), uint16ToBytes(v), mgl.Enum(bufferUsage))
|
||||
default:
|
||||
panic("not reach")
|
||||
}
|
||||
gl.BindBuffer(mgl.Enum(ArrayBuffer), b)
|
||||
gl.BufferInit(mgl.Enum(ArrayBuffer), size, mgl.Enum(DynamicDraw))
|
||||
return Buffer(b)
|
||||
}
|
||||
|
||||
func (c *Context) NewElementArrayBuffer(indices []uint16) Buffer {
|
||||
gl := c.gl
|
||||
b := gl.CreateBuffer()
|
||||
gl.BindBuffer(mgl.Enum(ElementArrayBuffer), b)
|
||||
gl.BufferData(mgl.Enum(ElementArrayBuffer), uint16ToBytes(indices), mgl.Enum(StaticDraw))
|
||||
return Buffer(b)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user