regl-project / regl

👑 Functional WebGL
https://regl-project.github.io/
MIT License
5.22k stars 322 forks source link

basic webggl2 support for those that dont need much from webgl2 #623

Open hrgdavor opened 3 years ago

hrgdavor commented 3 years ago

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 commented 3 years ago

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

rreusser commented 3 years ago

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.

hrgdavor commented 3 years ago

@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']      
    }
Francis-Tao-jinjin commented 1 year ago

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