ebiten: omit the exceeding part of vertices at Draw*

This commit is contained in:
Hajime Hoshi 2023-03-23 21:22:30 +09:00
parent e1386e2032
commit c7ca9cb321
2 changed files with 13 additions and 2 deletions

View File

@ -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")
}

View File

@ -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