Image.gl_touch - routine to prevent the image to be cleared by blender cache garbage...
[blender.git] / source / blender / makesrna / intern / rna_image_api.c
index 3d937fc561d760279b5708e928c8836779780039..cf19002f44e5298e964a019c03127a4d22ab7e73 100644 (file)
@@ -224,6 +224,19 @@ static int rna_Image_gl_load(Image *image, ReportList *reports, int filter, int
        return error;
 }
 
+static int rna_Image_gl_touch(Image *image, ReportList *reports, int filter, int mag)
+{
+       unsigned int *bind = &image->bindcode;
+       int error = GL_NO_ERROR;
+
+       BKE_image_tag_time(image);
+
+       if (*bind == 0)
+               error = rna_Image_gl_load(image, reports, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR);
+
+       return error;
+}
+
 static void rna_Image_gl_free(Image *image)
 {
        GPU_free_image(image);
@@ -274,6 +287,17 @@ void RNA_api_image(StructRNA *srna)
        parm = RNA_def_int(func, "height", 0, 1, 10000, "", "Height", 1, 10000);
        RNA_def_property_flag(parm, PROP_REQUIRED);
 
+       func = RNA_def_function(srna, "gl_touch", "rna_Image_gl_touch");
+       RNA_def_function_ui_description(func, "Delay the image from being cleaned from the cache due inactivity");
+       RNA_def_function_flag(func, FUNC_USE_REPORTS);
+       RNA_def_int(func, "filter", GL_LINEAR_MIPMAP_NEAREST, -INT_MAX, INT_MAX, "Filter",
+                   "The texture minifying function to use if the image wan't loaded", -INT_MAX, INT_MAX);
+       RNA_def_int(func, "mag", GL_LINEAR, -INT_MAX, INT_MAX, "Magnification",
+                   "The texture magnification function to use if the image wan't loaded", -INT_MAX, INT_MAX);
+       /* return value */
+       parm = RNA_def_int(func, "error", 0, -INT_MAX, INT_MAX, "Error", "OpenGL error value", -INT_MAX, INT_MAX);
+       RNA_def_function_return(func, parm);
+
        func = RNA_def_function(srna, "gl_load", "rna_Image_gl_load");
        RNA_def_function_ui_description(func, "Load the image into OpenGL graphics memory");
        RNA_def_function_flag(func, FUNC_USE_REPORTS);