OpenGL 3.x screenshots are now processed

This commit is contained in:
Cacodemon345
2025-03-10 23:02:18 +06:00
parent daf6e242ef
commit df1f739b90
4 changed files with 39 additions and 88 deletions

View File

@@ -1612,95 +1612,35 @@ OpenGLRenderer::render()
render_pass(&data); render_pass(&data);
} }
if (1) { if (monitors[r_monitor_index].mon_screenshots) {
// if (video_focus_dim && !(SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS)) { int width = destination.width() * devicePixelRatio(), height = destination.height() * devicePixelRatio();
#if 0 char path[1024];
if (0) { char fn[256];
struct shader_pass *pass = &active_shader->fs_color;
GLfloat r = 0; memset(fn, 0, sizeof(fn));
GLfloat g = 0; memset(path, 0, sizeof(path));
GLfloat b = 0;
GLfloat a = 0x80 / (float) 0xff; path_append_filename(path, usr_path, SCREENSHOT_PATH);
if (!plat_dir_check(path))
plat_dir_create(path);
path_slash(path);
strcat(path, "Monitor_");
snprintf(&path[strlen(path)], 42, "%d_", r_monitor_index + 1);
plat_tempfile(fn, NULL, (char*)".png");
strcat(path, fn);
GLfloat colors[] = { r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a }; unsigned char *rgba = (unsigned char *)calloc(1, width * height * 4);
glw.glFinish();
glw.glReadPixels(window_rect.x, window_rect.y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgba);
glw.glBindVertexArray(pass->vertex_array); QImage image(rgba, width, height, QImage::Format_RGBA8888);
image.mirrored(false, true).save(path, "png");
glw.glBindBuffer(GL_ARRAY_BUFFER, pass->vbo.color); monitors[r_monitor_index].mon_screenshots--;
glw.glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(GLfloat), colors); free(rgba);
glw.glBindBuffer(GL_ARRAY_BUFFER, 0);
memset(&data, 0, sizeof(struct render_data));
data.pass = -3;
data.shader_pass = pass;
data.texture = 0;
data.output_size = orig_output_size;
data.orig_pass = orig;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
render_pass(&data);
glDisable(GL_BLEND);
}
if (flash.enabled) {
struct shader_pass *pass = &active_shader->fs_color;
GLfloat r = (flash.color[0] & 0xff) / (float)0xff;
GLfloat g = (flash.color[1] & 0xff) / (float)0xff;
GLfloat b = (flash.color[2] & 0xff) / (float)0xff;
GLfloat a = (flash.color[3] & 0xff) / (float)0xff;
GLfloat colors[] = {r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a};
glw.glBindVertexArray(pass->vertex_array);
glw.glBindBuffer(GL_ARRAY_BUFFER, pass->vbo.color);
glw.glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(GLfloat), colors);
glw.glBindBuffer(GL_ARRAY_BUFFER, 0);
memset(&data, 0, sizeof(struct render_data));
data.pass = -3;
data.shader_pass = pass;
data.texture = 0;
data.output_size = orig_output_size;
data.orig_pass = orig;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
render_pass(&data);
glDisable(GL_BLEND);
}
#endif
} else {
#if 0
take_screenshot = 0;
int width = window_rect.w;
int height = window_rect.h;
SDL_GetWindowSize(window, &width, &height);
unsigned char *rgba = (unsigned char *)malloc(width * height * 4);
glFinish();
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgba);
int x, y;
unsigned char *rgb = (unsigned char *)malloc(width * height * 3);
for (x = 0; x < width; ++x) {
for (y = 0; y < height; ++y) {
rgb[(y * width + x) * 3 + 0] = rgba[((height - y - 1) * width + x) * 4 + 0];
rgb[(y * width + x) * 3 + 1] = rgba[((height - y - 1) * width + x) * 4 + 1];
rgb[(y * width + x) * 3 + 2] = rgba[((height - y - 1) * width + x) * 4 + 2];
}
}
screenshot_taken(rgb, width, height);
free(rgb);
free(rgba);
#endif
} }
glw.glDisable(GL_FRAMEBUFFER_SRGB); glw.glDisable(GL_FRAMEBUFFER_SRGB);

