regl icon indicating copy to clipboard operation
regl copied to clipboard

basic webggl2 support for those that dont need much from webgl2

Open hrgdavor opened this issue 3 years ago • 4 comments

openjscad uses regl, and looks to move to webgl2 with fall-back to webgl.

https://github.com/jscad/OpenJSCAD.org/pull/878

currently a kind of workaround is used that supplies context instead of canvas element. but some small changes will be needded in regl to support this.

hrgdavor avatar Jul 17 '21 20:07 hrgdavor

After some exploration, look slike geenral support for WEBGL 2 would be difficult for regl. But what would help is some smaller changes that will enable some users to support webgl2.

For example, just giving opengl2 context to regly, OpenJSCAD works just fine. First issue is that we are unable to add some optimizations by using oes_element_index_uint .

oes_element_index_uint works if we use webgl1 but with webgl context we get to impossible situation

  • if we register extension webgl2 complains
  • if we dont regl complains (does not know it is builtin for webgl2)

hrgdavor avatar Jul 20 '21 14:07 hrgdavor

Have you seen this issue? https://github.com/regl-project/regl/issues/561 I'm not quite sure how to use it, but people have taken a stab at ironing out some of the basic compatibility issues. I don't think regl will ever formally support webgl 2 (unless it's a separate webgl2 fork), but I believe people have had enough luck to at least be able to take advantage of some webgl 2 features.

rreusser avatar Jul 20 '21 16:07 rreusser

@rreusser thanks for the link to the wrapper. Ii it comes to that, I might use it, for now this ugly workaround is enough.

  function createContext (canvas, contextAttributes) {
    function get (type) {
      try {
        return {gl:canvas.getContext(type, contextAttributes), type}
      } catch (e) {
        return null
      }
    }
    return (
      get('webgl2') ||
      get('webgl') ||
      get('experimental-webgl') ||
      get('webgl-experimental')
    )
  }

.......
.......

    const {gl, type} = createContext(canvas)
    const options = {gl}
    if(type === 'webgl'){
        options.extensions = ['oes_element_index_uint']      
    }

hrgdavor avatar Jul 20 '21 19:07 hrgdavor

my current workaround is import createREGL from 'regl/dist/regl.unchecked'; + creating webgl2 context by myself, holp this works for you.

Francis-Tao-jinjin avatar May 18 '23 16:05 Francis-Tao-jinjin