fix display error on some android platforms

This commit is contained in:
jerrywwl
2019-04-25 18:52:34 +08:00
parent acf505a32b
commit d83e016f51
8 changed files with 121 additions and 80 deletions
-34
View File
@@ -1,37 +1,3 @@
// Extensions
export enum WebGLEXT {
UNSIGNED_INT_24_8_WEBGL = 0x84FA,
HALF_FLOAT_OES = 0x8D61,
COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0,
COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1,
COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2,
COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3,
COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C,
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8C4D,
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E,
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F,
COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00,
COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01,
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02,
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03,
COMPRESSED_RGB_ETC1_WEBGL = 0x8D64,
COMPRESSED_R11_EAC = 0x9270,
COMPRESSED_SIGNED_R11_EAC = 0x9271,
COMPRESSED_RG11_EAC = 0x9272,
COMPRESSED_SIGNED_RG11_EAC = 0x9273,
COMPRESSED_RGB8_ETC2 = 0x9274,
COMPRESSED_SRGB8_ETC2 = 0x9275,
COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276,
COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277,
COMPRESSED_RGBA8_ETC2_EAC = 0x9278,
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279,
}
export const GFX_MAX_VERTEX_ATTRIBUTES: number = 16;
export const GFX_MAX_TEXTURE_UNITS: number = 16;
export const GFX_MAX_ATTACHMENTS: number = 4;
+4
View File
@@ -25,8 +25,12 @@ export enum GFXAPI {
}
export enum GFXFeature {
COLOR_FLOAT,
COLOR_HALF_FLOAT,
TEXTURE_FLOAT,
TEXTURE_HALF_FLOAT,
TEXTURE_FLOAT_LINEAR,
TEXTURE_HALF_FLOAT_LINEAR,
FORMAT_R11G11B10F,
FORMAT_D24S8,
FORMAT_ETC1,
+6
View File
@@ -1,3 +1,9 @@
interface EXT_color_buffer_half_float {
readonly RGBA16F_EXT: GLenum;
readonly RGB16F_EXT: GLenum;
readonly FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT: GLenum;
readonly UNSIGNED_NORMALIZED_EXT: GLenum;
}
// note that ETC1 is not supported with the compressedTexSubImage2D() method
interface WEBGL_compressed_texture_etc1 {
+1 -13
View File
@@ -24,7 +24,6 @@ import {
IGFXFormatInfo,
IGFXRect,
IGFXViewport,
WebGLEXT,
} from '../define';
import { WebGLGFXCommandAllocator } from './webgl-command-allocator';
import {
@@ -33,24 +32,13 @@ import {
IWebGLStencilCompareMask,
IWebGLStencilWriteMask,
} from './webgl-command-buffer';
import { WebGLEXT } from './webgl-define';
import { WebGLGFXDevice } from './webgl-device';
import { IWebGLGPUInputAssembler, IWebGLGPUUniform, WebGLAttrib, WebGLGPUBindingLayout,
WebGLGPUBuffer, WebGLGPUFramebuffer, WebGLGPUInput,
WebGLGPUPipelineState, WebGLGPUShader, WebGLGPUTexture, WebGLGPUUniformBlock, WebGLGPUUniformSampler } from './webgl-gpu-objects';
import { IWebGLTexUnit } from './webgl-state-cache';
const SAMPLES: number[] = [
1,
2,
4,
8,
16,
32,
64,
];
// tslint:disable: max-line-length
function CmpF32NotEuqal (a: number, b: number): boolean {
const c = a - b;
return (c > 0.000001 || c < -0.000001);
+38
View File
@@ -0,0 +1,38 @@
// Extensions
export enum WebGLEXT {
RGBA16F_EXT = 0x881A,
RGB16F_EXT = 0x881B,
RGBA32F_EXT = 0x8814,
FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE_EXT = 0x8211,
UNSIGNED_NORMALIZED_EXT = 0x8C17,
UNSIGNED_INT_24_8_WEBGL = 0x84FA,
HALF_FLOAT_OES = 0x8D61,
COMPRESSED_RGB_S3TC_DXT1_EXT = 0x83F0,
COMPRESSED_RGBA_S3TC_DXT1_EXT = 0x83F1,
COMPRESSED_RGBA_S3TC_DXT3_EXT = 0x83F2,
COMPRESSED_RGBA_S3TC_DXT5_EXT = 0x83F3,
COMPRESSED_SRGB_S3TC_DXT1_EXT = 0x8C4C,
COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT = 0x8C4D,
COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT = 0x8C4E,
COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT = 0x8C4F,
COMPRESSED_RGB_PVRTC_4BPPV1_IMG = 0x8C00,
COMPRESSED_RGB_PVRTC_2BPPV1_IMG = 0x8C01,
COMPRESSED_RGBA_PVRTC_4BPPV1_IMG = 0x8C02,
COMPRESSED_RGBA_PVRTC_2BPPV1_IMG = 0x8C03,
COMPRESSED_RGB_ETC1_WEBGL = 0x8D64,
COMPRESSED_R11_EAC = 0x9270,
COMPRESSED_SIGNED_R11_EAC = 0x9271,
COMPRESSED_RG11_EAC = 0x9272,
COMPRESSED_SIGNED_RG11_EAC = 0x9273,
COMPRESSED_RGB8_ETC2 = 0x9274,
COMPRESSED_SRGB8_ETC2 = 0x9275,
COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9276,
COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2 = 0x9277,
COMPRESSED_RGBA8_ETC2_EAC = 0x9278,
COMPRESSED_SRGB8_ALPHA8_ETC2_EAC = 0x9279,
}
+26 -7
View File
@@ -167,6 +167,7 @@ export class WebGLGFXDevice extends GFXDevice {
private _EXT_shader_texture_lod: EXT_shader_texture_lod | null = null;
private _EXT_sRGB: EXT_sRGB | null = null;
private _OES_vertex_array_object: OES_vertex_array_object | null = null;
private _EXT_color_buffer_half_float: EXT_color_buffer_half_float | null = null;
private _WEBGL_color_buffer_float: WEBGL_color_buffer_float | null = null;
private _WEBGL_compressed_texture_etc1: WEBGL_compressed_texture_etc1 | null = null;
private _WEBGL_compressed_texture_etc: WEBGL_compressed_texture_etc | null = null;
@@ -182,6 +183,7 @@ export class WebGLGFXDevice extends GFXDevice {
private _OES_texture_half_float: OES_texture_half_float | null = null;
private _OES_texture_half_float_linear: OES_texture_half_float_linear | null = null;
private _OES_texture_float: OES_texture_float | null = null;
private _OES_texture_float_linear: OES_texture_float_linear | null = null;
private _OES_standard_derivatives: OES_standard_derivatives | null = null;
private _OES_element_index_uint: OES_element_index_uint | null = null;
private _ANGLE_instanced_arrays: ANGLE_instanced_arrays | null = null;
@@ -290,6 +292,7 @@ export class WebGLGFXDevice extends GFXDevice {
this._EXT_shader_texture_lod = gl.getExtension('EXT_shader_texture_lod');
this._EXT_sRGB = gl.getExtension('EXT_sRGB');
this._OES_vertex_array_object = gl.getExtension('OES_vertex_array_object');
this._EXT_color_buffer_half_float = gl.getExtension('EXT_color_buffer_half_float');
this._WEBGL_color_buffer_float = gl.getExtension('WEBGL_color_buffer_float');
this._WEBGL_compressed_texture_etc1 = gl.getExtension('WEBGL_compressed_texture_etc1');
this._WEBGL_compressed_texture_etc = gl.getExtension('WEBGL_compressed_texture_etc');
@@ -304,20 +307,36 @@ export class WebGLGFXDevice extends GFXDevice {
this._OES_texture_half_float = gl.getExtension('OES_texture_half_float');
this._OES_texture_half_float_linear = gl.getExtension('OES_texture_half_float_linear');
this._OES_texture_float = gl.getExtension('OES_texture_float');
this._OES_texture_float_linear = gl.getExtension('OES_texture_float_linear');
this._OES_standard_derivatives = gl.getExtension('OES_standard_derivatives');
this._OES_element_index_uint = gl.getExtension('OES_element_index_uint');
this._ANGLE_instanced_arrays = gl.getExtension('ANGLE_instanced_arrays');
this._features.fill(false);
if (cc.sys.platform !== cc.sys.WECHAT_GAME) {
if (this._OES_texture_float) {
this._features[GFXFeature.TEXTURE_FLOAT] = true;
}
// if (cc.sys.platform !== cc.sys.WECHAT_GAME) {
if (this._WEBGL_color_buffer_float) {
this._features[GFXFeature.COLOR_FLOAT] = true;
}
if (this._OES_texture_half_float) {
this._features[GFXFeature.TEXTURE_HALF_FLOAT] = true;
}
if (this._EXT_color_buffer_half_float) {
this._features[GFXFeature.COLOR_HALF_FLOAT] = true;
}
if (this._OES_texture_float) {
this._features[GFXFeature.TEXTURE_FLOAT] = true;
}
if (this._OES_texture_half_float) {
this._features[GFXFeature.TEXTURE_HALF_FLOAT] = true;
}
if (this._OES_texture_float_linear) {
this._features[GFXFeature.TEXTURE_FLOAT_LINEAR] = true;
}
if (this._OES_texture_half_float_linear) {
this._features[GFXFeature.TEXTURE_HALF_FLOAT_LINEAR] = true;
}
if (this._WEBGL_depth_texture) {
+20 -4
View File
@@ -109,6 +109,7 @@ export class WebGL2GFXDevice extends GFXDevice {
private _extensions: string[] | null = null;
private _EXT_texture_filter_anisotropic: EXT_texture_filter_anisotropic | null = null;
private _OES_texture_float_linear: OES_texture_float_linear | null = null;
private _OES_texture_half_float_linear: OES_texture_half_float_linear | null = null;
private _EXT_color_buffer_float: EXT_color_buffer_float | null = null;
private _EXT_disjoint_timer_query_webgl2: EXT_disjoint_timer_query_webgl2 | null = null;
private _WEBGL_compressed_texture_etc1: WEBGL_compressed_texture_etc1 | null = null;
@@ -217,18 +218,20 @@ export class WebGL2GFXDevice extends GFXDevice {
}
this._extensions = gl.getSupportedExtensions();
/*
let extensions = '';
if (this._extensions) {
for (let i = 0; i < this._extensions.length; ++i) {
console.info(this._extensions[i]);
for (const ext of this._extensions) {
extensions += ext + ' ';
}
console.debug('EXTENSIONS: ' + extensions);
}
*/
this._EXT_texture_filter_anisotropic = gl.getExtension('EXT_texture_filter_anisotropic');
this._EXT_color_buffer_float = gl.getExtension('EXT_color_buffer_float');
this._EXT_disjoint_timer_query_webgl2 = gl.getExtension('EXT_disjoint_timer_query_webgl2');
this._OES_texture_float_linear = gl.getExtension('OES_texture_float_linear');
this._OES_texture_half_float_linear = gl.getExtension('OES_texture_half_float_linear');
this._WEBGL_compressed_texture_etc1 = gl.getExtension('WEBGL_compressed_texture_etc1');
this._WEBGL_compressed_texture_etc = gl.getExtension('WEBGL_compressed_texture_etc');
this._WEBGL_compressed_texture_pvrtc = gl.getExtension('WEBGL_compressed_texture_pvrtc');
@@ -246,6 +249,19 @@ export class WebGL2GFXDevice extends GFXDevice {
this._features[GFXFeature.FORMAT_ETC2] = true;
this._features[GFXFeature.MSAA] = true;
if (this._EXT_color_buffer_float) {
this._features[GFXFeature.COLOR_FLOAT] = true;
this._features[GFXFeature.COLOR_HALF_FLOAT] = true;
}
if (this._OES_texture_float_linear) {
this._features[GFXFeature.TEXTURE_FLOAT_LINEAR] = true;
}
if (this._OES_texture_half_float_linear) {
this._features[GFXFeature.TEXTURE_HALF_FLOAT_LINEAR] = true;
}
let compressedFormat: string = '';
if (this._WEBGL_compressed_texture_etc1) {
+26 -22
View File
@@ -322,19 +322,17 @@ export abstract class RenderPipeline {
this._usePostProcess = info.enablePostProcess;
} else {
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
this._usePostProcess = false;
this._usePostProcess = true;
} else {
this._usePostProcess = true;
}
}
if (this._usePostProcess) {
if (this.device.gfxAPI !== GFXAPI.WEBGL) {
if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F) ||
this._device.hasFeature(GFXFeature.TEXTURE_HALF_FLOAT) ||
this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) {
this._isHDRSupported = true;
}
if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F) ||
this._device.hasFeature(GFXFeature.TEXTURE_HALF_FLOAT) ||
this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) {
this._isHDRSupported = true;
}
// this._isHDRSupported = false;
@@ -355,25 +353,31 @@ export abstract class RenderPipeline {
if (this._isHDR && this._isHDRSupported) {
// Try to use HDR format
if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F)) {
this._colorFmt = GFXFormat.R11G11B10F;
this._isHDR = true;
} else if (this._device.hasFeature(GFXFeature.TEXTURE_HALF_FLOAT)) {
this._colorFmt = GFXFormat.RGBA16F;
this._isHDR = true;
} else if (this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) {
this._colorFmt = GFXFormat.RGBA32F;
this._isHDR = true;
} else {
this._colorFmt = GFXFormat.RGBA8;
this._isHDR = false;
console.error('RenderPipeline doesn\'t support HDR.');
if (this._device.hasFeature(GFXFeature.COLOR_HALF_FLOAT) &&
this._device.hasFeature(GFXFeature.TEXTURE_HALF_FLOAT_LINEAR)) {
if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F)) {
this._colorFmt = GFXFormat.R11G11B10F;
this._isHDR = true;
} else if (this._device.hasFeature(GFXFeature.TEXTURE_HALF_FLOAT)) {
this._colorFmt = GFXFormat.RGBA16F;
this._isHDR = true;
}
} else if (this._device.hasFeature(GFXFeature.COLOR_FLOAT) &&
this._device.hasFeature(GFXFeature.TEXTURE_FLOAT_LINEAR)) {
if (this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) {
this._colorFmt = GFXFormat.RGBA32F;
this._isHDR = true;
}
}
} else { // Fallback to LDR
this._colorFmt = GFXFormat.RGBA8;
this._isHDR = false;
}
if (!this._isHDR) {
this._colorFmt = GFXFormat.RGBA8;
console.error('RenderPipeline doesn\'t support HDR.');
}
if (this._device.depthBits === 24) {
if (this._device.stencilBits === 8) {
this._depthStencilFmt = GFXFormat.D24S8;