mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-25 05:31:00 +00:00
- consolidated the 3 identical versions of I_CheckResolution and I_ClosestResolution.
This commit is contained in:
parent
e9e1911fa5
commit
dc2a5b0cc9
6 changed files with 67 additions and 169 deletions
|
@ -13,8 +13,6 @@ DFrameBuffer *I_SetMode (int &width, int &height, DFrameBuffer *old);
|
|||
// the original DOS version (if the Heretic/Hexen source is any indicator).
|
||||
void I_WaitVBL(int count);
|
||||
|
||||
bool I_CheckResolution (int width, int height, int bpp);
|
||||
void I_ClosestResolution (int *width, int *height, int bits);
|
||||
|
||||
enum EDisplayType
|
||||
{
|
||||
|
|
|
@ -758,67 +758,6 @@ DFrameBuffer* I_SetMode(int &width, int &height, DFrameBuffer* old)
|
|||
return Video->CreateFrameBuffer(width, height, false, fullscreen, old);
|
||||
}
|
||||
|
||||
bool I_CheckResolution(const int width, const int height, const int bits)
|
||||
{
|
||||
int twidth, theight;
|
||||
|
||||
Video->StartModeIterator(bits, fullscreen);
|
||||
|
||||
while (Video->NextMode(&twidth, &theight, NULL))
|
||||
{
|
||||
if (width == twidth && height == theight)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void I_ClosestResolution(int *width, int *height, int bits)
|
||||
{
|
||||
int twidth, theight;
|
||||
int cwidth = 0, cheight = 0;
|
||||
int iteration;
|
||||
uint32_t closest = uint32_t(-1);
|
||||
|
||||
for (iteration = 0; iteration < 2; ++iteration)
|
||||
{
|
||||
Video->StartModeIterator(bits, fullscreen);
|
||||
|
||||
while (Video->NextMode(&twidth, &theight, NULL))
|
||||
{
|
||||
if (twidth == *width && theight == *height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (iteration == 0 && (twidth < *width || theight < *height))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const uint32_t dist = (twidth - *width) * (twidth - *width)
|
||||
+ (theight - *height) * (theight - *height);
|
||||
|
||||
if (dist < closest)
|
||||
{
|
||||
closest = dist;
|
||||
cwidth = twidth;
|
||||
cheight = theight;
|
||||
}
|
||||
}
|
||||
|
||||
if (closest != uint32_t(-1))
|
||||
{
|
||||
*width = cwidth;
|
||||
*height = cheight;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
|
|
@ -123,56 +123,6 @@ DFrameBuffer *I_SetMode (int &width, int &height, DFrameBuffer *old)
|
|||
return res;
|
||||
}
|
||||
|
||||
bool I_CheckResolution (int width, int height, int bits)
|
||||
{
|
||||
int twidth, theight;
|
||||
|
||||
Video->StartModeIterator (bits, screen ? screen->IsFullscreen() : fullscreen);
|
||||
while (Video->NextMode (&twidth, &theight, NULL))
|
||||
{
|
||||
if (width == twidth && height == theight)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void I_ClosestResolution (int *width, int *height, int bits)
|
||||
{
|
||||
int twidth, theight;
|
||||
int cwidth = 0, cheight = 0;
|
||||
int iteration;
|
||||
uint32_t closest = 4294967295u;
|
||||
|
||||
for (iteration = 0; iteration < 2; iteration++)
|
||||
{
|
||||
Video->StartModeIterator (bits, screen ? screen->IsFullscreen() : fullscreen);
|
||||
while (Video->NextMode (&twidth, &theight, NULL))
|
||||
{
|
||||
if (twidth == *width && theight == *height)
|
||||
return;
|
||||
|
||||
if (iteration == 0 && (twidth < *width || theight < *height))
|
||||
continue;
|
||||
|
||||
uint32_t dist = (twidth - *width) * (twidth - *width)
|
||||
+ (theight - *height) * (theight - *height);
|
||||
|
||||
if (dist < closest)
|
||||
{
|
||||
closest = dist;
|
||||
cwidth = twidth;
|
||||
cheight = theight;
|
||||
}
|
||||
}
|
||||
if (closest != 4294967295u)
|
||||
{
|
||||
*width = cwidth;
|
||||
*height = cheight;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// SetFPSLimit
|
||||
|
|
|
@ -1114,6 +1114,66 @@ void V_CalcCleanFacs (int designwidth, int designheight, int realwidth, int real
|
|||
if (_cx2 != NULL) *_cx2 = cx2;
|
||||
}
|
||||
|
||||
bool V_CheckResolution(const int width, const int height, const int bits)
|
||||
{
|
||||
int twidth, theight;
|
||||
|
||||
Video->StartModeIterator(bits, fullscreen);
|
||||
|
||||
while (Video->NextMode(&twidth, &theight, NULL))
|
||||
{
|
||||
if (width == twidth && height == theight)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void V_ClosestResolution(int *width, int *height, int bits)
|
||||
{
|
||||
int twidth, theight;
|
||||
int cwidth = 0, cheight = 0;
|
||||
int iteration;
|
||||
uint32_t closest = uint32_t(-1);
|
||||
|
||||
for (iteration = 0; iteration < 2; ++iteration)
|
||||
{
|
||||
Video->StartModeIterator(bits, fullscreen);
|
||||
|
||||
while (Video->NextMode(&twidth, &theight, NULL))
|
||||
{
|
||||
if (twidth == *width && theight == *height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (iteration == 0 && (twidth < *width || theight < *height))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
const uint32_t dist = (twidth - *width) * (twidth - *width)
|
||||
+ (theight - *height) * (theight - *height);
|
||||
|
||||
if (dist < closest)
|
||||
{
|
||||
closest = dist;
|
||||
cwidth = twidth;
|
||||
cheight = theight;
|
||||
}
|
||||
}
|
||||
|
||||
if (closest != uint32_t(-1))
|
||||
{
|
||||
*width = cwidth;
|
||||
*height = cheight;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IVideo::SetResolution (int width, int height, int bits)
|
||||
{
|
||||
int oldwidth, oldheight;
|
||||
|
@ -1132,10 +1192,10 @@ bool IVideo::SetResolution (int width, int height, int bits)
|
|||
oldbits = bits;
|
||||
}
|
||||
|
||||
I_ClosestResolution (&width, &height, bits);
|
||||
if (!I_CheckResolution (width, height, bits))
|
||||
V_ClosestResolution (&width, &height, bits);
|
||||
if (!V_CheckResolution (width, height, bits))
|
||||
{ // Try specified resolution
|
||||
if (!I_CheckResolution (oldwidth, oldheight, oldbits))
|
||||
if (!V_CheckResolution (oldwidth, oldheight, oldbits))
|
||||
{ // Try previous resolution (if any)
|
||||
return false;
|
||||
}
|
||||
|
@ -1168,7 +1228,7 @@ CCMD (vid_setmode)
|
|||
}
|
||||
|
||||
const bool goodmode = (width > 0 && height > 0)
|
||||
&& (!fullscreen || (Video != nullptr && I_CheckResolution(width, height, bits)));
|
||||
&& (!fullscreen || (Video != nullptr && V_CheckResolution(width, height, bits)));
|
||||
|
||||
if (goodmode)
|
||||
{
|
||||
|
@ -1267,7 +1327,7 @@ void V_Init2()
|
|||
}
|
||||
|
||||
I_InitGraphics();
|
||||
I_ClosestResolution (&width, &height, 8);
|
||||
V_ClosestResolution (&width, &height, 8);
|
||||
|
||||
if (!Video->SetResolution (width, height, 8))
|
||||
I_FatalError ("Could not set resolution to %d x %d x %d", width, height, 8);
|
||||
|
|
|
@ -185,56 +185,6 @@ DFrameBuffer *I_SetMode (int &width, int &height, DFrameBuffer *old)
|
|||
return res;
|
||||
}
|
||||
|
||||
bool I_CheckResolution (int width, int height, int bits)
|
||||
{
|
||||
int twidth, theight;
|
||||
|
||||
Video->StartModeIterator (bits, screen ? screen->IsFullscreen() : fullscreen);
|
||||
while (Video->NextMode (&twidth, &theight, NULL))
|
||||
{
|
||||
if (width == twidth && height == theight)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void I_ClosestResolution (int *width, int *height, int bits)
|
||||
{
|
||||
int twidth, theight;
|
||||
int cwidth = 0, cheight = 0;
|
||||
int iteration;
|
||||
DWORD closest = 4294967295u;
|
||||
|
||||
for (iteration = 0; iteration < 2; iteration++)
|
||||
{
|
||||
Video->StartModeIterator (bits, screen ? screen->IsFullscreen() : fullscreen);
|
||||
while (Video->NextMode (&twidth, &theight, NULL))
|
||||
{
|
||||
if (twidth == *width && theight == *height)
|
||||
return;
|
||||
|
||||
if (iteration == 0 && (twidth < *width || theight < *height))
|
||||
continue;
|
||||
|
||||
DWORD dist = (twidth - *width) * (twidth - *width)
|
||||
+ (theight - *height) * (theight - *height);
|
||||
|
||||
if (dist < closest)
|
||||
{
|
||||
closest = dist;
|
||||
cwidth = twidth;
|
||||
cheight = theight;
|
||||
}
|
||||
}
|
||||
if (closest != 4294967295u)
|
||||
{
|
||||
*width = cwidth;
|
||||
*height = cheight;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void GetCenteredPos (int &winx, int &winy, int &winw, int &winh, int &scrwidth, int &scrheight)
|
||||
{
|
||||
DEVMODE displaysettings;
|
||||
|
|
|
@ -453,6 +453,7 @@ bool Win32GLVideo::GoFullscreen(bool yes)
|
|||
//
|
||||
//
|
||||
//==========================================================================
|
||||
void V_ClosestResolution(int *width, int *height, int bits);
|
||||
|
||||
|
||||
DFrameBuffer *Win32GLVideo::CreateFrameBuffer(int width, int height, bool bgra, bool fs, DFrameBuffer *old)
|
||||
|
@ -461,7 +462,7 @@ DFrameBuffer *Win32GLVideo::CreateFrameBuffer(int width, int height, bool bgra,
|
|||
|
||||
if (fs)
|
||||
{
|
||||
I_ClosestResolution(&width, &height, 32);
|
||||
V_ClosestResolution(&width, &height, 32);
|
||||
}
|
||||
|
||||
m_DisplayWidth = width;
|
||||
|
|
Loading…
Reference in a new issue