From d862a75fb3661266686f74a69cfecd8bd51b9720 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 4 Nov 2023 16:05:26 +0900 Subject: [PATCH] internal/graphics: rename constants Closes #2828 --- image.go | 23 ++++++++++++++--------- internal/graphics/vertex.go | 8 ++++---- internal/graphicscommand/commandqueue.go | 6 +++--- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/image.go b/image.go index 878679618..209f6e252 100644 --- a/image.go +++ b/image.go @@ -394,7 +394,12 @@ const MaxIndicesCount = (1 << 16) / 3 * 3 const MaxIndicesNum = MaxIndicesCount // MaxVerticesCount is the maximum number of vertices for DrawTriangles and DrawTrianglesShader. -const MaxVerticesCount = graphics.MaxVerticesCount +// +// Deprecated: as of v2.7. Use MaxVertexCount instead. +const MaxVerticesCount = graphics.MaxVertexCount + +// MaxVertexCount is the maximum number of vertices for DrawTriangles and DrawTrianglesShader. +const MaxVertexCount = graphics.MaxVertexCount // DrawTriangles draws triangles with the specified vertices and their indices. // @@ -406,11 +411,11 @@ const MaxVerticesCount = graphics.MaxVerticesCount // Vertex contains color values, which are interpreted as straight-alpha colors by default. // This depends on the option's ColorScaleMode. // -// If len(vertices) is more than MaxVerticesCount, the exceeding part is ignored. +// If len(vertices) is more than MaxVertexCount, the exceeding part is ignored. // // If len(indices) is not multiple of 3, DrawTriangles panics. // -// If a value in indices is out of range of vertices, or not less than MaxVerticesCount, DrawTriangles panics. +// If a value in indices is out of range of vertices, or not less than MaxVertexCount, DrawTriangles panics. // // The rule in which DrawTriangles works effectively is same as DrawImage's. // @@ -427,9 +432,9 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o return } - if len(vertices) > graphics.MaxVerticesCount { + if len(vertices) > graphics.MaxVertexCount { // The last part cannot be specified by indices. Just omit them. - vertices = vertices[:graphics.MaxVerticesCount] + vertices = vertices[:graphics.MaxVertexCount] } if len(indices)%3 != 0 { panic("ebiten: len(indices) % 3 must be 0") @@ -567,11 +572,11 @@ var _ [len(DrawTrianglesShaderOptions{}.Images) - graphics.ShaderImageCount]stru // DrawTrianglesShader panics. // If one of the specified image is non-nil and is disposed, DrawTrianglesShader panics. // -// If len(vertices) is more than MaxVerticesCount, the exceeding part is ignored. +// If len(vertices) is more than MaxVertexCount, the exceeding part is ignored. // // If len(indices) is not multiple of 3, DrawTrianglesShader panics. // -// If a value in indices is out of range of vertices, or not less than MaxVerticesCount, DrawTrianglesShader panics. +// If a value in indices is out of range of vertices, or not less than MaxVertexCount, DrawTrianglesShader panics. // // When a specified image is non-nil and is disposed, DrawTrianglesShader panics. // @@ -589,9 +594,9 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader panic("ebiten: the given shader to DrawTrianglesShader must not be disposed") } - if len(vertices) > graphics.MaxVerticesCount { + if len(vertices) > graphics.MaxVertexCount { // The last part cannot be specified by indices. Just omit them. - vertices = vertices[:graphics.MaxVerticesCount] + vertices = vertices[:graphics.MaxVertexCount] } if len(indices)%3 != 0 { panic("ebiten: len(indices) % 3 must be 0") diff --git a/internal/graphics/vertex.go b/internal/graphics/vertex.go index 822cb88c1..2db42c538 100644 --- a/internal/graphics/vertex.go +++ b/internal/graphics/vertex.go @@ -48,16 +48,16 @@ const ( is32bit = 1 >> (^uint(0) >> 63) is64bit = 1 - is32bit - // MaxVerticesCount is the maximum number of vertices for one draw call. + // 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 MaxVertexFloatsCount doesn't overflow int. - MaxVerticesCount = is64bit*math.MaxUint32 + is32bit*(math.MaxInt32/VertexFloatCount) + // On 32bit architectures, this value is an adjusted number so that MaxVertexFloatCount doesn't overflow int. + MaxVertexCount = is64bit*math.MaxUint32 + is32bit*(math.MaxInt32/VertexFloatCount) - MaxVertexFloatsCount = MaxVerticesCount * VertexFloatCount + MaxVertexFloatCount = MaxVertexCount * VertexFloatCount ) var ( diff --git a/internal/graphicscommand/commandqueue.go b/internal/graphicscommand/commandqueue.go index 68e76c5b7..eda936e81 100644 --- a/internal/graphicscommand/commandqueue.go +++ b/internal/graphicscommand/commandqueue.go @@ -81,13 +81,13 @@ func (q *commandQueue) appendIndices(indices []uint32, offset uint32) { // mustUseDifferentVertexBuffer reports whether a different vertex buffer must be used. func mustUseDifferentVertexBuffer(nextNumVertexFloats int) bool { - return nextNumVertexFloats > graphics.MaxVertexFloatsCount + return nextNumVertexFloats > graphics.MaxVertexFloatCount } // 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) { - if len(vertices) > graphics.MaxVertexFloatsCount { - panic(fmt.Sprintf("graphicscommand: len(vertices) must equal to or less than %d but was %d", graphics.MaxVertexFloatsCount, len(vertices))) + if len(vertices) > graphics.MaxVertexFloatCount { + panic(fmt.Sprintf("graphicscommand: len(vertices) must equal to or less than %d but was %d", graphics.MaxVertexFloatCount, len(vertices))) } split := false