GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap) { GPUTexture *tex = prv->gputexture[0]; GLint w, h, lastbindcode; GLuint bindcode = 0; glGetIntegerv(GL_TEXTURE_BINDING_2D, &lastbindcode); if (tex) bindcode = tex->bindcode; /* this binds a texture, so that's why to restore it */ if (bindcode == 0) { GPU_create_gl_tex(&bindcode, prv->rect[0], NULL, prv->w[0], prv->h[0], mipmap, 0, NULL); } if (tex) { tex->bindcode = bindcode; glBindTexture(GL_TEXTURE_2D, lastbindcode); return tex; } /* error binding anything */ if (!bindcode) { glBindTexture(GL_TEXTURE_2D, lastbindcode); return NULL; } tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); tex->bindcode = bindcode; tex->number = -1; tex->refcount = 1; tex->target = GL_TEXTURE_2D; prv->gputexture[0]= tex; if (!glIsTexture(tex->bindcode)) { GPU_print_error("Blender Texture"); } else { glBindTexture(GL_TEXTURE_2D, tex->bindcode); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h); tex->w = w; tex->h = h; } glBindTexture(GL_TEXTURE_2D, lastbindcode); return tex; }
GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap) { GPUTexture *tex = prv->gputexture[0]; GLuint bindcode = 0; if (tex) bindcode = tex->bindcode; /* this binds a texture, so that's why we restore it to 0 */ if (bindcode == 0) { GPU_create_gl_tex(&bindcode, prv->rect[0], NULL, prv->w[0], prv->h[0], GL_TEXTURE_2D, mipmap, 0, NULL); } if (tex) { tex->bindcode = bindcode; glBindTexture(GL_TEXTURE_2D, 0); return tex; } tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture"); tex->bindcode = bindcode; tex->number = -1; tex->refcount = 1; tex->target = GL_TEXTURE_2D; tex->target_base = GL_TEXTURE_2D; prv->gputexture[0] = tex; if (!glIsTexture(tex->bindcode)) { GPU_ASSERT_NO_GL_ERRORS("Blender Texture Not Loaded"); } else { GLint w, h; glBindTexture(GL_TEXTURE_2D, tex->bindcode); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &h); tex->w = w; tex->h = h; } glBindTexture(GL_TEXTURE_2D, 0); return tex; }
static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int filter, int mag) { ImBuf *ibuf; unsigned int *bind = &image->bindcode; int error = GL_NO_ERROR; ImageUser iuser = {NULL}; void *lock; if (*bind) return error; iuser.framenr = frame; iuser.ok = true; 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); return (int)GL_INVALID_OPERATION; } GPU_create_gl_tex(bind, ibuf->rect, ibuf->rect_float, ibuf->x, ibuf->y, (filter != GL_NEAREST && filter != GL_LINEAR), false, image); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLint)filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (GLint)mag); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); error = glGetError(); if (error) { glDeleteTextures(1, (GLuint *)bind); image->bindcode = 0; } BKE_image_release_ibuf(image, ibuf, NULL); return error; }