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);
}
if (1) {
// if (video_focus_dim && !(SDL_GetWindowFlags(window) & SDL_WINDOW_INPUT_FOCUS)) {
#if 0
if (0) {
struct shader_pass *pass = &active_shader->fs_color;
GLfloat r = 0;
GLfloat g = 0;
GLfloat b = 0;
GLfloat a = 0x80 / (float) 0xff;
if (monitors[r_monitor_index].mon_screenshots) {
int width = destination.width() * devicePixelRatio(), height = destination.height() * devicePixelRatio();
char path[1024];
char fn[256];
GLfloat colors[] = { r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a };
memset(fn, 0, sizeof(fn));
memset(path, 0, sizeof(path));
glw.glBindVertexArray(pass->vertex_array);
path_append_filename(path, usr_path, SCREENSHOT_PATH);
glw.glBindBuffer(GL_ARRAY_BUFFER, pass->vbo.color);
glw.glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(GLfloat), colors);
glw.glBindBuffer(GL_ARRAY_BUFFER, 0);
if (!plat_dir_check(path))
plat_dir_create(path);
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;
path_slash(path);
strcat(path, "Monitor_");
snprintf(&path[strlen(path)], 42, "%d_", r_monitor_index + 1);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
render_pass(&data);
glDisable(GL_BLEND);
}
plat_tempfile(fn, NULL, (char*)".png");
strcat(path, fn);
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;
unsigned char *rgba = (unsigned char *)calloc(1, width * height * 4);
GLfloat colors[] = {r, g, b, a, r, g, b, a, r, g, b, a, r, g, b, a};
glw.glFinish();
glw.glReadPixels(window_rect.x, window_rect.y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, rgba);
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);
QImage image(rgba, width, height, QImage::Format_RGBA8888);
image.mirrored(false, true).save(path, "png");
monitors[r_monitor_index].mon_screenshots--;
free(rgba);
#endif
}
glw.glDisable(GL_FRAMEBUFFER_SRGB);

View File

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

View File

@@ -63,6 +63,7 @@ RendererStack::RendererStack(QWidget *parent, int monitor_index)
: QStackedWidget(parent)
, ui(new Ui::RendererStack)
{
rendererTakesScreenshots = false;
#ifdef Q_OS_WINDOWS
int raw = 1;
#else
@@ -305,6 +306,7 @@ RendererStack::switchRenderer(Renderer renderer)
void
RendererStack::createRenderer(Renderer renderer)
{
rendererTakesScreenshots = false;
switch (renderer) {
default:
case Renderer::Software:
@@ -360,6 +362,7 @@ RendererStack::createRenderer(Renderer renderer)
case Renderer::OpenGL3:
{
this->createWinId();
this->rendererTakesScreenshots = true;
auto hw = new OpenGLRenderer(this);
rendererWindow = hw;
connect(this, &RendererStack::blitToRenderer, hw, &OpenGLRenderer::onBlit, Qt::QueuedConnection);
@@ -424,6 +427,8 @@ RendererStack::createRenderer(Renderer renderer)
this->setStyleSheet("background-color: black");
rendererWindow->r_monitor_index = m_monitor_index;
currentBuf = 0;
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);
}
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_blit_complete_monitor(m_monitor_index);

View File

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