1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Implement max MSAA level detection.

Zilmar spec and Windows only.

Fixes #2216 MSAA max not 16x in UI
This commit is contained in:
Sergey Lipskiy 2020-12-06 21:01:04 +07:00
parent deb84826e4
commit f04ac8296d
20 changed files with 179 additions and 29 deletions

View File

@ -190,3 +190,8 @@ void DisplayWindow::readScreen2(void * _dest, int * _width, int * _height, int _
{
_readScreen2(_dest, _width, _height, _front);
}
u32 DisplayWindow::maxMSAALevel() const
{
return _maxMSAALevel();
}

View File

@ -22,6 +22,7 @@ public:
void setToggleFullscreen() { m_bToggleFullscreen = true; }
void readScreen(void **_pDest, long *_pWidth, long *_pHeight);
void readScreen2(void * _dest, int * _width, int * _height, int _front);
u32 maxMSAALevel() const;
void updateScale();
f32 getScaleX() const { return m_scaleX; }
@ -81,6 +82,8 @@ private:
virtual void _readScreen(void **_pDest, long *_pWidth, long *_pHeight) = 0;
virtual void _readScreen2(void * _dest, int * _width, int * _height, int _front) = 0;
virtual graphics::ObjectHandle _getDefaultFramebuffer() = 0;
virtual u32 _maxMSAALevel() const = 0;
};
inline

View File

@ -37,6 +37,14 @@ void CConfigDlg::setRomName(const char * RomName) {
m_romName = RomName == NULL || strlen(RomName) == 0 ? NULL : RomName;
}
void CConfigDlg::setMSAALevel(uint32_t _maxMSAALevel) {
m_maxMSAALevel = _maxMSAALevel;
}
uint32_t CConfigDlg::getMSAALevel() const {
return m_maxMSAALevel;
}
LRESULT CConfigDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) {
HICON hIcon = AtlLoadIconImage(IDI_APPICON, LR_DEFAULTCOLOR, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON));
SetIcon(hIcon, TRUE);
@ -221,7 +229,7 @@ void CConfigDlg::SaveSettings() {
m_Saved = true;
for (size_t i = 0; i < m_TabWindows.size(); i++)
m_TabWindows[i]->SaveSettings();
if (config.generalEmulation.enableCustomSettings && CButton(GetDlgItem(IDC_GAME_PROFILE)).GetCheck() == BST_CHECKED && m_romName != nullptr)
saveCustomRomSettings(m_strIniPath.c_str(), m_romName);
else
@ -390,7 +398,7 @@ void CConfigDlg::SetLanguage(const std::string & language) {
m_Tabs.SetItem(i, &tci);
}
}
for (size_t i = 0; i < m_TabWindows.size(); i++)
for (size_t i = 0; i < m_TabWindows.size(); i++)
m_TabWindows[i]->ApplyLanguage();
ApplyLanguage();
}

View File

@ -26,7 +26,7 @@ public:
COMMAND_HANDLER(IDC_PROFILE, CBN_SELCHANGE, OnProfileChanged)
COMMAND_HANDLER_EX(IDC_GAME_PROFILE, BN_CLICKED, OnGameProfile)
COMMAND_HANDLER_EX(IDC_USE_PROFILE, BN_CLICKED, OnUseProfile)
COMMAND_ID_HANDLER(IDC_REMOVE_PROFILE, OnRemoveProfile)
COMMAND_ID_HANDLER(IDC_REMOVE_PROFILE, OnRemoveProfile)
COMMAND_ID_HANDLER(ID_RESTORE_DEFAULTS, OnRestoreDefaults)
COMMAND_ID_HANDLER(ID_SAVECLOSE, OnSaveClose)
COMMAND_ID_HANDLER(ID_SAVE, OnSave)
@ -35,6 +35,8 @@ public:
void setIniPath(const std::string & IniPath);
void setRomName(const char * RomName);
void setMSAALevel(uint32_t _maxMSAALevel);
uint32_t getMSAALevel() const;
bool Saved(void) const { return m_Saved; }
void OnCustomSettingsToggled(bool checked);
void SetLanguage(const std::string & language);
@ -62,6 +64,7 @@ protected:
std::vector<CConfigTab *> m_TabWindows;
std::string m_strIniPath;
const char * m_romName;
uint32_t m_maxMSAALevel;
bool m_blockReInit;
CFrameBufferTab * m_FrameBufferTab;
CVideoTab * m_VideoTab;

View File

