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