Skip to content

Commit

Permalink
Rewritten blit functions to support 32bpp.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrd2 committed Oct 29, 2018
1 parent 1000a57 commit fed7f8f
Show file tree
Hide file tree
Showing 17 changed files with 236 additions and 435 deletions.
3 changes: 0 additions & 3 deletions src/game/Init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ try
// INit shade tables
BuildShadeTable( );

// INit intensity tables
BuildIntensityTable( );

// Init Event Manager
InitializeEventManager();

Expand Down
2 changes: 1 addition & 1 deletion src/game/Strategic/MapScreen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6982,7 +6982,7 @@ static void CheckForAndRenderNewMailOverlay(void)
SGPRect area = { (UINT16)(STD_SCREEN_X + 463), (UINT16)(STD_SCREEN_Y + 417), (UINT16)(STD_SCREEN_X + 477), (UINT16)(STD_SCREEN_Y + 425) };

SGPVSurface::Lock l(FRAME_BUFFER);
Blt16BPPBufferHatchRect(l.Buffer<UINT16>(), l.Pitch(), &area);
Blt32BPPBufferHatchRect(l.Buffer<UINT16>(), l.Pitch(), &area);
}
InvalidateRegion( STD_SCREEN_X + 463, STD_SCREEN_Y + 417, STD_SCREEN_X + 481, STD_SCREEN_Y + 430 );

Expand Down
2 changes: 1 addition & 1 deletion src/game/Tactical/Interface_Panels.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ void RenderSMPanel(DirtyLevel* const dirty_level)
ClipRect.iTop = INV_INTERFACE_START_Y;
ClipRect.iBottom = SCREEN_HEIGHT;
SGPVSurface::Lock l(FRAME_BUFFER);
Blt16BPPBufferHatchRect(l.Buffer<UINT16>(), l.Pitch(), &ClipRect);
Blt32BPPBufferHatchRect(l.Buffer<UINT16>(), l.Pitch(), &ClipRect);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/Tactical/ShopKeeper_Interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2418,7 +2418,7 @@ void DrawHatchOnInventory(SGPVSurface* const uiSurface, const UINT16 usPosX, con
ClipRect.iBottom = usPosY + usHeight - 1;

SGPVSurface::Lock l(uiSurface);
Blt16BPPBufferHatchRect(l.Buffer<UINT16>(), l.Pitch(), &ClipRect);
Blt32BPPBufferHatchRect(l.Buffer<UINT16>(), l.Pitch(), &ClipRect);
}


