mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38: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
|
||||
}
|
||||
|
||||
type activatedTexture struct {
|
||||
textureNative textureNative
|
||||
index int
|
||||
}
|
||||
|
||||
type Graphics struct {
|
||||
state openGLState
|
||||
context context
|
||||
@ -42,6 +47,10 @@ type Graphics struct {
|
||||
drawCalled bool
|
||||
|
||||
uniformVariableNameCache map[int]string
|
||||
|
||||
// activatedTextures is a set of activated textures.
|
||||
// textureNative cannot be a map key unfortunately.
|
||||
activatedTextures []activatedTexture
|
||||
}
|
||||
|
||||
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
|
||||
loop:
|
||||
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.
|
||||
// Rebinding the same texture seems problematic (#1193).
|
||||
for _, at := range textureToActivatedTexture {
|
||||
for _, at := range g.activatedTextures {
|
||||
if t.native.equal(at.textureNative) {
|
||||
g.context.uniformInt(program, fmt.Sprintf("T%d", i), at.index)
|
||||
continue loop
|
||||
}
|
||||
}
|
||||
|
||||
textureToActivatedTexture = append(textureToActivatedTexture, activatedTexture{
|
||||
g.activatedTextures = append(g.activatedTextures, activatedTexture{
|
||||
textureNative: t.native,
|
||||
index: idx,
|
||||
})
|
||||
@ -336,5 +329,10 @@ loop:
|
||||
idx++
|
||||
}
|
||||
|
||||
for i := range g.activatedTextures {
|
||||
g.activatedTextures[i] = activatedTexture{}
|
||||
}
|
||||
g.activatedTextures = g.activatedTextures[:0]
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user