Blender V2.61 - r43446
Classes | Defines | Functions | Variables

glutil.c File Reference

#include <stdio.h>
#include <string.h>
#include "MEM_guardedalloc.h"
#include "DNA_vec_types.h"
#include "BLI_utildefines.h"
#include "BKE_colortools.h"
#include "BLI_math.h"
#include "BLI_threads.h"
#include "BIF_gl.h"
#include "BIF_glutil.h"

Go to the source code of this file.

Classes

struct  gla2DDrawInfo

Defines

#define GL_CLAMP_TO_EDGE   0x812F
#define glToggle(mode, onoff)   (((onoff)?glEnable:glDisable)(mode))

Functions

void fdrawbezier (float vec[4][3])
void fdrawline (float x1, float y1, float x2, float y2)
void fdrawbox (float x1, float y1, float x2, float y2)
void sdrawline (short x1, short y1, short x2, short y2)
static void sdrawtripoints (short x1, short y1, short x2, short y2)
void sdrawtri (short x1, short y1, short x2, short y2)
void sdrawtrifill (short x1, short y1, short x2, short y2)
void sdrawbox (short x1, short y1, short x2, short y2)
void setlinestyle (int nr)
void set_inverted_drawing (int enable)
void sdrawXORline (int x0, int y0, int x1, int y1)
void sdrawXORline4 (int nr, int x0, int y0, int x1, int y1)
void fdrawXORellipse (float xofs, float yofs, float hw, float hh)
void fdrawXORcirc (float xofs, float yofs, float rad)
void glutil_draw_filled_arc (float start, float angle, float radius, int nsegments)
void glutil_draw_lined_arc (float start, float angle, float radius, int nsegments)
int glaGetOneInteger (int param)
float glaGetOneFloat (int param)
void glaRasterPosSafe2f (float x, float y, float known_good_x, float known_good_y)
static int get_cached_work_texture (int *w_r, int *h_r)
void glaDrawPixelsTexScaled (float x, float y, int img_w, int img_h, int format, void *rect, float scaleX, float scaleY)
void glaDrawPixelsTex (float x, float y, int img_w, int img_h, int format, void *rect)
void glaDrawPixelsSafe (float x, float y, int img_w, int img_h, int row_w, int format, int type, void *rect)
void glaDefine2DArea (rcti *screen_rect)
void gla2DGetMap (gla2DDrawInfo *di, rctf *rect)
void gla2DSetMap (gla2DDrawInfo *di, rctf *rect)
gla2DDrawInfoglaBegin2DDraw (rcti *screen_rect, rctf *world_rect)
void gla2DDrawTranslatePt (gla2DDrawInfo *di, float wo_x, float wo_y, int *sc_x_r, int *sc_y_r)
void gla2DDrawTranslatePtv (gla2DDrawInfo *di, float world[2], int screen_r[2])
void glaEnd2DDraw (gla2DDrawInfo *di)
void bglBegin (int mode)
int bglPointHack (void)
void bglVertex3fv (float *vec)
void bglVertex3f (float x, float y, float z)
void bglVertex2fv (float *vec)
void bglEnd (void)
void bgl_get_mats (bglMats *mats)
void bglPolygonOffset (float viewdist, float dist)
void bglFlush (void)

Variables

GLubyte stipple_halftone [128]
GLubyte stipple_quarttone [128]
GLubyte stipple_diag_stripes_pos [128]
GLubyte stipple_diag_stripes_neg [128]
static int curmode = 0
static int pointhack = 0
static GLubyte Squaredot [16]

Detailed Description

Definition in file glutil.c.


Define Documentation

#define GL_CLAMP_TO_EDGE   0x812F
#define glToggle (   mode,
  onoff 
)    (((onoff)?glEnable:glDisable)(mode))

Definition at line 275 of file glutil.c.

Referenced by set_inverted_drawing().


Function Documentation

void bgl_get_mats ( bglMats mats)
void bglBegin ( int  mode)
void bglEnd ( void  )
void bglFlush ( void  )

Definition at line 901 of file glutil.c.

int bglPointHack ( void  )

Definition at line 779 of file glutil.c.

References floorf.

void bglPolygonOffset ( float  viewdist,
float  dist 
)
void bglVertex2fv ( float *  vec)

Definition at line 819 of file glutil.c.

References curmode, pointhack, and Squaredot.

Referenced by draw_uvs(), and ui_draw_but_CURVE().

void bglVertex3f ( float  x,
float  y,
float  z 
)

