You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
2.9 KiB
116 lines
2.9 KiB
/*
|
|
Copyright 2020-2021 Brad Parker
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
#include <QPainter>
|
|
#include <QPaintEvent>
|
|
#include <QOpenGLFramebufferObject>
|
|
#include <iostream>
|
|
#include <cmath>
|
|
#include "../common/video.h"
|
|
#include "../core/core.h"
|
|
#include "mainwindow.h"
|
|
|
|
void MainWindow::paintEvent(QPaintEvent *e) {
|
|
//std::cout << "paintEvent" << std::endl;
|
|
|
|
QOpenGLWidget::paintEvent(e);
|
|
|
|
if(!m_core->isRunning())
|
|
return;
|
|
|
|
QPainter p(this);
|
|
QRect r;
|
|
|
|
QImage *img = m_core->getImage();
|
|
auto videoState = VideoState::instance();
|
|
QOpenGLFramebufferObject *fbo = videoState->fbo();
|
|
struct retro_system_av_info *avInfo = videoState->avInfo();
|
|
|
|
if(m_core->isHWRender()) {
|
|
if(fbo && fbo->isValid()) {
|
|
r = QRect(rect().topLeft(), QSize(avInfo->geometry.base_width, avInfo->geometry.base_height));
|
|
}
|
|
}else{
|
|
p.fillRect(QRect(QPoint(0, 0), size()), Qt::black);
|
|
|
|
if(!img->isNull()) {
|
|
r = QRect(rect().topLeft(), img->size());
|
|
}
|
|
}
|
|
|
|
// integer scaling
|
|
float device_aspect = width() / (float)height();
|
|
float desired_aspect = videoState->aspect();
|
|
|
|
r.setWidth(videoState->baseWidth() * (height() / videoState->baseHeight()));
|
|
r.setHeight(videoState->baseHeight() * (height() / videoState->baseHeight()));
|
|
|
|
r.moveCenter(rect().center());
|
|
|
|
if(r.width() == 0)
|
|
r.setWidth(avInfo->geometry.base_width);
|
|
if(r.height() == 0)
|
|
r.setHeight(avInfo->geometry.base_height);
|
|
|
|
videoState->setAspectCorrectedRect(r);
|
|
|
|
if(!m_core->isHWRender()) {
|
|
if(!img->isNull()) {
|
|
p.drawImage(videoState->aspectCorrectedRect(), *img);
|
|
}
|
|
}
|
|
}
|
|
|
|
void MainWindow::initializeGL() {
|
|
std::cout << "initializeGL" << std::endl;
|
|
|
|
initializeOpenGLFunctions();
|
|
|
|
VideoState::instance()->setContext(context());
|
|
|
|
const unsigned char *renderer = glGetString(GL_RENDERER);
|
|
const unsigned char *version = glGetString(GL_VERSION);
|
|
|
|
std::cout << "OpenGL Renderer: " << renderer << " " << version << std::endl;
|
|
}
|
|
|
|
void MainWindow::paintGL() {
|
|
//std::cout << "paintGL" << std::endl;
|
|
|
|
static bool inited = false;
|
|
|
|
if(!inited) {
|
|
std::cout << "init" << std::endl;
|
|
inited = true;
|
|
go();
|
|
}
|
|
|
|
if(m_core->isHWRender()) {
|
|
m_core->blitFBO();
|
|
}
|
|
}
|
|
|
|
void MainWindow::resizeGL(int width, int height) {
|
|
std::cout << "resized window to " << width << "x" << height << std::endl;
|
|
}
|
|
|
|
void MainWindow::setFullScreen(bool on) {
|
|
if(on) {
|
|
showFullScreen();
|
|
}else{
|
|
showNormal();
|
|
}
|
|
}
|
|
|