laya-coreui-es
Version:
laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改
119 lines (118 loc) • 5.28 kB
JavaScript
import { Config } from "../../Config";
import { ILaya } from "../../ILaya";
import { VertexArrayObject } from "../../laya/webgl/VertexArrayObject";
import { SystemUtils } from "./SystemUtils";
export class LayaGPU {
constructor(gl, isWebGL2) {
this._gl = null;
this._vaoExt = null;
this._angleInstancedArrays = null;
this._isWebGL2 = false;
this._oesTextureHalfFloat = null;
this._oes_element_index_uint = null;
this._oesTextureHalfFloatLinear = null;
this._oesTextureFloat = null;
this._extShaderTextureLod = null;
this._extTextureFilterAnisotropic = null;
this._compressedTextureS3tc = null;
this._compressedTexturePvrtc = null;
this._compressedTextureEtc1 = null;
this._compressedTextureETC = null;
this._compressedTextureASTC = null;
this._webgl_depth_texture = null;
this._extColorBufferFloat = null;
this._gl = gl;
this._isWebGL2 = isWebGL2;
var maxTextureFS = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS);
var maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
if (!isWebGL2) {
if (!ILaya.Render.isConchApp) {
VertexArrayObject;
if (window._setupVertexArrayObject)
window._setupVertexArrayObject(gl);
}
this._vaoExt = this._getExtension("OES_vertex_array_object");
this._angleInstancedArrays = this._getExtension("ANGLE_instanced_arrays");
this._oesTextureHalfFloat = this._getExtension("OES_texture_half_float");
this._oesTextureHalfFloatLinear = this._getExtension("OES_texture_half_float_linear");
this._oesTextureFloat = this._getExtension("OES_texture_float");
this._oes_element_index_uint = this._getExtension("OES_element_index_uint");
this._extShaderTextureLod = this._getExtension("EXT_shader_texture_lod");
this._webgl_depth_texture = this._getExtension("WEBGL_depth_texture");
SystemUtils._shaderCapailityLevel = 30;
}
else {
this._extColorBufferFloat = this._getExtension("EXT_color_buffer_float");
SystemUtils._shaderCapailityLevel = 35;
}
this._extTextureFilterAnisotropic = this._getExtension("EXT_texture_filter_anisotropic");
this._compressedTextureS3tc = this._getExtension("WEBGL_compressed_texture_s3tc");
this._compressedTexturePvrtc = this._getExtension("WEBGL_compressed_texture_pvrtc");
this._compressedTextureEtc1 = this._getExtension("WEBGL_compressed_texture_etc1");
this._compressedTextureETC = this._getExtension("WEBGL_compressed_texture_etc");
this._compressedTextureASTC = this._getExtension("WEBGL_compressed_texture_astc");
SystemUtils._maxTextureCount = maxTextureFS;
SystemUtils._maxTextureSize = maxTextureSize;
}
_getExtension(name) {
var prefixes = LayaGPU._extentionVendorPrefixes;
for (var k in prefixes) {
var ext = this._gl.getExtension(prefixes[k] + name);
if (ext)
return ext;
}
return null;
}
createVertexArray() {
if (this._isWebGL2)
return this._gl.createVertexArray();
else
return this._vaoExt.createVertexArrayOES();
}
bindVertexArray(vertexArray) {
if (this._isWebGL2)
this._gl.bindVertexArray(vertexArray);
else
this._vaoExt.bindVertexArrayOES(vertexArray);
}
deleteVertexArray(vertexArray) {
if (this._isWebGL2)
this._gl.deleteVertexArray(vertexArray);
else
this._vaoExt.deleteVertexArrayOES(vertexArray);
}
isVertexArray(vertexArray) {
if (this._isWebGL2)
this._gl.isVertexArray(vertexArray);
else
this._vaoExt.isVertexArrayOES(vertexArray);
}
drawElementsInstanced(mode, count, type, offset, instanceCount) {
if (this._isWebGL2)
this._gl.drawElementsInstanced(mode, count, type, offset, instanceCount);
else
this._angleInstancedArrays.drawElementsInstancedANGLE(mode, count, type, offset, instanceCount);
}
drawArraysInstanced(mode, first, count, instanceCount) {
if (this._isWebGL2)
this._gl.drawArraysInstanced(mode, first, count, instanceCount);
else
this._angleInstancedArrays.drawArraysInstancedANGLE(mode, first, count, instanceCount);
}
vertexAttribDivisor(index, divisor) {
if (this._isWebGL2)
this._gl.vertexAttribDivisor(index, divisor);
else
this._angleInstancedArrays.vertexAttribDivisorANGLE(index, divisor);
}
supportInstance() {
if ((this._isWebGL2 || this._angleInstancedArrays) && Config.allowGPUInstanceDynamicBatch)
return true;
else
return false;
}
supportElementIndexUint32() {
return this._isWebGL2 || this._oes_element_index_uint ? true : false;
}
}
LayaGPU._extentionVendorPrefixes = ["", "WEBKIT_", "MOZ_"];