Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip empty draw calls in GLMakie #4704

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading