Cycles / CUDA: Increase maximum image textures on GPU.
[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.h"
21 #include "device_memory.h"
22
23 #include "util_string.h"
24 #include "util_thread.h"
25 #include "util_vector.h"
26
27 #include "kernel_types.h"  /* for TEX_NUM_FLOAT_IMAGES */
28
29 CCL_NAMESPACE_BEGIN
30
31 /* generic */
32 #define TEX_NUM_IMAGES                  95
33 #define TEX_IMAGE_BYTE_START    TEX_NUM_FLOAT_IMAGES
34
35 /* extended gpu */
36 #define TEX_EXTENDED_NUM_IMAGES_GPU             145
37
38 /* extended cpu */
39 #define TEX_EXTENDED_NUM_FLOAT_IMAGES   1024
40 #define TEX_EXTENDED_NUM_IMAGES_CPU             1024
41 #define TEX_EXTENDED_IMAGE_BYTE_START   TEX_EXTENDED_NUM_FLOAT_IMAGES
42
43 /* color to use when textures are not found */
44 #define TEX_IMAGE_MISSING_R 1
45 #define TEX_IMAGE_MISSING_G 0
46 #define TEX_IMAGE_MISSING_B 1
47 #define TEX_IMAGE_MISSING_A 1
48
49 class Device;
50 class DeviceScene;
51 class Progress;
52
53 class ImageManager {
54 public:
55         ImageManager();
56         ~ImageManager();
57
58         int add_image(const string& filename, void *builtin_data, bool animated, bool& is_float, bool& is_linear, InterpolationType interpolation, bool use_alpha);
59         void remove_image(int slot);
60         void remove_image(const string& filename, void *builtin_data, InterpolationType interpolation);
61         bool is_float_image(const string& filename, void *builtin_data, bool& is_linear);
62
63         void device_update(Device *device, DeviceScene *dscene, Progress& progress);
64         void device_free(Device *device, DeviceScene *dscene);
65
66         void set_osl_texture_system(void *texture_system);
67         void set_pack_images(bool pack_images_);
68         void set_extended_image_limits(const DeviceInfo& info);
69         bool set_animation_frame_update(int frame);
70
71         bool need_update;
72
73         boost::function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
74         boost::function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
75         boost::function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
76
77         struct Image {
78                 string filename;
79                 void *builtin_data;
80
81                 bool use_alpha;
82                 bool need_load;
83                 bool animated;
84                 InterpolationType interpolation;
85
86                 int users;
87         };
88
89 private:
90         int tex_num_images;
91         int tex_num_float_images;
92         int tex_image_byte_start;
93         thread_mutex device_mutex;
94         int animation_frame;
95
96         vector<Image*> images;
97         vector<Image*> float_images;
98         void *osl_texture_system;
99         bool pack_images;
100
101         bool file_load_image(Image *img, device_vector<uchar4>& tex_img);
102         bool file_load_float_image(Image *img, device_vector<float4>& tex_img);
103
104         void device_load_image(Device *device, DeviceScene *dscene, int slot, Progress *progess);
105         void device_free_image(Device *device, DeviceScene *dscene, int slot);
106
107         void device_pack_images(Device *device, DeviceScene *dscene, Progress& progess);
108 };
109
110 CCL_NAMESPACE_END
111
112 #endif /* __IMAGE_H__ */
113