- New: When using the D3D9 framebuffer, palette blending is now applied only

to the 3D area of the screen. This means the console and (the primary
  rectangular area of) the status bar are no longer blended.


SVN r601 (trunk)
This commit is contained in:
Randy Heit 2007-12-18 01:50:08 +00:00
parent 4d6fc97a9a
commit c087e4d411
7 changed files with 174 additions and 14 deletions

View file

@ -1,3 +1,8 @@
December 17, 2007
- New: When using the D3D9 framebuffer, palette blending is now applied only
to the 3D area of the screen. This means the console and (the primary
rectangular area of) the status bar are no longer blended.
December 17, 2007 (Changes by Graf Zahl) December 17, 2007 (Changes by Graf Zahl)
- Fixed: When a skybox viewpoint is destroyed it should clear all - Fixed: When a skybox viewpoint is destroyed it should clear all
sector references to itself. sector references to itself.

View file

@ -48,6 +48,7 @@ typedef enum cstate_t {
c_up=0, c_down=1, c_falling=2, c_rising=3 c_up=0, c_down=1, c_falling=2, c_rising=3
} constate_e; } constate_e;
extern constate_e ConsoleState; extern constate_e ConsoleState;
extern int ConBottom;
// Initialize the console // Initialize the console
void C_InitConsole (int width, int height, bool ingame); void C_InitConsole (int width, int height, bool ingame);

View file

