Fix T65386 Eevee: Crash after baking indirect lights or cubemap
[blender.git] / source / blender / editors / include / BIF_glutil.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) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup editorui
22  */
23
24 #ifndef __BIF_GLUTIL_H__
25 #define __BIF_GLUTIL_H__
26
27 struct rctf;
28 struct rcti;
29
30 struct ColorManagedDisplaySettings;
31 struct ColorManagedViewSettings;
32 struct ImBuf;
33 struct bContext;
34
35 typedef struct IMMDrawPixelsTexState {
36   struct GPUShader *shader;
37   unsigned int pos;
38   unsigned int texco;
39   bool do_shader_unbind;
40 } IMMDrawPixelsTexState;
41
42 /* To be used before calling immDrawPixelsTex
43  * Default shader is GPU_SHADER_2D_IMAGE_COLOR
44  * Returns a shader to be able to set uniforms */
45 IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin);
46
47 /**
48  * immDrawPixelsTex - Functions like a limited glDrawPixels, but actually draws the
49  * image using textures, which can be tremendously faster on low-end
50  * cards, and also avoids problems with the raster position being
51  * clipped when offscreen. Pixel unpacking parameters and
52  * the glPixelZoom values are _not_ respected.
53  *
54  * \attention Use immDrawPixelsTexSetup before calling this function.
55  *
56  * \attention This routine makes many assumptions: the rect data
57  * is expected to be in RGBA byte or float format, and the
58  * modelview and projection matrices are assumed to define a
59  * 1-to-1 mapping to screen space.
60  */
61 void immDrawPixelsTex(IMMDrawPixelsTexState *state,
62                       float x,
63                       float y,
64                       int img_w,
65                       int img_h,
66                       int format,
67                       int type,
68                       int zoomfilter,
69                       void *rect,
70                       float xzoom,
71                       float yzoom,
72                       float color[4]);
73 void immDrawPixelsTex_clipping(IMMDrawPixelsTexState *state,
74                                float x,
75                                float y,
76                                int img_w,
77                                int img_h,
78                                int format,
79                                int type,
80                                int zoomfilter,
81                                void *rect,
82                                float clip_min_x,
83                                float clip_min_y,
84                                float clip_max_x,
85                                float clip_max_y,
86                                float xzoom,
87                                float yzoom,
88                                float color[4]);
89 void immDrawPixelsTexScaled(IMMDrawPixelsTexState *state,
90                             float x,
91                             float y,
92                             int img_w,
93                             int img_h,
94                             int format,
95                             int type,
96                             int zoomfilter,
97                             void *rect,
98                             float scaleX,
99                             float scaleY,
100                             float xzoom,
101                             float yzoom,
102                             float color[4]);
103 void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state,
104                                      float x,
105                                      float y,
106                                      int img_w,
107                                      int img_h,
108                                      int format,
109                                      int type,
110                                      int zoomfilter,
111                                      void *rect,
112                                      float scaleX,
113                                      float scaleY,
114                                      float clip_min_x,
115                                      float clip_min_y,
116                                      float clip_max_x,
117                                      float clip_max_y,
118                                      float xzoom,
119                                      float yzoom,
120                                      float color[4]);
121
122 /* Image buffer drawing functions, with display transform
123  *
124  * The view and display settings can either be specified manually,
125  * or retrieved from the context with the '_ctx' variations.
126  *
127  * For better performance clipping coordinates can be specified so parts of the
128  * image outside the view are skipped. */
129
130 void ED_draw_imbuf(struct ImBuf *ibuf,
131                    float x,
132                    float y,
133                    int zoomfilter,
134                    struct ColorManagedViewSettings *view_settings,
135                    struct ColorManagedDisplaySettings *display_settings,
136                    float zoom_x,
137                    float zoom_y);
138 void ED_draw_imbuf_clipping(struct ImBuf *ibuf,
139                             float x,
140                             float y,
141                             int zoomfilter,
142                             struct ColorManagedViewSettings *view_settings,
143                             struct ColorManagedDisplaySettings *display_settings,
144                             float clip_min_x,
145                             float clip_min_y,
146                             float clip_max_x,
147                             float clip_max_y,
148                             float zoom_x,
149                             float zoom_y);
150
151 void ED_draw_imbuf_ctx(const struct bContext *C,
152                        struct ImBuf *ibuf,
153                        float x,
154                        float y,
155                        int zoomfilter,
156                        float zoom_x,
157                        float zoom_y);
158 void ED_draw_imbuf_ctx_clipping(const struct bContext *C,
159                                 struct ImBuf *ibuf,
160                                 float x,
161                                 float y,
162                                 int zoomfilter,
163                                 float clip_min_x,
164                                 float clip_min_y,
165                                 float clip_max_x,
166                                 float clip_max_y,
167                                 float zoom_x,
168                                 float zoom_y);
169
170 int ED_draw_imbuf_method(struct ImBuf *ibuf);
171
172 /* OpenGL drawing utility functions. Do not use these in new code, these
173  * are intended to be moved or removed in the future. */
174
175 /* own working polygon offset */
176 float bglPolygonOffsetCalc(const float winmat[16], float viewdist, float dist);
177 void bglPolygonOffset(float viewdist, float dist);
178
179 void immDrawBorderCorners(unsigned int pos, const struct rcti *border, float zoomx, float zoomy);
180
181 #endif /* __BIF_GLUTIL_H__ */