User:Monster Iestyn/Source Code Documentation/r_draw.h

From SRB2 Wiki
Jump to navigation Jump to search
This article or section is incomplete. It doesn't have all of the necessary core information on this topic. Please help the SRB2 Wiki by finishing this article.
Online link GitHub entry
File type C header file
#include guard __R_DRAW__

Includes

Common stuff for both 8bpp and 16bpp

Externs

Data name Data type Non-extern location(s) Description
*ylookup[MAXVIDHEIGHT*4] UINT8 r_draw.c Pointer to the start of each line of the screen of the currently rendered view, starting from the top of the view window.
*ylookup1[MAXVIDHEIGHT*4] UINT8 r_draw.c Pointer to the start of each line of the screen for Player 1's view (for splitscreen).
*ylookup2[MAXVIDHEIGHT*4] UINT8 r_draw.c Pointer to the start of each line of the screen for Player 2's view (for splitscreen).
columnofs[MAXVIDWIDTH*4] INT32 r_draw.c x byte offset for columns inside the view window, so the first column starts at (screen width - view width)/2.
*topleft UINT8 r_draw.c Pointer to the top left corner of the view window. In current versions of SRB2, this will always be the same as screens[0] i.e. the top left corner of the full screen window. In Doom Legacy and early versions of SRB2, this would differ if the view window's size was smaller.

Column drawing code stuff

Externs

Data name Data type Non-extern location(s) Description
*dc_colormap lighttable_t r_draw.c Pointer to the lighttable colormap to be used for drawing a column; e.g.: if dc_colormap == colormaps, the column will be drawn at full brightness. Used by all column drawing functions.
dc_x
dc_yl
dc_yh
INT32 r_draw.c The destination screen coordinates that a column is to be drawn to:
  • dc_x is the X-coordinate the entire column is to be drawn to
  • dc_yl and dc_yh are the lower and higher Y-coordinate bounds the column is to be drawn between, respectively. Since screen Y-coordinates are measured from the top of the screen downwards, dc_yl and dc_yh are actually the Y-coordinates of the top and bottom pixels of the column seen in-game, respectively.
dc_iscale
dc_texturemid
fixed_t r_draw.c dc_iscale is the "inverse scale" of the drawn seg or sprite on-screen, in FRACUNIT scale; for every pixel stepped horizontally or vertically on-screen when drawing a seg or sprite, the renderer steps dc_iscale>>FRACUNIT pixels on the source texture or sprite.

dc_texturemid is a reference relative map Z-coordinate, measured relative to viewz, that is used to help determine what row (or texture Y-coordinate) of the selected source texture or sprite column to start drawing from. Typically this is where the top of the texture or sprite would be located, even if it is not visible on-screen.

dc_hires UINT8 r_draw.c If non-zero, toggles on "hi-res" code for column drawing (?). This is currently always set to zero in SRB2's source code, if enabled it forces texture Y-coordinates in the column drawing functions to start from the top of the texture or sprite.
*dc_source UINT8 r_draw.c Pointer to the source column of the texture or sprite to be drawn onto the screen; this contains the palette indexes of the column's pixels, starting from the top pixel going downwards. Depending on the drawing function used, these indexes may then be remapped to other indexes based on light level using dc_colormap, translucency using dc_transmap, and/or skin colors or other sprite translations via dc_translation.

This is used by all column drawing functions except R_DrawFogColumn_8.

*transtables UINT8 r_draw.c The translucency lookup tables, used for drawing all translucent graphics in the software renderer:
  • transtablesTRANS10 table
  • transtables+0x10000TRANS20 table
  • transtables+0x20000TRANS30 table
  • transtables+0x30000TRANS40 table
  • transtables+0x40000TRANS50 table
  • transtables+0x50000TRANS60 table
  • transtables+0x60000TRANS70 table
  • transtables+0x70000TRANS80 table
  • transtables+0x80000TRANS90 table
*dc_transmap UINT8 r_draw.c Pointer to the translucency table to be used for drawing a translucent column; e.g.: if dc_transmap == transtables the column will be drawn with 10% translucency.

This is used by the following column drawing functions:

  • R_DrawTranslucentColumn_8
  • R_DrawTranslatedTranslucentColumn_8
