GPU: add offscreen buffer drawing utility functions.

This commit is contained in:
2018-02-13 18:18:04 +01:00
parent e9b1163162
commit 6e040b045a
9 changed files with 64 additions and 25 deletions

View File

@@ -641,7 +641,7 @@ struct GPUOffScreen {
GPUTexture *depth;
};
GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, bool high_bitdepth, char err_out[256])
GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, bool depth, bool high_bitdepth, char err_out[256])
{
GPUOffScreen *ofs;
@@ -663,15 +663,17 @@ GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, bool high
}
}
ofs->depth = GPU_texture_create_depth_with_stencil_multisample(width, height, samples, err_out);
if (!ofs->depth) {
GPU_offscreen_free(ofs);
return NULL;
}
if (depth) {
ofs->depth = GPU_texture_create_depth_with_stencil_multisample(width, height, samples, err_out);
if (!ofs->depth) {
GPU_offscreen_free(ofs);
return NULL;
}
if (!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth, 0, 0)) {
GPU_offscreen_free(ofs);
return NULL;
if (!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth, 0, 0)) {
GPU_offscreen_free(ofs);
return NULL;
}
}
if (high_bitdepth) {
@@ -731,6 +733,24 @@ void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore)
glEnable(GL_SCISSOR_TEST);
}
void GPU_offscreen_blit(GPUOffScreen *ofs, int x, int y)
{
const int w = GPU_texture_width(ofs->color);
const int h = GPU_texture_height(ofs->color);
glBindFramebuffer(GL_READ_FRAMEBUFFER, ofs->fb->object);
GLenum status = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER);
if (status == GL_FRAMEBUFFER_COMPLETE) {
glBlitFramebuffer(0, 0, w, h, x, y, x + w, y + h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
else {
gpu_print_framebuffer_error(status, NULL);
}
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
}
void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
{
const int w = GPU_texture_width(ofs->color);
@@ -818,9 +838,9 @@ int GPU_offscreen_height(const GPUOffScreen *ofs)
return GPU_texture_height(ofs->color);
}
int GPU_offscreen_color_texture(const GPUOffScreen *ofs)
GPUTexture *GPU_offscreen_color_texture(const GPUOffScreen *ofs)
{
return GPU_texture_opengl_bindcode(ofs->color);
return ofs->color;
}
/* only to be used by viewport code! */