CCTextureAtlas(Atlas地图集图册-表示将小纹理组成一张纹理集以达到批量渲染目的 方法-TextureAtlas维护了一个ccV3F_C4B_T2F_Quad数组)

本文主要是介绍CCTextureAtlas(Atlas地图集图册-表示将小纹理组成一张纹理集以达到批量渲染目的 方法-TextureAtlas维护了一个ccV3F_C4B_T2F_Quad数组),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

纹理和地图集

供AtlasSpriteManager与AtlasSprite的材质类
从Texture2D继承而来,在其基础上增加了一个非常重要的成员变量
ccV3F_C4B_T2F_Quad *  quads 

实际上AtlasSprite相比Sprite能快更得进行大批量渲染也是因为这个
TextureAtlas维护了一个ccV3F_C4B_T2F_Quad数组,使用一张texture进行batch render

其他与Texture2d没什么不同 


1.首先是AtlasSpriteManager使用一张TextureAtlas初始化,并设定Quad数组的长度
2.往AtlasSpriteManager加入AtlasSprite,这个加入的过程其实只是往AtlasSpriteManager的Quad数组中更新一个Quad
3.渲染的时候 使用一张Texture根据Quad数组中的不同值一个个渲染



#ifndef __CCTEXTURE_ATLAS_H__

#define __CCTEXTURE_ATLAS_H__


#include "ccTypes.h"

#include "cocoa/CCObject.h"

#include "ccConfig.h"

#include <string>


NS_CC_BEGIN


class CCTexture2D;


/** @brief A class that implements(执行 实现 工具) a Texture Atlas(图集).

Supported features:

* The atlas file can be a PVRTC, PNG or any other format supported by Texture2D//图集文件可以是PVRTC PNG等所有被Texture2D支持的类型

* Quads can be updated in runtime(执行时间,运行时间

* Quads can be added in runtime

* Quads can be removed in runtime

* Quads can be re-ordered in runtime

* The TextureAtlas capacity(容量) can be increased or decreased in runtime

* OpenGL component(组件): V3F, C4B, T2F.

The quads are rendered(绘制) using an OpenGL ES VBO.//默认使用OpenGL ES VBO绘制 想要使用别的方式绘制可以更改ccConfig.h file 

To render the quads using an interleaved(交叉存取 隔行扫描的 ) vertex array list, you should modify the ccConfig.h file 

*/

class CC_DLL CCTextureAtlas : public CCObject 

{

protected:

    GLushort*           m_pIndices;//目录

//

typedef unsigned short  GLushort;

//

#if CC_TEXTURE_ATLAS_USE_VAO  VAO顶点数组对象

    GLuint              m_uVAOname;

#endif

    GLuint              m_pBuffersVBO[2]; //0: vertex  1: indices   顶点缓冲对象(Vertex Buffer Object)

    bool                m_bDirty; //indicates(表明 显示) whether or not(不论 是否) the array buffer of the VBO needs to be updated



    /** quantity(数量) of quads that are going to be drawn */

    CC_PROPERTY_READONLY(unsigned int, m_uTotalQuads, TotalQuads)

    /** quantity of quads that can be stored with the current texture atlas size */

    CC_PROPERTY_READONLY(unsigned int, m_uCapacity, Capacity)

    /** Texture of the texture atlas */

    CC_PROPERTY(CCTexture2D *, m_pTexture, Texture)

    /** Quads that are going to be rendered */

    CC_PROPERTY(ccV3F_C4B_T2F_Quad *, m_pQuads, Quads)


public:


    CCTextureAtlas();

    virtual ~CCTextureAtlas();


    const char* description();


    /** creates a TextureAtlas with an filename and with an initial capacity for Quads.

    * The TextureAtlas capacity can be increased in runtime.

    */

    static CCTextureAtlas* create(const char* file , unsigned int capacity);


    /** initializes a TextureAtlas with a filename and with a certain capacity for Quads.

    * The TextureAtlas capacity can be increased in runtime.

    *

    * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)

    */

    bool initWithFile(const char* file, unsigned int capacity);


   /** creates a TextureAtlas with a previously initialized Texture2D object, and

    * with an initial capacity for n Quads. 

    * The TextureAtlas capacity can be increased in runtime.

    */