@ -87,6 +87,7 @@
#include "version.h" #include "version.h"
#include "v_text.h" #include "v_text.h"
#include "st_start.h" #include "st_start.h"
#include "templates.h"
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
@ -524,6 +525,7 @@ void D_Display (bool screenshot)
switch (gamestate) switch (gamestate)
{ {
case GS_FULLCONSOLE: case GS_FULLCONSOLE:
screen->SetBlendingRect(0,0,0,0);
C_DrawConsole (); C_DrawConsole ();
M_Drawer (); M_Drawer ();
if (!screenshot) if (!screenshot)
@ -535,6 +537,18 @@ void D_Display (bool screenshot)
if (!gametic) if (!gametic)
break; break;
if (!menuactive)
{
screen->SetBlendingRect(viewwindowx, MAX(ConBottom,viewwindowy),
viewwindowx + realviewwidth, MAX(ConBottom,viewwindowy + realviewheight));
}
else
{
// Don't chop the blending effect off at the status bar when the menu is
// active. Mostly, this is just to make Strife's dialogs with portrait
// images look okay when a blend is active.
screen->SetBlendingRect(0,0,0,0);
}
R_RefreshViewBorder (); R_RefreshViewBorder ();
P_CheckPlayerSprites(); P_CheckPlayerSprites();
R_RenderActorView (players[consoleplayer].mo); R_RenderActorView (players[consoleplayer].mo);
@ -559,16 +573,19 @@ void D_Display (bool screenshot)
break; break;
case GS_INTERMISSION: case GS_INTERMISSION:
screen->SetBlendingRect(0,0,0,0);
WI_Drawer (); WI_Drawer ();
CT_Drawer (); CT_Drawer ();
break; break;
case GS_FINALE: case GS_FINALE:
screen->SetBlendingRect(0,0,0,0);
F_Drawer (); F_Drawer ();
CT_Drawer (); CT_Drawer ();
break; break;
case GS_DEMOSCREEN: case GS_DEMOSCREEN:
screen->SetBlendingRect(0,0,0,0);
D_PageDrawer (); D_PageDrawer ();
CT_Drawer (); CT_Drawer ();
break; break;

View file

@ -50,6 +50,7 @@
#include "v_video.h" #include "v_video.h"
#include "vectors.h" #include "vectors.h"
#include "a_sharedglobal.h" #include "a_sharedglobal.h"
#include "c_console.h"
//EXTERN_CVAR (Int, tx) //EXTERN_CVAR (Int, tx)
//EXTERN_CVAR (Int, ty) //EXTERN_CVAR (Int, ty)
@ -452,8 +453,6 @@ void R_MapColoredPlane (int y, int x1)
// //
//========================================================================== //==========================================================================
extern int ConBottom;
void R_ClearPlanes (bool fullclear) void R_ClearPlanes (bool fullclear)
{ {
int i, max; int i, max;

View file

@ -264,6 +264,9 @@ public:
// Changes the vsync setting, if supported by the device. // Changes the vsync setting, if supported by the device.
virtual void SetVSync (bool vsync); virtual void SetVSync (bool vsync);
// Set the rect defining the area effected by blending.
virtual void SetBlendingRect (int x1, int y1, int x2, int y2) {}
#ifdef _WIN32 #ifdef _WIN32
virtual void PaletteChanged () = 0; virtual void PaletteChanged () = 0;
virtual int QueryNewPalette () = 0; virtual int QueryNewPalette () = 0;

View file

@ -67,6 +67,9 @@
// MACROS ------------------------------------------------------------------ // MACROS ------------------------------------------------------------------
// The number of vertices the vertex buffer should hold.
#define NUM_VERTS 28
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
IMPLEMENT_CLASS(D3DFB) IMPLEMENT_CLASS(D3DFB)
@ -194,6 +197,11 @@ D3DFB::D3DFB (int width, int height, bool fullscreen)
PalFormat = D3DFMT_UNKNOWN; PalFormat = D3DFMT_UNKNOWN;
VSync = vid_vsync; VSync = vid_vsync;
OffByOneAt = -1; OffByOneAt = -1;
BlendingRect.left = 0;
BlendingRect.top = 0;
BlendingRect.right = FBWidth;
BlendingRect.bottom = FBHeight;
UseBlendingRect = false;
Gamma = 1.0; Gamma = 1.0;
memset (FlashConstants, 0, sizeof(FlashConstants)); memset (FlashConstants, 0, sizeof(FlashConstants));
@ -621,32 +629,116 @@ bool D3DFB::CreatePaletteTexture ()
} }
bool D3DFB::CreateVertexes () bool D3DFB::CreateVertexes ()
{
if (FAILED(D3DDevice->CreateVertexBuffer (sizeof(FBVERTEX)*NUM_VERTS, D3DUSAGE_WRITEONLY, D3DFVF_FBVERTEX, D3DPOOL_DEFAULT, &VertexBuffer, NULL)) ||
!UploadVertices())
{
return false;
}
return true;
}
bool D3DFB::UploadVertices()
{ {
float top = (TrueHeight - Height) * 0.5f - 0.5f; float top = (TrueHeight - Height) * 0.5f - 0.5f;
float right = float(Width) - 0.5f; float right = float(Width) - 0.5f;
float bot = float(Height) + top; float bot = float(Height) + top;
float texright = float(Width) / float(FBWidth); float texright = float(Width) / float(FBWidth);
float texbot = float(Height) / float(FBHeight); float texbot = float(Height) / float(FBHeight);
FBVERTEX verts[4] =
{
{ -0.5f, top, 0.5f, 1.f, 0.f, 0.f },
{ right, top, 0.5f, 1.f, texright, 0.f },
{ right, bot, 0.5f, 1.f, texright, texbot },
{ -0.5f, bot, 0.5f, 1.f, 0.f, texbot }
};
void *pverts; void *pverts;
if (FAILED(D3DDevice->CreateVertexBuffer (sizeof(verts), D3DUSAGE_WRITEONLY, D3DFVF_FBVERTEX, D3DPOOL_DEFAULT, &VertexBuffer, NULL)) || if ((BlendingRect.left <= 0 && BlendingRect.right >= FBWidth &&
FAILED(VertexBuffer->Lock (0, sizeof(verts), &pverts, 0))) BlendingRect.top <= 0 && BlendingRect.bottom >= FBHeight) ||
BlendingRect.left >= BlendingRect.right ||
BlendingRect.top >= BlendingRect.bottom)
{ {
// Blending rect covers the whole screen, so only need 4 verts.
FBVERTEX verts[4] =
{
{ -0.5f, top, 0.5f, 1.f, 0.f, 0.f },
{ right, top, 0.5f, 1.f, texright, 0.f },
{ right, bot, 0.5f, 1.f, texright, texbot },
{ -0.5f, bot, 0.5f, 1.f, 0.f, texbot }
};
if (SUCCEEDED(VertexBuffer->Lock(0, sizeof(verts), &pverts, 0)))
{
memcpy (pverts, verts, sizeof(verts));
VertexBuffer->Unlock();
return true;
}
return false; return false;
} }
else // Only the 3D area of the screen is effected by palette flashes.
// So we create some boxes around it that can be drawn without the
// flash. These include the corners of the view area so I can be
// sure the texture interpolation is consistant. (Well, actually,
// since it's a 1-to-1 pixel mapping, it shouldn't matter.)
float mxl = float(BlendingRect.left) - 0.5f;
float mxr = float(BlendingRect.right) - 0.5f;
float myt = float(BlendingRect.top) + top;
float myb = float(BlendingRect.bottom) + top;
float tmxl = float(BlendingRect.left) / float(Width) * texright;
float tmxr = float(BlendingRect.right) / float(Width) * texright;
float tmyt = float(BlendingRect.top) / float(Height) * texbot;
float tmyb = float(BlendingRect.bottom) / float(Height) * texbot;
/* +-------------------+
| |
+-----+-------+-----+
| | | |
| | | |
| | | |
+-----+-------+-----+
| |
+-------------------+ */
FBVERTEX verts[28] =
{
// The whole screen, for when no blending is happening
{ -0.5f, top, 0.5f, 1.f, 0.f, 0.f }, // 0
{ right, top, 0.5f, 1.f, texright, 0.f },
{ right, bot, 0.5f, 1.f, texright, texbot },
{ -0.5f, bot, 0.5f, 1.f, 0.f, texbot },
// Left area
{ -0.5f, myt, 0.5f, 1.f, 0.f, tmyt }, // 4
{ mxl, myt, 0.5f, 1.f, tmxl, tmyt },
{ mxl, myb, 0.5f, 1.f, tmxl, tmyb },
{ -0.5f, myb, 0.5f, 1.f, 0.f, tmyb },
// Right area
{ mxr, myt, 0.5f, 1.f, tmxr, tmyt }, // 8
{ right, myt, 0.5f, 1.f, texright, tmyt },
{ right, myb, 0.5f, 1.f, texright, tmyb },
{ mxr, myb, 0.5f, 1.f, tmxr, tmyb },
// Bottom area
{ -0.5f, bot, 0.5f, 1.f, 0.f, texbot }, // 12
{ -0.5f, myb, 0.5f, 1.f, 0.f, tmyb },
{ mxl, myb, 0.5f, 1.f, tmxl, tmyb },
{ mxr, myb, 0.5f, 1.f, tmxr, tmyb },
{ right, myb, 0.5f, 1.f, texright, tmyb },
{ right, bot, 0.5f, 1.f, texright, texbot },
// Top area
{ right, top, 0.5f, 1.f, texright, 0.f }, // 18
{ right, myt, 0.5f, 1.f, texright, tmyt },
{ mxr, myt, 0.5f, 1.f, tmxr, tmyt },
{ mxl, myt, 0.5f, 1.f, tmxl, tmyt },
{ -0.5f, myt, 0.5f, 1.f, 0.f, tmyt },
{ -0.5f, top, 0.5f, 1.f, 0.f, 0.f },
// Middle (blended) area
{ mxl, myt, 0.5f, 1.f, tmxl, tmyt }, // 24
{ mxr, myt, 0.5f, 1.f, tmxr, tmyt },
{ mxr, myb, 0.5f, 1.f, tmxr, tmyb },
{ mxl, myb, 0.5f, 1.f, tmxl, tmyb }
};
if (SUCCEEDED(VertexBuffer->Lock(0, sizeof(verts), &pverts, 0)))
{ {
memcpy (pverts, verts, sizeof(verts)); memcpy (pverts, verts, sizeof(verts));
VertexBuffer->Unlock(); VertexBuffer->Unlock();
return true;
} }
return true; return false;
} }
int D3DFB::GetPageCount () int D3DFB::GetPageCount ()
@ -806,7 +898,25 @@ bool D3DFB::PaintToWindow ()
D3DDevice->SetFVF (D3DFVF_FBVERTEX); D3DDevice->SetFVF (D3DFVF_FBVERTEX);
D3DDevice->SetPixelShader (PalTexShader); D3DDevice->SetPixelShader (PalTexShader);
D3DDevice->SetPixelShaderConstantF (0, FlashConstants[0], 2); D3DDevice->SetPixelShaderConstantF (0, FlashConstants[0], 2);
D3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 0, 2); if (!UseBlendingRect || FlashConstants[1][0] == 1)
{ // The whole screen as a single quad.
D3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 0, 2);
}
else
{ // The screen split up so that only the 3D view is blended.
D3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 24, 2); // middle
// The rest is drawn unblended, so reset the shader constant.
static const float FlashZero[2][4] =
{ { 0, 0, 0, 0 },
{ 1, 1, 1, 0 } };
D3DDevice->SetPixelShaderConstantF (0, FlashZero[0], 2);
D3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 4, 2); // left
D3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 8, 2); // right
D3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 12, 4); // bottom
D3DDevice->DrawPrimitive (D3DPT_TRIANGLEFAN, 18, 4); // top
}
D3DDevice->EndScene(); D3DDevice->EndScene();
return SUCCEEDED(D3DDevice->Present(NULL, NULL, NULL, NULL)); return SUCCEEDED(D3DDevice->Present(NULL, NULL, NULL, NULL));
} }
@ -934,3 +1044,24 @@ void D3DFB::Blank ()
{ {
// Only used by movie player, which isn't working with D3D9 yet. // Only used by movie player, which isn't working with D3D9 yet.
} }
void D3DFB::SetBlendingRect(int x1, int y1, int x2, int y2)
{
if (BlendingRect.left != x1 ||
BlendingRect.top != y1 ||
BlendingRect.right != x2 ||
BlendingRect.bottom != y2)
{
BlendingRect.left = x1;
BlendingRect.top = y1;
BlendingRect.right = x2;
BlendingRect.bottom = y2;
if (UploadVertices())
{
UseBlendingRect = ((x1 > 0 || x2 < FBWidth || y1 > 0 || y2 < FBHeight)
&& BlendingRect.left < BlendingRect.right
&& BlendingRect.top < BlendingRect.bottom);
}
}
}

