Let's not try reading screenshots from the front buffer.

It was broken in fullscreen, at least on my system
This commit is contained in:
Andrei Alexeyev 2018-08-30 14:58:58 +03:00
parent 9669fb6df9
commit db3cb2bd03
No known key found for this signature in database
GPG key ID: 363707CD4C7FE8A4
4 changed files with 4 additions and 17 deletions

View file

@ -165,6 +165,7 @@ begin_frame:
if((!uncapped_rendering && frame_num % get_effective_frameskip()) || global.is_replay_verification) {
rframe_action = RFRAME_DROP;
} else {
r_clear(CLEAR_ALL);
rframe_action = render_frame(arg);
fpscounter_update(&global.fps.render);

View file

@ -218,6 +218,7 @@ static void gl33_init_context(SDL_Window *window) {
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadBuffer(GL_BACK);
glGetIntegerv(GL_VIEWPORT, &R.viewport.default_framebuffer.x);
R.viewport.active = R.viewport.default_framebuffer;
@ -417,7 +418,7 @@ static inline GLuint fbo_num(Framebuffer *fb) {
void gl33_sync_framebuffer(void) {
if(fbo_num(R.framebuffer.active) != fbo_num(R.framebuffer.pending)) {
glBindFramebuffer(GL_FRAMEBUFFER, fbo_num(R.framebuffer.pending));
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_num(R.framebuffer.pending));
R.framebuffer.active = R.framebuffer.pending;
}
@ -848,25 +849,11 @@ static DepthTestFunc gl33_depth_func_current(void) {
}
static uint8_t* gl33_screenshot(uint *out_width, uint *out_height) {
uint fbo = 0;
IntRect *vp = &R.viewport.default_framebuffer;
if(R.framebuffer.active != NULL) {
fbo = R.framebuffer.active->impl->gl_fbo;
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
}
uint8_t *pixels = malloc(vp->w * vp->h * 3);
glReadBuffer(GL_FRONT);
glReadPixels(vp->x, vp->y, vp->w, vp->h, GL_RGB, GL_UNSIGNED_BYTE, pixels);
*out_width = vp->w;
*out_height = vp->h;
if(fbo != 0) {
// FIXME: Maybe we should only ever bind FBOs to GL_DRAW_FRAMEBUFFER?
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
}
return pixels;
}

View file

@ -39,7 +39,7 @@ void gl33_framebuffer_attach(Framebuffer *framebuffer, Texture *tex, uint mipmap
r_framebuffer(framebuffer);
gl33_sync_framebuffer();
glFramebufferTexture2D(GL_FRAMEBUFFER, r_attachment_to_gl_attachment[attachment], GL_TEXTURE_2D, gl_tex, mipmap);
glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, r_attachment_to_gl_attachment[attachment], GL_TEXTURE_2D, gl_tex, mipmap);
r_framebuffer(prev_fb);
framebuffer->impl->attachments[attachment] = tex;

View file

@ -526,5 +526,4 @@ void video_shutdown(void) {
void video_swap_buffers(void) {
r_framebuffer(NULL);
r_swap(video.window);
r_clear(CLEAR_COLOR);
}