Texture Functions

Modify texture mapping settings

Texture attributes are part of the context (see: Context Functions) but a single context might contain multiple mapping attributes if multiple texture hardware units are present.

Summary
Texture FunctionsModify texture mapping settings
Texture Attribute Writes
d2_settextureSpecify the source for texture mapping.
d2_settexturemodeDefine texture addressing details.
d2_settextureoperationChoose texture operation for each channel.
d2_settexopparamSet texture operation parameter.
d2_settexturemappingDefine texture mapping.
d2_settexelcenterSet texel center offset.
d2_settexclutSet texture colour palette pointer.
d2_settexclut_partSet a part of the color lookup table.
d2_writetexclut_directWrite a part of the color lookup table directly to the render buffer.
d2_settexclut_offsetSet index offset for indexed texture formats.
d2_settexclut_formatSet color format of texture CLUT.
d2_setcolorkeySet the color for color keying.
Texture Attribute Queries
d2_gettextureoperationaQuery texture operation for alpha channel.
d2_gettextureoperationrQuery texture operation for red channel.
d2_gettextureoperationgQuery texture operation for green channel.
d2_gettextureoperationbQuery texture operation for blue channel.
d2_gettexopparam1Query texture operation parameter p1.
d2_gettexopparam2Query texture operation parameter p2.

Texture Attribute Writes

d2_settexture

d2_s32 d2_settexture(d2_device *handle,
void *ptr,
d2_s32 pitch,
d2_s32 width,
d2_s32 height,
d2_u32 format)

Specify the source for texture mapping.

The specified texture is used only when d2_setfillmode is set to d2_fm_texture

parameters

handledevice pointer (see: d2_opendevice)
ptraddress of the top left texel (coordinate 0,0)
pitchnumber of texels (not bytes) per scanline
widthwidth of texture in texels (equal or less than pitch)
heightheight of texture in texels
formattexel encoding type (texture format)

texture formats

d2_mode_alpha8monochrome 8bit per pixel
d2_mode_alpha4monochrome 4bit per pixel
d2_mode_alpha2monochrome 2bit per pixel
d2_mode_alpha1monochrome 1bit per pixel
d2_mode_rgb565colored 16bit per pixel (alpha is blue)
d2_mode_argb8888colored 32bit per pixel
d2_mode_rgba8888colored 32bit per pixel
d2_mode_rgb888(same as d2_mode_argb8888)
d2_mode_argb4444colored 16bit per pixel
d2_mode_rgba4444colored 16bit per pixel
d2_mode_rgb444(same as d2_mode_argb4444)
d2_mode_argb1555colored 16bit per pixel
d2_mode_rgba5551colored 16bit per pixel
d2_mode_rgb555(same as d2_mode_argb1555)
d2_mode_ai44colored, palletized 8bit per pixel, (4 bit alpha, 4 bit indexed RGB: see d2_settexclut)
d2_mode_i8colored, palletized 8bit per pixel (palette is used if d2_mode_clut is also set)
d2_mode_i4colored, palletized 4bit per pixel (palette is used if d2_mode_clut is also set)
d2_mode_i2colored, palletized 2bit per pixel (palette is used if d2_mode_clut is also set)
d2_mode_i1colored, palletized 1bit per pixel (palette is used if d2_mode_clut is also set)

additional flags (can be combined with all above formats) :

d2_mode_clutEnables the color look up table (for d2_mode_i8 through d2_mode_i1) (see d2_settexclut).

Modes d2_mode_rgb888, d2_mode_rgb444 and d2_mode_rgb555 can be used as well.  In this case alpha information has to be ignored by setting a d2_settextureoperation of d2_to_one for alpha.

If the CLUT is not enabled with an indexed color format (d2_mode_i8 to d2_mode_i1), the index is written directly to the framebuffer.  The index can be combined with the offset, see d2_settexclut_offset.

In case of d2_mode_alpha4 to d2_mode_alpha1 bits are MSB aligned and replicated to the lower bits of the 8 bit format of the internal A, R, G and B channels.

