Merging r50172 through r50173 from trunk into soc-2011-tomato
[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_memory.h"
23
24 #include "util_string.h"
25 #include "util_vector.h"
26
27 CCL_NAMESPACE_BEGIN
28
29 #define TEX_NUM_FLOAT_IMAGES    5
30 #define TEX_NUM_IMAGES                  95
31 #define TEX_IMAGE_BYTE_START    TEX_NUM_FLOAT_IMAGES
32
33 #define TEX_EXTENDED_NUM_FLOAT_IMAGES   5
34 #define TEX_EXTENDED_NUM_IMAGES                 512
35 #define TEX_EXTENDED_IMAGE_BYTE_START   TEX_EXTENDED_NUM_FLOAT_IMAGES
36
37 /* color to use when textures are not found */
38 #define TEX_IMAGE_MISSING_R 1
39 #define TEX_IMAGE_MISSING_G 0
40 #define TEX_IMAGE_MISSING_B 1
41 #define TEX_IMAGE_MISSING_A 1
42
43 class Device;
44 class DeviceScene;
45 class Progress;
46
47 class ImageManager {
48 public:
49         ImageManager();
50         ~ImageManager();
51
52         int add_image(const string& filename, bool& is_float);
53         void remove_image(const string& filename);
54
55         void device_update(Device *device, DeviceScene *dscene, Progress& progress);
56         void device_free(Device *device, DeviceScene *dscene);
57
58         void set_osl_texture_system(void *texture_system);
59         void set_pack_images(bool pack_images_);
60
61         void set_extended_image_limits(void);
62
63         bool need_update;
64
65 private:
66         int tex_num_images;
67         int tex_num_float_images;
68         int tex_image_byte_start;
69
70         struct Image {
71                 string filename;
72
73                 bool need_load;
74                 int users;
75         };
76
77         vector<Image*> images;
78         vector<Image*> float_images;
79         void *osl_texture_system;
80         bool pack_images;
81
82         bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
83         bool file_load_float_image(Image *img, device_vector<float4>& tex_img);
84
85         void device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progess);
86         void device_free_image(Device *device, DeviceScene *dscene, int slot);
87
88         void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
89 };
90
91 CCL_NAMESPACE_END
92
93 #endif /* __IMAGE_H__ */
94