mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 02:38:53 +01:00
internal/graphicscommand: reland: add graphics.MaxVertexFloatCount and use it instead of IndicesCount
This change is reland of 54e2790a06
but with a fix for WebGL. Also, this changes the logic when len(vertices)
exceeds the maximum: just remove the last part.
Updates #2460
This commit is contained in:
parent
c59bcbdb5b
commit
81581df2b9
@ -14,6 +14,10 @@
|
||||
|
||||
package graphics
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
const (
|
||||
ShaderImageCount = 4
|
||||
|
||||
@ -48,8 +52,18 @@ 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
|
||||
|
||||
// MaxVertexCount is the maximum number of vertices for one draw call.
|
||||
// This value is 2^16 - 1 = 65535, as the index type is uint16.
|
||||
// This value cannot be exactly 2^16 == 65536 especially with WebGL 2, as 65536th vertex is not rendered correctly.
|
||||
// See https://registry.khronos.org/webgl/specs/latest/2.0/#5.18 .
|
||||
MaxVertexCount = math.MaxUint16
|
||||
MaxVertexFloatCount = MaxVertexCount * VertexFloatCount
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -86,11 +86,16 @@ func (q *commandQueue) appendIndices(indices []uint16, offset uint16) {
|
||||
|
||||
// mustUseDifferentVertexBuffer reports whether a different vertex buffer must be used.
|
||||
func mustUseDifferentVertexBuffer(nextNumVertexFloats int) bool {
|
||||
return nextNumVertexFloats > graphics.IndicesCount*graphics.VertexFloatCount
|
||||
return nextNumVertexFloats > graphics.MaxVertexFloatCount
|
||||
}
|
||||
|
||||
// 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.MaxVertexFloatCount {
|
||||
// The last part cannot be specified by indices. Just omit them.
|
||||
vertices = vertices[:graphics.MaxVertexFloatCount]
|
||||
}
|
||||
|
||||
split := false
|
||||
if mustUseDifferentVertexBuffer(q.tmpNumVertexFloats + len(vertices)) {
|
||||
q.tmpNumVertexFloats = 0
|
||||
|
Loading…
Reference in New Issue
Block a user