    static CCTextureAtlas* createWithTexture(CCTexture2D *texture, unsigned int capacity);



    /** initializes a TextureAtlas with a previously initialized Texture2D object, and

    * with an initial capacity for Quads. 

    * The TextureAtlas capacity can be increased in runtime.

    *

    * WARNING: Do not reinitialize the TextureAtlas because it will leak memory (issue #706)

    */

    bool initWithTexture(CCTexture2D *texture, unsigned int capacity);


    /** updates a Quad (texture, vertex and color) at a certain index

    * index must be between 0 and the atlas capacity - 1

    @since v0.8

    */

    void updateQuad(ccV3F_C4B_T2F_Quad* quad, unsigned int index);


    /** Inserts a Quad (texture, vertex and color) at a certain index

    index must be between 0 and the atlas capacity - 1

    @since v0.8

    */

    void insertQuad(ccV3F_C4B_T2F_Quad* quad, unsigned int index);


    /** Inserts a c array of quads at a given index

     index must be between 0 and the atlas capacity - 1

     this method doesn't enlarge the array when amount + index > totalQuads

     @since v1.1

    */

    void insertQuads(ccV3F_C4B_T2F_Quad* quads, unsigned int index, unsigned int amount);


    /** Removes the quad that is located at a certain index and inserts it at a new index

    This operation is faster than removing and inserting in a quad in 2 different steps

    @since v0.7.2

    */

    void insertQuadFromIndex(unsigned int fromIndex, unsigned int newIndex);


    /** removes a quad at a given index number.

    The capacity remains the same, but the total number of quads to be drawn is reduced in 1

    @since v0.7.2

    */

    void removeQuadAtIndex(unsigned int index);


    /** removes a amount of quads starting from index

        @since 1.1

     */

    void removeQuadsAtIndex(unsigned int index, unsigned int amount);

    /** removes all Quads.

    The TextureAtlas capacity remains untouched. No memory is freed.

    The total number of quads to be drawn will be 0

    @since v0.7.2

    */

    void removeAllQuads();



    /** resize the capacity of the CCTextureAtlas.

    * The new capacity can be lower or higher than the current one

    * It returns YES if the resize was successful.

    * If it fails to resize the capacity it will return NO with a new capacity of 0.

    */

    bool resizeCapacity(unsigned int n);


    /**

     Used internally by CCParticleBatchNode

     don't use this unless you know what you're doing

     @since 1.1

    */

    void increaseTotalQuadsWith(unsigned int amount);


    /** Moves an amount of quads from oldIndex at newIndex

     @since v1.1

     */

    void moveQuadsFromIndex(unsigned int oldIndex, unsigned int amount, unsigned int newIndex);


    /**

     Moves quads from index till totalQuads to the newIndex

     Used internally by CCParticleBatchNode

     This method doesn't enlarge the array if newIndex + quads to be moved > capacity

     @since 1.1

    */

    void moveQuadsFromIndex(unsigned int index, unsigned int newIndex);


    /**

     Ensures that after a realloc quads are still empty

     Used internally by CCParticleBatchNode

     @since 1.1

    */

    void fillWithEmptyQuadsFromIndex(unsigned int index, unsigned int amount);


    /** draws n quads

    * n can't be greater than the capacity of the Atlas

    */

    void drawNumberOfQuads(unsigned int n);


    /** draws n quads from an index (offset).

    n + start can't be greater than the capacity of the atlas


    @since v1.0

    */

    void drawNumberOfQuads(unsigned int n, unsigned int start);


    /** draws all the Atlas's Quads

    */

    void drawQuads();

    /** listen the event that coming to foreground on Android

     */

    void listenBackToForeground(CCObject *obj);


    /** whether or not the array buffer of the VBO needs to be updated*/

    inline bool isDirty(void) { return m_bDirty; }

    /** specify if the array buffer of the VBO needs to be updated */

    inline void setDirty(bool bDirty) { m_bDirty = bDirty; }


private:

    void setupIndices();

    void mapBuffers();

#if CC_TEXTURE_ATLAS_USE_VAO

    void setupVBOandVAO();

#else

    void setupVBO();

#endif

};


// end of textures group

/// @}


NS_CC_END