Definition at line 806 of file glutil.c.

References curmode, pointhack, and Squaredot.

void bglVertex3fv ( float *  vec)
void fdrawbezier ( float  vec[4][3])

Definition at line 131 of file glutil.c.

References ABS, and cpack.

void fdrawbox ( float  x1,
float  y1,
float  x2,
float  y2 
)
void fdrawline ( float  x1,
float  y1,
float  x2,
float  y2 
)
void fdrawXORcirc ( float  xofs,
float  yofs,
float  rad 
)

Definition at line 353 of file glutil.c.

References glutil_draw_lined_arc(), M_PI, and set_inverted_drawing().

void fdrawXORellipse ( float  xofs,
float  yofs,
float  hw,
float  hh 
)

Definition at line 339 of file glutil.c.

References glutil_draw_lined_arc(), M_PI, and set_inverted_drawing().

static int get_cached_work_texture ( int *  w_r,
int *  h_r 
) [static]

Definition at line 425 of file glutil.c.

References glaGetOneInteger(), MEM_callocN(), and MEM_freeN().

Referenced by glaDrawPixelsTexScaled().

void gla2DDrawTranslatePt ( gla2DDrawInfo di,
float  wo_x,
float  wo_y,
int *  sc_x_r,
int *  sc_y_r 
)

Translate the (wo_x, wo_y) point from world coordinates into screen space.

Definition at line 731 of file glutil.c.

References gla2DDrawInfo::wo_to_sc, gla2DDrawInfo::world_rect, rctf::xmin, and rctf::ymin.

void gla2DDrawTranslatePtv ( gla2DDrawInfo di,
float  world[2],
int  screen_r[2] 
)

Translate the world point from world coordiantes into screen space.

Definition at line 736 of file glutil.c.

References gla2DDrawInfo::wo_to_sc, gla2DDrawInfo::world_rect, rctf::xmin, and rctf::ymin.

void gla2DGetMap ( gla2DDrawInfo di,
struct rctf rect 
)

Adjust the transformation mapping of a 2d area

Definition at line 675 of file glutil.c.

References gla2DDrawInfo::world_rect.

void gla2DSetMap ( gla2DDrawInfo di,
rctf rect 
)
gla2DDrawInfo* glaBegin2DDraw ( struct rcti screen_rect,
struct rctf world_rect 
)

Save the current OpenGL state and initialize OpenGL for 2D rendering. glaEnd2DDraw should be called on the returned structure to free it and to return OpenGL to its previous state. The scissor rectangle is set to match the viewport.

This routine sets up an OpenGL state appropriate for drawing using both vertice (glVertex, etc) and raster (glRasterPos, glRect) commands. All coordinates should be at integer positions. There is little to no reason to use glVertex2f etc. functions during 2D rendering, and thus no reason to +-0.5 the coordinates or perform other silly tricks.

Parameters:
screen_rectThe screen rectangle to be used for 2D drawing.
world_rectThe world rectangle that the 2D area represented by screen_rect is supposed to represent. If NULL it is assumed the world has a 1 to 1 mapping to the screen.

Definition at line 697 of file glutil.c.

References glaDefine2DArea(), MEM_mallocN(), gla2DDrawInfo::orig_projmat, gla2DDrawInfo::orig_sc, gla2DDrawInfo::orig_viewmat, gla2DDrawInfo::orig_vp, gla2DDrawInfo::screen_rect, gla2DDrawInfo::wo_to_sc, gla2DDrawInfo::world_rect, rcti::xmax, rctf::xmax, rcti::xmin, rctf::xmin, rcti::ymax, rctf::ymax, rcti::ymin, and rctf::ymin.

void glaDefine2DArea ( struct rcti screen_rect)

Define a 2D area (viewport, scissor, matrices) for OpenGL rendering. This routine sets up an OpenGL state appropriate for drawing using both vertice (glVertex, etc) and raster (glRasterPos, glRect) commands. All coordinates should be at integer positions. There is little to no reason to use glVertex2f etc. functions during 2D rendering, and thus no reason to +-0.5 the coordinates or perform other silly tricks.

Parameters:
screen_rectThe screen rectangle to be defined for 2D drawing.

Definition at line 642 of file glutil.c.

References rcti::xmax, rcti::xmin, rcti::ymax, and rcti::ymin.

Referenced by draw_nodespace_back_pix(), and glaBegin2DDraw().

void glaDrawPixelsSafe ( float  x,
float  y,
int  img_w,
int  img_h,
int  row_w,
int  format,
int  type,
void *  rect 
)

