- Added versions of Dim and Clear to D3DFB for use in 2D mode.

- Added a new color parameter to DCanvas::Clear() that specifies the
  ARGB value of the color. This is used if the old color parameter,
  which specifies a palette entry, is -1.


SVN r617 (trunk)
This commit is contained in:
Randy Heit 2007-12-22 04:52:51 +00:00
parent e84bece8eb
commit dddc781f18
18 changed files with 187 additions and 48 deletions

View file

@ -1,4 +1,8 @@
December 21, 2007
- Added versions of Dim and Clear to D3DFB for use in 2D mode.
- Added a new color parameter to DCanvas::Clear() that specifies the
ARGB value of the color. This is used if the old color parameter,
which specifies a palette entry, is -1.
- Fixed: TEAMINFO broke bot parsing for bots with invalid team names by
redefining TEAM_None from 255 to -1.

View file

@ -1095,7 +1095,7 @@ void AM_clearFB (int color)
{
if (mapback == NULL || !am_drawmapback)
{
screen->Clear (0, 0, f_w, f_h, color);
screen->Clear (0, 0, f_w, f_h, color, 0);
}
else
{

View file

@ -1163,7 +1163,7 @@ void C_DrawConsole ()
TAG_DONE);
if (conline && visheight < screen->GetHeight())
{
screen->Clear (0, visheight, screen->GetWidth(), visheight+1, 0);
screen->Clear (0, visheight, screen->GetWidth(), visheight+1, 0, 0);
}
if (ConBottom >= 12)

View file

@ -595,7 +595,7 @@ void D_Display (bool screenshot)
break;
}
}
//screen->Begin2D();
// draw pause pic
if (paused && menuactive == MENU_Off)
{
@ -820,7 +820,7 @@ void D_PageDrawer (void)
}
else
{
screen->Clear (0, 0, SCREENWIDTH, SCREENHEIGHT, 0);
screen->Clear (0, 0, SCREENWIDTH, SCREENHEIGHT, 0, 0);
if (!PageBlank)
{
screen->DrawText (CR_WHITE, 0, 0, "Page graphic goes here", TAG_DONE);

View file

@ -1197,7 +1197,7 @@ void F_Drawer (void)
}
else
{
screen->Clear (0, 0, SCREENWIDTH, SCREENHEIGHT, 0);
screen->Clear (0, 0, SCREENWIDTH, SCREENHEIGHT, 0, 0);
}
}
else

View file

