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

相关文章

Nginx设置连接超时并进行测试的方法步骤

《Nginx设置连接超时并进行测试的方法步骤》在高并发场景下,如果客户端与服务器的连接长时间未响应,会占用大量的系统资源,影响其他正常请求的处理效率,为了解决这个问题,可以通过设置Nginx的连接... 目录设置连接超时目的操作步骤测试连接超时测试方法:总结:设置连接超时目的设置客户端与服务器之间的连接

Java判断多个时间段是否重合的方法小结

《Java判断多个时间段是否重合的方法小结》这篇文章主要为大家详细介绍了Java中判断多个时间段是否重合的方法,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录判断多个时间段是否有间隔判断时间段集合是否与某时间段重合判断多个时间段是否有间隔实体类内容public class D

Python使用国内镜像加速pip安装的方法讲解

《Python使用国内镜像加速pip安装的方法讲解》在Python开发中,pip是一个非常重要的工具,用于安装和管理Python的第三方库,然而,在国内使用pip安装依赖时,往往会因为网络问题而导致速... 目录一、pip 工具简介1. 什么是 pip?2. 什么是 -i 参数?二、国内镜像源的选择三、如何

IDEA编译报错“java: 常量字符串过长”的原因及解决方法

《IDEA编译报错“java:常量字符串过长”的原因及解决方法》今天在开发过程中,由于尝试将一个文件的Base64字符串设置为常量,结果导致IDEA编译的时候出现了如下报错java:常量字符串过长,... 目录一、问题描述二、问题原因2.1 理论角度2.2 源码角度三、解决方案解决方案①:StringBui

Linux使用nload监控网络流量的方法

《Linux使用nload监控网络流量的方法》Linux中的nload命令是一个用于实时监控网络流量的工具,它提供了传入和传出流量的可视化表示,帮助用户一目了然地了解网络活动,本文给大家介绍了Linu... 目录简介安装示例用法基础用法指定网络接口限制显示特定流量类型指定刷新率设置流量速率的显示单位监控多个

Java覆盖第三方jar包中的某一个类的实现方法

《Java覆盖第三方jar包中的某一个类的实现方法》在我们日常的开发中,经常需要使用第三方的jar包,有时候我们会发现第三方的jar包中的某一个类有问题,或者我们需要定制化修改其中的逻辑,那么应该如何... 目录一、需求描述二、示例描述三、操作步骤四、验证结果五、实现原理一、需求描述需求描述如下:需要在

JavaScript中的reduce方法执行过程、使用场景及进阶用法

《JavaScript中的reduce方法执行过程、使用场景及进阶用法》:本文主要介绍JavaScript中的reduce方法执行过程、使用场景及进阶用法的相关资料,reduce是JavaScri... 目录1. 什么是reduce2. reduce语法2.1 语法2.2 参数说明3. reduce执行过程

C#中读取XML文件的四种常用方法

《C#中读取XML文件的四种常用方法》Xml是Internet环境中跨平台的,依赖于内容的技术,是当前处理结构化文档信息的有力工具,下面我们就来看看C#中读取XML文件的方法都有哪些吧... 目录XML简介格式C#读取XML文件方法使用XmlDocument使用XmlTextReader/XmlTextWr

C++初始化数组的几种常见方法(简单易懂)

《C++初始化数组的几种常见方法(简单易懂)》本文介绍了C++中数组的初始化方法,包括一维数组和二维数组的初始化,以及用new动态初始化数组,在C++11及以上版本中,还提供了使用std::array... 目录1、初始化一维数组1.1、使用列表初始化(推荐方式)1.2、初始化部分列表1.3、使用std::

C++ Primer 多维数组的使用

《C++Primer多维数组的使用》本文主要介绍了多维数组在C++语言中的定义、初始化、下标引用以及使用范围for语句处理多维数组的方法,具有一定的参考价值,感兴趣的可以了解一下... 目录多维数组多维数组的初始化多维数组的下标引用使用范围for语句处理多维数组指针和多维数组多维数组严格来说,C++语言没