@ -16,7 +16,7 @@ Q_IMPORT_PLUGIN(QICOPlugin)
//#define RUN_DIALOG_IN_THREAD
static
int openConfigDialog(const wchar_t * _strFileName, const char * _romName, bool & _accepted)
int openConfigDialog(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, bool & _accepted)
{
std::string IniFolder;
uint32_t slength = WideCharToMultiByte(CP_ACP, 0, _strFileName, -1, NULL, 0, NULL, NULL);
@ -33,26 +33,28 @@ int openConfigDialog(const wchar_t * _strFileName, const char * _romName, bool &
CConfigDlg Dlg;
Dlg.setIniPath(IniFolder.c_str());
Dlg.setRomName(_romName);
Dlg.setMSAALevel(_maxMSAALevel);
Dlg.DoModal();
_accepted = Dlg.Saved();
return 0;
}
bool runConfigThread(const wchar_t * _strFileName, const char * _romName) {
bool runConfigThread(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel)
{
bool accepted = false;
#ifdef RUN_DIALOG_IN_THREAD
std::thread configThread(openConfigDialog, _strFileName, std::ref(accepted));
std::thread configThread(openConfigDialog, _strFileName, _maxMSAALevel, std::ref(accepted));
configThread.join();
#else
openConfigDialog(_strFileName, _romName, accepted);
openConfigDialog(_strFileName, _romName, _maxMSAALevel, accepted);
#endif
return accepted;
}
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName)
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel)
{
return runConfigThread(_strFileName, _romName);
return runConfigThread(_strFileName, _romName, _maxMSAALevel);
}
EXPORT int CALL RunAbout(const wchar_t * _strFileName)

View File

@ -13,7 +13,7 @@ extern "C" {
#define CALL
#endif
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName);
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel);
EXPORT int CALL RunAbout(const wchar_t * _strFileName);
EXPORT void CALL LoadConfig(const wchar_t * _strFileName);
EXPORT void CALL LoadCustomRomSettings(const wchar_t * _strFileName, const char * _romName);

View File

@ -412,9 +412,11 @@ void CVideoTab::LoadSettings(bool /*blockCustomSettings*/) {
if (fullscreenRate == i)
RefreshRateComboBox.SetCurSel(index);
}
const u32 maxMSAALevel = m_Dlg.getMSAALevel();
const unsigned int multisampling = config.video.fxaa == 0 && config.video.multisampling > 0
? config.video.multisampling
: 8;
? min(config.video.multisampling, maxMSAALevel)
: maxMSAALevel;
m_AliasingSlider.SetRangeMax(powof(maxMSAALevel));
m_AliasingSlider.SetPos(powof(multisampling));
std::wstring AliasingText = FormatStrW(L"%dx", multisampling);
CWindow(GetDlgItem(IDC_ALIASING_LABEL)).SetWindowTextW(AliasingText.c_str());

View File

@ -169,9 +169,10 @@ void ConfigDialog::_init(bool reInit, bool blockCustomSettings)
ui->fullScreenRefreshRateComboBox->setCurrentIndex(fullscreenRate);
const unsigned int multisampling = config.video.fxaa == 0 && config.video.multisampling > 0
? config.video.multisampling
: 8;
? std::min(config.video.multisampling, m_maxMSAA)
: m_maxMSAA;
ui->aliasingSlider->blockSignals(true);
ui->aliasingSlider->setMaximum(powof(m_maxMSAA));
ui->aliasingSlider->setValue(powof(multisampling));
ui->aliasingSlider->blockSignals(false);
ui->aliasingLabelVal->setText(QString::number(multisampling));
@ -469,9 +470,10 @@ void ConfigDialog::setRomName(const char * _romName)
this->on_customSettingsCheckBox_toggled(ui->customSettingsCheckBox->isChecked());
}
ConfigDialog::ConfigDialog(QWidget *parent, Qt::WindowFlags f) :
ConfigDialog::ConfigDialog(QWidget *parent, Qt::WindowFlags f, unsigned int _maxMsaaLevel) :
QDialog(parent, f),
ui(new Ui::ConfigDialog),
m_maxMSAA(_maxMsaaLevel),
m_accepted(false),
m_fontsInited(false),
m_blockReInit(false)

View File

@ -15,7 +15,7 @@ class ConfigDialog : public QDialog
Q_OBJECT
public:
explicit ConfigDialog(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags());
explicit ConfigDialog(QWidget *parent = Q_NULLPTR, Qt::WindowFlags f = Qt::WindowFlags(), unsigned int _maxMsaaLevel = 8);
~ConfigDialog();
void setIniPath(const QString & _strIniPath);
@ -97,6 +97,7 @@ private:
bool m_blockReInit;
QString m_strIniPath;
const char * m_romName;
unsigned int m_maxMSAA;
};
#endif // CONFIGDIALOG_H