returns

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

note

Please notice that a cache flush using ‘d1_cacheblockflush’ might be necessary if memory contents were changed before!  To avoid problems you can use the d1 driver memory management functions ‘d1_copytovidmem’ or ‘d1_copyfromvidmem’, which implicitly do a cache flush.

d2_settexturemode

d2_s32 d2_settexturemode(d2_device *handle,
d2_u32 mode)

Define texture addressing details.

Texture wrapping will work with texture dimensions that are integer powers of two only (2,4,8,16,32,..).  Other sizes will wrap at the next higher power of two.

parameters

handledevice pointer (see: d2_opendevice)
modeany combination of texture mode bits (default is d2_tm_filter, see below)

texture mode bits

d2_tm_wrapuwrap texture on U axis (x-direction)
d2_tm_wrapvwrap texture on V axis (y-direction)
d2_tm_filteruapply linear filter on U axis (x-direction)
d2_tm_filtervapply linear filter in V axis (y-direction)
d2_tm_filterapply bilinear filter (both axis)

returns

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

d2_settextureoperation

d2_s32 d2_settextureoperation(d2_device *handle,
d2_u8 amode,
d2_u8 rmode,
d2_u8 gmode,
d2_u8 bmode)

Choose texture operation for each channel.

Textures can be ‘colorized’ by a varity of operations.  A textureoperation can be defined for each channel (a,r,g,b) individually.  Depending on the chosen operation one or two additional parameters have to be set using d2_settexopparam.

The default setting is d2_to_one, d2_to_copy, d2_to_copy, d2_to_copy and will therfore ignore any alpha information in the texture.

parameters

handledevice pointer (see: d2_opendevice)
amodetexture operation for alpha channel
rmodetexture operation for red channel
gmodetexture operation for green channel
bmodetexture operation for blue channel

texture operations

d2_to_zeroreplace channel data with zero (no parameters)
d2_to_onereplace channel data with one (no parameters)
d2_to_replacereplace channel data with a constant (p1)
d2_to_copycopy channel data unchanged (no parameters)
d2_to_invertinvert channel data (no parameters)
d2_to_multiplymultiply channel data with a constant (p1)
d2_to_invmultiplymultiply inverted data with a constant (p1)
d2_to_blenduse channel data to blend between two constants (p1,p2)

returns

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

see also

d2_settexopparam

d2_settexopparam

d2_s32 d2_settexopparam(d2_device *handle,
d2_u32 index,
d2_u32 p1,
d2_u32 p2)

Set texture operation parameter.

Several texture operations require additional constants.  See d2_settextureoperation for a list and description of all operations and their constants.  The index parameter selects the color channels for which new parameters are to be set.

Both constant have to be in the range of 0 ..  255 unused constants (e.g. p2 in most operations) are ignored.  Note that several color channel indices can be or’ed together.

parameters

handledevice pointer (see: d2_opendevice)
indexcolor channel index / indices
p1parameter ‘p1’ (see: d2_settextureoperation)
p2parameter ‘p2’ (see: d2_settextureoperation)

color channel indices

d2_cc_alphaalpha channel
d2_cc_redred channel
d2_cc_greengreen channel
d2_cc_blueblue channel
d2_cc_rgball channels except alpha
d2_cc_allall channels

returns

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

see also

d2_settextureoperation

d2_settexturemapping

d2_s32 d2_settexturemapping(d2_device *handle,
d2_point x,
d2_point y,
d2_s32 u0,
d2_s32 v0,
d2_s32 dxu,
d2_s32 dyu,
d2_s32 dxv,
d2_s32 dyv)

Define texture mapping.

This is the most basic function to setup the texture mapping frame of reference.  You can directly specify the texture increments in u and v direction for stepping on the x or y axis.

parameters

