Cleanup: Sequencer: Use GPUTexture instead of opengl calls
This commit is contained in:
parent
e2305690eb
commit
faeaf53255
Notes:
blender-bot
2023-05-22 12:40:41 +02:00
Referenced by commit 13c7df1054
, Fix T80193 Sequencer: Crash on float images when OCIO GLSL shader can't be used
Referenced by issue #82094, VSE: Alpha Over + Convert to float changes the color of the top layer
Referenced by issue #80193, Sequencer crash on float images when OCIO GLSL shader can't be used
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue