From 1dc93f90a003e0b8fa723994101a93dd1a41e0fa Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Mon, 11 Jun 2018 22:30:59 +0200 Subject: Cleanup: remove image->bindcode, always wrap in GPUTexture. This simplifies code, and will hopefully make UDIM usage of GPUTexture a little easier. --- source/blender/makesrna/intern/rna_image.c | 10 ++++++++- source/blender/makesrna/intern/rna_image_api.c | 28 ++++++++++++++------------ 2 files changed, 24 insertions(+), 14 deletions(-) (limited to 'source/blender/makesrna') diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index cf486ee399f..5736643ab0e 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -67,6 +67,7 @@ static const EnumPropertyItem image_source_items[] = { #include "BKE_global.h" #include "GPU_draw.h" +#include "GPU_texture.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" @@ -298,6 +299,13 @@ static void rna_Image_resolution_set(PointerRNA *ptr, const float *values) BKE_image_release_ibuf(im, ibuf, lock); } +static int rna_Image_bindcode_get(PointerRNA *ptr) +{ + Image *ima = (Image *)ptr->data; + GPUTexture *tex = ima->gputexture[TEXTARGET_TEXTURE_2D]; + return (tex) ? GPU_texture_opengl_bindcode(tex) : 0; +} + static int rna_Image_depth_get(PointerRNA *ptr) { Image *im = (Image *)ptr->data; @@ -796,7 +804,7 @@ static void rna_def_image(BlenderRNA *brna) RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL); prop = RNA_def_property(srna, "bindcode", PROP_INT, PROP_UNSIGNED); - RNA_def_property_int_sdna(prop, NULL, "bindcode"); + RNA_def_property_int_funcs(prop, "rna_Image_bindcode_get", NULL, NULL); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Bindcode", "OpenGL bindcode"); RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL); diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c index 39164430140..d839995d15e 100644 --- a/source/blender/makesrna/intern/rna_image_api.c +++ b/source/blender/makesrna/intern/rna_image_api.c @@ -220,29 +220,30 @@ static void rna_Image_scale(Image *image, ReportList *reports, int width, int he static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int filter, int mag) { - ImBuf *ibuf; - unsigned int *bind = &image->bindcode[TEXTARGET_TEXTURE_2D]; + GPUTexture *tex = image->gputexture[TEXTARGET_TEXTURE_2D]; int error = GL_NO_ERROR; - ImageUser iuser = {NULL}; - void *lock; - if (*bind) + if (tex) return error; + + ImageUser iuser = {NULL}; iuser.framenr = frame; iuser.ok = true; - ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock); + void *lock; + ImBuf *ibuf = BKE_image_acquire_ibuf(image, &iuser, &lock); /* clean glError buffer */ while (glGetError() != GL_NO_ERROR) {} if (ibuf == NULL || ibuf->rect == NULL) { BKE_reportf(reports, RPT_ERROR, "Image '%s' does not have any image data", image->id.name + 2); - BKE_image_release_ibuf(image, ibuf, NULL); + BKE_image_release_ibuf(image, ibuf, lock); return (int)GL_INVALID_OPERATION; } - GPU_create_gl_tex(bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, GL_TEXTURE_2D, + unsigned int bindcode = 0; + GPU_create_gl_tex(&bindcode, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, GL_TEXTURE_2D, (filter != GL_NEAREST && filter != GL_LINEAR), false, image); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLint)filter); @@ -253,23 +254,24 @@ static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int f error = glGetError(); if (error) { - glDeleteTextures(1, (GLuint *)bind); - image->bindcode[TEXTARGET_TEXTURE_2D] = 0; + glDeleteTextures(1, (GLuint *)&bindcode); + } + else { + image->gputexture[TEXTARGET_TEXTURE_2D] = GPU_texture_from_bindcode(GL_TEXTURE_2D, bindcode); } - BKE_image_release_ibuf(image, ibuf, NULL); + BKE_image_release_ibuf(image, ibuf, lock); return error; } static int rna_Image_gl_touch(Image *image, ReportList *reports, int frame, int filter, int mag) { - unsigned int *bind = &image->bindcode[TEXTARGET_TEXTURE_2D]; int error = GL_NO_ERROR; BKE_image_tag_time(image); - if (*bind == 0) + if (image->gputexture[TEXTARGET_TEXTURE_2D] == NULL) error = rna_Image_gl_load(image, reports, frame, filter, mag); return error; -- cgit v1.2.3