*dc_translation UINT8 r_draw.c Pointer to the translation colormap array to be used for drawing a sprite column with translation applied (e.g.: skin colors).

This is used by the following column drawing functions:

  • R_DrawTranslatedColumn_8
  • R_DrawTranslatedTranslucentColumn_8
*dc_lightlist struct r_lightlist_s r_draw.c If a drawn seg's front sector has FOFs that affect lighting (e.g.: shadowcasting FOFs or FOFs with colormaps applied via linedef type 606), this points to the list of lights that can affect the seg's columns. This means that each column will be vertically split into segments, one for each entry in the light list, which will be drawn separately.
dc_numlights
dc_maxlights
INT32 r_draw.c If a drawn seg's front sector has FOFs that affect lighting (e.g.: shadowcasting FOFs or FOFs with colormaps applied via linedef type 606), dc_numlights is the number of lights that can affect the seg's columns.

dc_maxlights is the number of light entries allocated in memory for dc_lightlist; i.e.: it takes up sizeof (*dc_lightlist) * dc_maxlights bytes in memory. Note that dc_maxlights is dynamically updated to give more space if needed; if the number of lights in a front sector for a drawn seg is found to exceed dc_maxlights, dc_maxlights will be increased to that value, and dc_lightlist will be reallocated in memory accordingly.

dc_texheight INT32 r_draw.c The height of the source texture or sprite to be drawn to a column on-screen, measured in pixels.

Span drawing code stuff

Externs

Data name Data type Non-extern location(s) Description
ds_y
ds_x1
ds_x2
INT32 r_draw.c The destination screen coordinates that a span is to be drawn to:
  • ds_y is the Y-coordinate the entire span is to be drawn to.
  • ds_x1 and ds_x2 are the left and right X-coordinate bounds the span is to be drawn between, respectively.
*ds_colormap lighttable_t r_draw.c Pointer to the lighttable colormap to be used for drawing a span; e.g.: if ds_colormap == colormaps, the span will be drawn at full brightness. Used by all span drawing functions.
ds_xfrac
ds_yfrac
ds_xstep
ds_ystep
fixed_t r_draw.c ds_xfrac and ds_yfrac are the starting x and y positions of the source flat to draw a span from, respectively.

ds_xstep and ds_ystep are the x and y step values used when drawing a span, respectively. For every pixel stepped horizontally on-screen when drawing a span, the renderer steps ds_xstep>>FRACUNIT pixels left on the source flat, and for every pixel stepped vertically on-screen ds_ystep>>FRACUNIT pixels are stepped down on the source flat.

Note that within all span drawing functions these four values are bit-shifted up by nflatshiftup bits. The current calculated x and y positions are then bit-shifted back down by nflatxshift and nflatyshift bits, respectively.

ds_flatwidth UINT16 r_draw.c
ds_flatheight UINT16 r_draw.c
ds_powersoftwo boolean r_draw.c
*ds_source UINT8 r_draw.c Pointer to the source data of the flat texture to be drawn onto the screen; this contains the palette indexes of the flats's pixels, starting from the top left corner pixel going left through each row. Depending on the drawing function used, these indexes may then be remapped to other indexes based on light level using ds_colormap, and/or translucency using ds_transmap.

This is used by all span drawing functions except R_DrawFogSpan_8.

*ds_transmap UINT8 r_draw.c Pointer to the translucency table to be used for drawing a translucent span; e.g.: if ds_transmap == transtables the span will be drawn with 10% translucency.

This is used by the following span/splat drawing functions:

  • R_DrawTiltedTranslucentSpan_8
  • R_DrawTranslucentSplat_8
  • R_DrawTranslucentSpan_8
  • R_DrawTranslucentWaterSpan_8 (defined in r_plane.c)
*ds_slope pslope_t r_draw.c Declared only if ESLOPE is defined

(Unused)

ds_su
ds_sv
ds_sz
floatv3_t r_draw.c Declared only if ESLOPE is defined

Texture vectors to be used for drawing spans for sloped planes.

These are used by the following span/splat drawing functions:

  • R_DrawTiltedSpan_8
  • R_DrawTiltedTranslucentSpan_8
  • R_DrawTiltedSplat_8
