Rendering Functions

There is a rendering function for each supported geometric shape.

Rendering functions are the only functions that cause entries into the Render Buffers.  Material and mode changes translate into hardware register access only when something is actually rendered.

Summary
Rendering FunctionsThere is a rendering function for each supported geometric shape.
Direct Rendering
d2_clearRender fill the entire framebuffer with a single color.
d2_renderboxRender a rectangle.
d2_renderlineRender a wide line.
d2_renderline2Render a wide line with 2 different widths.
d2_rendertriRender a triangle.
d2_renderquadRender a quadrangle.
d2_rendercircleRender a circle or circle ring.
d2_renderwedgeRender a circle arc or circle ring arc.
Buffer Rendering
d2_renderpolylineRender a polyline
d2_renderpolyline2Render a polyline with multiple width
d2_rendertrilistRender a polygon from a triangle list.
d2_rendertristripRender a polygon from a triangle strip.
d2_rendertrifanRender a polygon from a triangle fan
d2_renderpolygonRender a convex polygon

Direct Rendering

d2_clear

d2_s32 d2_clear(d2_device *handle,
d2_color color)

Render fill the entire framebuffer with a single color.

The current cliprect is used to determine framebuffer dimensions.  Clearing is the only function that bypasses the current solid context and renders plain color - regardless of blendmodes, fillmodes and other attributes.

Because clearing does bypass the context material settings it is the only function that includes both alpha and color in the 32bit ‘color’ argument.  The most significant byte is used to fill the framebuffer alpha channel if one is present.

To clear using all context attributes simply use d2_renderbox.

parameters

handledevice pointer (see: d2_opendevice)
colorfill color and alpha

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

d2_renderbox

d2_s32 d2_renderbox(d2_device *handle,
d2_point x1,
d2_point y1,
d2_width w,
d2_width h)

Render a rectangle.

Nothing is rendered if width or height are 0.  Subpixel positions and fractional sizes are supported.

parameters

handledevice pointer (see: d2_opendevice)
x1,y1top left corner (fixedpoint)
wwidth of rectangle in pixels (fixedpoint)
hheight of rectangle in pixels (fixedpoint)

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

d2_renderline

d2_s32 d2_renderline(d2_device *handle,
d2_point x1,
d2_point y1,
d2_point x2,
d2_point y2,
d2_width w,
d2_u32 flags)

Render a wide line.

Subpixel positions and fractional widths are supported.

To modify the lineend styles use d2_setlinecap, but note that only included endpoints will get a cap.  So if d2_lf_exclude_end is specified and linecap is set to round - the endpoint will not get rounded.

parameters

handledevice pointer (see: d2_opendevice)
x1,y1startpoint (fixedpoint)
x2,y2endpoint (fixedpoint)
wwidth of line in pixels (fixedpoint)
flagsadditional lineend flags

lineend flags

d2_le_exclude_startstartpoint is not part of the line
d2_le_exclude_endendpoint is not part of the line
d2_le_exclude_nonestart and endpoint are part of the line
d2_le_exclude_bothstart and endpoint are not part of the line

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

see also

d2_renderline2, d2_setlinecap

d2_renderline2

d2_s32 d2_renderline2(d2_device *handle,
d2_point x1,
d2_point y1,
d2_point x2,
d2_point y2,
d2_width w1,
d2_width w2,
d2_u32 flags)

Render a wide line with 2 different widths.

Line can have two different width at start and endpoint, forming a trapezoid.  If both widths are equal it is faster to use d2_renderline instead.  Subpixel positions and fractional widths are supported.

To modify the lineend styles use d2_setlinecap, but note that only included endpoints will get a cap.  So if d2_lf_exclude_end is specified and linecap is set to round - the endpoint will not get rounded.

parameters

handledevice pointer (see: d2_opendevice)
x1,y1startpoint (fixedpoint)
x2,y2endpoint (fixedpoint)
w1width of line in pixels at startpoint (fixedpoint)
w2width of line in pixels at endpoint (fixedpoint)
flagsadditional lineend flags

lineend flags

d2_le_exclude_startstartpoint is not part of the line
d2_le_exclude_endendpoint is not part of the line
d2_le_exclude_nonestart and endpoint are part of the line
d2_le_exclude_bothstart and endpoint are not part of the line

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

see also

d2_renderline, d2_setlinecap

d2_rendertri

d2_s32 d2_rendertri(d2_device *handle,
d2_point x1,
d2_point y1,
d2_point x2,
d2_point y2,
d2_point x3,
d2_point y3,
d2_u32 flags)

Render a triangle.

Triangles must be specified with clockwise orientation.  Subpixel positions are supported.  In order to get correct antialiasing and outlines shared edges must be specified using edge flags.

parameters

