Cleanup: remove redundant doxygen \file argument
[blender.git] / source / blender / blenkernel / BKE_studiolight.h
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2006-2007 Blender Foundation.
17  * All rights reserved.
18  */
19
20 #ifndef __BKE_STUDIOLIGHT_H__
21 #define __BKE_STUDIOLIGHT_H__
22
23 /** \file \ingroup bke
24  *
25  * Studio lighting for the 3dview
26  */
27
28 #include "BKE_context.h"
29
30 #include "BLI_sys_types.h"
31
32 #include "DNA_space_types.h"
33 #include "DNA_userdef_types.h"
34
35 #include "IMB_imbuf_types.h"
36
37 /*
38  * These defines are the indexes in the StudioLight.diffuse_light
39  * X_POS means the light that is traveling towards the positive X
40  * So Light direction.
41  */
42 #define STUDIOLIGHT_X_POS 0
43 #define STUDIOLIGHT_X_NEG 1
44 #define STUDIOLIGHT_Y_POS 2
45 #define STUDIOLIGHT_Y_NEG 3
46 #define STUDIOLIGHT_Z_POS 4
47 #define STUDIOLIGHT_Z_NEG 5
48
49 #define STUDIOLIGHT_ICON_ID_TYPE_RADIANCE       (1 << 0)
50 #define STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE     (1 << 1)
51 #define STUDIOLIGHT_ICON_ID_TYPE_MATCAP         (1 << 2)
52 #define STUDIOLIGHT_ICON_ID_TYPE_MATCAP_FLIPPED (1 << 3)
53
54 #define STUDIOLIGHT_MAX_LIGHT 4
55
56 #define STUDIOLIGHT_ICON_SIZE 96
57
58 /* Only 1 - 5 is supported */
59 #define STUDIOLIGHT_SH_BANDS 2
60
61 #define STUDIOLIGHT_SH_COEFS_LEN (STUDIOLIGHT_SH_BANDS * STUDIOLIGHT_SH_BANDS)
62
63 #if STUDIOLIGHT_SH_BANDS > 3
64 /* Bypass L3 */
65 #define STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN (STUDIOLIGHT_SH_COEFS_LEN - 7)
66 #else
67 #define STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN STUDIOLIGHT_SH_COEFS_LEN
68 #endif
69
70 struct GPUTexture;
71 struct StudioLight;
72
73 /* StudioLight.flag */
74 enum StudioLightFlag {
75         STUDIOLIGHT_SPHERICAL_HARMONICS_COEFFICIENTS_CALCULATED = (1 << 0),
76 /*      STUDIOLIGHT_LIGHT_DIRECTION_CALCULATED                  = (1 << 1), */
77         STUDIOLIGHT_INTERNAL                                    = (1 << 2),
78         STUDIOLIGHT_EXTERNAL_FILE                               = (1 << 3),
79         STUDIOLIGHT_TYPE_STUDIO                                 = (1 << 4),
80         STUDIOLIGHT_TYPE_WORLD                                  = (1 << 5),
81         STUDIOLIGHT_TYPE_MATCAP                                 = (1 << 6),
82         STUDIOLIGHT_EXTERNAL_IMAGE_LOADED                       = (1 << 7),
83         STUDIOLIGHT_EQUIRECT_IRRADIANCE_IMAGE_CALCULATED        = (1 << 8),
84         STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE                = (1 << 9),
85         STUDIOLIGHT_EQUIRECT_IRRADIANCE_GPUTEXTURE              = (1 << 10),
86         STUDIOLIGHT_RADIANCE_BUFFERS_CALCULATED                 = (1 << 11),
87         STUDIOLIGHT_USER_DEFINED                                = (1 << 12),
88         STUDIOLIGHT_UI_EXPANDED                                 = (1 << 13),
89 };
90
91 #define STUDIOLIGHT_FLAG_ALL (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_EXTERNAL_FILE)
92 #define STUDIOLIGHT_FLAG_ORIENTATIONS (STUDIOLIGHT_TYPE_STUDIO | STUDIOLIGHT_TYPE_WORLD | STUDIOLIGHT_TYPE_MATCAP)
93 #define STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE (STUDIOLIGHT_TYPE_WORLD)
94 #define STUDIOLIGHT_ORIENTATIONS_SOLID (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_TYPE_STUDIO)
95
96 typedef void StudioLightFreeFunction(struct StudioLight *, void *data);
97
98 typedef struct StudioLight {
99         struct StudioLight *next, *prev;
100
101         int index;
102         int flag;
103         char name[FILE_MAXFILE];
104         char path[FILE_MAX];
105         char *path_irr_cache;
106         char *path_sh_cache;
107         int icon_id_irradiance;
108         int icon_id_radiance;
109         int icon_id_matcap;
110         int icon_id_matcap_flipped;
111         float spherical_harmonics_coefs[STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN][3];
112         float light_direction[3];
113         ImBuf *equirect_radiance_buffer;
114         ImBuf *equirect_irradiance_buffer;
115         ImBuf *radiance_cubemap_buffers[6];
116         struct GPUTexture *equirect_radiance_gputexture;
117         struct GPUTexture *equirect_irradiance_gputexture;
118         SolidLight light[STUDIOLIGHT_MAX_LIGHT];
119         float light_ambient[3];
120
121         /*
122          * Free function to clean up the running icons previews (wmJob) the usage is in
123          * interface_icons. Please be aware that this was build to handle only one free function
124          * that cleans up all icons. just to keep the code simple.
125          */
126         StudioLightFreeFunction *free_function;
127         void *free_function_data;
128 } StudioLight;
129
130 void BKE_studiolight_init(void);
131 void BKE_studiolight_free(void);
132 struct StudioLight *BKE_studiolight_find(const char *name, int flag);
133 struct StudioLight *BKE_studiolight_findindex(int index, int flag);
134 struct StudioLight *BKE_studiolight_find_default(int flag);
135 void BKE_studiolight_preview(uint *icon_buffer, StudioLight *sl, int icon_id_type);
136 struct ListBase *BKE_studiolight_listbase(void);
137 void BKE_studiolight_ensure_flag(StudioLight *sl, int flag);
138 void BKE_studiolight_refresh(void);
139 StudioLight *BKE_studiolight_load(const char *path, int orientation);
140 StudioLight *BKE_studiolight_create(const char *path, const SolidLight light[4], const float light_ambient[3]);
141 StudioLight *BKE_studiolight_studio_edit_get(void);
142 void BKE_studiolight_remove(StudioLight *sl);
143 void BKE_studiolight_set_free_function(StudioLight *sl, StudioLightFreeFunction *free_function, void *data);
144 void BKE_studiolight_unset_icon_id(StudioLight *sl, int icon_id);
145
146 #endif /*  __BKE_STUDIOLIGHT_H__ */