- moved viewport code to DFrameBuffer.
This commit is contained in:
parent
f17f8c9359
commit
c2a7a4bf30
16 changed files with 245 additions and 208 deletions
115
src/v_video.cpp
115
src/v_video.cpp
|
|
@ -75,6 +75,8 @@
|
|||
EXTERN_CVAR(Bool, cl_capfps)
|
||||
EXTERN_CVAR(Float, vid_brightness)
|
||||
EXTERN_CVAR(Float, vid_contrast)
|
||||
CVAR(Bool, gl_scale_viewport, true, CVAR_ARCHIVE);
|
||||
EXTERN_CVAR(Int, screenblocks)
|
||||
|
||||
CUSTOM_CVAR(Int, vid_maxfps, 200, CVAR_ARCHIVE | CVAR_GLOBALCONFIG)
|
||||
{
|
||||
|
|
@ -134,6 +136,8 @@ public:
|
|||
bool SetFlash(PalEntry rgb, int amount) { DBGBREAK; return false; }
|
||||
void GetFlash(PalEntry &rgb, int &amount) { DBGBREAK; }
|
||||
bool IsFullscreen() { DBGBREAK; return 0; }
|
||||
int GetClientWidth() { DBGBREAK; return 0; }
|
||||
int GetClientHeight() { DBGBREAK; return 0; }
|
||||
|
||||
float Gamma;
|
||||
};
|
||||
|
|
@ -967,6 +971,117 @@ void DFrameBuffer::WriteSavePic(player_t *player, FileWriter *file, int width, i
|
|||
}
|
||||
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Calculates the viewport values needed for 2D and 3D operations
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void DFrameBuffer::SetOutputViewport(IntRect *bounds)
|
||||
{
|
||||
if (bounds)
|
||||
{
|
||||
mSceneViewport = *bounds;
|
||||
mScreenViewport = *bounds;
|
||||
mOutputLetterbox = *bounds;
|
||||
return;
|
||||
}
|
||||
|
||||
// Special handling so the view with a visible status bar displays properly
|
||||
int height, width;
|
||||
if (screenblocks >= 10)
|
||||
{
|
||||
height = GetHeight();
|
||||
width = GetWidth();
|
||||
}
|
||||
else
|
||||
{
|
||||
height = (screenblocks*GetHeight() / 10) & ~7;
|
||||
width = (screenblocks*GetWidth() / 10);
|
||||
}
|
||||
|
||||
// Back buffer letterbox for the final output
|
||||
int clientWidth = GetClientWidth();
|
||||
int clientHeight = GetClientHeight();
|
||||
if (clientWidth == 0 || clientHeight == 0)
|
||||
{
|
||||
// When window is minimized there may not be any client area.
|
||||
// Pretend to the rest of the render code that we just have a very small window.
|
||||
clientWidth = 160;
|
||||
clientHeight = 120;
|
||||
}
|
||||
int screenWidth = GetWidth();
|
||||
int screenHeight = GetHeight();
|
||||
float scaleX, scaleY;
|
||||
if (ViewportIsScaled43())
|
||||
{
|
||||
scaleX = MIN(clientWidth / (float)screenWidth, clientHeight / (screenHeight * 1.2f));
|
||||
scaleY = scaleX * 1.2f;
|
||||
}
|
||||
else
|
||||
{
|
||||
scaleX = MIN(clientWidth / (float)screenWidth, clientHeight / (float)screenHeight);
|
||||
scaleY = scaleX;
|
||||
}
|
||||
mOutputLetterbox.width = (int)round(screenWidth * scaleX);
|
||||
mOutputLetterbox.height = (int)round(screenHeight * scaleY);
|
||||
mOutputLetterbox.left = (clientWidth - mOutputLetterbox.width) / 2;
|
||||
mOutputLetterbox.top = (clientHeight - mOutputLetterbox.height) / 2;
|
||||
|
||||
// The entire renderable area, including the 2D HUD
|
||||
mScreenViewport.left = 0;
|
||||
mScreenViewport.top = 0;
|
||||
mScreenViewport.width = screenWidth;
|
||||
mScreenViewport.height = screenHeight;
|
||||
|
||||
// Viewport for the 3D scene
|
||||
mSceneViewport.left = viewwindowx;
|
||||
mSceneViewport.top = screenHeight - (height + viewwindowy - ((height - viewheight) / 2));
|
||||
mSceneViewport.width = viewwidth;
|
||||
mSceneViewport.height = height;
|
||||
|
||||
// Scale viewports to fit letterbox
|
||||
bool notScaled = ((mScreenViewport.width == ViewportScaledWidth(mScreenViewport.width, mScreenViewport.height)) &&
|
||||
(mScreenViewport.width == ViewportScaledHeight(mScreenViewport.width, mScreenViewport.height)) &&
|
||||
!ViewportIsScaled43());
|
||||
if ((gl_scale_viewport && !IsFullscreen() && notScaled) || !RenderBuffersEnabled())
|
||||
{
|
||||
mScreenViewport.width = mOutputLetterbox.width;
|
||||
mScreenViewport.height = mOutputLetterbox.height;
|
||||
mSceneViewport.left = (int)round(mSceneViewport.left * scaleX);
|
||||
mSceneViewport.top = (int)round(mSceneViewport.top * scaleY);
|
||||
mSceneViewport.width = (int)round(mSceneViewport.width * scaleX);
|
||||
mSceneViewport.height = (int)round(mSceneViewport.height * scaleY);
|
||||
|
||||
// Without render buffers we have to render directly to the letterbox
|
||||
if (!RenderBuffersEnabled())
|
||||
{
|
||||
mScreenViewport.left += mOutputLetterbox.left;
|
||||
mScreenViewport.top += mOutputLetterbox.top;
|
||||
mSceneViewport.left += mOutputLetterbox.left;
|
||||
mSceneViewport.top += mOutputLetterbox.top;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
//
|
||||
// Calculates the OpenGL window coordinates for a zdoom screen position
|
||||
//
|
||||
//===========================================================================
|
||||
|
||||
int DFrameBuffer::ScreenToWindowX(int x)
|
||||
{
|
||||
return mScreenViewport.left + (int)round(x * mScreenViewport.width / (float)GetWidth());
|
||||
}
|
||||
|
||||
int DFrameBuffer::ScreenToWindowY(int y)
|
||||
{
|
||||
return mScreenViewport.top + mScreenViewport.height - (int)round(y * mScreenViewport.height / (float)GetHeight());
|
||||
}
|
||||
|
||||
|
||||
|
||||
CCMD(clean)
|
||||
{
|
||||
Printf ("CleanXfac: %d\nCleanYfac: %d\n", CleanXfac, CleanYfac);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue