本文主要是介绍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数组)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!