#endif //__CCTEXTURE_ATLAS_H__


这篇关于CCTextureAtlas(Atlas地图集图册-表示将小纹理组成一张纹理集以达到批量渲染目的 方法-TextureAtlas维护了一个ccV3F_C4B_T2F_Quad数组)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/661611

相关文章

Java中读取YAML文件配置信息常见问题及解决方法

《Java中读取YAML文件配置信息常见问题及解决方法》:本文主要介绍Java中读取YAML文件配置信息常见问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要... 目录1 使用Spring Boot的@ConfigurationProperties2. 使用@Valu

Java中的数组与集合基本用法详解

《Java中的数组与集合基本用法详解》本文介绍了Java数组和集合框架的基础知识,数组部分涵盖了一维、二维及多维数组的声明、初始化、访问与遍历方法,以及Arrays类的常用操作,对Java数组与集合相... 目录一、Java数组基础1.1 数组结构概述1.2 一维数组1.2.1 声明与初始化1.2.2 访问

Java 方法重载Overload常见误区及注意事项

《Java方法重载Overload常见误区及注意事项》Java方法重载允许同一类中同名方法通过参数类型、数量、顺序差异实现功能扩展,提升代码灵活性,核心条件为参数列表不同,不涉及返回类型、访问修饰符... 目录Java 方法重载(Overload)详解一、方法重载的核心条件二、构成方法重载的具体情况三、不构

SQL中如何添加数据(常见方法及示例)

《SQL中如何添加数据(常见方法及示例)》SQL全称为StructuredQueryLanguage,是一种用于管理关系数据库的标准编程语言,下面给大家介绍SQL中如何添加数据,感兴趣的朋友一起看看吧... 目录在mysql中,有多种方法可以添加数据。以下是一些常见的方法及其示例。1. 使用INSERT I

Python中反转字符串的常见方法小结

《Python中反转字符串的常见方法小结》在Python中,字符串对象没有内置的反转方法,然而,在实际开发中,我们经常会遇到需要反转字符串的场景,比如处理回文字符串、文本加密等,因此,掌握如何在Pyt... 目录python中反转字符串的方法技术背景实现步骤1. 使用切片2. 使用 reversed() 函

Python中将嵌套列表扁平化的多种实现方法

《Python中将嵌套列表扁平化的多种实现方法》在Python编程中,我们常常会遇到需要将嵌套列表(即列表中包含列表)转换为一个一维的扁平列表的需求,本文将给大家介绍了多种实现这一目标的方法,需要的朋... 目录python中将嵌套列表扁平化的方法技术背景实现步骤1. 使用嵌套列表推导式2. 使用itert

Python使用pip工具实现包自动更新的多种方法

《Python使用pip工具实现包自动更新的多种方法》本文深入探讨了使用Python的pip工具实现包自动更新的各种方法和技术,我们将从基础概念开始,逐步介绍手动更新方法、自动化脚本编写、结合CI/C... 目录1. 背景介绍1.1 目的和范围1.2 预期读者1.3 文档结构概述1.4 术语表1.4.1 核

在Linux中改变echo输出颜色的实现方法

《在Linux中改变echo输出颜色的实现方法》在Linux系统的命令行环境下,为了使输出信息更加清晰、突出,便于用户快速识别和区分不同类型的信息,常常需要改变echo命令的输出颜色,所以本文给大家介... 目python录在linux中改变echo输出颜色的方法技术背景实现步骤使用ANSI转义码使用tpu

Conda与Python venv虚拟环境的区别与使用方法详解

《Conda与Pythonvenv虚拟环境的区别与使用方法详解》随着Python社区的成长,虚拟环境的概念和技术也在不断发展,:本文主要介绍Conda与Pythonvenv虚拟环境的区别与使用... 目录前言一、Conda 与 python venv 的核心区别1. Conda 的特点2. Python v

Spring Boot中WebSocket常用使用方法详解

《SpringBoot中WebSocket常用使用方法详解》本文从WebSocket的基础概念出发,详细介绍了SpringBoot集成WebSocket的步骤,并重点讲解了常用的使用方法,包括简单消... 目录一、WebSocket基础概念1.1 什么是WebSocket1.2 WebSocket与HTTP