123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import { getMultMaterial, MultBatch2D } from "./MultTextures";
- //仅原生需要,发布H5或者小游戏,可以删除本脚本
- if (CC_JSB) {
- //@ts-ignore
- let RenderFlow = cc.RenderFlow;
- RenderFlow.FLAG_REORDER_CHILDREN = 1 << 29;
- RenderFlow.FLAG_WORLD_TRANSFORM_CHANGED = 1 << 30;
- RenderFlow.FLAG_OPACITY_CHANGED = 1 << 31;
- let _dirtyTargets = [];
- let _dirtyWaiting = [];
- let _rendering = false;
- var director = cc.director;
- RenderFlow.render = function (scene, dt, camera = null) {
- _rendering = true;
- RenderFlow.validateRenderers();
- for (let i = 0, l = _dirtyTargets.length; i < l; i++) {
- let node = _dirtyTargets[i];
- node._inJsbDirtyList = false;
- let comp = node._renderComponent;
- if (!comp) continue;
- let assembler = comp._assembler;
- if (!assembler) continue;
- let flag = node._dirtyPtr[0];
- if (flag & RenderFlow.FLAG_UPDATE_RENDER_DATA) {
- node._dirtyPtr[0] &= ~RenderFlow.FLAG_UPDATE_RENDER_DATA;
- assembler._updateRenderData && assembler._updateRenderData();
- }
- if (flag & RenderFlow.FLAG_COLOR) {
- node._dirtyPtr[0] &= ~RenderFlow.FLAG_COLOR;
- comp._updateColor && comp._updateColor();
- }
- }
- _dirtyTargets.length = 0;
- this.visitBegin(scene);
- dt = dt || 0;
- this._nativeFlow.render(scene._proxy, dt, camera);
- _dirtyTargets = _dirtyWaiting.slice(0);
- _dirtyWaiting.length = 0;
- _rendering = false;
- };
- RenderFlow.renderCamera = function (camera, scene) {
- RenderFlow.render(scene, 0, camera);
- }
- RenderFlow.init = function (nativeFlow) {
- cc.EventTarget.call(this);
- this._nativeFlow = nativeFlow;
- };
- RenderFlow.register = function (target) {
- if (target._inJsbDirtyList) return;
- if (_rendering) {
- _dirtyWaiting.push(target);
- } else {
- _dirtyTargets.push(target);
- }
- target._inJsbDirtyList = true;
- }
- const empty_cullingMask = 1;
- const empty_node = new cc.Node();
- const empty_material = new cc.Material();
- const Renderer = {
- node: empty_node,
- material: empty_material,
- cullingMask: empty_cullingMask,
- _dummyNode: empty_node,
- reset: function () {
- this.node = empty_node;
- this.empty_material = empty_material;
- this.cullingMask = empty_cullingMask;
- this.material = getMultMaterial(empty_material);
- },
- flush: function (node) {
- this.cullingMask = node._cullingMask;
- this.material = getMultMaterial(empty_material);
- }
- };
- cc.Node.prototype["realOpacity"] = 1;
- const FLAG_RENDER = RenderFlow.FLAG_RENDER;
- const FLAG_DONOTHING = RenderFlow.FLAG_DONOTHING;
- const FLAG_POST_RENDER = RenderFlow.FLAG_POST_RENDER;
- const buildTree = function (node) {
- let opacity = node.realOpacity;
- let renderFlag = node._renderFlag;
- if (opacity == 0 || !node._activeInHierarchy || renderFlag & FLAG_DONOTHING) return;
- let comp = node._renderComponent;
- if (comp) {
- if (renderFlag & FLAG_POST_RENDER) Renderer.flush(node);
- else if (renderFlag & FLAG_RENDER) {
- comp._checkBacth(Renderer, node._cullingMask);
- }
- }
- let children = node._children;
- for (let i = 0, n = children.length; i < n; i++) {
- let c = children[i];
- c.realOpacity = opacity * (~~c._opacity / 255);
- buildTree(c);
- }
- if (comp) {
- //cc.Mask Armature Skeleton
- if (renderFlag & FLAG_POST_RENDER) Renderer.flush(node);
- }
- };
- RenderFlow.visitBegin = function (node) {
- if(MultBatch2D.enable){
- buildTree(node);
- Renderer.reset();
- }
- };
- }
|