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

相关文章

python获取网页表格的多种方法汇总

《python获取网页表格的多种方法汇总》我们在网页上看到很多的表格,如果要获取里面的数据或者转化成其他格式,就需要将表格获取下来并进行整理,在Python中,获取网页表格的方法有多种,下面就跟随小编... 目录1. 使用Pandas的read_html2. 使用BeautifulSoup和pandas3.

Spring 中的循环引用问题解决方法

《Spring中的循环引用问题解决方法》:本文主要介绍Spring中的循环引用问题解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录什么是循环引用?循环依赖三级缓存解决循环依赖二级缓存三级缓存本章来聊聊Spring 中的循环引用问题该如何解决。这里聊

Java学习手册之Filter和Listener使用方法

《Java学习手册之Filter和Listener使用方法》:本文主要介绍Java学习手册之Filter和Listener使用方法的相关资料,Filter是一种拦截器,可以在请求到达Servl... 目录一、Filter(过滤器)1. Filter 的工作原理2. Filter 的配置与使用二、Listen

Pandas统计每行数据中的空值的方法示例

《Pandas统计每行数据中的空值的方法示例》处理缺失数据(NaN值)是一个非常常见的问题,本文主要介绍了Pandas统计每行数据中的空值的方法示例,具有一定的参考价值,感兴趣的可以了解一下... 目录什么是空值?为什么要统计空值?准备工作创建示例数据统计每行空值数量进一步分析www.chinasem.cn处

Windows 上如果忘记了 MySQL 密码 重置密码的两种方法

《Windows上如果忘记了MySQL密码重置密码的两种方法》:本文主要介绍Windows上如果忘记了MySQL密码重置密码的两种方法,本文通过两种方法结合实例代码给大家介绍的非常详细,感... 目录方法 1:以跳过权限验证模式启动 mysql 并重置密码方法 2:使用 my.ini 文件的临时配置在 Wi

MySQL重复数据处理的七种高效方法

《MySQL重复数据处理的七种高效方法》你是不是也曾遇到过这样的烦恼:明明系统测试时一切正常,上线后却频频出现重复数据,大批量导数据时,总有那么几条不听话的记录导致整个事务莫名回滚,今天,我就跟大家分... 目录1. 重复数据插入问题分析1.1 问题本质1.2 常见场景图2. 基础解决方案:使用异常捕获3.

最详细安装 PostgreSQL方法及常见问题解决

《最详细安装PostgreSQL方法及常见问题解决》:本文主要介绍最详细安装PostgreSQL方法及常见问题解决,介绍了在Windows系统上安装PostgreSQL及Linux系统上安装Po... 目录一、在 Windows 系统上安装 PostgreSQL1. 下载 PostgreSQL 安装包2.

SQL中redo log 刷⼊磁盘的常见方法

《SQL中redolog刷⼊磁盘的常见方法》本文主要介绍了SQL中redolog刷⼊磁盘的常见方法,将redolog刷入磁盘的方法确保了数据的持久性和一致性,下面就来具体介绍一下,感兴趣的可以了解... 目录Redo Log 刷入磁盘的方法Redo Log 刷入磁盘的过程代码示例(伪代码)在数据库系统中,r

Python实现图片分割的多种方法总结

《Python实现图片分割的多种方法总结》图片分割是图像处理中的一个重要任务,它的目标是将图像划分为多个区域或者对象,本文为大家整理了一些常用的分割方法,大家可以根据需求自行选择... 目录1. 基于传统图像处理的分割方法(1) 使用固定阈值分割图片(2) 自适应阈值分割(3) 使用图像边缘检测分割(4)

Java中Switch Case多个条件处理方法举例

《Java中SwitchCase多个条件处理方法举例》Java中switch语句用于根据变量值执行不同代码块,适用于多个条件的处理,:本文主要介绍Java中SwitchCase多个条件处理的相... 目录前言基本语法处理多个条件示例1:合并相同代码的多个case示例2:通过字符串合并多个case进阶用法使用