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.
Texture Functions | Modify texture mapping settings |
Texture Attribute Writes | |
d2_settexture | Specify the source for texture mapping. |
d2_settexturemode | Define texture addressing details. |
d2_settextureoperation | Choose texture operation for each channel. |
d2_settexopparam | Set texture operation parameter. |
d2_settexturemapping | Define texture mapping. |
d2_settexelcenter | Set texel center offset. |
d2_settexclut | Set texture colour palette pointer. |
d2_settexclut_part | Set a part of the color lookup table. |
d2_writetexclut_direct | Write a part of the color lookup table directly to the render buffer. |
d2_settexclut_offset | Set index offset for indexed texture formats. |
d2_settexclut_format | Set color format of texture CLUT. |
d2_setcolorkey | Set the color for color keying. |
Texture Attribute Queries | |
d2_gettextureoperationa | Query texture operation for alpha channel. |
d2_gettextureoperationr | Query texture operation for red channel. |
d2_gettextureoperationg | Query texture operation for green channel. |
d2_gettextureoperationb | Query texture operation for blue channel. |
d2_gettexopparam1 | Query texture operation parameter p1. |
d2_gettexopparam2 | Query texture operation parameter p2. |
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
handle | device pointer (see: d2_opendevice) |
ptr | address of the top left texel (coordinate 0,0) |
pitch | number of texels (not bytes) per scanline |
width | width of texture in texels (equal or less than pitch) |
height | height of texture in texels |
format | texel encoding type (texture format) |
d2_mode_alpha8 | monochrome 8bit per pixel |
d2_mode_alpha4 | monochrome 4bit per pixel |
d2_mode_alpha2 | monochrome 2bit per pixel |
d2_mode_alpha1 | monochrome 1bit per pixel |
d2_mode_rgb565 | colored 16bit per pixel (alpha is blue) |
d2_mode_argb8888 | colored 32bit per pixel |
d2_mode_rgba8888 | colored 32bit per pixel |
d2_mode_rgb888 | (same as d2_mode_argb8888) |
d2_mode_argb4444 | colored 16bit per pixel |
d2_mode_rgba4444 | colored 16bit per pixel |
d2_mode_rgb444 | (same as d2_mode_argb4444) |
d2_mode_argb1555 | colored 16bit per pixel |
d2_mode_rgba5551 | colored 16bit per pixel |
d2_mode_rgb555 | (same as d2_mode_argb1555) |
d2_mode_ai44 | colored, palletized 8bit per pixel, (4 bit alpha, 4 bit indexed RGB: see d2_settexclut) |
d2_mode_i8 | colored, palletized 8bit per pixel (palette is used if d2_mode_clut is also set) |
d2_mode_i4 | colored, palletized 4bit per pixel (palette is used if d2_mode_clut is also set) |
d2_mode_i2 | colored, palletized 2bit per pixel (palette is used if d2_mode_clut is also set) |
d2_mode_i1 | colored, 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_clut | Enables 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.
errorcode (D2_OK if successful) see list of Errorcodes for details
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_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.
handle | device pointer (see: d2_opendevice) |
mode | any combination of texture mode bits (default is d2_tm_filter, see below) |
d2_tm_wrapu | wrap texture on U axis (x-direction) |
d2_tm_wrapv | wrap texture on V axis (y-direction) |
d2_tm_filteru | apply linear filter on U axis (x-direction) |
d2_tm_filterv | apply linear filter in V axis (y-direction) |
d2_tm_filter | apply bilinear filter (both axis) |
errorcode (D2_OK if successfull) see list of Errorcodes for 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.
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.
handle | device pointer (see: d2_opendevice) |
amode | texture operation for alpha channel |
rmode | texture operation for red channel |
gmode | texture operation for green channel |
bmode | texture operation for blue channel |
d2_to_zero | replace channel data with zero (no parameters) |
d2_to_one | replace channel data with one (no parameters) |
d2_to_replace | replace channel data with a constant (p1) |
d2_to_copy | copy channel data unchanged (no parameters) |
d2_to_invert | invert channel data (no parameters) |
d2_to_multiply | multiply channel data with a constant (p1) |
d2_to_invmultiply | multiply inverted data with a constant (p1) |
d2_to_blend | use channel data to blend between two constants (p1,p2) |
errorcode (D2_OK if successfull) see list of Errorcodes for details
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.
handle | device pointer (see: d2_opendevice) |
index | color channel index / indices |
p1 | parameter ‘p1’ (see: d2_settextureoperation) |
p2 | parameter ‘p2’ (see: d2_settextureoperation) |
d2_cc_alpha | alpha channel |
d2_cc_red | red channel |
d2_cc_green | green channel |
d2_cc_blue | blue channel |
d2_cc_rgb | all channels except alpha |
d2_cc_all | all channels |
errorcode (D2_OK if successfull) see list of Errorcodes for details
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.
handle | device pointer (see: d2_opendevice) |
x , y | position of the (u0,v0) texel on screen (fixedpoint) |
u0, v0 | initial texture coordinates (valid at point x,y) (16:16 fixedpoint) |
dxu, dxv | texture increment for a step in x direction (16:16 fixedpoint) |
dyu, dyv | texture increment for a step in y direction (16:16 fixedpoint) |
errorcode (D2_OK if successfull) see list of Errorcodes for details
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)
handle | device pointer (see: d2_opendevice) |
x , y | subpixel position of the texel center (fixedpoint) |
errorcode (D2_OK if successfull) see list of Errorcodes for details
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.
handle | device pointer (see: d2_opendevice) |
clut | persistent pointer to CLUT |
errorcode (D2_OK if successful) see list of Errorcodes for details
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)
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))
handle | device pointer (see: d2_opendevice) |
clut_part | pointer to a segment for the CLUT |
start_index | start index of the CLUT where clut_part will be copied to (0..size-1) |
length | number of CLUT entries to be copied (1..size) |
errorcode (D2_OK if successful) see list of Errorcodes for details
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))
handle | device pointer (see: d2_opendevice) |
clut_part | pointer to a segment for the CLUT |
start_index | start index of the CLUT where clut_part will be written to (0..size-1) |
length | number of CLUT entries to write (1..size) |
errorcode (D2_OK if successful) see list of Errorcodes for details
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))
handle | device pointer (see: d2_opendevice) |
offset | offset to index (default = 0); will be or’ed with the index of the texel |
errorcode (D2_OK if successful) see list of Errorcodes for details
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).
handle | device pointer (see: d2_opendevice) |
format | color format |
errorcode (D2_OK if successful) see list of Errorcodes for details
d2_mode_argb8888 | colored 32bit per pixel (default) |
d2_mode_rgb565 | colored 16bit per pixel (alpha is blue) |
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.
handle | device pointer (see: d2_opendevice) |
enable | enables color keying |
color_key | RGB value of color key |
errorcode (D2_OK if successfull) see list of Errorcodes for details
colorkeying is available if the feature bit D2FB_COLORKEY is set (see d2_getrevisionhw)
d2_u8 d2_gettextureoperationa( d2_device * handle )
Query texture operation for alpha channel.
See d2_settextureoperation for a list of texture operations
handle | device pointer (see: d2_opendevice) |
texture operation. undefined in case of an error (check with d2_geterror or d2_geterrorstring)
d2_gettextureoperationr, d2_gettextureoperationg, d2_gettextureoperationb
d2_u8 d2_gettextureoperationr( d2_device * handle )
Query texture operation for red channel.
See d2_settextureoperation for a list of texture operations
handle | device pointer (see: d2_opendevice) |
texture operation. undefined in case of an error (check with d2_geterror or d2_geterrorstring)
d2_gettextureoperationa, d2_gettextureoperationg, d2_gettextureoperationb
d2_u8 d2_gettextureoperationg( d2_device * handle )
Query texture operation for green channel.
See d2_settextureoperation for a list of texture operations
handle | device pointer (see: d2_opendevice) |
texture operation. undefined in case of an error (check with d2_geterror or d2_geterrorstring)
d2_gettextureoperationa, d2_gettextureoperationr, d2_gettextureoperationb
d2_u8 d2_gettextureoperationb( d2_device * handle )
Query texture operation for blue channel.
See d2_settextureoperation for a list of texture operations
handle | device pointer (see: d2_opendevice) |
texture operation. undefined in case of an error (check with d2_geterror or d2_geterrorstring)
d2_gettextureoperationa, d2_gettextureoperationr, d2_gettextureoperationg
d2_alpha d2_gettexopparam1( d2_device * handle, d2_u32 index )
Query texture operation parameter p1.
See d2_settexopparam and d2_settextureoperation for details
handle | device pointer (see: d2_opendevice) |
index | color channel index |
d2_cc_alpha | alpha channel |
d2_cc_red | red channel |
d2_cc_green | green channel |
d2_cc_blue | blue channel |
texture operation parameter p1. undefined in case of an error (check with d2_geterror or d2_geterrorstring)
d2_alpha d2_gettexopparam2( d2_device * handle, d2_u32 index )
Query texture operation parameter p2.
See d2_settexopparam and d2_settextureoperation for details
handle | device pointer (see: d2_opendevice) |
index | color channel index |
d2_cc_alpha | alpha channel |
d2_cc_red | red channel |
d2_cc_green | green channel |
d2_cc_blue | blue channel |
texture operation parameter p2. undefined in case of an error (check with d2_geterror or d2_geterrorstring)
Specify the source for texture mapping.
d2_s32 d2_settexture( d2_device * handle, void * ptr, d2_s32 pitch, d2_s32 width, d2_s32 height, d2_u32 format )
Define texture addressing details.
d2_s32 d2_settexturemode( d2_device * handle, d2_u32 mode )
Choose texture operation for each channel.
d2_s32 d2_settextureoperation( d2_device * handle, d2_u8 amode, d2_u8 rmode, d2_u8 gmode, d2_u8 bmode )
Set texture operation parameter.
d2_s32 d2_settexopparam( d2_device * handle, d2_u32 index, d2_u32 p1, d2_u32 p2 )
Define texture mapping.
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 )
Set texel center offset.
d2_s32 d2_settexelcenter( d2_device * handle, d2_point x, d2_point y )
Set texture colour palette pointer.
d2_s32 d2_settexclut( d2_device * handle, d2_color * clut )
Set a part of the color lookup table.
d2_s32 d2_settexclut_part( 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_writetexclut_direct( d2_device * handle, const d2_color * clut_part, d2_u32 start_index, d2_u32 length )
Set index offset for indexed texture formats.
d2_s32 d2_settexclut_offset( d2_device * handle, d2_u32 offset )
Set color format of texture CLUT.
d2_s32 d2_settexclut_format( d2_device * handle, d2_u32 format )
Set the color for color keying.
d2_s32 d2_setcolorkey( d2_device * handle, d2_s32 enable, d2_color color_key )
Query texture operation for alpha channel.
d2_u8 d2_gettextureoperationa( d2_device * handle )
Query texture operation for red channel.
d2_u8 d2_gettextureoperationr( d2_device * handle )
Query texture operation for green channel.
d2_u8 d2_gettextureoperationg( d2_device * handle )
Query texture operation for blue channel.
d2_u8 d2_gettextureoperationb( d2_device * handle )
Query texture operation parameter p1.
d2_alpha d2_gettexopparam1( d2_device * handle, d2_u32 index )
Query texture operation parameter p2.
d2_alpha d2_gettexopparam2( d2_device * handle, d2_u32 index )
Select fillmode (solid,patter,texture,..)
d2_s32 d2_setfillmode( d2_device * handle, d2_u32 mode )
Create a new device handle.
d2_device * d2_opendevice( d2_u32 flags )
Query hw revisionID.
d2_u32 d2_getrevisionhw( const d2_device * handle )
Query device error information.
d2_s32 d2_geterror( const d2_device * handle )
Query detailed device error information.
const d2_char * d2_geterrorstring( const d2_device * handle )