mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
Avoid copying for performance
This commit is contained in:
parent
447bda7d68
commit
1117862d19
@ -41,7 +41,7 @@ func textWidth(str string) int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func drawText(rt *ebiten.Image, str string, ox, oy, scale int, c color.Color) error {
|
func drawText(rt *ebiten.Image, str string, ox, oy, scale int, c color.Color) error {
|
||||||
parts := []ebiten.ImagePart{}
|
parts := make([]ebiten.ImagePart, 0, len(str))
|
||||||
|
|
||||||
locationX, locationY := 0, 0
|
locationX, locationY := 0, 0
|
||||||
for _, c := range str {
|
for _, c := range str {
|
||||||
|
@ -144,7 +144,16 @@ const fieldBlockNumX = 10
|
|||||||
const fieldBlockNumY = 20
|
const fieldBlockNumY = 20
|
||||||
|
|
||||||
func drawBlocks(r *ebiten.Image, blocks [][]BlockType, x, y int, clr ebiten.ColorM) error {
|
func drawBlocks(r *ebiten.Image, blocks [][]BlockType, x, y int, clr ebiten.ColorM) error {
|
||||||
parts := []ebiten.ImagePart{}
|
l := 0
|
||||||
|
for _, blockCol := range blocks {
|
||||||
|
for _, block := range blockCol {
|
||||||
|
if block == BlockTypeNone {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
l++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parts := make([]ebiten.ImagePart, 0, l)
|
||||||
for i, blockCol := range blocks {
|
for i, blockCol := range blocks {
|
||||||
for j, block := range blockCol {
|
for j, block := range blockCol {
|
||||||
if block == BlockTypeNone {
|
if block == BlockTypeNone {
|
||||||
|
4
image.go
4
image.go
@ -63,11 +63,9 @@ func (i *innerImage) drawImage(c *opengl.Context, img *innerImage, options *Draw
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
geo := options.GeoM
|
|
||||||
clr := options.ColorM
|
|
||||||
w, h := img.size()
|
w, h := img.size()
|
||||||
quads := &textureQuads{parts, w, h}
|
quads := &textureQuads{parts, w, h}
|
||||||
return i.framebuffer.DrawTexture(c, img.texture, quads, &geo, &clr)
|
return i.framebuffer.DrawTexture(c, img.texture, quads, &options.GeoM, &options.ColorM)
|
||||||
}
|
}
|
||||||
|
|
||||||
func u(x float64, width int) float32 {
|
func u(x float64, width int) float32 {
|
||||||
|
@ -20,13 +20,13 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func orthoProjectionMatrix(left, right, bottom, top int) [4][4]float64 {
|
func orthoProjectionMatrix(left, right, bottom, top int) *[4][4]float64 {
|
||||||
e11 := float64(2) / float64(right-left)
|
e11 := float64(2) / float64(right-left)
|
||||||
e22 := float64(2) / float64(top-bottom)
|
e22 := float64(2) / float64(top-bottom)
|
||||||
e14 := -1 * float64(right+left) / float64(right-left)
|
e14 := -1 * float64(right+left) / float64(right-left)
|
||||||
e24 := -1 * float64(top+bottom) / float64(top-bottom)
|
e24 := -1 * float64(top+bottom) / float64(top-bottom)
|
||||||
|
|
||||||
return [4][4]float64{
|
return &[4][4]float64{
|
||||||
{e11, 0, 0, e14},
|
{e11, 0, 0, e14},
|
||||||
{0, e22, 0, e24},
|
{0, e22, 0, e24},
|
||||||
{0, 0, 1, 0},
|
{0, 0, 1, 0},
|
||||||
@ -77,7 +77,7 @@ func (f *Framebuffer) setAsViewport(c *opengl.Context) error {
|
|||||||
return c.SetViewport(f.native, width, height)
|
return c.SetViewport(f.native, width, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framebuffer) projectionMatrix() [4][4]float64 {
|
func (f *Framebuffer) projectionMatrix() *[4][4]float64 {
|
||||||
width := internal.NextPowerOf2Int(f.width)
|
width := internal.NextPowerOf2Int(f.width)
|
||||||
height := internal.NextPowerOf2Int(f.height)
|
height := internal.NextPowerOf2Int(f.height)
|
||||||
m := orthoProjectionMatrix(0, width, 0, height)
|
m := orthoProjectionMatrix(0, width, 0, height)
|
||||||
|
@ -18,7 +18,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||||
)
|
)
|
||||||
|
|
||||||
func glMatrix(m [4][4]float64) [16]float32 {
|
func glMatrix(m *[4][4]float64) [16]float32 {
|
||||||
result := [16]float32{}
|
result := [16]float32{}
|
||||||
for j := 0; j < 4; j++ {
|
for j := 0; j < 4; j++ {
|
||||||
for i := 0; i < 4; i++ {
|
for i := 0; i < 4; i++ {
|
||||||
@ -43,7 +43,7 @@ var initialized = false
|
|||||||
// TODO: Use unsafe.SizeOf?
|
// TODO: Use unsafe.SizeOf?
|
||||||
const float32Size = 4
|
const float32Size = 4
|
||||||
|
|
||||||
func DrawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix [4][4]float64, quads TextureQuads, geo Matrix, color Matrix) error {
|
func DrawTexture(c *opengl.Context, texture opengl.Texture, projectionMatrix *[4][4]float64, quads TextureQuads, geo Matrix, color Matrix) error {
|
||||||
// TODO: Check len(quads) and gl.MAX_ELEMENTS_INDICES?
|
// TODO: Check len(quads) and gl.MAX_ELEMENTS_INDICES?
|
||||||
const stride = 4 * 4
|
const stride = 4 * 4
|
||||||
if !initialized {
|
if !initialized {
|
||||||
|
Loading…
Reference in New Issue
Block a user