handledevice pointer (see: d2_opendevice)
x , yposition of the (u0,v0) texel on screen (fixedpoint)
u0, v0initial texture coordinates (valid at point x,y) (16:16 fixedpoint)
dxu, dxvtexture increment for a step in x direction (16:16 fixedpoint)
dyu, dyvtexture increment for a step in y direction (16:16 fixedpoint)

returns

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

d2_settexelcenter

d2_s32 d2_settexelcenter(d2_device *handle,
d2_point x,
d2_point y)

Set texel center offset.

Default texel center is top left corner (0.0 , 0.0)

parameters

handledevice pointer (see: d2_opendevice)
x , ysubpixel position of the texel center (fixedpoint)

returns

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

d2_settexclut

d2_s32 d2_settexclut(d2_device *handle,
d2_color *clut)

Set texture colour palette pointer.

For indexed texture formats (see: d2_settexture), a colour look-up table is used.  This function registers a pointer to a ARGB CLUT (32 bit values, format 0xAARRGGBB) with the current context.  The size of the CLUT must be 16 resp.  256 words (see note).

The pointer needs to be persistent, as the table is not immediately copied to the context.  It is read once before the next object using textures is rendered or if d2_settexclut_part is used.  If the CLUT is changed later on, d2_settexclut has to be called again to trigger a new upload.

parameters

handledevice pointer (see: d2_opendevice)
clutpersistent pointer to CLUT

returns

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

note

size of CLUT:16 x 32bit if feature bit D2FB_TEXCLUT256 = 0 (see d2_getrevisionhw)
size of CLUT:256 x 32bit if feature bit D2FB_TEXCLUT256 = 1 (see d2_getrevisionhw)

the parameter clut can be NULL.  If the CLUT was cached then the allocated memory will be freed (see: d2_settexclut_part)

see also

d2_settexture, d2_settexclut_part

d2_settexclut_part

d2_s32 d2_settexclut_part(d2_device *handle,
const d2_color *clut_part,
d2_u32 start_index,
d2_u32 length)

Set a part of the color lookup table.

Only parts of the CLUT can be set or overridden.  The CLUT content will be cached in the current context.  If a pointer to a CLUT was given by d2_settexclut this CLUT contents is first copied to the context.  The contents of clut_part is then copied to the cached CLUT starting at start_index with a length of length.

The size of the CLUT is 256 resp.  16 (if feature bit D2FB_TEXCLUT256 = 1 resp.  = 0 (see d2_getrevisionhw))

parameters

handledevice pointer (see: d2_opendevice)
clut_partpointer to a segment for the CLUT
start_indexstart index of the CLUT where clut_part will be copied to (0..size-1)
lengthnumber of CLUT entries to be copied (1..size)

returns

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

see also

d2_settexclut

d2_writetexclut_direct

d2_s32 d2_writetexclut_direct(d2_device *handle,
const d2_color *clut_part,
d2_u32 start_index,
d2_u32 length)

Write a part of the color lookup table directly to the render buffer.

Only parts of the CLUT can be set.  The contents of clut_part is written directly to the render buffer starting at start_index with a length of length.

The size of the CLUT is 256 resp.  16 (if feature bit D2FB_TEXCLUT256 = 1 resp.  = 0 (see d2_getrevisionhw))

parameters

handledevice pointer (see: d2_opendevice)
clut_partpointer to a segment for the CLUT
start_indexstart index of the CLUT where clut_part will be written to (0..size-1)
lengthnumber of CLUT entries to write (1..size)

returns

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

note

  • no data needs to be cached
  • clut_part does not need to be persistent
  • a context switch does not restore the contents of the CLUT

see also

d2_settexclut d2_settexclut_part

d2_settexclut_offset

d2_s32 d2_settexclut_offset(d2_device *handle,
d2_u32 offset)

Set index offset for indexed texture formats.

For the indexed texture formats d2_mode_i4, d2_mode_i2 and d2_mode_i1 (see: d2_settexture) an offset to the color index can be used.

The offset is an 8 bit resp.  4 bit value (if feature bit D2FB_TEXCLUT256 = 1 resp.  = 0 (see d2_getrevisionhw))