@ -294,10 +294,10 @@ static void HU_DrawPlayer (player_t *player, bool highlight, int x, int y, int h
D_GetPlayerColor (player - players, &h, &s, &v);
HSVtoRGB (&r, &g, &b, h, s, v);
color = ColorMatcher.Pick (clamp (int(r*255.f),0,255),
clamp (int(g*255.f),0,255), clamp (int(b*255.f),0,255));
screen->Clear (SCREENWIDTH / 24, y, SCREENWIDTH / 24 + 24*CleanXfac, y + height, color);
screen->Clear (SCREENWIDTH / 24, y, SCREENWIDTH / 24 + 24*CleanXfac, y + height, -1,
MAKEARGB(255,clamp(int(r*255.f),0,255),
clamp(int(g*255.f),0,255),
clamp(int(b*255.f),0,255)));
if (teamplay)
{

View file

@ -1084,7 +1084,7 @@ static void M_DrawSaveLoadCommon ()
else
{
screen->Clear (savepicLeft, savepicTop,
savepicLeft+savepicWidth, savepicTop+savepicHeight, 0);
savepicLeft+savepicWidth, savepicTop+savepicHeight, 0, 0);
if (!SaveGames.IsEmpty ())
{
@ -1101,7 +1101,7 @@ static void M_DrawSaveLoadCommon ()
// Draw comment area
M_DrawFrame (commentLeft, commentTop, commentWidth, commentHeight);
screen->Clear (commentLeft, commentTop, commentRight, commentBottom, 0);
screen->Clear (commentLeft, commentTop, commentRight, commentBottom, 0, 0);
if (SaveComment != NULL)
{
// I'm not sure why SaveComment would go NULL in this loop, but I got
@ -1119,7 +1119,7 @@ static void M_DrawSaveLoadCommon ()
do
{
M_DrawFrame (listboxLeft, listboxTop, listboxWidth, listboxHeight);
screen->Clear (listboxLeft, listboxTop, listboxRight, listboxBottom, 0);
screen->Clear (listboxLeft, listboxTop, listboxRight, listboxBottom, 0, 0);
if (SaveGames.IsEmpty ())
{
@ -1156,8 +1156,8 @@ static void M_DrawSaveLoadCommon ()
if (node == SelSaveGame)
{
screen->Clear (listboxLeft, listboxTop+rowHeight*i,
listboxRight, listboxTop+rowHeight*(i+1),
ColorMatcher.Pick (genStringEnter ? 255 : 0, 0, genStringEnter ? 0 : 255));
listboxRight, listboxTop+rowHeight*(i+1), -1,
genStringEnter ? MAKEARGB(255,255,0,0) : MAKEARGB(255,0,0,255));
didSeeSelected = true;
if (!genStringEnter)
{
@ -1671,7 +1671,7 @@ static void M_DrawClassMenu ()
if (!FireScreen)
{
screen->Clear (x, y, x + 72 * CleanXfac, y + 80 * CleanYfac-1, 0);
screen->Clear (x, y, x + 72 * CleanXfac, y + 80 * CleanYfac-1, 0, 0);
}
else
{
@ -2091,7 +2091,7 @@ static void M_PlayerSetupDrawer ()
y = (y-100)*CleanYfac+(SCREENHEIGHT>>1);
if (!FireScreen)
{
screen->Clear (x, y, x + 72 * CleanXfac, y + 80 * CleanYfac-1, 0);
screen->Clear (x, y, x + 72 * CleanXfac, y + 80 * CleanYfac-1, 0, 0);
}
else
{

View file

@ -1698,7 +1698,7 @@ void M_OptDrawer ()
box_x = (CurrentMenu->indent - 35 - 160) * CleanXfac + screen->GetWidth()/2;
box_y = (y - ((gameinfo.gametype & GAME_Raven) ? 99 : 100)) * CleanYfac + screen->GetHeight()/2;
screen->Clear (box_x, box_y, box_x + 32*CleanXfac, box_y + (fontheight-1)*CleanYfac,
item->a.colorcvar->GetIndex());
item->a.colorcvar->GetIndex(), 0);
}
break;
@ -1714,10 +1714,11 @@ void M_OptDrawer ()
box_x = (CurrentMenu->indent - 32 - 160) * CleanXfac + screen->GetWidth()/2;
for (x1 = 0, p = int(item->b.min * 16); x1 < 16; ++p, ++x1)
{
screen->Clear (box_x, box_y, box_x + w, box_y + h, p);
screen->Clear (box_x, box_y, box_x + w, box_y + h, p, 0);
if (p == CurrColorIndex || (i == CurrentItem && x1 == SelColorIndex))
{
int r, g, b, col;
int r, g, b;
DWORD col;
double blinky;
if (i == CurrentItem && x1 == SelColorIndex)
{
@ -1730,12 +1731,12 @@ void M_OptDrawer ()
// Make sure the cursors stand out against similar colors
// by pulsing them.
blinky = fabs(sin(I_MSTime()/1000.0)) * 0.5 + 0.5;
col = ColorMatcher.Pick (int(r*blinky), int(g*blinky), int(b*blinky));
col = MAKEARGB(255,int(r*blinky),int(g*blinky),int(b*blinky));
screen->Clear (box_x, box_y, box_x + w, box_y + 1, col);
screen->Clear (box_x, box_y + h-1, box_x + w, box_y + h, col);
screen->Clear (box_x, box_y, box_x + 1, box_y + h, col);
screen->Clear (box_x + w - 1, box_y, box_x + w, box_y + h, col);
screen->Clear (box_x, box_y, box_x + w, box_y + 1, -1, col);
screen->Clear (box_x, box_y + h-1, box_x + w, box_y + h, -1, col);
screen->Clear (box_x, box_y, box_x + 1, box_y + h, -1, col);
screen->Clear (box_x + w - 1, box_y, box_x + w, box_y + h, -1, col);
}
box_x += w;
}
@ -2555,17 +2556,17 @@ static void DefaultCustomColors ()
static void ColorPickerDrawer ()
{
int newColorIndex = ColorMatcher.Pick (
DWORD newColor = MAKEARGB(255,
int(ColorPickerItems[2].a.fval),
int(ColorPickerItems[3].a.fval),
int(ColorPickerItems[4].a.fval));
int oldColorIndex = ColorPickerItems[0].a.colorcvar->GetIndex();
DWORD oldColor = DWORD(*ColorPickerItems[0].a.colorcvar) | 0xFF000000;
int x = screen->GetWidth()*2/3;
int y = (15 + BigFont->GetHeight() + SmallFont->GetHeight()*2 - 102) * CleanYfac + screen->GetHeight()/2;
screen->Clear (x, y, x + 48*CleanXfac, y + 48*CleanYfac, oldColorIndex);
screen->Clear (x + 48*CleanXfac, y, x + 48*2*CleanXfac, y + 48*CleanYfac, newColorIndex);
screen->Clear (x, y, x + 48*CleanXfac, y + 48*CleanYfac, -1, oldColor);
screen->Clear (x + 48*CleanXfac, y, x + 48*2*CleanXfac, y + 48*CleanYfac, -1, newColor);
y += 49*CleanYfac;
screen->DrawText (CR_GRAY, x+(24-SmallFont->StringWidth("Old")/2)*CleanXfac, y,

View file

@ -1789,7 +1789,7 @@ void R_DrawBorder (int x1, int y1, int x2, int y2)
}
else
{
screen->Clear (x1, y1, x2, y2, 0);
screen->Clear (x1, y1, x2, y2, 0, 0);
}
}

View file

@ -1577,7 +1577,7 @@ void R_RenderActorView (AActor *actor, bool dontmaplines)
// draw a black line at the bottom of the view window.
if (detailyshift && viewwindowy == 0 && (realviewheight & 1))
{
screen->Clear (0, realviewheight-1, realviewwidth, realviewheight, 0);
screen->Clear (0, realviewheight-1, realviewwidth, realviewheight, 0, 0);
}
R_SetupBuffer (false);

View file

@ -676,7 +676,7 @@ void drawpolymosttest()
fcol = 0; ccol = 0;
RenderTarget->Clear(0, 0, RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0);
RenderTarget->Clear(0, 0, RenderTarget->GetWidth(), RenderTarget->GetHeight(), 0, 0);
for (vsp = ovsp->Next; vsp->Next != &TestPoly.UsedList; ovsp = vsp, vsp = nvsp)
{
nvsp = vsp->Next;

View file

@ -601,10 +601,10 @@ void DCanvas::FillBorder (FTexture *img)
}
else
{
Clear (0, 0, Width, bordtop, 0); // Top
Clear (0, bordtop, bordleft, Height - bordbottom, 0); // Left
Clear (Width - bordright, bordtop, Width, Height - bordbottom, 0); // Right
Clear (0, Height - bordbottom, Width, Height, 0); // Bottom
Clear (0, 0, Width, bordtop, 0, 0); // Top
Clear (0, bordtop, bordleft, Height - bordbottom, 0, 0); // Left
Clear (Width - bordright, bordtop, Width, Height - bordbottom, 0, 0); // Right
Clear (0, Height - bordbottom, Width, Height, 0, 0); // Bottom
}
}

View file

@ -226,7 +226,7 @@ void DCanvas::FlatFill (int left, int top, int right, int bottom, FTexture *src)
// [RH] Set an area to a specified color
void DCanvas::Clear (int left, int top, int right, int bottom, int color) const
void DCanvas::Clear (int left, int top, int right, int bottom, int palcolor, uint32 color) const
{
int x, y;
BYTE *dest;
@ -236,14 +236,33 @@ void DCanvas::Clear (int left, int top, int right, int bottom, int color) const
return;
}
assert (left < right);
assert (top < bottom);
assert(left < right);
assert(top < bottom);
if (palcolor < 0)
{
if (APART(color) != 255)
{
Dim(color, APART(color)/255.f, left, top, right - left, bottom - top);
return;
}
// Quick check for black.
if (color == MAKEARGB(255,0,0,0))
{
palcolor = 0;
}
else
{
palcolor = ColorMatcher.Pick(RPART(color), GPART(color), BPART(color));
}
}
dest = Buffer + top * Pitch + left;
x = right - left;
for (y = top; y < bottom; y++)
{
memset (dest, color, x);
memset(dest, palcolor, x);
dest += Pitch;
}
}
@ -689,7 +708,7 @@ void DFrameBuffer::DrawRateStuff ()
chars = sprintf (fpsbuff, "%2u ms (%3u fps)", howlong, LastCount);
RateX = Width - chars * 8;
Clear (RateX, 0, Width, 8, 0);
Clear (RateX, 0, Width, 8, 0, 0);
SetFont (ConFont);
DrawText (CR_WHITE, RateX, 0, (char *)&fpsbuff[0], TAG_DONE);
SetFont (SmallFont);

View file

@ -163,7 +163,7 @@ public:
virtual void FlatFill (int left, int top, int right, int bottom, FTexture *src);
// Set an area to a specified color
virtual void Clear (int left, int top, int right, int bottom, int color) const;
virtual void Clear (int left, int top, int right, int bottom, int palcolor, uint32 color) const;
// Calculate gamma table
void CalcGamma (float gamma, BYTE gammalookup[256]);

View file

@ -626,7 +626,7 @@ void WI_drawBackground()
}
else
{
screen->Clear(0,0, SCREENWIDTH, SCREENHEIGHT, 0);
screen->Clear(0,0, SCREENWIDTH, SCREENHEIGHT, 0, 0);
}
for(i=0;i<anims.Size();i++)

View file

@ -274,11 +274,9 @@ bool D3DFB::CreateResources ()
I_RestoreWindowedPos ();
VidResizing = false;
}
if (FAILED(D3DDevice->CreatePixelShader (PalTexShaderDef, &PalTexShader)))
{
return false;
}
if (FAILED(D3DDevice->CreatePixelShader (PlainShaderDef, &PlainShader)))
if (FAILED(D3DDevice->CreatePixelShader (PalTexShaderDef, &PalTexShader)) ||
FAILED(D3DDevice->CreatePixelShader (PlainShaderDef, &PlainShader)) ||
FAILED(D3DDevice->CreatePixelShader (DimShaderDef, &DimShader)))
{
return false;
}
@ -335,6 +333,11 @@ void D3DFB::ReleaseResources ()
PlainShader->Release();
PlainShader = NULL;
}
if (DimShader != NULL)
{
DimShader->Release();
DimShader = NULL;
}
}
bool D3DFB::Reset ()
@ -1292,6 +1295,70 @@ FNativeTexture *D3DFB::CreateTexture(FTexture *gametex)
return new D3DTex(gametex, D3DDevice);
}
//==========================================================================
//
// D3DFB :: Clear
//
// Fills the specified region with a color.
//
//==========================================================================
void D3DFB::Clear (int left, int top, int right, int bottom, int palcolor, uint32 color) const
{
if (In2D < 2)
{
Super::Clear(left, top, right, bottom, palcolor, color);
return;
}
if (palcolor >= 0)
{
color = GPalette.BaseColors[palcolor];
}
D3DRECT rect = { left, top, right, bottom };
D3DDevice->Clear(1, &rect, D3DCLEAR_TARGET, color | 0xFF000000, 1.f, 0);
}
//==========================================================================
//
// D3DFB :: Dim
//
//==========================================================================
void D3DFB::Dim (PalEntry color, float amount, int x1, int y1, int w, int h) const
{
if (amount <= 0)
return;
if (In2D < 2)
{
Super::Dim(color, amount, x1, y1, w, h);
return;
}
if (amount >= 1)
{
D3DRECT rect = { x1, y1, x1 + w, y1 + h };
D3DDevice->Clear(1, &rect, D3DCLEAR_TARGET, color | 0xFF000000, 1.f, 0);
}
else
{
FBVERTEX verts[4] =
{
{ x1-0.5f, y1-0.5f, 0.5f, 1, 0, 0 },
{ x1+w-0.5f, y1-0.5f, 0.5f, 1, 0, 0 },
{ x1+w-0.5f, y1+h-0.5f, 0.5f, 1, 0, 0 },
{ x1-0.5f, y1+h-0.5f, 0.5f, 1, 0, 0 }
};
float constant[4] =
{
RPART(color)/255.f, GPART(color)/255.f, BPART(color)/255.f, APART(color)/255.f,
};
D3DDevice->SetPixelShader(DimShader);
D3DDevice->SetPixelShaderConstantF(1, constant, 1);
D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &verts, sizeof(FBVERTEX));
D3DDevice->SetPixelShader(PalTexShader);
}
}
//==========================================================================
//
// D3DFB :: DrawTextureV

View file

@ -72,7 +72,7 @@ const DWORD PalTexShaderDef[] =
};
// A texture that doesn't look up colors from a palette.
// Can be used for shaded L8 textures or RGB textures.
// Can be used for RGB textures.
#if HLSL_SOURCE_CODE
sampler2D Image : register(s0);
@ -129,3 +129,48 @@ const DWORD PlainShaderDef[] =
0x00000042, 0x800f0000, 0xb0e40000, 0x00000004, 0x800f0000, 0x80e40000,
0xa0e40001, 0xa0e40000, 0x0000ffff
};
// A shader that just returns the value of c1
#if HLSL_SOURCE_CODE
float4 Color : register(c1);
float4 main () : COLOR
{
return Color;
}
#endif
#if SHADER_ASSEMBLY_CODE
//
// Generated by Microsoft (R) D3DX9 Shader Compiler 9.15.779.0000
//
// fxc dimshader.ps /Tps_1_1 /VnDimShader /Fh
//
//
// Parameters:
//
// float4 Color;
//
//
// Registers:
//
// Name Reg Size
// ------------ ----- ----
// Color c1 1
//
ps_1_1
mov r0, c1
// approximately 1 instruction slot used
#endif
const DWORD DimShaderDef[] =
{
0xffff0101, 0x0022fffe, 0x42415443, 0x0000001c, 0x0000004f, 0xffff0101,
0x00000001, 0x0000001c, 0x00000100, 0x00000048, 0x00000030, 0x00010002,
0x00020001, 0x00000038, 0x00000000, 0x6f6c6f43, 0xabab0072, 0x00030001,
0x00040001, 0x00000001, 0x00000000, 0x315f7370, 0x4d00315f, 0x6f726369,
0x74666f73, 0x29522820, 0x44334420, 0x53203958, 0x65646168, 0x6f432072,
0x6c69706d, 0x39207265, 0x2e35312e, 0x2e393737, 0x30303030, 0xababab00,
0x00000001, 0x800f0000, 0xa0e40001, 0x0000ffff
};

View file

@ -234,6 +234,8 @@ public:
FNativeTexture *CreateTexture (FTexture *gametex);
FNativeTexture *CreatePalette (FTexture *pal);
void STACK_ARGS DrawTextureV (FTexture *img, int x, int y, uint32 tag, va_list tags);
void Clear (int left, int top, int right, int bottom, int palcolor, uint32 color) const;
void Dim (PalEntry color, float amount, int x1, int y1, int w, int h) const;
HRESULT GetHR ();
private:
@ -279,6 +281,7 @@ private:
IDirect3DTexture9 *ShadedPaletteTexture;
IDirect3DPixelShader9 *PalTexShader;
IDirect3DPixelShader9 *PlainShader;
IDirect3DPixelShader9 *DimShader;
D3DFB() {}
};