Cycles: Expose image image extension mapping to the image manager
[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,
59                       void *builtin_data,
60                       bool animated,
61                       float frame,
62                       bool& is_float,
63                       bool& is_linear,
64                       InterpolationType interpolation,
65                       ExtensionType extension,
66                       bool use_alpha);
67         void remove_image(int slot);
68         void remove_image(const string& filename,
69                           void *builtin_data,
70                           InterpolationType interpolation,
71                           ExtensionType extension);
72         void tag_reload_image(const string& filename,
73                               void *builtin_data,
74                               InterpolationType interpolation,
75                               ExtensionType extension);
76         bool is_float_image(const string& filename, void *builtin_data, bool& is_linear);
77
78         void device_update(Device *device, DeviceScene *dscene, Progress& progress);
79         void device_update_slot(Device *device, DeviceScene *dscene, int slot, Progress *progress);
80         void device_free(Device *device, DeviceScene *dscene);
81         void device_free_builtin(Device *device, DeviceScene *dscene);
82
83         void set_osl_texture_system(void *texture_system);
84         void set_pack_images(bool pack_images_);
85         void set_extended_image_limits(const DeviceInfo& info);
86         bool set_animation_frame_update(int frame);
87
88         bool need_update;
89
90         function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
91         function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
92         function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
93
94         struct Image {
95                 string filename;
96                 void *builtin_data;
97
98                 bool use_alpha;
99                 bool need_load;
100                 bool animated;
101                 float frame;
102                 InterpolationType interpolation;
103                 ExtensionType extension;
104
105                 int users;
106         };
107
108 private:
109         int tex_num_images;
110         int tex_num_float_images;
111         int tex_image_byte_start;
112         thread_mutex device_mutex;
113         int animation_frame;
114
115         vector<Image*> images;
116         vector<Image*> float_images;
117         void *osl_texture_system;
118         bool pack_images;
119
120         bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
121         bool file_load_float_image(Image *img, device_vector<float4>& tex_img);
122
123         void device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progess);
124         void device_free_image(Device *device, DeviceScene *dscene, int slot);
125
126         void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
127 };
128
129 CCL_NAMESPACE_END
130
131 #endif /* __IMAGE_H__ */
132