parameters

handledevice pointer (see: d2_opendevice)
offsetoffset to index (default = 0); will be or’ed with the index of the texel

returns

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

see also

d2_settexclut d2_settexture

d2_settexclut_format

d2_s32 d2_settexclut_format(d2_device *handle,
d2_u32 format)

Set color format of texture CLUT.

The Color lookup table has 256 entries of 32 bit color values.  Each color value is coded as ARGB8888.  In case of RGB565 the CLUT 256x32bit is divided into a lower and an upper part for 256 16bit color entries.  One 32bit word contains two successive 16bit color entries.  The lower 16 bit contain the first color entry and the upper 16 bit contain the next color entry.  The upper part of the CLUT can be accessed by the texture unit by setting the texclut_offset to 0x80.  When loading the CLUT 32bit words are written to the RAM.  In this 16bit mode the driver has to take care to write the correct data.

If the feature bit D2FB_TEXCLUT256 = 0 the format applies to 16 entries of 32 bit (see d2_getrevisionhw).

parameters

handledevice pointer (see: d2_opendevice)
formatcolor format

returns

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

color formats

d2_mode_argb8888colored 32bit per pixel (default)
d2_mode_rgb565colored 16bit per pixel (alpha is blue)

see also

d2_settexclut d2_settexture

d2_setcolorkey

d2_s32 d2_setcolorkey(d2_device *handle,
d2_s32 enable,
d2_color color_key)

Set the color for color keying.

Color keying compares every RGB value of a texture pixel with color_key.  If the values are equal then Alpha as well as R, G and B are set to 0 to mark the pixel transparent.

parameters

handledevice pointer (see: d2_opendevice)
enableenables color keying
color_keyRGB value of color key

returns

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

note

colorkeying is available if the feature bit D2FB_COLORKEY is set (see d2_getrevisionhw)

see also

d2_settexture

Texture Attribute Queries

d2_gettextureoperationa

d2_u8 d2_gettextureoperationa(d2_device *handle)

Query texture operation for alpha channel.

See d2_settextureoperation for a list of texture operations

parameters

handledevice pointer (see: d2_opendevice)

returns

texture operation. undefined in case of an error (check with d2_geterror or d2_geterrorstring)

see also

d2_gettextureoperationr, d2_gettextureoperationg, d2_gettextureoperationb

d2_gettextureoperationr

d2_u8 d2_gettextureoperationr(d2_device *handle)

Query texture operation for red channel.

See d2_settextureoperation for a list of texture operations

parameters

handledevice pointer (see: d2_opendevice)

returns

texture operation. undefined in case of an error (check with d2_geterror or d2_geterrorstring)

see also

d2_gettextureoperationa, d2_gettextureoperationg, d2_gettextureoperationb

d2_gettextureoperationg

d2_u8 d2_gettextureoperationg(d2_device *handle)

Query texture operation for green channel.

See d2_settextureoperation for a list of texture operations

parameters

handledevice pointer (see: d2_opendevice)

returns

texture operation. undefined in case of an error (check with d2_geterror or d2_geterrorstring)

see also

d2_gettextureoperationa, d2_gettextureoperationr, d2_gettextureoperationb

d2_gettextureoperationb

d2_u8 d2_gettextureoperationb(d2_device *handle)

Query texture operation for blue channel.

See d2_settextureoperation for a list of texture operations

parameters

handledevice pointer (see: d2_opendevice)

returns

texture operation. undefined in case of an error (check with d2_geterror or d2_geterrorstring)

see also

d2_gettextureoperationa, d2_gettextureoperationr, d2_gettextureoperationg

d2_gettexopparam1

d2_alpha d2_gettexopparam1(d2_device *handle,
d2_u32 index)

Query texture operation parameter p1.

See d2_settexopparam and d2_settextureoperation for details

parameters

handledevice pointer (see: d2_opendevice)
indexcolor channel index

color channel indices