Expand Down
12 changes: 6 additions & 6 deletions src/game/TileEngine/Overhead_Map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ void RenderOverheadMap(INT16 const sStartPointX_M, INT16 const sStartPointY_M, I
INT16 const sX = sTempPosX_S;
INT16 const sY = sTempPosY_S - sHeight + gsRenderHeight / 5;
pTile.vo->CurrentShade(n->ubShadeLevel);
Blt8BPPDataTo16BPPBufferTransparent(
Blt32BPPDataTo32BPPBufferTransparent(
reinterpret_cast<UINT32 *>(pDestBuf), // FIXME: maxrd2
uiDestPitchBYTES, pTile.vo, sX, sY, pTile.usSubIndex);
}
Expand Down Expand Up @@ -581,7 +581,7 @@ void RenderOverheadMap(INT16 const sStartPointX_M, INT16 const sStartPointY_M, I
sY += gsRenderHeight / 5;

pTile.vo->CurrentShade(n->ubShadeLevel);
Blt8BPPDataTo16BPPBufferTransparent(
Blt32BPPDataTo32BPPBufferTransparent(
reinterpret_cast<UINT32 *>(pDestBuf), // FIXME: maxrd2
uiDestPitchBYTES, pTile.vo, sX, sY, pTile.usSubIndex);
}
Expand Down Expand Up @@ -622,7 +622,7 @@ void RenderOverheadMap(INT16 const sStartPointX_M, INT16 const sStartPointY_M, I
sY += gsRenderHeight / 5;

pTile.vo->CurrentShade(n->ubShadeLevel);
Blt8BPPDataTo16BPPBufferTransparent(
Blt32BPPDataTo32BPPBufferTransparent(
reinterpret_cast<UINT32 *>(pDestBuf), // FIXME: maxrd2
uiDestPitchBYTES, pTile.vo, sX, sY, pTile.usSubIndex);
}
Expand Down Expand Up @@ -685,7 +685,7 @@ void RenderOverheadMap(INT16 const sStartPointX_M, INT16 const sStartPointY_M, I
pTile.vo->CurrentShade(n->ubShadeLevel);

// RENDER!
Blt8BPPDataTo16BPPBufferTransparent(
Blt32BPPDataTo32BPPBufferTransparent(
reinterpret_cast<UINT32 *>(pDestBuf), // FIXME: maxrd2
uiDestPitchBYTES, pTile.vo, sX, sY, pTile.usSubIndex);
}
Expand Down Expand Up @@ -791,7 +791,7 @@ static void RenderOverheadOverlays(void)

if (gfEditMode && GameState::getInstance()->isEditorMode() && gpSelected && gpSelected->pSoldier == &s)
{ //editor: show the selected edited merc as the yellow one.
Blt8BPPDataTo16BPPBufferTransparent(
Blt32BPPDataTo32BPPBufferTransparent(
reinterpret_cast<UINT32 *>(pDestBuf), // FIXME: maxrd2
uiDestPitchBYTES, marker, sX, sY, 0);
}
Expand All @@ -803,7 +803,7 @@ static void RenderOverheadOverlays(void)
&s == gpTacticalPlacementSelectedSoldier ? 7 :
&s == gpTacticalPlacementHilightedSoldier && s.uiStatusFlags ? 8 :
s.bTeam;
Blt8BPPDataTo16BPPBufferTransparent(
Blt32BPPDataTo32BPPBufferTransparent(
reinterpret_cast<UINT32 *>(pDestBuf), // FIXME: maxrd2
uiDestPitchBYTES, marker, sX, sY, region);
ETRLEObject const& e = marker->SubregionProperties(region);
Expand Down
8 changes: 4 additions & 4 deletions src/game/TileEngine/RenderWorld.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,7 @@ static void RenderTiles(RenderTilesFlags const uiFlags, INT32 const iStartPointX
}
else
{
Blt8BPPDataTo16BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, hVObject, sXPos, sYPos, usImageIndex, &gClippingRect);
Blt32BPPDataTo32BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, hVObject, sXPos, sYPos, usImageIndex, &gClippingRect);
}
}
else
Expand Down Expand Up @@ -1384,7 +1384,7 @@ static void RenderTiles(RenderTilesFlags const uiFlags, INT32 const iStartPointX
}
else
{
Blt8BPPDataTo16BPPBufferShadowClip(pDestBuf, uiDestPitchBYTES, hVObject, sXPos, sYPos, usImageIndex, &gClippingRect);
Blt32BPPDataTo32BPPBufferShadowClip(pDestBuf, uiDestPitchBYTES, hVObject, sXPos, sYPos, usImageIndex, &gClippingRect);
}
}
else if (fIntensityBlitter)
Expand Down Expand Up @@ -1436,7 +1436,7 @@ static void RenderTiles(RenderTilesFlags const uiFlags, INT32 const iStartPointX
}
else
{
Blt8BPPDataTo16BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, hVObject, sXPos, sYPos, usImageIndex, &gClippingRect);
Blt32BPPDataTo32BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, hVObject, sXPos, sYPos, usImageIndex, &gClippingRect);
}
}
else if (bBlitClipVal == FALSE)
Expand Down Expand Up @@ -1556,7 +1556,7 @@ static void RenderTiles(RenderTilesFlags const uiFlags, INT32 const iStartPointX
}
else
{
Blt8BPPDataTo16BPPBufferTransparent(
Blt32BPPDataTo32BPPBufferTransparent(
reinterpret_cast<UINT32 *>(pDestBuf), // FIXME: maxrd2
uiDestPitchBYTES, hVObject, sXPos, sYPos, usImageIndex);
}
Expand Down
10 changes: 6 additions & 4 deletions src/game/TileEngine/Render_Dirty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,10 @@ BACKGROUND_SAVE* RegisterBackgroundRect(BackgroundFlags const uiFlags, INT16 sLe
const UINT32 uiBufSize = (sRight - sLeft) * (sBottom - sTop);
if (uiBufSize == 0) return NO_BGND_RECT;

if (uiFlags & BGND_FLAG_SAVERECT) b->pSaveArea = MALLOCN(UINT16, uiBufSize);
if (uiFlags & BGND_FLAG_SAVE_Z) b->pZSaveArea = MALLOCN(UINT16, uiBufSize);
if (uiFlags & BGND_FLAG_SAVERECT)
b->pSaveArea = reinterpret_cast<UINT16 *>(MALLOCN(UINT32, uiBufSize));
if (uiFlags & BGND_FLAG_SAVE_Z)
b->pZSaveArea = reinterpret_cast<UINT16 *>(MALLOCN(UINT32, uiBufSize));

b->fFreeMemory = TRUE;
b->fAllocated = TRUE;
Expand Down Expand Up @@ -273,11 +275,11 @@ void SaveBackgroundRects(void)

if (b->pSaveArea != NULL)
{
Blt16BPPTo16BPP(b->pSaveArea, b->sWidth * 2, pSrcBuf, uiDestPitchBYTES, 0, 0, b->sLeft, b->sTop, b->sWidth, b->sHeight);
Blt16BPPTo16BPP(b->pSaveArea, b->sWidth * 4, pSrcBuf, uiDestPitchBYTES, 0, 0, b->sLeft, b->sTop, b->sWidth, b->sHeight);
}
else if (b->pZSaveArea != NULL)
{
Blt16BPPTo16BPP(b->pZSaveArea, b->sWidth * 2, gpZBuffer, uiDestPitchBYTES, 0, 0, b->sLeft, b->sTop, b->sWidth, b->sHeight);
Blt16BPPTo16BPP(b->pZSaveArea, b->sWidth * 4, gpZBuffer, uiDestPitchBYTES, 0, 0, b->sLeft, b->sTop, b->sWidth, b->sHeight);
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions src/game/TileEngine/Tactical_Placement_GUI.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ static void RenderTacticalPlacementGUI()
BlitBufferToBuffer(guiSAVEBUFFER, buf, STD_SCREEN_X + 4, STD_SCREEN_Y + 4, 636, 320);
InvalidateRegion(STD_SCREEN_X + 4, STD_SCREEN_Y + 4, STD_SCREEN_X + 636, STD_SCREEN_Y + 320);

UINT16 const hatch_colour =
const UINT32 hatch_colour =
DayTime() ? 0 : // 6AM to 9PM is black
Get16BPPColor(FROMRGB(63, 31, 31)); // 9PM to 6AM is gray (black is too dark to distinguish)
RGB(63, 31, 31); // 9PM to 6AM is gray (black is too dark to distinguish)
SGPRect clip = { (UINT16)(STD_SCREEN_X + 4), (UINT16)(STD_SCREEN_Y + 4), (UINT16)(STD_SCREEN_X + 636), (UINT16)(STD_SCREEN_Y + 320) };
if (gbCursorMercID == -1)
{
Expand All @@ -321,7 +321,7 @@ static void RenderTacticalPlacementGUI()
SGPVSurface::Lock l(buf);
UINT16* const pDestBuf = l.Buffer<UINT16>();
UINT32 const uiDestPitchBYTES = l.Pitch();
Blt16BPPBufferLooseHatchRectWithColor(pDestBuf, uiDestPitchBYTES, &clip, hatch_colour);
Blt32BPPBufferLooseHatchRectWithColor(pDestBuf, uiDestPitchBYTES, &clip, hatch_colour);
SetClippingRegionAndImageWidth(uiDestPitchBYTES, STD_SCREEN_X + 0, STD_SCREEN_Y + 0, 640, 480);
RectangleDraw(TRUE, clip.iLeft, clip.iTop, clip.iRight, clip.iBottom, hatch_colour, pDestBuf);
}
Expand Down
18 changes: 9 additions & 9 deletions src/sgp/Button_System.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ static void DrawHatchOnButton(const GUI_BUTTON* b)
ClipRect.iTop = b->Y();
ClipRect.iBottom = b->BottomRightY() - 1;
SGPVSurface::Lock l(ButtonDestBuffer);
Blt16BPPBufferHatchRect(l.Buffer<UINT16>(), l.Pitch(), &ClipRect);
Blt32BPPBufferHatchRect(l.Buffer<UINT16>(), l.Pitch(), &ClipRect);
}


Expand Down Expand Up @@ -1607,27 +1607,27 @@ static void DrawGenericButton(const GUI_BUTTON* b)
{
INT32 const ImgNum = (q == 0 ? 0 : 1);
INT32 const x = bx + q * iBorderWidth;
Blt8BPPDataTo16BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, x, by, ImgNum, &ClipRect);
Blt8BPPDataTo16BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, x, cy, ImgNum + 5, &ClipRect);
Blt32BPPDataTo32BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, x, by, ImgNum, &ClipRect);
Blt32BPPDataTo32BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, x, cy, ImgNum + 5, &ClipRect);
}
// Blit the right side corners
Blt8BPPDataTo16BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, cx, by, 2, &ClipRect);
Blt8BPPDataTo16BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, cx, cy, 7, &ClipRect);
Blt32BPPDataTo32BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, cx, by, 2, &ClipRect);
Blt32BPPDataTo32BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, cx, cy, 7, &ClipRect);
// Draw the vertical members of the button's borders
NumChunksHigh--;

