mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-27 03:02:49 +01:00
graphics: Remove unneeded mutex
This commit is contained in:
parent
c767c0631e
commit
ab7a3e1ab3
@ -20,7 +20,6 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||||
emath "github.com/hajimehoshi/ebiten/internal/math"
|
emath "github.com/hajimehoshi/ebiten/internal/math"
|
||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||||
"github.com/hajimehoshi/ebiten/internal/sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// command represents a drawing command.
|
// command represents a drawing command.
|
||||||
@ -48,8 +47,6 @@ type commandQueue struct {
|
|||||||
// nvertices must <= len(vertices).
|
// nvertices must <= len(vertices).
|
||||||
// vertices is never shrunk since re-extending a vertices buffer is heavy.
|
// vertices is never shrunk since re-extending a vertices buffer is heavy.
|
||||||
nvertices int
|
nvertices int
|
||||||
|
|
||||||
m sync.Mutex
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// theCommandQueue is the command queue for the current process.
|
// theCommandQueue is the command queue for the current process.
|
||||||
@ -72,13 +69,11 @@ func (q *commandQueue) appendVertices(vertices []float32) {
|
|||||||
// EnqueueDrawImageCommand enqueues a drawing-image command.
|
// EnqueueDrawImageCommand enqueues a drawing-image command.
|
||||||
func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float32, color *affine.ColorM, mode opengl.CompositeMode, filter Filter) {
|
func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float32, color *affine.ColorM, mode opengl.CompositeMode, filter Filter) {
|
||||||
// Avoid defer for performance
|
// Avoid defer for performance
|
||||||
q.m.Lock()
|
|
||||||
q.appendVertices(vertices)
|
q.appendVertices(vertices)
|
||||||
if 0 < len(q.commands) {
|
if 0 < len(q.commands) {
|
||||||
last := q.commands[len(q.commands)-1]
|
last := q.commands[len(q.commands)-1]
|
||||||
if last.CanMerge(dst, src, color, mode, filter) {
|
if last.CanMerge(dst, src, color, mode, filter) {
|
||||||
last.AddNumVertices(len(vertices))
|
last.AddNumVertices(len(vertices))
|
||||||
q.m.Unlock()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -91,16 +86,13 @@ func (q *commandQueue) EnqueueDrawImageCommand(dst, src *Image, vertices []float
|
|||||||
filter: filter,
|
filter: filter,
|
||||||
}
|
}
|
||||||
q.commands = append(q.commands, c)
|
q.commands = append(q.commands, c)
|
||||||
q.m.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enqueue enqueues a drawing command other than a draw-image command.
|
// Enqueue enqueues a drawing command other than a draw-image command.
|
||||||
//
|
//
|
||||||
// For a draw-image command, use EnqueueDrawImageCommand.
|
// For a draw-image command, use EnqueueDrawImageCommand.
|
||||||
func (q *commandQueue) Enqueue(command command) {
|
func (q *commandQueue) Enqueue(command command) {
|
||||||
q.m.Lock()
|
|
||||||
q.commands = append(q.commands, command)
|
q.commands = append(q.commands, command)
|
||||||
q.m.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// commandGroups separates q.commands into some groups.
|
// commandGroups separates q.commands into some groups.
|
||||||
@ -136,8 +128,6 @@ func (q *commandQueue) commandGroups() [][]command {
|
|||||||
|
|
||||||
// Flush flushes the command queue.
|
// Flush flushes the command queue.
|
||||||
func (q *commandQueue) Flush() error {
|
func (q *commandQueue) Flush() error {
|
||||||
q.m.Lock()
|
|
||||||
defer q.m.Unlock()
|
|
||||||
// glViewport must be called at least at every frame on iOS.
|
// glViewport must be called at least at every frame on iOS.
|
||||||
opengl.GetContext().ResetViewportSize()
|
opengl.GetContext().ResetViewportSize()
|
||||||
n := 0
|
n := 0
|
||||||
|
@ -18,20 +18,17 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/affine"
|
"github.com/hajimehoshi/ebiten/internal/affine"
|
||||||
"github.com/hajimehoshi/ebiten/internal/math"
|
"github.com/hajimehoshi/ebiten/internal/math"
|
||||||
"github.com/hajimehoshi/ebiten/internal/opengl"
|
"github.com/hajimehoshi/ebiten/internal/opengl"
|
||||||
"github.com/hajimehoshi/ebiten/internal/sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// maxTextureSize is the maximum texture size
|
// maxTextureSize is the maximum texture size
|
||||||
//
|
//
|
||||||
// maxTextureSize also represents the default size (width or height) of viewport.
|
// maxTextureSize also represents the default size (width or height) of viewport.
|
||||||
maxTextureSize = 0
|
maxTextureSize = 0
|
||||||
maxTextureSizeLock sync.Mutex
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// MaxImageSize returns the maximum of width/height of an image.
|
// MaxImageSize returns the maximum of width/height of an image.
|
||||||
func MaxImageSize() int {
|
func MaxImageSize() int {
|
||||||
maxTextureSizeLock.Lock()
|
|
||||||
if maxTextureSize == 0 {
|
if maxTextureSize == 0 {
|
||||||
maxTextureSize = opengl.GetContext().MaxTextureSize()
|
maxTextureSize = opengl.GetContext().MaxTextureSize()
|
||||||
if maxTextureSize == 0 {
|
if maxTextureSize == 0 {
|
||||||
@ -39,7 +36,6 @@ func MaxImageSize() int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
s := maxTextureSize
|
s := maxTextureSize
|
||||||
maxTextureSizeLock.Unlock()
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user