Functions like a limited glDrawPixels, except ensures that the image is displayed onscreen even if the x and y coordinates for would be clipped. The routine respects the glPixelZoom values, pixel unpacking parameters are _not_ respected.

Attention:
This routine makes many assumptions: the rect data is expected to be in RGBA unsigned byte format, the coordinate (0.375, 0.375) is assumed to be within the view frustum, and the modelview and projection matrices are assumed to define a 1-to-1 mapping to screen space.
Furthmore, in the case of zoomed or unpixel aligned images extending outside the view frustum, but still within the window, some portion of the image may be visible left and/or below of the given x and y coordinates. It is recommended to use the glScissor functionality if images are to be drawn with an inset view matrix.

Definition at line 562 of file glutil.c.

References glaGetOneFloat(), glaGetOneInteger(), glaRasterPosSafe2f(), MAX2, and MIN2.

Referenced by draw_image_buffer(), draw_image_buffer_tiled(), draw_image_paint_helpers(), draw_movieclip_buffer(), draw_nodespace_back_pix(), ed_preview_draw_rect(), icon_draw_rect(), sima_draw_alpha_pixels(), sima_draw_alpha_pixelsf(), sima_draw_zbuf_pixels(), sima_draw_zbuffloat_pixels(), ui_draw_but_IMAGE(), and ui_draw_but_TRACKPREVIEW().

void glaDrawPixelsTex ( float  x,
float  y,
int  img_w,
int  img_h,
int  format,
void *  rect 
)

Functions like a limited glDrawPixels, but actually draws the image using textures, which can be tremendously faster on low-end cards, and also avoids problems with the raster position being clipped when offscreen. The routine respects the glPixelZoom values, pixel unpacking parameters are _not_ respected.

Attention:
This routine makes many assumptions: the rect data is expected to be in RGBA byte or float format, and the modelview and projection matrices are assumed to define a 1-to-1 mapping to screen space.

Definition at line 557 of file glutil.c.

References glaDrawPixelsTexScaled().

Referenced by draw_bgpic(), draw_empty_image(), and node_draw_preview().

void glaDrawPixelsTexScaled ( float  x,
float  y,
int  img_w,
int  img_h,
int  format,
void *  rect,
float  scaleX,
float  scaleY 
)
void glaEnd2DDraw ( gla2DDrawInfo di)
float glaGetOneFloat ( int  param)

Routines a float value as obtained by glGetIntegerv. The param must cause only one value to be gotten from GL.

Definition at line 401 of file glutil.c.

Referenced by glaDrawPixelsSafe(), and glaDrawPixelsTexScaled().

int glaGetOneInteger ( int  param)

Routines an integer value as obtained by glGetIntegerv. The param must cause only one value to be gotten from GL.

Definition at line 394 of file glutil.c.

References i.

Referenced by draw_image_seq(), get_cached_work_texture(), glaDrawPixelsSafe(), and glaDrawPixelsTexScaled().

void glaRasterPosSafe2f ( float  x,
float  y,
float  known_good_x,
float  known_good_y 
)

Functions like glRasterPos2i, except ensures that the resulting raster position is valid. known_good_x and known_good_y should be coordinates of a point known to be within the current view frustum.

Attention:
This routine should be used when the distance of x and away from the known good point is small (ie. for small icons and for bitmap characters), when drawing large+zoomed images it is possible for overflow to occur, the glaDrawPixelsSafe routine should be used instead.

Definition at line 408 of file glutil.c.

Referenced by glaDrawPixelsSafe().

void glutil_draw_filled_arc ( float  start,
float  angle,
float  radius,
int  nsegments 
)

Draw a filled arc with the given radius, starting at angle start and arcing through angle. The arc is centered at the origin and drawn in the XY plane.

Parameters:
startThe initial angle (in radians).
angleThe length of the arc (in radians).
radiusThe arc radius.
nsegmentsThe number of segments to use in drawing the arc.

Definition at line 365 of file glutil.c.

References angle(), cosf, i, and sinf.

Referenced by radial_control_paint_tex(), ui_hsv_cursor(), and wm_gesture_draw_circle().

void glutil_draw_lined_arc ( float  start,
float  angle,
float  radius,
int  nsegments 
)

Draw a lined (non-looping) arc with the given radius, starting at angle start and arcing through angle. The arc is centered at the origin and drawn in the XY plane.

Parameters:
startThe initial angle (in radians).
angleThe length of the arc (in radians).
radiusThe arc radius.
nsegmentsThe number of segments to use in drawing the arc.

