mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-21 05:09:46 -06:00
get the GL shit going
This commit is contained in:
@ -2,6 +2,7 @@ project(qt_sdl)
|
|||||||
|
|
||||||
SET(SOURCES_QT_SDL
|
SET(SOURCES_QT_SDL
|
||||||
main.cpp
|
main.cpp
|
||||||
|
main_shaders.h
|
||||||
EmuSettingsDialog.cpp
|
EmuSettingsDialog.cpp
|
||||||
InputConfigDialog.cpp
|
InputConfigDialog.cpp
|
||||||
AudioSettingsDialog.cpp
|
AudioSettingsDialog.cpp
|
||||||
|
@ -639,7 +639,7 @@ void ScreenHandler::screenOnMouseMove(QMouseEvent* event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent)
|
ScreenPanelNative::ScreenPanelNative(QWidget* parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
screen[0] = QImage(256, 192, QImage::Format_RGB32);
|
screen[0] = QImage(256, 192, QImage::Format_RGB32);
|
||||||
screen[1] = QImage(256, 192, QImage::Format_RGB32);
|
screen[1] = QImage(256, 192, QImage::Format_RGB32);
|
||||||
@ -650,16 +650,11 @@ MainWindowPanel::MainWindowPanel(QWidget* parent) : QWidget(parent)
|
|||||||
touching = false;
|
touching = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindowPanel::~MainWindowPanel()
|
ScreenPanelNative::~ScreenPanelNative()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowPanel::ensureProperMinSize()
|
void ScreenPanelNative::setupScreenLayout()
|
||||||
{
|
|
||||||
setMinimumSize(screenGetMinSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindowPanel::setupScreenLayout()
|
|
||||||
{
|
{
|
||||||
int w = width();
|
int w = width();
|
||||||
int h = height();
|
int h = height();
|
||||||
@ -678,7 +673,7 @@ void MainWindowPanel::setupScreenLayout()
|
|||||||
mtx[4], mtx[5], 1.f);
|
mtx[4], mtx[5], 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowPanel::paintEvent(QPaintEvent* event)
|
void ScreenPanelNative::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
@ -702,28 +697,78 @@ void MainWindowPanel::paintEvent(QPaintEvent* event)
|
|||||||
painter.drawImage(screenrc, screen[1]);
|
painter.drawImage(screenrc, screen[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowPanel::resizeEvent(QResizeEvent* event)
|
void ScreenPanelNative::resizeEvent(QResizeEvent* event)
|
||||||
{
|
{
|
||||||
setupScreenLayout();
|
setupScreenLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowPanel::mousePressEvent(QMouseEvent* event)
|
void ScreenPanelNative::mousePressEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
screenOnMousePress(event);
|
screenOnMousePress(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowPanel::mouseReleaseEvent(QMouseEvent* event)
|
void ScreenPanelNative::mouseReleaseEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
screenOnMouseRelease(event);
|
screenOnMouseRelease(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowPanel::mouseMoveEvent(QMouseEvent* event)
|
void ScreenPanelNative::mouseMoveEvent(QMouseEvent* event)
|
||||||
{
|
{
|
||||||
screenOnMouseMove(event);
|
screenOnMouseMove(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowPanel::onScreenLayoutChanged()
|
void ScreenPanelNative::onScreenLayoutChanged()
|
||||||
{
|
{
|
||||||
|
setMinimumSize(screenGetMinSize());
|
||||||
|
setupScreenLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ScreenPanelGL::ScreenPanelGL(QWidget* parent) : QOpenGLWidget(parent)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
ScreenPanelGL::~ScreenPanelGL()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenPanelGL::setupScreenLayout()
|
||||||
|
{
|
||||||
|
int w = width();
|
||||||
|
int h = height();
|
||||||
|
|
||||||
|
screenSetupLayout(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenPanelGL::paintEvent(QPaintEvent* event)
|
||||||
|
{
|
||||||
|
// TODO?
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenPanelGL::resizeEvent(QResizeEvent* event)
|
||||||
|
{
|
||||||
|
setupScreenLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenPanelGL::mousePressEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
screenOnMousePress(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenPanelGL::mouseReleaseEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
screenOnMouseRelease(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenPanelGL::mouseMoveEvent(QMouseEvent* event)
|
||||||
|
{
|
||||||
|
screenOnMouseMove(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScreenPanelGL::onScreenLayoutChanged()
|
||||||
|
{
|
||||||
|
setMinimumSize(screenGetMinSize());
|
||||||
setupScreenLayout();
|
setupScreenLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -932,9 +977,10 @@ MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent)
|
|||||||
}
|
}
|
||||||
setMenuBar(menubar);
|
setMenuBar(menubar);
|
||||||
|
|
||||||
panel = new MainWindowPanel(this);
|
panel = new ScreenPanelNative(this);
|
||||||
setCentralWidget(panel);
|
setCentralWidget(panel);
|
||||||
panel->ensureProperMinSize();
|
connect(this, SIGNAL(screenLayoutChange()), panel, SLOT(onScreenLayoutChanged()));
|
||||||
|
emit screenLayoutChange();
|
||||||
|
|
||||||
resize(Config::WindowWidth, Config::WindowHeight);
|
resize(Config::WindowWidth, Config::WindowHeight);
|
||||||
|
|
||||||
@ -1413,8 +1459,7 @@ void MainWindow::onChangeScreenRotation(QAction* act)
|
|||||||
int rot = act->data().toInt();
|
int rot = act->data().toInt();
|
||||||
Config::ScreenRotation = rot;
|
Config::ScreenRotation = rot;
|
||||||
|
|
||||||
panel->ensureProperMinSize();
|
emit screenLayoutChange();
|
||||||
panel->setupScreenLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onChangeScreenGap(QAction* act)
|
void MainWindow::onChangeScreenGap(QAction* act)
|
||||||
@ -1422,8 +1467,7 @@ void MainWindow::onChangeScreenGap(QAction* act)
|
|||||||
int gap = act->data().toInt();
|
int gap = act->data().toInt();
|
||||||
Config::ScreenGap = gap;
|
Config::ScreenGap = gap;
|
||||||
|
|
||||||
panel->ensureProperMinSize();
|
emit screenLayoutChange();
|
||||||
panel->setupScreenLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onChangeScreenLayout(QAction* act)
|
void MainWindow::onChangeScreenLayout(QAction* act)
|
||||||
@ -1431,8 +1475,7 @@ void MainWindow::onChangeScreenLayout(QAction* act)
|
|||||||
int layout = act->data().toInt();
|
int layout = act->data().toInt();
|
||||||
Config::ScreenLayout = layout;
|
Config::ScreenLayout = layout;
|
||||||
|
|
||||||
panel->ensureProperMinSize();
|
emit screenLayoutChange();
|
||||||
panel->setupScreenLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onChangeScreenSizing(QAction* act)
|
void MainWindow::onChangeScreenSizing(QAction* act)
|
||||||
@ -1440,14 +1483,14 @@ void MainWindow::onChangeScreenSizing(QAction* act)
|
|||||||
int sizing = act->data().toInt();
|
int sizing = act->data().toInt();
|
||||||
Config::ScreenSizing = sizing;
|
Config::ScreenSizing = sizing;
|
||||||
|
|
||||||
panel->setupScreenLayout();
|
emit screenLayoutChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onChangeIntegerScaling(bool checked)
|
void MainWindow::onChangeIntegerScaling(bool checked)
|
||||||
{
|
{
|
||||||
Config::IntegerScaling = checked?1:0;
|
Config::IntegerScaling = checked?1:0;
|
||||||
|
|
||||||
panel->setupScreenLayout();
|
emit screenLayoutChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onChangeScreenFiltering(bool checked)
|
void MainWindow::onChangeScreenFiltering(bool checked)
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QActionGroup>
|
#include <QActionGroup>
|
||||||
|
#include <QOpenGLWidget>
|
||||||
|
|
||||||
|
|
||||||
class EmuThread : public QThread
|
class EmuThread : public QThread
|
||||||
@ -66,6 +67,11 @@ private:
|
|||||||
|
|
||||||
class ScreenHandler
|
class ScreenHandler
|
||||||
{
|
{
|
||||||
|
Q_GADGET
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~ScreenHandler() {}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void screenSetupLayout(int w, int h);
|
void screenSetupLayout(int w, int h);
|
||||||
|
|
||||||
@ -81,16 +87,13 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class MainWindowPanel : public QWidget, public ScreenHandler
|
class ScreenPanelNative : public QWidget, public ScreenHandler
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit MainWindowPanel(QWidget* parent);
|
explicit ScreenPanelNative(QWidget* parent);
|
||||||
~MainWindowPanel();
|
~ScreenPanelNative();
|
||||||
|
|
||||||
void ensureProperMinSize();
|
|
||||||
void setupScreenLayout();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent* event) override;
|
void paintEvent(QPaintEvent* event) override;
|
||||||
@ -105,11 +108,40 @@ private slots:
|
|||||||
void onScreenLayoutChanged();
|
void onScreenLayoutChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setupScreenLayout();
|
||||||
|
|
||||||
QImage screen[2];
|
QImage screen[2];
|
||||||
QTransform screenTrans[2];
|
QTransform screenTrans[2];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ScreenPanelGL : public QOpenGLWidget, public ScreenHandler
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ScreenPanelGL(QWidget* parent);
|
||||||
|
~ScreenPanelGL();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent* event) override;
|
||||||
|
|
||||||
|
void resizeEvent(QResizeEvent* event) override;
|
||||||
|
|
||||||
|
void mousePressEvent(QMouseEvent* event) override;
|
||||||
|
void mouseReleaseEvent(QMouseEvent* event) override;
|
||||||
|
void mouseMoveEvent(QMouseEvent* event) override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void onScreenLayoutChanged();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupScreenLayout();
|
||||||
|
|
||||||
|
//
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -127,6 +159,9 @@ protected:
|
|||||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
void dropEvent(QDropEvent* event) override;
|
void dropEvent(QDropEvent* event) override;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void screenLayoutChange();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onOpenFile();
|
void onOpenFile();
|
||||||
void onBootFirmware();
|
void onBootFirmware();
|
||||||
@ -167,7 +202,7 @@ private:
|
|||||||
QString loadErrorStr(int error);
|
QString loadErrorStr(int error);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindowPanel* panel;
|
QWidget* panel;
|
||||||
|
|
||||||
QAction* actOpenROM;
|
QAction* actOpenROM;
|
||||||
QAction* actBootFirmware;
|
QAction* actBootFirmware;
|
||||||
|
124
src/frontend/qt_sdl/main_shaders.h
Normal file
124
src/frontend/qt_sdl/main_shaders.h
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2016-2020 Arisotura
|
||||||
|
|
||||||
|
This file is part of melonDS.
|
||||||
|
|
||||||
|
melonDS is free software: you can redistribute it and/or modify it under
|
||||||
|
the terms of the GNU General Public License as published by the Free
|
||||||
|
Software Foundation, either version 3 of the License, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
melonDS is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License along
|
||||||
|
with melonDS. If not, see http://www.gnu.org/licenses/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MAIN_SHADERS_H
|
||||||
|
#define MAIN_SHADERS_H
|
||||||
|
|
||||||
|
const char* kScreenVS = R"(#version 140
|
||||||
|
|
||||||
|
layout(std140) uniform uConfig
|
||||||
|
{
|
||||||
|
vec2 uScreenSize;
|
||||||
|
uint u3DScale;
|
||||||
|
uint uFilterMode;
|
||||||
|
};
|
||||||
|
|
||||||
|
in vec2 vPosition;
|
||||||
|
in vec2 vTexcoord;
|
||||||
|
|
||||||
|
smooth out vec2 fTexcoord;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 fpos;
|
||||||
|
fpos.xy = ((vPosition * 2.0) / uScreenSize) - 1.0;
|
||||||
|
fpos.y *= -1;
|
||||||
|
fpos.z = 0.0;
|
||||||
|
fpos.w = 1.0;
|
||||||
|
|
||||||
|
gl_Position = fpos;
|
||||||
|
fTexcoord = vTexcoord;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
const char* kScreenFS = R"(#version 140
|
||||||
|
|
||||||
|
layout(std140) uniform uConfig
|
||||||
|
{
|
||||||
|
vec2 uScreenSize;
|
||||||
|
uint u3DScale;
|
||||||
|
uint uFilterMode;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform usampler2D ScreenTex;
|
||||||
|
|
||||||
|
smooth in vec2 fTexcoord;
|
||||||
|
|
||||||
|
out vec4 oColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
ivec4 pixel = ivec4(texelFetch(ScreenTex, ivec2(fTexcoord), 0));
|
||||||
|
|
||||||
|
// TODO: filters
|
||||||
|
|
||||||
|
oColor = vec4(vec3(pixel.bgr) / 255.0, 1.0);
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const char* kScreenVS_OSD = R"(#version 140
|
||||||
|
|
||||||
|
layout(std140) uniform uConfig
|
||||||
|
{
|
||||||
|
vec2 uScreenSize;
|
||||||
|
uint u3DScale;
|
||||||
|
uint uFilterMode;
|
||||||
|
};
|
||||||
|
|
||||||
|
uniform ivec2 uOSDPos;
|
||||||
|
uniform ivec2 uOSDSize;
|
||||||
|
|
||||||
|
in vec2 vPosition;
|
||||||
|
|
||||||
|
smooth out vec2 fTexcoord;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 fpos;
|
||||||
|
|
||||||
|
vec2 osdpos = (vPosition * vec2(uOSDSize));
|
||||||
|
fTexcoord = osdpos;
|
||||||
|
osdpos += uOSDPos;
|
||||||
|
|
||||||
|
fpos.xy = ((osdpos * 2.0) / uScreenSize) - 1.0;
|
||||||
|
fpos.y *= -1;
|
||||||
|
fpos.z = 0.0;
|
||||||
|
fpos.w = 1.0;
|
||||||
|
|
||||||
|
gl_Position = fpos;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
const char* kScreenFS_OSD = R"(#version 140
|
||||||
|
|
||||||
|
uniform sampler2D OSDTex;
|
||||||
|
|
||||||
|
smooth in vec2 fTexcoord;
|
||||||
|
|
||||||
|
out vec4 oColor;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec4 pixel = texelFetch(OSDTex, ivec2(fTexcoord), 0);
|
||||||
|
oColor = pixel.bgra;
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
#endif // MAIN_SHADERS_H
|
Reference in New Issue
Block a user