Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@gmail.com>2018-06-11 23:30:59 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2018-06-11 23:30:59 +0300
commit8242a5bc853a74da1273fc7ad4b959ac716c563c (patch)
tree82f930c68a2dd6b665e775a98685e6fcae5d662d /source
parent0054dff67eb5262aabb1a0ee1f70641859044e65 (diff)
Cleanup: remove image->bindcode, always wrap in GPUTexture.
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/BKE_image.h2
-rw-r--r--source/blender/blenkernel/intern/image.c26
-rw-r--r--source/blender/blenloader/intern/readfile.c2
-rw-r--r--source/blender/gpu/GPU_texture.h1
-rw-r--r--source/blender/gpu/intern/gpu_draw.c164
-rw-r--r--source/blender/gpu/intern/gpu_texture.c29
-rw-r--r--source/blender/makesdna/DNA_image_types.h1
-rw-r--r--source/blender/makesrna/intern/rna_image.c9
-rw-r--r--source/blender/makesrna/intern/rna_image_api.c26
9 files changed, 104 insertions, 156 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index fc018dbfe81..546204b5eef 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -271,7 +271,7 @@ bool BKE_image_scale(struct Image *image, int width, int height);
bool BKE_image_has_alpha(struct Image *image);
/* check if texture has gpu texture code */
-bool BKE_image_has_bindcode(struct Image *ima);
+bool BKE_image_has_opengl_texture(struct Image *ima);
void BKE_image_get_size(struct Image *image, struct ImageUser *iuser, int *width, int *height);
void BKE_image_get_size_fl(struct Image *image, struct ImageUser *iuser, float size[2]);
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index c1ecabcfb5a..b6b3dd31096 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -473,7 +473,6 @@ void BKE_image_copy_data(Main *UNUSED(bmain), Image *ima_dst, const Image *ima_s
BLI_listbase_clear(&ima_dst->anims);
for (int i = 0; i < TEXTARGET_COUNT; i++) {
- ima_dst->bindcode[i] = 0;
ima_dst->gputexture[i] = NULL;
}
@@ -538,16 +537,14 @@ bool BKE_image_scale(Image *image, int width, int height)
return (ibuf != NULL);
}
-bool BKE_image_has_bindcode(Image *ima)
+bool BKE_image_has_opengl_texture(Image *ima)
{
- bool has_bindcode = false;
for (int i = 0; i < TEXTARGET_COUNT; i++) {
- if (ima->bindcode[i]) {
- has_bindcode = true;
- break;
+ if (ima->gputexture[i]) {
+ return true;
}
}
- return has_bindcode;
+ return false;
}
static void image_init_color_management(Image *ima)
@@ -930,21 +927,6 @@ void BKE_image_tag_time(Image *ima)
ima->lastused = PIL_check_seconds_timer_i();
}
-#if 0
-static void tag_all_images_time(Main *bmain)
-{
- Image *ima;
- int ctime = PIL_check_seconds_timer_i();
-
- ima = bmain->image.first;
- while (ima) {
- if (ima->bindcode || ima->repbind || ima->ibufs.first) {
- ima->lastused = ctime;
- }
- }
-}
-#endif
-
static uintptr_t image_mem_size(Image *image)
{
uintptr_t size = 0;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 039af3cfa61..8807cbc1d21 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1681,7 +1681,6 @@ void blo_end_image_pointer_map(FileData *fd, Main *oldmain)
if (ima->cache == NULL) {
ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
for (i = 0; i < TEXTARGET_COUNT; i++) {
- ima->bindcode[i] = 0;
ima->gputexture[i] = NULL;
}
ima->rr = NULL;
@@ -3916,7 +3915,6 @@ static void direct_link_image(FileData *fd, Image *ima)
if (!ima->cache) {
ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
for (int i = 0; i < TEXTARGET_COUNT; i++) {
- ima->bindcode[i] = 0;
ima->gputexture[i] = NULL;
}
ima->rr = NULL;
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index 09b351a544a..e58d5d92831 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -161,6 +161,7 @@ GPUTexture *GPU_texture_create_from_vertbuf(
GPUTexture *GPU_texture_create_buffer(
GPUTextureFormat data_type, const uint buffer);
+GPUTexture *GPU_texture_from_bindcode(int textarget, int bindcode);
GPUTexture *GPU_texture_from_blender(
struct Image *ima, struct ImageUser *iuser, int textarget, bool is_data, double time, int mipmap);
GPUTexture *GPU_texture_from_preview(struct PreviewImage *prv, int mipmap);
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 7bfebb702a1..0c9832f20b3 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -127,8 +127,6 @@ static int smaller_power_of_2_limit(int num)
/* Current OpenGL state caching for GPU_set_tpage */
static struct GPUTextureState {
- Image *ima, *curima;
-
/* also controls min/mag filtering */
bool domipmap;
/* only use when 'domipmap' is set */
@@ -136,10 +134,9 @@ static struct GPUTextureState {
/* store this so that new images created while texture painting won't be set to mipmapped */
bool texpaint;
- int alphablend;
float anisotropic;
int gpu_mipmap;
-} GTS = {NULL, NULL, 1, 0, 0, -1, 1.0f, 0};
+} GTS = {1, 0, 0, 1.0f, 0};
/* Mipmap settings */
@@ -227,16 +224,14 @@ float GPU_get_anisotropic(void)
/* Set OpenGL state for an MTFace */
-static unsigned int *gpu_get_image_bindcode(Image *ima, GLenum textarget)
+static GPUTexture **gpu_get_image_gputexture(Image *ima, GLenum textarget)
{
- unsigned int *bind = 0;
-
if (textarget == GL_TEXTURE_2D)
- bind = &ima->bindcode[TEXTARGET_TEXTURE_2D];
+ return &ima->gputexture[TEXTARGET_TEXTURE_2D];
else if (textarget == GL_TEXTURE_CUBE_MAP)
- bind = &ima->bindcode[TEXTARGET_TEXTURE_CUBE_MAP];
+ return &ima->gputexture[TEXTARGET_TEXTURE_CUBE_MAP];
- return bind;
+ return NULL;
}
typedef struct VerifyThreadData {
@@ -289,33 +284,38 @@ static void gpu_verify_high_bit_srgb_buffer(float *srgb_frect,
}
}
-int GPU_verify_image(
- Image *ima, ImageUser *iuser,
- int textarget, bool compare, bool mipmap, bool is_data)
+GPUTexture *GPU_texture_from_blender(Image *ima,
+ ImageUser *iuser,
+ int textarget,
+ bool is_data,
+ double UNUSED(time),
+ int mipmap)
{
- unsigned int *bind = NULL;
- int tpx = 0, tpy = 0;
- unsigned int *rect = NULL;
- float *frect = NULL;
- float *srgb_frect = NULL;
- /* flag to determine whether deep format is used */
- bool use_high_bit_depth = false, do_color_management = false;
-
- GTS.ima = ima;
+ /* check if we have a valid image */
+ if (ima == NULL || ima->ok == 0) {
+ return NULL;
+ }
- if (compare && ima == GTS.curima) {
- return (ima != NULL);
+ /* currently, tpage refresh is used by ima sequences */
+ if (ima->tpageflag & IMA_TPAGE_REFRESH) {
+ GPU_free_image(ima);
+ ima->tpageflag &= ~IMA_TPAGE_REFRESH;
}
- /* check if we have a valid image */
- if (ima == NULL || ima->ok == 0)
- return 0;
+ /* Test if we already have a texture. */
+ GPUTexture **tex = gpu_get_image_gputexture(ima, textarget);
+ if (*tex) {
+ return *tex;
+ }
/* check if we have a valid image buffer */
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
+ if (ibuf == NULL) {
+ return NULL;
+ }
- if (ibuf == NULL)
- return 0;
+ /* flag to determine whether deep format is used */
+ bool use_high_bit_depth = false, do_color_management = false;
if (ibuf->rect_float) {
if (U.use_16bit_textures) {
@@ -337,54 +337,38 @@ int GPU_verify_image(
}
}
- /* currently, tpage refresh is used by ima sequences */
- if (ima->tpageflag & IMA_TPAGE_REFRESH) {
- GPU_free_image(ima);
- ima->tpageflag &= ~IMA_TPAGE_REFRESH;
- }
+ const int rectw = ibuf->x;
+ const int recth = ibuf->y;
+ unsigned int *rect = ibuf->rect;
+ float *frect = NULL;
+ float *srgb_frect = NULL;
- {
- /* regular image mode */
- bind = gpu_get_image_bindcode(ima, textarget);
-
- if (*bind == 0) {
- tpx = ibuf->x;
- tpy = ibuf->y;
- rect = ibuf->rect;
- if (use_high_bit_depth) {
- if (do_color_management) {
- frect = srgb_frect = MEM_mallocN(ibuf->x * ibuf->y * sizeof(*srgb_frect) * 4, "floar_buf_col_cor");
- gpu_verify_high_bit_srgb_buffer(srgb_frect, ibuf);
- }
- else
- frect = ibuf->rect_float;
- }
+ if (use_high_bit_depth) {
+ if (do_color_management) {
+ frect = srgb_frect = MEM_mallocN(ibuf->x * ibuf->y * sizeof(*srgb_frect) * 4, "floar_buf_col_cor");
+ gpu_verify_high_bit_srgb_buffer(srgb_frect, ibuf);
+ }
+ else {
+ frect = ibuf->rect_float;
}
}
- if (*bind != 0) {
- /* enable opengl drawing with textures */
- glBindTexture(textarget, *bind);
- BKE_image_release_ibuf(ima, ibuf, NULL);
- return *bind;
- }
-
- const int rectw = tpx;
- const int recth = tpy;
-
+ unsigned int bindcode = 0;
#ifdef WITH_DDS
if (ibuf->ftype == IMB_FTYPE_DDS)
- GPU_create_gl_tex_compressed(bind, rect, rectw, recth, textarget, mipmap, ima, ibuf);
+ GPU_create_gl_tex_compressed(&bindcode, rect, rectw, recth, textarget, mipmap, ima, ibuf);
else
#endif
- GPU_create_gl_tex(bind, rect, frect, rectw, recth, textarget, mipmap, use_high_bit_depth, ima);
+ GPU_create_gl_tex(&bindcode, rect, frect, rectw, recth, textarget, mipmap, use_high_bit_depth, ima);
/* mark as non-color data texture */
- if (*bind) {
+ if (bindcode) {
if (is_data)
ima->tpageflag |= IMA_GLBIND_IS_DATA;
else
ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
+
+ *tex = GPU_texture_from_bindcode(textarget, bindcode);
}
/* clean up */
@@ -393,7 +377,7 @@ int GPU_verify_image(
BKE_image_release_ibuf(ima, ibuf, NULL);
- return *bind;
+ return *tex;
}
static void **gpu_gen_cube_map(unsigned int *rect, float *frect, int rectw, int recth, bool use_high_bit_depth)
@@ -594,6 +578,8 @@ void GPU_create_gl_tex(
if (GLEW_EXT_texture_filter_anisotropic)
glTexParameterf(textarget, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
+ glBindTexture(textarget, 0);
+
if (ibuf)
IMB_freeImBuf(ibuf);
}
@@ -680,6 +666,8 @@ void GPU_create_gl_tex_compressed(
glDeleteTextures(1, (GLuint *)bind);
GPU_create_gl_tex(bind, pix, NULL, x, y, textarget, mipmap, 0, ima);
}
+
+ glBindTexture(textarget, 0);
#endif
}
@@ -696,17 +684,13 @@ void GPU_paint_set_mipmap(bool mipmap)
if (mipmap) {
for (Image *ima = G.main->image.first; ima; ima = ima->id.next) {
- if (BKE_image_has_bindcode(ima)) {
+ if (BKE_image_has_opengl_texture(ima)) {
if (ima->tpageflag & IMA_MIPMAP_COMPLETE) {
- if (ima->bindcode[TEXTARGET_TEXTURE_2D]) {
- glBindTexture(GL_TEXTURE_2D, ima->bindcode[TEXTARGET_TEXTURE_2D]);
+ if (ima->gputexture[TEXTARGET_TEXTURE_2D]) {
+ GPU_texture_bind(ima->gputexture[TEXTARGET_TEXTURE_2D], 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
- }
- if (ima->bindcode[TEXTARGET_TEXTURE_CUBE_MAP]) {
- glBindTexture(GL_TEXTURE_CUBE_MAP, ima->bindcode[TEXTARGET_TEXTURE_CUBE_MAP]);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, gpu_get_mipmap_filter(0));
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
+ GPU_texture_unbind(ima->gputexture[TEXTARGET_TEXTURE_2D]);
}
}
else
@@ -719,16 +703,12 @@ void GPU_paint_set_mipmap(bool mipmap)
}
else {
for (Image *ima = G.main->image.first; ima; ima = ima->id.next) {
- if (BKE_image_has_bindcode(ima)) {
- if (ima->bindcode[TEXTARGET_TEXTURE_2D]) {
- glBindTexture(GL_TEXTURE_2D, ima->bindcode[TEXTARGET_TEXTURE_2D]);
+ if (BKE_image_has_opengl_texture(ima)) {
+ if (ima->gputexture[TEXTARGET_TEXTURE_2D]) {
+ GPU_texture_bind(ima->gputexture[TEXTARGET_TEXTURE_2D], 0);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
- }
- if (ima->bindcode[TEXTARGET_TEXTURE_CUBE_MAP]) {
- glBindTexture(GL_TEXTURE_CUBE_MAP, ima->bindcode[TEXTARGET_TEXTURE_CUBE_MAP]);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, gpu_get_mipmap_filter(1));
+ GPU_texture_unbind(ima->gputexture[TEXTARGET_TEXTURE_2D]);
}
}
else
@@ -761,12 +741,13 @@ static bool gpu_check_scaled_image(ImBuf *ibuf, Image *ima, float *frect, int x,
if (rectw + x > x_limit) rectw--;
if (recth + y > y_limit) recth--;
+ GPU_texture_bind(ima->gputexture[TEXTARGET_TEXTURE_2D], 0);
+
/* float rectangles are already continuous in memory so we can use IMB_scaleImBuf */
if (frect) {
ImBuf *ibuf_scale = IMB_allocFromBuffer(NULL, frect, w, h);
IMB_scaleImBuf(ibuf_scale, rectw, recth);
- glBindTexture(GL_TEXTURE_2D, ima->bindcode[TEXTARGET_TEXTURE_2D]);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, rectw, recth, GL_RGBA,
GL_FLOAT, ibuf_scale->rect_float);
@@ -786,7 +767,7 @@ static bool gpu_check_scaled_image(ImBuf *ibuf, Image *ima, float *frect, int x,
bilinear_interpolation_color_wrap(ibuf, (unsigned char *)(p + i + j * (rectw)), NULL, u, v);
}
}
- glBindTexture(GL_TEXTURE_2D, ima->bindcode[TEXTARGET_TEXTURE_2D]);
+
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, rectw, recth, GL_RGBA,
GL_UNSIGNED_BYTE, scalerect);
@@ -800,6 +781,8 @@ static bool gpu_check_scaled_image(ImBuf *ibuf, Image *ima, float *frect, int x,
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
}
+ GPU_texture_unbind(ima->gputexture[TEXTARGET_TEXTURE_2D]);
+
return true;
}
@@ -811,7 +794,7 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
if ((!GTS.gpu_mipmap && GPU_get_mipmap()) ||
- (ima->bindcode[TEXTARGET_TEXTURE_2D] == 0) ||
+ (ima->gputexture[TEXTARGET_TEXTURE_2D] == NULL) ||
(ibuf == NULL) ||
(w == 0) || (h == 0))
{
@@ -835,7 +818,7 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
return;
}
- glBindTexture(GL_TEXTURE_2D, ima->bindcode[TEXTARGET_TEXTURE_2D]);
+ GPU_texture_bind(ima->gputexture[TEXTARGET_TEXTURE_2D], 0);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA, GL_FLOAT, buffer);
MEM_freeN(buffer);
@@ -849,6 +832,8 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
}
+ GPU_texture_unbind(ima->gputexture[TEXTARGET_TEXTURE_2D]);
+
BKE_image_release_ibuf(ima, ibuf, NULL);
return;
}
@@ -858,7 +843,7 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
return;
}
- glBindTexture(GL_TEXTURE_2D, ima->bindcode[TEXTARGET_TEXTURE_2D]);
+ GPU_texture_bind(ima->gputexture[TEXTARGET_TEXTURE_2D], 0);
glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length);
glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skip_pixels);
@@ -882,6 +867,8 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
else {
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
}
+
+ GPU_texture_unbind(ima->gputexture[TEXTARGET_TEXTURE_2D]);
}
BKE_image_release_ibuf(ima, ibuf, NULL);
@@ -1016,11 +1003,6 @@ void GPU_free_image(Image *ima)
}
for (int i = 0; i < TEXTARGET_COUNT; i++) {
- /* free regular image binding */
- if (ima->bindcode[i]) {
- glDeleteTextures(1, (GLuint *)&ima->bindcode[i]);
- ima->bindcode[i] = 0;
- }
/* free glsl image binding */
if (ima->gputexture[i]) {
GPU_texture_free(ima->gputexture[i]);
@@ -1071,7 +1053,7 @@ void GPU_free_images_old(void)
if ((ima->flag & IMA_NOCOLLECT) == 0 && ctime - ima->lastused > U.textimeout) {
/* If it's in GL memory, deallocate and set time tag to current time
* This gives textures a "second chance" to be used before dying. */
- if (BKE_image_has_bindcode(ima)) {
+ if (BKE_image_has_opengl_texture(ima)) {
GPU_free_image(ima);
ima->lastused = ctime;
}
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c
index aac75014b3e..4bb26128aa2 100644
--- a/source/blender/gpu/intern/gpu_texture.c
+++ b/source/blender/gpu/intern/gpu_texture.c
@@ -79,7 +79,6 @@ struct GPUTexture {
GLenum target_base; /* same as target, (but no multisample)
* use it for unbinding */
GLuint bindcode; /* opengl identifier for texture */
- int fromblender; /* we got the texture from Blender */
GPUTextureFormat format;
GPUTextureFormatFlag format_flag;
@@ -673,42 +672,24 @@ GPUTexture *GPU_texture_create_buffer(GPUTextureFormat data_type, const GLuint b
return tex;
}
-GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget, bool is_data, double UNUSED(time), int mipmap)
+GPUTexture *GPU_texture_from_bindcode(int textarget, int bindcode)
{
- int gputt;
- /* this binds a texture, so that's why to restore it to 0 */
- GLint bindcode = GPU_verify_image(ima, iuser, textarget, 0, mipmap, is_data);
-
/* see GPUInput::textarget: it can take two values - GL_TEXTURE_2D and GL_TEXTURE_CUBE_MAP
* these values are correct for glDisable, so textarget can be safely used in
* GPU_texture_bind/GPU_texture_unbind through tex->target_base */
/* (is any of this obsolete now that we don't glEnable/Disable textures?) */
- if (textarget == GL_TEXTURE_2D)
- gputt = TEXTARGET_TEXTURE_2D;
- else
- gputt = TEXTARGET_TEXTURE_CUBE_MAP;
-
- if (ima->gputexture[gputt]) {
- ima->gputexture[gputt]->bindcode = bindcode;
- glBindTexture(textarget, 0);
- return ima->gputexture[gputt];
- }
-
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
tex->bindcode = bindcode;
tex->number = -1;
tex->refcount = 1;
tex->target = textarget;
tex->target_base = textarget;
- tex->fromblender = 1;
tex->format = -1;
tex->components = -1;
tex->samples = 0;
- ima->gputexture[gputt] = tex;
-
if (!glIsTexture(tex->bindcode)) {
- GPU_print_error_debug("Blender Texture Not Loaded");
+ GPU_print_error_debug("Invalid bindcode in GPU_texture_from_bindcode");
}
else {
GLint w, h;
@@ -725,10 +706,9 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget
glGetTexLevelParameteriv(gettarget, 0, GL_TEXTURE_HEIGHT, &h);
tex->w = w;
tex->h = h;
+ glBindTexture(textarget, 0);
}
- glBindTexture(textarget, 0);
-
return tex;
}
@@ -1090,9 +1070,6 @@ void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat)
static void gpu_texture_delete(GPUTexture *tex)
{
- if (tex->bindcode && !tex->fromblender)
- glDeleteTextures(1, &tex->bindcode);
-
gpu_texture_memory_footprint_remove(tex);
MEM_freeN(tex);
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index 3d29c5b3833..327b77f12b3 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -118,7 +118,6 @@ typedef struct Image {
/* texture page */
short tpageflag;
short pad2;
- unsigned int bindcode[2]; /* only for current image... 2 = TEXTARGET_COUNT */
unsigned int pad3;
struct PackedFile *packedfile DNA_DEPRECATED; /* deprecated */
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index cf486ee399f..9f6552e4587 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -298,6 +298,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 +803,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..854036cc1dc 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,
+ 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);
@@ -254,22 +255,23 @@ static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int f
if (error) {
glDeleteTextures(1, (GLuint *)bind);
- image->bindcode[TEXTARGET_TEXTURE_2D] = 0;
+ }
+ 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;