View file

@ -229,6 +229,7 @@ public:
void Blank (); void Blank ();
bool PaintToWindow (); bool PaintToWindow ();
void SetVSync (bool vsync); void SetVSync (bool vsync);
void SetBlendingRect (int x1, int y1, int x2, int y2);
HRESULT GetHR (); HRESULT GetHR ();
private: private:
@ -240,6 +241,7 @@ private:
void DoOffByOneCheck(); void DoOffByOneCheck();
void UploadPalette(); void UploadPalette();
void FillPresentParameters (D3DPRESENT_PARAMETERS *pp, bool fullscreen, bool vsync); void FillPresentParameters (D3DPRESENT_PARAMETERS *pp, bool fullscreen, bool vsync);
bool UploadVertices();
bool Reset(); bool Reset();
BYTE GammaTable[256]; BYTE GammaTable[256];
@ -257,6 +259,8 @@ private:
int FBWidth, FBHeight; int FBWidth, FBHeight;
int OffByOneAt; int OffByOneAt;
bool VSync; bool VSync;
RECT BlendingRect;
bool UseBlendingRect;
IDirect3DDevice9 *D3DDevice; IDirect3DDevice9 *D3DDevice;
IDirect3DVertexBuffer9 *VertexBuffer; IDirect3DVertexBuffer9 *VertexBuffer;