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

Add gfx.device.copyTextureToTexture #17272

Draft
wants to merge 5 commits into
base: v3.8.4
Choose a base branch
from

Conversation

dumganhar
Copy link
Contributor

@dumganhar dumganhar commented Jul 2, 2024

Re: #17268

This PR was originally developed by @zhoujianbo0

Changelog


Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

@dumganhar dumganhar requested review from minggo and star-e July 2, 2024 05:40
@dumganhar dumganhar changed the title Add gfx.copyTextureToTexture Add gfx.device.copyTextureToTexture Jul 2, 2024
Copy link

github-actions bot commented Jul 2, 2024

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -9656,8 +9656,9 @@
              * @param texture The texture to copy to.
              * @param regions The region descriptions.
              */
             abstract copyTexImagesToTexture(texImages: Readonly<TexImageSource[]>, texture: Texture, regions: Readonly<BufferTextureCopy[]>): void;
+            abstract copyTextureToTexture(from: Texture, to: Texture, dx: number, dy: number, fromRegion: Readonly<Rect> | null): any;
             /**
              * @en Whether the device has specific feature.
              * @zh 是否具备特性。
              * @param feature The GFX feature to be queried.
@@ -45104,8 +45105,9 @@
         getBufferBarrier(info: Readonly<gfx.BufferBarrierInfo>): __private._cocos_gfx_base_states_buffer_barrier__BufferBarrier;
         copyBuffersToTexture(buffers: Readonly<ArrayBufferView[]>, texture: gfx.Texture, regions: Readonly<gfx.BufferTextureCopy[]>): void;
         copyTextureToBuffers(texture: Readonly<gfx.Texture>, buffers: ArrayBufferView[], regions: Readonly<gfx.BufferTextureCopy[]>): void;
         copyTexImagesToTexture(texImages: Readonly<TexImageSource[]>, texture: gfx.Texture, regions: Readonly<gfx.BufferTextureCopy[]>): void;
+        copyTextureToTexture(from: gfx.Texture, to: gfx.Texture, dx: number, dy: number, fromRegion: Readonly<gfx.Rect> | null): void;
     }
     export class WebGLDevice extends gfx.Device {
         get gl(): WebGLRenderingContext;
         get extensions(): __private._cocos_gfx_webgl_webgl_define__IWebGLExtensions;
@@ -45142,8 +45144,9 @@
         getBufferBarrier(info: Readonly<gfx.BufferBarrierInfo>): __private._cocos_gfx_base_states_buffer_barrier__BufferBarrier;
         copyBuffersToTexture(buffers: Readonly<ArrayBufferView[]>, texture: gfx.Texture, regions: Readonly<gfx.BufferTextureCopy[]>): void;
         copyTextureToBuffers(texture: Readonly<gfx.Texture>, buffers: ArrayBufferView[], regions: Readonly<gfx.BufferTextureCopy[]>): void;
         copyTexImagesToTexture(texImages: Readonly<TexImageSource[]>, texture: gfx.Texture, regions: Readonly<gfx.BufferTextureCopy[]>): void;
+        copyTextureToTexture(from: gfx.Texture, to: gfx.Texture, dx: number, dy: number, fromRegion: Readonly<gfx.Rect> | null): void;
     }
     export class WebGL2Device extends gfx.Device {
         get gl(): WebGL2RenderingContext;
         get extensions(): __private._cocos_gfx_webgl2_webgl2_define__IWebGL2Extensions;
@@ -45180,8 +45183,9 @@
         getBufferBarrier(info: Readonly<gfx.BufferBarrierInfo>): __private._cocos_gfx_base_states_buffer_barrier__BufferBarrier;
         copyBuffersToTexture(buffers: Readonly<ArrayBufferView[]>, texture: gfx.Texture, regions: Readonly<gfx.BufferTextureCopy[]>): void;
         copyTextureToBuffers(texture: Readonly<gfx.Texture>, buffers: ArrayBufferView[], regions: Readonly<gfx.BufferTextureCopy[]>): void;
         copyTexImagesToTexture(texImages: Readonly<TexImageSource[]>, texture: gfx.Texture, regions: Readonly<gfx.BufferTextureCopy[]>): void;
+        copyTextureToTexture(from: gfx.Texture, to: gfx.Texture, dx: number, dy: number, fromRegion: Readonly<gfx.Rect> | null): void;
     }
     export class WebGPUDevice extends gfx.Device {
         createSwapchain(info: Readonly<gfx.SwapchainInfo>): gfx.Swapchain;
         getSampler(info: Readonly<gfx.SamplerInfo>): gfx.Sampler;
@@ -45228,8 +45232,9 @@
         copyBuffersToTexture(buffers: ArrayBufferView[], texture: gfx.Texture, regions: gfx.BufferTextureCopy[]): void;
         copyTexImagesToTexture(texImages: TexImageSource[], texture: gfx.Texture, regions: gfx.BufferTextureCopy[]): void;
         copyFramebufferToBuffer(srcFramebuffer: gfx.Framebuffer, dstBuffer: ArrayBuffer, regions: gfx.BufferTextureCopy[]): void;
         blitFramebuffer(src: gfx.Framebuffer, dst: gfx.Framebuffer, srcRect: gfx.Rect, dstRect: gfx.Rect, filter: gfx.Filter): void;
+        copyTextureToTexture(from: gfx.Texture, to: gfx.Texture, dx: number, dy: number, fromRegion: Readonly<gfx.Rect> | null): void;
     }
     /**
      * @en Intersection2D helper class
      * @zh 辅助类,用于测试形状与形状是否相交
@@ -61128,8 +61133,9 @@
              * @param {Texture2D} image
              * @param {Number} x
              * @param {Number} y
              */
+            drawTextureAt(texture: Texture2D, x: number, y: number): void;
             drawTextureAt(image: ImageAsset, x: number, y: number): void;
         }
         /**
          * @en The instance of [[MorphRendering]] for dedicated control in the mesh renderer.

gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, dx, dy, srcX, srcY, srcW, srcH);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
cache.glFramebuffer = null;
gl.deleteFramebuffer(framebuffer);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to create / delete FBO each time. Consider to re-use it.

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

5 similar comments
@shaoqiangcai
Copy link
Contributor

@cocos-robot run test cases

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

@shaoqiangcai
Copy link
Contributor

@cocos-robot run test cases

@sushanhong
Copy link
Contributor

@cocos-robot run test cases

@dumganhar dumganhar force-pushed the 385-gfx-copyTextureToTexture branch from ffb3265 to 1e4f032 Compare July 2, 2024 08:34
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

3 similar comments
@minggo
Copy link
Contributor

minggo commented Jul 2, 2024

@cocos-robot run test cases

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

@dumganhar dumganhar force-pushed the 385-gfx-copyTextureToTexture branch from ce703d4 to f141514 Compare July 2, 2024 09:48
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

1 similar comment
@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases

@dumganhar
Copy link
Contributor Author

@cocos-robot run test cases


GL_CHECK(glBindTexture(dstGPU->glTarget, dstGPU->glTexture));
cache->glTextures[cache->texUint] = dstGPU->glTexture;
GL_CHECK(glCopyTexSubImage2D(dstGPU->glTarget, 0, dstX, dstY, x, y, w, h));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memoryleak here. need to invoke glDeleteFramebuffers and reset cache->glReadFramebuffer to 0.

@shaoqiangcai
Copy link
Contributor

@cocos-robot run test cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants