Merged revision(s) 57828-57907 from trunk/blender into soc-2013-dingto
[blender-staging.git] / intern / cycles / render / image.h
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #ifndef __IMAGE_H__
20 #define __IMAGE_H__
21
22 #include "device.h"
23 #include "device_memory.h"
24
25 #include "util_string.h"
26 #include "util_thread.h"
27 #include "util_vector.h"
28
29 #include "kernel_types.h"  /* for TEX_NUM_FLOAT_IMAGES */
30
31 CCL_NAMESPACE_BEGIN
32
33 /* Normal Image amount */
34 #define TEX_NUM_IMAGES                  95
35 #define TEX_IMAGE_BYTE_START    TEX_NUM_FLOAT_IMAGES
36
37 /* Extended Image amount*/
38 #define TEX_EXTENDED_NUM_FLOAT_IMAGES   5
39 #define TEX_EXTENDED_IMAGE_BYTE_START   TEX_EXTENDED_NUM_FLOAT_IMAGES
40 #define TEX_EXTENDED_NUM_IMAGES_CPU             512
41 #define TEX_EXTENDED_NUM_IMAGES_GPU             145
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, bool& is_float, bool& is_linear);
59         void remove_image(const string& filename, void *builtin_data);
60         bool is_float_image(const string& filename, void *builtin_data, bool& is_linear);
61
62         void device_update(Device *device, DeviceScene *dscene, Progress& progress);
63         void device_free(Device *device, DeviceScene *dscene);
64
65         void set_osl_texture_system(void *texture_system);
66         void set_pack_images(bool pack_images_);
67         void set_extended_image_limits(const DeviceInfo& info);
68         bool set_animation_frame_update(int frame);
69
70         bool need_update;
71
72         boost::function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &channels)> builtin_image_info_cb;
73         boost::function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
74         boost::function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
75 private:
76         int tex_num_images;
77         int tex_num_float_images;
78         int tex_image_byte_start;
79         thread_mutex device_mutex;
80         int animation_frame;
81
82         struct Image {
83                 string filename;
84                 void *builtin_data;
85
86                 bool need_load;
87                 bool animated;
88                 int users;
89         };
90
91         vector<Image*> images;
92         vector<Image*> float_images;
93         void *osl_texture_system;
94         bool pack_images;
95
96         bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
97         bool file_load_float_image(Image *img, device_vector<float4>& tex_img);
98
99         void device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progess);
100         void device_free_image(Device *device, DeviceScene *dscene, int slot);
101
102         void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
103 };
104
105 CCL_NAMESPACE_END
106
107 #endif /* __IMAGE_H__ */
108