Remove most redundant WebGL calls #4136
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resolves #3794
This adds some caching to avoid redundancy with many of the most common GL state updates. This puts a little more stress on the CPU but on three different devices (2 laptops, 1 mobile) this PR doubles the framerate with the manual test examples. The number of GL calls is typically reduced by 100-200%.
GL call statisics (Before and After this PR):
performance/spheres
-- before: 20,0004 -- after: 10,002performance/triangles
-- before: 17,004 -- after: 9,002geometryLit
-- before: 4,801 -- after: 1,644geometryUnlit
-- before: 1,257 -- after: 462textures/multipleTextures
-- before: 214 -- after: 73textures/transparentTexture
-- before: 101 -- after: 36geometryImmediate
-- before: 373 -- after: 148Redundancy is removed with calls to:
gl.uniformXX()
gl.clearColor()
gl.enableVertexAttribArray()
gl.enable()/gl.disable()
gl.depthMask()
gl.blendEquation()/gl.blendFunc()
Two improvements that would help further but aren't present in this PR:
gl.bindBuffer()
andgl.vertexAttribPoint()
but is beyond scope for this.Small unrelated changes made while working on this:
RendererGL.GL
andRendererGL.drawingContext
(consider future removal of RendererGL.GL)