去掉多纹理合批

This commit is contained in:
2024-08-12 09:41:06 +08:00
parent 9941b5149d
commit 78dbca673f
12 changed files with 87 additions and 3269 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +0,0 @@
{
"ver": "1.1.50",
"importer": "prefab",
"imported": true,
"uuid": "21141edb-3848-4481-ac80-0ea8aa4498d4",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "expbg"
}
}

View File

@@ -1,137 +0,0 @@
import { _decorator, cclegacy, Color, Component, Director, director, dynamicAtlasManager, Label, macro, profiler, Scene, setDisplayStats, Toggle } from 'cc';
import { MultBatch2D } from './multTextures/MultTextures';
const { ccclass, property } = _decorator;
//仅供测试使用,不用复制到项目
macro.CLEANUP_IMAGE_CACHE = false;
dynamicAtlasManager.enabled = true;
let isAutoBatch = true;
let isMultexture = true;
@ccclass('expbg')
export class expbg extends Component {
@property(Label)
drawcall!:Label;
@property(Label)
fps!:Label;
@property(Label)
render!:Label;
@property(Label)
triangle!:Label;
toggle:Array<Toggle> = [];
protected start(): void {
profiler.showStats();
this.toggle = this.node.getComponentsInChildren(Toggle)!;
isMultexture = this.toggle[0].isChecked = MultBatch2D.enable;
isAutoBatch = this.toggle[1].isChecked = dynamicAtlasManager.enabled;
this.changeColor();
}
changeColor(){
let all = isMultexture&&isAutoBatch;
if(all){
this.drawcall.color = Color.GREEN;
}else{
this.drawcall.color = isMultexture? new Color(255,100,0,255):Color.RED;
}
}
btMultexture(){
isMultexture = this.toggle[0].isChecked;
// _mulMaterial.enable = isMultexture;
// resetRenders = !isMultexture;
this.changeColor();
}
btAutoBatch(){
isAutoBatch = this.toggle[1].isChecked;
// dynamicAtlasManager.enabled = isAutoBatch;
// resetRenders = !isAutoBatch;
this.changeColor();
}
btExit(){
director.loadScene('main');
}
lateUpdate(dt:number){
let state = null;
if(cclegacy.profiler.stats){
state = cclegacy.profiler.stats;
}else{
state = cclegacy.profiler._stats;
}
let dc = state.draws.counter._value;
let tris = state.tricount.counter._value;
let fps = state.fps.counter._averageValue;
let render = state.render.counter._averageValue;
//director.root!.device.numDrawCalls;
this.drawcall.string = "dc: " + dc;
this.fps.string = 'fps: '+fps.toFixed(2);
// this.triangle.string = "triangles: "+tris;
this.render.string = 'render: '+render.toFixed(2);
}
}
let renders:Set<any> = new Set();
director.on(Director.EVENT_BEFORE_DRAW,()=>{
let resetRenders = false;
if(MultBatch2D.enable != isMultexture){
MultBatch2D.enable = isMultexture;
resetRenders = true;
}
if(dynamicAtlasManager.enabled != isAutoBatch){
dynamicAtlasManager.enabled = isAutoBatch;
resetRenders = true;
}
if(resetRenders){
resetRenders = false;
renders.forEach((render)=>{
if(render){
let rd = render.renderData;
rd && render.markForUpdateRenderData(true);
}
});
}
});
let UIMeshRenderer = cclegacy.UIMeshRenderer.prototype;
let UIMeshDisable = UIMeshRenderer.onDisable;
let UIMeshEnable = UIMeshRenderer.onEnable;
UIMeshRenderer.onEnable = function(){
renders.add(this);
UIMeshEnable.call(this);
}
UIMeshRenderer.onDisable = function(){
renders.delete(this);
UIMeshDisable.call(this);
}
let UIRenderer = cclegacy.internal.UIRenderer.prototype;
let UIDisable = UIRenderer.onDisable;
let UIEnable = UIRenderer.onEnable;
UIRenderer.onEnable = function(){
renders.add(this);
UIEnable.call(this);
}
UIRenderer.onDisable = function(){
renders.delete(this);
UIDisable.call(this);
}

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "05c5a7a2-f660-4f27-8d2c-e58f7738de6f",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -28,17 +28,17 @@
"_active": true,
"_components": [
{
"__id__": 81
"__id__": 72
},
{
"__id__": 83
"__id__": 74
},
{
"__id__": 85
"__id__": 76
}
],
"_prefab": {
"__id__": 87
"__id__": 78
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -197,17 +197,17 @@
"_active": true,
"_components": [
{
"__id__": 74
"__id__": 65
},
{
"__id__": 76
"__id__": 67
},
{
"__id__": 78
"__id__": 69
}
],
"_prefab": {
"__id__": 80
"__id__": 71
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -251,23 +251,23 @@
"__id__": 8
},
{
"__id__": 55
"__id__": 46
},
{
"__id__": 59
"__id__": 50
},
{
"__id__": 65
"__id__": 56
}
],
"_active": true,
"_components": [
{
"__id__": 71
"__id__": 62
}
],
"_prefab": {
"__id__": 73
"__id__": 64
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -314,14 +314,14 @@
"_active": true,
"_components": [
{
"__id__": 50
"__id__": 41
},
{
"__id__": 52
"__id__": 43
}
],
"_prefab": {
"__id__": 54
"__id__": 45
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -365,23 +365,23 @@
"__id__": 10
},
{
"__id__": 25
"__id__": 16
},
{
"__id__": 31
"__id__": 22
}
],
"_active": true,
"_components": [
{
"__id__": 45
"__id__": 36
},
{
"__id__": 47
"__id__": 38
}
],
"_prefab": {
"__id__": 49
"__id__": 40
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -420,22 +420,18 @@
"_parent": {
"__id__": 9
},
"_children": [
{
"__id__": 11
}
],
"_children": [],
"_active": true,
"_components": [
{
"__id__": 20
"__id__": 11
},
{
"__id__": 22
"__id__": 13
}
],
"_prefab": {
"__id__": 24
"__id__": 15
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -466,131 +462,6 @@
},
"_id": ""
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 10
},
"_prefab": {
"__id__": 12
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 11
},
"asset": {
"__uuid__": "21141edb-3848-4481-ac80-0ea8aa4498d4",
"__expectedType__": "cc.Prefab"
},
"fileId": "588mX12fFBc6tNNhK5kSwP",
"instance": {
"__id__": 13
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "3a78SMrvBMNbijh9vr2yQQ",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 14
},
{
"__id__": 16
},
{
"__id__": 17
},
{
"__id__": 18
},
{
"__id__": 19
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": -0.827,
"y": 53.339,
"z": 0
}
},
{
"__type__": "cc.TargetInfo",
"localID": [
"588mX12fFBc6tNNhK5kSwP"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_name"
],
"value": "expbg"
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_active"
],
"value": true
},
{
"__type__": "cc.UITransform",
"_name": "",
@@ -601,7 +472,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 21
"__id__": 12
},
"_contentSize": {
"__type__": "cc.Size",
@@ -629,7 +500,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 23
"__id__": 14
},
"_customMaterial": null,
"_srcBlendFactor": 2,
@@ -689,14 +560,14 @@
"_active": true,
"_components": [
{
"__id__": 26
"__id__": 17
},
{
"__id__": 28
"__id__": 19
}
],
"_prefab": {
"__id__": 30
"__id__": 21
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -733,11 +604,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 25
"__id__": 16
},
"_enabled": true,
"__prefab": {
"__id__": 27
"__id__": 18
},
"_contentSize": {
"__type__": "cc.Size",
@@ -761,11 +632,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 25
"__id__": 16
},
"_enabled": true,
"__prefab": {
"__id__": 29
"__id__": 20
},
"_customMaterial": null,
"_srcBlendFactor": 2,
@@ -825,26 +696,26 @@
"_active": true,
"_components": [
{
"__id__": 32
"__id__": 23
},
{
"__id__": 34
"__id__": 25
},
{
"__id__": 36
"__id__": 27
},
{
"__id__": 38
"__id__": 29
},
{
"__id__": 40
"__id__": 31
},
{
"__id__": 42
"__id__": 33
}
],
"_prefab": {
"__id__": 44
"__id__": 35
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -881,11 +752,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 31
"__id__": 22
},
"_enabled": true,
"__prefab": {
"__id__": 33
"__id__": 24
},
"_contentSize": {
"__type__": "cc.Size",
@@ -909,11 +780,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 31
"__id__": 22
},
"_enabled": true,
"__prefab": {
"__id__": 35
"__id__": 26
},
"_customMaterial": null,
"_srcBlendFactor": 2,
@@ -954,11 +825,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 31
"__id__": 22
},
"_enabled": true,
"__prefab": {
"__id__": 37
"__id__": 28
},
"enabledContactListener": false,
"bullet": true,
@@ -988,11 +859,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 31
"__id__": 22
},
"_enabled": true,
"__prefab": {
"__id__": 39
"__id__": 30
},
"tag": 0,
"_group": 1,
@@ -1022,11 +893,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 31
"__id__": 22
},
"_enabled": true,
"__prefab": {
"__id__": 41
"__id__": 32
},
"tag": 0,
"_group": 1,
@@ -1056,11 +927,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 31
"__id__": 22
},
"_enabled": true,
"__prefab": {
"__id__": 43
"__id__": 34
},
"tag": 0,
"_group": 1,
@@ -1107,7 +978,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 46
"__id__": 37
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1135,7 +1006,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 48
"__id__": 39
},
"_customMaterial": null,
"_srcBlendFactor": 2,
@@ -1193,7 +1064,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 51
"__id__": 42
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1221,10 +1092,10 @@
},
"_enabled": true,
"__prefab": {
"__id__": 53
"__id__": 44
},
"bgImg": {
"__id__": 47
"__id__": 38
},
"_id": ""
},
@@ -1257,11 +1128,11 @@
"_active": true,
"_components": [
{
"__id__": 56
"__id__": 47
}
],
"_prefab": {
"__id__": 58
"__id__": 49
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1298,11 +1169,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 55
"__id__": 46
},
"_enabled": true,
"__prefab": {
"__id__": 57
"__id__": 48
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1345,14 +1216,14 @@
"_active": true,
"_components": [
{
"__id__": 60
"__id__": 51
},
{
"__id__": 62
"__id__": 53
}
],
"_prefab": {
"__id__": 64
"__id__": 55
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1389,11 +1260,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 59
"__id__": 50
},
"_enabled": true,
"__prefab": {
"__id__": 61
"__id__": 52
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1417,11 +1288,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 59
"__id__": 50
},
"_enabled": true,
"__prefab": {
"__id__": 63
"__id__": 54
},
"_id": ""
},
@@ -1454,14 +1325,14 @@
"_active": true,
"_components": [
{
"__id__": 66
"__id__": 57
},
{
"__id__": 68
"__id__": 59
}
],
"_prefab": {
"__id__": 70
"__id__": 61
},
"_lpos": {
"__type__": "cc.Vec3",
@@ -1498,11 +1369,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 65
"__id__": 56
},
"_enabled": true,
"__prefab": {
"__id__": 67
"__id__": 58
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1526,11 +1397,11 @@
"_objFlags": 0,
"__editorExtras__": {},
"node": {
"__id__": 65
"__id__": 56
},
"_enabled": true,
"__prefab": {
"__id__": 69
"__id__": 60
},
"light": {
"__uuid__": "683fa094-5032-4f8d-a8c6-63a962c9bdd5",
@@ -1565,7 +1436,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 72
"__id__": 63
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1606,7 +1477,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 75
"__id__": 66
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1634,7 +1505,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 77
"__id__": 68
},
"camera": {
"__id__": 3
@@ -1643,13 +1514,13 @@
"__id__": 7
},
"mapLayer": {
"__id__": 52
"__id__": 43
},
"floorLayer": {
"__id__": 55
"__id__": 46
},
"entityLayer": {
"__id__": 62
"__id__": 53
},
"isFollowPlayer": true,
"_id": ""
@@ -1668,7 +1539,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 79
"__id__": 70
},
"_id": ""
},
@@ -1699,7 +1570,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 82
"__id__": 73
},
"_contentSize": {
"__type__": "cc.Size",
@@ -1727,7 +1598,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 84
"__id__": 75
},
"_cameraComponent": {
"__id__": 3
@@ -1749,7 +1620,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 86
"__id__": 77
},
"_alignFlags": 45,
"_target": null,
@@ -1785,11 +1656,6 @@
},
"fileId": "32qENLKwZHV5S2IyZfpNx2",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": [
{
"__id__": 11
}
]
"targetOverrides": null
}
]

