Restores any packing state that was set based on the options.
@param {module:twgl.TextureOptions} options A TextureOptions object with whatever parameters you want set.
@param {WebGLRenderingContext} gl the WebGLRenderingContext
@private
323621
function restorePackState(gl, options) {
  if (options.colorspaceConversion !== undefined) {
    gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, lastPackState.colorspaceConversion);
  }
  if (options.premultiplyAlpha !== undefined) {
    gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, lastPackState.premultiplyAlpha);
  }
  if (options.flipY !== undefined) {
    gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, lastPackState.flipY);
  }
}
169046
function SceneNode(gl) {
  this._children = [];
  this._visible = true;
  this._name = name || '';
  this._gl = gl;
  this._order = 1;
}
1366570
function() {
		var gl = this.gl;

		var fragmentShaderSource = [
			"precision mediump float;",
			"uniform sampler2D bgTexture;",
			"uniform sampler2D spriteTexture;",
			"uniform sampler2D prioTexture;",
			"uniform sampler2D paletteTexture;",
			"uniform vec4 bgColor;",
			"varying vec2 texCoord;",

			"void main(void) {",
				"float bgIndex = texture2D(bgTexture, texCoord).r;",
				"float spriteIndex = texture2D(spriteTexture, texCoord).r;",
				"float prioIndex = texture2D(prioTexture, texCoord).r;",
				"float colorIndex = ((spriteIndex > 0.0 && (prioIndex == 0.0 || bgIndex == 0.0)) ? spriteIndex : bgIndex);",
				"vec4 color = texture2D(paletteTexture, vec2( colorIndex * 4.0 + 0.0078, 0.5));", // 0.0078 == ( 0.5 * 3 / 192 ) === ( 0.5 * [RGB colors] / [palette width] )
				"if ( colorIndex > 0.0 ) {",
					"gl_FragColor = color;",
				"} else {",
					"gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);",
					"gl_FragColor = bgColor;",
				"}",
			"}"
		].join("\n");

		var vertexShaderSource = [
			"attribute vec2 vertCoord;",
			"varying vec2 texCoord;",

			"void main() {",
				"gl_Position = vec4(vertCoord, 0, 1);",
				"texCoord = vec2( 0.5 * ( vertCoord.x + 1.0 ), 0.5 * (1.0 - vertCoord.y));",
			"}"
		].join("");

		this.fragmentShader = compileShader( gl.FRAGMENT_SHADER, fragmentShaderSource );
		this.vertexShader = compileShader( gl.VERTEX_SHADER, vertexShaderSource );

		function compileShader( shaderType, shaderSource ) {
			var shader = gl.createShader( shaderType );
			gl.shaderSource( shader, shaderSource );
			gl.compileShader( shader );

			if ( !gl.getShaderParameter( shader, gl.COMPILE_STATUS ) ) {  
				throw ( "An error occurred compiling the shaders: " + gl.getShaderInfoLog( shader ) );
			}

			return shader;
		}
	}
1245623
protected void prepare(GuiRenderer renderer, float x, float y, float z, FontOptions options)
	{
		renderer.next(GL11.GL_QUADS);

		Minecraft.getMinecraft().getTextureManager().bindTexture(textureRl);
		GL11.glPushMatrix();
		GL11.glTranslatef(x, y, 0);

		zIndex = z;
	}
1002470
def set_gl_state(self, preset=None, **kwargs):
        
        self._vshare.gl_state = kwargs
        self._vshare.gl_state['preset'] = preset
1370337
function( gl, v, renderer ) {

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

		}