focallengthf
zeroheight
float r_draw.c Declared only if ESLOPE is defined
nflatxshift UINT32 r_draw.c Number of bits to shift calculated x positions back down by in span drawing functions. The value of this differs depending on the flat size:
  • 32×32: 27
  • 64×64: 26
  • 128×128: 25
  • 256×256: 24
  • 512×512: 23
  • 1024×1024: 22
  • 2048×2048: 21

Note that for all flat sizes listed these values are equivalent to 16+nflatshiftup; e.g.: for 64×64 flats this is 16 + 10, or 26.

nflatyshift UINT32 r_draw.c Number of bits to shift calculated y positions back down by in span drawing functions. The value of this differs depending on the flat size:
  • 32×32: 22
  • 64×64: 20
  • 128×128: 18
  • 256×256: 16
  • 512×512: 14
  • 1024×1024: 12
  • 2048×2048: 10

Note that for all flat sizes listed these values are equivalent to 16+nflatshiftup-(number of width bits); e.g.: for 64×64 flats this is 16 + 10 - 6, or 20 (64 is equal to 1<<6).

nflatshiftup UINT32 r_draw.c Number of bits to shift ds_xfrac, ds_yfrac, ds_xstep and ds_ystep up by in span drawing functions. The value of this differs depending on the flat size:
  • 32×32: 11
  • 64×64: 10
  • 128×128: 9
  • 256×256: 8
  • 512×512: 7
  • 1024×1024: 6
  • 2048×2048: 5

These values are chosen to mask out any out-of range x or y positions, by moving the bits of the actual position (FRACBITS (16) + (number of width bits)) so they take up the highest bits of the 32-bit integers used to store the current positions (usually xposition and yposition) in the span drawing functions. Note that for all flat sizes listed these values are equivalent to 16-(number of width bits); e.g.: for 64×64 flats this is 16 - 6, or 10 (64 is equal to 1<<6). This means that 16 + (number of width bits) + nflatshiftup totals to 32 bits.

nflatmask UINT32 r_draw.c Mask for the y position offset. The value of this differs depending on the flat size:
  • 32×32: 0x3E0
  • 64×64: 0xFC0
  • 128×128: 0x3F80
  • 256×256: 0xFF00
  • 512×512: 0x3FE00
  • 1024×1024: 0xFFC00
  • 2048×2048: 0x3FF800

Note that for all flat sizes listed these values are equivalent to (flat size - 1) × (flat size); e.g.: for 64×64 flats this is is 63 × 64, or 4032 (0xFC0 in hexadecimal).

viewborderlump[8] lumpnum_t r_draw.c The array storing patches for the view border. The BRDR_* macros are used with this to get patches for particular edges or corners of the border, e.g. viewborderlump[BRDR_T] gets the patch for the border's top edge. Note that current versions of SRB2 can no longer change the view window's size, so the view border is never drawn.

Structs

floatv3_t

The data structure of a float 3D vector. (Declared only if ESLOPE is defined)

Type name floatv3_t
Data type struct
Data name Data type Description
x
y
z
float The vector's X, Y and Z components

Macros

Macro Defined as Description
BRDR_T 0 The index in viewborderlump storing the patch for the view border's top edge.
BRDR_B 1 The index in viewborderlump storing the patch for the view border's bottom edge.
BRDR_L 2 The index in viewborderlump storing the patch for the view border's left edge.
BRDR_R 3 The index in viewborderlump storing the patch for the view border's right edge.
BRDR_TL 4 The index in viewborderlump storing the patch for the view border's top left corner.
BRDR_TR 5 The index in viewborderlump storing the patch for the view border's top right corner.
BRDR_BL 6 The index in viewborderlump storing the patch for the view border's bottom left corner.
BRDR_BR 7 The index in viewborderlump storing the patch for the view border's bottom right corner.

r_draw.c common routines for both 8bpp and 16bpp

Macros

