mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/graphics: refactoring: move some constants to internal/graphicscommand
This commit is contained in:
parent
d862a75fb3
commit
3fa8e6ac52
13
image.go
13
image.go
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/builtinshader"
|
"github.com/hajimehoshi/ebiten/v2/internal/builtinshader"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||||
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
"github.com/hajimehoshi/ebiten/v2/internal/ui"
|
||||||
@ -396,10 +397,10 @@ const MaxIndicesNum = MaxIndicesCount
|
|||||||
// MaxVerticesCount is the maximum number of vertices for DrawTriangles and DrawTrianglesShader.
|
// MaxVerticesCount is the maximum number of vertices for DrawTriangles and DrawTrianglesShader.
|
||||||
//
|
//
|
||||||
// Deprecated: as of v2.7. Use MaxVertexCount instead.
|
// Deprecated: as of v2.7. Use MaxVertexCount instead.
|
||||||
const MaxVerticesCount = graphics.MaxVertexCount
|
const MaxVerticesCount = graphicscommand.MaxVertexCount
|
||||||
|
|
||||||
// MaxVertexCount is the maximum number of vertices for DrawTriangles and DrawTrianglesShader.
|
// MaxVertexCount is the maximum number of vertices for DrawTriangles and DrawTrianglesShader.
|
||||||
const MaxVertexCount = graphics.MaxVertexCount
|
const MaxVertexCount = graphicscommand.MaxVertexCount
|
||||||
|
|
||||||
// DrawTriangles draws triangles with the specified vertices and their indices.
|
// DrawTriangles draws triangles with the specified vertices and their indices.
|
||||||
//
|
//
|
||||||
@ -432,9 +433,9 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(vertices) > graphics.MaxVertexCount {
|
if len(vertices) > graphicscommand.MaxVertexCount {
|
||||||
// The last part cannot be specified by indices. Just omit them.
|
// The last part cannot be specified by indices. Just omit them.
|
||||||
vertices = vertices[:graphics.MaxVertexCount]
|
vertices = vertices[:graphicscommand.MaxVertexCount]
|
||||||
}
|
}
|
||||||
if len(indices)%3 != 0 {
|
if len(indices)%3 != 0 {
|
||||||
panic("ebiten: len(indices) % 3 must be 0")
|
panic("ebiten: len(indices) % 3 must be 0")
|
||||||
@ -594,9 +595,9 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader
|
|||||||
panic("ebiten: the given shader to DrawTrianglesShader must not be disposed")
|
panic("ebiten: the given shader to DrawTrianglesShader must not be disposed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(vertices) > graphics.MaxVertexCount {
|
if len(vertices) > graphicscommand.MaxVertexCount {
|
||||||
// The last part cannot be specified by indices. Just omit them.
|
// The last part cannot be specified by indices. Just omit them.
|
||||||
vertices = vertices[:graphics.MaxVertexCount]
|
vertices = vertices[:graphicscommand.MaxVertexCount]
|
||||||
}
|
}
|
||||||
if len(indices)%3 != 0 {
|
if len(indices)%3 != 0 {
|
||||||
panic("ebiten: len(indices) % 3 must be 0")
|
panic("ebiten: len(indices) % 3 must be 0")
|
||||||
|
@ -14,10 +14,6 @@
|
|||||||
|
|
||||||
package graphics
|
package graphics
|
||||||
|
|
||||||
import (
|
|
||||||
"math"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ShaderImageCount = 4
|
ShaderImageCount = 4
|
||||||
|
|
||||||
@ -44,20 +40,6 @@ const (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
VertexFloatCount = 8
|
VertexFloatCount = 8
|
||||||
|
|
||||||
is32bit = 1 >> (^uint(0) >> 63)
|
|
||||||
is64bit = 1 - is32bit
|
|
||||||
|
|
||||||
// MaxVertexCount is the maximum number of vertices for one draw call.
|
|
||||||
//
|
|
||||||
// On 64bit architectures, this value is 2^32-1, as the index type is uint32.
|
|
||||||
// This value cannot be exactly 2^32 especially with WebGL 2, as 2^32th vertex is not rendered correctly.
|
|
||||||
// See https://registry.khronos.org/webgl/specs/latest/2.0/#5.18 .
|
|
||||||
//
|
|
||||||
// On 32bit architectures, this value is an adjusted number so that MaxVertexFloatCount doesn't overflow int.
|
|
||||||
MaxVertexCount = is64bit*math.MaxUint32 + is32bit*(math.MaxInt32/VertexFloatCount)
|
|
||||||
|
|
||||||
MaxVertexFloatCount = MaxVertexCount * VertexFloatCount
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -27,6 +27,22 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
is32bit = 1 >> (^uint(0) >> 63)
|
||||||
|
is64bit = 1 - is32bit
|
||||||
|
|
||||||
|
// MaxVertexCount is the maximum number of vertices for one draw call.
|
||||||
|
//
|
||||||
|
// On 64bit architectures, this value is 2^32-1, as the index type is uint32.
|
||||||
|
// This value cannot be exactly 2^32 especially with WebGL 2, as 2^32th vertex is not rendered correctly.
|
||||||
|
// See https://registry.khronos.org/webgl/specs/latest/2.0/#5.18 .
|
||||||
|
//
|
||||||
|
// On 32bit architectures, this value is an adjusted number so that maxVertexFloatCount doesn't overflow int.
|
||||||
|
MaxVertexCount = is64bit*math.MaxUint32 + is32bit*(math.MaxInt32/graphics.VertexFloatCount)
|
||||||
|
|
||||||
|
maxVertexFloatCount = MaxVertexCount * graphics.VertexFloatCount
|
||||||
|
)
|
||||||
|
|
||||||
var vsyncEnabled int32 = 1
|
var vsyncEnabled int32 = 1
|
||||||
|
|
||||||
func SetVsyncEnabled(enabled bool) {
|
func SetVsyncEnabled(enabled bool) {
|
||||||
@ -81,13 +97,13 @@ func (q *commandQueue) appendIndices(indices []uint32, offset uint32) {
|
|||||||
|
|
||||||
// mustUseDifferentVertexBuffer reports whether a different vertex buffer must be used.
|
// mustUseDifferentVertexBuffer reports whether a different vertex buffer must be used.
|
||||||
func mustUseDifferentVertexBuffer(nextNumVertexFloats int) bool {
|
func mustUseDifferentVertexBuffer(nextNumVertexFloats int) bool {
|
||||||
return nextNumVertexFloats > graphics.MaxVertexFloatCount
|
return nextNumVertexFloats > maxVertexFloatCount
|
||||||
}
|
}
|
||||||
|
|
||||||
// EnqueueDrawTrianglesCommand enqueues a drawing-image command.
|
// EnqueueDrawTrianglesCommand enqueues a drawing-image command.
|
||||||
func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, evenOdd bool) {
|
func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageCount]*Image, vertices []float32, indices []uint32, blend graphicsdriver.Blend, dstRegion image.Rectangle, srcRegions [graphics.ShaderImageCount]image.Rectangle, shader *Shader, uniforms []uint32, evenOdd bool) {
|
||||||
if len(vertices) > graphics.MaxVertexFloatCount {
|
if len(vertices) > maxVertexFloatCount {
|
||||||
panic(fmt.Sprintf("graphicscommand: len(vertices) must equal to or less than %d but was %d", graphics.MaxVertexFloatCount, len(vertices)))
|
panic(fmt.Sprintf("graphicscommand: len(vertices) must equal to or less than %d but was %d", maxVertexFloatCount, len(vertices)))
|
||||||
}
|
}
|
||||||
|
|
||||||
split := false
|
split := false
|
||||||
|
Loading…
Reference in New Issue
Block a user