Purpose: Create/destroy GL a Render Model for a single tracked device
546007
def setupRenderModelForTrackedDevice(self, unTrackedDeviceIndex):
        ""
        if unTrackedDeviceIndex >= openvr.k_unMaxTrackedDeviceCount:
            return
        # try to find a model we've already set up
        sRenderModelName = getTrackedDeviceString( self.m_pHMD, unTrackedDeviceIndex, openvr.Prop_RenderModelName_String )
        pRenderModel = self.findOrLoadRenderModel( sRenderModelName )
        if pRenderModel is None:        
            sTrackingSystemName = getTrackedDeviceString( self.m_pHMD, unTrackedDeviceIndex, openvr.Prop_TrackingSystemName_String )
            dprintf( "Unable to load render model for tracked device %d (%s.%s)" % (
                    unTrackedDeviceIndex, sTrackingSystemName, sRenderModelName) )
        else:
            self.m_rTrackedDeviceToRenderModel[ unTrackedDeviceIndex ] = pRenderModel
            self.m_rbShowTrackedDevice[ unTrackedDeviceIndex ] = True
1301339
function (outputName, renderer) {
        var outputInfo = this.outputs[outputName];
        var parameters = outputInfo.parameters;
        var parametersCopy = outputInfo._parametersCopy;
        if (!parametersCopy) {
            parametersCopy = outputInfo._parametersCopy = {};
        }
        if (parameters) {
            for (var key in parameters) {
                if (key !== 'width' && key !== 'height') {
                    parametersCopy[key] = parameters[key];
                }
            }
        }
        var width, height;
        if (parameters.width instanceof Function) {
            width = parameters.width.call(this, renderer);
        }
        else {
            width = parameters.width;
        }
        if (parameters.height instanceof Function) {
            height = parameters.height.call(this, renderer);
        }
        else {
            height = parameters.height;
        }
        if (
            parametersCopy.width !== width
            || parametersCopy.height !== height
        ) {
            if (this._outputTextures[outputName]) {
                this._outputTextures[outputName].dispose(renderer.gl);
            }
        }
        parametersCopy.width = width;
        parametersCopy.height = height;

        return parametersCopy;
    }
348611
function (renderer, size) {
        renderer.saveClear();
        var viewport = renderer.viewport;
        var x = 0, y = 0;
        var width = size || viewport.width / 4;
        var height = width;
        if (this.softShadow === ShadowMapPass.VSM) {
            this._outputDepthPass.material.define('fragment', 'USE_VSM');
        }
        else {
            this._outputDepthPass.material.undefine('fragment', 'USE_VSM');
        }
        for (var name in this._textures) {
            var texture = this._textures[name];
            renderer.setViewport(x, y, width * texture.width / texture.height, height);
            this._outputDepthPass.setUniform('depthMap', texture);
            this._outputDepthPass.render(renderer);
            x += width * texture.width / texture.height;
        }
        renderer.setViewport(viewport);
        renderer.restoreClear();
    }
118960
function( gl, v, renderer ) {

			var n = v.length,
				units = allocTexUnits( renderer, n );

			gl.uniform1iv( this.addr, units );

			for ( var i = 0; i !== n; ++ i ) {

				renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );

			}

		}
591765
function render(gl, width, height, dt, batch, shader) {
    time+=dt
    var anim = Math.sin(time/1000)/2+0.5
        
    //clear the batch to zero
    batch.clear()

    //bind before drawing
    batch.bind(shader)

    //push our sprites which may have a variety
    //of textures
    batch.push({
        position: [anim*100, anim*50],
        shape: [128, 128],
        texture: tex2
    })

    batch.push({
        position: [100, 100],
        shape: [128, 128],
        color: [1, 1, 1, 0.5],
        texture: tex
    })
    batch.push({
        position: [300, 100],
        shape: [128, 128],
        color: [1, 1, 1, 0.5],
        texcoord: [0, 0, 2.5, 2.5],
        texture: tex
    })


    batch.push({
        texture: null,
        position: [100+100*Math.sin(time/2000), 100],
        shape: [63, 63],
        color: [anim, 0, 0, 1.0]
    })


    //we need to flush any outstanding sprites
    batch.draw()

    //and unbind it...
    batch.unbind()
}
523812
function() {
    if( this.gl !== null ){
      this.gl.deleteProgram( this.program );
      this.gl.deleteShader(  this.fShader  );
      this.gl.deleteShader(  this.vShader  );
      this.gl = null;
    }
  }
5453
def delete(self):
        
        # We only allow the object from being deleted once, otherwise
        # we might be deleting another GPU object that got our gl-id
        # after our GPU object was deleted. Also note that e.g.
        # DataBufferView does not have the _glir attribute.
        if hasattr(self, '_glir'):
            # Send our final command into the queue
            self._glir.command('DELETE', self._id)
            # Tell master glir queue that this queue is no longer being used
            self._glir._deletable = True
            # Detach the queue
            del self._glir
646297
def expose_init(self, *args):
        
        # Obtain a reference to the OpenGL drawable
        # and rendering context.
        gldrawable = self.get_gl_drawable()
        glcontext = self.get_gl_context()

        # OpenGL begin
        if not gldrawable or not gldrawable.gl_begin(glcontext):
            return False

        # logger.debug("expose_init")

        # Reset buffers
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # Prepare name stack
        glInitNames()
        glPushName(0)
        self.name_counter = 1

        return False
