creator - automatic atlas optimization for rendering batches


title: creator-automatic atlas optimization rendering batches
categories: Cocos2dx
tags: [creator, optimization, rendering, atlas]
date: 2023-03-23 ​​16:08:24
comments: false
mathjax: true
toc: true

creator - automatic atlas optimization for rendering batches


Prequel

  • Auto Atlas - https://docs.cocos.com/creator/manual/zh/asset/auto-atlas.html
  • Cocos Creator atlas (TexturePacker, automatic atlas function, compressed texture, compression plugin) - https://www.jianshu.com/p/f8f1e830d112
  • cocos automatic atlas - https://www.cnblogs.com/xiaochongchong/p/9681414.html

When previewing a project or using fragmented images in Cocos Creator, they are directly used fragmented image resources, and the atlas will be actually generated into the project in the step of building the project. Under normal circumstances, after the atlas resource is generated, the texture and image image resources of the original small image in the package body will be deleted. The following two special cases will be handled specially:

When the atlas resources are in the Bundle directory, in addition to the normal generation of atlas resources, the texture and image resources generated by the original spriteFrame will also be generated at the same time. If there is a clear scope of use for the atlas resources, please check the corresponding exclusion option to avoid causing The package is too large.

When any spriteFrame dependent texture in the atlas resource folder is directly used by other resources (such as directly used as a texture map), the dependent texture and its image resources will be packaged together.

The above two cases will actually increase the package size, and the build will warn you. If it is not necessary, please do not use it like this.

The purpose of creating an atlas is to reduce the number of rendering batches, so the pictures on the same ui should be typed into the same atlas as much as possible to reduce the number of rendering batches


manual

When dynamically loading a fragmented image in the business code, you don’t need to care whether it is an automatic atlas. So this automatic atlas is still very friendly, and it will be more painless than the atlas created by texture packer

  1. Directly need to print the directory of the atlas, right-click the directory -> create -> automatic atlas configuration

    image-20230323161002463

    • An auto-atlas.pac file will be automatically created in this directory
  2. done


Modify gallery and preview

  1. After modifying the gallery configuration, click to save

    image-20230323161740297

    You can preview the packaged atlas to see what it looks like. If you don’t preview it, it will not affect the packaged atlas.


practical testing

In development mode, you can’t see the batching effect until you run it in the browser, and you can only see it after building it

  1. The build configuration opens the debug mode to see the drawcall

    image-20230323162131085

  2. Both are atlases, but two more pictures are displayed on the right

    image-20230323162246288

    There are two more pictures on the left than on the right (2*2=4 more triangles), and the batch is the same, indicating that the atlas is valid

  3. Atlas on the left, no atlas on the right

    image-20230323162516691

    There are two more batches without the atlas on the right


Guess you like

Origin blog.csdn.net/yangxuan0261/article/details/129733864