tahoma2d/toonz/sources/include/ext/ttexturesstorage.h

124 lines
4 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef DRAWABLEMESHIMAGE_H
#define DRAWABLEMESHIMAGE_H
2016-04-14 19:51:50 +12:00
#include <memory>
2016-03-19 06:57:51 +13:00
// TnzExt includes
#include "meshtexturizer.h"
// TnzCore includes
#include "tgldisplaylistsmanager.h"
#undef DVAPI
#undef DVVAR
#ifdef TNZEXT_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//***************************************************************************************
// DrawableMeshImage definition
//***************************************************************************************
//! DrawableTextureData is a MeshTexturizer::TextureData wrapper that
struct DrawableTextureData {
2016-06-15 18:43:10 +12:00
MeshTexturizer::TextureData *m_textureData; //!< The wrapped texture data
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
DrawableTextureData() {}
~DrawableTextureData();
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
friend class TTexturesStorage;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
int m_texId; //!< The texture Id in MeshTexturizer
int m_dlSpaceId; //!< Object's display lists id
int m_objIdx; //!< Object index in the container
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
// Not copyable
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
DrawableTextureData(const DrawableTextureData &);
DrawableTextureData &operator=(const DrawableTextureData &);
2016-03-19 06:57:51 +13:00
};
2016-04-14 19:51:50 +12:00
typedef std::shared_ptr<DrawableTextureData> DrawableTextureDataP;
2016-03-19 06:57:51 +13:00
//***************************************************************************************
// TexturesStorage declaration
//***************************************************************************************
/*!
2016-06-15 18:43:10 +12:00
\brief TTexturesStorage is the class responsible for the storage of
textures associated with mesh rendering.
\details This class deals with textures storage and meshes compilation for
drawing purposes.
An OpenGL texture is typically split into several tiles before being
rendered. A texturized mesh is then
compiled against a texture in order to decide which mesh faces must
be rendered with a given texture
2016-03-19 06:57:51 +13:00
tile.
2016-06-15 18:43:10 +12:00
The TTextureStorage class uses a QCache to store texture objects up
to a maximum memory size, plus all
the already compiled mesh objects against the stored textures.
Whenever a texture loading procedure would
exceed the maximum textures size, the least accessed stored textures
are automatically removed from the
2016-03-19 06:57:51 +13:00
storage to make space for the newly assigned one.
2016-06-15 18:43:10 +12:00
Textures can be \a stored only if the OpenGL context they are loaded
on has a valid known <I>display lists
proxy</I> submitted in the TGLDisplayListsManager. In case the
OpenGL context does not have a proxy, the
loaded texture is a temporary, and will be deleted as soon as the
returned TexturObject is destroyed
(so, make sure the associated context is still current at that
point).
2016-03-19 06:57:51 +13:00
\note TTexturesStorage is thread-safe.
\sa The TGLDisplayListsManager class.
*/
2016-06-15 18:43:10 +12:00
class DVAPI TTexturesStorage : private TGLDisplayListsManager::Observer {
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
static TTexturesStorage *instance();
/*!
\brief Stores the specified raster to a group of OpenGL textures, returning a
reference
pointer ensuring the texture survival during its lifetime.
\warning This class may keep a copy of the specified texture only for a \b
limited
amount of time, \a if the current context has an associated display
lists
space proxy. Users must always be ready to \a reload the texture in case
it was not found.
*/
DrawableTextureDataP loadTexture(const std::string &textureId,
const TRaster32P &ras,
const TRectD &geometry);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! Releases the texture associated with the specified texture id.
void unloadTexture(const std::string &textureId);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
//! Returns the texture data associated to the specified string identifier.
DrawableTextureDataP getTextureData(const std::string &textureId);
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
TTexturesStorage();
~TTexturesStorage();
2016-03-19 06:57:51 +13:00
2016-06-19 20:06:29 +12:00
void onDisplayListDestroyed(int dlSpaceId) override;
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
#endif // DRAWABLEMESHIMAGE_H