d2_cc_alphaalpha channel
d2_cc_redred channel
d2_cc_greengreen channel
d2_cc_blueblue channel

returns

texture operation parameter p1. undefined in case of an error (check with d2_geterror or d2_geterrorstring)

see also

d2_settexopparam

d2_gettexopparam2

d2_alpha d2_gettexopparam2(d2_device *handle,
d2_u32 index)

Query texture operation parameter p2.

See d2_settexopparam and d2_settextureoperation for details

parameters

handledevice pointer (see: d2_opendevice)
indexcolor channel index

color channel indices

d2_cc_alphaalpha channel
d2_cc_redred channel
d2_cc_greengreen channel
d2_cc_blueblue channel

returns

texture operation parameter p2. undefined in case of an error (check with d2_geterror or d2_geterrorstring)

see also

d2_settexopparam

d2_s32 d2_settexture(d2_device *handle,
void *ptr,
d2_s32 pitch,
d2_s32 width,
d2_s32 height,
d2_u32 format)
Specify the source for texture mapping.
d2_s32 d2_settexturemode(d2_device *handle,
d2_u32 mode)
Define texture addressing details.
d2_s32 d2_settextureoperation(d2_device *handle,
d2_u8 amode,
d2_u8 rmode,
d2_u8 gmode,
d2_u8 bmode)
Choose texture operation for each channel.
d2_s32 d2_settexopparam(d2_device *handle,
d2_u32 index,
d2_u32 p1,
d2_u32 p2)
Set texture operation parameter.
d2_s32 d2_settexturemapping(d2_device *handle,
d2_point x,
d2_point y,
d2_s32 u0,
d2_s32 v0,
d2_s32 dxu,
d2_s32 dyu,
d2_s32 dxv,
d2_s32 dyv)
Define texture mapping.
d2_s32 d2_settexelcenter(d2_device *handle,
d2_point x,
d2_point y)
Set texel center offset.
d2_s32 d2_settexclut(d2_device *handle,
d2_color *clut)
Set texture colour palette pointer.
d2_s32 d2_settexclut_part(d2_device *handle,
const d2_color *clut_part,
d2_u32 start_index,
d2_u32 length)
Set a part of the color lookup table.
d2_s32 d2_writetexclut_direct(d2_device *handle,
const d2_color *clut_part,
d2_u32 start_index,
d2_u32 length)
Write a part of the color lookup table directly to the render buffer.
d2_s32 d2_settexclut_offset(d2_device *handle,
d2_u32 offset)
Set index offset for indexed texture formats.
d2_s32 d2_settexclut_format(d2_device *handle,
d2_u32 format)
Set color format of texture CLUT.
d2_s32 d2_setcolorkey(d2_device *handle,
d2_s32 enable,
d2_color color_key)
Set the color for color keying.
d2_u8 d2_gettextureoperationa(d2_device *handle)
Query texture operation for alpha channel.
d2_u8 d2_gettextureoperationr(d2_device *handle)
Query texture operation for red channel.
d2_u8 d2_gettextureoperationg(d2_device *handle)
Query texture operation for green channel.
d2_u8 d2_gettextureoperationb(d2_device *handle)
Query texture operation for blue channel.
d2_alpha d2_gettexopparam1(d2_device *handle,
d2_u32 index)
Query texture operation parameter p1.
d2_alpha d2_gettexopparam2(d2_device *handle,
d2_u32 index)
Query texture operation parameter p2.
Modify material settings
d2_s32 d2_setfillmode(d2_device *handle,
d2_u32 mode)
Select fillmode (solid,patter,texture,..)
d2_device * d2_opendevice(d2_u32 flags)
Create a new device handle.
List of all dave driver errorcodes.
d2_u32 d2_getrevisionhw(const d2_device *handle)
Query hw revisionID.
d2_s32 d2_geterror(const d2_device *handle)
Query device error information.
const d2_char * d2_geterrorstring(const d2_device *handle)
Query detailed device error information.
Close