-
Notifications
You must be signed in to change notification settings - Fork 5
/
poTextureAtlas.h
93 lines (74 loc) · 2.58 KB
/
poTextureAtlas.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
/*
* Copyright 2012 Potion Design. All rights reserved.
* This file is part of pocode.
*
* pocode is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* pocode is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with pocode. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
#include "poRect.h"
#include "poPoint.h"
#include "poTexture.h"
#include "poBinPacker.h"
class poTextureAtlas {
public:
poTextureAtlas(GLenum f, uint w, uint h);
poTextureAtlas(poTextureConfig config, uint w, uint h);
~poTextureAtlas();
// pass in the id you want to have associated with the image
void addImage(poImage *img, uint requested_id);
// remove all images that are current in there
void clearImages();
// will redo all the bin packing with the current set of images
void layoutAtlas();
bool hasUID(uint uid);
int getNumPages();
poPoint getDimensions() const;
uint getPageForUID(uint uid);
poRect getCoordsForUID(uint uid);
poRect getSizeForUID(uint uid);
poTexture* getTextureForPage(uint pg);
poTexture* getTextureForUID(uint uid);
// draws will shift the texture as needed,
// tho user can look at the pages for what it wants to draw and
// organize it so there are minimal texture switches
// size should be between 0..1, will scale
void drawUID(uint uid, poRect r, float scale);
// this one will draw the subtex at its native size
void drawUID(uint uid, poPoint p, float scale);
// dump the pack to screen for debugging
void debugDraw();
private:
struct ImageLookup {
uint page;
poRect coords;
poPoint size;
};
void clearPages();
void clearTextures();
int width, height;
std::vector<ImageLookup> coords;
// the items to be atlased
std::vector<poImage*> images;
// users control the ids
std::vector<uint> requestedIDs;
// the pages of the atlas
std::vector<poImage*> pages;
// the textures of the atlas
std::vector<poTexture*> textures;
std::map<uint,uint> uids;
// this is the configuration we want for the atlas
poTextureConfig config;
BinPacker packer;
};