mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-04 10:32:39 +08:00
don't destroy samplers; don't do slice every frame (#3953)
This commit is contained in:
committed by
Weiliang Wang
parent
a63e82dddc
commit
2cd00ca2cc
@@ -862,13 +862,13 @@ export function WebGL2CmdFuncUpdateBuffer (device: WebGL2GFXDevice, gpuBuffer: W
|
||||
if (buffer instanceof Float32Array) {
|
||||
buf = buffer;
|
||||
} else {
|
||||
buf = new Float32Array(buffer as ArrayBuffer);
|
||||
buf = new Float32Array(buffer as ArrayBuffer, 0, size / 4);
|
||||
}
|
||||
|
||||
if (size === buff.byteLength) {
|
||||
if (size === buf.byteLength) {
|
||||
gl.bufferSubData(gpuBuffer.glTarget, offset, buf);
|
||||
} else {
|
||||
gl.bufferSubData(gpuBuffer.glTarget, offset, buff.slice(0, size));
|
||||
gl.bufferSubData(gpuBuffer.glTarget, offset, new Float32Array(buff, 0, size / 4));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
+16
-16
@@ -28,20 +28,20 @@ export enum UniformBinding {
|
||||
|
||||
export class UBOGlobal {
|
||||
public static TIME_OFFSET: number = 0;
|
||||
public static SCREEN_SIZE_OFFSET: number = 4;
|
||||
public static SCREEN_SCALE_OFFSET: number = 8;
|
||||
public static MAT_VIEW_OFFSET: number = 12;
|
||||
public static MAT_VIEW_INV_OFFSET: number = 28;
|
||||
public static MAT_PROJ_OFFSET: number = 44;
|
||||
public static MAT_PROJ_INV_OFFSET: number = 60;
|
||||
public static MAT_VIEW_PROJ_OFFSET: number = 76;
|
||||
public static MAT_VIEW_PROJ_INV_OFFSET: number = 92;
|
||||
public static CAMERA_POS_OFFSET: number = 108;
|
||||
public static MAIN_LIT_DIR_OFFSET: number = 112;
|
||||
public static MAIN_LIT_COLOR_OFFSET: number = 116;
|
||||
public static AMBIENT_SKY_OFFSET: number = 120;
|
||||
public static AMBIENT_GROUND_OFFSET: number = 124;
|
||||
public static COUNT: number = 128;
|
||||
public static SCREEN_SIZE_OFFSET: number = UBOGlobal.TIME_OFFSET + 4;
|
||||
public static SCREEN_SCALE_OFFSET: number = UBOGlobal.SCREEN_SIZE_OFFSET + 4;
|
||||
public static MAT_VIEW_OFFSET: number = UBOGlobal.SCREEN_SCALE_OFFSET + 4;
|
||||
public static MAT_VIEW_INV_OFFSET: number = UBOGlobal.MAT_VIEW_OFFSET + 16;
|
||||
public static MAT_PROJ_OFFSET: number = UBOGlobal.MAT_VIEW_INV_OFFSET + 16;
|
||||
public static MAT_PROJ_INV_OFFSET: number = UBOGlobal.MAT_PROJ_OFFSET + 16;
|
||||
public static MAT_VIEW_PROJ_OFFSET: number = UBOGlobal.MAT_PROJ_INV_OFFSET + 16;
|
||||
public static MAT_VIEW_PROJ_INV_OFFSET: number = UBOGlobal.MAT_VIEW_PROJ_OFFSET + 16;
|
||||
public static CAMERA_POS_OFFSET: number = UBOGlobal.MAT_VIEW_PROJ_INV_OFFSET + 16;
|
||||
public static MAIN_LIT_DIR_OFFSET: number = UBOGlobal.CAMERA_POS_OFFSET + 4;
|
||||
public static MAIN_LIT_COLOR_OFFSET: number = UBOGlobal.MAIN_LIT_DIR_OFFSET + 4;
|
||||
public static AMBIENT_SKY_OFFSET: number = UBOGlobal.MAIN_LIT_COLOR_OFFSET + 4;
|
||||
public static AMBIENT_GROUND_OFFSET: number = UBOGlobal.AMBIENT_SKY_OFFSET + 4;
|
||||
public static COUNT: number = UBOGlobal.AMBIENT_GROUND_OFFSET + 4;
|
||||
public static SIZE: number = UBOGlobal.COUNT * 4;
|
||||
|
||||
public static BLOCK: GFXUniformBlock = {
|
||||
@@ -70,8 +70,8 @@ export class UBOGlobal {
|
||||
|
||||
export class UBOLocal {
|
||||
public static MAT_WORLD_OFFSET: number = 0;
|
||||
public static MAT_WORLD_IT_OFFSET: number = 16;
|
||||
public static COUNT: number = 32;
|
||||
public static MAT_WORLD_IT_OFFSET: number = UBOLocal.MAT_WORLD_OFFSET + 16;
|
||||
public static COUNT: number = UBOLocal.MAT_WORLD_IT_OFFSET + 16;
|
||||
public static SIZE: number = UBOLocal.COUNT * 4;
|
||||
|
||||
public static BLOCK: GFXUniformBlock = {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
||||
|
||||
import { IPassInfo, IShaderInfo } from '../../3d/assets/effect-asset';
|
||||
import { IPassInfo, IShaderInfo, ISamplerInfo } from '../../3d/assets/effect-asset';
|
||||
import { builtinResMgr } from '../../3d/builtin';
|
||||
import { TextureBase } from '../../assets/texture-base';
|
||||
import { color4, mat2, mat3, mat4, vec2, vec3, vec4 } from '../../core/vmath';
|
||||
@@ -13,7 +13,7 @@ import { GFXPipelineLayout } from '../../gfx/pipeline-layout';
|
||||
import { GFXBlendState, GFXBlendTarget, GFXDepthStencilState,
|
||||
GFXInputState, GFXPipelineState, GFXRasterizerState } from '../../gfx/pipeline-state';
|
||||
import { GFXRenderPass } from '../../gfx/render-pass';
|
||||
import { GFXSampler, IGFXSamplerInfo } from '../../gfx/sampler';
|
||||
import { GFXSampler, IGFXSamplerInfo, GFXSamplerState } from '../../gfx/sampler';
|
||||
import { GFXShader } from '../../gfx/shader';
|
||||
import { GFXTextureView } from '../../gfx/texture-view';
|
||||
import { RenderPassStage, RenderPriority } from '../../pipeline/define';
|
||||
@@ -260,16 +260,16 @@ export class Pass {
|
||||
}
|
||||
|
||||
public destroy () {
|
||||
if (this._buffers) {
|
||||
for (const b of Object.values(this._buffers)) {
|
||||
const buffers = Object.values(this._buffers);
|
||||
if (buffers.length) {
|
||||
for (const b of buffers) {
|
||||
b.destroy();
|
||||
}
|
||||
this._buffers = {};
|
||||
}
|
||||
if (this._samplers) {
|
||||
for (const s of Object.values(this._samplers)) {
|
||||
s.destroy();
|
||||
}
|
||||
const samplers = Object.values(this._samplers);
|
||||
if (samplers.length) {
|
||||
// samplers are reused
|
||||
this._samplers = {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user