Skip to content

Commit

Permalink
add whole buffer recreation
Browse files Browse the repository at this point in the history
  • Loading branch information
star-e committed Sep 14, 2024
1 parent 78909fd commit e482312
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions cocos/gfx/webgl2/webgl2-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,9 @@ export function WebGL2CmdFuncUpdateBuffer (
cache.glArrayBuffer = gpuBuffer.glBuffer;
}

if (size === buff.byteLength) {
if ((gpuBuffer.memUsage & MemoryUsageBit.HOST) && offset === 0 && size === buff.byteLength) {
gl.bufferData(gpuBuffer.glTarget, buff, gl.DYNAMIC_DRAW);
} else if (size === buff.byteLength) {
gl.bufferSubData(gpuBuffer.glTarget, offset, buff);
} else {
gl.bufferSubData(gpuBuffer.glTarget, offset, buff.slice(0, size));
Expand All @@ -1022,7 +1024,9 @@ export function WebGL2CmdFuncUpdateBuffer (
cache.glElementArrayBuffer = gpuBuffer.glBuffer;
}

if (size === buff.byteLength) {
if ((gpuBuffer.memUsage & MemoryUsageBit.HOST) && offset === 0 && size === buff.byteLength) {
gl.bufferData(gpuBuffer.glTarget, buff, gl.DYNAMIC_DRAW);
} else if (size === buff.byteLength) {
gl.bufferSubData(gpuBuffer.glTarget, offset, buff);
} else {
gl.bufferSubData(gpuBuffer.glTarget, offset, buff.slice(0, size));
Expand All @@ -1035,7 +1039,9 @@ export function WebGL2CmdFuncUpdateBuffer (
cache.glUniformBuffer = gpuBuffer.glBuffer;
}

if (size === buff.byteLength) {
if ((gpuBuffer.memUsage & MemoryUsageBit.HOST) && offset === 0 && size === buff.byteLength) {
gl.bufferData(gpuBuffer.glTarget, buff, gl.DYNAMIC_DRAW);
} else if (size === buff.byteLength) {
gl.bufferSubData(gpuBuffer.glTarget, offset, buff);
} else {
gl.bufferSubData(gpuBuffer.glTarget, offset, new Float32Array(buff, 0, size / 4));
Expand Down

0 comments on commit e482312

Please sign in to comment.