19959
function Graphics()
{
    Container.call(this);

    /**
     * The alpha value used when filling the Graphics object.
     *
     * @member {number}
     * @default 1
     */
    this.fillAlpha = 1;

    /**
     * The width (thickness) of any lines drawn.
     *
     * @member {number}
     * @default 0
     */
    this.lineWidth = 0;

    /**
     * The color of any lines drawn.
     *
     * @member {string}
     * @default 0
     */
    this.lineColor = 0;

    /**
     * Graphics data
     *
     * @member {GraphicsData[]}
     * @private
     */
    this.graphicsData = [];

    /**
     * The tint applied to the graphic shape. This is a hex value. Apply a value of 0xFFFFFF to reset the tint.
     *
     * @member {number}
     * @default 0xFFFFFF
     */
    this.tint = 0xFFFFFF;

    /**
     * The previous tint applied to the graphic shape. Used to compare to the current tint and check if theres change.
     *
     * @member {number}
     * @private
     * @default 0xFFFFFF
     */
    this._prevTint = 0xFFFFFF;

    /**
     * The blend mode to be applied to the graphic shape. Apply a value of blendModes.NORMAL to reset the blend mode.
     *
     * @member {number}
     * @default CONST.BLEND_MODES.NORMAL;
     */
    this.blendMode = CONST.BLEND_MODES.NORMAL;

    /**
     * Current path
     *
     * @member {GraphicsData}
     * @private
     */
    this.currentPath = null;

    /**
     * Array containing some WebGL-related properties used by the WebGL renderer.
     *
     * @member {object<number, object>}
     * @private
     */
    // TODO - _webgl should use a prototype object, not a random undocumented object...
    this._webGL = {};

    /**
     * Whether this shape is being used as a mask.
     *
     * @member {boolean}
     */
    this.isMask = false;

    /**
     * The bounds' padding used for bounds calculation.
     *
     * @member {number}
     */
    this.boundsPadding = 0;

    /**
     * A cache of the local bounds to prevent recalculation.
     *
     * @member {Rectangle}
     * @private
     */
    this._localBounds = new math.Rectangle(0,0,1,1);

    /**
     * Used to detect if the graphics object has changed. If this is set to true then the graphics
     * object will be recalculated.
     *
     * @member {boolean}
     * @private
     */
    this.dirty = true;

    /**
     * Used to detect if the WebGL graphics object has changed. If this is set to true then the
     * graphics object will be recalculated.
     *
     * @member {boolean}
     * @private
     */
    this.glDirty = false;

    this.boundsDirty = true;

    /**
     * Used to detect if the cached sprite object needs to be updated.
     *
     * @member {boolean}
     * @private
     */
    this.cachedSpriteDirty = false;
}
850029
def set_opengl_implementation(option):
    
    if option == 'software':
        QCoreApplication.setAttribute(Qt.AA_UseSoftwareOpenGL)
        if QQuickWindow is not None:
            QQuickWindow.setSceneGraphBackend(QSGRendererInterface.Software)
    elif option == 'desktop':
        QCoreApplication.setAttribute(Qt.AA_UseDesktopOpenGL)
        if QQuickWindow is not None:
            QQuickWindow.setSceneGraphBackend(QSGRendererInterface.OpenGL)
    elif option == 'gles':
        QCoreApplication.setAttribute(Qt.AA_UseOpenGLES)
        if QQuickWindow is not None:
            QQuickWindow.setSceneGraphBackend(QSGRendererInterface.OpenGL)
815306
function() {
    var gl = this._canvas.gl();
    gl.clearColor(0.0, 0.0, 0.0, 0.0);
    gl.disable(gl.BLEND);
    gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
    gl.clearColor(this._options.background[0], this._options.background[1], 
                  this._options.background[2], 1.0);
    gl.cullFace(gl.FRONT);
    gl.enable(gl.CULL_FACE);
    this._drawWithPass('select');
  }