172196
def set_shaders(self, vert, frag):
        
        self._linked = False
        # Create temporary shader objects
        vert_handle = gl.glCreateShader(gl.GL_VERTEX_SHADER)
        frag_handle = gl.glCreateShader(gl.GL_FRAGMENT_SHADER)
        # For both vertex and fragment shader: set source, compile, check
        for code, handle, type_ in [(vert, vert_handle, 'vertex'),
                                    (frag, frag_handle, 'fragment')]:
            gl.glShaderSource(handle, code)
            gl.glCompileShader(handle)
            status = gl.glGetShaderParameter(handle, gl.GL_COMPILE_STATUS)
            if not status:
                errors = gl.glGetShaderInfoLog(handle)
                errormsg = self._get_error(code, errors, 4)
                raise RuntimeError("Shader compilation error in %s:\n%s" %
                                   (type_ + ' shader', errormsg))
        # Attach shaders
        gl.glAttachShader(self._handle, vert_handle)
        gl.glAttachShader(self._handle, frag_handle)
        # Link the program and check
        gl.glLinkProgram(self._handle)
        if not gl.glGetProgramParameter(self._handle, gl.GL_LINK_STATUS):
            raise RuntimeError('Program linking error:\n%s'
                               % gl.glGetProgramInfoLog(self._handle))
        # Now we can remove the shaders. We no longer need them and it
        # frees up precious GPU memory:
        # http://gamedev.stackexchange.com/questions/47910
        gl.glDetachShader(self._handle, vert_handle)
        gl.glDetachShader(self._handle, frag_handle)
        gl.glDeleteShader(vert_handle)
        gl.glDeleteShader(frag_handle)
        # Now we know what variables will be used by the program
        self._unset_variables = self._get_active_attributes_and_uniforms()
        self._handles = {}
        self._known_invalid = set()
        self._linked = True
1339073
public static RenderTarget create (Graphics gfx, final Texture tex) {
    GL20 gl = gfx.gl;
    final int fb = gl.glGenFramebuffer();
    if (fb == 0) throw new RuntimeException("Failed to gen framebuffer: " + gl.glGetError());
    gl.glBindFramebuffer(GL_FRAMEBUFFER, fb);
    gl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.id, 0);
    gl.checkError("RenderTarget.create");
    return new RenderTarget (gfx) {
      public int id () { return fb; }
      public int width () { return tex.pixelWidth; }
      public int height () { return tex.pixelHeight; }
      public float xscale () { return tex.pixelWidth / tex.displayWidth; }
      public float yscale () { return tex.pixelHeight / tex.displayHeight; }
      public boolean flip () { return false; }
    };
  }
1010850
function (renderer, size) {
        if (!renderer.getGLExtension('EXT_shader_texture_lod')) {
            console.warn('Device not support textureCubeLodEXT');
            return;
        }
        if (!this._brdfLookup) {
            this._normalDistribution = cubemapUtil.generateNormalDistribution();
            this._brdfLookup = cubemapUtil.integrateBRDF(renderer, this._normalDistribution);
        }
        var cubemap = this.cubemap;
        if (cubemap.__prefiltered) {
            return;
        }

        var result = cubemapUtil.prefilterEnvironmentMap(
            renderer, cubemap, {
                encodeRGBM: true,
                width: size,
                height: size
            }, this._normalDistribution, this._brdfLookup
        );
        this.cubemap = result.environmentMap;
        this.cubemap.__prefiltered = true;

        cubemap.dispose(renderer);
    }
1242126
function( gl, v, renderer ) {

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

		}
1191013
function( unit ){
    var gl = this.gl;
    if( unit !== undefined ){
      gl.activeTexture( gl.TEXTURE0 + (0|unit) );
    }
    gl.bindTexture( T2D, this.id );
  }
735346
def create_opengl_object(gl_gen_function, n=1):
    """"""
    handle = gl.GLuint(1)
    gl_gen_function(n, byref(handle))  # Create n Empty Objects
    if n > 1:
        return [handle.value + el for el in range(n)]  # Return list of handle values
    else:
        return handle.value
924537
function setValueT1a( gl, v, renderer ) {

	var cache = this.cache;
	var n = v.length;

	var units = allocTexUnits( renderer, n );

	if ( arraysEqual( cache, units ) === false ) {

		gl.uniform1iv( this.addr, units );
		copyArray( cache, units );

	}

	for ( var i = 0; i !== n; ++ i ) {

		renderer.setTexture2D( v[ i ] || emptyTexture, units[ i ] );

	}

}
297099
function updateRenderbuffer(ctx, renderbuffer, opts) {
  Object.assign(renderbuffer, opts)

  const gl = ctx.gl

  assert(
    renderbuffer.pixelFormat === ctx.PixelFormat.Depth16,
    'Only PixelFormat.Depth16 is supported for renderbuffers'
  )
  renderbuffer.format = gl.DEPTH_COMPONENT16

  gl.bindRenderbuffer(renderbuffer.target, renderbuffer.handle)
  gl.renderbufferStorage(
    renderbuffer.target,
    renderbuffer.format,
    renderbuffer.width,
    renderbuffer.height
  )
  gl.bindRenderbuffer(renderbuffer.target, null)
}
968341
public final void render(GL2 gl) {
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();

    gl.glOrtho(0, width, 0, height, -1, +1);
    gl.glColor4f(0f, 0f, 0f, .5f);

    // Fade background:
    gl.glBegin(GL2.GL_QUADS);
    gl.glVertex2f(0f, 0f);
    gl.glVertex2f(width, 0f);
    gl.glVertex2f(width, height);
    gl.glVertex2f(0f, height);
    gl.glEnd();
    
    renderContents(gl);

    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glPopMatrix();
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glPopMatrix();
  }