handledevice pointer (see: d2_opendevice)
x1,y1first point (fixedpoint)
x2,y2second point (fixedpoint)
x3,y3third point (fixedpoint)
flagstriangle edge flags

triangle edge flags

d2_edge0_sharededge from (x1,y1) - (x2,y2) is shared
d2_edge1_sharededge from (x2,y2) - (x3,y3) is shared
d2_edge2_sharededge from (x3,y3) - (x1,y1) is shared

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

d2_renderquad

d2_s32 d2_renderquad(d2_device *handle,
d2_point x1,
d2_point y1,
d2_point x2,
d2_point y2,
d2_point x3,
d2_point y3,
d2_point x4,
d2_point y4,
d2_u32 flags)

Render a quadrangle.

A quadrangle is a convex four-sided polygon (quadrilateral is the precise mathematical term).  Quadrangles must be specified with clockwise orientation.  Subpixel positions are supported.  In order to get correct antialiasing and outlines shared edges must be specified using edge flags.

parameters

handledevice pointer (see: d2_opendevice)
x1,y1first point (fixedpoint)
x2,y2second point (fixedpoint)
x3,y3third point (fixedpoint)
x4,y4fourth point (fixedpoint)
flagsquadrangle edge flags

triangle edge flags

d2_edge0_sharededge from (x1,y1) - (x2,y2) is shared
d2_edge1_sharededge from (x2,y2) - (x3,y3) is shared
d2_edge2_sharededge from (x3,y3) - (x4,y4) is shared
d2_edge3_sharededge from (x4,y4) - (x1,y1) is shared

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

d2_rendercircle

d2_s32 d2_rendercircle(d2_device *handle,
d2_point x,
d2_point y,
d2_width r,
d2_width w)

Render a circle or circle ring.

Circles are directly rasterized and not reduced to linear parts by the hardware.  Subpixel positions, radii and widths are supported.  Nonantialiased circle rings with a fractional width below 1 pixel will have drop outs (missing pixels).

parameters

handledevice pointer (see: d2_opendevice)
x,ycenter (fixedpoint)
rradius (fixedpoint)
wwidth or 0 for a solid circle (fixedpoint)

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

d2_renderwedge

d2_s32 d2_renderwedge(d2_device *handle,
d2_point x,
d2_point y,
d2_width r,
d2_width w,
d2_s32 nx1,
d2_s32 ny1,
d2_s32 nx2,
d2_s32 ny2,
d2_u32 flags)

Render a circle arc or circle ring arc.

Same as d2_rendercircle but clipped by two additional linear boundaries, resulting in an arc.  As default the two half planes form an intersected area for the clipping region.  For angles > 180 deg the flag d2_wf_concave must be used.  When the flag d2_wf_concave is set the two half planes form a united, concave area.  In order to get correct antialiasing and outlines shared edges must be specified using edge flags (only linear edges can be shared).

parameters

handledevice pointer (see: d2_opendevice)
x,ycenter (fixedpoint)
rradius (fixedpoint)
wwidth or 0 for a solid circle (fixedpoint)
nx1, ny1normal vector of first edge (16:16 fixedpoint)
nx2, ny2normal vector of second edge (16:16 fixedpoint)
flagsedge sharing and concave flags

circle wedge flags

d2_edge0_sharedfirst edge is shared
d2_edge1_sharedsecond edge is shared
d2_wf_concavedefines that the clipping region forms a united area for angles > 180 deg

returns

errorcode (D2_OK if successful) see list of Errorcodes for details

note

d2_renderwedge internally calls d2_setclipgradient for drawing wedges and will overwrite the clip gradient settings!

remarks

The figure below shows four examples of different wedges and the corresponding normal vectors (n1, n2).  In order to get correct antialiasing all vectors must be normalized to a length of one.

example

...
d2_setcolor(handle, 0, 0x0000ff);
d2_renderwedge(handle, 100<<4, 100<<4, 50<<4, 0,    1<<16, 0<<16,   -46340, -46340,   0);
d2_renderwedge(handle, 200<<4, 100<<4, 50<<4, 0,    1<<16, 0<<16,    0<<16, -1<<16,   0);
d2_renderwedge(handle, 300<<4, 100<<4, 50<<4, 0,    1<<16, 0<<16,    46340, -46340,   0);
d2_renderwedge(handle, 400<<4, 100<<4, 50<<4, 0,    1<<16, 0<<16,    1<<16,  0<<16,   0);
...

remarks

The figure below shows the same examples but with d2_wf_concave set.

example

...
d2_setcolor(handle, 0, 0x0000ff);
d2_renderwedge(handle, 100<<4, 100<<4, 50<<4, 0,    1<<16, 0<<16,   -46340, -46340,   d2_wf_concave);
d2_renderwedge(handle, 200<<4, 100<<4, 50<<4, 0,    1<<16, 0<<16,    0<<16, -1<<16,   d2_wf_concave);
d2_renderwedge(handle, 300<<4, 100<<4, 50<<4, 0,    1<<16, 0<<16,    46340, -46340,   d2_wf_concave);
d2_renderwedge(handle, 400<<4, 100<<4, 50<<4, 0,    1<<16, 0<<16,    1<<16,  0<<16,   d2_wf_concave);
...

