Cycles: Synchronize images after building mesh BVH
[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_update_slot(Device *device, DeviceScene *dscene, int slot, Progress *progress);
67         void device_free(Device *device, DeviceScene *dscene);
68         void device_free_builtin(Device *device, DeviceScene *dscene);
69
70         void set_osl_texture_system(void *texture_system);
71         void set_pack_images(bool pack_images_);
72         void set_extended_image_limits(const DeviceInfo& info);
73         bool set_animation_frame_update(int frame);
74
75         bool need_update;
76
77         function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
78         function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
79         function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
80
81         struct Image {
82                 string filename;
83                 void *builtin_data;
84
85                 bool use_alpha;
86                 bool need_load;
87                 bool animated;
88                 float frame;
89                 InterpolationType interpolation;
90
91                 int users;
92         };
93
94 private:
95         int tex_num_images;
96         int tex_num_float_images;
97         int tex_image_byte_start;
98         thread_mutex device_mutex;
99         int animation_frame;
100
101         vector<Image*> images;
102         vector<Image*> float_images;
103         void *osl_texture_system;
104         bool pack_images;
105
106         bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
107         bool file_load_float_image(Image *img, device_vector<float4>& tex_img);
108
109         void device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progess);
110         void device_free_image(Device *device, DeviceScene *dscene, int slot);
111
112         void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
113 };
114
115 CCL_NAMESPACE_END
116
117 #endif /* __IMAGE_H__ */
118