mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
graphics: Reduce magic numbers
This commit is contained in:
parent
cbcbdb0b97
commit
3efabe988a
@ -108,7 +108,7 @@ func (q *commandQueue) Flush(context *opengl.Context) error {
|
|||||||
}
|
}
|
||||||
// NOTE: WebGL doesn't seem to have Check gl.MAX_ELEMENTS_VERTICES or gl.MAX_ELEMENTS_INDICES so far.
|
// NOTE: WebGL doesn't seem to have Check gl.MAX_ELEMENTS_VERTICES or gl.MAX_ELEMENTS_INDICES so far.
|
||||||
// Let's use them to compare to len(quads) in the future.
|
// Let's use them to compare to len(quads) in the future.
|
||||||
if maxQuads < len(vertices)/16 {
|
if maxQuads < len(vertices)/quadVertexNum {
|
||||||
return errors.New(fmt.Sprintf("len(quads) must be equal to or less than %d", maxQuads))
|
return errors.New(fmt.Sprintf("len(quads) must be equal to or less than %d", maxQuads))
|
||||||
}
|
}
|
||||||
numc := len(g)
|
numc := len(g)
|
||||||
@ -118,7 +118,7 @@ func (q *commandQueue) Flush(context *opengl.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if c, ok := c.(*drawImageCommand); ok {
|
if c, ok := c.(*drawImageCommand); ok {
|
||||||
indexOffsetInBytes += 6 * len(c.vertices) / 16 * 2
|
indexOffsetInBytes += 6 * len(c.vertices) / quadVertexNum * 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if 0 < numc {
|
if 0 < numc {
|
||||||
@ -161,6 +161,10 @@ type drawImageCommand struct {
|
|||||||
mode opengl.CompositeMode
|
mode opengl.CompositeMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
quadVertexNum = 16 // 4 * 2 [vertices] * 2 [tex_coords]
|
||||||
|
)
|
||||||
|
|
||||||
func (c *drawImageCommand) Exec(context *opengl.Context, indexOffsetInBytes int) error {
|
func (c *drawImageCommand) Exec(context *opengl.Context, indexOffsetInBytes int) error {
|
||||||
if err := c.dst.framebuffer.setAsViewport(context); err != nil {
|
if err := c.dst.framebuffer.setAsViewport(context); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -195,13 +199,13 @@ func (c *drawImageCommand) Exec(context *opengl.Context, indexOffsetInBytes int)
|
|||||||
func (c *drawImageCommand) split(quadsNum int) [2]*drawImageCommand {
|
func (c *drawImageCommand) split(quadsNum int) [2]*drawImageCommand {
|
||||||
c1 := *c
|
c1 := *c
|
||||||
c2 := *c
|
c2 := *c
|
||||||
c1.vertices = c.vertices[:quadsNum*16]
|
c1.vertices = c.vertices[:quadsNum*quadVertexNum]
|
||||||
c2.vertices = c.vertices[quadsNum*16:]
|
c2.vertices = c.vertices[quadsNum*quadVertexNum:]
|
||||||
return [2]*drawImageCommand{&c1, &c2}
|
return [2]*drawImageCommand{&c1, &c2}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *drawImageCommand) quadsNum() int {
|
func (c *drawImageCommand) quadsNum() int {
|
||||||
return len(c.vertices) / 16
|
return len(c.vertices) / quadVertexNum
|
||||||
}
|
}
|
||||||
|
|
||||||
type replacePixelsCommand struct {
|
type replacePixelsCommand struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user