Buffer Rendering

d2_renderpolyline

d2_s32 d2_renderpolyline(d2_device *handle,
const d2_point *data,
d2_u32 count,
d2_width w,
d2_u32 flags)

Render a polyline

Line segments inside the polyline are connected as defined by d2_setlinejoin and endpoints of the polyline are using the current linecap style set by d2_setlinecap.  If the line is closed (d2_le_closed) it has no endpoints and therefore no linecaps.

parameters

handledevice pointer (see: d2_opendevice)
datapointer to an array of 2*’count’ d2_point values (‘count’ x,y pairs)
countnumber of vertices
wwidth of polyline
flagsadditional lineend flags

lineend flags

d2_le_exclude_startfirst point is not part of the polyline
d2_le_exclude_endlast point is not part of the polyline
d2_le_closedpolyline has no start or endpoint, last vertex is connected back to first

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

see also

d2_setlinecap, d2_setlinejoin

d2_renderpolyline2

d2_s32 d2_renderpolyline2(d2_device *handle,
const d2_point *data,
d2_u32 count,
const d2_width *w,
d2_u32 flags)

Render a polyline with multiple width

Similar to d2_renderpolyline but a width can be supplied for each vertex.  Line segments inside the polyline are connected by round line joins and endpoints of the polyline are using the current linecap style set by d2_setlinecap.  If the line is closed (d2_le_closed) it has no endpoints and therefore no linecaps.

parameters

handledevice pointer (see: d2_opendevice)
datapointer to an array of 2*’count’ d2_point values (‘count’ x,y pairs)
countnumber of vertices
wpointer width to an array of ‘count’ d2_width values (width for each vertex)
flagsadditional lineend flags

lineend flags

d2_le_exclude_startfirst point is not part of the polyline
d2_le_exclude_endlast point is not part of the polyline
d2_le_closedpolyline has no start or endpoint, last vertex is connected back to first

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

see also

d2_setlinecap, d2_setlinejoin, d2_renderpolyline

d2_rendertrilist

d2_s32 d2_rendertrilist(d2_device *handle,
const d2_point *data,
const d2_u32 *flags,
d2_u32 count)

Render a polygon from a triangle list.

Each triangle must be defined in clockwise order.  In order to get correct antialiasing and outlines, shared edges must be specified using edge flags (see: d2_rendertri for flag definition).  There is one flagbyte per triangle.  If no sharing is required (e.g. no antialiasing) you can pass NULL for the ‘flags’ pointer.

For each triangle 3 vertices are specified in the data array.

parameters

handledevice pointer (see: d2_opendevice)
datapointer to an array of 6*count d2_point values (3*count x,y pairs)
flagspointer to an array to count bytes containing edgesharing flags or NULL.  If NULL is passed it is assumed that no edges are shared.
countnumber of triangles

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

see also

d2_rendertri, d2_rendertrifan, d2_rendertristrip

d2_rendertristrip

d2_s32 d2_rendertristrip(d2_device *handle,
const d2_point *data,
const d2_u32 *flags,
d2_u32 count)

Render a polygon from a triangle strip.

When rendering connected structures using a set of triangles a triangle strip can be used instead of a triangle list (d2_rendertrilist).  The advantage is that for every triangle except the first one only one additional vertex has to be specified.  The other two vertices are reused from the previous triangle.  See diagram for explanation:

Triangles rendered from the order given above are :

  • 1,2,3
  • 2,4,3
  • 3,4,5
  • 4,6,5

Note that every second triangle is flipped automatically in order to keep them all in clockwise orientation.  Internal edges are automatically flagged as shared but you can still specify a flag for each triangle in order to define additional shared edges.  There is one flagbyte per triangle.  If no additional sharing information is required you can pass NULL for the ‘flags’ pointer.

The first triangle must be defined in clockwise order (others will then be clockwise as well).

parameters

handledevice pointer (see: d2_opendevice)
datapointer to an array of 2*count+4 d2_point values (count+2 x,y pairs)
flagspointer to an array to count bytes containing edgesharing flags or NULL
countnumber of triangles

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

see also

d2_rendertri, d2_rendertrifan, d2_rendertrilist

d2_rendertrifan

d2_s32 d2_rendertrifan(d2_device *handle,
const d2_point *data,
const d2_u32 *flags,
d2_u32 count)

Render a polygon from a triangle fan

