Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:add imutable texture flag for Webgl2 #16332

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cocos/gfx/base/define.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ export enum TextureFlagBit {
EXTERNAL_NORMAL = 0x8, // External normal texture
LAZILY_ALLOCATED = 0x10, // Try lazily allocated mode.
MUTABLE_VIEW_FORMAT = 0x40, // texture view as different format
MUTABLE_STORAGE = 0x80, // mutable storage for gl
}

export enum FormatFeatureBit {
Expand Down
5 changes: 4 additions & 1 deletion cocos/gfx/webgl2/webgl2-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ export class WebGL2CmdDraw extends WebGL2CmdObject {
}

public clear (): void {
// noop
}
}

Expand Down Expand Up @@ -1087,6 +1088,8 @@ export function WebGL2CmdFuncCreateTexture (device: WebGL2Device, gpuTexture: IW
w = Math.max(1, w >> 1);
h = Math.max(1, h >> 1);
}
} else if (gpuTexture.flags & TextureFlagBit.MUTABLE_STORAGE) {
gl.texImage2D(gl.TEXTURE_2D, 0, gpuTexture.glInternalFmt, w, h, 0, gpuTexture.glFormat, gpuTexture.glType, null);
} else {
gl.texStorage2D(gl.TEXTURE_2D, gpuTexture.mipLevel, gpuTexture.glInternalFmt, w, h);
}
Expand Down Expand Up @@ -2849,7 +2852,7 @@ export function WebGL2CmdFuncCopyTexImagesToTexture (

switch (gpuTexture.glTarget) {
case gl.TEXTURE_2D: {
if (toUseTexImage2D(texImages, regions)) {
if ((gpuTexture.flags & TextureFlagBit.MUTABLE_STORAGE) || toUseTexImage2D(texImages, regions)) {
gl.texImage2D(
gl.TEXTURE_2D,
regions[0].texSubres.mipLevel,
Expand Down
1 change: 1 addition & 0 deletions native/cocos/renderer/gfx-base/GFXDef-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ enum class TextureFlagBit : uint32_t {
EXTERNAL_NORMAL = 0x8, // External normal texture
LAZILY_ALLOCATED = 0x10, // Try lazily allocated mode.
MUTABLE_VIEW_FORMAT = 0x40, // texture view as different format
MUTABLE_STORAGE = 0x80, // mutable storage for gl image
};
using TextureFlags = TextureFlagBit;
CC_ENUM_BITWISE_OPERATORS(TextureFlagBit);
Expand Down
17 changes: 16 additions & 1 deletion native/cocos/renderer/gfx-gles3/GLES3Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,12 @@ static void textureStorage(GLES3Device *device, GLES3GPUTexture *gpuTexture) {
} else {
auto target = hasFlag(gpuTexture->flags, TextureFlagBit::EXTERNAL_OES) ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D;
GL_CHECK(glBindTexture(target, gpuTexture->glTexture));
GL_CHECK(glTexStorage2D(target, gpuTexture->mipLevel, gpuTexture->glInternalFmt, w, h));
if (hasFlag(gpuTexture->flags, TextureFlagBit::MUTABLE_STORAGE)) {
GL_CHECK(glTexImage2D(GL_TEXTURE_2D, gpuTexture->mipLevel, gpuTexture->glInternalFmt, w, h, 0,
gpuTexture->glFormat, gpuTexture->glType, nullptr));
} else {
GL_CHECK(glTexStorage2D(GL_TEXTURE_2D, gpuTexture->mipLevel, gpuTexture->glInternalFmt, w, h));
}
}
break;
case TextureType::TEX3D:
Expand Down Expand Up @@ -2736,6 +2741,16 @@ void cmdFuncGLES3CopyBuffersToTexture(GLES3Device *device, const uint8_t *const
gpuTexture->glFormat,
memSize,
(GLvoid *)buff));
} else if (hasFlag(gpuTexture->flags, TextureFlagBit::MUTABLE_STORAGE)) {
GL_CHECK(glTexImage2D(GL_TEXTURE_2D,
gpuTexture->mipLevel,
gpuTexture->glInternalFmt,
destWidth,
destHeight,
0,
gpuTexture->glFormat,
gpuTexture->glType,
(GLvoid *)buff));
} else {
GL_CHECK(glTexSubImage2D(GL_TEXTURE_2D,
mipLevel,
Expand Down
Loading