You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should maintain all current state in the painter object so that we can avoid doing redundant calls (e.g. to bind buffers or switch shaders). Some of that is already done in the switchShader code, but we're still happily binding buffers repeatedly and setting other WebGL state that isn't strictly necessary.
My dream interface here is to do away with all GL getters / setters in favor of passing all desired state to the draw* call as an object. This is a clean abstraction that will allow us to run the smallest possible # of WebGL api calls, prevent bugs stemming from unexpected GL state, and make our code easier to understand.
I've been meaning to have a closer look at the API of glium (Rust OpenGL bindings). It promises:
Glium is stateless. There are no set_something() functions in the entire library, and everything is done by parameter passing. The same set of function calls will always produce the same results, which greatly reduces the number of potential problems.
gl2.drawElements({shader: getShader('circle'),mode: gl2.TRIANGLES,// Allow circles to be drawn across boundaries, so that// large circles are not clipped to tilesstencilTest: false,depthMask: false,depthSubrange: getDepthSubrange(0),count: group.getCount(),offset: group.getOffset(),elementBuffer: group.getElementBuffer(),vertexBuffer: group.getVertexBuffer(),attributes: {a_pos: group.getVertexBuffer().pos,},uniforms: {u_exmatrix: transform.exMatrix,u_posmatrix: translatePosMatrix(calculatePosMatrix(coord,source.maxzoom),tile,layer.paint['circle-translate'],layer.paint['circle-translate-anchor']),u_color: util.premultiply(layer.paint['circle-color'],layer.paint['circle-opacity']),u_blur: Math.max(layer.paint['circle-blur'],1/browser.devicePixelRatio/layer.paint['circle-radius'])),u_size: layer.paint['circle-radius']}});
@kkaefer Based on our discussion, we (the luma.gl/deck.gl team) would like to propose the following stand-alone webgl state management system: trackContextState as a possible base for enabling on a true WebGL plugin API in mapbox-gl-js.
In its current incarnation, this state management system basically offers three functions, trackContextState(gl), pushContextState(gl) and popContextState(gl).
Comments:
While this code is currently part of the luma.gl repository, it has no dependencies on luma and is in the completely independent base webgl-utils folder.
We can make this available as a separate repository + npm module (or you could copy the code and use this as a base as you see fit).
Currently this only covers context parameters, but it can be extend it based on your requirements, for instance to also cover buffer bindings etc. You'll need to set the requirements here.
This module currently also caches state access for speed. If you already have similar solutions we can make sure we disable that part for you.
As discussed we might be able to collaborate on/support you on a PR to help you integrate this, should you like it.
Let me know if the code is reviewable in its current state or if we need to further preparations.
The following files are of interest:
There don't seem to be any clear next actions here after we started tracking most of the GL state. Should we close this @kkaefer? We could outline any potential remaining work in a new ticket.
maybe we should sync to make sure our two state tracking systems are compatible?
While this would be nice, do you think the benefits here would be significant? My guess would be that cost of assuming the state is undefined when you switch between libraries once or twice a frame should be pretty insignificant.
do you think the benefits of [syncing to make sure our systems are compatible] would be significant?
If there aren't any problems there should not be a need to spend much time on this. That said it doesn't hurt if we understand each other's systems.
Some observations looking at your code:
Looks like you are building a nice typesafe wrapper class on top of the WebGLContext.
Our implementation is more raw, it replaces functions on the webgl context itself.
So in that sense, our implementations do not clash. Thoughts:
We can track all changes to the context, including the ones your Context class make, as your methods ultimately hit the gl... methods
However, as far as I can tell, you may not see changes that we make to the context.
Our solution has push state and pop state (save and restore), I couldn't see if you have functions that completely restores a context or just per-setting management.
Activity
lucaswoj commentedon Dec 14, 2015
My dream interface here is to do away with all GL getters / setters in favor of passing all desired state to the
draw*call as an object. This is a clean abstraction that will allow us to run the smallest possible # of WebGL api calls, prevent bugs stemming from unexpected GL state, and make our code easier to understand.jfirebaugh commentedon Dec 17, 2015
I've been meaning to have a closer look at the API of glium (Rust OpenGL bindings). It promises:
lucaswoj commentedon Jan 21, 2016
As part of this refactoring, we should merge
Painterandgl_utilslucaswoj commentedon Mar 2, 2016
💭
lucaswoj commentedon Mar 2, 2016
It'd be cool to build this as an external library, maybe including our
Bufferimplementation too.lucaswoj commentedon Mar 3, 2016
http://jsperf.com/webgl-api-calls/2
lucaswoj commentedon Jun 1, 2016
As long as performance is acceptable, https://github.com/mikolalysenko/regl would be a perfect fit for this.
lucaswoj commentedon Jul 28, 2016
As part of this work, I am interested in exploring other abstractions around VAOs
16 remaining items
[-]Maintain state in renderer to avoid redundant calls[/-][+]OpenGL state management system[/+]ibgreen commentedon Jun 26, 2017
@kkaefer Based on our discussion, we (the luma.gl/deck.gl team) would like to propose the following stand-alone webgl state management system: trackContextState as a possible base for enabling on a true WebGL plugin API in mapbox-gl-js.
In its current incarnation, this state management system basically offers three functions,
trackContextState(gl),pushContextState(gl)andpopContextState(gl).Comments:
luma.glrepository, it has no dependencies on luma and is in the completely independent basewebgl-utilsfolder.Let me know if the code is reviewable in its current state or if we need to further preparations.
The following files are of interest:
mourner commentedon Mar 1, 2019
There don't seem to be any clear next actions here after we started tracking most of the GL state. Should we close this @kkaefer? We could outline any potential remaining work in a new ticket.
ibgreen commentedon Mar 1, 2019
@mourner Just an update from our side, we have now published our WebGL state tracker as a separate module.
Since it sounds like you have rolled your own system, maybe we should sync to make sure our two state tracking systems are compatible?
Ours is based on WebGL context interception and is thus very generic, is that how you also went about things?
CC: @Pessimistress @tsherif
chloekraw commentedon Apr 10, 2019
cc/ @ansis @asheemmamoowala
ansis commentedon Apr 10, 2019
Our implementation can mostly be found in https://github.com/mapbox/mapbox-gl-js/blob/master/src/gl/value.js and https://github.com/mapbox/mapbox-gl-js/blob/master/src/gl/context.js. I'm not that familiar with the design choices behind our implementation.
While this would be nice, do you think the benefits here would be significant? My guess would be that cost of assuming the state is undefined when you switch between libraries once or twice a frame should be pretty insignificant.
ibgreen commentedon Apr 10, 2019
@ansis Thanks.
If there aren't any problems there should not be a need to spend much time on this. That said it doesn't hurt if we understand each other's systems.
Some observations looking at your code:
So in that sense, our implementations do not clash. Thoughts:
mourner commentedon Sep 11, 2019
Closing as an issue without clear next actions — let's open new issues for any specific items we should address.