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