This commit is contained in:
Ernest Romero Climent 2024-07-02 16:41:05 +09:00 committed by GitHub
commit 32c7fdcfeb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 57 additions and 7 deletions

View File

@ -16,7 +16,6 @@ package ebiten
import (
"fmt"
"sync"
"github.com/hajimehoshi/ebiten/v2/internal/builtinshader"
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
@ -82,14 +81,10 @@ func (s *Shader) appendUniforms(dst []uint32, uniforms map[string]any) []uint32
}
var (
builtinShaders [builtinshader.FilterCount][builtinshader.AddressCount][2]*Shader
builtinShadersM sync.Mutex
builtinShaders [builtinshader.FilterCount][builtinshader.AddressCount][2]*Shader
)
func builtinShader(filter builtinshader.Filter, address builtinshader.Address, useColorM bool) *Shader {
builtinShadersM.Lock()
defer builtinShadersM.Unlock()
func getBuiltinShader(filter builtinshader.Filter, address builtinshader.Address, useColorM bool) *Shader {
var c int
if useColorM {
c = 1

32
shader_notsinglethread.go Normal file
View File

@ -0,0 +1,32 @@
// Copyright 2024 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build !ebitenginesinglethread && !ebitensinglethread
package ebiten
import (
"sync"
"github.com/hajimehoshi/ebiten/v2/internal/builtinshader"
)
var shaderMu sync.Mutex
func builtinShader(filter builtinshader.Filter, address builtinshader.Address, useColorM bool) *Shader {
shaderMu.Lock()
defer shaderMu.Unlock()
return getBuiltinShader(filter, address, useColorM)
}

23
shader_singlethread.go Normal file
View File

@ -0,0 +1,23 @@
// Copyright 2024 The Ebiten Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//go:build ebitenginesinglethread || ebitensinglethread
package ebiten
import "github.com/hajimehoshi/ebiten/v2/internal/builtinshader"
func builtinShader(filter builtinshader.Filter, address builtinshader.Address, useColorM bool) *Shader {
return getBuiltinShader(filter, address, useColorM)
}