Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TextureManager.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2012 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
20 #include "TextureManager.h"
21 
24 #include "lib/res/h_mgr.h"
25 #include "lib/file/vfs/vfs_tree.h"
27 #include "lib/timer.h"
28 #include "maths/MD5.h"
29 #include "ps/CacheLoader.h"
30 #include "ps/CLogger.h"
31 #include "ps/Filesystem.h"
32 #include "ps/Profile.h"
33 
34 #include <iomanip>
35 #include <boost/unordered_map.hpp>
36 #include <boost/unordered_set.hpp>
37 #include <boost/functional/hash.hpp>
38 
39 struct TPhash
40  : std::unary_function<CTextureProperties, std::size_t>,
41  std::unary_function<CTexturePtr, std::size_t>
42 {
43  std::size_t operator()(CTextureProperties const& a) const
44  {
45  std::size_t seed = 0;
46  boost::hash_combine(seed, a.m_Path);
47  boost::hash_combine(seed, a.m_Filter);
48  boost::hash_combine(seed, a.m_WrapS);
49  boost::hash_combine(seed, a.m_WrapT);
50  boost::hash_combine(seed, a.m_Aniso);
51  return seed;
52  }
53  std::size_t operator()(CTexturePtr const& a) const
54  {
55  return (*this)(a->m_Properties);
56  }
57 };
58 
59 struct TPequal_to
60  : std::binary_function<CTextureProperties, CTextureProperties, bool>,
61  std::binary_function<CTexturePtr, CTexturePtr, bool>
62 {
63  bool operator()(CTextureProperties const& a, CTextureProperties const& b) const
64  {
65  return a.m_Path == b.m_Path && a.m_Filter == b.m_Filter
66  && a.m_WrapS == b.m_WrapS && a.m_WrapT == b.m_WrapT
67  && a.m_Aniso == b.m_Aniso;
68  }
69  bool operator()(CTexturePtr const& a, CTexturePtr const& b) const
70  {
71  return (*this)(a->m_Properties, b->m_Properties);
72  }
73 };
74 
75 
77 {
78  friend class CTexture;
79 public:
80  CTextureManagerImpl(PIVFS vfs, bool highQuality, bool disableGL) :
81  m_VFS(vfs), m_CacheLoader(vfs, L".dds"), m_DisableGL(disableGL), m_TextureConverter(vfs, highQuality),
83  {
84  // Initialise some textures that will always be available,
85  // without needing to load any files
86 
87  // Default placeholder texture (grey)
88  if (!m_DisableGL)
89  {
90  // Construct 1x1 24-bit texture
91  shared_ptr<u8> data(new u8[3], ArrayDeleter());
92  data.get()[0] = 64;
93  data.get()[1] = 64;
94  data.get()[2] = 64;
95  Tex t;
96  (void)tex_wrap(1, 1, 24, 0, data, 0, &t);
97 
98  m_DefaultHandle = ogl_tex_wrap(&t, m_VFS, L"(default texture)");
99  (void)ogl_tex_set_filter(m_DefaultHandle, GL_LINEAR);
100  if (!m_DisableGL)
102  }
103 
104  // Error texture (magenta)
105  if (!m_DisableGL)
106  {
107  // Construct 1x1 24-bit texture
108  shared_ptr<u8> data(new u8[3], ArrayDeleter());
109  data.get()[0] = 255;
110  data.get()[1] = 0;
111  data.get()[2] = 255;
112  Tex t;
113  (void)tex_wrap(1, 1, 24, 0, data, 0, &t);
114 
115  m_ErrorHandle = ogl_tex_wrap(&t, m_VFS, L"(error texture)");
116  (void)ogl_tex_set_filter(m_ErrorHandle, GL_LINEAR);
117  if (!m_DisableGL)
119 
120  // Construct a CTexture to return to callers who want an error texture
121  CTextureProperties props(L"(error texture)");
122  m_ErrorTexture = CTexturePtr(new CTexture(m_ErrorHandle, props, this));
123  m_ErrorTexture->m_State = CTexture::LOADED;
124  m_ErrorTexture->m_Self = m_ErrorTexture;
125  }
126 
127  // Allow hotloading of textures
129  }
130 
132  {
134 
137  }
138 
140  {
141  return m_ErrorTexture;
142  }
143 
144  /**
145  * See CTextureManager::CreateTexture
146  */
148  {
149  // Construct a new default texture with the given properties to use as the search key
150  CTexturePtr texture(new CTexture(m_DefaultHandle, props, this));
151 
152  // Try to find an existing texture with the given properties
153  TextureCache::iterator it = m_TextureCache.find(texture);
154  if (it != m_TextureCache.end())
155  return *it;
156 
157  // Can't find an existing texture - finish setting up this new texture
158  texture->m_Self = texture;
159  m_TextureCache.insert(texture);
160  m_HotloadFiles[props.m_Path].insert(texture);
161 
162  return texture;
163  }
164 
165  /**
166  * Load the given file into the texture object and upload it to OpenGL.
167  * Assumes the file already exists.
168  */
169  void LoadTexture(const CTexturePtr& texture, const VfsPath& path)
170  {
171  if (m_DisableGL)
172  return;
173 
174  PROFILE2("load texture");
175  PROFILE2_ATTR("name: %ls", path.string().c_str());
176 
177  Handle h = ogl_tex_load(m_VFS, path, RES_UNIQUE);
178  if (h <= 0)
179  {
180  LOGERROR(L"Texture failed to load; \"%ls\"", texture->m_Properties.m_Path.string().c_str());
181 
182  // Replace with error texture to make it obvious
183  texture->SetHandle(m_ErrorHandle);
184  return;
185  }
186 
187  // Get some flags for later use
188  size_t flags = 0;
189  (void)ogl_tex_get_format(h, &flags, NULL);
190 
191  // Initialise base colour from the texture
192  (void)ogl_tex_get_average_colour(h, &texture->m_BaseColour);
193 
194  // Set GL upload properties
195  (void)ogl_tex_set_wrap(h, texture->m_Properties.m_WrapS, texture->m_Properties.m_WrapT);
196  (void)ogl_tex_set_anisotropy(h, texture->m_Properties.m_Aniso);
197 
198  // Prevent ogl_tex automatically generating mipmaps (which is slow and unwanted),
199  // by avoiding mipmapped filters unless the source texture already has mipmaps
200  GLint filter = texture->m_Properties.m_Filter;
201  if (!(flags & TEX_MIPMAPS))
202  {
203  switch (filter)
204  {
205  case GL_NEAREST_MIPMAP_NEAREST:
206  case GL_NEAREST_MIPMAP_LINEAR:
207  filter = GL_NEAREST;
208  break;
209  case GL_LINEAR_MIPMAP_NEAREST:
210  case GL_LINEAR_MIPMAP_LINEAR:
211  filter = GL_LINEAR;
212  break;
213  }
214  }
215  (void)ogl_tex_set_filter(h, filter);
216 
217  // Upload to GL
218  if (!m_DisableGL && ogl_tex_upload(h) < 0)
219  {
220  LOGERROR(L"Texture failed to upload: \"%ls\"", texture->m_Properties.m_Path.string().c_str());
221 
222  ogl_tex_free(h);
223 
224  // Replace with error texture to make it obvious
225  texture->SetHandle(m_ErrorHandle);
226  return;
227  }
228 
229  // Let the texture object take ownership of this handle
230  texture->SetHandle(h, true);
231  }
232 
233  /**
234  * Set up some parameters for the loose cache filename code.
235  */
236  void PrepareCacheKey(const CTexturePtr& texture, MD5& hash, u32& version)
237  {
238  // Hash the settings, so we won't use an old loose cache file if the
239  // settings have changed
241  settings.Hash(hash);
242 
243  // Arbitrary version number - change this if we update the code and
244  // need to invalidate old users' caches
245  version = 1;
246  }
247 
248  /**
249  * Attempts to load a cached version of a texture.
250  * If the texture is loaded (or there was an error), returns true.
251  * Otherwise, returns false to indicate the caller should generate the cached version.
252  */
253  bool TryLoadingCached(const CTexturePtr& texture)
254  {
255  MD5 hash;
256  u32 version;
257  PrepareCacheKey(texture, hash, version);
258 
259  VfsPath loadPath;
260  Status ret = m_CacheLoader.TryLoadingCached(texture->m_Properties.m_Path, hash, version, loadPath);
261 
262  if (ret == INFO::OK)
263  {
264  // Found a cached texture - load it
265  LoadTexture(texture, loadPath);
266  return true;
267  }
268  else if (ret == INFO::SKIPPED)
269  {
270  // No cached version was found - we'll need to create it
271  return false;
272  }
273  else
274  {
275  ENSURE(ret < 0);
276 
277  // No source file or archive cache was found, so we can't load the
278  // real texture at all - return the error texture instead
279  LOGERROR(L"CCacheLoader failed to find archived or source file for: \"%ls\"", texture->m_Properties.m_Path.string().c_str());
280  texture->SetHandle(m_ErrorHandle);
281  return true;
282  }
283  }
284 
285  /**
286  * Initiates an asynchronous conversion process, from the texture's
287  * source file to the corresponding loose cache file.
288  */
289  void ConvertTexture(const CTexturePtr& texture)
290  {
291  VfsPath sourcePath = texture->m_Properties.m_Path;
292 
293  PROFILE2("convert texture");
294  PROFILE2_ATTR("name: %ls", sourcePath.string().c_str());
295 
296  MD5 hash;
297  u32 version;
298  PrepareCacheKey(texture, hash, version);
299  VfsPath looseCachePath = m_CacheLoader.LooseCachePath(sourcePath, hash, version);
300 
301 // LOGWARNING(L"Converting texture \"%ls\"", srcPath.c_str());
302 
304 
305  m_TextureConverter.ConvertTexture(texture, sourcePath, looseCachePath, settings);
306  }
307 
308  bool GenerateCachedTexture(const VfsPath& sourcePath, VfsPath& archiveCachePath)
309  {
310  archiveCachePath = m_CacheLoader.ArchiveCachePath(sourcePath);
311 
312  CTextureProperties textureProps(sourcePath);
313  CTexturePtr texture = CreateTexture(textureProps);
315 
316  if (!m_TextureConverter.ConvertTexture(texture, sourcePath, VfsPath("cache") / archiveCachePath, settings))
317  return false;
318 
319  while (true)
320  {
321  CTexturePtr textureOut;
322  VfsPath dest;
323  bool ok;
324  if (m_TextureConverter.Poll(textureOut, dest, ok))
325  return ok;
326 
327  // Spin-loop is dumb but it works okay for now
328  SDL_Delay(0);
329  }
330  }
331 
333  {
334  // Process any completed conversion tasks
335  {
336  CTexturePtr texture;
337  VfsPath dest;
338  bool ok;
339  if (m_TextureConverter.Poll(texture, dest, ok))
340  {
341  if (ok)
342  {
343  LoadTexture(texture, dest);
344  }
345  else
346  {
347  LOGERROR(L"Texture failed to convert: \"%ls\"", texture->m_Properties.m_Path.string().c_str());
348  texture->SetHandle(m_ErrorHandle);
349  }
350  texture->m_State = CTexture::LOADED;
351  return true;
352  }
353  }
354 
355  // We'll only push new conversion requests if it's not already busy
356  bool converterBusy = m_TextureConverter.IsBusy();
357 
358  if (!converterBusy)
359  {
360  // Look for all high-priority textures needing conversion.
361  // (Iterating over all textures isn't optimally efficient, but it
362  // doesn't seem to be a problem yet and it's simpler than maintaining
363  // multiple queues.)
364  for (TextureCache::iterator it = m_TextureCache.begin(); it != m_TextureCache.end(); ++it)
365  {
366  if ((*it)->m_State == CTexture::HIGH_NEEDS_CONVERTING)
367  {
368  // Start converting this texture
369  (*it)->m_State = CTexture::HIGH_IS_CONVERTING;
370  ConvertTexture(*it);
371  return true;
372  }
373  }
374  }
375 
376  // Try loading prefetched textures from their cache
377  for (TextureCache::iterator it = m_TextureCache.begin(); it != m_TextureCache.end(); ++it)
378  {
379  if ((*it)->m_State == CTexture::PREFETCH_NEEDS_LOADING)
380  {
381  if (TryLoadingCached(*it))
382  {
383  (*it)->m_State = CTexture::LOADED;
384  }
385  else
386  {
387  (*it)->m_State = CTexture::PREFETCH_NEEDS_CONVERTING;
388  }
389  return true;
390  }
391  }
392 
393  // If we've got nothing better to do, then start converting prefetched textures.
394  if (!converterBusy)
395  {
396  for (TextureCache::iterator it = m_TextureCache.begin(); it != m_TextureCache.end(); ++it)
397  {
398  if ((*it)->m_State == CTexture::PREFETCH_NEEDS_CONVERTING)
399  {
400  (*it)->m_State = CTexture::PREFETCH_IS_CONVERTING;
401  ConvertTexture(*it);
402  return true;
403  }
404  }
405  }
406 
407  return false;
408  }
409 
410  /**
411  * Compute the conversion settings that apply to a given texture, by combining
412  * the textures.xml files from its directory and all parent directories
413  * (up to the VFS root).
414  */
416  {
417  fs::wpath srcPath = texture->m_Properties.m_Path.string();
418 
419  std::vector<CTextureConverter::SettingsFile*> files;
420  VfsPath p;
421  for (fs::wpath::iterator it = srcPath.begin(); it != srcPath.end(); ++it)
422  {
423  VfsPath settingsPath = p / "textures.xml";
424  m_HotloadFiles[settingsPath].insert(texture);
426  if (f)
427  files.push_back(f);
428  p = p / GetWstringFromWpath(*it);
429  }
430  return m_TextureConverter.ComputeSettings(GetWstringFromWpath(srcPath.leaf()), files);
431  }
432 
433  /**
434  * Return the (cached) settings file with the given filename,
435  * or NULL if it doesn't exist.
436  */
438  {
439  SettingsFilesMap::iterator it = m_SettingsFiles.find(path);
440  if (it != m_SettingsFiles.end())
441  return it->second.get();
442 
443  if (m_VFS->GetFileInfo(path, NULL) >= 0)
444  {
445  shared_ptr<CTextureConverter::SettingsFile> settings(m_TextureConverter.LoadSettings(path));
446  m_SettingsFiles.insert(std::make_pair(path, settings));
447  return settings.get();
448  }
449  else
450  {
451  m_SettingsFiles.insert(std::make_pair(path, shared_ptr<CTextureConverter::SettingsFile>()));
452  return NULL;
453  }
454  }
455 
456  static Status ReloadChangedFileCB(void* param, const VfsPath& path)
457  {
458  return static_cast<CTextureManagerImpl*>(param)->ReloadChangedFile(path);
459  }
460 
462  {
463  // Uncache settings file, if this is one
464  m_SettingsFiles.erase(path);
465 
466  // Find all textures using this file
467  HotloadFilesMap::iterator files = m_HotloadFiles.find(path);
468  if (files != m_HotloadFiles.end())
469  {
470  // Flag all textures using this file as needing reloading
471  for (std::set<boost::weak_ptr<CTexture> >::iterator it = files->second.begin(); it != files->second.end(); ++it)
472  {
473  if (shared_ptr<CTexture> texture = it->lock())
474  {
475  texture->m_State = CTexture::UNLOADED;
476  texture->SetHandle(m_DefaultHandle);
477  }
478  }
479  }
480 
481  return INFO::OK;
482  }
483 
484 private:
489 
493 
494  // Cache of all loaded textures
495  typedef boost::unordered_set<CTexturePtr, TPhash, TPequal_to > TextureCache;
497  // TODO: we ought to expire unused textures from the cache eventually
498 
499  // Store the set of textures that need to be reloaded when the given file
500  // (a source file or settings.xml) is modified
501  typedef boost::unordered_map<VfsPath, std::set<boost::weak_ptr<CTexture> > > HotloadFilesMap;
503 
504  // Cache for the conversion settings files
505  typedef boost::unordered_map<VfsPath, shared_ptr<CTextureConverter::SettingsFile> > SettingsFilesMap;
507 };
508 
510  m_Handle(handle), m_BaseColour(0), m_State(UNLOADED), m_Properties(props), m_TextureManager(textureManager)
511 {
512  // Add a reference to the handle (it might be shared by multiple CTextures
513  // so we can't take ownership of it)
514  if (m_Handle)
516 }
517 
519 {
520  if (m_Handle)
522 }
523 
524 void CTexture::Bind(size_t unit)
525 {
526  ogl_tex_bind(GetHandle(), unit);
527 }
528 
530 {
531  // TODO: TryLoad might call ogl_tex_upload which enables GL_TEXTURE_2D
532  // on texture unit 0, regardless of 'unit', which callers might
533  // not be expecting. Ideally that wouldn't happen.
534 
535  TryLoad();
536 
537  return m_Handle;
538 }
539 
541 {
542  // If we haven't started loading, then try loading, and if that fails then request conversion.
543  // If we have already tried prefetch loading, and it failed, bump the conversion request to HIGH priority.
545  {
546  if (shared_ptr<CTexture> self = m_Self.lock())
547  {
549  m_State = LOADED;
550  else
552  }
553  }
554 
555  return (m_State == LOADED);
556 }
557 
559 {
560  if (m_State == UNLOADED)
561  {
562  if (shared_ptr<CTexture> self = m_Self.lock())
563  {
565  }
566  }
567 }
568 
570 {
571  return (m_State == LOADED);
572 }
573 
574 void CTexture::SetHandle(Handle handle, bool takeOwnership)
575 {
576  if (handle == m_Handle)
577  return;
578 
579  if (!takeOwnership)
580  h_add_ref(handle);
581 
583  m_Handle = handle;
584 }
585 
586 size_t CTexture::GetWidth() const
587 {
588  size_t w = 0;
589  (void)ogl_tex_get_size(m_Handle, &w, 0, 0);
590  return w;
591 }
592 
593 size_t CTexture::GetHeight() const
594 {
595  size_t h = 0;
596  (void)ogl_tex_get_size(m_Handle, 0, &h, 0);
597  return h;
598 }
599 
600 bool CTexture::HasAlpha() const
601 {
602  size_t flags = 0;
603  (void)ogl_tex_get_format(m_Handle, &flags, 0);
604  return (flags & TEX_ALPHA) != 0;
605 }
606 
608 {
609  return m_BaseColour;
610 }
611 
612 
613 // CTextureManager: forward all calls to impl:
614 
615 CTextureManager::CTextureManager(PIVFS vfs, bool highQuality, bool disableGL) :
616  m(new CTextureManagerImpl(vfs, highQuality, disableGL))
617 {
618 }
619 
621 {
622  delete m;
623 }
624 
626 {
627  return m->CreateTexture(props);
628 }
629 
631 {
632  return m->GetErrorTexture();
633 }
634 
636 {
637  return m->MakeProgress();
638 }
639 
641 {
642  return m->GenerateCachedTexture(path, outputPath);
643 }
CTextureConverter::SettingsFile * GetSettingsFile(const VfsPath &path)
Return the (cached) settings file with the given filename, or NULL if it doesn&#39;t exist.
Status ogl_tex_set_anisotropy(Handle ht, GLfloat anisotropy)
Override default maximum anisotropic filtering for this texture.
Definition: ogl_tex.cpp:679
#define u8
Definition: types.h:39
u32 m_BaseColour
bool TryLoadingCached(const CTexturePtr &texture)
Attempts to load a cached version of a texture.
bool operator()(CTextureProperties const &a, CTextureProperties const &b) const
bool GenerateCachedTexture(const VfsPath &path, VfsPath &outputPath)
Synchronously converts and compresses and saves the texture, and returns the output path (minus a &quot;ca...
CTexturePtr CreateTexture(const CTextureProperties &props)
Create a texture with the given GL properties.
CTextureManagerImpl(PIVFS vfs, bool highQuality, bool disableGL)
bool Poll(CTexturePtr &texture, VfsPath &dest, bool &ok)
Returns the result of a successful ConvertTexture call.
void Prefetch()
Activate the prefetching optimisation for this texture.
boost::unordered_map< VfsPath, shared_ptr< CTextureConverter::SettingsFile > > SettingsFilesMap
const Status OK
Definition: status.h:386
#define LOGERROR
Definition: CLogger.h:35
Handle m_Handle
void SDL_Delay(Uint32 ms)
Definition: wsdl.cpp:1457
CTexture(Handle handle, const CTextureProperties &props, CTextureManagerImpl *textureManager)
Handle ogl_tex_wrap(Tex *t, const PIVFS &vfs, const VfsPath &pathname, size_t flags)
Make the Tex object ready for use as an OpenGL texture and return a handle to it. ...
Definition: ogl_tex.cpp:570
Status ogl_tex_free(Handle &ht)
Release this texture reference.
Definition: ogl_tex.cpp:586
VfsPath LooseCachePath(const VfsPath &sourcePath, const MD5 &initialHash, u32 version)
Return the path of the loose cache for the given source file.
CTexturePtr m_ErrorTexture
shared_ptr< IVFS > PIVFS
Definition: vfs.h:226
Represents the filename and GL parameters of a texture, for passing to CTextureManager::CreateTexture...
mask
Definition: tex.h:199
indicates the image contains an alpha channel.
Definition: tex.h:171
const CTextureProperties m_Properties
SettingsFile * LoadSettings(const VfsPath &path) const
Load a texture conversion settings XML file.
Texture conversion settings.
bool IsLoaded()
Returns whether the texture data is currently loaded.
void Hash(MD5 &hash)
Append this object&#39;s state to the given hash.
CTextureManagerImpl * m_TextureManager
CTextureConverter::Settings GetConverterSettings(const CTexturePtr &texture)
Compute the conversion settings that apply to a given texture, by combining the textures.xml files from its directory and all parent directories (up to the VFS root).
boost::weak_ptr< CTexture > m_Self
size_t GetWidth() const
Returns the width (in pixels) of the current texture.
std::wstring GetWstringFromWpath(const fs::wpath &path)
Helper function to handle API differences between Boost Filesystem v2 and v3.
Definition: Filesystem.cpp:98
Status ReloadChangedFile(const VfsPath &path)
Status ogl_tex_bind(Handle ht, size_t unit)
Bind texture to the specified unit in preparation for using it in rendering.
Definition: ogl_tex.cpp:1054
#define ENSURE(expr)
ensure the expression &lt;expr&gt; evaluates to non-zero.
Definition: debug.h:282
#define PROFILE2(region)
Starts timing from now until the end of the current scope.
Definition: Profiler2.h:446
bool MakeProgress()
Work on asynchronous texture loading operations, if any.
CTextureManager(PIVFS vfs, bool highQuality, bool disableGL)
Construct texture manager.
u32 GetBaseColour() const
Returns the ARGB value of the lowest mipmap level (i.e.
MD5 hashing algorithm.
Definition: MD5.h:27
void UnregisterFileReloadFunc(FileReloadFunc func, void *obj)
delete a callback function registered with RegisterFileReloadFunc (removes any with the same func and...
Definition: Filesystem.cpp:44
void RegisterFileReloadFunc(FileReloadFunc func, void *obj)
register a callback function to be called by ReloadChangedFiles
Definition: Filesystem.cpp:39
Status ogl_tex_set_wrap(Handle ht, GLint wrap_s, GLint wrap_t)
Override default wrap mode (GL_REPEAT) for this texture.
Definition: ogl_tex.cpp:657
Definition: path.h:75
VfsPath ArchiveCachePath(const VfsPath &sourcePath)
Return the path of the archive cache for the given source file.
SettingsFilesMap m_SettingsFiles
const String & string() const
Definition: path.h:123
boost::unordered_map< VfsPath, std::set< boost::weak_ptr< CTexture > > > HotloadFilesMap
bool HasAlpha() const
Returns whether the current texture has an alpha channel.
CTexturePtr GetErrorTexture()
Represents a texture object.
size_t GetHeight() const
Returns the height (in pixels) of the current texture.
static Status ReloadChangedFileCB(void *param, const VfsPath &path)
Handle GetHandle()
Returns a ogl_tex handle, for later binding.
CTextureManagerImpl * m
CCacheLoader m_CacheLoader
i64 Status
Error handling system.
Definition: status.h:171
i64 Handle
`handle&#39; representing a reference to a resource (sound, texture, etc.)
Definition: handle.h:41
void LoadTexture(const CTexturePtr &texture, const VfsPath &path)
Load the given file into the texture object and upload it to OpenGL.
bool GenerateCachedTexture(const VfsPath &sourcePath, VfsPath &archiveCachePath)
Representation of settings XML file.
stores all data describing an image.
Definition: tex.h:210
Handle ogl_tex_load(const PIVFS &vfs, const VfsPath &pathname, size_t flags)
Load and return a handle to the texture.
Definition: ogl_tex.cpp:542
bool IsBusy()
Returns whether there is currently a queued request from ConvertTexture().
#define PROFILE2_ATTR
Associates a string (with printf-style formatting) with the current region or event.
Definition: Profiler2.h:461
CTexturePtr GetErrorTexture()
Returns a magenta texture.
const Status SKIPPED
Definition: status.h:392
#define u32
Definition: types.h:41
CTextureConverter m_TextureConverter
std::size_t operator()(CTextureProperties const &a) const
std::size_t operator()(CTexturePtr const &a) const
Status ogl_tex_set_filter(Handle ht, GLint filter)
Override default filter (see ogl_tex_set_defaults) for this texture.
Definition: ogl_tex.cpp:638
HotloadFilesMap m_HotloadFiles
TextureCache m_TextureCache
Status ogl_tex_get_format(Handle ht, size_t *flags, GLenum *fmt)
Retrieve pixel format of the texture.
Definition: ogl_tex.cpp:999
void SetHandle(Handle handle, bool takeOwnership=false)
Replace the Handle stored by this object.
bool TryLoad()
Attempt to load the texture data quickly, as with Bind().
CTexturePtr CreateTexture(const CTextureProperties &props)
See CTextureManager::CreateTexture.
Status tex_wrap(size_t w, size_t h, size_t bpp, size_t flags, const shared_ptr< u8 > &data, size_t ofs, Tex *t)
store the given image data into a Tex object; this will be as if it had been loaded via tex_load...
Definition: tex.cpp:593
enum CTexture::@17 m_State
void ConvertTexture(const CTexturePtr &texture)
Initiates an asynchronous conversion process, from the texture&#39;s source file to the corresponding loo...
Texture conversion helper class.
void Bind(size_t unit=0)
Bind the texture to the given GL texture unit.
static Handle handle(size_t idx, u64 tag)
Definition: h_mgr.cpp:121
boost::unordered_set< CTexturePtr, TPhash, TPequal_to > TextureCache
bool operator()(CTexturePtr const &a, CTexturePtr const &b) const
Status TryLoadingCached(const VfsPath &sourcePath, const MD5 &initialHash, u32 version, VfsPath &loadPath)
Attempts to find a valid cached which can be loaded.
Definition: CacheLoader.cpp:32
Helper class for systems that have an expensive cacheable conversion process when loading files...
Definition: CacheLoader.h:40
void PrepareCacheKey(const CTexturePtr &texture, MD5 &hash, u32 &version)
Set up some parameters for the loose cache filename code.
Status ogl_tex_get_average_colour(Handle ht, u32 *p)
Retrieve ARGB value of 1x1 mipmap level of the texture, i.e.
Definition: ogl_tex.cpp:1030
bool ConvertTexture(const CTexturePtr &texture, const VfsPath &src, const VfsPath &dest, const Settings &settings)
Begin converting a texture, using the given settings.
Settings ComputeSettings(const std::wstring &filename, const std::vector< SettingsFile * > &settingsFiles) const
Match a sequence of settings files against a given texture filename, and return the resulting setting...
Status ogl_tex_upload(const Handle ht, GLenum fmt_ovr, int q_flags_ovr, GLint int_fmt_ovr)
Upload texture to OpenGL.
Definition: ogl_tex.cpp:912
Status ogl_tex_get_size(Handle ht, size_t *w, size_t *h, size_t *bpp)
Retrieve dimensions and bit depth of the texture.
Definition: ogl_tex.cpp:982
shared_ptr< CTexture > CTexturePtr
Definition: Texture.h:22
void h_add_ref(Handle h)
Definition: h_mgr.cpp:715