internal/ui: prepare extra capacities for uniform variables

This commit is contained in:
Hajime Hoshi 2022-11-04 03:14:06 +09:00
parent 80e3baae9f
commit 005e87a917

View File

@ -18,6 +18,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
"github.com/hajimehoshi/ebiten/v2/internal/mipmap" "github.com/hajimehoshi/ebiten/v2/internal/mipmap"
"github.com/hajimehoshi/ebiten/v2/internal/shaderir" "github.com/hajimehoshi/ebiten/v2/internal/shaderir"
) )
@ -72,7 +73,8 @@ func (s *Shader) ConvertUniforms(uniforms map[string]any) [][]float32 {
} }
} }
us := make([][]float32, len(s.uniformNameToIndex)) // Allocate a new slice with an extra capacity. This slice's length is extended at internal/graphicscommand.
us := make([][]float32, len(s.uniformNameToIndex), len(s.uniformNameToIndex)+graphics.PreservedUniformVariablesCount)
for name, idx := range s.uniformNameToIndex { for name, idx := range s.uniformNameToIndex {
if v, ok := nameToF32s[name]; ok { if v, ok := nameToF32s[name]; ok {
us[idx] = v us[idx] = v