[Glide64] Update code related to resolution

This commit is contained in:
zilmar 2017-01-31 21:37:16 +11:00
parent 70abd5df17
commit bd7eaf3be4
4 changed files with 165 additions and 119 deletions

View File

@ -48,6 +48,7 @@
#include "DepthBufferRender.h" #include "DepthBufferRender.h"
#include "Config.h" #include "Config.h"
#include "trace.h" #include "trace.h"
#include "ScreenResolution.h"
#include <Common/StdString.h> #include <Common/StdString.h>
#ifdef _WIN32 #ifdef _WIN32
@ -297,30 +298,10 @@ public:
TTInit(); TTInit();
TTSize(400); TTSize(400);
m_WindowRes.Attach(GetDlgItem(IDC_CMB_WINDOW_RES)); m_WindowRes.Attach(GetDlgItem(IDC_CMB_WINDOW_RES));
m_WindowRes.SetItemData(m_WindowRes.AddString("320x200"), 0); for (uint32_t i = 0, n = GetScreenResolutionCount(); i < n; i++)
m_WindowRes.SetItemData(m_WindowRes.AddString("320x240"), 1); {
m_WindowRes.SetItemData(m_WindowRes.AddString("400x256"), 2); m_WindowRes.SetItemData(m_WindowRes.AddString(GetScreenResolutionName(i)), i);
m_WindowRes.SetItemData(m_WindowRes.AddString("512x384"), 3); }
m_WindowRes.SetItemData(m_WindowRes.AddString("640x200"), 4);
m_WindowRes.SetItemData(m_WindowRes.AddString("640x350"), 5);
m_WindowRes.SetItemData(m_WindowRes.AddString("640x400"), 6);
m_WindowRes.SetItemData(m_WindowRes.AddString("640x480"), 7);
m_WindowRes.SetItemData(m_WindowRes.AddString("800x600"), 8);
m_WindowRes.SetItemData(m_WindowRes.AddString("960x720"), 9);
m_WindowRes.SetItemData(m_WindowRes.AddString("856x480"), 10);
m_WindowRes.SetItemData(m_WindowRes.AddString("512x256"), 11);
m_WindowRes.SetItemData(m_WindowRes.AddString("1024x768"), 12);
m_WindowRes.SetItemData(m_WindowRes.AddString("1280x1024"), 13);
m_WindowRes.SetItemData(m_WindowRes.AddString("1600x1200"), 14);
m_WindowRes.SetItemData(m_WindowRes.AddString("400x300"), 15);
m_WindowRes.SetItemData(m_WindowRes.AddString("1152x864"), 16);
m_WindowRes.SetItemData(m_WindowRes.AddString("1280x960"), 17);
m_WindowRes.SetItemData(m_WindowRes.AddString("1600x1024"), 18);
m_WindowRes.SetItemData(m_WindowRes.AddString("1792x1344"), 19);
m_WindowRes.SetItemData(m_WindowRes.AddString("1856x1392"), 20);
m_WindowRes.SetItemData(m_WindowRes.AddString("1920x1440"), 21);
m_WindowRes.SetItemData(m_WindowRes.AddString("2048x1536"), 22);
m_WindowRes.SetItemData(m_WindowRes.AddString("2048x2048"), 23);
SetComboBoxIndex(m_WindowRes, g_settings->ScreenRes()); SetComboBoxIndex(m_WindowRes, g_settings->ScreenRes());
TTSetTxt(IDC_CMB_WINDOW_RES, "Resolution:\n\nThis option selects the windowed resolution.\n\n[Recommended: 640x480, 800x600, 1024x768]"); TTSetTxt(IDC_CMB_WINDOW_RES, "Resolution:\n\nThis option selects the windowed resolution.\n\n[Recommended: 640x480, 800x600, 1024x768]");

View File

