From ce9274a29d6e803bb47e48bb84cf7e9640711083 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 23 Mar 2023 20:01:10 +0900 Subject: [PATCH] ebiten: remove the restriction for len(indices) at Draw* Closes #2460 --- image.go | 18 +++++------------- image_test.go | 6 +++--- internal/graphics/vertex.go | 4 ---- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/image.go b/image.go index 9d2367cba..e1ded5bba 100644 --- a/image.go +++ b/image.go @@ -391,12 +391,14 @@ type DrawTrianglesOptions struct { } // MaxIndicesCount is the maximum number of indices for DrawTriangles and DrawTrianglesShader. -const MaxIndicesCount = graphics.IndicesCount +// +// Deprecated: as of v2.6. This constant is no longer used. +const MaxIndicesCount = (1 << 16) / 3 * 3 // MaxIndicesNum is the maximum number of indices for DrawTriangles and DrawTrianglesShader. // -// Deprecated: as of v2.4. Use MaxIndicesCount instead. -const MaxIndicesNum = graphics.IndicesCount +// Deprecated: as of v2.4. This constant is no longer used. +const MaxIndicesNum = MaxIndicesCount // DrawTriangles draws triangles with the specified vertices and their indices. // @@ -410,8 +412,6 @@ const MaxIndicesNum = graphics.IndicesCount // // If len(indices) is not multiple of 3, DrawTriangles panics. // -// If len(indices) is more than MaxIndicesCount, DrawTriangles panics. -// // The rule in which DrawTriangles works effectively is same as DrawImage's. // // When the given image is disposed, DrawTriangles panics. @@ -430,9 +430,6 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o if len(indices)%3 != 0 { panic("ebiten: len(indices) % 3 must be 0") } - if len(indices) > MaxIndicesCount { - panic("ebiten: len(indices) must be <= MaxIndicesCount") - } // TODO: Check the maximum value of indices and len(vertices)? if options == nil { @@ -556,8 +553,6 @@ var _ [len(DrawTrianglesShaderOptions{}.Images) - graphics.ShaderImageCount]stru // // If len(indices) is not multiple of 3, DrawTrianglesShader panics. // -// If len(indices) is more than MaxIndicesCount, DrawTrianglesShader panics. -// // When a specified image is non-nil and is disposed, DrawTrianglesShader panics. // // When the image i is disposed, DrawTrianglesShader does nothing. @@ -571,9 +566,6 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader if len(indices)%3 != 0 { panic("ebiten: len(indices) % 3 must be 0") } - if len(indices) > MaxIndicesCount { - panic("ebiten: len(indices) must be <= MaxIndicesCount") - } // TODO: Check the maximum value of indices and len(vertices)? if options == nil { diff --git a/image_test.go b/image_test.go index 1101e80ac..6f4f1e28c 100644 --- a/image_test.go +++ b/image_test.go @@ -2742,7 +2742,7 @@ func TestIndicesOverflow(t *testing.T) { op := &ebiten.DrawTrianglesOptions{} vs := make([]ebiten.Vertex, 3) - is := make([]uint16, graphics.IndicesCount/3*3) + is := make([]uint16, graphics.MaxVertexCount/3*3) dst.DrawTriangles(vs, is, src, op) // Cause an overflow for indices. @@ -2813,7 +2813,7 @@ func TestVerticesOverflow(t *testing.T) { src.Fill(color.White) op := &ebiten.DrawTrianglesOptions{} - vs := make([]ebiten.Vertex, graphics.IndicesCount-1) + vs := make([]ebiten.Vertex, graphics.MaxVertexCount-1) is := make([]uint16, 3) dst.DrawTriangles(vs, is, src, op) @@ -2885,7 +2885,7 @@ func TestTooManyVertices(t *testing.T) { src.Fill(color.White) op := &ebiten.DrawTrianglesOptions{} - vs := make([]ebiten.Vertex, graphics.IndicesCount+1) + vs := make([]ebiten.Vertex, graphics.MaxVertexCount+1) is := make([]uint16, 3) dst.DrawTriangles(vs, is, src, op) diff --git a/internal/graphics/vertex.go b/internal/graphics/vertex.go index 00815a57b..7fa2cde87 100644 --- a/internal/graphics/vertex.go +++ b/internal/graphics/vertex.go @@ -51,10 +51,6 @@ const ( 16 // the projection matrix ) -const ( - IndicesCount = (1 << 16) / 3 * 3 // Adjust num for triangles. TODO: Remove this (#2460). -) - const ( VertexFloatCount = 8