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
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/gpu/intern/gpu_texture.c')
-rw-r--r--source/blender/gpu/intern/gpu_texture.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c
index 4bb26128aa2..aac75014b3e 100644
--- a/source/blender/gpu/intern/gpu_texture.c
+++ b/source/blender/gpu/intern/gpu_texture.c
@@ -79,6 +79,7 @@ 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;
@@ -672,24 +673,42 @@ GPUTexture *GPU_texture_create_buffer(GPUTextureFormat data_type, const GLuint b
return tex;
}
-GPUTexture *GPU_texture_from_bindcode(int textarget, int bindcode)
+GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget, bool is_data, double UNUSED(time), int mipmap)
{
+ 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("Invalid bindcode in GPU_texture_from_bindcode");
+ GPU_print_error_debug("Blender Texture Not Loaded");
}
else {
GLint w, h;
@@ -706,9 +725,10 @@ GPUTexture *GPU_texture_from_bindcode(int textarget, int bindcode)
glGetTexLevelParameteriv(gettarget, 0, GL_TEXTURE_HEIGHT, &h);
tex->w = w;
tex->h = h;
- glBindTexture(textarget, 0);
}
+ glBindTexture(textarget, 0);
+
return tex;
}
@@ -1070,6 +1090,9 @@ 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);