Creating a BGE staging branch.
[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, void *builtin_data, bool animated, bool& is_float, bool& is_linear);
55         void remove_image(const string& filename, void *builtin_data);
56         bool is_float_image(const string& filename, void *builtin_data, bool& is_linear);
57
58         void device_update(Device *device, DeviceScene *dscene, Progress& progress);
59         void device_free(Device *device, DeviceScene *dscene);
60
61         void set_osl_texture_system(void *texture_system);
62         void set_pack_images(bool pack_images_);
63         void set_extended_image_limits(void);
64         bool set_animation_frame_update(int frame);
65
66         bool need_update;
67
68         boost::function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &channels)> builtin_image_info_cb;
69         boost::function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
70         boost::function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
71 private:
72         int tex_num_images;
73         int tex_num_float_images;
74         int tex_image_byte_start;
75         thread_mutex device_mutex;
76         int animation_frame;
77
78         struct Image {
79                 string filename;
80                 void *builtin_data;
81
82                 bool need_load;
83                 bool animated;
84                 int users;
85         };
86
87         vector<Image*> images;
88         vector<Image*> float_images;
89         void *osl_texture_system;
90         bool pack_images;
91
92         bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
93         bool file_load_float_image(Image *img, device_vector<float4>& tex_img);
94
95         void device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progess);
96         void device_free_image(Device *device, DeviceScene *dscene, int slot);
97
98         void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
99 };
100
101 CCL_NAMESPACE_END
102
103 #endif /* __IMAGE_H__ */
104