-
-
Notifications
You must be signed in to change notification settings - Fork 180
/
Copy pathTextureAtlas.h
109 lines (87 loc) · 2.18 KB
/
TextureAtlas.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Copyright (c) scott.cgi All Rights Reserved.
*
* This source code belongs to project Mojoc, which is a pure C Game Engine hosted on GitHub.
* The Mojoc Game Engine is licensed under the MIT License, and will continue to be iterated with coding passion.
*
* License : https://github.com/scottcgi/Mojoc/blob/master/LICENSE
* GitHub : https://github.com/scottcgi/Mojoc
* CodeStyle: https://github.com/scottcgi/Mojoc/blob/master/Docs/CodeStyle.md
*
* Since : 2016-7-22
* Update : 2019-1-31
* Author : scott.cgi
*/
#ifndef TEXTURE_ATLAS_H
#define TEXTURE_ATLAS_H
#include "Engine/Graphics/Draw/Quad.h"
#include "Engine/Toolkit/Utils/ArrayStrMap.h"
/**
* The atlas including textures and quads info.
*/
typedef struct
{
/**
* Texture atlas quad info from file.
*/
ArrayStrMap(quadName, TextureAtlasQuad) quadMap[1];
/**
* Textures in atlas.
*/
ArrayList (Texture*) textureList[1];
/**
* Be key identify TextureAtlas.
*/
const char* filePath;
}
TextureAtlas;
/**
* Quad in TextureAtlas.
*/
typedef struct
{
/**
* Quad belongs to.
*/
TextureAtlas* atlas;
/**
* Quad data in texture.
*/
Quad quad[1];
/**
* The index of Quad's texture in TextureAtlas textureList.
*/
int textureIndex;
}
TextureAtlasQuad;
/**
* Manage TextureAtlas.
*/
struct ATextureAtlas
{
/**
* Get TextureAtlas by TextureAtlas.
*
* filePath:
* Android: assets
* IOS : NSBundle
*/
TextureAtlas* (*Get) (const char* filePath);
void (*Release)(TextureAtlas* textureAtlas);
};
extern struct ATextureAtlas ATextureAtlas[1];
/**
* Get TextureAtlasQuad from atlas by quadName.
*/
static inline TextureAtlasQuad* ATextureAtlas_GetQuad(TextureAtlas* atlas, const char* quadName)
{
return AArrayStrMap_GetPtr(atlas->quadMap, quadName, TextureAtlasQuad);
}
/**
* Get Texture from atlasQuad.
*/
static inline Texture* ATextureAtlas_GetQuadTexture(TextureAtlasQuad* atlasQuad)
{
return AArrayList_Get(atlasQuad->atlas->textureList, atlasQuad->textureIndex, Texture*);
}
#endif