@ -14,115 +14,203 @@
struct ResolutionInfo struct ResolutionInfo
{ {
unsigned int dwW, dwH, dwF; ResolutionInfo(const char * name = NULL, uint32_t width = 0, uint32_t height = 0, uint32_t frequency = 0, bool default_res = false) :
m_name(name),
ResolutionInfo() : dwW(0), dwH(0), dwF(0) {} m_width(width),
m_height(height),
ResolutionInfo(unsigned int _w, unsigned int _h, unsigned int _f) : dwW(_w), dwH(_h), dwF(_f) {} m_frequency(frequency),
m_default_res(default_res)
bool operator == (const ResolutionInfo & _other) const
{ {
if (dwW != _other.dwW)
return false;
if (dwH != _other.dwH)
return false;
if (dwF != _other.dwF)
return false;
return true;
} }
bool operator != (const ResolutionInfo & _other) const const char * Name(void) const { return m_name; }
{ uint32_t width(void) const { return m_width; }
return !(operator==(_other)); uint32_t height(void) const { return m_height; }
} uint32_t frequency(void) const { return m_frequency; }
bool DefaultRes(void) const { return m_default_res; }
void toString(char * _str) const bool operator == (const ResolutionInfo& rRes) const
{ {
if (dwF > 0) return m_width == rRes.m_width && m_height == rRes.m_height && m_frequency == rRes.m_frequency;
sprintf(_str, "%ix%i 32bpp %iHz", dwW, dwH, dwF);
else
sprintf(_str, "%ix%i 32bpp", dwW, dwH);
} }
bool operator != (const ResolutionInfo& rRes) const
{
return !(*this == rRes);
}
private:
uint32_t m_width, m_height, m_frequency;
const char * m_name;
bool m_default_res;
}; };
#ifdef ANDROID
static ResolutionInfo g_resolutions[] =
{
ResolutionInfo("#3200#", 0, 0, 0, true),
ResolutionInfo("960x720", 960, 720, 0, false),
ResolutionInfo("800x600", 800, 600, 0, false),
ResolutionInfo("640x480", 640, 480, 0, false),
ResolutionInfo("480x360", 480, 360, 0, false),
ResolutionInfo("320x240", 320, 240, 0, false),
};
#else
static ResolutionInfo g_resolutions[] =
{
{ "320x200", 320, 200, 0, false },
{ "320x240", 320, 240, 0, false },
{ "400x256", 400, 256, 0, false },
{ "512x384", 512, 384, 0, false },
{ "640x200", 640, 200, 0, false },
{ "640x350", 640, 350, 0, false },
{ "640x400", 640, 400, 0, false },
{ "640x480", 640, 480, 0, true },
{ "800x600", 800, 600, 0, false },
{ "960x720", 960, 720, 0, false },
{ "856x480", 856, 480, 0, false },
{ "512x256", 512, 256, 0, false },
{ "1024x768", 1024, 768, 0, false },
{ "1280x1024", 1280, 1024, 0, false },
{ "1600x1200", 1600, 1200, 0, false },
{ "400x300", 400, 300, 0, false },
{ "1152x864", 1152, 864, 0, false },
{ "1280x960", 1280, 960, 0, false },
{ "1600x1024", 1600, 1024, 0, false },
{ "1792x1344", 1792, 1344, 0, false },
{ "1856x1392", 1856, 1392, 0, false },
{ "1920x1440", 1920, 1440, 0, false },
{ "2048x1536", 2048, 1536, 0, false },
{ "2048x2048", 2048, 2048, 0, false },
};
#endif
uint32_t GetScreenResolutionCount()
{
return sizeof(g_resolutions) / sizeof(g_resolutions[0]);
}
const char * GetScreenResolutionName(uint32_t index)
{
if (index < GetScreenResolutionCount())
{
return g_resolutions[index].Name();
}
return "unknown";
}
uint32_t GetDefaultScreenRes()
{
for (uint32_t i = 0, n = GetScreenResolutionCount(); i < n; i++)
{
if (g_resolutions[i].DefaultRes())
{
return i;
}
}
return 0;
}
uint32_t GetScreenResWidth(uint32_t index)
{
if (index < GetScreenResolutionCount())
{
return g_resolutions[index].width();
}
return 0;
}
uint32_t GetScreenResHeight(uint32_t index)
{
if (index < GetScreenResolutionCount())
{
return g_resolutions[index].height();
}
return 0;
}
class FullScreenResolutions class FullScreenResolutions
{ {
public: public:
FullScreenResolutions() : dwNumResolutions(0), aResolutions(0), aResolutionsStr(0) {} FullScreenResolutions() :
m_dwNumResolutions(0),
m_aResolutions(0),
m_aResolutionsStr(0)
{
}
~FullScreenResolutions(); ~FullScreenResolutions();
void getResolution(uint32_t _idx, uint32_t * _width, uint32_t * _height, uint32_t * _frequency = 0) void getResolution(uint32_t _idx, uint32_t * _width, uint32_t * _height, uint32_t * _frequency = 0)
{ {
WriteTrace(TraceResolution, TraceDebug, "_idx: %d", _idx); WriteTrace(TraceResolution, TraceDebug, "_idx: %d", _idx);
if (dwNumResolutions == 0) if (m_dwNumResolutions == 0)
{ {
init(); init();
} }
if (_idx >= dwNumResolutions) if (_idx >= m_dwNumResolutions)
{ {
WriteTrace(TraceGlitch, TraceError, "NumResolutions = %d", dwNumResolutions); WriteTrace(TraceGlitch, TraceError, "NumResolutions = %d", m_dwNumResolutions);
_idx = 0; _idx = 0;
} }
*_width = (uint32_t)aResolutions[_idx].dwW; *_width = (uint32_t)m_aResolutions[_idx].width();
*_height = (uint32_t)aResolutions[_idx].dwH; *_height = (uint32_t)m_aResolutions[_idx].height();
if (_frequency != 0) if (_frequency != 0)
{ {
*_frequency = (uint32_t)aResolutions[_idx].dwF; *_frequency = (uint32_t)m_aResolutions[_idx].frequency();
} }
} }
int getCurrentResolutions(void) int getCurrentResolutions(void)
{ {
if (dwNumResolutions == 0) if (m_dwNumResolutions == 0)
{ {
init(); init();
} }
return currentResolutions; return m_currentResolutions;
} }
char ** getResolutionsList(int32_t * Size) char ** getResolutionsList(int32_t * Size)
{ {
if (dwNumResolutions == 0) if (m_dwNumResolutions == 0)
{ {
init(); init();
} }
*Size = (int32_t)dwNumResolutions; *Size = (int32_t)m_dwNumResolutions;
return aResolutionsStr; return m_aResolutionsStr;
} }
bool changeDisplaySettings(uint32_t _resolution); bool changeDisplaySettings(uint32_t _resolution);
private: private:
void init(); void init();
unsigned int dwNumResolutions; unsigned int m_dwNumResolutions;
ResolutionInfo * aResolutions; ResolutionInfo * m_aResolutions;
char ** aResolutionsStr; char ** m_aResolutionsStr;
int currentResolutions; int m_currentResolutions;
}; };
FullScreenResolutions::~FullScreenResolutions() FullScreenResolutions::~FullScreenResolutions()
{ {
for (unsigned int i = 0; i < dwNumResolutions; i++) for (unsigned int i = 0; i < m_dwNumResolutions; i++)
{ {
delete[] aResolutionsStr[i]; delete[] m_aResolutionsStr[i];
aResolutionsStr[i] = NULL; m_aResolutionsStr[i] = NULL;
} }
if (aResolutionsStr) if (m_aResolutionsStr)
{ {
delete[] aResolutionsStr; delete[] m_aResolutionsStr;
aResolutionsStr = NULL; m_aResolutionsStr = NULL;
} }
if (aResolutions) if (m_aResolutions)
{ {
delete[] aResolutions; delete[] m_aResolutions;
aResolutions = NULL; m_aResolutions = NULL;
} }
} }
void FullScreenResolutions::init() void FullScreenResolutions::init()
{ {
#ifdef _WIN32 #ifdef _WIN32
currentResolutions = -1; m_currentResolutions = -1;
DEVMODE enumMode, currentMode; DEVMODE enumMode, currentMode;
int iModeNum = 0; int iModeNum = 0;
memset(&enumMode, 0, sizeof(DEVMODE)); memset(&enumMode, 0, sizeof(DEVMODE));
@ -132,16 +220,16 @@ void FullScreenResolutions::init()
ResolutionInfo prevInfo; ResolutionInfo prevInfo;
while (EnumDisplaySettings(NULL, iModeNum++, &enumMode) != 0) while (EnumDisplaySettings(NULL, iModeNum++, &enumMode) != 0)
{ {
ResolutionInfo curInfo(enumMode.dmPelsWidth, enumMode.dmPelsHeight, enumMode.dmDisplayFrequency); ResolutionInfo curInfo("", enumMode.dmPelsWidth, enumMode.dmPelsHeight, enumMode.dmDisplayFrequency);
if (enumMode.dmBitsPerPel == 32 && curInfo != prevInfo) if (enumMode.dmBitsPerPel == 32 && curInfo != prevInfo)
{ {
dwNumResolutions++; m_dwNumResolutions++;
prevInfo = curInfo; prevInfo = curInfo;
} }
} }
aResolutions = new ResolutionInfo[dwNumResolutions]; m_aResolutions = new ResolutionInfo[m_dwNumResolutions];
aResolutionsStr = new char*[dwNumResolutions]; m_aResolutionsStr = new char*[m_dwNumResolutions];
iModeNum = 0; iModeNum = 0;
int current = 0; int current = 0;
char smode[256]; char smode[256];
@ -149,17 +237,17 @@ void FullScreenResolutions::init()
memset(&prevInfo, 0, sizeof(ResolutionInfo)); memset(&prevInfo, 0, sizeof(ResolutionInfo));
while (EnumDisplaySettings(NULL, iModeNum++, &enumMode) != 0) while (EnumDisplaySettings(NULL, iModeNum++, &enumMode) != 0)
{ {
ResolutionInfo curInfo(enumMode.dmPelsWidth, enumMode.dmPelsHeight, enumMode.dmDisplayFrequency); ResolutionInfo curInfo(NULL, enumMode.dmPelsWidth, enumMode.dmPelsHeight, enumMode.dmDisplayFrequency);
if (enumMode.dmBitsPerPel == 32 && curInfo != prevInfo) if (enumMode.dmBitsPerPel == 32 && curInfo != prevInfo)
{ {
if (enumMode.dmPelsHeight == currentMode.dmPelsHeight && enumMode.dmPelsWidth == currentMode.dmPelsWidth) if (enumMode.dmPelsHeight == currentMode.dmPelsHeight && enumMode.dmPelsWidth == currentMode.dmPelsWidth)
{ {
currentResolutions = current; m_currentResolutions = current;
} }
aResolutions[current] = curInfo; m_aResolutions[current] = curInfo;
curInfo.toString(smode); sprintf(smode, curInfo.frequency() > 0 ? "%ix%i 32bpp %iHz" : "%ix%i 32bpp", curInfo.width(), curInfo.height(), curInfo.frequency());
aResolutionsStr[current] = new char[strlen(smode) + 1]; m_aResolutionsStr[current] = new char[strlen(smode) + 1];
strcpy(aResolutionsStr[current], smode); strcpy(m_aResolutionsStr[current], smode);
prevInfo = curInfo; prevInfo = curInfo;
current++; current++;
} }
@ -172,13 +260,13 @@ bool FullScreenResolutions::changeDisplaySettings(uint32_t _resolution)
#ifdef _WIN32 #ifdef _WIN32
uint32_t width, height, frequency; uint32_t width, height, frequency;
getResolution(_resolution, &width, &height, &frequency); getResolution(_resolution, &width, &height, &frequency);
ResolutionInfo info(width, height, frequency); ResolutionInfo info(NULL, width, height, frequency);
DEVMODE enumMode; DEVMODE enumMode;
int iModeNum = 0; int iModeNum = 0;
memset(&enumMode, 0, sizeof(DEVMODE)); memset(&enumMode, 0, sizeof(DEVMODE));
while (EnumDisplaySettings(NULL, iModeNum++, &enumMode) != 0) while (EnumDisplaySettings(NULL, iModeNum++, &enumMode) != 0)
{ {
ResolutionInfo curInfo(enumMode.dmPelsWidth, enumMode.dmPelsHeight, enumMode.dmDisplayFrequency); ResolutionInfo curInfo(NULL, enumMode.dmPelsWidth, enumMode.dmPelsHeight, enumMode.dmDisplayFrequency);
if (enumMode.dmBitsPerPel == 32 && curInfo == info) { if (enumMode.dmBitsPerPel == 32 && curInfo == info) {
bool bRes = ChangeDisplaySettings(&enumMode, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL; bool bRes = ChangeDisplaySettings(&enumMode, CDS_FULLSCREEN) == DISP_CHANGE_SUCCESSFUL;
WriteTrace(TraceGlitch, TraceDebug, "width=%d, height=%d, freq=%d %s\r\n", enumMode.dmPelsWidth, enumMode.dmPelsHeight, enumMode.dmDisplayFrequency, bRes ? "Success" : "Failed"); WriteTrace(TraceGlitch, TraceDebug, "width=%d, height=%d, freq=%d %s\r\n", enumMode.dmPelsWidth, enumMode.dmPelsHeight, enumMode.dmDisplayFrequency, bRes ? "Success" : "Failed");

View File

@ -11,6 +11,13 @@
#pragma once #pragma once
#include <Common/stdtypes.h> #include <Common/stdtypes.h>
uint32_t GetScreenResolutionCount();
uint32_t GetDefaultScreenRes();
uint32_t GetScreenResWidth(uint32_t index);
uint32_t GetScreenResHeight(uint32_t index);
const char * GetScreenResolutionName(uint32_t index);
int GetCurrentResIndex(void);
uint32_t GetFullScreenResWidth(uint32_t index); uint32_t GetFullScreenResWidth(uint32_t index);
uint32_t GetFullScreenResHeight(uint32_t index); uint32_t GetFullScreenResHeight(uint32_t index);
bool EnterFullScreen(uint32_t index); bool EnterFullScreen(uint32_t index);

View File

@ -207,9 +207,9 @@ void CSettings::RegisterSettings(void)
void CSettings::SetScreenRes(uint32_t value) void CSettings::SetScreenRes(uint32_t value)
{ {
if (value >= 0x18) if (value >= GetScreenResolutionCount())
{ {
value = 7; value = GetDefaultScreenRes();
} }
if (value != m_ScreenRes) if (value != m_ScreenRes)
@ -221,36 +221,6 @@ void CSettings::SetScreenRes(uint32_t value)
void CSettings::UpdateScreenSize(bool fullscreen) void CSettings::UpdateScreenSize(bool fullscreen)
{ {
// Resolutions, MUST be in the correct order (SST1VID.H)
uint32_t resolutions[0x18][2] = {
{ 320, 200 },
{ 320, 240 },
{ 400, 256 },
{ 512, 384 },
{ 640, 200 },
{ 640, 350 },
{ 640, 400 },
{ 640, 480 },
{ 800, 600 },
{ 960, 720 },
{ 856, 480 },
{ 512, 256 },
{ 1024, 768 },
{ 1280, 1024 },
{ 1600, 1200 },
{ 400, 300 },
// 0x10
{ 1152, 864 },
{ 1280, 960 },
{ 1600, 1024 },
{ 1792, 1344 },
{ 1856, 1392 },
{ 1920, 1440 },
{ 2048, 1536 },
{ 2048, 2048 }
};
#ifndef ANDROID #ifndef ANDROID
if (fullscreen) if (fullscreen)
{ {
@ -259,8 +229,8 @@ void CSettings::UpdateScreenSize(bool fullscreen)
} }
else else
{ {
g_width = resolutions[m_ScreenRes][0]; g_width = GetScreenResWidth(m_ScreenRes);
g_height = resolutions[m_ScreenRes][1]; g_height = GetScreenResHeight(m_ScreenRes);
} }
m_scr_res_x = m_res_x = g_width; m_scr_res_x = m_res_x = g_width;
m_scr_res_y = m_res_y = g_height; m_scr_res_y = m_res_y = g_height;