Skip to content

Commit

Permalink
skip empty draw calls in GLMakie (#4704)
Browse files Browse the repository at this point in the history
* skip empty draw calls

* fix incorrect number of vertices
  • Loading branch information
ffreyer authored Jan 7, 2025
1 parent 7a95dbc commit 6431881
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions GLMakie/src/GLAbstraction/GLRender.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ end

function render(vao::GLVertexArray{T}, mode::GLenum=GL_TRIANGLES) where T <: TOrSignal{UnitRange{Int}}
r = to_value(vao.indices)
offset = first(r) - 1 # 1 based -> 0 based
ndraw = length(r)
ndraw == 0 && return nothing
offset = first(r) - 1 # 1 based -> 0 based
nverts = length(vao)
if (offset < 0 || offset + ndraw > nverts)
error("Bounds error for drawrange. Offset $(offset) and length $(ndraw) aren't a valid range for vertexarray with length $(nverts)")
Expand All @@ -121,6 +122,7 @@ end

function render(vao::GLVertexArray{T}, mode::GLenum=GL_TRIANGLES) where T <: TOrSignal{Int}
r = to_value(vao.indices)
r == 0 && return nothing
glDrawArrays(mode, 0, r)
return nothing
end
Expand All @@ -129,20 +131,19 @@ end
Renders a vertex array which supplies an indexbuffer
"""
function render(vao::GLVertexArray{GLBuffer{T}}, mode::GLenum=GL_TRIANGLES) where T <: Union{Integer,AbstractFace}
glDrawElements(
mode,
length(vao.indices) * cardinality(vao.indices),
julia2glenum(T), C_NULL
)
return
N = length(vao.indices) * cardinality(vao.indices)
N == 0 && return nothing
glDrawElements(mode, N, julia2glenum(T), C_NULL)
return nothing
end

"""
Renders a normal vertex array only containing the usual buffers buffers.
"""
function render(vao::GLVertexArray, mode::GLenum=GL_TRIANGLES)
length(vao) == 0 && return nothing
glDrawArrays(mode, 0, length(vao))
return
return nothing
end

"""
Expand All @@ -154,16 +155,19 @@ renderinstanced(vao::GLVertexArray, a, primitive=GL_TRIANGLES) = renderinstanced
Renders `amount` instances of an indexed geometry
"""
function renderinstanced(vao::GLVertexArray{GLBuffer{T}}, amount::Integer, primitive=GL_TRIANGLES) where T <: Union{Integer,AbstractFace}
glDrawElementsInstanced(primitive, length(vao.indices) * cardinality(vao.indices), julia2glenum(T), C_NULL, amount)
return
N = length(vao.indices) * cardinality(vao.indices)
N * amount == 0 && return nothing
glDrawElementsInstanced(primitive, N, julia2glenum(T), C_NULL, amount)
return nothing
end

"""
Renders `amount` instances of an not indexed geometry geometry
"""
function renderinstanced(vao::GLVertexArray, amount::Integer, primitive=GL_TRIANGLES)
length(vao) * amount == 0 && return nothing
glDrawElementsInstanced(primitive, length(vao), GL_UNSIGNED_INT, C_NULL, amount)
return
return nothing
end
# handle all uniform objects

Expand Down

0 comments on commit 6431881

Please sign in to comment.