mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-12-01 16:41:22 +00:00
Rename packing textures to texture atlases for the D3D code
- I figure since I now know the "proper" name for these things, I should call them by it.
This commit is contained in:
parent
a43f5a8eca
commit
f330a81909
2 changed files with 50 additions and 45 deletions
|
@ -90,7 +90,7 @@ IMPLEMENT_CLASS(D3DFB)
|
||||||
|
|
||||||
struct D3DFB::PackedTexture
|
struct D3DFB::PackedTexture
|
||||||
{
|
{
|
||||||
D3DFB::PackingTexture *Owner;
|
D3DFB::Atlas *Owner;
|
||||||
|
|
||||||
PackedTexture *Next, **Prev;
|
PackedTexture *Next, **Prev;
|
||||||
|
|
||||||
|
@ -104,10 +104,10 @@ struct D3DFB::PackedTexture
|
||||||
bool Padded;
|
bool Padded;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct D3DFB::PackingTexture
|
struct D3DFB::Atlas
|
||||||
{
|
{
|
||||||
PackingTexture(D3DFB *fb, int width, int height, D3DFORMAT format);
|
Atlas(D3DFB *fb, int width, int height, D3DFORMAT format);
|
||||||
~PackingTexture();
|
~Atlas();
|
||||||
|
|
||||||
PackedTexture *GetBestFit(int width, int height, int &area);
|
PackedTexture *GetBestFit(int width, int height, int &area);
|
||||||
void AllocateImage(PackedTexture *box, int width, int height);
|
void AllocateImage(PackedTexture *box, int width, int height);
|
||||||
|
@ -115,7 +115,7 @@ struct D3DFB::PackingTexture
|
||||||
void AddEmptyBox(int left, int top, int right, int bottom);
|
void AddEmptyBox(int left, int top, int right, int bottom);
|
||||||
void FreeBox(PackedTexture *box);
|
void FreeBox(PackedTexture *box);
|
||||||
|
|
||||||
PackingTexture *Next;
|
Atlas *Next;
|
||||||
IDirect3DTexture9 *Tex;
|
IDirect3DTexture9 *Tex;
|
||||||
D3DFORMAT Format;
|
D3DFORMAT Format;
|
||||||
PackedTexture *UsedList; // Boxes that contain images
|
PackedTexture *UsedList; // Boxes that contain images
|
||||||
|
@ -283,7 +283,7 @@ D3DFB::D3DFB (UINT adapter, int width, int height, bool fullscreen)
|
||||||
ScreenWipe = NULL;
|
ScreenWipe = NULL;
|
||||||
InScene = false;
|
InScene = false;
|
||||||
QuadExtra = new BufferedTris[MAX_QUAD_BATCH];
|
QuadExtra = new BufferedTris[MAX_QUAD_BATCH];
|
||||||
Packs = NULL;
|
Atlases = NULL;
|
||||||
PixelDoubling = 0;
|
PixelDoubling = 0;
|
||||||
SkipAt = -1;
|
SkipAt = -1;
|
||||||
CurrRenderTexture = 0;
|
CurrRenderTexture = 0;
|
||||||
|
@ -496,7 +496,7 @@ void D3DFB::FillPresentParameters (D3DPRESENT_PARAMETERS *pp, bool fullscreen, b
|
||||||
|
|
||||||
bool D3DFB::CreateResources()
|
bool D3DFB::CreateResources()
|
||||||
{
|
{
|
||||||
Packs = NULL;
|
Atlases = NULL;
|
||||||
if (!Windowed)
|
if (!Windowed)
|
||||||
{
|
{
|
||||||
// Remove the window border in fullscreen mode
|
// Remove the window border in fullscreen mode
|
||||||
|
@ -624,8 +624,8 @@ void D3DFB::ReleaseResources ()
|
||||||
delete ScreenWipe;
|
delete ScreenWipe;
|
||||||
ScreenWipe = NULL;
|
ScreenWipe = NULL;
|
||||||
}
|
}
|
||||||
PackingTexture *pack, *next;
|
Atlas *pack, *next;
|
||||||
for (pack = Packs; pack != NULL; pack = next)
|
for (pack = Atlases; pack != NULL; pack = next)
|
||||||
{
|
{
|
||||||
next = pack->Next;
|
next = pack->Next;
|
||||||
delete pack;
|
delete pack;
|
||||||
|
@ -1826,8 +1826,9 @@ IDirect3DTexture9 *D3DFB::GetCurrentScreen(D3DPOOL pool)
|
||||||
//
|
//
|
||||||
// D3DFB :: DrawPackedTextures
|
// D3DFB :: DrawPackedTextures
|
||||||
//
|
//
|
||||||
// DEBUG: Draws the packing textures to the screen, starting with the
|
// DEBUG: Draws the texture atlases to the screen, starting with the
|
||||||
// 1-based packnum.
|
// 1-based packnum. Ignores atlases that are flagged for use by one
|
||||||
|
// texture only.
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
|
@ -1838,30 +1839,34 @@ void D3DFB::DrawPackedTextures(int packnum)
|
||||||
0xFFFF9999, 0xFF99FF99, 0xFF9999FF, 0xFFFFFF99,
|
0xFFFF9999, 0xFF99FF99, 0xFF9999FF, 0xFFFFFF99,
|
||||||
0xFFFF99FF, 0xFF99FFFF, 0xFFFFCC99, 0xFF99CCFF
|
0xFFFF99FF, 0xFF99FFFF, 0xFFFFCC99, 0xFF99CCFF
|
||||||
};
|
};
|
||||||
PackingTexture *pack;
|
Atlas *pack;
|
||||||
int x = 8, y = 8;
|
int x = 8, y = 8;
|
||||||
|
|
||||||
if (packnum <= 0)
|
if (packnum <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pack = Packs;
|
pack = Atlases;
|
||||||
|
// Find the first texture atlas that is an actual atlas.
|
||||||
while (pack != NULL && pack->OneUse)
|
while (pack != NULL && pack->OneUse)
|
||||||
{ // Skip textures that aren't used as packing containers
|
{ // Skip textures that aren't used as atlases
|
||||||
pack = pack->Next;
|
pack = pack->Next;
|
||||||
}
|
}
|
||||||
|
// Skip however many atlases we would have otherwise drawn
|
||||||
|
// until we've skipped <packnum> of them.
|
||||||
while (pack != NULL && packnum != 1)
|
while (pack != NULL && packnum != 1)
|
||||||
{
|
{
|
||||||
if (!pack->OneUse)
|
if (!pack->OneUse)
|
||||||
{ // Skip textures that aren't used as packing containers
|
{ // Skip textures that aren't used as atlases
|
||||||
packnum--;
|
packnum--;
|
||||||
}
|
}
|
||||||
pack = pack->Next;
|
pack = pack->Next;
|
||||||
}
|
}
|
||||||
|
// Draw atlases until we run out of room on the screen.
|
||||||
while (pack != NULL)
|
while (pack != NULL)
|
||||||
{
|
{
|
||||||
if (pack->OneUse)
|
if (pack->OneUse)
|
||||||
{ // Skip textures that aren't used as packing containers
|
{ // Skip textures that aren't used as atlases
|
||||||
pack = pack->Next;
|
pack = pack->Next;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1969,34 +1974,34 @@ void D3DFB::DrawPackedTextures(int packnum)
|
||||||
//
|
//
|
||||||
// D3DFB :: AllocPackedTexture
|
// D3DFB :: AllocPackedTexture
|
||||||
//
|
//
|
||||||
// Finds space to pack an image inside a packing texture and returns it.
|
// Finds space to pack an image inside a texture atlas and returns it.
|
||||||
// Large images and those that need to wrap always get their own textures.
|
// Large images and those that need to wrap always get their own textures.
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
D3DFB::PackedTexture *D3DFB::AllocPackedTexture(int w, int h, bool wrapping, D3DFORMAT format)
|
D3DFB::PackedTexture *D3DFB::AllocPackedTexture(int w, int h, bool wrapping, D3DFORMAT format)
|
||||||
{
|
{
|
||||||
PackingTexture *bestpack;
|
Atlas *bestpack;
|
||||||
PackedTexture *bestbox;
|
PackedTexture *bestbox;
|
||||||
int area;
|
int area;
|
||||||
|
|
||||||
// check for 254 to account for padding
|
// check for 254 to account for padding
|
||||||
if (w > 254 || h > 254 || wrapping)
|
if (w > 254 || h > 254 || wrapping)
|
||||||
{ // Create a new packing texture.
|
{ // Create a new texture atlas.
|
||||||
bestpack = new PackingTexture(this, w, h, format);
|
bestpack = new Atlas(this, w, h, format);
|
||||||
bestpack->OneUse = true;
|
bestpack->OneUse = true;
|
||||||
bestbox = bestpack->GetBestFit(w, h, area);
|
bestbox = bestpack->GetBestFit(w, h, area);
|
||||||
bestbox->Padded = false;
|
bestbox->Padded = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // Try to find space in an existing packing texture.
|
{ // Try to find space in an existing texture atlas.
|
||||||
w += 2; // Add padding
|
w += 2; // Add padding
|
||||||
h += 2;
|
h += 2;
|
||||||
int bestarea = INT_MAX;
|
int bestarea = INT_MAX;
|
||||||
int bestareaever = w * h;
|
int bestareaever = w * h;
|
||||||
bestpack = NULL;
|
bestpack = NULL;
|
||||||
bestbox = NULL;
|
bestbox = NULL;
|
||||||
for (PackingTexture *pack = Packs; pack != NULL; pack = pack->Next)
|
for (Atlas *pack = Atlases; pack != NULL; pack = pack->Next)
|
||||||
{
|
{
|
||||||
if (pack->Format == format)
|
if (pack->Format == format)
|
||||||
{
|
{
|
||||||
|
@ -2016,8 +2021,8 @@ D3DFB::PackedTexture *D3DFB::AllocPackedTexture(int w, int h, bool wrapping, D3D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bestpack == NULL)
|
if (bestpack == NULL)
|
||||||
{ // Create a new packing texture.
|
{ // Create a new texture atlas.
|
||||||
bestpack = new PackingTexture(this, 256, 256, format);
|
bestpack = new Atlas(this, 256, 256, format);
|
||||||
bestbox = bestpack->GetBestFit(w, h, bestarea);
|
bestbox = bestpack->GetBestFit(w, h, bestarea);
|
||||||
}
|
}
|
||||||
bestbox->Padded = true;
|
bestbox->Padded = true;
|
||||||
|
@ -2028,11 +2033,11 @@ D3DFB::PackedTexture *D3DFB::AllocPackedTexture(int w, int h, bool wrapping, D3D
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// PackingTexture Constructor
|
// Atlas Constructor
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
D3DFB::PackingTexture::PackingTexture(D3DFB *fb, int w, int h, D3DFORMAT format)
|
D3DFB::Atlas::Atlas(D3DFB *fb, int w, int h, D3DFORMAT format)
|
||||||
{
|
{
|
||||||
Tex = NULL;
|
Tex = NULL;
|
||||||
Format = format;
|
Format = format;
|
||||||
|
@ -2043,8 +2048,8 @@ D3DFB::PackingTexture::PackingTexture(D3DFB *fb, int w, int h, D3DFORMAT format)
|
||||||
Width = 0;
|
Width = 0;
|
||||||
Height = 0;
|
Height = 0;
|
||||||
|
|
||||||
Next = fb->Packs;
|
Next = fb->Atlases;
|
||||||
fb->Packs = this;
|
fb->Atlases = this;
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
if (FAILED(fb->D3DDevice->CreateTexture(w, h, 1, 0, format, D3DPOOL_MANAGED, &Tex, NULL)))
|
if (FAILED(fb->D3DDevice->CreateTexture(w, h, 1, 0, format, D3DPOOL_MANAGED, &Tex, NULL)))
|
||||||
|
@ -2068,11 +2073,11 @@ D3DFB::PackingTexture::PackingTexture(D3DFB *fb, int w, int h, D3DFORMAT format)
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// PackingTexture Destructor
|
// Atlas Destructor
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
D3DFB::PackingTexture::~PackingTexture()
|
D3DFB::Atlas::~Atlas()
|
||||||
{
|
{
|
||||||
PackedTexture *box, *next;
|
PackedTexture *box, *next;
|
||||||
|
|
||||||
|
@ -2096,14 +2101,14 @@ D3DFB::PackingTexture::~PackingTexture()
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// PackingTexture :: GetBestFit
|
// Atlas :: GetBestFit
|
||||||
//
|
//
|
||||||
// Returns the empty box that provides the best fit for the requested
|
// Returns the empty box that provides the best fit for the requested
|
||||||
// dimensions, or NULL if none of them are large enough.
|
// dimensions, or NULL if none of them are large enough.
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
D3DFB::PackedTexture *D3DFB::PackingTexture::GetBestFit(int w, int h, int &area)
|
D3DFB::PackedTexture *D3DFB::Atlas::GetBestFit(int w, int h, int &area)
|
||||||
{
|
{
|
||||||
PackedTexture *box;
|
PackedTexture *box;
|
||||||
int smallestarea = INT_MAX;
|
int smallestarea = INT_MAX;
|
||||||
|
@ -2133,17 +2138,17 @@ D3DFB::PackedTexture *D3DFB::PackingTexture::GetBestFit(int w, int h, int &area)
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// PackingTexture :: AllocateImage
|
// Atlas :: AllocateImage
|
||||||
//
|
//
|
||||||
// Moves the box from the empty list to the used list, sizing it to the
|
// Moves the box from the empty list to the used list, sizing it to the
|
||||||
// requested dimensions and adding additional boxes to the empty list if
|
// requested dimensions and adding additional boxes to the empty list if
|
||||||
// needed.
|
// needed.
|
||||||
//
|
//
|
||||||
// The passed box *MUST* be in this packing texture's empty list.
|
// The passed box *MUST* be in this texture atlas's empty list.
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void D3DFB::PackingTexture::AllocateImage(D3DFB::PackedTexture *box, int w, int h)
|
void D3DFB::Atlas::AllocateImage(D3DFB::PackedTexture *box, int w, int h)
|
||||||
{
|
{
|
||||||
RECT start = box->Area;
|
RECT start = box->Area;
|
||||||
|
|
||||||
|
@ -2212,13 +2217,13 @@ void D3DFB::PackingTexture::AllocateImage(D3DFB::PackedTexture *box, int w, int
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// PackingTexture :: AddEmptyBox
|
// Atlas :: AddEmptyBox
|
||||||
//
|
//
|
||||||
// Adds a box with the specified dimensions to the empty list.
|
// Adds a box with the specified dimensions to the empty list.
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void D3DFB::PackingTexture::AddEmptyBox(int left, int top, int right, int bottom)
|
void D3DFB::Atlas::AddEmptyBox(int left, int top, int right, int bottom)
|
||||||
{
|
{
|
||||||
PackedTexture *box = AllocateBox();
|
PackedTexture *box = AllocateBox();
|
||||||
box->Area.left = left;
|
box->Area.left = left;
|
||||||
|
@ -2236,14 +2241,14 @@ void D3DFB::PackingTexture::AddEmptyBox(int left, int top, int right, int bottom
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// PackingTexture :: AllocateBox
|
// Atlas :: AllocateBox
|
||||||
//
|
//
|
||||||
// Returns a new PackedTexture box, either by retrieving one off the free
|
// Returns a new PackedTexture box, either by retrieving one off the free
|
||||||
// list or by creating a new one. The box is not linked into a list.
|
// list or by creating a new one. The box is not linked into a list.
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
D3DFB::PackedTexture *D3DFB::PackingTexture::AllocateBox()
|
D3DFB::PackedTexture *D3DFB::Atlas::AllocateBox()
|
||||||
{
|
{
|
||||||
PackedTexture *box;
|
PackedTexture *box;
|
||||||
|
|
||||||
|
@ -2266,7 +2271,7 @@ D3DFB::PackedTexture *D3DFB::PackingTexture::AllocateBox()
|
||||||
|
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
//
|
//
|
||||||
// PackingTexture :: FreeBox
|
// Atlas :: FreeBox
|
||||||
//
|
//
|
||||||
// Removes a box from its current list and adds it to the empty list,
|
// Removes a box from its current list and adds it to the empty list,
|
||||||
// updating EmptyArea. If there are no boxes left in the used list, then
|
// updating EmptyArea. If there are no boxes left in the used list, then
|
||||||
|
@ -2275,7 +2280,7 @@ D3DFB::PackedTexture *D3DFB::PackingTexture::AllocateBox()
|
||||||
//
|
//
|
||||||
//==========================================================================
|
//==========================================================================
|
||||||
|
|
||||||
void D3DFB::PackingTexture::FreeBox(D3DFB::PackedTexture *box)
|
void D3DFB::Atlas::FreeBox(D3DFB::PackedTexture *box)
|
||||||
{
|
{
|
||||||
*(box->Prev) = box->Next;
|
*(box->Prev) = box->Next;
|
||||||
if (box->Next != NULL)
|
if (box->Next != NULL)
|
||||||
|
@ -4004,7 +4009,7 @@ void D3DFB::SetPaletteTexture(IDirect3DTexture9 *texture, int count, D3DCOLOR bo
|
||||||
SetTexture(1, texture);
|
SetTexture(1, texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3DFB::SetPalTexBilinearConstants(PackingTexture *tex)
|
void D3DFB::SetPalTexBilinearConstants(Atlas *tex)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
float con[8];
|
float con[8];
|
||||||
|
|
|
@ -279,7 +279,7 @@ private:
|
||||||
friend class D3DPal;
|
friend class D3DPal;
|
||||||
|
|
||||||
struct PackedTexture;
|
struct PackedTexture;
|
||||||
struct PackingTexture;
|
struct Atlas;
|
||||||
|
|
||||||
struct FBVERTEX
|
struct FBVERTEX
|
||||||
{
|
{
|
||||||
|
@ -392,7 +392,7 @@ private:
|
||||||
void SetPixelShader(IDirect3DPixelShader9 *shader);
|
void SetPixelShader(IDirect3DPixelShader9 *shader);
|
||||||
void SetTexture(int tnum, IDirect3DTexture9 *texture);
|
void SetTexture(int tnum, IDirect3DTexture9 *texture);
|
||||||
void SetPaletteTexture(IDirect3DTexture9 *texture, int count, D3DCOLOR border_color);
|
void SetPaletteTexture(IDirect3DTexture9 *texture, int count, D3DCOLOR border_color);
|
||||||
void SetPalTexBilinearConstants(PackingTexture *texture);
|
void SetPalTexBilinearConstants(Atlas *texture);
|
||||||
|
|
||||||
BOOL AlphaTestEnabled;
|
BOOL AlphaTestEnabled;
|
||||||
BOOL AlphaBlendEnabled;
|
BOOL AlphaBlendEnabled;
|
||||||
|
@ -431,7 +431,7 @@ private:
|
||||||
BYTE BlockNum;
|
BYTE BlockNum;
|
||||||
D3DPal *Palettes;
|
D3DPal *Palettes;
|
||||||
D3DTex *Textures;
|
D3DTex *Textures;
|
||||||
PackingTexture *Packs;
|
Atlas *Atlases;
|
||||||
HRESULT LastHR;
|
HRESULT LastHR;
|
||||||
|
|
||||||
UINT Adapter;
|
UINT Adapter;
|
||||||
|
|
Loading…
Reference in a new issue