View File

@ -17,7 +17,8 @@ void Config_DoConfig(/*HWND hParent*/)
api().FindPluginPath(strIniFolderPath);
ConfigOpen = true;
const bool bRestart = RunConfig(strIniFolderPath, api().isRomOpen() ? RSP.romname : nullptr);
const u32 maxMsaa = dwnd().maxMSAALevel();
const bool bRestart = RunConfig(strIniFolderPath, api().isRomOpen() ? RSP.romname : nullptr, maxMsaa);
if (config.generalEmulation.enableCustomSettings != 0)
LoadCustomRomSettings(strIniFolderPath, RSP.romname);
config.validate();

View File

@ -20,7 +20,7 @@ inline void initMyResource() { Q_INIT_RESOURCE(icon); }
inline void cleanMyResource() { Q_CLEANUP_RESOURCE(icon); }
static
int openConfigDialog(const wchar_t * _strFileName, const char * _romName, bool & _accepted)
int openConfigDialog(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel, bool & _accepted)
{
cleanMyResource();
initMyResource();
@ -43,7 +43,7 @@ int openConfigDialog(const wchar_t * _strFileName, const char * _romName, bool &
if (translator.load(getTranslationFile(), strIniFileName))
pApp->installTranslator(&translator);
ConfigDialog w(Q_NULLPTR, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint);
ConfigDialog w(Q_NULLPTR, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint, _maxMSAALevel);
w.setIniPath(strIniFileName);
w.setRomName(_romName);
@ -74,13 +74,13 @@ int openAboutDialog(const wchar_t * _strFileName)
return a.exec();
}
bool runConfigThread(const wchar_t * _strFileName, const char * _romName) {
bool runConfigThread(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel) {
bool accepted = false;
#ifdef RUN_DIALOG_IN_THREAD
std::thread configThread(openConfigDialog, _strFileName, std::ref(accepted));
std::thread configThread(openConfigDialog, _strFileName, _maxMSAALevel, std::ref(accepted));
configThread.join();
#else
openConfigDialog(_strFileName, _romName, accepted);
openConfigDialog(_strFileName, _romName, _maxMSAALevel, accepted);
#endif
return accepted;
@ -96,9 +96,9 @@ int runAboutThread(const wchar_t * _strFileName) {
return 0;
}
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName)
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel)
{
return runConfigThread(_strFileName, _romName);
return runConfigThread(_strFileName, _romName, _maxMSAALevel);
}
EXPORT int CALL RunAbout(const wchar_t * _strFileName)

View File

@ -13,7 +13,7 @@ extern "C" {
#define CALL
#endif
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName);
EXPORT bool CALL RunConfig(const wchar_t * _strFileName, const char * _romName, unsigned int _maxMSAALevel);
EXPORT int CALL RunAbout(const wchar_t * _strFileName);
EXPORT void CALL LoadConfig(const wchar_t * _strFileName);
EXPORT void CALL LoadCustomRomSettings(const wchar_t * _strFileName, const char * _romName);

View File

@ -479,7 +479,7 @@
<item>
<widget class="QSlider" name="aliasingSlider">
<property name="maximum">
<number>3</number>
<number>4</number>
</property>
<property name="singleStep">
<number>1</number>

View File

@ -5326,6 +5326,36 @@ private:
std::function<void()> m_swapBuffersCallback;
};
class WindowsMaxMSAALevelCommand : public OpenGlCommand
{
public:
WindowsMaxMSAALevelCommand() :
OpenGlCommand(true, false, "WindowsMaxMSAALevelCommand", false)
{
}
static std::shared_ptr<OpenGlCommand> get(u32& returnValue)
{
static int poolId = OpenGlCommandPool::get().getNextAvailablePool();
auto ptr = getFromPool<WindowsMaxMSAALevelCommand>(poolId);
ptr->set(returnValue);
return ptr;
}
void commandToExecute() override
{
*m_returnValue = WindowsWGL::maxMSAALevel();
}
private:
void set(u32& returnValue)
{
m_returnValue = &returnValue;
}
u32* m_returnValue;
};
#endif
}
#ifdef __clang__

View File