Macro Defined as Description
GTC_CACHE 1 Flag for R_GetTranslationColormap, to indicate the translation colormap cache should be used.
TC_DEFAULT -1 Special skin number for R_GetTranslationColormap, to get the default colormap, for Objects without a skin. This uses the default starting index (index 96) for the range of 16 palette colors to remap to the given skin color.
TC_BOSS -2 Special skin number for R_GetTranslationColormap, to get the boss flash colormap. This inverts the brightness of black or dark grey pixels.
TC_METALSONIC -3 Special skin number for R_GetTranslationColormap, to get Metal Sonic's boss flash colormap. This inverts the brightness of blue and dark blue pixels.
TC_ALLWHITE -4 Special skin number for R_GetTranslationColormap, to get Brak Eggman's boss flash colormap. This remaps all pixel colors on the sprite to white (index 0).
TC_RAINBOW -5
TC_BLINK -6
TC_DASHMODE -7
TRANSPARENTPIXEL 255

Function prototypes

Function name Return type Params Defined in Description
R_InitTranslationTables void none r_draw.c Initialises the translucency tables, The data from the TRANSxx lumps is loaded into transtables.

(Note: This function formerly initialised the translation colormaps for skin colors as well; these are now handled at runtime by R_GetTranslationColormap instead)

R_GetTranslationColormap UINT8 * INT32 skinnum,
skincolors_t color,
UINT8 flags
r_draw.c Retrieves a translation colormap from the cache. If the colormap is not cached, this generates the colormap for the skin and skin color given and caches it if needed. skinnum can be a skin number, or any of the TC_* constants (for the default colormap, or special colormaps used by non-player Objects). color is the given skin color number. If GTC_CACHE is set in flags, use the cache; if not, the colormap should always be generated (and should be freed manually afterwards).
R_FlushTranslationColormapCache void none r_draw.c Flushes the cache for translation colormaps.
R_GetSuperColorByName UINT8 const char *name r_draw.c Returns the skin color number corresponding with the string given. The name string can be itself a number string, or any valid color names set in Color_Names. If the skin color was not found for the string, returns 0.
R_GetColorByName UINT8 const char *name r_draw.c
R_InitViewBuffer void INT32 width,
INT32 height
r_draw.c Initalises the following variables for the view window:
  • viewwindowx
  • viewwindowy
  • columnofs
  • ylookup
  • ylookup1
  • ylookup2

width and height are the given dimensions of the view window. They cannot exceed MAXVIDWIDTH and MAXVIDHEIGHT, respectively – this function will resize them if this is attempted.

R_InitViewBorder void none r_draw.c Stores the patches for the view border in viewborderlump. Note that current versions of SRB2 can no longer change the view window's size, so the view border is never drawn.
R_VideoErase void size_t ofs,
INT32 count
r_draw.c "Erases" a portion of the screen buffer, from ofs to ofs + count. This in fact just copies a portion of the buffer from screens[1] to screens[0]. This is called by HU_Erase to erase the screen around the view window if using a reduced view size, where the view border would be drawn. However, current versions of SRB2 no longer change the view size, so this is never used.

8bpp drawing code

Function prototypes

Function name Return type Params Defined in Attributes Description
R_DrawColumn_8 void none r_draw8.c Draws a column.
R_DrawShadeColumn_8 void none r_draw8.c Draws a "shaded" column. This was used by wall splats to "shade" pixels rather than recolor them, using the source graphic's palette indexes as the row in COLORMAP to be selected rather than for the actual colors. (Note: This is unused, as wall splats are currently disabled in SRB2.)
R_DrawTranslucentColumn_8 void none r_draw8.c Draws a translucent column.
R_DrawColumn_8_ASM void none tmap.nas ASMCALL Declared only if USEASM is defined

The ASM version of R_DrawColumn_8.

R_DrawShadeColumn_8_ASM void none tmap.nas ASMCALL Declared only if USEASM is defined

The ASM version of R_DrawShadeColumn_8. (Note: This function is unused, because shadecolfunc is always set to the C version by SCR_SetMode.)

R_DrawTranslucentColumn_8_ASM void none tmap.nas ASMCALL Declared only if USEASM is defined

The ASM version of R_DrawTranslucentColumn_8. (Note: This function is unused, because fuzzcolfunc is always set to the C version by SCR_SetMode.)

R_Draw2sMultiPatchColumn_8_ASM void none tmap.nas ASMCALL Declared only if USEASM is defined

The ASM version of R_Draw2sMultiPatchColumn_8.

R_DrawColumn_8_MMX void none tmap_mmx.nas ASMCALL Declared only if USEASM is defined

The MMX version of R_DrawColumn_8.

