From c7ca9cb3219e360ab8bc76ef4dedb518546ad8a8 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Thu, 23 Mar 2023 21:22:30 +0900 Subject: [PATCH] ebiten: omit the exceeding part of vertices at Draw* --- image.go | 12 ++++++++++++ internal/graphicscommand/command.go | 3 +-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/image.go b/image.go index ae11f8601..3837aef6c 100644 --- a/image.go +++ b/image.go @@ -413,6 +413,8 @@ 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(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. @@ -432,6 +434,10 @@ func (i *Image) DrawTriangles(vertices []Vertex, indices []uint16, img *Image, o return } + if len(vertices) > graphics.MaxVerticesCount { + // The last part cannot be specified by indices. Just omit them. + vertices = vertices[:graphics.MaxVerticesCount] + } if len(indices)%3 != 0 { panic("ebiten: len(indices) % 3 must be 0") } @@ -563,6 +569,8 @@ var _ [len(DrawTrianglesShaderOptions{}.Images) - graphics.ShaderImageCount]stru // // For the details about the shader, see https://ebitengine.org/en/documents/shader.html. // +// If len(vertices) is more than MaxVerticesCount, 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. @@ -577,6 +585,10 @@ func (i *Image) DrawTrianglesShader(vertices []Vertex, indices []uint16, shader return } + if len(vertices) > graphics.MaxVerticesCount { + // The last part cannot be specified by indices. Just omit them. + vertices = vertices[:graphics.MaxVerticesCount] + } if len(indices)%3 != 0 { panic("ebiten: len(indices) % 3 must be 0") } diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 8f9ddcf80..ba4c82bab 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -92,8 +92,7 @@ func mustUseDifferentVertexBuffer(nextNumVertexFloats int) bool { // EnqueueDrawTrianglesCommand enqueues a drawing-image command. func (q *commandQueue) EnqueueDrawTrianglesCommand(dst *Image, srcs [graphics.ShaderImageCount]*Image, offsets [graphics.ShaderImageCount - 1][2]float32, vertices []float32, indices []uint16, blend graphicsdriver.Blend, dstRegion, srcRegion graphicsdriver.Region, shader *Shader, uniforms []uint32, evenOdd bool) { if len(vertices) > graphics.MaxVertexFloatsCount { - // The last part cannot be specified by indices. Just omit them. - vertices = vertices[:graphics.MaxVertexFloatsCount] + panic(fmt.Sprintf("graphicscommand: len(vertices) must equal to or less than %d but was %d", graphics.MaxVertexFloatsCount, len(vertices))) } split := false