Uniform buffer objects.

Handles blocks of uniform on the GPU.

If WebGL 2 is not available, this class falls back on traditionnal setUniformXXX calls.

For more information, please refer to :
https://www.khronos.org/opengl/wiki/Uniform_Buffer_Object
11149
function UniformBuffer(engine, data, dynamic) {
            this._engine = engine;
            this._noUBO = !engine.supportsUniformBuffers;
            this._dynamic = dynamic;
            this._data = data || [];
            this._uniformLocations = {};
            this._uniformSizes = {};
            this._uniformLocationPointer = 0;
            this._needSync = false;
            if (this._noUBO) {
                this.updateMatrix3x3 = this._updateMatrix3x3ForEffect;
                this.updateMatrix2x2 = this._updateMatrix2x2ForEffect;
                this.updateFloat = this._updateFloatForEffect;
                this.updateFloat2 = this._updateFloat2ForEffect;
                this.updateFloat3 = this._updateFloat3ForEffect;
                this.updateFloat4 = this._updateFloat4ForEffect;
                this.updateMatrix = this._updateMatrixForEffect;
                this.updateVector3 = this._updateVector3ForEffect;
                this.updateVector4 = this._updateVector4ForEffect;
                this.updateColor3 = this._updateColor3ForEffect;
                this.updateColor4 = this._updateColor4ForEffect;
            }
            else {
                this._engine._uniformBuffers.push(this);
                this.updateMatrix3x3 = this._updateMatrix3x3ForUniform;
                this.updateMatrix2x2 = this._updateMatrix2x2ForUniform;
                this.updateFloat = this._updateFloatForUniform;
                this.updateFloat2 = this._updateFloat2ForUniform;
                this.updateFloat3 = this._updateFloat3ForUniform;
                this.updateFloat4 = this._updateFloat4ForUniform;
                this.updateMatrix = this._updateMatrixForUniform;
                this.updateVector3 = this._updateVector3ForUniform;
                this.updateVector4 = this._updateVector4ForUniform;
                this.updateColor3 = this._updateColor3ForUniform;
                this.updateColor4 = this._updateColor4ForUniform;
            }
        }
1242126
function( gl, v, renderer ) {

			var unit = renderer.allocTextureUnit();
			gl.uniform1i( this.addr, unit );
			renderer.setTextureCube( v || emptyCubeTexture, unit );

		}
1285197
function( gl, v ) {

			if ( v.x !== undefined )
				gl.uniform3f( this.addr, v.x, v.y, v.z );
			else if ( v.r !== undefined )
				gl.uniform3f( this.addr, v.r, v.g, v.b );
			else
				gl.uniform3fv( this.addr, v );

		}
1123783
function RenderBuffer( gl, format ){
  this._uid = _UID++;
  this.gl = gl;
  this.id = gl.createRenderbuffer();

  this.width  = 0;
  this.height = 0;
  this.format = format || gl.DEPTH_COMPONENT16;

  this._valid = false;

  // Dummy allocation needed
  // on some platform (chrome 57, osx, nvidia), gl.framebufferRenderbuffer raise 
  // an INVALID_OPERATION if a RB is attached before it storage is set.
  this._storage();

}
177092
function refreshUniformsCommon ( uniforms, material ) {

		uniforms.opacity.value = material.opacity;

		if ( _this.gammaInput ) {

			uniforms.diffuse.value.copyGammaToLinear( material.color );

		} else {

			uniforms.diffuse.value = material.color;

		}

		uniforms.map.texture = material.map;

		if ( material.map ) {

			uniforms.offsetRepeat.value.set( material.map.offset.x, material.map.offset.y, material.map.repeat.x, material.map.repeat.y );

		}

		uniforms.lightMap.texture = material.lightMap;

		uniforms.envMap.texture = material.envMap;
		uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : -1;

		if ( _this.gammaInput ) {

			//uniforms.reflectivity.value = material.reflectivity * material.reflectivity;
			uniforms.reflectivity.value = material.reflectivity;

		} else {

			uniforms.reflectivity.value = material.reflectivity;

		}

		uniforms.refractionRatio.value = material.refractionRatio;
		uniforms.combine.value = material.combine;
		uniforms.useRefract.value = material.envMap && material.envMap.mapping instanceof THREE.CubeRefractionMapping;

	}
1174890
function() {
		var gl = this.gl;

		var buffer = this.buffer = gl.createBuffer();
		gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
		gl.bufferData(
			gl.ARRAY_BUFFER,
			new Float32Array([
				-1.0, -1.0, 
				1.0, -1.0,
				-1.0,  1.0,
				-1.0,  1.0,
				1.0, -1.0,
				1.0,  1.0
			]),
			gl.STATIC_DRAW
		);
	}