Definition at line 380 of file glutil.c.

References angle(), cosf, i, and sinf.

Referenced by brush_drawcursor(), fdrawXORcirc(), fdrawXORellipse(), paint_draw_cursor(), radial_control_paint_cursor(), ui_draw_but_HSVCIRCLE(), ui_draw_but_NORMAL(), ui_hsv_cursor(), and wm_gesture_draw_circle().

void sdrawbox ( short  x1,
short  y1,
short  x2,
short  y2 
)

Definition at line 238 of file glutil.c.

Referenced by wm_gesture_draw_rect().

void sdrawline ( short  x1,
short  y1,
short  x2,
short  y2 
)
void sdrawtri ( short  x1,
short  y1,
short  x2,
short  y2 
)

Definition at line 224 of file glutil.c.

References sdrawtripoints().

void sdrawtrifill ( short  x1,
short  y1,
short  x2,
short  y2 
)

Definition at line 231 of file glutil.c.

References sdrawtripoints().

static void sdrawtripoints ( short  x1,
short  y1,
short  x2,
short  y2 
) [static]

Definition at line 213 of file glutil.c.

Referenced by sdrawtri(), and sdrawtrifill().

void sdrawXORline ( int  x0,
int  y0,
int  x1,
int  y1 
)

Definition at line 284 of file glutil.c.

References set_inverted_drawing().

void sdrawXORline4 ( int  nr,
int  x0,
int  y0,
int  x1,
int  y1 
)

Definition at line 298 of file glutil.c.

References set_inverted_drawing().

void set_inverted_drawing ( int  enable)
void setlinestyle ( int  nr)

Variable Documentation

int curmode = 0 [static]

Definition at line 756 of file glutil.c.

Referenced by bglBegin(), bglVertex2fv(), bglVertex3f(), and bglVertex3fv().

int pointhack = 0 [static]

Definition at line 757 of file glutil.c.

Referenced by bglBegin(), bglEnd(), bglVertex2fv(), bglVertex3f(), and bglVertex3fv().

GLubyte Squaredot[16] [static]
Initial value:
 { 0xff,0xff,0xff,0xff,
                                 0xff,0xff,0xff,0xff,
                                 0xff,0xff,0xff,0xff, 
                                 0xff,0xff,0xff,0xff}

Definition at line 758 of file glutil.c.

Referenced by bglVertex2fv(), bglVertex3f(), and bglVertex3fv().

Initial value:
 {
    0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
    0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
    0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
    0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f,
    0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
    0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
    0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
    0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80,
    0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
    0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
    0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
    0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f,
    0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
    0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
    0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
    0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80}

Definition at line 112 of file glutil.c.

Referenced by draw_seq_strip().

Initial value:
 {
    0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
    0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
    0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
    0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80,
    0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
    0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
    0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
    0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f,
    0x00, 0xff, 0x00, 0xff, 0x01, 0xfe, 0x01, 0xfe,
    0x03, 0xfc, 0x03, 0xfc, 0x07, 0xf8, 0x07, 0xf8,
    0x0f, 0xf0, 0x0f, 0xf0, 0x1f, 0xe0, 0x1f, 0xe0,
    0x3f, 0xc0, 0x3f, 0xc0, 0x7f, 0x80, 0x7f, 0x80,
    0xff, 0x00, 0xff, 0x00, 0xfe, 0x01, 0xfe, 0x01,
    0xfc, 0x03, 0xfc, 0x03, 0xf8, 0x07, 0xf8, 0x07,
    0xf0, 0x0f, 0xf0, 0x0f, 0xe0, 0x1f, 0xe0, 0x1f,
    0xc0, 0x3f, 0xc0, 0x3f, 0x80, 0x7f, 0x80, 0x7f}

Definition at line 93 of file glutil.c.

Referenced by draw_seq_strip().

GLubyte stipple_halftone[128]
Initial value:
 {
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55,
    0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55}

Definition at line 56 of file glutil.c.

Referenced by console_draw_sel(), draw_shadedstrip(), and drawmeta_stipple().

GLubyte stipple_quarttone[128]
Initial value:
 { 
    136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
    136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
    136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
    136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
    136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
    136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
    136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0,
    136,136,136,136,0,0,0,0,34,34,34,34,0,0,0,0}

Definition at line 82 of file glutil.c.

Referenced by ccgDM_drawMappedFaces(), draw_uvs(), and emDM_drawMappedFaces().