daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Dec 7th, 2018 68 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. function isBuiltIn(name: string): boolean {
  2.     return name.startsWith("gl_") || name.startsWith("webgl_");
  3. }
  4.  
  5. export function getAttribSetters(gl: WebGL2RenderingContext, program: WebGLProgram): void {
  6.     const numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
  7.  
  8.     const uniformSetters: { [key: string]: any } = {};
  9.  
  10.     for(let i = 0; i < numUniforms; ++i) {
  11.         const uniformInfo = gl.getActiveUniform(program, i);
  12.         if(!uniformInfo || isBuiltIn(uniformInfo.name)) {
  13.             continue;
  14.         }
  15.  
  16.         let name = uniformInfo.name;
  17.         if(name.substr(-3) === "[0]") {
  18.             name = name.substr(0, name.length - 3);
  19.         }
  20.         const setter = createUniformSetter(gl, program, uniformInfo);
  21.     }
  22. }
  23.  
  24. // This gets set the first time getUniformSetters() is called to avoid circular dependency problems
  25. let uniformSetters: Array<[GLUniformType, typeof GLSetter]> | undefined;
  26.  
  27. function getUniformSetter(type: GLUniformType): typeof GLSetter | undefined {
  28.     if(!uniformSetters) {
  29.         uniformSetters = [
  30.             [GLUniformType.INT, GLIntSetter],
  31.             [GLUniformType.BOOL, GLIntSetter],
  32.             [GLUniformType.FLOAT, GLFloatSetter],
  33.             [GLUniformType.VEC2, GLVec2Setter],
  34.             [GLUniformType.VEC3, GLVec3Setter],
  35.             [GLUniformType.VEC4, GLVec4Setter],
  36.             [GLUniformType.MAT2, GLMat2Setter],
  37.             [GLUniformType.MAT3, GLMat3Setter],
  38.             [GLUniformType.MAT4, GLMat4Setter],
  39.             [GLUniformType.SAMPLER2D, GLSampler2DSetter],
  40.         ];
  41.     }
  42.  
  43.     let setter: typeof GLSetter | undefined;
  44.     for(const i in uniformSetters) {
  45.         if(!uniformSetters[i]) { continue; }
  46.         if(uniformSetters[i][0] === type) {
  47.             setter = uniformSetters[i][1];
  48.         }
  49.     }
  50.  
  51.     return setter;
  52. }
  53.  
  54. function createUniformSetter(gl: WebGL2RenderingContext, program: WebGLProgram, info: WebGLActiveInfo): void {
  55.     const loc = gl.getUniformLocation(program, info.name);
  56.     const isArray = (info.size > 1 && info.name.substr(-3) === "[0]");
  57.     const type = info.type;
  58.     const typeInfo = getUniformSetter(type);
  59.     if(!typeInfo) {
  60.         throw new Error(`Program uniform '${info.name}' type 0x${type.toString(16)} is unavailable.`);
  61.     }
  62.  
  63.     // TODO: Finish creating uniform setters https://github.com/greggman/twgl.js/blob/master/src/programs.js#L840
  64. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top