mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
graphics: Cache total bytes
This commit is contained in:
parent
2b2d6157c7
commit
6de9e6696e
@ -199,7 +199,7 @@ type drawImageCommand struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func QuadVertexSizeInBytes() int {
|
func QuadVertexSizeInBytes() int {
|
||||||
return 4 * theArrayBufferLayout.total()
|
return 4 * theArrayBufferLayout.totalBytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *drawImageCommand) Exec(context *opengl.Context, indexOffsetInBytes int) error {
|
func (c *drawImageCommand) Exec(context *opengl.Context, indexOffsetInBytes int) error {
|
||||||
|
@ -30,25 +30,30 @@ type arrayBufferLayoutPart struct {
|
|||||||
|
|
||||||
type arrayBufferLayout struct {
|
type arrayBufferLayout struct {
|
||||||
parts []arrayBufferLayoutPart
|
parts []arrayBufferLayoutPart
|
||||||
|
total int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *arrayBufferLayout) total() int {
|
func (a *arrayBufferLayout) totalBytes() int {
|
||||||
|
if a.total != 0 {
|
||||||
|
return a.total
|
||||||
|
}
|
||||||
t := 0
|
t := 0
|
||||||
for _, p := range a.parts {
|
for _, p := range a.parts {
|
||||||
t += p.dataType.SizeInBytes() * p.num
|
t += p.dataType.SizeInBytes() * p.num
|
||||||
}
|
}
|
||||||
return t
|
a.total = t
|
||||||
|
return a.total
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *arrayBufferLayout) newArrayBuffer(c *opengl.Context) opengl.Buffer {
|
func (a *arrayBufferLayout) newArrayBuffer(c *opengl.Context) opengl.Buffer {
|
||||||
return c.NewBuffer(opengl.ArrayBuffer, a.total()*4*maxQuads, opengl.DynamicDraw)
|
return c.NewBuffer(opengl.ArrayBuffer, a.totalBytes()*4*maxQuads, opengl.DynamicDraw)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *arrayBufferLayout) enable(c *opengl.Context, program opengl.Program) {
|
func (a *arrayBufferLayout) enable(c *opengl.Context, program opengl.Program) {
|
||||||
for _, p := range a.parts {
|
for _, p := range a.parts {
|
||||||
c.EnableVertexAttribArray(program, p.name)
|
c.EnableVertexAttribArray(program, p.name)
|
||||||
}
|
}
|
||||||
total := a.total()
|
total := a.totalBytes()
|
||||||
offset := 0
|
offset := 0
|
||||||
for _, p := range a.parts {
|
for _, p := range a.parts {
|
||||||
c.VertexAttribPointer(program, p.name, p.num, p.dataType, p.normalize, total, offset)
|
c.VertexAttribPointer(program, p.name, p.num, p.dataType, p.normalize, total, offset)
|
||||||
|
Loading…
Reference in New Issue
Block a user