View File

@@ -36,6 +36,8 @@ public:
virtual void reloadOptions() { } virtual void reloadOptions() { }
/* Make the renderer reload itself */ /* Make the renderer reload itself */
virtual bool reloadRendererOption() { return false; } virtual bool reloadRendererOption() { return false; }
/* Should the renderer take screenshots itself? */
virtual bool rendererTakeScreenshot() { return false; }
int r_monitor_index = 0; int r_monitor_index = 0;

View File

@@ -63,6 +63,7 @@ RendererStack::RendererStack(QWidget *parent, int monitor_index)
: QStackedWidget(parent) : QStackedWidget(parent)
, ui(new Ui::RendererStack) , ui(new Ui::RendererStack)
{ {
rendererTakesScreenshots = false;
#ifdef Q_OS_WINDOWS #ifdef Q_OS_WINDOWS
int raw = 1; int raw = 1;
#else #else
@@ -305,6 +306,7 @@ RendererStack::switchRenderer(Renderer renderer)
void void
RendererStack::createRenderer(Renderer renderer) RendererStack::createRenderer(Renderer renderer)
{ {
rendererTakesScreenshots = false;
switch (renderer) { switch (renderer) {
default: default:
case Renderer::Software: case Renderer::Software:
@@ -360,6 +362,7 @@ RendererStack::createRenderer(Renderer renderer)
case Renderer::OpenGL3: case Renderer::OpenGL3:
{ {
this->createWinId(); this->createWinId();
this->rendererTakesScreenshots = true;
auto hw = new OpenGLRenderer(this); auto hw = new OpenGLRenderer(this);
rendererWindow = hw; rendererWindow = hw;
connect(this, &RendererStack::blitToRenderer, hw, &OpenGLRenderer::onBlit, Qt::QueuedConnection); connect(this, &RendererStack::blitToRenderer, hw, &OpenGLRenderer::onBlit, Qt::QueuedConnection);
@@ -424,6 +427,8 @@ RendererStack::createRenderer(Renderer renderer)
this->setStyleSheet("background-color: black"); this->setStyleSheet("background-color: black");
rendererWindow->r_monitor_index = m_monitor_index;
currentBuf = 0; currentBuf = 0;
if (renderer != Renderer::OpenGL3 && renderer != Renderer::Vulkan && renderer != Renderer::OpenGL3PCem) { if (renderer != Renderer::OpenGL3 && renderer != Renderer::Vulkan && renderer != Renderer::OpenGL3PCem) {
@@ -454,7 +459,7 @@ RendererStack::blit(int x, int y, int w, int h)
video_copy(scanline, &(monitors[m_monitor_index].target_buffer->line[y1][x]), w * 4); video_copy(scanline, &(monitors[m_monitor_index].target_buffer->line[y1][x]), w * 4);
} }
if (monitors[m_monitor_index].mon_screenshots) { if (monitors[m_monitor_index].mon_screenshots && !rendererTakesScreenshots) {
video_screenshot_monitor((uint32_t *) imagebits, x, y, 2048, m_monitor_index); video_screenshot_monitor((uint32_t *) imagebits, x, y, 2048, m_monitor_index);
} }
video_blit_complete_monitor(m_monitor_index); video_blit_complete_monitor(m_monitor_index);

View File

@@ -15,6 +15,8 @@
#include "qt_renderercommon.hpp" #include "qt_renderercommon.hpp"
#include <atomic>
namespace Ui { namespace Ui {
class RendererStack; class RendererStack;
} }
@@ -110,6 +112,8 @@ private:
RendererCommon *rendererWindow { nullptr }; RendererCommon *rendererWindow { nullptr };
std::unique_ptr<QWidget> current; std::unique_ptr<QWidget> current;
std::atomic_bool rendererTakesScreenshots;
}; };
#endif // QT_RENDERERCONTAINER_HPP #endif // QT_RENDERERCONTAINER_HPP