R_Draw2sMultiPatchColumn_8_MMX void none tmap_mmx.nas ASMCALL Declared only if USEASM is defined

The MMX version of R_Draw2sMultiPatchColumn_8.

R_DrawSpan_8_MMX void none tmap_mmx.nas ASMCALL Declared only if USEASM is defined

The MMX version of R_DrawSpan_8.

R_DrawTranslatedColumn_8 void none r_draw8.c Draws a translated column. Currently only used for drawing sprites with translation maps applied (usually skin colors).
R_DrawTranslatedTranslucentColumn_8 void none r_draw8.c Draws a translated translucent column. Currently only used for drawing sprites with both translucency and translation maps applied (usually skin colors).
R_DrawSpan_8 void none r_draw8.c Draws a span.
R_CalcTiltedLighting void fixed_t start,
fixed_t end
r_draw8.c Declared only if ESLOPE is defined
R_DrawTiltedSpan_8 void none r_draw8.c Declared only if ESLOPE is defined

Draws a tilted span. Used for drawing sloped planes.

R_DrawTiltedTranslucentSpan_8 void none r_draw8.c Declared only if ESLOPE is defined

Draws a tilted translucent span.

R_DrawTiltedSplat_8 void none r_draw8.c Declared only if ESLOPE is defined

Draws a tilted splat span. (Note: Cyan pixels become transparent)

As splats are not enabled in SRB2, this is only used for drawing sloped planes belonging to translucent FOFs with an alpha of #255.

R_DrawSplat_8 void none r_draw8.c Draws a splat span. (Note: cyan pixels become transparent)

As splats are not enabled in SRB2, this is only used for drawing planes belonging to translucent FOFs with an alpha of #255.

R_DrawTranslucentSplat_8 void none r_draw8.c Draws a translucent splat span. (Note: cyan pixels become transparent)

As splats are not enabled in SRB2, this function is unused.

R_DrawTranslucentSpan_8 void none r_draw8.c Draws a translucent span.
R_Draw2sMultiPatchColumn_8 void none r_draw8.c Draws a column such that cyan pixels become transparent (i.e. they are not drawn). This is used for drawing multi-patch textures (or single patch textures without holes) as midtextures for two-sided linedefs.
R_Draw2sMultiPatchTranslucentColumn_8 void none r_draw8.c Draws a translucent column such that cyan pixels become transparent (i.e. they are not drawn). This is used for drawing multi-patch textures (or single patch textures without holes) as midtextures for two-sided linedefs which also have translucency applied.
R_DrawFogSpan_8 void none r_draw8.c Draws a "fog" span. This simply applies a colormap to the colors already on the screen.
R_DrawFogColumn_8 void none r_draw8.c Draws a "fog" column. This simply applies a colormap to the colors already on the screen.
R_DrawColumnShadowed_8 void none r_draw8.c Draws a column affected by FOF lighting/colormaps. This splits the column into several pieces and draws the pieces separately. Any parts of the column covered by an FOF with FF_CUTSOLIDS (i.e. the FOF cuts solid pixels) will not be drawn.
R_DrawTranslucentWaterSpan_8 void none r_draw8.c Declared only if NOWATER is not defined

Macros

Macro Defined as Description
R_DrawWallColumn_8 R_DrawColumn_8 Draws a wall column.
R_DrawWallColumn_8_ASM R_DrawColumn_8_ASM Defined only if USEASM is defined

The ASM version of R_DrawWallColumn_8.

R_DrawWallColumn_8_MMX R_DrawColumn_8_MMX Defined only if USEASM is defined

The MMX version of R_DrawWallColumn_8.

Externs

Data name Data type Non-extern location(s) Description
ds_bgofs INT32 r_plane.c Declared only if NOWATER is not defined
ds_waterofs INT32 r_plane.c Declared only if NOWATER is not defined

16bpp drawing code (HIGHCOLOR-only)

Function prototypes

Function name Return type Params Defined in Description
R_DrawColumn_16 void none r_draw16.c Draws a column.
R_DrawWallColumn_16 void none r_draw16.c Draws a wall column.
R_DrawTranslucentColumn_16 void none r_draw16.c Draws a translucent column.
R_DrawTranslatedColumn_16 void none r_draw16.c Draws a translated column.
R_DrawSpan_16 void none r_draw16.c Draws a span.