diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 12 | ||||
-rw-r--r-- | source/blender/gpu/GPU_texture.h | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_texture.c | 29 |
3 files changed, 34 insertions, 10 deletions
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index bfc48f839da..f3e8ba9cbea 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -2509,16 +2509,8 @@ void DRW_framebuffer_select_id_release(ARegion *ar) /* Read a block of pixels from the select frame buffer. */ void DRW_framebuffer_select_id_read(const rcti *rect, uint *r_buf) { - DRW_opengl_context_enable(); - GPU_framebuffer_bind(g_select_buffer.framebuffer_select_id); - glReadBuffer(GL_COLOR_ATTACHMENT0); - - glReadPixels(rect->xmin, rect->ymin, - BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), - GL_RED_INTEGER, GL_UNSIGNED_INT, r_buf); - - GPU_framebuffer_restore(); - DRW_opengl_context_disable(); + GPU_texture_read_rect( + g_select_buffer.texture_u32, GPU_DATA_UNSIGNED_INT, rect, r_buf); } /** \} */ diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h index e596fe9256e..18cf3dc4ced 100644 --- a/source/blender/gpu/GPU_texture.h +++ b/source/blender/gpu/GPU_texture.h @@ -185,6 +185,9 @@ void GPU_texture_update_sub( int offset_x, int offset_y, int offset_z, int width, int height, int depth); void *GPU_texture_read(GPUTexture *tex, eGPUDataFormat gpu_data_format, int miplvl); +void GPU_texture_read_rect( + GPUTexture *tex, eGPUDataFormat gpu_data_format, + const struct rcti *rect, void *r_buf); void GPU_invalid_tex_init(void); void GPU_invalid_tex_bind(int mode); diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c index ebb7b4bc0f0..e2aa26c3b33 100644 --- a/source/blender/gpu/intern/gpu_texture.c +++ b/source/blender/gpu/intern/gpu_texture.c @@ -1266,6 +1266,35 @@ void *GPU_texture_read(GPUTexture *tex, eGPUDataFormat gpu_data_format, int mipl return buf; } +void GPU_texture_read_rect( + GPUTexture *tex, eGPUDataFormat gpu_data_format, + const rcti *rect, void *r_buf) +{ + gpu_validate_data_format(tex->format, gpu_data_format); + + GPUFrameBuffer *cur_fb = GPU_framebuffer_active_get(); + GPUFrameBuffer *tmp_fb = GPU_framebuffer_create(); + GPU_framebuffer_texture_attach(tmp_fb, tex, 0, 0); + + GPU_framebuffer_bind(tmp_fb); + glReadBuffer(GL_COLOR_ATTACHMENT0); + + GLenum data_format = gpu_get_gl_dataformat(tex->format, &tex->format_flag); + GLenum data_type = gpu_get_gl_datatype(gpu_data_format); + + glReadPixels(rect->xmin, rect->ymin, + BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), + data_format, data_type, r_buf); + + if (cur_fb) { + GPU_framebuffer_bind(cur_fb); + } + else { + GPU_framebuffer_restore(); + } + GPU_framebuffer_free(tmp_fb); +} + void GPU_texture_update(GPUTexture *tex, eGPUDataFormat data_format, const void *pixels) { GPU_texture_update_sub(tex, data_format, pixels, 0, 0, 0, tex->w, tex->h, tex->d); |