67 lines
3 KiB
C
67 lines
3 KiB
C
// Renderer: 2D primitives that operate on the software framebuffer
|
|
// and the colour state shared with the scenery interpreter.
|
|
|
|
#ifndef RENDERER_H
|
|
#define RENDERER_H
|
|
|
|
#include "framebuffer.h"
|
|
#include "palette.h"
|
|
#include "types.h"
|
|
|
|
// Active framebuffer / colour state. The scenery VM reads these so
|
|
// individual opcodes need only set the colour and call the line or
|
|
// span primitives. `hiresColor` is the chunk5 ToHiresColorTable code
|
|
// (HIRES_BLACK1 / HIRES_VIOLET / HIRES_GREEN / HIRES_WHITE1 etc.) the
|
|
// hires bitplane primitives use. `drawColor` stays the legacy palette
|
|
// index for the panel-area renderers that haven't moved to the
|
|
// bitplane yet.
|
|
typedef struct RenderStateT {
|
|
FramebufferT *fb;
|
|
ColorE fillColor;
|
|
ColorE altFillColor;
|
|
ColorE drawColor;
|
|
uint8_t hiresColor;
|
|
uint8_t hiresFill;
|
|
uint8_t hiresAltFill;
|
|
} RenderStateT;
|
|
|
|
void rendererBegin(RenderStateT *state, FramebufferT *fb);
|
|
void rendererSetDrawColor(RenderStateT *state, ColorE color);
|
|
void rendererSetHiresColor(RenderStateT *state, uint8_t hiresCode);
|
|
void rendererSetFillColors(RenderStateT *state, ColorE fill, ColorE altFill);
|
|
void rendererSwapFillColors(RenderStateT *state);
|
|
|
|
void rendererDrawLine(RenderStateT *state, int16_t x1, int16_t y1, int16_t x2, int16_t y2);
|
|
|
|
// Horizontal color-pixel span at color-column space (0..139).
|
|
// `xRight` is the rightmost color column, walking leftward for `length+1`
|
|
// pixels. Mirrors chunk5's DrawColorSpan ($78E0). Used by the polygon
|
|
// scan-line fill (chunk5.s L7826+).
|
|
void rendererDrawColorSpan(RenderStateT *state, int16_t xRight, int16_t length, int16_t y);
|
|
|
|
// Scan-line fill of an arbitrary polygon. Vertices are color-pixel
|
|
// coordinates (xColor 0..139, y 0..191). Mirrors chunk5's L7724+
|
|
// polygon edge rasterizer that walks edges per row, sorts intersections,
|
|
// and emits paired DrawColorSpan calls. The current `hiresColor` is
|
|
// used as the fill color.
|
|
void rendererFillPolygon(RenderStateT *state, const int16_t *xs, const int16_t *ys, int count);
|
|
void rendererFillSkyAndGround(RenderStateT *state, int16_t horizonRow);
|
|
|
|
// Same idea as `rendererFillSkyAndGround` but the divide line is
|
|
// tilted by `bankSin`/`bankCos` (Q1.15: -32767..+32767, the
|
|
// `math6502Sin/Cos` output) and centred on `(horizonX, horizonY)`.
|
|
// Pixels strictly above the line use `altFillColor` (sky) and below
|
|
// use `fillColor` (ground).
|
|
void rendererFillTiltedSkyGround(RenderStateT *state, int16_t horizonX, int16_t horizonY, int16_t bankSin, int16_t bankCos);
|
|
|
|
// Draw a wing-strut / tail overlay over a side / rear viewport. FS2
|
|
// chunk3 DrawWingsOrTail fills a trapezoid of color spans in a fixed
|
|
// pattern per view-direction; we render a filled triangle at the
|
|
// matching corner of the viewport so the player can see the wingtip
|
|
// in F2/F4, vertical fin in F3, wheel well in F5.
|
|
// viewDir : 0=FORWARD, 1=RIGHT, 2=BACK, 3=LEFT, 4=DOWN (matches
|
|
// ViewDirectionE in aircraft.h)
|
|
// FORWARD draws nothing.
|
|
void rendererDrawWingOverlay(RenderStateT *state, int viewDir);
|
|
|
|
#endif
|