717028
function updateFramebuffer(ctx, framebuffer, opts) {
  const gl = ctx.gl

  // TODO: if color.length > 1 check for WebGL2 or gl.getExtension('WEBGL_draw_buffers')
  framebuffer.color = opts.color.map((attachment) => {
    const colorAttachment = attachment.texture
      ? attachment
      : { texture: attachment }
    colorAttachment.level = 0 // we can't render to mipmap level other than 0 in webgl
    if (!colorAttachment.target) {
      colorAttachment.target = colorAttachment.texture.target
    }
    return colorAttachment
  })

  if (opts.depth && !opts.depth.texture) {
    opts.depth = { texture: opts.depth }
  }
  framebuffer.depth = opts.depth

  framebuffer.width = framebuffer.color[0].texture.width
  framebuffer.height = framebuffer.color[0].texture.height

  // TODO: ctx push framebuffer
  gl.bindFramebuffer(framebuffer.target, framebuffer.handle)

  framebuffer.drawBuffers.length = 0

  for (let i = 0; i < framebuffer.color.length; i++) {
    const colorAttachment = framebuffer.color[i]
    framebuffer.drawBuffers.push(gl.COLOR_ATTACHMENT0 + i)
    gl.framebufferTexture2D(
      framebuffer.target,
      gl.COLOR_ATTACHMENT0 + i,
      colorAttachment.target,
      colorAttachment.texture.handle,
      colorAttachment.level
    )
  }
  for (
    let i = framebuffer.color.length;
    i < ctx.capabilities.maxColorAttachments;
    i++
  ) {
    gl.framebufferTexture2D(
      framebuffer.target,
      gl.COLOR_ATTACHMENT0 + i,
      gl.TEXTURE_2D,
      null,
      0
    )
  }

  if (framebuffer.depth) {
    if (ctx.debugMode) log('fbo attaching depth', framebuffer.depth)
    const depthAttachment = framebuffer.depth

    if (depthAttachment.texture.target === gl.RENDERBUFFER) {
      gl.framebufferRenderbuffer(
        gl.FRAMEBUFFER,
        gl.DEPTH_ATTACHMENT,
        gl.RENDERBUFFER,
        depthAttachment.texture.handle
      )
    } else {
      gl.framebufferTexture2D(
        gl.FRAMEBUFFER,
        gl.DEPTH_ATTACHMENT,
        depthAttachment.texture.target,
        depthAttachment.texture.handle,
        depthAttachment.level
      )
    }
  } else {
    if (ctx.debugMode) log('fbo deattaching depth')
    gl.framebufferRenderbuffer(
      gl.FRAMEBUFFER,
      gl.DEPTH_ATTACHMENT,
      gl.RENDERBUFFER,
      null
    )
    gl.framebufferTexture2D(
      framebuffer.target,
      gl.DEPTH_ATTACHMENT,
      gl.TEXTURE_2D,
      null,
      0
    )
  }
  var statusStr = []
  statusStr[gl.FRAMEBUFFER_COMPLETE] = 'FRAMEBUFFER_COMPLETE'
  statusStr[gl.FRAMEBUFFER_INCOMPLETE_ATTACHMENT] =
    'FRAMEBUFFER_INCOMPLETE_ATTACHMENT'
  statusStr[gl.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT] =
    'FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT'
  statusStr[gl.FRAMEBUFFER_INCOMPLETE_DIMENSIONS] =
    'FRAMEBUFFER_INCOMPLETE_DIMENSIONS'
  statusStr[gl.FRAMEBUFFER_UNSUPPORTED] = 'FRAMEBUFFER_UNSUPPORTED'
  var fboStatus = gl.checkFramebufferStatus(gl.FRAMEBUFFER)
  assert(
    fboStatus === gl.FRAMEBUFFER_COMPLETE,
    `FBO incomplete ${statusStr[fboStatus]}`
  )

  // TODO: ctx. pop framebuffer
  gl.bindFramebuffer(framebuffer.target, null)
}
160520
function updateTexture(texture, renderState) {
    if (!texture) {
      return;
    }

    console.log('updateTexture ', m_width);
    console.log('updateTexture ', m_height);

    if (texture.width() !== m_width) {
      texture.setWidth(m_width);
    }

    if (texture.height() !== m_height) {
      texture.setHeight(m_height);
    }

    texture.setup(renderState);
  }
