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中,函数通常用于封装一段代码,使其可以重复调用,有时,我们希望一个函数能够返回多个值,Python提供了几种不同的方法来实现这一点,需要的朋友... 目录一、使用元组(Tuple):二、使用列表(list)三、使用字典(Dictionary)四、 使

Linux查看系统盘和SSD盘的容量、型号及挂载信息的方法

《Linux查看系统盘和SSD盘的容量、型号及挂载信息的方法》在Linux系统中,管理磁盘设备和分区是日常运维工作的重要部分,而lsblk命令是一个强大的工具,它用于列出系统中的块设备(blockde... 目录1. 查看所有磁盘的物理信息方法 1:使用 lsblk(推荐)方法 2:使用 fdisk -l(

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1

MySQL查看表的最后一个ID的常见方法

《MySQL查看表的最后一个ID的常见方法》在使用MySQL数据库时,我们经常会遇到需要查看表中最后一个id值的场景,无论是为了调试、数据分析还是其他用途,了解如何快速获取最后一个id都是非常实用的技... 目录背景介绍方法一:使用MAX()函数示例代码解释适用场景方法二:按id降序排序并取第一条示例代码解

Python中合并列表(list)的六种方法小结

《Python中合并列表(list)的六种方法小结》本文主要介绍了Python中合并列表(list)的六种方法小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋... 目录一、直接用 + 合并列表二、用 extend() js方法三、用 zip() 函数交叉合并四、用

Java 中的跨域问题解决方法

《Java中的跨域问题解决方法》跨域问题本质上是浏览器的一种安全机制,与Java本身无关,但Java后端开发者需要理解其来源以便正确解决,下面给大家介绍Java中的跨域问题解决方法,感兴趣的朋友一起... 目录1、Java 中跨域问题的来源1.1. 浏览器同源策略(Same-Origin Policy)1.

Java Stream.reduce()方法操作实际案例讲解

《JavaStream.reduce()方法操作实际案例讲解》reduce是JavaStreamAPI中的一个核心操作,用于将流中的元素组合起来产生单个结果,:本文主要介绍JavaStream.... 目录一、reduce的基本概念1. 什么是reduce操作2. reduce方法的三种形式二、reduce

MybatisX快速生成增删改查的方法示例

《MybatisX快速生成增删改查的方法示例》MybatisX是基于IDEA的MyBatis/MyBatis-Plus开发插件,本文主要介绍了MybatisX快速生成增删改查的方法示例,文中通过示例代... 目录1 安装2 基本功能2.1 XML跳转2.2 代码生成2.2.1 生成.xml中的sql语句头2

python3 pip终端出现错误解决的方法详解

《python3pip终端出现错误解决的方法详解》这篇文章主要为大家详细介绍了python3pip如果在终端出现错误该如何解决,文中的示例方法讲解详细,感兴趣的小伙伴可以跟随小编一起了解一下... 目录前言一、查看是否已安装pip二、查看是否添加至环境变量1.查看环境变量是http://www.cppcns

Linux给磁盘扩容(LVM方式)的方法实现

《Linux给磁盘扩容(LVM方式)的方法实现》本文主要介绍了Linux给磁盘扩容(LVM方式)的方法实现,涵盖PV/VG/LV概念及操作步骤,具有一定的参考价值,感兴趣的可以了解一下... 目录1 概念2 实战2.1 相关基础命令2.2 开始给LVM扩容2.3 总结最近测试性能,在本地打数据时,发现磁盘空