Skip to content

Commit

Permalink
Cleanup Texture and WebglTexture to remove WebGL1 functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Valigursky committed Apr 26, 2024
1 parent 6ecaaad commit e744355
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 104 deletions.
22 changes: 11 additions & 11 deletions src/platform/graphics/texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Texture {
* @param {string} [options.name] - The name of the texture. Defaults to null.
* @param {number} [options.width] - The width of the texture in pixels. Defaults to 4.
* @param {number} [options.height] - The height of the texture in pixels. Defaults to 4.
* @param {number} [options.depth] - The number of depth slices in a 3D texture (not supported by WebGl1).
* @param {number} [options.depth] - The number of depth slices in a 3D texture.
* @param {number} [options.format] - The pixel format of the texture. Can be:
*
* - {@link PIXELFORMAT_A8}
Expand Down Expand Up @@ -128,9 +128,9 @@ class Texture {
* Defaults to false.
* @param {number} [options.arrayLength] - Specifies whether the texture is to be a 2D texture array.
* When passed in as undefined or < 1, this is not an array texture. If >= 1, this is an array texture.
* (not supported by WebGL1). Defaults to undefined.
* @param {boolean} [options.volume] - Specifies whether the texture is to be a 3D volume
* (not supported by WebGL1). Defaults to false.
* Defaults to undefined.
* @param {boolean} [options.volume] - Specifies whether the texture is to be a 3D volume.
* Defaults to false.
* @param {string} [options.type] - Specifies the texture type. Can be:
*
* - {@link TEXTURETYPE_DEFAULT}
Expand All @@ -150,10 +150,10 @@ class Texture {
* present) is multiplied into the color channels. Defaults to false.
* @param {boolean} [options.compareOnRead] - When enabled, and if texture format is
* {@link PIXELFORMAT_DEPTH} or {@link PIXELFORMAT_DEPTHSTENCIL}, hardware PCF is enabled for
* this texture, and you can get filtered results of comparison using texture() in your shader
* (not supported by WebGL1). Defaults to false.
* @param {number} [options.compareFunc] - Comparison function when compareOnRead is enabled
* (not supported by WebGL1). Can be:
* this texture, and you can get filtered results of comparison using texture() in your shader.
* Defaults to false.
* @param {number} [options.compareFunc] - Comparison function when compareOnRead is enabled.
* Can be:
*
* - {@link FUNC_LESS}
* - {@link FUNC_LESSEQUAL}
Expand Down Expand Up @@ -485,7 +485,7 @@ class Texture {
}

/**
* The addressing mode to be applied to the 3D texture depth (not supported on WebGL1). Can be:
* The addressing mode to be applied to the 3D texture depth. Can be:
*
* - {@link ADDRESS_REPEAT}
* - {@link ADDRESS_CLAMP_TO_EDGE}
Expand All @@ -512,7 +512,7 @@ class Texture {
/**
* When enabled, and if texture format is {@link PIXELFORMAT_DEPTH} or
* {@link PIXELFORMAT_DEPTHSTENCIL}, hardware PCF is enabled for this texture, and you can get
* filtered results of comparison using texture() in your shader (not supported on WebGL1).
* filtered results of comparison using texture() in your shader.
*
* @type {boolean}
*/
Expand All @@ -528,7 +528,7 @@ class Texture {
}

/**
* Comparison function when compareOnRead is enabled (not supported on WebGL1). Possible values:
* Comparison function when compareOnRead is enabled. Possible values:
*
* - {@link FUNC_LESS}
* - {@link FUNC_LESSEQUAL}
Expand Down
141 changes: 48 additions & 93 deletions src/platform/graphics/webgl/webgl-texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ class WebglTexture {
break;
case PIXELFORMAT_RGB8:
this._glFormat = gl.RGB;
this._glInternalFormat = device.isWebGL2 ? gl.RGB8 : gl.RGB;
this._glInternalFormat = gl.RGB8;
this._glPixelType = gl.UNSIGNED_BYTE;
break;
case PIXELFORMAT_RGBA8:
this._glFormat = gl.RGBA;
this._glInternalFormat = device.isWebGL2 ? gl.RGBA8 : gl.RGBA;
this._glInternalFormat = gl.RGBA8;
this._glPixelType = gl.UNSIGNED_BYTE;
break;
case PIXELFORMAT_DXT1:
Expand Down Expand Up @@ -197,202 +197,157 @@ class WebglTexture {
this._glInternalFormat = device.extCompressedTextureATC.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL;
break;
case PIXELFORMAT_R16F:
if (device.isWebGL2) {
this._glFormat = gl.RED;
this._glInternalFormat = gl.R16F;
this._glPixelType = gl.HALF_FLOAT;
} else {
this._glFormat = gl.LUMINANCE;
this._glInternalFormat = gl.LUMINANCE;
this._glPixelType = device.extTextureHalfFloat.HALF_FLOAT_OES;
}
this._glFormat = gl.RED;
this._glInternalFormat = gl.R16F;
this._glPixelType = gl.HALF_FLOAT;
break;
case PIXELFORMAT_RG16F:
if (device.isWebGL2) {
this._glFormat = gl.RG;
this._glInternalFormat = gl.RG16F;
this._glPixelType = gl.HALF_FLOAT;
} else {
this._glFormat = gl.RG;
this._glInternalFormat = gl.RG;
this._glPixelType = device.extTextureHalfFloat.HALF_FLOAT_OES;
}
this._glFormat = gl.RG;
this._glInternalFormat = gl.RG16F;
this._glPixelType = gl.HALF_FLOAT;
break;
case PIXELFORMAT_RGB16F:
// definition varies between WebGL1 and 2
this._glFormat = gl.RGB;
if (device.isWebGL2) {
this._glInternalFormat = gl.RGB16F;
this._glPixelType = gl.HALF_FLOAT;
} else {
this._glInternalFormat = gl.RGB;
this._glPixelType = device.extTextureHalfFloat.HALF_FLOAT_OES;
}
this._glInternalFormat = gl.RGB16F;
this._glPixelType = gl.HALF_FLOAT;
break;
case PIXELFORMAT_RGBA16F:
// definition varies between WebGL1 and 2
this._glFormat = gl.RGBA;
if (device.isWebGL2) {
this._glInternalFormat = gl.RGBA16F;
this._glPixelType = gl.HALF_FLOAT;
} else {
this._glInternalFormat = gl.RGBA;
this._glPixelType = device.extTextureHalfFloat.HALF_FLOAT_OES;
}
this._glInternalFormat = gl.RGBA16F;
this._glPixelType = gl.HALF_FLOAT;
break;
case PIXELFORMAT_RGB32F:
// definition varies between WebGL1 and 2
this._glFormat = gl.RGB;
if (device.isWebGL2) {
this._glInternalFormat = gl.RGB32F;
} else {
this._glInternalFormat = gl.RGB;
}
this._glInternalFormat = gl.RGB32F;
this._glPixelType = gl.FLOAT;
break;
case PIXELFORMAT_RGBA32F:
// definition varies between WebGL1 and 2
this._glFormat = gl.RGBA;
if (device.isWebGL2) {
this._glInternalFormat = gl.RGBA32F;
} else {
this._glInternalFormat = gl.RGBA;
}
this._glInternalFormat = gl.RGBA32F;
this._glPixelType = gl.FLOAT;
break;
case PIXELFORMAT_R32F: // WebGL2 only
case PIXELFORMAT_R32F:
this._glFormat = gl.RED;
this._glInternalFormat = gl.R32F;
this._glPixelType = gl.FLOAT;
break;
case PIXELFORMAT_DEPTH:
if (device.isWebGL2) {
// native WebGL2
this._glFormat = gl.DEPTH_COMPONENT;
this._glInternalFormat = gl.DEPTH_COMPONENT32F; // should allow 16/24 bits?
this._glPixelType = gl.FLOAT;
} else {
// using WebGL1 extension
this._glFormat = gl.DEPTH_COMPONENT;
this._glInternalFormat = gl.DEPTH_COMPONENT;
this._glPixelType = gl.UNSIGNED_SHORT; // the only acceptable value?
}
this._glFormat = gl.DEPTH_COMPONENT;
this._glInternalFormat = gl.DEPTH_COMPONENT32F; // should allow 16/24 bits?
this._glPixelType = gl.FLOAT;
break;
case PIXELFORMAT_DEPTHSTENCIL:
this._glFormat = gl.DEPTH_STENCIL;
if (device.isWebGL2) {
this._glInternalFormat = gl.DEPTH24_STENCIL8;
this._glPixelType = gl.UNSIGNED_INT_24_8;
} else {
this._glInternalFormat = gl.DEPTH_STENCIL;
this._glPixelType = device.extDepthTexture.UNSIGNED_INT_24_8_WEBGL;
}
this._glInternalFormat = gl.DEPTH24_STENCIL8;
this._glPixelType = gl.UNSIGNED_INT_24_8;
break;
case PIXELFORMAT_111110F: // WebGL2 only
Debug.assert(device.isWebGL2, "PIXELFORMAT_111110F texture format is not supported by WebGL1.");
case PIXELFORMAT_111110F:
this._glFormat = gl.RGB;
this._glInternalFormat = gl.R11F_G11F_B10F;
this._glPixelType = gl.UNSIGNED_INT_10F_11F_11F_REV;
break;
case PIXELFORMAT_SRGB: // WebGL2 only
case PIXELFORMAT_SRGB:
this._glFormat = gl.RGB;
this._glInternalFormat = gl.SRGB8;
this._glPixelType = gl.UNSIGNED_BYTE;
break;
case PIXELFORMAT_SRGBA: // WebGL2 only
case PIXELFORMAT_SRGBA:
this._glFormat = gl.RGBA;
this._glInternalFormat = gl.SRGB8_ALPHA8;
this._glPixelType = gl.UNSIGNED_BYTE;
break;
// Integer texture formats (R) (WebGL2 only)
case PIXELFORMAT_R8I: // WebGL2 only

// Integer texture formats (R)
case PIXELFORMAT_R8I:
this._glFormat = gl.RED_INTEGER;
this._glInternalFormat = gl.R8I;
this._glPixelType = gl.BYTE;
break;
case PIXELFORMAT_R8U: // WebGL2 only
case PIXELFORMAT_R8U:
this._glFormat = gl.RED_INTEGER;
this._glInternalFormat = gl.R8UI;
this._glPixelType = gl.UNSIGNED_BYTE;
break;
case PIXELFORMAT_R16I: // WebGL2 only
case PIXELFORMAT_R16I:
this._glFormat = gl.RED_INTEGER;
this._glInternalFormat = gl.R16I;
this._glPixelType = gl.SHORT;
break;
case PIXELFORMAT_R16U: // WebGL2 only
case PIXELFORMAT_R16U:
this._glFormat = gl.RED_INTEGER;
this._glInternalFormat = gl.R16UI;
this._glPixelType = gl.UNSIGNED_SHORT;
break;
case PIXELFORMAT_R32I: // WebGL2 only
case PIXELFORMAT_R32I:
this._glFormat = gl.RED_INTEGER;
this._glInternalFormat = gl.R32I;
this._glPixelType = gl.INT;
break;
case PIXELFORMAT_R32U: // WebGL2 only
case PIXELFORMAT_R32U:
this._glFormat = gl.RED_INTEGER;
this._glInternalFormat = gl.R32UI;
this._glPixelType = gl.UNSIGNED_INT;
break;
// Integer texture formats (RG) (WebGL2 only)
case PIXELFORMAT_RG8I: // WebGL2 only

// Integer texture formats (RG)
case PIXELFORMAT_RG8I:
this._glFormat = gl.RG_INTEGER;
this._glInternalFormat = gl.RG8I;
this._glPixelType = gl.BYTE;
break;
case PIXELFORMAT_RG8U: // WebGL2 only
case PIXELFORMAT_RG8U:
this._glFormat = gl.RG_INTEGER;
this._glInternalFormat = gl.RG8UI;
this._glPixelType = gl.UNSIGNED_BYTE;
break;
case PIXELFORMAT_RG16I: // WebGL2 only
case PIXELFORMAT_RG16I:
this._glFormat = gl.RG_INTEGER;
this._glInternalFormat = gl.RG16I;
this._glPixelType = gl.SHORT;
break;
case PIXELFORMAT_RG16U: // WebGL2 only
case PIXELFORMAT_RG16U:
this._glFormat = gl.RG_INTEGER;
this._glInternalFormat = gl.RG16UI;
this._glPixelType = gl.UNSIGNED_SHORT;
break;
case PIXELFORMAT_RG32I: // WebGL2 only
case PIXELFORMAT_RG32I:
this._glFormat = gl.RG_INTEGER;
this._glInternalFormat = gl.RG32I;
this._glPixelType = gl.INT;
break;
case PIXELFORMAT_RG32U: // WebGL2 only
case PIXELFORMAT_RG32U:
this._glFormat = gl.RG_INTEGER;
this._glInternalFormat = gl.RG32UI;
this._glPixelType = gl.UNSIGNED_INT;
break;
// Integer texture formats (RGBA) (WebGL2 only)
case PIXELFORMAT_RGBA8I: // WebGL2 only

// Integer texture formats (RGBA)
case PIXELFORMAT_RGBA8I:
this._glFormat = gl.RGBA_INTEGER;
this._glInternalFormat = gl.RGBA8I;
this._glPixelType = gl.BYTE;
break;
case PIXELFORMAT_RGBA8U: // WebGL2 only
case PIXELFORMAT_RGBA8U:
this._glFormat = gl.RGBA_INTEGER;
this._glInternalFormat = gl.RGBA8UI;
this._glPixelType = gl.UNSIGNED_BYTE;
break;
case PIXELFORMAT_RGBA16I: // WebGL2 only
case PIXELFORMAT_RGBA16I:
this._glFormat = gl.RGBA_INTEGER;
this._glInternalFormat = gl.RGBA16I;
this._glPixelType = gl.SHORT;
break;
case PIXELFORMAT_RGBA16U: // WebGL2 only
case PIXELFORMAT_RGBA16U:
this._glFormat = gl.RGBA_INTEGER;
this._glInternalFormat = gl.RGBA16UI;
this._glPixelType = gl.UNSIGNED_SHORT;
break;
case PIXELFORMAT_RGBA32I: // WebGL2 only
case PIXELFORMAT_RGBA32I:
this._glFormat = gl.RGBA_INTEGER;
this._glInternalFormat = gl.RGBA32I;
this._glPixelType = gl.INT;
break;
case PIXELFORMAT_RGBA32U: // WebGL2 only
case PIXELFORMAT_RGBA32U:
this._glFormat = gl.RGBA_INTEGER;
this._glInternalFormat = gl.RGBA32UI;
this._glPixelType = gl.UNSIGNED_INT;
Expand Down Expand Up @@ -740,7 +695,7 @@ class WebglTexture {
}
}

if (!texture._compressed && !texture._integerFormat && texture._mipmaps && texture._needsMipmapsUpload && (texture.pot || device.isWebGL2) && texture._levels.length === 1) {
if (!texture._compressed && !texture._integerFormat && texture._mipmaps && texture._needsMipmapsUpload && texture._levels.length === 1) {
gl.generateMipmap(this._glTarget);
texture._mipmapsUploaded = true;
}
Expand Down

0 comments on commit e744355

Please sign in to comment.