fix mesh loading on wechat

This commit is contained in:
jerrywwl
2019-04-16 11:33:03 +08:00
parent 19e615f577
commit 009f317c23
9 changed files with 88 additions and 53 deletions
+5 -4
View File
@@ -160,12 +160,12 @@ export class RenderingMesh {
@ccclass('cc.Mesh')
export class Mesh extends Asset {
get _nativeAsset () {
return this._data;
get _nativeAsset (): ArrayBuffer {
return this._data!.buffer;
}
set _nativeAsset (value) {
this._data = value;
set _nativeAsset (value: ArrayBuffer) {
this._data = new Uint8Array(value);
}
/**
@@ -575,6 +575,7 @@ export class Mesh extends Asset {
size: vertexBundle.view.length,
stride: vertexBundle.view.stride,
});
vertexBuffer.update(new Uint8Array(data, vertexBundle.view.offset, vertexBundle.view.length));
return vertexBuffer;
});
+6 -6
View File
@@ -275,24 +275,24 @@ export default [
"shaders": [
{
"name": "pipeline/tonemap|tonemap-vs:vert|tonemap-fs:frag",
"hash": 1212847014,
"hash": 1444180786,
"glsl3": {
"vert": `\nprecision highp float;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\nin vec2 a_position;\nin vec2 a_texCoord;\nout vec2 v_uv;\nout vec4 v_offset;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offset = v_uv.xyxy + cc_nativeSize.zwzw * vec4(1.0, 0.0, 0.0, -1.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
"frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nin vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#else\n color = SRGBToLinear(color);\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n#if CC_USE_SMAA\n \n vec4 a;\n a.rb = texture(u_blendTexSampler, v_uv).rb; \n a.g = texture(u_blendTexSampler, v_offset.zw).g; \n a.a = texture(u_blendTexSampler, v_offset.xy).a; \n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else \n vec4 o = texture(u_texSampler, v_uv);\n \n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
"frag": `\nprecision highp float;\nuniform CCGlobal {\n vec4 cc_time; \n vec4 cc_screenSize; \n vec4 cc_screenScale; \n vec4 cc_nativeSize; \n mat4 cc_matView;\n mat4 cc_matViewInv;\n mat4 cc_matProj;\n mat4 cc_matProjInv;\n mat4 cc_matViewProj;\n mat4 cc_matViewProjInv;\n vec4 cc_cameraPos; \n vec4 cc_exposure; \n vec4 cc_mainLitDir; \n vec4 cc_mainLitColor; \n vec4 cc_ambientSky;\n vec4 cc_ambientGround;\n};\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nin vec2 v_uv;\nin vec4 v_offset;\nuniform sampler2D u_texSampler;\n#if CC_USE_SMAA\nuniform sampler2D u_blendTexSampler;\n#endif\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#else\n color = SRGBToLinear(color);\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n#if CC_USE_SMAA\n \n vec4 a;\n a.rb = texture(u_blendTexSampler, v_uv).rb; \n a.g = texture(u_blendTexSampler, v_offset.zw).g; \n a.a = texture(u_blendTexSampler, v_offset.xy).a; \n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else \n vec4 o = texture(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nout vec4 cc_FragColor;\nvoid main() { cc_FragColor = frag(); }\n`
},
"glsl1": {
"vert": `\nprecision highp float;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\nattribute vec2 a_position;\nattribute vec2 a_texCoord;\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nvec4 vert () {\n vec4 pos = vec4(a_position, 0, 1);\n v_uv = a_texCoord * cc_screenScale.xy;\n v_offset = v_uv.xyxy + cc_nativeSize.zwzw * vec4(1.0, 0.0, 0.0, -1.0);\n return pos;\n}\nvoid main() { gl_Position = vert(); }\n`,
"frag": `\nprecision highp float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nuniform sampler2D u_texSampler;\nuniform sampler2D u_blendTexSampler;\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#else\n color = SRGBToLinear(color);\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n#if CC_USE_SMAA\n \n vec4 a;\n a.rb = texture2D(u_blendTexSampler, v_uv).rb; \n a.g = texture2D(u_blendTexSampler, v_offset.zw).g; \n a.a = texture2D(u_blendTexSampler, v_offset.xy).a; \n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture2D(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture2D(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else \n vec4 o = texture2D(u_texSampler, v_uv);\n \n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nvoid main() { gl_FragColor = frag(); }\n`
"frag": `\nprecision highp float;\nuniform vec4 cc_time;\nuniform vec4 cc_screenSize;\nuniform vec4 cc_screenScale;\nuniform vec4 cc_nativeSize;\nuniform mat4 cc_matView;\nuniform mat4 cc_matViewInv;\nuniform mat4 cc_matProj;\nuniform mat4 cc_matProjInv;\nuniform mat4 cc_matViewProj;\nuniform mat4 cc_matViewProjInv;\nuniform vec4 cc_cameraPos;\nuniform vec4 cc_exposure;\nuniform vec4 cc_mainLitDir;\nuniform vec4 cc_mainLitColor;\nuniform vec4 cc_ambientSky;\nuniform vec4 cc_ambientGround;\n#define PI 3.14159265359\n#define PI2 6.28318530718\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define FP_MAX 65504.0\n#define FP_SCALE 0.0009765625\n#define FP_SCALE_INV 1024.0\nvec3 SRGBToLinear(vec3 gamma)\n{\n return pow(gamma, vec3(2.2));\n \n}\nvec3 LinearToSRGB(vec3 linear)\n{\n return pow(linear, vec3(0.454545));\n \n}\nvec3 ACESToneMap(vec3 color) {\n const float A = 2.51;\n const float B = 0.03;\n const float C = 2.43;\n const float D = 0.59;\n const float E = 0.14;\n return (color * (A * color + B)) / (color * (C * color + D) + E);\n}\nvarying vec2 v_uv;\nvarying vec4 v_offset;\nuniform sampler2D u_texSampler;\n#if CC_USE_SMAA\nuniform sampler2D u_blendTexSampler;\n#endif\nvec3 ToLDR(vec3 color) {\n#if CC_USE_HDR\n color *= cc_exposure.x * 1024.0;\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#else\n color = SRGBToLinear(color);\n color = ACESToneMap(color);\n color = LinearToSRGB(color);\n#endif\n return color;\n}\nvec4 frag () {\n#if CC_USE_SMAA\n \n vec4 a;\n a.rb = texture2D(u_blendTexSampler, v_uv).rb; \n a.g = texture2D(u_blendTexSampler, v_offset.zw).g; \n a.a = texture2D(u_blendTexSampler, v_offset.xy).a; \n if (dot(a, vec4(1.0)) < 1e-5) {\n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n } else {\n vec2 offset;\n offset.x = a.a > a.b ? a.a : -a.b;\n offset.y = a.g > a.r ? -a.g : a.r;\n if (abs(offset.x) > abs(offset.y)) {\n offset.y = 0.0;\n } else {\n offset.x = 0.0;\n }\n vec4 C = texture2D(u_texSampler, v_uv);\n C.rgb = ToLDR(C.rgb);\n vec2 uv = v_uv + sign(offset) * cc_nativeSize.zw;\n vec4 Cop = texture2D(u_texSampler, uv);\n Cop.rgb = ToLDR(Cop.rgb);\n float s = abs(offset.x) > abs(offset.y) ? abs(offset.x) : abs(offset.y);\n C.rgb = pow(C.rgb, vec3(2.2));\n Cop.rgb = pow(Cop.rgb, vec3(2.2));\n vec4 mixed = mix(C, Cop, s);\n mixed.rgb = pow(mixed.rgb, vec3(1.0 / 2.2));\n return mixed;\n }\n#else \n vec4 o = texture2D(u_texSampler, v_uv);\n o.rgb = ToLDR(o.rgb);\n return o;\n#endif\n}\nvoid main() { gl_FragColor = frag(); }\n`
},
"builtins": {"globals":{"blocks":["CCGlobal"], "samplers":[]}, "locals":{"blocks":[], "samplers":[]}},
"defines": [
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]},
{"name":"CC_USE_SMAA", "type":"boolean", "defines":[]}
{"name":"CC_USE_SMAA", "type":"boolean", "defines":[]},
{"name":"CC_USE_HDR", "type":"boolean", "defines":[]}
],
"blocks": [],
"samplers": [
{"name":"u_texSampler", "type":28, "count":1, "defines":[], "binding":0},
{"name":"u_blendTexSampler", "type":28, "count":1, "defines":[], "binding":1}
{"name":"u_blendTexSampler", "type":28, "count":1, "defines":["CC_USE_SMAA"], "binding":1}
],
"dependencies": {}
}
+1 -1
View File
@@ -145,7 +145,7 @@ class Component extends CCObject {
visible: false,
})
get enabledInHierarchy () {
return this._enabled && this.node.activeInHierarchy;
return this._enabled && this.node && this.node.activeInHierarchy;
}
/**
+11 -2
View File
@@ -208,6 +208,13 @@ export class WebGLGFXDevice extends GFXDevice {
failIfMajorPerformanceCaveat: false,
};
/*
if (cc.sys.platform === cc.sys.WECHAT_GAME ||
cc.sys.platform === cc.sys.QQ_PLAY) {
webGLCtxAttribs.preserveDrawingBuffer = true;
}
*/
this._webGLRC = this._canvas.getContext('webgl', webGLCtxAttribs);
} catch (err) {
console.error(err);
@@ -222,7 +229,6 @@ export class WebGLGFXDevice extends GFXDevice {
}
this._canvas2D = document.createElement('canvas');
console.info('WebGL device initialized.');
this._gfxAPI = GFXAPI.WEBGL;
@@ -339,7 +345,7 @@ export class WebGLGFXDevice extends GFXDevice {
this._features[GFXFeature.MSAA] = false;
if (this._OES_vertex_array_object) {
this._useVAO = true;
this._useVAO = false;
}
console.info('RENDERER: ' + this._renderer);
@@ -645,15 +651,18 @@ export class WebGLGFXDevice extends GFXDevice {
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
// rasteriazer state
gl.disable(gl.SCISSOR_TEST);
gl.enable(gl.CULL_FACE);
gl.cullFace(gl.BACK);
gl.frontFace(gl.CCW);
gl.disable(gl.POLYGON_OFFSET_FILL);
gl.polygonOffset(0.0, 0.0);
// depth stencil state
gl.enable(gl.DEPTH_TEST);
gl.depthMask(true);
gl.depthFunc(gl.LESS);
gl.depthRange(0.0, 1.0);
gl.stencilFuncSeparate(gl.FRONT, gl.ALWAYS, 1, 0xffffffff);
gl.stencilOpSeparate(gl.FRONT, gl.KEEP, gl.KEEP, gl.KEEP);
+2 -2
View File
@@ -33,8 +33,8 @@ export default function downloadBinary (item, callback) {
xhr.onload = function () {
var arrayBuffer = xhr.response;
if (arrayBuffer) {
var result = new Uint8Array(arrayBuffer);
callback(null, result);
// var result = new Uint8Array(arrayBuffer);
callback(null, arrayBuffer);
}
else {
callback({status:xhr.status, errorMessage:errInfo + '(no response)'});
+10 -10
View File
@@ -1,6 +1,5 @@
import { frustum, intersect, sphere } from '../../3d/geom-utils';
import { intersect, sphere } from '../../3d/geom-utils';
import { Root } from '../../core/root';
import { Vec3 } from '../../core/value-types';
import { v3 } from '../../core/value-types/vec3';
import { vec3 } from '../../core/vmath';
import { GFXBuffer } from '../../gfx/buffer';
@@ -96,18 +95,19 @@ export class ForwardPipeline extends RenderPipeline {
priority: ForwardFlowPriority.FORWARD,
});
if (this._useSMAA) {
this.createFlow(SMAAEdgeFlow, {
name: PIPELINE_FLOW_SMAA,
if (this._usePostProcess) {
if (this._useSMAA) {
this.createFlow(SMAAEdgeFlow, {
name: PIPELINE_FLOW_SMAA,
priority: 0,
});
}
this.createFlow(ToneMapFlow, {
name: PIPELINE_FLOW_TONEMAP,
priority: 0,
});
}
this.createFlow(ToneMapFlow, {
name: PIPELINE_FLOW_TONEMAP,
priority: 0,
});
this.createFlow(UIFlow, {
name: 'UIFlow',
priority: ForwardFlowPriority.UI,
+10 -7
View File
@@ -1,14 +1,13 @@
import { GFXCommandBuffer } from '../../gfx/command-buffer';
import { GFXClearFlag, GFXCommandBufferType, GFXFilter, IGFXColor } from '../../gfx/define';
import { Model } from '../../renderer';
import { cullSceneWithDirectionalLight } from '../culling';
import { getPhaseID } from '../pass-phase';
import { SRGBToLinear } from '../pipeline-funcs';
import { RenderFlow } from '../render-flow';
import { opaqueCompareFn, RenderQueue, transparentCompareFn } from '../render-queue';
import { IRenderStageInfo, RenderStage } from '../render-stage';
import { RenderView } from '../render-view';
import { IRenderObject } from '../define';
import { cullSceneWithDirectionalLight } from '../culling';
import { Model } from '../../renderer';
import { getPhaseID } from '../pass-phase';
const colors: IGFXColor[] = [];
const bufs: GFXCommandBuffer[] = [];
@@ -119,10 +118,14 @@ export class ForwardStage extends RenderStage {
colors.length = 1;
}
if (!this._pipeline.useMSAA) {
this._framebuffer = this._pipeline.curShadingFBO;
if (this._pipeline.usePostProcess) {
if (!this._pipeline.useMSAA) {
this._framebuffer = this._pipeline.curShadingFBO;
} else {
this._framebuffer = this._pipeline.msaaShadingFBO;
}
} else {
this._framebuffer = this._pipeline.msaaShadingFBO;
this._framebuffer = view.window!.framebuffer;
}
cmdBuff.begin();
+42 -21
View File
@@ -36,6 +36,7 @@ const _outMat = new Mat4();
const _v3tmp = new Vec3();
export interface IRenderPipelineInfo {
enablePostProcess?: boolean;
enableHDR?: boolean;
enableMSAA?: boolean;
enableSMAA?: boolean;
@@ -63,6 +64,10 @@ export abstract class RenderPipeline {
return this._flows;
}
public get usePostProcess (): boolean {
return this._usePostProcess;
}
public get isHDRSupported (): boolean {
return this._isHDRSupported;
}
@@ -188,6 +193,7 @@ export abstract class RenderPipeline {
protected _shadingScale: number = 1.0;
protected _curIdx: number = 0;
protected _prevIdx: number = 1;
protected _usePostProcess: boolean = false;
protected _useMSAA: boolean = false;
protected _useSMAA: boolean = false;
protected _smaaPass: GFXRenderPass | null = null;
@@ -312,21 +318,40 @@ export abstract class RenderPipeline {
protected _initialize (info: IRenderPipelineInfo): boolean {
if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F) ||
this._device.hasFeature(GFXFeature.TEXTURE_HALF_FLOAT) ||
this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) {
this._isHDRSupported = true;
if (info.enablePostProcess !== undefined) {
this._usePostProcess = info.enablePostProcess;
} else {
if (cc.sys.platform === cc.sys.WECHAT_GAME) {
this._usePostProcess = true;
} else {
this._usePostProcess = true;
}
}
// this._isHDRSupported = false;
if (this._usePostProcess) {
if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F) ||
this._device.hasFeature(GFXFeature.TEXTURE_HALF_FLOAT) ||
this._device.hasFeature(GFXFeature.TEXTURE_FLOAT)) {
this._isHDRSupported = true;
}
this._fboCount = 1;
this._shadingTextures = new Array<GFXTexture>(this._fboCount);
this._shadingTexViews = new Array<GFXTextureView>(this._fboCount);
this._shadingFBOs = new Array<GFXFramebuffer>(this._fboCount);
// this._isHDRSupported = false;
this._fboCount = 1;
this._shadingTextures = new Array<GFXTexture>(this._fboCount);
this._shadingTexViews = new Array<GFXTextureView>(this._fboCount);
this._shadingFBOs = new Array<GFXFramebuffer>(this._fboCount);
const enableHDR = (info.enableHDR !== undefined ? info.enableHDR : true);
if (enableHDR && this._isHDRSupported) {
this._isHDR = (info.enableHDR !== undefined ? info.enableHDR : true);
// Config Anti-Aliasing
this._useSMAA = info.enableSMAA !== undefined ? info.enableSMAA : false;
this._useMSAA = info.enableMSAA !== undefined ? info.enableMSAA : false;
if (this._useMSAA) {
this._useMSAA = this.device.hasFeature(GFXFeature.MSAA);
}
}
if (this._isHDR && this._isHDRSupported) {
// Try to use HDR format
if (this._device.hasFeature(GFXFeature.FORMAT_R11G11B10F)) {
this._colorFmt = GFXFormat.R11G11B10F;
@@ -347,13 +372,6 @@ export abstract class RenderPipeline {
this._isHDR = false;
}
// Config Anti-Aliasing
this._useSMAA = info.enableSMAA !== undefined ? info.enableSMAA : false;
this._useMSAA = info.enableMSAA !== undefined ? info.enableMSAA : false;
if (this._useMSAA) {
this._useMSAA = this.device.hasFeature(GFXFeature.MSAA);
}
if (this._device.hasFeature(GFXFeature.FORMAT_D24S8)) {
this._depthStencilFmt = GFXFormat.D24S8;
} else {
@@ -369,9 +387,12 @@ export abstract class RenderPipeline {
this._shadingWidth = Math.floor(this._device.nativeWidth);
this._shadingHeight = Math.floor(this._device.nativeHeight);
console.info('USE_MSAA: ' + this._useMSAA);
console.info('USE_SMAA: ' + this._useSMAA);
console.info('CC_USE_HDR: ' + this._isHDR);
console.info('USE_POST_PROCESS: ' + this._usePostProcess);
if (this._usePostProcess) {
console.info('USE_MSAA: ' + this._useMSAA);
console.info('USE_SMAA: ' + this._useSMAA);
console.info('USE_HDR: ' + this._isHDR);
}
console.info('SHADING_SIZE: ' + this._shadingWidth + ' x ' + this._shadingHeight);
console.info('SHADING_SCALE: ' + this._shadingScale.toFixed(4));
console.info('SHADING_COLOR_FORMAT: ' + GFXFormatInfos[this._colorFmt].name);
+1
View File
@@ -397,6 +397,7 @@ export class Pass {
get rasterizerState () { return this._rs; }
get dynamics () { return this._dynamics; }
get customizations () { return this._customizations; }
get shader (): GFXShader { return this._shader!; }
}
const serializeBlendState = (bs: GFXBlendState) => {