Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable options when renderer requirements aren't met #2177

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion src/frontend/qt_sdl/VideoSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,93 @@ void VideoSettingsDialog::setEnabled()
{
auto& cfg = emuInstance->getGlobalConfig();
int renderer = cfg.GetInt("3D.Renderer");
int ogldisplay = cfg.GetBool("Screen.UseGL");

if (!compute_gl)
{
ui->rb3DCompute->setEnabled(false);
if (renderer == renderer3D_OpenGLCompute) // fallback to software renderer
{
ui->rb3DSoftware->setChecked(true);
renderer = renderer3D_Software;
}
}

if (!base_gl) // fallback to software renderer
{
renderer = renderer3D_Software;
ogldisplay = false;

ui->rb3DOpenGL->setEnabled(false);
ui->cbGLDisplay->setChecked(false);
ui->rb3DSoftware->setChecked(true);
}

cfg.SetInt("3D.Renderer", renderer);
cfg.SetBool("Screen.UseGL", ogldisplay);
bool softwareRenderer = renderer == renderer3D_Software;
ui->cbGLDisplay->setEnabled(softwareRenderer);

ui->cbGLDisplay->setEnabled(softwareRenderer && base_gl);
setVsyncControlEnable(ogldisplay || !softwareRenderer);
ui->cbSoftwareThreaded->setEnabled(softwareRenderer);
ui->cbxGLResolution->setEnabled(!softwareRenderer);
ui->cbBetterPolygons->setEnabled(renderer == renderer3D_OpenGL);
ui->cbxComputeHiResCoords->setEnabled(renderer == renderer3D_OpenGLCompute);
}

int VideoSettingsDialog::getsupportedRenderers()
{
ScreenPanelGL *glpanel = new ScreenPanelGL(this);
std::optional<WindowInfo> windowinfo = glpanel->getWindowInfo();

int renderer = renderer3D_Software;

if (windowinfo.has_value())
{
std::array<GL::Context::Version, 2> versionsToTry = {
GL::Context::Version{GL::Context::Profile::Core, 4, 3},
GL::Context::Version{GL::Context::Profile::Core, 3, 2}
};

std::unique_ptr<GL::Context> glContext = GL::Context::Create(*windowinfo, versionsToTry);

if (glContext)
{
const char* gl_version_str = reinterpret_cast<const char*>(glGetString(GL_VERSION));

if (gl_version_str)
{
int gl_version = 0;

// A proper version string or object isn't provided, so we have to parse it ourselves
if (isdigit(gl_version_str[0]) && isdigit(gl_version_str[2]))
Mrcubix marked this conversation as resolved.
Show resolved Hide resolved
gl_version = (gl_version_str[0] - '0') * 100 +
(gl_version_str[2] - '0') * 10;

// OpenGL 4.3 is required for Compute Shaders while 3.2 is the base requirement
if (gl_version >= 430)
renderer = renderer3D_OpenGLCompute;
else if (gl_version >= 320)
renderer = renderer3D_OpenGL;
}
}
}

delete glpanel;

return renderer;
}

VideoSettingsDialog::VideoSettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::VideoSettingsDialog)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);

emuInstance = ((MainWindow*)parent)->getEmuInstance();
int supportedRenderers = getsupportedRenderers();

base_gl = supportedRenderers > renderer3D_Software;
compute_gl = supportedRenderers == renderer3D_OpenGLCompute;

auto& cfg = emuInstance->getGlobalConfig();
oldRenderer = cfg.GetInt("3D.Renderer");
Expand Down Expand Up @@ -146,6 +218,7 @@ void VideoSettingsDialog::on_VideoSettingsDialog_rejected()

void VideoSettingsDialog::setVsyncControlEnable(bool hasOGL)
{
ui->label_2->setEnabled(hasOGL);
ui->cbVSync->setEnabled(hasOGL);
ui->sbVSyncInterval->setEnabled(hasOGL);
}
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/qt_sdl/VideoSettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ private slots:
private:
void setVsyncControlEnable(bool hasOGL);
void setEnabled();
int getsupportedRenderers();

Ui::VideoSettingsDialog* ui;
EmuInstance* emuInstance;
bool base_gl;
Mrcubix marked this conversation as resolved.
Show resolved Hide resolved
bool compute_gl;

QButtonGroup* grp3DRenderer;

Expand Down
Loading