2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * Contributor(s): Blender Foundation 2002-2008
23 * ***** END GPL LICENSE BLOCK *****
26 /** \file BIF_glutil.h
30 #ifndef __BIF_GLUTIL_H__
31 #define __BIF_GLUTIL_H__
38 struct ColorManagedViewSettings;
39 struct ColorManagedDisplaySettings;
41 void fdrawbezier(float vec[4][3]);
42 void fdrawline(float x1, float y1, float x2, float y2);
43 void fdrawbox(float x1, float y1, float x2, float y2);
44 void sdrawline(short x1, short y1, short x2, short y2);
45 void sdrawtri(short x1, short y1, short x2, short y2);
46 void sdrawtrifill(short x1, short y1, short x2, short y2);
47 void sdrawbox(short x1, short y1, short x2, short y2);
49 void sdrawXORline(int x0, int y0, int x1, int y1);
50 void sdrawXORline4(int nr, int x0, int y0, int x1, int y1);
52 void fdrawXORellipse(float xofs, float yofs, float hw, float hh);
53 void fdrawXORcirc(float xofs, float yofs, float rad);
55 void fdrawcheckerboard(float x1, float y1, float x2, float y2);
57 /* OpenGL stipple defines */
58 extern const unsigned char stipple_halftone[128];
59 extern const unsigned char stipple_quarttone[128];
60 extern const unsigned char stipple_diag_stripes_pos[128];
61 extern const unsigned char stipple_diag_stripes_neg[128];
64 * Draw a lined (non-looping) arc with the given
65 * \a radius, starting at angle \a start and arcing
66 * through \a angle. The arc is centered at the origin
67 * and drawn in the XY plane.
69 * \param start The initial angle (in radians).
70 * \param angle The length of the arc (in radians).
71 * \param radius The arc radius.
72 * \param nsegments The number of segments to use in drawing the arc.
74 void glutil_draw_lined_arc(float start, float angle, float radius, int nsegments);
77 * Draw a filled arc with the given \a radius,
78 * starting at angle \a start and arcing through
79 * \a angle. The arc is centered at the origin
80 * and drawn in the XY plane.
82 * \param start The initial angle (in radians).
83 * \param angle The length of the arc (in radians).
84 * \param radius The arc radius.
85 * \param nsegments The number of segments to use in drawing the arc.
87 void glutil_draw_filled_arc(float start, float angle, float radius, int nsegments);
90 * Routines an integer value as obtained by glGetIntegerv.
91 * The param must cause only one value to be gotten from GL.
93 int glaGetOneInteger(int param);
96 * Routines a float value as obtained by glGetIntegerv.
97 * The param must cause only one value to be gotten from GL.
99 float glaGetOneFloat(int param);
102 * Functions like glRasterPos2i, except ensures that the resulting
103 * raster position is valid. \a known_good_x and \a known_good_y
104 * should be coordinates of a point known to be within the current
106 * \attention This routine should be used when the distance of \a x
107 * and \a y away from the known good point is small (ie. for small icons
108 * and for bitmap characters), when drawing large+zoomed images it is
109 * possible for overflow to occur, the glaDrawPixelsSafe routine should
112 void glaRasterPosSafe2f(float x, float y, float known_good_x, float known_good_y);
115 * Functions like a limited glDrawPixels, except ensures that
116 * the image is displayed onscreen even if the \a x and \a y
117 * coordinates for would be clipped. The routine respects the
118 * glPixelZoom values, pixel unpacking parameters are _not_
121 * \attention This routine makes many assumptions: the rect data
122 * is expected to be in RGBA unsigned byte format, the coordinate
123 * (GLA_PIXEL_OFS, GLA_PIXEL_OFS) is assumed to be within the view frustum,
124 * and the modelview and projection matrices are assumed to define a
125 * 1-to-1 mapping to screen space.
126 * \attention Furthermore, in the case of zoomed or unpixel aligned
127 * images extending outside the view frustum, but still within the
128 * window, some portion of the image may be visible left and/or
129 * below of the given \a x and \a y coordinates. It is recommended
130 * to use the glScissor functionality if images are to be drawn
131 * with an inset view matrix.
133 void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int format, int type, void *rect);
136 * glaDrawPixelsTex - Functions like a limited glDrawPixels, but actually draws the
137 * image using textures, which can be tremendously faster on low-end
138 * cards, and also avoids problems with the raster position being
139 * clipped when offscreen. The routine respects the glPixelZoom values,
140 * pixel unpacking parameters are _not_ respected.
142 * \attention This routine makes many assumptions: the rect data
143 * is expected to be in RGBA byte or float format, and the
144 * modelview and projection matrices are assumed to define a
145 * 1-to-1 mapping to screen space.
148 void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect);
151 * glaDrawPixelsAuto - Switches between texture or pixel drawing using UserDef.
153 * needs glaDefine2DArea to be set.
155 void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect);
158 void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY);
160 /* 2D Drawing Assistance */
162 /** Define a 2D area (viewport, scissor, matrices) for OpenGL rendering.
164 * glwDefine2DArea and glaBegin2DDraw set up an OpenGL state appropriate
165 * for drawing using both vertice (Vertex, etc) and raster (RasterPos, Rect)
166 * commands. All coordinates should be at integer positions. There is little
167 * to no reason to use glVertex2f etc. functions during 2D rendering, and
168 * thus no reason to +-0.5 the coordinates or perform other silly
171 * \param screen_rect The screen rectangle to be defined for 2D drawing.
173 void glaDefine2DArea(struct rcti *screen_rect);
175 typedef struct gla2DDrawInfo gla2DDrawInfo;
180 gla2DDrawInfo *glaBegin2DDraw(struct rcti *screen_rect, struct rctf *world_rect);
181 void gla2DDrawTranslatePt(gla2DDrawInfo *di, float wo_x, float wo_y, int *sc_x_r, int *sc_y_r);
182 void gla2DDrawTranslatePtv(gla2DDrawInfo *di, float world[2], int screen_r[2]);
184 void glaEnd2DDraw(gla2DDrawInfo *di);
186 /** Adjust the transformation mapping of a 2d area */
187 void gla2DGetMap(gla2DDrawInfo *di, struct rctf *rect);
188 void gla2DSetMap(gla2DDrawInfo *di, struct rctf *rect);
191 /* use this for platform hacks. glPointSize is solved here */
192 void bglBegin(int mode);
194 // int bglPointHack(void); /* UNUSED */
195 void bglVertex3fv(const float vec[3]);
196 void bglVertex3f(float x, float y, float z);
197 void bglVertex2fv(const float vec[2]);
198 /* intel gfx cards frontbuffer problem */
199 // void bglFlush(void); /* UNUSED */
200 void set_inverted_drawing(int enable);
201 void setlinestyle(int nr);
203 /* own working polygon offset */
204 void bglPolygonOffset(float viewdist, float dist);
206 /* For caching opengl matrices (gluProject/gluUnProject) */
207 typedef struct bglMats {
208 double modelview[16];
209 double projection[16];
212 void bgl_get_mats(bglMats *mats);
214 /* **** Color management helper functions for GLSL display/transform ***** */
216 /* Draw imbuf on a screen, preferably using GLSL display transform */
217 void glaDrawImBuf_glsl(struct ImBuf *ibuf, float x, float y, int zoomfilter,
218 struct ColorManagedViewSettings *view_settings,
219 struct ColorManagedDisplaySettings *display_settings);
221 /* Draw imbuf on a screen, preferably using GLSL display transform */
222 void glaDrawImBuf_glsl_ctx(const struct bContext *C, struct ImBuf *ibuf, float x, float y, int zoomfilter);
224 /* Transform buffer from role to scene linear space using GLSL OCIO conversion */
225 int glaBufferTransformFromRole_glsl(float *buffer, int width, int height, int role);
227 #endif /* __BIF_GLUTIL_H__ */