Skip to content

Commit

Permalink
libgui|GL: TextureBank can use multiple atlases
Browse files Browse the repository at this point in the history
Based on user-provided atlas IDs, the allocations in a TextureBank
can be split to multiple atlases.

ModelDrawable was updated to support separate atlases for different
texture map types.
  • Loading branch information
skyjake committed Sep 1, 2019
1 parent 2669882 commit ad10b5a
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 84 deletions.
14 changes: 12 additions & 2 deletions doomsday/libs/gui/include/de/graphics/modeldrawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,22 @@ class LIBGUI_PUBLIC ModelDrawable : public AssetGroup
void setAtlas(IAtlas &atlas);

/**
* Removes the model's atlas. All allocations this model has made from the atlas
* Sets the atlas to use for a specific type of textures. THis is needed for glInit(). Unlike
* setAtlas(atlas) that uses the same atlas for everything, this will associate a certain type
* of texture with a specific atlas.
*
* @param textureMap Texture map. This
* @param atlas Atlas for model textures of type @a textureMap.
*/
void setAtlas(TextureMap textureMap, IAtlas &atlas);

/**
* Removes the model's atlases. All allocations this model has made from the atlas
* are freed.
*/
void unsetAtlas();

IAtlas *atlas() const;
IAtlas *atlas(TextureMap textureMap = Unknown) const;

/**
* Sets which textures are to be passed to the model shader via the GL buffer.
Expand Down
28 changes: 25 additions & 3 deletions doomsday/libs/gui/include/de/graphics/texturebank.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace de {

/**
* Bank that stores images on an atlas.
* Bank that stores images on one or more atlases.
*
* The data item sources in the bank must be derived from TextureBank::ImageSource.
*
Expand All @@ -34,6 +34,8 @@ namespace de {
class LIBGUI_PUBLIC TextureBank : public Bank
{
public:
using AtlasId = int;

/**
* Base classs for entries in the bank. When requested, provides the Image data
* of the specified item.
Expand All @@ -42,6 +44,9 @@ class LIBGUI_PUBLIC TextureBank : public Bank
{
public:
ImageSource(DotPath const &sourcePath = "");
ImageSource(AtlasId atlasId, DotPath const &sourcePath);

AtlasId atlasId() const;
DotPath const &sourcePath() const;

virtual Image load() const = 0;
Expand All @@ -50,6 +55,14 @@ class LIBGUI_PUBLIC TextureBank : public Bank
DENG2_PRIVATE(d)
};

struct LIBGUI_PUBLIC Allocation
{
Id id;
AtlasId atlas;

operator Id const &() const { return id; }
};

public:
TextureBank(char const *nameForLog = "TextureBank",
Flags const &flags = DefaultFlags);
Expand All @@ -61,9 +74,18 @@ class LIBGUI_PUBLIC TextureBank : public Bank
*/
void setAtlas(IAtlas *atlas);

IAtlas *atlas();
/**
* Sets one of the atlases that will be used for allocating images.
*
* @param atlasId Id of the atlas.
*
* @param atlas Texture atlas.
*/
void setAtlas(AtlasId atlasId, IAtlas *atlas);

IAtlas *atlas(AtlasId atlasId = 0);

Id const &texture(DotPath const &id);
Allocation texture(DotPath const &id);

/**
* Returns the source path of an image that has been loaded into the atlas.
Expand Down
Loading

0 comments on commit ad10b5a

Please sign in to comment.