mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
graphics: Use opengl.DataType
This commit is contained in:
parent
9abeb29d2a
commit
d981466aed
@ -22,7 +22,6 @@ type Mode int
|
||||
type operation int
|
||||
|
||||
type CompositeMode int
|
||||
type DataType int
|
||||
|
||||
const (
|
||||
CompositeModeSourceOver CompositeMode = iota // This value must be 0 (= initial value)
|
||||
@ -73,3 +72,16 @@ func operations(mode CompositeMode) (src operation, dst operation) {
|
||||
panic("not reach")
|
||||
}
|
||||
}
|
||||
|
||||
type DataType int
|
||||
|
||||
func (d DataType) SizeInBytes() int {
|
||||
switch d {
|
||||
case Short:
|
||||
return 2
|
||||
case Float:
|
||||
return 4
|
||||
default:
|
||||
panic("not reach")
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
|
||||
type arrayBufferLayoutPart struct {
|
||||
name string
|
||||
unit int // e.g. int16 is 2 [bytes]
|
||||
dataType opengl.DataType
|
||||
num int
|
||||
normalize bool
|
||||
}
|
||||
@ -34,7 +34,7 @@ type arrayBufferLayout struct {
|
||||
func (a *arrayBufferLayout) newArrayBuffer(c *opengl.Context) opengl.Buffer {
|
||||
total := 0
|
||||
for _, p := range a.parts {
|
||||
total += p.unit * p.num
|
||||
total += p.dataType.SizeInBytes() * p.num
|
||||
}
|
||||
return c.NewBuffer(opengl.ArrayBuffer, total*4*maxQuads, opengl.DynamicDraw)
|
||||
}
|
||||
@ -45,12 +45,12 @@ func (a *arrayBufferLayout) enable(c *opengl.Context, program opengl.Program) {
|
||||
}
|
||||
total := 0
|
||||
for _, p := range a.parts {
|
||||
total += p.unit * p.num
|
||||
total += p.dataType.SizeInBytes() * p.num
|
||||
}
|
||||
offset := 0
|
||||
for _, p := range a.parts {
|
||||
size := p.unit * p.num
|
||||
c.VertexAttribPointer(program, p.name, size, opengl.Short, p.normalize, total, offset)
|
||||
size := p.dataType.SizeInBytes() * p.num
|
||||
c.VertexAttribPointer(program, p.name, size, p.dataType, p.normalize, total, offset)
|
||||
offset += size
|
||||
}
|
||||
}
|
||||
@ -62,23 +62,18 @@ func (a *arrayBufferLayout) disable(c *opengl.Context, program opengl.Program) {
|
||||
}
|
||||
}
|
||||
|
||||
// unsafe.SizeOf can't be used because unsafe doesn't work with GopherJS.
|
||||
const (
|
||||
int16Size = 2
|
||||
)
|
||||
|
||||
var (
|
||||
theArrayBufferLayout = arrayBufferLayout{
|
||||
parts: []arrayBufferLayoutPart{
|
||||
{
|
||||
name: "vertex",
|
||||
unit: int16Size,
|
||||
dataType: opengl.Short,
|
||||
num: 2,
|
||||
normalize: false,
|
||||
},
|
||||
{
|
||||
name: "tex_coord",
|
||||
unit: int16Size,
|
||||
dataType: opengl.Short,
|
||||
num: 2,
|
||||
normalize: true,
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user