From faeaf5325554e37981424ded5add7bf2df484c55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Fri, 17 Jul 2020 16:41:02 +0200 Subject: Cleanup: Sequencer: Use GPUTexture instead of opengl calls --- .../editors/space_sequencer/sequencer_draw.c | 59 ++++++++++------------ 1 file changed, 26 insertions(+), 33 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 310204a4dae..995e980aba0 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -1450,8 +1450,11 @@ static void seq_prefetch_wm_notify(const bContext *C, Scene *scene) } } -static void *sequencer_OCIO_transform_ibuf( - const bContext *C, ImBuf *ibuf, bool *r_glsl_used, int *r_format, int *r_type) +static void *sequencer_OCIO_transform_ibuf(const bContext *C, + ImBuf *ibuf, + bool *r_glsl_used, + eGPUTextureFormat *r_format, + eGPUDataFormat *r_data) { void *display_buffer; void *cache_handle = NULL; @@ -1460,30 +1463,32 @@ static void *sequencer_OCIO_transform_ibuf( force_fallback |= (ED_draw_imbuf_method(ibuf) != IMAGE_DRAW_METHOD_GLSL); force_fallback |= (ibuf->dither != 0.0f); + /* Default */ + *r_format = GPU_RGBA8; + *r_data = GPU_DATA_UNSIGNED_BYTE; + /* Fallback to CPU based color space conversion. */ if (force_fallback) { *r_glsl_used = false; - *r_format = GL_RGBA; - *r_type = GL_UNSIGNED_BYTE; display_buffer = NULL; } else if (ibuf->rect_float) { display_buffer = ibuf->rect_float; + *r_data = GPU_DATA_FLOAT; if (ibuf->channels == 4) { - *r_format = GL_RGBA; + *r_format = GPU_RGBA16F; } else if (ibuf->channels == 3) { - *r_format = GL_RGB; + /* Alpha is implicitly 1. */ + *r_format = GPU_RGB16F; } else { BLI_assert(!"Incompatible number of channels for float buffer in sequencer"); - *r_format = GL_RGBA; + *r_format = GPU_RGBA16F; display_buffer = NULL; } - *r_type = GL_FLOAT; - if (ibuf->float_colorspace) { *r_glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx( C, ibuf->float_colorspace, ibuf->dither, true); @@ -1494,15 +1499,11 @@ static void *sequencer_OCIO_transform_ibuf( } else if (ibuf->rect) { display_buffer = ibuf->rect; - *r_format = GL_RGBA; - *r_type = GL_UNSIGNED_BYTE; *r_glsl_used = IMB_colormanagement_setup_glsl_draw_from_space_ctx( C, ibuf->rect_colorspace, ibuf->dither, false); } else { - *r_format = GL_RGBA; - *r_type = GL_UNSIGNED_BYTE; display_buffer = NULL; } @@ -1510,8 +1511,6 @@ static void *sequencer_OCIO_transform_ibuf( * properly, in this case we fallback to CPU-based display transform. */ if ((ibuf->rect || ibuf->rect_float) && !*r_glsl_used) { display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle); - *r_format = GL_RGBA; - *r_type = GL_UNSIGNED_BYTE; } if (cache_handle) { IMB_display_buffer_release(cache_handle); @@ -1602,9 +1601,9 @@ static void sequencer_draw_display_buffer(const bContext *C, /* Format needs to be created prior to any immBindProgram call. * Do it here because OCIO binds it's own shader. */ - int format, type; + eGPUTextureFormat format; + eGPUDataFormat data; bool glsl_used = false; - GLuint texid; GPUVertFormat *imm_format = immVertexFormat(); uint pos = GPU_vertformat_attr_add(imm_format, "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); uint texCoord = GPU_vertformat_attr_add( @@ -1618,11 +1617,11 @@ static void sequencer_draw_display_buffer(const bContext *C, } display_buffer = (uchar *)ibuf->rect; - format = GL_RGBA; - type = GL_UNSIGNED_BYTE; + format = GPU_RGBA8; + data = GPU_DATA_UNSIGNED_BYTE; } else { - display_buffer = sequencer_OCIO_transform_ibuf(C, ibuf, &glsl_used, &format, &type); + display_buffer = sequencer_OCIO_transform_ibuf(C, ibuf, &glsl_used, &format, &data); } if (draw_backdrop) { @@ -1632,18 +1631,11 @@ static void sequencer_draw_display_buffer(const bContext *C, GPU_matrix_identity_projection_set(); } - glGenTextures(1, (GLuint *)&texid); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, texid); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + GPUTexture *texture = GPU_texture_create_nD( + ibuf->x, ibuf->y, 0, 2, display_buffer, format, data, 0, false, NULL); + GPU_texture_filter_mode(texture, false); - if (type == GL_FLOAT) { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, ibuf->x, ibuf->y, 0, format, type, display_buffer); - } - else { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, format, type, display_buffer); - } + GPU_texture_bind(texture, 0); if (!glsl_used) { immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR); @@ -1677,8 +1669,9 @@ static void sequencer_draw_display_buffer(const bContext *C, immVertex2f(pos, preview.xmax, preview.ymin); immEnd(); - glBindTexture(GL_TEXTURE_2D, 0); - glDeleteTextures(1, &texid); + + GPU_texture_unbind(texture); + GPU_texture_free(texture); if (!glsl_used) { immUnbindProgram(); -- cgit v1.2.3