717445
def bind_to_uniform_block(self, binding=0, *, offset=0, size=-1) -> None:
        '''
            
        '''

        self.mglo.bind_to_uniform_block(binding, offset, size)
506841
function LGraphChannelsTexture() {
            this.addInput("R", "Texture");
            this.addInput("G", "Texture");
            this.addInput("B", "Texture");
            this.addInput("A", "Texture");

            this.addOutput("Texture", "Texture");

            this.properties = {
                precision: LGraphTexture.DEFAULT,
                R: 1,
                G: 1,
                B: 1,
                A: 1
            };
            this._color = vec4.create();
            this._uniforms = {
                u_textureR: 0,
                u_textureG: 1,
                u_textureB: 2,
                u_textureA: 3,
                u_color: this._color
            };
        }
459285
function createUniformSetter(program, uniformInfo) {
    const location = gl.getUniformLocation(program, uniformInfo.name);
    const isArray = (uniformInfo.size > 1 && uniformInfo.name.substr(-3) === "[0]");
    const type = uniformInfo.type;
    const typeInfo = typeMap[type];
    if (!typeInfo) {
      throw ("unknown type: 0x" + type.toString(16)); // we should never get here.
    }
    let setter;
    if (typeInfo.bindPoint) {
      // it's a sampler
      const unit = textureUnit;
      textureUnit += uniformInfo.size;
      if (isArray) {
        setter = typeInfo.arraySetter(gl, type, unit, location, uniformInfo.size);
      } else {
        setter = typeInfo.setter(gl, type, unit, location, uniformInfo.size);
      }
    } else {
      if (typeInfo.arraySetter && isArray) {
        setter = typeInfo.arraySetter(gl, location);
      } else {
        setter = typeInfo.setter(gl, location);
      }
    }
    setter.location = location;
    return setter;
  }
1030086
function makeLineProgram(gl, data, drawTriangles) {
  let lineProgram = lineProgramCache.get(gl)
  if (!lineProgram) {
    var lineVSShader = gl_utils.compile(gl, gl.VERTEX_SHADER, lineVSSrc);
    var lineFSShader = gl_utils.compile(gl, gl.FRAGMENT_SHADER, lineFSSrc);
    lineProgram = gl_utils.link(gl, lineVSShader, lineFSShader);
    lineProgramCache.set(gl, lineProgram);
  }

  var locations = gl_utils.getLocations(gl, lineProgram);

  var lineBuffer = gl.createBuffer();
  var bpe = data.BYTES_PER_ELEMENT;
  var drawType = drawTriangles ? gl.TRIANGLES : gl.LINES;
  gl.bindBuffer(gl.ARRAY_BUFFER, lineBuffer)
  gl.bufferData(gl.ARRAY_BUFFER, data.byteLength, gl.STATIC_DRAW);
  gl.bufferSubData(gl.ARRAY_BUFFER, 0, data);

  var api = {
    draw,
    dispose
  }

  return api;

  function dispose() {
    gl.deleteBuffer(lineBuffer);
    gl.deleteProgram(lineProgram);
    lineProgramCache.delete(gl);
  }

  function draw(transform, color, screen) {
    if (data.length === 0) return;

    gl.useProgram(lineProgram);

    gl.uniformMatrix4fv(locations.uniforms.uTransform, false, transform.getArray());
    gl.uniform2f(locations.uniforms.uScreenSize, screen.width, screen.height);
    gl.uniform4f(locations.uniforms.uColor, color.r, color.g, color.b, color.a);

    gl.bindBuffer(gl.ARRAY_BUFFER, lineBuffer);
    gl.enableVertexAttribArray(locations.attributes.aPosition)
    // TODO: Avoid buffering, if data hasn't changed?
    gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
    gl.vertexAttribPointer(locations.attributes.aPosition, 2, gl.FLOAT, false, bpe * 2, 0)

    gl.drawArrays(drawType, 0, data.length / 2);
  }
}
79464
def render
      raise ArgumentError, "Block required" unless block_given?
      raise Error, "Can't nest rendering" if rendering?

      $window.flush # Ensure that any drawing _before_ the render block is drawn to screen, rather than into the buffer.

      render_

      @rendering = true

      # Project onto the texture itself, using Gosu (inverted) coordinates.
      Gl.glPushMatrix
      Gl.glMatrixMode Gl::GL_PROJECTION
      Gl.glLoadIdentity
      Gl.glViewport 0, 0, width, height
      Gl.glOrtho 0, width, height, 0, -1, 1

      begin
        yield self
      ensure
        $window.flush # Force all the drawing to draw now!
        Gl.glBindFramebufferEXT Gl::GL_FRAMEBUFFER_EXT, 0

        @rendering = false

        Gl.glPopMatrix

        cache.refresh # Force lazy reloading of the cache.
      end

      self
    end
