mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/graphicsdriver/opengl: Optimization: Avoid creating slices for every frame
This commit is contained in:
parent
76324254c1
commit
b4f45edff8
@ -28,6 +28,11 @@ func Get() *Graphics {
|
|||||||
return &theGraphics
|
return &theGraphics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type activatedTexture struct {
|
||||||
|
textureNative textureNative
|
||||||
|
index int
|
||||||
|
}
|
||||||
|
|
||||||
type Graphics struct {
|
type Graphics struct {
|
||||||
state openGLState
|
state openGLState
|
||||||
context context
|
context context
|
||||||
@ -42,6 +47,10 @@ type Graphics struct {
|
|||||||
drawCalled bool
|
drawCalled bool
|
||||||
|
|
||||||
uniformVariableNameCache map[int]string
|
uniformVariableNameCache map[int]string
|
||||||
|
|
||||||
|
// activatedTextures is a set of activated textures.
|
||||||
|
// textureNative cannot be a map key unfortunately.
|
||||||
|
activatedTextures []activatedTexture
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Graphics) Begin() {
|
func (g *Graphics) Begin() {
|
||||||
|
@ -297,13 +297,6 @@ func (g *Graphics) useProgram(program program, uniforms []uniformVariable, textu
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type activatedTexture struct {
|
|
||||||
textureNative textureNative
|
|
||||||
index int
|
|
||||||
}
|
|
||||||
|
|
||||||
// textureNative cannot be a map key unfortunately.
|
|
||||||
textureToActivatedTexture := []activatedTexture{}
|
|
||||||
var idx int
|
var idx int
|
||||||
loop:
|
loop:
|
||||||
for i, t := range textures {
|
for i, t := range textures {
|
||||||
@ -313,14 +306,14 @@ loop:
|
|||||||
|
|
||||||
// If the texture is already bound, set the texture variable to point to the texture.
|
// If the texture is already bound, set the texture variable to point to the texture.
|
||||||
// Rebinding the same texture seems problematic (#1193).
|
// Rebinding the same texture seems problematic (#1193).
|
||||||
for _, at := range textureToActivatedTexture {
|
for _, at := range g.activatedTextures {
|
||||||
if t.native.equal(at.textureNative) {
|
if t.native.equal(at.textureNative) {
|
||||||
g.context.uniformInt(program, fmt.Sprintf("T%d", i), at.index)
|
g.context.uniformInt(program, fmt.Sprintf("T%d", i), at.index)
|
||||||
continue loop
|
continue loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textureToActivatedTexture = append(textureToActivatedTexture, activatedTexture{
|
g.activatedTextures = append(g.activatedTextures, activatedTexture{
|
||||||
textureNative: t.native,
|
textureNative: t.native,
|
||||||
index: idx,
|
index: idx,
|
||||||
})
|
})
|
||||||
@ -336,5 +329,10 @@ loop:
|
|||||||
idx++
|
idx++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := range g.activatedTextures {
|
||||||
|
g.activatedTextures[i] = activatedTexture{}
|
||||||
|
}
|
||||||
|
g.activatedTextures = g.activatedTextures[:0]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user