View File

@@ -1,9 +0,0 @@
{
"ver": "1.2.0",
"importer": "directory",
"imported": true,
"uuid": "e323e368-94a2-4088-974a-f225ef5451fd",
"files": [],
"subMetas": {},
"userData": {}
}

View File

@@ -1,126 +0,0 @@
// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd.
CCEffect %{
techniques:
- passes:
- vert: sprite-vs:vert
frag: sprite-fs:frag
depthStencilState:
depthTest: false
depthWrite: false
blendState:
targets:
- blend: true
blendSrc: src_alpha
blendDst: one_minus_src_alpha
blendDstAlpha: one_minus_src_alpha
rasterizerState:
cullMode: none
properties:
alphaThreshold: { value: 0.5 }
texture1: { value: white}
texture2: { value: white}
texture3: { value: white}
texture4: { value: white}
texture5: { value: white}
texture6: { value: white}
texture7: { value: white}
}%
CCProgram sprite-vs %{
precision highp float;
#include <builtin/uniforms/cc-global>
#if USE_LOCAL
#include <builtin/uniforms/cc-local>
#endif
#if SAMPLE_FROM_RT
#include <common/common-define>
#endif
in vec3 a_position;
in vec2 a_texCoord;
in vec4 a_color;
out vec4 color;
out vec3 uv0;
vec4 vert () {
vec4 pos = vec4(a_position, 1);
#if USE_LOCAL
pos = cc_matWorld * pos;
#endif
#if USE_PIXEL_ALIGNMENT
pos = cc_matView * pos;
pos.xyz = floor(pos.xyz);
pos = cc_matProj * pos;
#else
pos = cc_matViewProj * pos;
#endif
// uv0 = a_texCoord;
float id = mod(a_texCoord.x,10.0);
uv0.x = (a_texCoord.x - id)*0.000001;
uv0.y = a_texCoord.y;
uv0.z = id;
#if SAMPLE_FROM_RT
CC_HANDLE_RT_SAMPLE_FLIP(uv0.xy);
#endif
color = a_color;
return pos;
}
}%
CCProgram sprite-fs %{
precision highp float;
#include <builtin/internal/embedded-alpha>
#include <builtin/internal/alpha-test>
in vec4 color;
#if USE_TEXTURE
in vec3 uv0;
#pragma builtin(local)
layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
uniform sampler2D texture1;
uniform sampler2D texture2;
uniform sampler2D texture3;
uniform sampler2D texture4;
uniform sampler2D texture5;
uniform sampler2D texture6;
uniform sampler2D texture7;
#endif
vec4 frag () {
vec4 o = vec4(1, 1, 1, 1);
#if USE_TEXTURE
if(uv0.z<0.5)
o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0.xy);
else if(uv0.z<1.5)
o *= CCSampleWithAlphaSeparated(texture1, uv0.xy);
else if(uv0.z<2.5)
o *= CCSampleWithAlphaSeparated(texture2, uv0.xy);
else if(uv0.z<3.5)
o *= CCSampleWithAlphaSeparated(texture3, uv0.xy);
else if(uv0.z<4.5)
o *= CCSampleWithAlphaSeparated(texture4, uv0.xy);
else if(uv0.z<5.5)
o *= CCSampleWithAlphaSeparated(texture5, uv0.xy);
else if(uv0.z<6.5)
o *= CCSampleWithAlphaSeparated(texture6, uv0.xy);
else
o *= CCSampleWithAlphaSeparated(texture7, uv0.xy);
#if IS_GRAY
float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b;
o.r = o.g = o.b = gray;
#endif
#endif
o *= color;
ALPHA_TEST(o);
return o;
}
}%