if (hremain != 0)
{
INT32 const y = by + NumChunksHigh * iBorderHeight - iBorderHeight + hremain;
Blt8BPPDataTo16BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, bx, y, 3, &ClipRect);
Blt8BPPDataTo16BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, cx, y, 4, &ClipRect);
Blt32BPPDataTo32BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, bx, y, 3, &ClipRect);
Blt32BPPDataTo32BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, cx, y, 4, &ClipRect);
}

for (INT32 q = 1; q < NumChunksHigh; q++)
{
INT32 const y = by + q * iBorderHeight;
Blt8BPPDataTo16BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, bx, y, 3, &ClipRect);
Blt8BPPDataTo16BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, cx, y, 4, &ClipRect);
Blt32BPPDataTo32BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, bx, y, 3, &ClipRect);
Blt32BPPDataTo32BPPBufferTransparentClip(pDestBuf, uiDestPitchBYTES, BPic, cx, y, 4, &ClipRect);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/sgp/Font.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ void gprintf(INT32 x, INT32 const y, wchar_t const* fmt, ...)
for (wchar_t const* i = string; *i != L'\0'; ++i)
{
GlyphIdx const glyph = GetGlyphIndex(*i);
Blt8BPPDataTo16BPPBufferTransparentClip(buf, pitch, font, x, y, glyph, &FontDestRegion);
Blt32BPPDataTo32BPPBufferTransparentClip(buf, pitch, font, x, y, glyph, &FontDestRegion);
x += GetWidth(font, glyph);
}
}
Expand Down
33 changes: 6 additions & 27 deletions src/sgp/Shading.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
#include "Shading.h"
#include "VObject.h"

