bindTexture method

void bindTexture(
  1. int webglType,
  2. WebGLTexture? webglTexture, [
  3. int? webglSlot
])

Implementation

void bindTexture(int webglType, WebGLTexture? webglTexture, [int? webglSlot]) {
		if ( webglSlot == null ) {
			if ( currentTextureSlot == null ) {
				webglSlot = WebGL.TEXTURE0 + maxTextures - 1;
			}
    else {
				webglSlot = currentTextureSlot;
			}
		}

  BoundTexture? boundTexture = currentBoundTextures[webglSlot];

  if (boundTexture == null) {
    boundTexture = BoundTexture();
    currentBoundTextures[webglSlot!] = boundTexture;
  }

  if (boundTexture.type != webglType || boundTexture.texture != webglTexture) {
			if ( currentTextureSlot != webglSlot ) {
				gl.activeTexture( webglSlot! );
				currentTextureSlot = webglSlot;
			}

    gl.bindTexture(
      webglType,
      webglTexture ?? emptyTextures[webglType]
    );

    boundTexture.type = webglType;
    boundTexture.texture = webglTexture;
  }
}