Cycles / Sky Texture:
[blender-staging.git] / intern / cycles / render / image.h
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16
17 #ifndef __IMAGE_H__
18 #define __IMAGE_H__
19
20 #include "device_memory.h"
21
22 #include "util_string.h"
23 #include "util_thread.h"
24 #include "util_vector.h"
25
26 #include "kernel_types.h"  /* for TEX_NUM_FLOAT_IMAGES */
27
28 CCL_NAMESPACE_BEGIN
29
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, void *builtin_data, bool animated, bool& is_float, bool& is_linear);
53         void remove_image(const string& filename, void *builtin_data);
54         bool is_float_image(const string& filename, void *builtin_data, bool& is_linear);
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         void set_extended_image_limits(void);
62         bool set_animation_frame_update(int frame);
63
64         bool need_update;
65
66         boost::function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &channels)> builtin_image_info_cb;
67         boost::function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
68         boost::function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
69 private:
70         int tex_num_images;
71         int tex_num_float_images;
72         int tex_image_byte_start;
73         thread_mutex device_mutex;
74         int animation_frame;
75
76         struct Image {
77                 string filename;
78                 void *builtin_data;
79
80                 bool need_load;
81                 bool animated;
82                 int users;
83         };
84
85         vector<Image*> images;
86         vector<Image*> float_images;
87         void *osl_texture_system;
88         bool pack_images;
89
90         bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
91         bool file_load_float_image(Image *img, device_vector<float4>& tex_img);
92
93         void device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progess);
94         void device_free_image(Device *device, DeviceScene *dscene, int slot);
95
96         void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
97 };
98
99 CCL_NAMESPACE_END
100
101 #endif /* __IMAGE_H__ */
102