UINT16 IntensityTable[65536];
UINT16 ShadeTable[65536];
UINT16 White16BPPPalette[256];
static float guiShadePercent = 0.48f;

float gShadowShadePercent = 0.48f;
float gIntensityShadePercent = 0.80f;



/* Builds a 16-bit color shading table. This function should be called only
Expand All @@ -25,7 +27,7 @@ void BuildShadeTable(void)
for (UINT16 blue = 0; blue < 256; blue += 4)
{
UINT16 index = Get16BPPColor(FROMRGB(red, green, blue));
ShadeTable[index] = Get16BPPColor(FROMRGB(red * guiShadePercent, green * guiShadePercent, blue * guiShadePercent));
ShadeTable[index] = Get16BPPColor(FROMRGB(red * gShadowShadePercent, green * gShadowShadePercent, blue * gShadowShadePercent));
}
}
}
Expand All @@ -34,31 +36,8 @@ void BuildShadeTable(void)
}


/* Builds a 16-bit color shading table. This function should be called only
* after the current video adapter's pixel format is known (IE:
* GetRgbDistribution() has been called, and the globals for masks and shifts
* have been initialized by that function), and before any blitting is done.
*/
void BuildIntensityTable(void)
{
const float dShadedPercent = 0.80f;

for (UINT16 red = 0; red < 256; red += 4)
{
for (UINT16 green = 0; green < 256; green += 4)
{
for (UINT16 blue = 0; blue < 256; blue += 4)
{
UINT16 index = Get16BPPColor(FROMRGB(red, green, blue));
IntensityTable[index] = Get16BPPColor(FROMRGB(red * dShadedPercent, green * dShadedPercent, blue * dShadedPercent));
}
}
}
}


