diff --git a/docs/rh-log.txt b/docs/rh-log.txt index ba467e2c7..8791e73cf 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -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. diff --git a/src/am_map.cpp b/src/am_map.cpp index 0951cacb9..62d94e76d 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -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 { diff --git a/src/c_console.cpp b/src/c_console.cpp index 25c98a568..ed63fa525 100644 --- a/src/c_console.cpp +++ b/src/c_console.cpp @@ -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) diff --git a/src/d_main.cpp b/src/d_main.cpp index 6d5deef9f..027fe59ff 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -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); diff --git a/src/f_finale.cpp b/src/f_finale.cpp index dd9f73169..56684465b 100644 --- a/src/f_finale.cpp +++ b/src/f_finale.cpp @@ -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 diff --git a/src/hu_scores.cpp b/src/hu_scores.cpp index 3e405faba..c654dd973 100644 --- a/src/hu_scores.cpp +++ b/src/hu_scores.cpp @@ -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) { diff --git a/src/m_menu.cpp b/src/m_menu.cpp index 80b649ad3..36e14173f 100644 --- a/src/m_menu.cpp +++ b/src/m_menu.cpp @@ -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 { diff --git a/src/m_options.cpp b/src/m_options.cpp index 62ab9729a..812f2a292 100644 --- a/src/m_options.cpp +++ b/src/m_options.cpp @@ -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, diff --git a/src/r_draw.cpp b/src/r_draw.cpp index a551abe1b..73fcaa607 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -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); } } diff --git a/src/r_main.cpp b/src/r_main.cpp index ce1d0a5fe..1ef130790 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -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); diff --git a/src/r_polymost.cpp b/src/r_polymost.cpp index 082ea7661..3f36d3df2 100644 --- a/src/r_polymost.cpp +++ b/src/r_polymost.cpp @@ -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; diff --git a/src/v_draw.cpp b/src/v_draw.cpp index c9989a2d0..3b3e86c5a 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -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 } } diff --git a/src/v_video.cpp b/src/v_video.cpp index 7d49865ea..adeb885c4 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -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); diff --git a/src/v_video.h b/src/v_video.h index 05c3c4124..884ec1674 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -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]); diff --git a/src/wi_stuff.cpp b/src/wi_stuff.cpp index 23802b9a0..84b43580c 100644 --- a/src/wi_stuff.cpp +++ b/src/wi_stuff.cpp @@ -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;iCreatePixelShader (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 diff --git a/src/win32/fb_d3d9_shaders.h b/src/win32/fb_d3d9_shaders.h index da553ab18..995dc58c1 100644 --- a/src/win32/fb_d3d9_shaders.h +++ b/src/win32/fb_d3d9_shaders.h @@ -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 +}; diff --git a/src/win32/win32iface.h b/src/win32/win32iface.h index 9946003f6..247734687 100644 --- a/src/win32/win32iface.h +++ b/src/win32/win32iface.h @@ -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() {} };