View File

@@ -1,11 +0,0 @@
{
"ver": "1.7.1",
"importer": "effect",
"imported": true,
"uuid": "add9fcaa-8475-4521-917b-7de307b81c4d",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

View File

@@ -1,31 +0,0 @@
{
"__type__": "cc.Material",
"_name": "",
"_objFlags": 0,
"__editorExtras__": {},
"_native": "",
"_effectAsset": {
"__uuid__": "add9fcaa-8475-4521-917b-7de307b81c4d",
"__expectedType__": "cc.EffectAsset"
},
"_techIdx": 0,
"_defines": [
{
"USE_TEXTURE": true
}
],
"_states": [
{
"rasterizerState": {},
"depthStencilState": {},
"blendState": {
"targets": [
{}
]
}
}
],
"_props": [
{}
]
}

View File

@@ -1,11 +0,0 @@
{
"ver": "1.0.21",
"importer": "material",
"imported": true,
"uuid": "490db6c2-4dd4-4050-98ec-c1c62ccaae16",
"files": [
".json"
],
"subMetas": {},
"userData": {}
}

View File

@@ -1,306 +0,0 @@
//*//
import { BaseRenderData, Director, Game, Material, Node, ParticleSystem2D, Sprite, SpriteFrame, StencilManager, UIRenderer, __private, _decorator, assert, cclegacy, director, game, renderer, resources } from 'cc';
import { DEBUG, EDITOR, JSB } from 'cc/env';
const { ccclass, property } = _decorator;
export const MultBatch2D: any = {
enable: false,
parent: null,
textures: [],
hash: 0,
reset: function () {
this.textures.length = 0;
}
};
let _cacheUseCount: number = 0;
let _cacheMaterials: Array<Material> = [];
const getMultMaterial = function () {
if (!MultBatch2D.enable) return null;
let material: any = _cacheMaterials[_cacheUseCount++];
if (!material) {
const mat = { parent: MultBatch2D.parent };
material = new renderer.MaterialInstance(mat);
material['isMultTextures'] = true;
_cacheMaterials.push(material);
}
return material;
}
let MAX_TEX = 8;
const _texture = {
texture: new cclegacy.SimpleTexture(),
defalut: new cclegacy.SimpleTexture(),
setFrame(frame: any) {
this.texture['_gfxSampler'] = frame.getGFXSampler();
this.texture['_gfxTextureView'] = frame.getGFXTexture();
}
};
game.once(Game.EVENT_GAME_INITED, () => {
if (EDITOR || JSB) return;
resources.load("multTextures/Mult-material", Material, (err, material) => {
if (!err) {
let mat = cclegacy.builtinResMgr.get('ui-sprite-material');
MultBatch2D.hash = Material.getHash(mat);
MultBatch2D.parent = material;
MultBatch2D.enable = true;
}
});
const UIR: any = UIRenderer.prototype;
const updateMaterial: any = UIR.updateMaterial;
UIR.updateMaterial = function () {
updateMaterial.call(this);
//this.getSharedMaterial(0);
let material = this.customMaterial || this.material;
if (material) {
material['isMultTextures'] = false;
if (MultBatch2D.hash == material.hash) {
material['isMultTextures'] = true;
}
}
}
const PS2D: any = ParticleSystem2D.prototype;
const _updateMaterial = PS2D._updateMaterial;
PS2D._updateMaterial = function () {
_updateMaterial.call(this);
let material = this.customMaterial || this.material;
if (material) {
material['isMultTextures'] = false;
if (MultBatch2D.hash == material.hash) {
material['isMultTextures'] = true;
}
}
}
});
game.once(Game.EVENT_ENGINE_INITED, () => {
if (EDITOR || JSB) return;
cclegacy.UI.RenderData.prototype.texID = -1;
cclegacy.UI.RenderData.prototype.texDirty = true;
cclegacy.UI.RenderData.prototype.dataDirty = true;
Object.defineProperty(cclegacy.UI.RenderData.prototype, "vertDirty", {
get: function () {
return this._vertDirty;
},
set: function (val: boolean) {
this._vertDirty = val;
if (val === true) {
this.dataDirty = true;
}
if (this._renderDrawInfo && val) {
this._renderDrawInfo.setVertDirty(val);
}
}
});
Object.defineProperty(cclegacy.UI.RenderData.prototype, "textureDirty", {
get: function () {
return this.texDirty;
},
set: function (val: boolean) {
this.texDirty = val;
if (val === true) {
this.texID = -1;
}
}
});
const Spr: any = Sprite.prototype;
Spr.flagChangedVersion = -1;
Object.defineProperty(Spr, "_flagChangedVersion", {
get: function () {
return this.flagChangedVersion;
},
set: function (val: number) {
if (this.flagChangedVersion != val) {
this.flagChangedVersion = val;
let rd = this.renderData;
let type = this.type;
if (rd && type == Sprite.Type.TILED
|| (type == Sprite.Type.FILLED && Sprite.FillType.RADIAL)) {
rd.dataDirty = true;
}
}
}
});
director.on(Director.EVENT_AFTER_DRAW, (dt) => {
cclegacy.internal.Batcher2D._rdHash = -1;
MultBatch2D.reset();
_cacheUseCount = 0;
});
cclegacy.internal.Batcher2D.prototype.currMaterial = null;
Object.defineProperty(cclegacy.internal.Batcher2D.prototype, "_currMaterial", {
get: function () {
return this.currMaterial;
},
set: function (metrial: any) {
if (this.currMaterial === metrial) return;
this.currMaterial = metrial;
MultBatch2D.reset();
if (metrial && metrial.isMultTextures) {
let mat = getMultMaterial();
if (mat) {
this.currMaterial = mat;
}
}
}
});
const Stage_ENTER_LEVEL = 2;
const Stage_ENTER_LEVEL_INVERTED = 6;
type TextureBase = __private._cocos_asset_assets_texture_base__TextureBase;
cclegacy.internal.Batcher2D.prototype._rdHash = -1;
cclegacy.internal.Batcher2D.prototype.commitComp = function (comp: UIRenderer, renderData: BaseRenderData | null, frame: TextureBase | SpriteFrame | null, assembler: any, transform: Node | null) {
let rdHash = -1;
let dataHash = 0;
let mat: any;
let bufferID = -1;
if (renderData && renderData.chunk) {
if (!renderData.isValid()) return;
dataHash = renderData.dataHash;
mat = renderData.material;
bufferID = renderData.chunk.bufferId;
// as RenderData;
let rd: any = renderData;
rdHash = bufferID << 16 | rd.layer;
}
// Notice: A little hack, if it is for mask, not need update here, while control by stencilManger
if (comp.stencilStage === Stage_ENTER_LEVEL || comp.stencilStage === Stage_ENTER_LEVEL_INVERTED) {
this._insertMaskBatch(comp);
} else {
comp.stencilStage = StencilManager.sharedManager!.stage;
}
const depthStencilStateStage = comp.stencilStage;
let texID = -1;
let texture = null;
let flushBatch = false;
let isMultTextures = false;
if (MultBatch2D.enable && mat && mat.isMultTextures) {
texture = frame && frame.getGFXTexture();
texID = MultBatch2D.textures.indexOf(texture);
isMultTextures = true;
if (texID < 0) {
if (MultBatch2D.textures.length == MAX_TEX) {
// MultBatch2D.textures.length = 0;
flushBatch = true;
}
}
if (this._currMaterial && this._currMaterial.isMultTextures) {
mat = this._currMaterial;
dataHash = this._currHash;
if (this._rdHash != rdHash) {
flushBatch = true;
texID = -1;
}
}
}
if (flushBatch
|| this._currHash !== dataHash || dataHash === 0 || this._currMaterial !== mat
|| this._currDepthStencilStateStage !== depthStencilStateStage) {
// Merge all previous data to a render batch, and update buffer for next render data
this.autoMergeBatches(this._currComponent!);
if (renderData && !renderData._isMeshBuffer) {
this.updateBuffer(renderData.vertexFormat, bufferID);
}
this._rdHash = rdHash;
this._currRenderData = renderData;
this._currHash = renderData ? renderData.dataHash : 0;
this._currComponent = comp;
this._currTransform = transform;
this._currMaterial = comp.getRenderMaterial(0)!;
this._currDepthStencilStateStage = depthStencilStateStage;
this._currLayer = comp.node.layer;
if (frame) {
if (DEBUG) {
assert(frame.isValid, 'frame should not be invalid, it may have been released');
}
this._currTexture = frame.getGFXTexture();
this._currSampler = frame.getGFXSampler();
this._currTextureHash = frame.getHash();
this._currSamplerHash = this._currSampler.hash;
} else {
this._currTexture = null;
this._currSampler = null;
this._currTextureHash = 0;
this._currSamplerHash = 0;
}
}
assembler.fillBuffers(comp, this);
if (isMultTextures) {
if (texID < 0) {
texID = MultBatch2D.textures.length;
MultBatch2D.textures.push(texture);
if (texID > 0) {
_texture.setFrame(frame);
const name = "texture" + texID;
this._currMaterial.setProperty(name, _texture.texture);
}
}
this._fillDatas(renderData, texID);
}
}
cclegacy.internal.Batcher2D.prototype["_fillDatas"] = function (renderData: any, texID: number) {
if (!renderData) return;
let uvX = 0;
let vbuf = renderData.chunk.vb;
if (renderData.dataDirty) {
renderData.dataDirty = false;
for (let i = 0, length = vbuf.length; i < length; i += 9) {
uvX = ~~(vbuf[i + 3] * 100000);
vbuf[i + 3] = uvX * 10 + texID;
}
} else {
if (renderData.texID != texID) {
for (let i = 0, length = vbuf.length; i < length; i += 9) {
uvX = ~~(vbuf[i + 3] * 0.1);
vbuf[i + 3] = uvX * 10 + texID;
}
}
}
renderData.texID = texID;
};
});
//*/

View File

@@ -1,9 +0,0 @@
{
"ver": "4.0.23",
"importer": "typescript",
"imported": true,
"uuid": "bd7e7bed-a237-4c50-9383-95bb886ff622",
"files": [],
"subMetas": {},
"userData": {}
}