18 #include "precompiled.h"
35 #include <boost/unordered_map.hpp>
36 #include <boost/unordered_set.hpp>
37 #include <boost/functional/hash.hpp>
40 : std::unary_function<CTextureProperties, std::size_t>,
41 std::unary_function<CTexturePtr, std::size_t>
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);
55 return (*
this)(a->m_Properties);
60 : std::binary_function<CTextureProperties, CTextureProperties, bool>,
61 std::binary_function<CTexturePtr, CTexturePtr, bool>
71 return (*
this)(a->m_Properties, b->m_Properties);
96 (void)
tex_wrap(1, 1, 24, 0, data, 0, &t);
113 (void)
tex_wrap(1, 1, 24, 0, data, 0, &t);
158 texture->m_Self = texture;
180 LOGERROR(L
"Texture failed to load; \"%ls\"", texture->m_Properties.m_Path.string().c_str());
195 (void)
ogl_tex_set_wrap(h, texture->m_Properties.m_WrapS, texture->m_Properties.m_WrapT);
200 GLint filter = texture->m_Properties.m_Filter;
205 case GL_NEAREST_MIPMAP_NEAREST:
206 case GL_NEAREST_MIPMAP_LINEAR:
209 case GL_LINEAR_MIPMAP_NEAREST:
210 case GL_LINEAR_MIPMAP_LINEAR:
220 LOGERROR(L
"Texture failed to upload: \"%ls\"", texture->m_Properties.m_Path.string().c_str());
230 texture->SetHandle(h,
true);
279 LOGERROR(L
"CCacheLoader failed to find archived or source file for: \"%ls\"", texture->m_Properties.m_Path.string().c_str());
291 VfsPath sourcePath = texture->m_Properties.m_Path;
347 LOGERROR(L
"Texture failed to convert: \"%ls\"", texture->m_Properties.m_Path.string().c_str());
417 fs::wpath srcPath = texture->m_Properties.m_Path.string();
419 std::vector<CTextureConverter::SettingsFile*> files;
421 for (fs::wpath::iterator it = srcPath.begin(); it != srcPath.end(); ++it)
423 VfsPath settingsPath = p /
"textures.xml";
441 return it->second.get();
443 if (
m_VFS->GetFileInfo(path, NULL) >= 0)
447 return settings.get();
451 m_SettingsFiles.insert(std::make_pair(path, shared_ptr<CTextureConverter::SettingsFile>()));
471 for (std::set<boost::weak_ptr<CTexture> >::iterator it = files->second.begin(); it != files->second.end(); ++it)
473 if (shared_ptr<CTexture> texture = it->lock())
495 typedef boost::unordered_set<CTexturePtr, TPhash, TPequal_to >
TextureCache;
501 typedef boost::unordered_map<VfsPath, std::set<boost::weak_ptr<CTexture> > >
HotloadFilesMap;
505 typedef boost::unordered_map<VfsPath, shared_ptr<CTextureConverter::SettingsFile> >
SettingsFilesMap;
546 if (shared_ptr<CTexture>
self =
m_Self.lock())
562 if (shared_ptr<CTexture>
self =
m_Self.lock())
CTextureConverter::SettingsFile * GetSettingsFile(const VfsPath &path)
Return the (cached) settings file with the given filename, or NULL if it doesn't exist.
Status ogl_tex_set_anisotropy(Handle ht, GLfloat anisotropy)
Override default maximum anisotropic filtering for this texture.
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 "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
void SDL_Delay(Uint32 ms)
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. ...
Status ogl_tex_free(Handle &ht)
Release this texture reference.
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
Represents the filename and GL parameters of a texture, for passing to CTextureManager::CreateTexture...
indicates the image contains an alpha channel.
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'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.
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.
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
#define PROFILE2(region)
Starts timing from now until the end of the current scope.
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.
void UnregisterFileReloadFunc(FileReloadFunc func, void *obj)
delete a callback function registered with RegisterFileReloadFunc (removes any with the same func and...
void RegisterFileReloadFunc(FileReloadFunc func, void *obj)
register a callback function to be called by ReloadChangedFiles
Status ogl_tex_set_wrap(Handle ht, GLint wrap_s, GLint wrap_t)
Override default wrap mode (GL_REPEAT) for this texture.
VfsPath ArchiveCachePath(const VfsPath &sourcePath)
Return the path of the archive cache for the given source file.
SettingsFilesMap m_SettingsFiles
const String & string() const
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.
CCacheLoader m_CacheLoader
i64 Status
Error handling system.
i64 Handle
`handle' representing a reference to a resource (sound, texture, etc.)
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.
Handle ogl_tex_load(const PIVFS &vfs, const VfsPath &pathname, size_t flags)
Load and return a handle to the texture.
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.
CTexturePtr GetErrorTexture()
Returns a magenta texture.
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.
HotloadFilesMap m_HotloadFiles
TextureCache m_TextureCache
Status ogl_tex_get_format(Handle ht, size_t *flags, GLenum *fmt)
Retrieve pixel format of the texture.
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...
enum CTexture::@17 m_State
void ConvertTexture(const CTexturePtr &texture)
Initiates an asynchronous conversion process, from the texture'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)
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.
Helper class for systems that have an expensive cacheable conversion process when loading files...
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.
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.
Status ogl_tex_get_size(Handle ht, size_t *w, size_t *h, size_t *bpp)
Retrieve dimensions and bit depth of the texture.
shared_ptr< CTexture > CTexturePtr