mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-11 07:12:16 +00:00
Merge branch 'master' of https://github.com/rheit/zdoom
This commit is contained in:
commit
011385a20e
3 changed files with 91 additions and 7 deletions
|
@ -119,7 +119,7 @@ Rect SkylineBinPack::Insert(int width, int height)
|
||||||
return newNode;
|
return newNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
return InsertMinWaste(width, height);
|
return InsertBottomLeft(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkylineBinPack::RectangleFits(int skylineNodeIndex, int width, int height, int &y) const
|
bool SkylineBinPack::RectangleFits(int skylineNodeIndex, int width, int height, int &y) const
|
||||||
|
@ -254,6 +254,73 @@ void SkylineBinPack::MergeSkylines()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Rect SkylineBinPack::InsertBottomLeft(int width, int height)
|
||||||
|
{
|
||||||
|
int bestHeight;
|
||||||
|
int bestWidth;
|
||||||
|
int bestIndex;
|
||||||
|
Rect newNode = FindPositionForNewNodeBottomLeft(width, height, bestHeight, bestWidth, bestIndex);
|
||||||
|
|
||||||
|
if (bestIndex != -1)
|
||||||
|
{
|
||||||
|
assert(disjointRects.Disjoint(newNode));
|
||||||
|
// Perform the actual packing.
|
||||||
|
AddSkylineLevel(bestIndex, newNode);
|
||||||
|
|
||||||
|
usedSurfaceArea += width * height;
|
||||||
|
#ifdef _DEBUG
|
||||||
|
disjointRects.Add(newNode);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
memset(&newNode, 0, sizeof(Rect));
|
||||||
|
|
||||||
|
return newNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect SkylineBinPack::FindPositionForNewNodeBottomLeft(int width, int height, int &bestHeight, int &bestWidth, int &bestIndex) const
|
||||||
|
{
|
||||||
|
bestHeight = INT_MAX;
|
||||||
|
bestIndex = -1;
|
||||||
|
// Used to break ties if there are nodes at the same level. Then pick the narrowest one.
|
||||||
|
bestWidth = INT_MAX;
|
||||||
|
Rect newNode = { 0, 0, 0, 0 };
|
||||||
|
for(unsigned i = 0; i < skyLine.Size(); ++i)
|
||||||
|
{
|
||||||
|
int y;
|
||||||
|
if (RectangleFits(i, width, height, y))
|
||||||
|
{
|
||||||
|
if (y + height < bestHeight || (y + height == bestHeight && skyLine[i].width < bestWidth))
|
||||||
|
{
|
||||||
|
bestHeight = y + height;
|
||||||
|
bestIndex = i;
|
||||||
|
bestWidth = skyLine[i].width;
|
||||||
|
newNode.x = skyLine[i].x;
|
||||||
|
newNode.y = y;
|
||||||
|
newNode.width = width;
|
||||||
|
newNode.height = height;
|
||||||
|
assert(disjointRects.Disjoint(newNode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* if (RectangleFits(i, height, width, y))
|
||||||
|
{
|
||||||
|
if (y + width < bestHeight || (y + width == bestHeight && skyLine[i].width < bestWidth))
|
||||||
|
{
|
||||||
|
bestHeight = y + width;
|
||||||
|
bestIndex = i;
|
||||||
|
bestWidth = skyLine[i].width;
|
||||||
|
newNode.x = skyLine[i].x;
|
||||||
|
newNode.y = y;
|
||||||
|
newNode.width = height;
|
||||||
|
newNode.height = width;
|
||||||
|
assert(disjointRects.Disjoint(newNode));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/ }
|
||||||
|
|
||||||
|
return newNode;
|
||||||
|
}
|
||||||
|
|
||||||
Rect SkylineBinPack::InsertMinWaste(int width, int height)
|
Rect SkylineBinPack::InsertMinWaste(int width, int height)
|
||||||
{
|
{
|
||||||
int bestHeight;
|
int bestHeight;
|
||||||
|
|
|
@ -72,7 +72,10 @@ private:
|
||||||
bool useWasteMap;
|
bool useWasteMap;
|
||||||
GuillotineBinPack wasteMap;
|
GuillotineBinPack wasteMap;
|
||||||
|
|
||||||
|
Rect InsertBottomLeft(int width, int height);
|
||||||
Rect InsertMinWaste(int width, int height);
|
Rect InsertMinWaste(int width, int height);
|
||||||
|
|
||||||
|
Rect FindPositionForNewNodeBottomLeft(int width, int height, int &bestHeight, int &bestWidth, int &bestIndex) const;
|
||||||
Rect FindPositionForNewNodeMinWaste(int width, int height, int &bestHeight, int &bestWastedArea, int &bestIndex) const;
|
Rect FindPositionForNewNodeMinWaste(int width, int height, int &bestHeight, int &bestWastedArea, int &bestIndex) const;
|
||||||
|
|
||||||
bool RectangleFits(int skylineNodeIndex, int width, int height, int &y) const;
|
bool RectangleFits(int skylineNodeIndex, int width, int height, int &y) const;
|
||||||
|
|
|
@ -85,6 +85,10 @@
|
||||||
// The number of quads we can batch together.
|
// The number of quads we can batch together.
|
||||||
#define MAX_QUAD_BATCH (NUM_INDEXES / 6)
|
#define MAX_QUAD_BATCH (NUM_INDEXES / 6)
|
||||||
|
|
||||||
|
// The default size for a texture atlas.
|
||||||
|
#define DEF_ATLAS_WIDTH 512
|
||||||
|
#define DEF_ATLAS_HEIGHT 512
|
||||||
|
|
||||||
// TYPES -------------------------------------------------------------------
|
// TYPES -------------------------------------------------------------------
|
||||||
|
|
||||||
IMPLEMENT_CLASS(D3DFB)
|
IMPLEMENT_CLASS(D3DFB)
|
||||||
|
@ -1833,8 +1837,8 @@ void D3DFB::DrawPackedTextures(int packnum)
|
||||||
{
|
{
|
||||||
D3DCOLOR empty_colors[8] =
|
D3DCOLOR empty_colors[8] =
|
||||||
{
|
{
|
||||||
0xFFFF9999, 0xFF99FF99, 0xFF9999FF, 0xFFFFFF99,
|
0x50FF0000, 0x5000FF00, 0x500000FF, 0x50FFFF00,
|
||||||
0xFFFF99FF, 0xFF99FFFF, 0xFFFFCC99, 0xFF99CCFF
|
0x50FF00FF, 0x5000FFFF, 0x50FF8000, 0x500080FF
|
||||||
};
|
};
|
||||||
Atlas *pack;
|
Atlas *pack;
|
||||||
int x = 8, y = 8;
|
int x = 8, y = 8;
|
||||||
|
@ -1869,7 +1873,17 @@ void D3DFB::DrawPackedTextures(int packnum)
|
||||||
}
|
}
|
||||||
|
|
||||||
AddColorOnlyRect(x-1, y-1-LBOffsetI, 258, 258, D3DCOLOR_XRGB(255,255,0));
|
AddColorOnlyRect(x-1, y-1-LBOffsetI, 258, 258, D3DCOLOR_XRGB(255,255,0));
|
||||||
AddColorOnlyQuad(x, y-LBOffsetI, 256, 256, D3DCOLOR_ARGB(180,0,0,0));
|
int back = 0;
|
||||||
|
for (PackedTexture *box = pack->UsedList; box != NULL; box = box->Next)
|
||||||
|
{
|
||||||
|
AddColorOnlyQuad(
|
||||||
|
x + box->Area.left * 256 / pack->Width,
|
||||||
|
y + box->Area.top * 256 / pack->Height,
|
||||||
|
(box->Area.right - box->Area.left) * 256 / pack->Width,
|
||||||
|
(box->Area.bottom - box->Area.top) * 256 / pack->Height, empty_colors[back]);
|
||||||
|
back = (back + 1) & 7;
|
||||||
|
}
|
||||||
|
// AddColorOnlyQuad(x, y-LBOffsetI, 256, 256, D3DCOLOR_ARGB(180,0,0,0));
|
||||||
|
|
||||||
CheckQuadBatch();
|
CheckQuadBatch();
|
||||||
|
|
||||||
|
@ -1973,8 +1987,8 @@ D3DFB::PackedTexture *D3DFB::AllocPackedTexture(int w, int h, bool wrapping, D3D
|
||||||
Rect box;
|
Rect box;
|
||||||
bool padded;
|
bool padded;
|
||||||
|
|
||||||
// check for 254 to account for padding
|
// The - 2 to account for padding
|
||||||
if (w > 254 || h > 254 || wrapping)
|
if (w > 256 - 2 || h > 256 - 2 || wrapping)
|
||||||
{ // Create a new texture atlas.
|
{ // Create a new texture atlas.
|
||||||
pack = new Atlas(this, w, h, format);
|
pack = new Atlas(this, w, h, format);
|
||||||
pack->OneUse = true;
|
pack->OneUse = true;
|
||||||
|
@ -1999,7 +2013,7 @@ D3DFB::PackedTexture *D3DFB::AllocPackedTexture(int w, int h, bool wrapping, D3D
|
||||||
}
|
}
|
||||||
if (pack == NULL)
|
if (pack == NULL)
|
||||||
{ // Create a new texture atlas.
|
{ // Create a new texture atlas.
|
||||||
pack = new Atlas(this, 256, 256, format);
|
pack = new Atlas(this, DEF_ATLAS_WIDTH, DEF_ATLAS_HEIGHT, format);
|
||||||
box = pack->Packer.Insert(w, h);
|
box = pack->Packer.Insert(w, h);
|
||||||
}
|
}
|
||||||
padded = true;
|
padded = true;
|
||||||
|
|
Loading…
Reference in a new issue