@ -375,7 +375,7 @@ namespace opengl {
ptrDrawElements(mode, count, type, indices);
return;
}
int typeSizeBytes;
unsigned int maxElementIndex;
@ -1443,7 +1443,7 @@ namespace opengl {
if (m_threaded_wrapper) {
executeCommand(CoreVideoQuitCommand::get());
executeCommand(ShutdownCommand::get());
}
}
else
CoreVideoQuitCommand::get()->performCommandSingleThreaded();
@ -1658,4 +1658,20 @@ namespace opengl {
return textureSize;
}
u32 FunctionWrapper::maxMSAALevel()
{
#if defined(OS_WINDOWS) && !defined(MUPENPLUSAPI)
u32 returnValue;
if (m_threaded_wrapper)
executeCommand(WindowsMaxMSAALevelCommand::get(returnValue));
else
WindowsMaxMSAALevelCommand::get(returnValue)->performCommandSingleThreaded();
return returnValue;
#else
return 8;
#endif
}
}

View File

@ -221,5 +221,6 @@ namespace opengl {
static void WaitForSwapBuffersQueued();
static int getTextureBytes(GLenum format, GLenum type, int width, int height);
static u32 maxMSAALevel();
};
}

View File

@ -40,6 +40,7 @@ private:
void _changeWindow() override;
void _readScreen(void **_pDest, long *_pWidth, long *_pHeight) override {}
void _readScreen2(void * _dest, int * _width, int * _height, int _front) override;
u32 _maxMSAALevel() const override;
#ifdef M64P_GLIDENUI
bool _supportsWithRateFunctions = true;
#endif // M64P_GLIDENUI
@ -325,3 +326,10 @@ graphics::ObjectHandle DisplayWindowMupen64plus::_getDefaultFramebuffer()
return graphics::ObjectHandle(CoreVideo_GL_GetDefaultFramebuffer());
return graphics::ObjectHandle::null;
}
u32 DisplayWindowMupen64plus::_maxMSAALevel() const
{
FunctionWrapper::setThreadedMode(config.video.threadedVideo);
return FunctionWrapper::maxMSAALevel();
}

View File

@ -5,6 +5,7 @@
HGLRC WindowsWGL::hRC = NULL;
HDC WindowsWGL::hDC = NULL;
unsigned int WindowsWGL::m_sMaxMsaa = 0;
bool WindowsWGL::start()
{
@ -106,6 +107,57 @@ bool WindowsWGL::start()
}
}
if (m_sMaxMsaa > 0)
return true;
PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB =
(PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress("wglChoosePixelFormatARB");
if (wglChoosePixelFormatARB != nullptr) {
const int piAttribIList16[] =
{
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
WGL_SAMPLE_BUFFERS_ARB, 1,
WGL_SAMPLES_EXT, 16,
0 // zero term
};
const float pfAttribFList[] = { 0.0f };
int piFormats;
unsigned int nNumFormats;
int res = wglChoosePixelFormatARB(hDC, piAttribIList16, pfAttribFList, 1, &piFormats, &nNumFormats);
if (res > 0 && nNumFormats > 0)
m_sMaxMsaa = 16;
else {
const int piAttribIList8[] =
{
WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_PIXEL_TYPE_ARB, WGL_TYPE_RGBA_ARB,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_COLOR_BITS_ARB, 32,
WGL_DEPTH_BITS_ARB, 24,
WGL_STENCIL_BITS_ARB, 8,
WGL_SAMPLE_BUFFERS_ARB, 1,
WGL_SAMPLES_EXT, 8,
0 // zero term
};
res = wglChoosePixelFormatARB(hDC, piAttribIList16, pfAttribFList, 1, &piFormats, &nNumFormats);
if (res > 0 && nNumFormats > 0)
m_sMaxMsaa = 8;
else
m_sMaxMsaa = 4;
}
}
return true;
}
@ -132,3 +184,12 @@ void WindowsWGL::swapBuffers()
SwapBuffers(hDC);
}
unsigned int WindowsWGL::maxMSAALevel()
{
if (hRC != NULL || m_sMaxMsaa > 0)
return m_sMaxMsaa;
start();
stop();
return m_sMaxMsaa;
}

View File

@ -11,10 +11,11 @@ public:
static bool start();
static void stop();
static void swapBuffers();
static unsigned int maxMSAALevel();
private:
static HGLRC hRC;
static HDC hDC;
static unsigned int m_sMaxMsaa;
};

View File

@ -28,6 +28,7 @@ private:
void _changeWindow() override;
void _readScreen(void **_pDest, long *_pWidth, long *_pHeight) override;
void _readScreen2(void * _dest, int * _width, int * _height, int _front) override {}
u32 _maxMSAALevel() const override;
graphics::ObjectHandle _getDefaultFramebuffer() override;
};
@ -227,3 +228,8 @@ graphics::ObjectHandle DisplayWindowWindows::_getDefaultFramebuffer()
{
return graphics::ObjectHandle::null;
}
u32 DisplayWindowWindows::_maxMSAALevel() const
{
return FunctionWrapper::maxMSAALevel();
}