setTextureParameters method

void setTextureParameters(
  1. dynamic textureType,
  2. Texture texture,
  3. dynamic supportsMips
)

Implementation

void setTextureParameters(textureType, Texture texture, supportsMips) {
  if (supportsMips) {
    gl.texParameteri(textureType, WebGL.TEXTURE_WRAP_S, wrappingToGL[texture.wrapS]!);
    gl.texParameteri(textureType, WebGL.TEXTURE_WRAP_T, wrappingToGL[texture.wrapT]!);

    if (textureType == WebGL.TEXTURE_3D || textureType == WebGL.TEXTURE_2D_ARRAY) {
      gl.texParameteri(textureType, WebGL.TEXTURE_WRAP_R, wrappingToGL[texture.wrapR]!);
    }

    gl.texParameteri(textureType, WebGL.TEXTURE_MAG_FILTER, filterToGL[texture.magFilter]!);
    gl.texParameteri(textureType, WebGL.TEXTURE_MIN_FILTER, filterToGL[texture.minFilter]!);
  }
  else {
    gl.texParameteri(textureType, WebGL.TEXTURE_WRAP_S, WebGL.CLAMP_TO_EDGE);
    gl.texParameteri(textureType, WebGL.TEXTURE_WRAP_T, WebGL.CLAMP_TO_EDGE);

    if (textureType == WebGL.TEXTURE_3D || textureType == WebGL.TEXTURE_2D_ARRAY) {
      gl.texParameteri(textureType, WebGL.TEXTURE_WRAP_R, WebGL.CLAMP_TO_EDGE);
    }

    if (texture.wrapS != ClampToEdgeWrapping || texture.wrapT != ClampToEdgeWrapping) {
      console.error('WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to ClampToEdgeWrapping.');
    }

    gl.texParameteri(textureType, WebGL.TEXTURE_MAG_FILTER, filterFallback(texture.magFilter));
    gl.texParameteri(textureType, WebGL.TEXTURE_MIN_FILTER, filterFallback(texture.minFilter));

    if (texture.minFilter != NearestFilter && texture.minFilter != LinearFilter) {
      console.error('WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to NearestFilter or LinearFilter.');
    }
  }

  final extension = extensions.get('EXT_texture_filter_anisotropic');

  if (extension != null) {
    if (texture.type == FloatType && extensions.get('OES_texture_float_linear') == null) return;
    if (texture.type == HalfFloatType && (isWebGL2 || extensions.get('OES_texture_half_float_linear') == null)) {
      return;
    }

    if (texture.anisotropy > 1 || properties.get(texture)["__currentAnisotropy"] != null) {
      if (kIsWeb) {
        gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT,math.min(texture.anisotropy, capabilities.getMaxAnisotropy()).toDouble());
      }
      else {
        gl.texParameterf(textureType, WebGL.TEXTURE_MAX_ANISOTROPY_EXT,math.min(texture.anisotropy, capabilities.getMaxAnisotropy()).toDouble());
      }

      properties.get(texture)["__currentAnisotropy"] = texture.anisotropy;
    }
  }
}