void SetShadeTablePercent(float uiShadePercent)
{
guiShadePercent = uiShadePercent;
gShadowShadePercent = uiShadePercent;
BuildShadeTable();
}
5 changes: 3 additions & 2 deletions src/sgp/Shading.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#define SHADING_H

void BuildShadeTable(void);
void BuildIntensityTable(void);
void SetShadeTablePercent(float uiShadePercent);

extern UINT16 IntensityTable[65536];
extern float gShadowShadePercent;
extern float gIntensityShadePercent;

extern UINT16 ShadeTable[65536];
extern UINT16 White16BPPPalette[256];

Expand Down
5 changes: 2 additions & 3 deletions src/sgp/VObject.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,13 @@ void BltVideoObject(SGPVSurface* const dst, SGPVObject const* const src, UINT16

if (BltIsClipped(src, iDestX, iDestY, usRegionIndex, &ClippingRect))
{
Assert(src->BPP() == 8); // maxrd2
Blt8BPPDataTo16BPPBufferTransparentClip(
Blt32BPPDataTo32BPPBufferTransparentClip(
reinterpret_cast<UINT16 *>(pBuffer), // FIXME: maxrd2
uiPitch, src, iDestX, iDestY, usRegionIndex, &ClippingRect);
}
else
{
Blt8BPPDataTo16BPPBufferTransparent(pBuffer, uiPitch, src, iDestX, iDestY, usRegionIndex);
Blt32BPPDataTo32BPPBufferTransparent(pBuffer, uiPitch, src, iDestX, iDestY, usRegionIndex);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/sgp/VObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct ZStripInfo
// From RGB to COLORVAL
#define FROMRGB(r, g ,b) ((UINT32) (((UINT8) (r) | ((UINT16) (g) << 8)) | (((UINT32) (UINT8) (b)) << 16)))

#define RGBA(r, g, b, a) (UINT32(r) << 24 | UINT32(g) << 16 | UINT32(b) << 8 | UINT32(a))
#define RGB(r, g, b) (UINT32(r) << 24 | UINT32(g) << 16 | UINT32(b) << 8 | 0xFF)

// This structure is a video object.
// The video object contains different data based on it's type, compressed or not
class SGPVObject
Expand Down

0 comments on commit fed7f8f

Please sign in to comment.