/
texturemanifest.cpp
144 lines (122 loc) · 3.76 KB
/
texturemanifest.cpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/** @file texturemanifest.cpp Texture Manifest.
*
* @author Copyright © 2010-2012 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program 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 General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA</small>
*/
#include "resource/texturemanifest.h"
#include "resource/textures.h"
namespace de {
TextureManifest::TextureManifest(PathTree::NodeArgs const &args) : Node(args),
uniqueId_(0), resourceUri_(), texture_(0)
{}
TextureManifest::~TextureManifest()
{
LOG_AS("~TextureManifest");
if(texture_)
{
#if _DEBUG
LOG_WARNING("\"%s\" still has an associated texture!")
<< composeUri();
#endif
delete texture_;
}
}
Textures &TextureManifest::textures()
{
return *App_Textures();
}
Texture *TextureManifest::derive(Size2Raw const &dimensions, Texture::Flags flags)
{
if(Texture *tex = texture())
{
#if _DEBUG
LOG_WARNING("A Texture with uri \"%s\" already exists, returning existing.")
<< composeUri();
#endif
tex->setDimensions(dimensions);
tex->flagCustom(!!(flags & Texture::Custom));
/// @todo Materials and Surfaces should be notified of this!
return tex;
}
Texture *tex = Textures::ResourceClass::interpret(*this, dimensions, flags);
if(!texture()) setTexture(tex);
return tex;
}
Texture *TextureManifest::derive(Texture::Flags flags)
{
return derive(Size2Raw(0, 0), flags);
}
Textures::Scheme &TextureManifest::scheme() const
{
LOG_AS("TextureManifest::scheme");
/// @todo Optimize: TextureManifest should contain a link to the owning Textures::Scheme.
Textures::Schemes const &schemes = textures().allSchemes();
DENG2_FOR_EACH_CONST(Textures::Schemes, i, schemes)
{
Textures::Scheme &scheme = **i;
if(&scheme.index() == &tree()) return scheme;
}
// This should never happen...
/// @throw Error Failed to determine the scheme of the manifest.
throw Error("TextureManifest::scheme", String("Failed to determine scheme for manifest [%p].").arg(de::dintptr(this)));
}
String const &TextureManifest::schemeName() const
{
return scheme().name();
}
Uri TextureManifest::composeUri(QChar sep) const
{
return Uri(scheme().name(), path(sep));
}
Uri TextureManifest::composeUrn() const
{
return Uri("urn", String("%1:%2").arg(scheme().name()).arg(uniqueId_, 0, 10));
}
Uri const &TextureManifest::resourceUri() const
{
return resourceUri_;
}
bool TextureManifest::setResourceUri(Uri const &newUri)
{
// Avoid resolving; compare as text.
if(resourceUri_.asText() != newUri.asText())
{
resourceUri_ = newUri;
return true;
}
return false;
}
Texture *TextureManifest::texture() const
{
return texture_;
}
void TextureManifest::setTexture(Texture *newTexture)
{
texture_ = newTexture;
}
int TextureManifest::uniqueId() const
{
return uniqueId_;
}
bool TextureManifest::setUniqueId(int newUniqueId)
{
if(uniqueId_ == newUniqueId) return false;
uniqueId_ = newUniqueId;
// We'll need to rebuild the id map too.
scheme().markUniqueIdLutDirty();
return true;
}
} // namespace de