internal/graphicscommand: add graphics.MaxVertexFloatCount and use it instead of IndicesCount

Updates #2460
This commit is contained in:
Hajime Hoshi 2023-03-23 13:43:47 +09:00
parent 3f2ac129d2
commit 54e2790a06
2 changed files with 16 additions and 3 deletions

View File

@ -14,6 +14,10 @@
package graphics package graphics
import (
"math"
)
const ( const (
ShaderImageCount = 4 ShaderImageCount = 4
@ -49,7 +53,12 @@ const (
const ( const (
IndicesCount = (1 << 16) / 3 * 3 // Adjust num for triangles. TODO: Remove this (#2460). IndicesCount = (1 << 16) / 3 * 3 // Adjust num for triangles. TODO: Remove this (#2460).
)
const (
VertexFloatCount = 8 VertexFloatCount = 8
MaxVertexCount = math.MaxUint16 + 1
MaxVertexFloatCount = MaxVertexCount * VertexFloatCount
) )
var ( var (

View File

@ -86,11 +86,15 @@ func (q *commandQueue) appendIndices(indices []uint16, offset uint16) {
// 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.IndicesCount*graphics.VertexFloatCount return nextNumVertexFloats > graphics.MaxVertexFloatCount
} }
// EnqueueDrawTrianglesCommand enqueues a drawing-image command. // 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) { 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.MaxVertexFloatCount {
panic(fmt.Sprintf("graphicscommand: len(vertices) must not exceed %d but was %d", graphics.MaxVertexFloatCount, len(vertices)))
}
split := false split := false
if mustUseDifferentVertexBuffer(q.tmpNumVertexFloats + len(vertices)) { if mustUseDifferentVertexBuffer(q.tmpNumVertexFloats + len(vertices)) {
q.tmpNumVertexFloats = 0 q.tmpNumVertexFloats = 0