mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +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 operation int
|
||||||
|
|
||||||
type CompositeMode int
|
type CompositeMode int
|
||||||
type DataType int
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CompositeModeSourceOver CompositeMode = iota // This value must be 0 (= initial value)
|
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")
|
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 {
|
type arrayBufferLayoutPart struct {
|
||||||
name string
|
name string
|
||||||
unit int // e.g. int16 is 2 [bytes]
|
dataType opengl.DataType
|
||||||
num int
|
num int
|
||||||
normalize bool
|
normalize bool
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ type arrayBufferLayout struct {
|
|||||||
func (a *arrayBufferLayout) newArrayBuffer(c *opengl.Context) opengl.Buffer {
|
func (a *arrayBufferLayout) newArrayBuffer(c *opengl.Context) opengl.Buffer {
|
||||||
total := 0
|
total := 0
|
||||||
for _, p := range a.parts {
|
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)
|
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
|
total := 0
|
||||||
for _, p := range a.parts {
|
for _, p := range a.parts {
|
||||||
total += p.unit * p.num
|
total += p.dataType.SizeInBytes() * p.num
|
||||||
}
|
}
|
||||||
offset := 0
|
offset := 0
|
||||||
for _, p := range a.parts {
|
for _, p := range a.parts {
|
||||||
size := p.unit * p.num
|
size := p.dataType.SizeInBytes() * p.num
|
||||||
c.VertexAttribPointer(program, p.name, size, opengl.Short, p.normalize, total, offset)
|
c.VertexAttribPointer(program, p.name, size, p.dataType, p.normalize, total, offset)
|
||||||
offset += size
|
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 (
|
var (
|
||||||
theArrayBufferLayout = arrayBufferLayout{
|
theArrayBufferLayout = arrayBufferLayout{
|
||||||
parts: []arrayBufferLayoutPart{
|
parts: []arrayBufferLayoutPart{
|
||||||
{
|
{
|
||||||
name: "vertex",
|
name: "vertex",
|
||||||
unit: int16Size,
|
dataType: opengl.Short,
|
||||||
num: 2,
|
num: 2,
|
||||||
normalize: false,
|
normalize: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "tex_coord",
|
name: "tex_coord",
|
||||||
unit: int16Size,
|
dataType: opengl.Short,
|
||||||
num: 2,
|
num: 2,
|
||||||
normalize: true,
|
normalize: true,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user