When rendering connected structures where all triangles share a common vertex a triangle fan can be used instead of a triangle list (d2_rendertrilist).  The advantage is that for every triangle except the first one only one additional vertex has to be specified.  The other two vertices are reused from the previous triangle and the common base vertex.  See diagram for explanation:

Triangles rendered from the order given above are :

  • 1,2,3
  • 1,3,4
  • 1,4,5

Internal edges are automatically flagged as shared but you can still specify a flag for each triangle in order to define additional shared edges.  There is one flagbyte per triangle.  If no additional sharing information is required you can pass NULL for the ‘flags’ pointer.

The first triangle must be defined in clockwise order (others will then be clockwise as well).

parameters

handledevice pointer (see: d2_opendevice)
datapointer to an array of 2*count+4 d2_point values (count+2 x,y pairs)
flagspointer to an array to count bytes containing edgesharing flags or NULL
countnumber of triangles

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

see also

d2_rendertri, d2_rendertrilist, d2_rendertristrip

d2_renderpolygon

d2_s32 d2_renderpolygon(d2_device *handle,
const d2_point *data,
d2_u32 count,
d2_u32 flags)

Render a convex polygon

All vertices have to be in clockwise order.  If seperation into monoton subregions is required, internal edges will be flagged as ‘shared’ automatically.  Outer edges are always nonshared for now.

parameters

handledevice pointer (see: d2_opendevice)
datapointer to an array of d2_point values (count x,y pairs)
countnumber of points
flagsreserved (should be NULL)

returns

errorcode (D2_OK if successfull) see list of Errorcodes for details

d2_s32 d2_clear(d2_device *handle,
d2_color color)
Render fill the entire framebuffer with a single color.
d2_s32 d2_renderbox(d2_device *handle,
d2_point x1,
d2_point y1,
d2_width w,
d2_width h)
Render a rectangle.
d2_s32 d2_renderline(d2_device *handle,
d2_point x1,
d2_point y1,
d2_point x2,
d2_point y2,
d2_width w,
d2_u32 flags)
Render a wide line.
d2_s32 d2_renderline2(d2_device *handle,
d2_point x1,
d2_point y1,
d2_point x2,
d2_point y2,
d2_width w1,
d2_width w2,
d2_u32 flags)
Render a wide line with 2 different widths.
d2_s32 d2_rendertri(d2_device *handle,
d2_point x1,
d2_point y1,
d2_point x2,
d2_point y2,
d2_point x3,
d2_point y3,
d2_u32 flags)
Render a triangle.
d2_s32 d2_renderquad(d2_device *handle,
d2_point x1,
d2_point y1,
d2_point x2,
d2_point y2,
d2_point x3,
d2_point y3,
d2_point x4,
d2_point y4,
d2_u32 flags)
Render a quadrangle.
d2_s32 d2_rendercircle(d2_device *handle,
d2_point x,
d2_point y,
d2_width r,
d2_width w)
Render a circle or circle ring.
d2_s32 d2_renderwedge(d2_device *handle,
d2_point x,
d2_point y,
d2_width r,
d2_width w,
d2_s32 nx1,
d2_s32 ny1,
d2_s32 nx2,
d2_s32 ny2,
d2_u32 flags)
Render a circle arc or circle ring arc.
d2_s32 d2_renderpolyline(d2_device *handle,
const d2_point *data,
d2_u32 count,
d2_width w,
d2_u32 flags)
Render a polyline
d2_s32 d2_renderpolyline2(d2_device *handle,
const d2_point *data,
d2_u32 count,
const d2_width *w,
d2_u32 flags)
Render a polyline with multiple width
d2_s32 d2_rendertrilist(d2_device *handle,
const d2_point *data,
const d2_u32 *flags,
d2_u32 count)
Render a polygon from a triangle list.
d2_s32 d2_rendertristrip(d2_device *handle,
const d2_point *data,
const d2_u32 *flags,
d2_u32 count)
Render a polygon from a triangle strip.
d2_s32 d2_rendertrifan(d2_device *handle,
const d2_point *data,
const d2_u32 *flags,
d2_u32 count)
Render a polygon from a triangle fan
d2_s32 d2_renderpolygon(d2_device *handle,
const d2_point *data,
d2_u32 count,
d2_u32 flags)
Render a convex polygon
Renderbuffers (similar in concept to OpenGL display lists) are the main interface between driver and hardware.
d2_device * d2_opendevice(d2_u32 flags)
Create a new device handle.
List of all dave driver errorcodes.
d2_s32 d2_setlinecap(d2_device *handle,
d2_u32 mode)
Specify lineend style.
d2_s32 d2_setclipgradient(d2_device *handle,
d2_s32 index,
d2_point x,
d2_point y,
d2_s32 nx,
d2_s32 ny,
d2_u32 flags)
Define an alpha gradient for clipping.
d2_s32 d2_setlinejoin(d2_device *handle,
d2_u32 mode)
Specify polyline connection style.
Close