1062811
function LGraphTextureOperation() {
            this.addInput("Texture", "Texture");
            this.addInput("TextureB", "Texture");
            this.addInput("value", "number");
            this.addOutput("Texture", "Texture");
            this.help =
                "<p>pixelcode must be vec3</p>\
			<p>uvcode must be vec2, is optional</p>\
			<p><strong>uv:</strong> tex. coords</p><p><strong>color:</strong> texture</p><p><strong>colorB:</strong> textureB</p><p><strong>time:</strong> scene time</p><p><strong>value:</strong> input value</p><p>For multiline you must type: result = ...</p>";

            this.properties = {
                value: 1,
                uvcode: "",
                pixelcode: "color + colorB * value",
                precision: LGraphTexture.DEFAULT
            };

			this.has_error = false;
        }
861379
function() {
		this.gl = this.context.gl;
		var gl = this.gl;
		this.vertexBuffer = gl.createBuffer();

		//ignore index buffer if we haven't specified any
		this.indexBuffer = this.numIndices > 0
					? gl.createBuffer()
					: null;

		this.dirty = true;
	}
257041
function LGraphTextureAverage() {
            this.addInput("Texture", "Texture");
            this.addOutput("tex", "Texture");
            this.addOutput("avg", "vec4");
            this.addOutput("lum", "number");
            this.properties = {
                use_previous_frame: true,
                mipmap_offset: 0,
                low_precision: false
            };

            this._uniforms = {
                u_texture: 0,
                u_mipmap_offset: this.properties.mipmap_offset
            };
            this._luminance = new Float32Array(4);
        }
174823
function setValue2fv( gl, v ) {

	var cache = this.cache;

	if ( v.x !== undefined ) {

		if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {

			gl.uniform2f( this.addr, v.x, v.y );

			cache[ 0 ] = v.x;
			cache[ 1 ] = v.y;

		}

	} else {

		if ( arraysEqual( cache, v ) ) return;

		gl.uniform2fv( this.addr, v );

		copyArray( cache, v );

	}

}
360542
function loadGblockModel(url, onProgress) {
  return new Promise(function(resolve, reject) {

    // create unviresal GLTF loader for google blocks
    // this one will inherit methods from GLTF V1 or V2 based on file version
    function GBlockLoader () {
      this.manager = THREE.DefaultLoadingManager
      this.path = THREE.Loader.prototype.extractUrlBase( url )
    }

    // load model
    var loader = new THREE.FileLoader( GBlockLoader.manager )
    loader.setResponseType( 'arraybuffer' )
    loader.load( url, function onLoad( data ) {
      try {

        // convert uint8 to json
        var json = JSON.parse(decodeArrayToString.utf8(data))

        // check GLTF version
        var isGLTF1 = json.asset === undefined || json.asset.version[ 0 ] < 2

        if (isGLTF1) {

          fetchGLTF1Loader().then(function(GLTF1Loader){

            // inherit methods from GLTF V1 loader
            GBlockLoader.prototype = GLTF1Loader.prototype
            var gblockLoader = new GBlockLoader()
            GLTF1Loader.call(gblockLoader)

            // Replace original shaders with placeholders
            Object.keys(json.shaders).forEach(function (key, i) {
              if (key.indexOf('fragment') > -1) json.shaders[key].uri = fragmentShader.base64
              else if (key.indexOf('vertex') > -1) json.shaders[key].uri = vertexShader.base64
            })

            // convert json back to uint8 data
            var modifiedData = new TextEncoder('utf-8').encode(JSON.stringify(json))

            // parse data
            gblockLoader.parse( modifiedData, function onParsingDone (gltf) {

              // FIXME: adapt projection matrix in original shaders and do not replace materials
              (gltf.scene || gltf.scenes[0]).traverse(function (child) {
                if (child.material) child.material = new THREE.MeshPhongMaterial({ vertexColors: THREE.VertexColors })
              })

              // GLTF V1 ready
              resolve(gltf)

            }, gblockLoader.path)

          })

        } else {

          // inferit methods from GLTF V2 loader
          GBlockLoader.prototype = THREE.GLTFLoader.prototype
          var gblockLoader = new GBlockLoader()
          THREE.GLTFLoader.call(gblockLoader)

          // parse data
          gblockLoader.parse( data, gblockLoader.path, resolve, reject)

        }

      } catch ( e ) {

        // For SyntaxError or TypeError, return a generic failure message.
        reject( e.constructor === Error ? e : new Error( 'THREE.GLTFLoader: Unable to parse model.' ) )

      }

    }, onProgress, reject )

  })
}
344223
function createParticleBuffers ( geometry ) {

		geometry.__webglVertexBuffer = _gl.createBuffer();
		geometry.__webglColorBuffer = _gl.createBuffer();

		_this.info.geometries ++;

	}