Fix T41109: Reloading image that has been modified outside Blender does not update...
[blender-staging.git] / intern / cycles / render / image.h
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16
17 #ifndef __IMAGE_H__
18 #define __IMAGE_H__
19
20 #include "device.h"
21 #include "device_memory.h"
22
23 #include "util_string.h"
24 #include "util_thread.h"
25 #include "util_vector.h"
26
27 #include "kernel_types.h"  /* for TEX_NUM_FLOAT_IMAGES */
28
29 CCL_NAMESPACE_BEGIN
30
31 /* generic */
32 #define TEX_NUM_IMAGES                  94
33 #define TEX_IMAGE_BYTE_START    TEX_NUM_FLOAT_IMAGES
34
35 /* extended gpu */
36 #define TEX_EXTENDED_NUM_IMAGES_GPU             145
37
38 /* extended cpu */
39 #define TEX_EXTENDED_NUM_FLOAT_IMAGES   1024
40 #define TEX_EXTENDED_NUM_IMAGES_CPU             1024
41 #define TEX_EXTENDED_IMAGE_BYTE_START   TEX_EXTENDED_NUM_FLOAT_IMAGES
42
43 /* color to use when textures are not found */
44 #define TEX_IMAGE_MISSING_R 1
45 #define TEX_IMAGE_MISSING_G 0
46 #define TEX_IMAGE_MISSING_B 1
47 #define TEX_IMAGE_MISSING_A 1
48
49 class Device;
50 class DeviceScene;
51 class Progress;
52
53 class ImageManager {
54 public:
55         ImageManager();
56         ~ImageManager();
57
58         int add_image(const string& filename, void *builtin_data, bool animated, float frame,
59                 bool& is_float, bool& is_linear, InterpolationType interpolation, bool use_alpha);
60         void remove_image(int slot);
61         void remove_image(const string& filename, void *builtin_data, InterpolationType interpolation);
62         void tag_reload_image(const string& filename, void *builtin_data, InterpolationType interpolation);
63         bool is_float_image(const string& filename, void *builtin_data, bool& is_linear);
64
65         void device_update(Device *device, DeviceScene *dscene, Progress& progress);
66         void device_free(Device *device, DeviceScene *dscene);
67         void device_free_builtin(Device *device, DeviceScene *dscene);
68
69         void set_osl_texture_system(void *texture_system);
70         void set_pack_images(bool pack_images_);
71         void set_extended_image_limits(const DeviceInfo& info);
72         bool set_animation_frame_update(int frame);
73
74         bool need_update;
75
76         boost::function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
77         boost::function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
78         boost::function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
79
80         struct Image {
81                 string filename;
82                 void *builtin_data;
83
84                 bool use_alpha;
85                 bool need_load;
86                 bool animated;
87                 float frame;
88                 InterpolationType interpolation;
89
90                 int users;
91         };
92
93 private:
94         int tex_num_images;
95         int tex_num_float_images;
96         int tex_image_byte_start;
97         thread_mutex device_mutex;
98         int animation_frame;
99
100         vector<Image*> images;
101         vector<Image*> float_images;
102         void *osl_texture_system;
103         bool pack_images;
104
105         bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
106         bool file_load_float_image(Image *img, device_vector<float4>& tex_img);
107
108         void device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progess);
109         void device_free_image(Device *device, DeviceScene *dscene, int slot);
110
111         void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
112 };
113
114 CCL_NAMESPACE_END
115
116 #endif /* __IMAGE_H__ */
117