1309637
function( wrap ) {
    var gl = this.gl;
    gl.texParameteri( T2D, gl.TEXTURE_WRAP_S, wrap );
    gl.texParameteri( T2D, gl.TEXTURE_WRAP_T, wrap );
  }
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 )

  })
}
550813
function createTextureArray(gl, array) {
  var dtype = array.dtype
  var shape = array.shape.slice()
  var maxSize = gl.getParameter(gl.MAX_TEXTURE_SIZE)
  if(shape[0] < 0 || shape[0] > maxSize || shape[1] < 0 || shape[1] > maxSize) {
    throw new Error('gl-texture2d: Invalid texture size')
  }
  var packed = isPacked(shape, array.stride.slice())
  var type = 0
  if(dtype === 'float32') {
    type = gl.FLOAT
  } else if(dtype === 'float64') {
    type = gl.FLOAT
    packed = false
    dtype = 'float32'
  } else if(dtype === 'uint8') {
    type = gl.UNSIGNED_BYTE
  } else {
    type = gl.UNSIGNED_BYTE
    packed = false
    dtype = 'uint8'
  }
  var format = 0
  if(shape.length === 2) {
    format = gl.LUMINANCE
    shape = [shape[0], shape[1], 1]
    array = ndarray(array.data, shape, [array.stride[0], array.stride[1], 1], array.offset)
  } else if(shape.length === 3) {
    if(shape[2] === 1) {
      format = gl.ALPHA
    } else if(shape[2] === 2) {
      format = gl.LUMINANCE_ALPHA
    } else if(shape[2] === 3) {
      format = gl.RGB
    } else if(shape[2] === 4) {
      format = gl.RGBA
    } else {
      throw new Error('gl-texture2d: Invalid shape for pixel coords')
    }
  } else {
    throw new Error('gl-texture2d: Invalid shape for texture')
  }
  if(type === gl.FLOAT && !gl.getExtension('OES_texture_float')) {
    type = gl.UNSIGNED_BYTE
    packed = false
  }
  var buffer, buf_store
  var size = array.size
  if(!packed) {
    var stride = [shape[2], shape[2]*shape[0], 1]
    buf_store = pool.malloc(size, dtype)
    var buf_array = ndarray(buf_store, shape, stride, 0)
    if((dtype === 'float32' || dtype === 'float64') && type === gl.UNSIGNED_BYTE) {
      convertFloatToUint8(buf_array, array)
    } else {
      ops.assign(buf_array, array)
    }
    buffer = buf_store.subarray(0, size)
  } else if (array.offset === 0 && array.data.length === size) {
    buffer = array.data
  } else {
    buffer = array.data.subarray(array.offset, array.offset + size)
  }
  var tex = initTexture(gl)
  gl.texImage2D(gl.TEXTURE_2D, 0, format, shape[0], shape[1], 0, format, type, buffer)
  if(!packed) {
    pool.free(buf_store)
  }
  return new Texture2D(gl, tex, shape[0], shape[1], format, type)
}
347963
def _use_gl(objs):
    ''' 

    '''
    from ..models.plots import Plot
    return _any(objs, lambda obj: isinstance(obj, Plot) and obj.output_backend == "webgl")
231129
function getTextureFromData(gl, data, opts) {
  if (data instanceof Texture2D) {
    return data;
  }
  return new Texture2D(gl, Object.assign({data}, opts));
}
999151
function freeGLResources(glResources) {
  const gl = glResources.gl;

  // Delete each program
  Object.keys(glResources.programs).forEach((programName) => {
    const program = glResources.programs[programName];
    const shaders = program.shaders;

    let count = shaders.length;

    // Delete shaders
    while (count) {
      count -= 1;
      gl.deleteShader(shaders[count]);
    }

    // Delete program
    gl.deleteProgram(program);
  });

  // Delete framebuffers
  Object.keys(glResources.framebuffers).forEach((fbName) => {
    gl.deleteFramebuffer(glResources.framebuffers[fbName]);
  });

  // Delete textures
  Object.keys(glResources.textures).forEach((textureName) => {
    gl.deleteTexture(glResources.textures[textureName]);
  });

  // Delete buffers
  Object.keys(glResources.buffers).forEach((bufferName) => {
    gl.deleteBuffer(glResources.buffers[bufferName]);
  });
}