-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
OpenGL state management system #145
Comments
My dream interface here is to do away with all GL getters / setters in favor of passing all desired state to the |
I've been meaning to have a closer look at the API of glium (Rust OpenGL bindings). It promises:
|
As part of this refactoring, we should merge |
💭 gl2.drawElements({
shader: getShader('circle'),
mode: gl2.TRIANGLES,
// Allow circles to be drawn across boundaries, so that
// large circles are not clipped to tiles
stencilTest: 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']
}
}); |
It'd be cool to build this as an external library, maybe including our |
As long as performance is acceptable, https://github.com/mikolalysenko/regl would be a perfect fit for this. |
As part of this work, I am interested in exploring other abstractions around VAOs |
Noting that regl hit v1.0 today 🎉 http://regl.party/ |
I've come to think that Regl is a poor fit for our project because Regl objects cannot be transferred between threads. I'm envisioning creating a similar interface using flat objects called Note that the interface RendererAtom {
mode: GLEnum;
vertexArrays: Array<StructArray>;
elementArray: StructArray;
vertexProgram: string;
fragmentProgram: string;
stencil: {
enable: boolean;
func: GLEnum;
ref: number;
valueMask: GLEnum;
fail: GLEnum;
depthFail: GLEnum;
pass: GLEnum
};
depth: {
enable: boolean;
func: GLEnum;
rangeNear: number;
rangeFar: number;
};
texture: {
enable: boolean;
width: number;
height: number;
format: GLEnum;
type: GLEnum;
data: ImageData;
wrapS: GLEnum;
wrapT: GLEnum;
minFilter: GLEnum;
magFilter: GLEnum;
mipmap: GLEnum;
};
blend: {
enable: boolean;
sourceFactor: GLEnum;
destFactor: GLEnum;
};
} |
Some cool features of
|
My experience implementing this in mapbox-gl-native:
|
@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, Comments:
Let me know if the code is reviewable in its current state or if we need to further preparations. |
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. |
@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? |
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. |
@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:
|
Closing as an issue without clear next actions — let's open new issues for any specific items we should address. |
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.The text was updated successfully, but these errors were encountered: